[go: up one dir, main page]

0% found this document useful (0 votes)
61 views14 pages

Accenture

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views14 pages

Accenture

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

01.

Googly Number

Problem Statement

You are given a number N, your task is to check whether the number is GOOGLY or NOT
GOOGLY. A number is GOOGLY if the sum of digits of that number is prime.

Input Format:

The input consists of a single line:

The first line contains an integer N.

Input will be read from the STDIN by the candidate.

Output Format:

Print the string denoting whether the number is GOOGLY or NOT GOOGLY..

Constraints:

1≤N≤10^9

Example:

Input:

21

Output:

GOOGLY

Explanation:

The sum of digits of 21 is 2+1-3, which is a prime number. Hence, the number is GOOGLY.
02. Battle of the Titan

Problem Statement

The first line contains two integers d and m-the titan's durability and the number of squads you
have...

The second line contains m integers a1,a2,...,am- the amount of damage each squad deals per
attack.

The third line contains mmm integers r1,r2,..., rm-the recovery time for each squad, indicating
how many turns they must wait before attacking again after an attack.

Input Format:

The input consists of the following lines:

The input will be read from the STDIN by the candidate.

Output Format:

The output consists of one line:

For each battle scenario, print the minimum number of turns required to defeat the titan. The
output will be matched to the candidate's output printed on STDOUT.

Constraints:

1≤d,m≤2×10^5

1≤ai≤2×10^5

1≤ri≤2×10^5

03. Secret Agent Decoder

Problem Statement

Alex is a secret agent, and he intercepted some encoded strings sent by a rival organization.
Alex needs to decode these strings into numbers using a specific decoding rule. The decoding
rule converts each character in the string to its ASCII value and then uses positional weights to
form the final number.

For example:

The string "ABC" is decoded as follows:

ASCII value of ' A' = 65

ASCII value of ' B' = 66

ASCII value of ^ prime C' = 67

Decoded number = 65 * 100 + 66 * 10 + 67 * 1 = 7227

Given n strings, help Alex decode each string according to this rule.

Input Format:

The first line contains an integer n the number of strings to decode.

The next n lines each contain a string.

Output Format:

Print n decoded numbers, each on a new line.

04. ALTERNATING PRIME

Problem Statement

Alex has an integer array arr of size N and needs to construct an alternating prime sequence
from the given set of integers for the coding challenge. For each integer in the array that he is
unable to use, his penalty increases by the amount of that integer value An alternating prime
sequence is defined as a sequence where each prime integer is followed by a non-prime integer
and each non-prime integer is followed by a prime one. For example, [1, 2, 4, 3, 6, 5] is
considered to be a valid alternating prime sequence while [1, 2, 3, 4, 5, 6] is not a 2 and 3 are
both primes. Note that 1 is considered to be a non-prime integer, Your task is to find and print
the minimum possible penalty that Alec can have while completing the task.

Input Format:

The input is in the following format:


The first line contains an integer, i.e. N..

Each of the next N lines contains a single element denoting the elements of the array arr

The input will be read from the STDIN by the candidate

Output Format:

Print the minimum possible penalty that Alex can have while completing the task.

Sample Input:

Sample Output:

05. TREES AND SPRINKLERS

Problem Statement

There are exactly N trees on a number line. Each tree stands at a unique integral point T[i].
Exactly M water sprinklers are also placed on the same number line, with each placed at a
unique integral point S[i]. A point can contain a tree as well as a water sprinkler. A water
sprinkler can provide water to the trees, which are not more than k units far in both directions
from the water sprinkler. If k=0, then the water sprinkler will only provide its water to the tree at
the same point. Your task is to find the minimum value of k such that all the trees receive water
from the water sprinklers
Input Format:

The input consists of four lines: The first line contains an integer N denoting the number of trees
on the number line.

The second line contains N space-separated integers, representing the positions of the trees on
the number line, denoted as T[1]. T[2],.... T[N].

The third line contains an integer M, denoting the number of water sprinklers on the number
line.

The fourth line contains M space-separated integers, representing the positions of the water
sprinklers on the number line, denoted as S[1], S[2]..., S[M].

Output Format:

Output a single integer k, which is the minimum value such that every tree receives water from
at least one sprinkler.

Sample Input:

146

35

Sample Output:

06. SUBARRAY SUM OPERATION

Problem Statement

You are given an array A consisting of N positive numbers. In one operation, you can take any
subarray of the array and replace it with its sum. You can perform this operation any number of
times. Your task is to print a number that denotes the maximum length of the non-decreasing
array after performing the above operations.
For example: If A: [1, 4, 2, 6, 9], you can choose the subarray [2.6] and replace it with its sum.
We get A: [1, 4, 8, 9]. Therefore in 1 operation, the array can be made non-decreasing.
Input format:

The input consists of two lines:

The first line contains an integer N.

The second line contains N space-separated integers denoting the array elements.

The input will be read from the STDIN by the candidate.

Output Format:

Output a single integer denoting the maximum length of the non-decreasing array after
performing the operations.

Sample Input:

14269

Sample Output:

07. STRING REPITITION

Problem Statement

You are given a string s. Your task is to modify and print the given strings in such a way that the
adjacent characters in the string don't repeat themselves more than twice.

Note:

You can delete the extra characters to ensure that the characters in the string don't repeat
themselves more than twice.

The modified string should be of maximum length.

Uppercase and lowercase characters should be considered different.

Input format:
The input consists of a single line:

The line contains the string s.

Output format:

Print the modified string such that the characters in the string don't repeat themselves more than
twice.

The output will be matched to the candidate's output printed on the STDOUT.

Sample input:

aaabbc

Sample Output:

aabbc

08. CLIMBING STAIRS

Problem Statement

Alice climbs a staircase and takes N steps to reach the top. In each turn Alice can climb 1 or M
stairs. Find the minimum number of climbs to reach the top i.e. Nth stair.

Input Format:

The input consists of a single line:

The line contains two space-separated integers N and M.

The input will be read from the STDIN by the candidate.

Output Format:

Print the number that represents the minimum number of climbs required to reach the top.

The output will be matched to the candidate's output printed on the STDOUT.

Sample Input: 10 3
Sample Output:

09. POWER OF TWO

Problem Statement.

The power of a number indicates how many times that number is multiplied by itself. You are
given an integer n, find whether n is the power of 2. If n is a power of 2, then print the power,
else print-1.

Input Format:

Input consists of a single line:

The line contains a single integer, i.e. n.

Input will be read from the STDIN by the candidate.

Output Format:

The output will be an integer, ie., the power of 2.

The output will be matched to the candidate's output printed on the STDOUT.

Constraints:0≤n≤10^9

Sample Input:

64

Sample Output:

10. Counting Votes

Problem Statement

Elections are conducted in a town that has a population N. All the people of the town cast votes
on the various candidates in town. The people of the town later realized that the votes of only
the candidates 18 and above years of age should be considered. Find out the candidate who is
the winner if only the votes of age group 18 and above are considered. If the winner cannot be
decided or there is a tie, print-1.

You are given an array vote which represents the candidate to whom the vote is given by the i th
person and another array of age which represents the age of that particular voter.

Input Format:

The input consists of three lines:

The first line will contain one value N, the size of the arrays.

The second line will contain N space-separated integers representing the vote array

The third line will contain N space-separated integers representing the age array.

Output Format:

Print the candidate number who received the most votes from people aged 18 and above, If
there is a tie or no valid votes, print-1.

Sample Input:

12132

17 21 20 19 18

Sample Output:

11. PASSWORD VALIDATOR

Problem Statement

You are given a string str. Your task is to find the number of checks that is not satisfied by the
string str by checking the validation of the string str if it's a strong password or not. A password
is a strong password only if:

It contains at least 6 characters and at most 22 characters.


It must contain at least one uppercase character.

It must contain at least one lowercase character.

It must contain at least two special characters (@, !, &, ^,%,*,#).

It must contain at least one numeric value.

It must not contain any two same consecutive character.

Input Format:

The input consists of a single line:

The first line contains a string str.

The input will be read from the STDIN by the candidate.

Output Format:

Print the number that represents the number of checks that is not satisfied by the str.

The output will be matched to the candidate's output printed on the STDOUT.

Sample input:

A1b@!cd

Sample Output:

Sample input:
aabbcc

Sample output:
4
12. STRING SHORTENING

Problem Statement

You are provided with string str and your task is to shorten the string to the minimum length
possible. The minimum length of the string can be attained by performing a set of operations
that states that you could select two same characters and delete them but without disturbing the
order in the string which means that only the adjacent same letters can be deleted. For
example, "baaab" can be reduced to "bab" in just one iteration. Your task is to shorten the length
of the string str and print the reduced string and if all the characters are deleted then print
"Empty String".

Input Format:

The input consists of a single line:

The line contains string str

The input will be read from the STDIN by the candidate

Output Format:

Print the modified string. If the modified string contains no character, then print" Empty String".

The output will be matched to the candidate's output printed on the STDOUT

Sample Input:

abba

Sample Output:

Empty String

Sample Input:
baaab

Sample Output:
Bab
13. KEYPAD STROKES

Problem Statement

The keypad shown below works as follows: To type "a", it requires a single stroke on the "2"
button, to type "b", it requires two strokes on the "2" button, to type "c", it requires three strokes
on the "2" button, to type "d", it requires a single stroke on the "3" button. It works the same way
for the other alphabets.

Input Format:

The input consists of a single line:

A string str that contains lowercase alphabets only.

Output Format:

Print the total number of strokes required to type the given string.

Sample Input:

hello

Sample output:

13
14. TRUNCATE SEQUENCES OF BINARY NUMBERS

Problem Statement

Alex is working with sequences of binary strings. They are given a sequence of binary strings
and an integer k. Their task is to truncate the sequence such that it contains only the first k
binary strings. Alex needs your help to write a code that performs this task efficiently.

Note: If k=0, then print -1

Input Format:

The input consists of two lines:

The first line contains a string s representing the sequence of binary strings, where each binary
string is separated by a space.

The second line contains an integer k.

The input will be read from the STDIN by the candidate

Output Format:

If k=0, print-1.

Otherwise, print the truncated sequence of binary strings containing the first k strings, each
separated by a space.

Sample Input:

101 111 1001 110 1010.

Sample Output:

101 111 1001

15. LARGEST VALUE POSSIBLE

Problem Statement
You are given an integer array arr of size N. The elements of the array arr represent a number.
Your task is to rearrange and print the array elements such that after rearranging, the number
represented by the array arr gives the largest value.

Input Format:

The input consist of two lines:

The first line contains N.

The second line contains arr.

Input will be read from the STDIN by the candidate

Output Format:

Print the modified array arr.

The output will be matched to the candidate's output printed on the STDOUT

Sample Input:

3 30 34

Sample Output:

34 3 30

You might also like