Created
Oct 2, 2025
Last Modified
6 months ago

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 area

  • unit → Amount of food each rat consumes

  • Each element of arr → Food present in house (i+1)

Conditions:

  • Return -1 if the array is null

  • Return 0 if the total amount of food in all houses is insufficient for all rats

  • Otherwise, return the minimum number of houses required to feed all rats

Example:

text
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 → AND

  • B → OR

  • C → XOR

Implement:

text
int OperationsBinaryString(char* str);

Conditions:

  • Scan the string left-to-right, performing operations one by one

  • No precedence required

  • Return -1 if string is null

  • String length will always be odd

Example:

text
Input: "1C0C1C1A0B1"
Output: 1

Explanation:
Expanded: 1 XOR 0 XOR 1 XOR 1 AND 0 OR 1 → Result = 1


3. Password Validation

Function:

text
int CheckPassword(char str[], int n);

A valid password must satisfy:

  1. At least 4 characters

  2. At least one numeric digit

  3. At least one uppercase letter

  4. Must not contain space or slash /

  5. Must not start with a number

Assumption: Input string is not empty.

Example:

text
Input: "aA1_67"
Output: 1

4. Count Elements Within Difference

Function:

text
int findCount(int arr[], int length, int num, int diff);

Requirements:

  • Return count of elements x in arr such that |x - num| ≤ diff

  • If none found, return -1

Example:

text
Input:
arr = [12, 3, 14, 56, 77, 13]
num = 13
diff = 2

Output: 3

Explanation: Elements: {12, 13, 14}


5. Difference of Sums

Function:

text
def differenceofSum(n, m)

Requirements:

  • Compute sum of numbers from 1 to m that are divisible by n

  • Compute sum of numbers from 1 to m not divisible by n

  • Return difference = (sum of non-divisible) – (sum of divisible)

Example:

text
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:

text
def LargeSmallSum(arr)

Requirements:

  • Return (second largest element from even positions) + (second smallest element from odd positions)

  • 0th index is treated as even

  • Return 0 if array is empty or length ≤ 3

Example:

text
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:

text
def ProductSmallestPair(sum, arr)

Requirements:

  • Find the two smallest elements (x,y) in arr such that x+y ≤ sum

  • Return product x*y

  • If no such pair → return 0

  • If array empty or size < 2 → return -1

Example:

text
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:

text
char* DectoNBase(int n, int num);

Requirements:

  • Convert num (decimal) to base-n

  • Use digits 0-9 and letters A-Z

Example:

text
Input: n = 12, num = 718
Output: "4BA"

9. Move Hyphens to Front

Function:

text
char* MoveHyphen(char str[], int n);

Requirements:

  • Move all hyphens '-' to the front of string

  • Return null if input is null

Example:

text
Input: "Move-Hyphens-to-Front"
Output: "---MoveHyphenstoFront"

10. Number of Carries

Function:

text
int NumberOfCarries(int num1, int num2);

Requirements:

  • Add two numbers digit by digit (right-to-left)

  • Count number of carries generated

Example:

text
Input: num1=451, num2=349
Output: 2

11. Replace Characters

Function:

text
void* ReplaceCharacter(char str[], int n, char ch1, char ch2);

Requirements:

  • Replace all ch1 with ch2 and all ch2 with ch1

  • Return null if string is null

  • If ch1 or ch2 not present → return unchanged

Example:

text
Input: str="apples", ch1='a', ch2='p'
Output: "paales"

12. Max Exponents of 2

Function:

text
int MaxExponents(int a, int b);

Requirements:

  • Find number between [a, b] with maximum exponent of 2 in its factorization

  • If tie, return smaller number

Example:

text
Input: a=7, b=12
Output: 8

13. Calculate Sum Divisible by 3 and 5

Function:

text
int Calculate(int m, int n);

Requirements:

  • Return sum of numbers divisible by both 3 and 5 in range [m, n]

Example:

text
Input: m=12, n=50
Output: 90

Explanation: {15, 30, 45} → sum = 90