Accenture (OA Round 2 - Coding Test)
Accenture ASE & AASE – Online Assessment (Round 2: Coding Test)
Number of Questions: 2 coding questions
Duration: 45 minutes
1. Rats and Food Requirement
Problem Statement:
The function accepts two positive integers r and unit, and a positive integer array arr of size n.
r→ Number of rats in the areaunit→ Amount of food each rat consumesEach element of
arr→ Food present in house(i+1)
Conditions:
Return
-1if the array isnullReturn
0if the total amount of food in all houses is insufficient for all ratsOtherwise, return the minimum number of houses required to feed all rats
Example:
Input:
r = 7
unit = 2
n = 8
arr = [2, 8, 3, 5, 7, 4, 1, 2]
Output: 4
Explanation:
Food required = r * unit = 7 * 2 = 14
Food in first 4 houses = 2+8+3+5 = 18 ≥ 14 → Answer = 4
2. Operations on Binary String
Problem Statement:
You are given a binary string that contains 0 and 1, separated by alphabets representing bitwise operations:
A→ ANDB→ ORC→ XOR
Implement:
int OperationsBinaryString(char* str);
Conditions:
Scan the string left-to-right, performing operations one by one
No precedence required
Return
-1if string isnullString length will always be odd
Example:
Input: "1C0C1C1A0B1"
Output: 1
Explanation:
Expanded: 1 XOR 0 XOR 1 XOR 1 AND 0 OR 1 → Result = 1
3. Password Validation
Function:
int CheckPassword(char str[], int n);
A valid password must satisfy:
At least 4 characters
At least one numeric digit
At least one uppercase letter
Must not contain space or slash
/Must not start with a number
Assumption: Input string is not empty.
Example:
Input: "aA1_67"
Output: 1
4. Count Elements Within Difference
Function:
int findCount(int arr[], int length, int num, int diff);
Requirements:
Return count of elements
xinarrsuch that|x - num| ≤ diffIf none found, return
-1
Example:
Input:
arr = [12, 3, 14, 56, 77, 13]
num = 13
diff = 2
Output: 3
Explanation: Elements: {12, 13, 14}
5. Difference of Sums
Function:
def differenceofSum(n, m)
Requirements:
Compute sum of numbers from
1 to mthat are divisible bynCompute sum of numbers from
1 to mnot divisible bynReturn difference =
(sum of non-divisible) – (sum of divisible)
Example:
Input: n = 4, m = 20
Output: 90
Explanation:
Divisible sum = 4+8+12+16+20 = 60
Non-divisible sum = 150
Difference = 150 - 60 = 90
6. Large Small Sum
Function:
def LargeSmallSum(arr)
Requirements:
Return
(second largest element from even positions) + (second smallest element from odd positions)0th index is treated as even
Return
0if array is empty or length ≤ 3
Example:
Input: [3, 2, 1, 7, 5, 4]
Output: 7
Explanation:
Even positions → [3,1,5] → second largest = 3
Odd positions → [2,7,4] → second smallest = 4
Answer = 3+4 = 7
7. Product of Smallest Pair
Function:
def ProductSmallestPair(sum, arr)
Requirements:
Find the two smallest elements
(x,y)inarrsuch thatx+y ≤ sumReturn product
x*yIf no such pair → return
0If array empty or size < 2 → return
-1
Example:
Input:
sum = 9
arr = [5, 2, 4, 3, 9, 7, 1]
Output: 2
Explanation: Pair = (1,2) → 1+2=3 ≤ 9 → Product = 2
8. Decimal to N-Base Conversion
Function:
char* DectoNBase(int n, int num);
Requirements:
Convert
num(decimal) to base-nUse digits
0-9and lettersA-Z
Example:
Input: n = 12, num = 718
Output: "4BA"
9. Move Hyphens to Front
Function:
char* MoveHyphen(char str[], int n);
Requirements:
Move all hyphens
'-'to the front of stringReturn
nullif input isnull
Example:
Input: "Move-Hyphens-to-Front"
Output: "---MoveHyphenstoFront"
10. Number of Carries
Function:
int NumberOfCarries(int num1, int num2);
Requirements:
Add two numbers digit by digit (right-to-left)
Count number of carries generated
Example:
Input: num1=451, num2=349
Output: 2
11. Replace Characters
Function:
void* ReplaceCharacter(char str[], int n, char ch1, char ch2);
Requirements:
Replace all
ch1withch2and allch2withch1Return
nullif string is nullIf
ch1orch2not present → return unchanged
Example:
Input: str="apples", ch1='a', ch2='p'
Output: "paales"
12. Max Exponents of 2
Function:
int MaxExponents(int a, int b);
Requirements:
Find number between
[a, b]with maximum exponent of 2 in its factorizationIf tie, return smaller number
Example:
Input: a=7, b=12
Output: 8
13. Calculate Sum Divisible by 3 and 5
Function:
int Calculate(int m, int n);
Requirements:
Return sum of numbers divisible by both 3 and 5 in range
[m, n]
Example:
Input: m=12, n=50
Output: 90
Explanation: {15, 30, 45} → sum = 90
