Accenture Coding Questions and Answers

Accenture Coding Questions and Answers

Accenture Coding Round :

In Accenture, there will be two coding questions that you need to solve within 45 minutes. In the Accenture Coding Round, you can write code using the following preferred languages:

  • C
  • C++
  • Java
  • Python
  • .NET

The difficulty level of the questions is high. You need to practice extensively to achieve a good score in Accenture coding questions. [Accenture Coding Questions and Answers]

Accenture Coding Questions and Answers

Accenture Coding Questions and Answers 2025

Question 1 : Rat Count House

Problem Statement:  Given the number of rats r, the amount of food each rat consumes unit, and an array arr representing the amount of food in each house, determine the minimum number of houses required to feed all the rats.

Input Format

  • The first line contains an integer r (number of rats).
  • The second line contains an integer unit (amount of food per rat).
  • The third line contains an integer n (size of the array).
  • The fourth line contains n space-separated integers representing the array arr.
Output

  • An integer representing the minimum number of houses required to feed all the rats. If it is not possible to feed all the rats, output 0.
Example

Input:

5
3
4
2 2 2 2

Output: 0

 
Explanation : 
  • Total food required = 5 * 3 = 15.
  • Total food available = 2 + 2 + 2 + 2 = 8 (insufficient).
  • Therefore, the output is 0.

[Accenture Coding Questions and Answers]

Solution :

Question 2 : Counting 1s in Binary: Alex and Carrie's Game

Problem Statement: Alex and Carrie are playing a binary game. In this game, Alex gives Carrie a number, and Carrie’s task is to start from 0 and incrementally go up to the given number N.

For each number in this range, Carrie must count the number of 1s in its binary representation.

Question Constraints: 1 <= N<= 5*10^6

Input Format

  • The input consists of a single character representing the number N.
Output

  • Print a vector where each element is the count of 1s in the binary representation of numbers from 0 up to N.

[Accenture Coding Questions and Answers]

Solution :

Question 3 : Difference of Sums: Divisible vs. Non-Divisible Numbers

Problem Statement:  The function def differenceofSum(n. m) 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
Sample Input : 
n:3
m:10
Sample Output : 
19

[Accenture Coding Questions and Answers]

Solution :

Question 4 : Second Largest and Second Smallest: The Position-Based Sum

Problem Statement: You are required to implement the following Function def LargeSmallSum(arr). 

The function accepts an integers arr of size ’length’ as its arguments you are required to return the sum of second largest 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 a seven

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:

7

Explanation

  • Second largest among even position elements(1 3 5) is 3
  • Second largest among odd position element is 4
  • Thus output is 3+4 = 7
Sample Input:

arr:1 8 0 2 3 5 6

Sample Output: 8

[Accenture Coding Questions and Answers]

Solution :

Question 5 : Find the Smallest Positive Integer Missing from Array

Problem Statement: Given an unsorted array of integers, find the smallest positive integer that does not appear in the array.

[Accenture Coding Questions and Answers]

Solution :

Question 6 : Longest Substring Without Repeating Characters

Problem Statement:

Given a string s, find the length of the longest substring that does not contain any repeating characters.

Input Format:

  • A single string s consisting of lowercase and uppercase letters, digits, and symbols.

Output Format:

  • An integer representing the length of the longest substring without repeating characters.

Example Input and Output:

Input: abcabcbb

Output: 3

Explanation:
The longest substring without repeating characters is "abc", which has length 3.

 

[Accenture Coding Questions and Answers]

Solution :

Question 7 : Shorten Word with Middle Character Count

Problem Statement:

Given a word, return a string that consists of:

  • The first letter.
  • The count of middle characters.
  • The last letter.

If the word length is 2 or less, return the word as it is.

Input Format:

    A single string s (length ≥ 1).

Output Format:

   A shortened string in the specified format.

Example Input and Output:

Input: examination

Output: e9n

Explanation:

  • First letter: e
  • Middle characters count: 9 (“xaminatio”)
  • Last letter: n
  • Final output: "e9n"

[Accenture Coding Questions and Answers]

Solution :

Question 8 : Parking Lot Problem

Problem Statement:

You are given a character array arr of size n, where:

  • 'S' represents an empty parking slot.
  • 'X' represents an occupied slot.

You need to return the maximum number of cars that can be parked in the parking lot, assuming that:

  • A car can only park in consecutive empty slots ('S').
  • Two cars cannot occupy the same slot.

Input Format:

  • An integer n representing the number of slots.
  • A string of length n consisting of 'S' (empty) and 'X' (occupied).

Output Format:

  •   An integer representing the maximum number of cars that can be parked.
Example Input and Output:

Input:  n= 16      arr= XXXSXXSXXSSXXSXX

Output: 7

Explanation:

  • The empty slots (S) are at positions: [3, 6, 9, 10, 13].
  • Consecutive empty slots are SS at indices [9, 10], so 2 cars can be parked there.
  • Single empty slots can hold 1 car each.
  • Total cars that can be parked = 7.

[Accenture Coding Questions and Answers]

Solution :

Question 9 : Calculate Prime Sum

Problem Statement:    Int CalculatePrimeSum(int m, int n);

Calculate and return the sum of prime numbers between ‘m’ and ‘n’ (inclusive).

Note: 0 < m <= n

Input Format:

  • Two integers m and n such that 0 < m <= n.

Output Format:

  • A single integer representing the sum of all prime numbers in the given range.
Example Input and Output:

Input:   m= 10  n= 50

Output: 158

Explanation:

  • The prime numbers between 10 and 50 are:
    11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47
    Sum: 11 + 13 + 17 + 19 + 23 + 29 + 31 + 37 + 41 + 43 + 47 = 158

[Accenture Coding Questions and Answers]

Solution :
WhatsApp Group Join Now
Telegram Group Join Now
Instagram Group Join Now
Linkedin Page Join Now

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top