0% found this document useful (0 votes)
7 views11 pages

Accenture Coding Questions

The document describes multiple programming problems, including calculating the minimum number of houses needed to feed rats, validating passwords, identifying autobiographical numbers, and finding elements with specific absolute differences. Each problem includes a description, input examples, and expected outputs. The problems cover various algorithmic challenges suitable for coding practice.

Uploaded by

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

Accenture Coding Questions

The document describes multiple programming problems, including calculating the minimum number of houses needed to feed rats, validating passwords, identifying autobiographical numbers, and finding elements with specific absolute differences. Each problem includes a description, input examples, and expected outputs. The problems cover various algorithmic challenges suitable for coding practice.

Uploaded by

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

Finding Minimum Number of Houses to Feed All Rats

Problem Description :
The function accepts two positive integers ‘r’ and ‘unit’ and a positive integer array ‘arr’ of size ‘n’ as its
argument ‘r’ represents the number of rats present in an area, ‘unit’ is the amount of food each rat
consumes and each ith element of array ‘arr’ represents the amount of food present in ‘i+1’ house number,
where 0 <= i
Note:
Return -1 if the array is null
Return 0 if the total amount of food from all houses is not sufficient for all the rats.
Computed values lie within the integer range.
Example: Explanation:
Input: Total amount of food required for all rats = r * unit
= 7 * 2 = 14.
r: 7
unit: 2 The amount of food in 1st houses = 2+8+3+5 = 18.
n: 8 Since, amount of food in 1st 4 houses is sufficient for
all the rats. Thus, output is 4.
arr: 2 8 3 5 7 4 1 2
Output:
4
Password checker
The function accepts string str of size n as an argument. Implement the function which returns 1 if
given string str is valid password else 0.
str is a valid password if it satisfies the below conditions.
– At least 4 characters
– At least one numeric digit
– At Least one Capital Letter
– Must not have space or slash (/)
– Starting character must not be a number
Assumption:
Input string will not be empty.
Example:
Input 1:
aA1_67
Input 2:
a987 abC012
Autobiographical Number
An Autobiographical Number is a number N such that the first digit of N represents the count of how
many zeroes are there in N, the second digit represents the count of how many ones are there in N
and so on.
You are given a function, FindAutoCount(n):
The function accepts string “n” which is a number and checks whether the number is an
autobiographical number or not. If it is, an integer is returned, i.e. the count of distinct numbers in
‘n’. If not, it returns 0.
Assumption:
The input string will not be longer than 10 characters.
Input string will consist of numeric characters.
Note:
If string is None return 0.
Autobiographical Number
Input:
n: “1210”
Output:
3

Explanation:
0th position in the input contains the number of 0 present in input, i.e. 1, in 1st position the count of
number of 1s in input i.e. 2, in 2nd position the count of 2s in input i.e. 1, and in 3rd position the
count of 3s i.e. 0, so the number is an autobiographical number.

Now unique numbers in the input are 0, 1, 2, so the count of unique numbers is 3. So 3 is returned.
Finding Elements with Absolute Difference within a Given Range

The function accepts an integer array ‘arr’, its length and two integer variables ‘num’ and ‘diff’.
Implement this function to find and return the number of elements of ‘arr’ having an absolute difference
of less than or equal to ‘diff’ with ‘num’.
Note: In case there is no element in ‘arr’ whose absolute difference with ‘num’ is less than or equal to
‘diff’, return -1.
Example:
Input:
arr: 12 3 14 56 77 13
num: 13
diff: 2
Output:
3
Explanation:
Elements of ‘arr’ having absolute difference of less than or equal to ‘diff’ i.e. 2 with ‘num’ i.e. 13 are
12, 13 and 14.
Sum and Difference of Numbers Based on Divisibility
The function accepts two integers n, m as arguments Find the sum of all numbers in range from 1 to
m(both inclusive) that are not divisible by n. Return difference between sum of integers not divisible
by n with sum of numbers divisible by n.
Assumption:
n>0 and m>0
Sum lies between integral range
Example
Input
n:4
m:20
Output
90

Explanation
Sum of numbers divisible by 4 are 4 + 8 + 12 + 16 + 20 = 60
Sum of numbers not divisible by 4 are 1 +2 + 3 + 5 + 6 + 7 + 9 + 10 + 11 + 13 + 14 + 15 + 17 + 18 + 19 = 150
Difference 150 – 60 = 90
Sum of Second Largest from Even and Second Smallest from Odd Positions
The function accepts an integers arr of size ’length’ as its arguments you are required to return the sum of
second largest element from the even positions and second smallest from the odd position of given ‘arr’
Assumption:
All array elements are unique
Treat the 0th position as even
NOTE
Return 0 if array is empty
Return 0, if array length is 3 or less than 3
Example
Input
arr:3 2 1 7 5 4
Output Explanation
7 Second largest among even position elements(1 3 5) is 3
Second smallest among odd position element is 4
Thus output is 3+4 = 7
Find the Least Sum Pair
The function accepts an integers sum and an integer array arr of size n. Implement the function to
find the pair, (arr[j], arr[k]) where j!=k, Such that arr[j] and arr[k] are the least two elements of array
(arr[j] + arr[k] <= sum) and return the product of element of this pair
NOTE
Return -1 if array is empty or if n<2
Return 0, if no such pairs found
All computed values lie within integer range
Example
Input
sum:9
Explanation
size of Arr = 7
Arr:5 2 4 3 9 7 1 Pair of least two element is (2, 1) 2 + 1 = 3 < 9, Product of (2, 1) 2*1 =
2. Thus, output is 2
Output
2
Move Hyphens to the Front of a String
The function accepts a string “str” of length ‘n’, that contains alphabets and
hyphens (-). Implement the function to move all hyphens(-) in the string to the
front of the given string.
NOTE:- Return null if str is null.
Example :-
Input:
str.Move-Hyphens-to-Front
Output:
—MoveHyphenstoFront
Explanation:-
The string “Move-Hyphens -to-front” has 3 hyphens (-), which are moved to the
front of the string, this output is “— MoveHyphen”
Sample Input
Str: String-Compare
Sample Output-
-StringCompare
Divide Matrix into Even and Odd Matrices and Sort
You are required to input the size of the matrix then the elements of matrix, then you have to divide the main
matrix in two sub matrices (even and odd) in such a way that element at 0 index will be considered as even and
element at 1st index will be considered as odd and so on. then you have sort the even and odd matrices in
ascending order
Example
enter the size of array : 5
enter element at 0 index : 3
enter element at 1 index : 4
enter element at 2 index : 1
enter element at 3 index : 7
enter element at 4 index : 9
Sorted even array : 1 3 9
Sorted odd array : 4 7
Calculate Number of Carries

A carry is a digit that is transferred to left if sum of digits exceeds 9 while adding two numbers from
right-to-left one digit at a time
The functions accepts two numbers ‘num1’ and ‘num2’ as its arguments. You are required to
calculate and return the total number of carries generated while adding digits of two numbers
‘num1’ and ‘ num2’.
Assumption: num1, num2>=0
Example:
Input
Sample Input
Num 1: 451 Num 1: 23
Num 2: 349 Num 2: 563
Sample Output
Output 0
2
Explanation:
Adding ‘num 1’ and ‘num 2’ right-to-left results in 2 carries since ( 1+9) is 10. 1 is carried and
(5+4=1) is 10, again 1 is carried. Hence 2 is returned.

You might also like