ACCENTURE
ACCENTURE
ACCENTURE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The "Nambiar Number" Generator: M.Nambiar has devised a mechanism to process any given
mobile number and thus generate a new resultant number. He calls this mechanism the `Nambiar
Number Generator" and the resultant number is referred to as the `Nambiar Number". The
mechanism is as follows in the given mobile number, starting with the first digit keep on adding all
subsequent digits till the state (even or odd) of the sum of the digits is opposite to the state (odd or
even) of the first digit Continue this from the subsequent digit till the last digit of the mobile number
is reached. Concatenating the sums thus generated results in the Nambiar Number."
The below examples will help to illustrate this. Please also look at the bottom of this problem
description for the expected function prototype.
Example 1
If the given mobile number is 9880127431 The first pass should start with the first digit. First digit is
9 which is odd. So, we will keep adding subsequent digits till the sum becomes even. 9+8=17 (17 is
odd, so continue adding the digits) 9+8+8 = 25 (25 is odd, so continue adding the digits) 9+8+8+0 =
25 (25 is odd, so continue adding the digits) 9+8+8+0+1 = 26 ( 26 is even, which is opposite to the
state of the first digit 9) So, Stop first pass here and remember that the result at the end of first pass
= 26
Now we enter the second pass. The second pass should start after the digit where we stopped the
first pass. In the first pass we have added the digits 9,8,8,0 and 1. So, the first digit for second pass
will be 2. which is even. Now, we will keep adding subsequent digits till the sum becomes odd. 2+7=9
( 9 is odd. which is opposite to the state of the first digit 2) So, Stop second pass here and remember
that the result at the end of second pass = 9
Now we enter the third pass. In the first pass we have added the digits 9.8,8.0 and 1, and the
resultant sum was 26. In the second pass we have added the digits 2 and 7, and the resultant sum
was 9. The third pass should start after the digit where we stopped the second pass. So, the first digit
for third pass will be 4. which is even. Now, we will keep adding subsequent digits till the sum
becomes odd. 4+3=7 ( 7 is odd. which is opposite to the state of the first digit 4) So, Stop third pass
here and remember that the result at the end of third pass = 7
Now we enter the fourth pass. In the first pass we have added the digits 9.8,8.0 and 1, and the
resultant sum was 26. In the second pass we have added the digits 2 and 7, and the resultant sum
was 9. In the third pass we have added the digits 4 and 3. and the resultant sum was 7. The fourth
pass should start after the digit where we stopped the third pass. So, the first digit for fourth pass
will be 1, which is odd. Now, we will keep adding subsequent digits till the sum becomes even.
However. we realize that this digit 1 is the last digit of the mobile number and there are no further
digits. So. Stop fourth pass here and remember that the result at the end of fourth pass = 1
For the mobile number 9880127431, the resultant number (Nambiar Number) will be the
concatenation of the results of the 4 passes = [26][9][7][1] = 26971
Note1: Please note that the number of passes required to process the given number may vary
depending upon the constitution of the mobile number.
Example 2:
If the given mobile number is 9860857152 First digit 9 is odd. First pass results in 9+8+6+0+8+5= 36
Second pass results in 7+1= 8 Third pass results in 5+2= 7 Note that the third pass stops at 7 (even
though we do not meet a change of state) because we have reached the end of the mobile number.
For the mobile number 9860857152, the resultant number (Nambiar Number) will be the
concatenation of the results of the 3 passes = [36][8][7] = 3687
Example 3:
If the given mobile number is 8123454210 The resultant number (Nambiar Number) will be 95970
Example 4:
If the given mobile number is 9900114279 The resultant number (Nambiar Number) will be 181149
______________________________________________________________________
You are required to implement the following function: Int CountDigitOccurrences(int l, int u , int x):
The function accepts 3 positive integers ‘T’,’u’ and ‘x’ as its arguments. You are required to calculate
the number of occurrences of a digit ‘x’ in the digits of numbers lying in the range between ‘l’ and ’u’
both inclusive, and return the same.
Note:
• l<=u
• 0<=x<=9
Example: Input:
l: 2 u: 13 x: 3
Output: 2
Explanation:
The number of occurrence of digit 3 in the digits of numbers lying in the range [2, 13] both inclusive
is 2, i.e., {3, 13}, hence 2 is returned
Sample input:
l: 1
u: 30 x: 2
Sample output:
12
____________________________________________________________________
Question :
Given a number, you are expected to find its two-digit "Reduced Subtracted Form (RSF)". The
"Reduced Subtracted Form (RSF)" of a number can be found by concatenating the difference
between its adjacent digits. To find the two-digit "Reduced Subtracted Form (RSF)", we need to
continue this process till the resultant RSF is not a two digit number.
For eg. if the input number is 6928, its RSF can be found by concatenating the difference between (6
and 9), (9 and 2) and (2 and 8) as shown below
So, the "Reduced Subtracted Form (RSF)" of 6928 = 376 The resultant RSF (376) is not a two-digit
number, so we must continue finding its "Reduced Subtracted Form(RSF)'.
So RSF of 376 = 41
Input1 = 5271
Expected output = 21
Note2: Note that while concatenating the differences, we are expected to use the absolute values
(non-negative)
Note3: The input values for all test cases in this program have been designed such that their two-
digit RSF is possible
____________________________________________________________________________
seed1 be ABC
seed2 be MNO
seed3 be PQR
PIN is 4 digit made of
123
345
289
9389
_____________________________________________________________________
Formula
~~~~~~~~
The function take two integers ‘n’ and ’div’ as input implement the function such that it returns the
sum of remainders given by numbers from 1 to ‘n’ (both inclusive) on being divided by ‘div’
Example: Input:
12
Output:
18
Explanation:
1+2+3+0+1+2+3+0+1+2+3+0=18
Sample Input:
15
5
Sample Output:
30
1+2+3+4+0+1+2+3+4+0+1+2+3+4+0
______________________________________________________________________
Given an number n, the task is to be broken in such a way that multiplication of its parts is
maximized.
Input : n = 10
Output : 36
exp:
10 = 4 + 3 + 3 and 4 * 3 * 3 = 36
Input : n = 8
Output : 18
8 = 2 + 3 + 3 and 2 * 3 * 3 = 18
_______________________________________________________________________
Arrays
~~~~~~
Problem statement
The function takes an integer array 'arr' of size 'n' as its arguments. Implement the function to find
and return the number of array elements which are equal to their index value in array i.e. arr[k] = k,
01 2345678 9
10 1 12 3 5 8 9 7 12 23
Output:
Explanation:
Index Element
0 10
1 1
2 12
3 3
4 5
5 8
6 9
7 7
8 12
9 23
Elements at index {1, 3, 7} are equal to their index values (1, 3, 7} respectively. Since these are 3
elements, thus, output is 3.
Sample Input:
-3 0 1 3 5 7
Sample Output:
________________________________________________________________________
Strings
~~~~~~~
English alphabet contains 26 letters. 5 of them are vowels {a, e , I, o, u} and rest 21 are consonants.
The function accepts a string ‘str’ of length ‘len’ as its argument. String ‘str’ contains space separated
words. A word is ‘hard’ if at least one of the 2 conditions hold true:
Otherwise, the word is ‘easy’. Implement the function to find the difficulty quotient of the string and
Difficulty quotient = (5*hard) – (2*easy) where, hard = count of hard words in the string and, easy =
count of easy words in the string
Note:
Input:
H E E H H
Output:
11
return 0;
_________________________________________________________________________
('a' to 'z' and 'A' to 'Z') along with other characters. Reverse this string 's' in such a way that only
alphabets are reversed and other characters are not affected.
Note:
Characters '' and '$' are at their original positions while all alphabets got reversed.
Sample Input:
$A5b*ntp^
Sample Output:
$p5t*nbA^
____________________________________________________________________________
PASSWORD : a secret word or phrase that must be used to gain admission to a place.
Passwords provide the first line of defense against unauthorized access to your computer and
personal information. The stronger your password, the more protected your computer will be from
hackers and malicious software. You should maintain strong passwords for all accounts on your
computer. At the same time remembering the passwords also should be an easy task, this problem
depicts one such method.
6 3 8 3 2 3 6 6 1 9
six three eight three two three six six one nine
stetttsson
ttetstsson
ttetsnosst
__________________________________________________________________________________
__
A common type of text alignment in print media is "justification", where the spaces between words
and between glyphs or letters are stretched or compressed in order to align both the left and right
ends of consecutive lines of text. When using justification, it is customary to treat the last line of a
paragraph separately by simply left or right aligning it, depending on the language direction. Lines in
which the spaces have been stretched beyond their normal width are called loose lines, while those
whose spaces have been compressed are called tight lines.
Sample Input: "The word learning is used routinely in discussions about teaching in higher
education"
Output : The word learning is used routinely in discussions about teaching in higher education
_______________________________________________________________________
The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard so that
no two queens threaten each other; thus, a solution requires that no two queens share the same
row, column, or diagonal. The eight queens puzzle has 92 distinct solutions. If solutions that differ
only by the symmetry operations of rotation and reflection of the board are counted as one, the
puzzle has 12 solutions.
The task given to us is the representation of the status of 8 Queens placed on a Chess Board. The
Input is an 8 X 8 matrix - made of 0's and 1's, where 0 represent an empty square and 1 represents a
square occupied by a queen. We need to verify if the eight queens are safe
Input :
00010000
00000010
00100000
00000001
01000000
00001000
10000000
00000100
Output : Valid
Input :
10000000
00010000
01000000
00001000
00100000
00000001
00000100
00100000
Output : Invalid
_________________________________________________________________________________
Prime : Dictionary says the meaning is "Of first importance , main".Primes are central in number
theory because of the fundamental theorem of arithmetic - every natural number greater than 1 is
either a prime itself or can be factorized as a product of primes that is unique up to their order.The
property of being prime is called primality.
The task of yours is to find if a name is Prime - how do we test a set of characters to be prime, let us
perform a calculation, sum of the ASCII values of the characters of the name, if the sum is Prime -
Name is to be considered as a Prime Name else it is not.
Note : Parameswaran Hariharan is a valid input - do not consider the ASCII value of any embedded
spaces.
__________________________________________________________________________________
___
You have a robot standing on the origin of x-axis. The robot can only follow these type of
3.A digit j : do same as jth instruction (where j is a digit which is less than i). You are given a function,
The function accepts a string ‘instr’ as its argument. Implement the function to find and return the
Assumptions:
3.Instructions will contain only the characters L,R, and a digit between 0 to 9. Example:
Input:
Instr: LR1RL2
Output:
int main()
{
return 0;
______________________________________________________________________
Joseph's team has been assigned the task of creating user-ids for all participants of an online gaming
competition. Joseph has designed a process for generating the user -id using the participant's
First_Name. Last_Name, PIN code and a number N. The process defined by Joseph is as below —
Stepl - Compare the lengths of First_Name and Last_Name of the participant. The one that is shorter
will be called 'Smaller Name- and the one that is longer will be called the -Longer Name". If both
First_Name and Last_Name are of equal Length. then the name that appears earlier in alphabetical
order will be called -Smaller Name' and the name that appears later in alphabetical order will be
called the -Longer Name.
Step2 - The user-id should be generated as below —Last Letter of the smaller name + Entire word of
the longer name + Digit at position N in the PIN when traversing the PIN from left to right + Digit at
position N in the PIN when traversing the PIN from right to left
Step3 - Toggle the alphabets of the user-id generated in step-2 i.e. upper-case alphabets should
become lower-case and lower-case alphabets should become upper-case.
Example-1 - If the participant's details are as below -First_Name = Rajiv Last_Name = Roy PIN =
560037 N = 6
Stepl - Length of Last_Name is less than the Length of First_Name. so the Smaller Name is "Roy" and
the Longer Name is "Rajiv'
Step2 - The user-id will be = Last Letter of the smaller name + Entire word in the longer name + Digit
at position N in the PIN when traversing the PIN from left to right + Digit at position N in the PIN
when traversing the PIN from right to left = Last Letter of 'Roy + Entire word in "Rajiv- + 6th Digit of
PIN from left + 6th Digit of PIN from right = y + Rajiv +7+5 Therefore. user-id = yRajiv75
Step1 - Length of First_Name is equal to the Length of Last_Name. Alphabetically, 'Kumar' appears
earlier than 'Manoj' (by comparing alphabetic positions of K and 'M') so the Smaller Name is 'Kumar'
and the Longer Name is 'Manoj'
Step2 - The user-id will be = Last Letter of the smaller name + Entire word in the longer name + Digit
at position N in the PIN when traversing the PIN from left to right + Digit at position N in the PIN
when traversing the PIN from right to left = Last Letter of 'Kumar + Entire word in "Manor + 2nd Digit
of PIN from left + 2 "d
name + Digit at position N in the PIN when traversing the PIN from left to right + Digit at position N in
the PIN when traversing the PIN from right to left = Last Letter of 'Kumar + Entire word in "Manor +
2nd Digit of PIN from left + 2 "d Digit of PIN from right = r + Manoj + 6 + 2 Therefore. user-id =
rManoj62
Step1 - Length of First_Name is equal to the Length of Last_Name. Alphabetically, 'Kumar' appears
earlier than 'Kumud' (by comparing alphabetic positions of 'Kum a' and 'Kum u') so the Smaller Name
is 'Kumar" and the Longer Name is "Kumud"
Step2 - The user-id will be = Last Letter of the smaller name + Entire word in the longer name + Digit
at position N in the PIN when traversing the PIN from left to right + Digit at position N in the PIN
when traversing the PIN from right to left = Last Letter of "Kumar- + Entire word in "Kumud' + 2nd
Digit of PIN from left + 2 rd Digit of PIN from right = r + Kumud + 6 + 2 Therefore. user-id = rKumud62
You are part of Joseph's team and he has asked you to write a program (method) to generate the
participant's user-id using the above rules.
_________________________________________________________________________
Patterns
~~~~~~~~
3<= N <= 20
N=5
01 02 03 04 05
16 06
15 07
14 08
13 12 11 10 09
__________________________________________________________________________________
________
Accept array of N integers from the user and find the maximum sum of consecutive elements.
"1<= N <=10000
1<= arr[ele] <= 10^9"
"#include<stdio.h>
#include<limits.h>
int main()
int N;
scanf(""%d"",&N);
int arr[N];
for(int ind=0;ind<N;scanf(""%d"",&arr[ind++]));
int max=INT_MIN,maxsum=0;
for(int ind=0;ind<N;ind++)
maxsum+=arr[ind];
if (max<maxsum)
max=maxsum;
if (maxsum<0)
maxsum=0;
printf(""%d"",max);
return 0;
}"
______________________________________________________________________________
Anagram
Given two strings as a input, Find whether the strings are Anagram are Not a Anagram.
"#include<stdio.h>
#include<stdlib.h>
#include<string.h>
return (*a)-(*b);
int main()
char str1[1000];
char str2[1000];
scanf(""%s%s"",str1,str2);
qsort(str1,strlen(str1),sizeof(char),cchar);
qsort(str2,strlen(str2),sizeof(char),cchar);
printf(""%s"",(strcmp(str1,str2))?""Not a Anagram"":""Anagram"");
}"
__________________________________________________________________________________
_____
Factorial
Given the integer value as a input. Return the factorial value of a given number as a string.
1<= N <=100
"#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char* factorial(int n)
char *result=(char*)calloc(10000,sizeof(char));
result[0] = '1';
int size = 1;
for(int i=2;i<=n;i++)
int carry = 0;
while (carry)
carry /= 10;
size++;
return result;
int main()
int num;
scanf(""%d"",&num);
char *result=factorial(num);
for(int i=strlen(result)-1;i>=0;printf(""%c"",result[i--]));
return 0;
}"
__________________________________________________________________________________
_______________________
"Given the group of characters as a input. Your work is to find the character which is having highest
frequency based on occurance.
Note:- if more then one characters having the same maximum frequency display 0 as output;"
"#include<stdio.h>
int max=0,maxcount=0;
char ref;
for(int ch=0;str[ch];ch++)
int count=1;
for(int ind=ch+1;str[ind];ind++)
if(str[ch]==str[ind])
count++;
if(count>max) max=count,ref=str[ch],maxcount=0;
return (maxcount==1)?ref:'0';
int main()
char str[10000];
scanf(""%[^\n]"",str);
printf(""%c"",check(str));
return 0;
}"
__________________________________________________________________________________
_______________________________
1) Ravi wants to install an elevator at his home for domestic uses. He has everything except
equal weight boxes to balance it on the either side ( two weights) of the elevator .help ravi installing
the elevator with the multiple weight boxes he has by returning the final weight which can be
formed by merging possible unequal weights . the only condition here is the final weight boxes
should be of equal weights . return the maximum possible final weight so that elevator can be more
balanced
Sample input:-
123
Output :-
Explanation :-
Here to balance the weights the only possible way is to merge the weights 1
__________________________________________________________________________________
__________________________________
while playing with the number system , nobita found some interesting numbers and named them
nobita’s numbers . A number is considered to be nobita’s number if all adjacent digits of the number
have an absolute difference of 1.
Write a program to find sum of all of nobita’s numbers within a given range [X,Y]
Read the input from STDIN and print the output to STDOUT .
Do not write arbitrary strings anywhere in the program , as these contribute to the standard output
and test cases will fail
Constraint
10<=X<=Y<=107
Input format
Output format
The output contains the sum of all of nobita’s numbers in the given range
Sample input 1
123 456
Sample output
4119
Explanation
Thus all adjacent digits of the number have an absolute difference of 1 andhence this is a nobits’s
number
__________________________________________________________________________________
________________________________________
Write a program to take two integers & n as input and find the number of possible sequences of
length n such that each of the next element is greater than or equal to twice of the previous element
but less than or equal to m.
Example 1:
Input:
10
Output: 4
Explanation there should be no elements and value of last element should be at- most m.
Example 2:
Input:
Output: 6
__________________________________________________________________________________
___________________________________________
Product of numbers
The function accepts an integer array ‘arr’ of length ‘n’. Implement the function to modify the given
array such that , value at present in the array,in that array have to return products of all integers
except at index.
Assumption:
Note:
Example:
Input:
2375
Output:
105 70 30 42
Explanation:
arr[0]=arr[1]*arr[2]*arr[3]=3*7*5=105
__________________________________________________________________________________
__________________________________________
Repeating Digits
The function accepts three positive integers ‘a’, ’b’, and ‘c’ as its argument. implement the function
to find the repeating digit in all the three input numbers. if there is no common digit ,then return -1.
Assumption:
Examples :
Input:
A:426
B:486
C:652
Output:
Explanation:
__________________________________________________________________________________
_______________________________________________