Coding Questions for Accenture.

Hi! Welcome to another post by geekstocode! Today we will be going through Coding Questions for Accenture. In this post we have covered all the important coding questions that you will need to crack the Accenture coding round. Hence, going through these questions will help you with your preparations. 

Have a look to TCS NQT Coding Questions, TCS NQT Programming Questions

Also, we have detailed explanation for each question to help you understand better. Additionally, we have also mentioned the test pattern for the coding round for Accenture. Thus, this article could be an all round help for you. 

So, buckle up your coding belts, we are here for a ride!

What is Accenture Hiring Process?

Accenture is one of the world’s largest IT firms. It deals in worldwide management consulting, outsourcing and IT services. Accenture headquarters is located in Dublin, Republic of Ireland. 

Also, the company stepped foot in India in 1987 with its first office in Mumbai. However, It has now set up centers in Delhi and Chennai. 

Additionally, the company partners with clients and helps them to build high performance governments and businesses.

Accenture Selection Process

The job recruitment process is of the same aim as any other company, i.e. to choose potential working persons for a company or organization. 

Thus the Accenture Recruitment process includes a selection stage when they make decisions depending on the viability of a particular candidate’s application. 

It directly affects the overall productivity of an organization. A right selection may increase the overall performance of a company & a wrong one may lead to material and financial loss. A perfect selection process can help to pick the most eligible candidates amongst all applicants. Thus, the Process of selecting candidates focuses on abilities, knowledge, skills, experience and various other related factors.

Accenture Test Pattern

Coming onto its test patter, for 2021 selection process, Accenture will use the CoCubes exam for hiring. 

Note that, Accenture does not use Wheebox and MeritTrac anymore.Because, Accenture has changed its hiring pattern for the year 2021. The company will conduct four Rounds including an interview. In this hiring process one of the prominent ones is the coding round. 

Hence, in the Coding Round, they will test you upon your coding skills in varied coding languages like C, C++, Java, and Python.

The pattern of questions is as follows:

Name of the SectionCoding assessment
Number of Questions2
Total Time Limit45 min
Difficulty LevelHigh
Accenture Coding Round Test Pattern.

Accenture Coding Questions with Explanations.

Question 1:

Implement the following Function 

def differenceofSum(n. m)

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

Sample Input

n:3

m:10

Sample Output

19

Code:

#include<stdio.h>;
int differenceofSum(int n, int m)
{
    int i, sum1 = 0, sum2 = 0;
    for(i=1; i<=m; i++)
    {
        if(i%n==0)
        {
            sum1 = sum1 + i;
        }
        else
        {
            sum2 = sum2 + i;
        }   
    }
    return sum2 - sum1;
}
 
int main()
{
    int n, m;
    int result;
    scanf("%d",&n);
    scanf("%d",&m);
    result = differenceofSum(n, m);
    printf("%d",result);
    return 0;
}

Explanation: 

So, this is a pretty simple question to implement. Thus, lets get started with the problem statement itself. 

If you have read the explanation of the problem statement carefully, you know that the basic thing we are aiming for is the numbers divisible by n and not divisible by n. Then, accordingly we have to find the sum.

Thus, first we start with defining the function that the problem statement has given, i.e the def differenceofSum(n. m) function. Then we declare a counter i and two sum variables and initialize them with 0. 

These variables will contain our sums. After that, we move on to the loop. In the loop, we have started the counter i from 0 and took it to m, incrementing it by 1 for each iteration. 

Next, we have checked for the divisibility. If n % i = 0, i.e if our counter is divisible by n, we add it to sum 1. If not, then we add it to sum2. 

Finally, after the loop completes all its iterations, we subtract sum2 and sum1 to obtain our result. 

Question 2:

Problem statement: 

The binary number system only uses two digits, 0 and 1. Any string that represents a number in the binary number system can be called a binary string. You are required to implement the following function: 

int OperationsBinaryString(char *str);

The function accepts a string ‘str’ as its argument. The string ‘str’ consists of binary digits separated with an alphabet as follows: 

  • ‘A’ denotes AND operation 
  • ‘B’ denotes OR operation 
  • ‘C’ denotes XOR operation 

You are required to calculate the result of the string ‘str’, scanning the string left to right, taking one operation at a time, and return the same. 

Note: 

  • No order of priorities of operations is required. 
  • Length of ‘str’ is odd 
  • If ‘str’ is NULL or None(in case of python), return -1 

Example: 

Input: 

str: ICOCICIAOBI 

Output: 

Explanation: 

The alphabet in ‘str’ when expanded becomes “1 XOR 0 XOR 1 XOR 1 AND 0 OR 1”, the result of the expression becomes 1, hence 1 is returned. 

Code: 

#include<iostream>
using namespace std;
int OperationsBinaryString(char* str)
{
	int len=0;
	int ans= str[0]-'0';
	for(len=0;str[len]!='\0';len++);
	for(int i=1;i<len-1;i+=2)
	{
		int j=i+1;
		if(str[i]=='A')
		{
			ans = ans & (str[j]-'0');
		}
		else if(str[i]=='B')
		{
			ans = ans | (str[j]-'0');
		}
		else if(str[i]=='C')
		{
			ans = ans ^ (str[j]-'0');
		}
	}
	return ans;
}
int main()
{
	char str[100];
	scanf("%s",str);
	cout<<OperationsBinaryString(str);
}

Explanation: 

The above question is nothing but a test of binary operations. Hence, in order to implement this, you have to be thorough with all the binary operations. 

Once you are okay with the binary operations, let us start breaking down the code.

At first we have defined the function as the program has instructed us to do. Then, we have declared a len variable storing the value 0 which we will use for the length of the string. Also, we have declared an ans variable for storing the answer. 

Now, we have started a loop which will start from the initial position in the string and go uptil the end. This is for reading all the characters in the string.

Then, according to the conditions of binary operations we have calculated the ans along with the expressions. 

Finally, when the loop ends, we will have our answer in the ans variable. Thus, we return it to the main function and print our result. 

Question 3:

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

Code: 

#include <stdio.h>;
 
int largeSmallSum(int *array, int n)
{
    int answer, i, j, temp;;
    int even[n], odd[n];
    int evencount = 0, oddcount = 0;
    if(n<=3)
    {
        answer = 0;
    }
    else
    {
        even[0] = array[0];
        evencount = 1;
        for(i=1; i<n; i++)                   //creating two array even and odd
        {
            if(i%2==0)
            {
                even[evencount] = array[i];
                evencount++;
            }
            else
            {
                odd[oddcount] = array[i];
                oddcount++;
            }  
        }
        for(i=0; i<evencount; i++)           //sorting of even array
        {
            for(j=i+1; j<evencount; j++)
            {
                if(even[i]>even[j])
                {
                    temp = even[i];
                    even[i] = even[j];
                    even[j] = temp;
                }
            }
        }
        for(i=0; i<oddcount; i++)            //sorting of odd array
        {
            for(j=i+1; j<oddcount; j++)
            {
                if(odd[i]>odd[j])
                {
                    temp = odd[i];
                    odd[i] = odd[j];
                    odd[j] = temp;
                }
            }
        }
        answer = even[evencount-2] + odd[1];
    }
    return answer;
}
 
int main()
{
    int n, result, i;
    scanf("%d",&n);
    int array[n];
    for(i=0; i<n; i++)
    {
        scanf("%d",&array[i]);
    }
    result = largeSmallSum(array, n);
    printf("%d",result);
    return 0;
}

Explanation: 

The above problem deals with the positioning in the array. Thus, we need to traverse it carefully. 

First, we have defined the function just as the problem statement has stated. Then, we have declared the required counter variables and even and odd arrays which will store our required number which we would operate on later. 

Then, in the first if block, we have checked if n is 3. Because if that is the case, the answer will be 0. Else, we proceed to further calculations. 

After that using for loop and if block, we have created an array even[] with all the even position numbers. Also, using the else block, we have created an array odd[] with all the odd position. 

Then, we have used for loop in both even[] and odd[] arrays to traverse through them and sort both of them to find the second largest even position number and second smallest odd position number.

Finally, we have calculated our required result in answer variable and returned it.

Lastly, we have defined the main function where we have displayed our answer by calling the largeSmallSum(int *array, int n) function. 

Question 4:

Problem statement: 

You are given a function, void MaxInArray(int arr[], int length); The function accepts an integer array ‘arr’ of size ‘length’ as its argument. Implement the function to find the maximum element of the array and print the maximum element and its index to the standard output 

(STDOUT). The maximum element and its index should be printed in separate lines.

Note: 

  • Array index starts with 0 
  • Maximum element and its index should be separated by a line in the output 
  • Assume there is only 1 maximum element in the array 
  • Print exactly what is asked, do not print any additional greeting messages 

Example: 

Input: 

23 45 82 27 66 12 78 13 71 86 

Output: 

86 

Explanation: 

86 is the maximum element of the array at index 9. 

Code: 

#include<iostream>
using namespace std;
void MaxInArray(int arr[],int length)
{
	int max=-999999,maxIdx=-1;
	for(int i=0;i<length;i++)
	{
		if(arr[i]>max)
		{
			max=arr[i];
			maxIdx=i;
		}
	}
	cout<<max<<endl<<maxIdx;
}
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	MaxInArray(a,n);
}

Explanation: 

This is a very simple problem statement or coding question which tests your basic knowledge about arrays. Here, you just need to traverse the array and find the index of largest number. Let us get into the code.

First, just like the problem statement we have defined the function MaxInArray(int arr[], int length) which takes two parameters.

Next we have initialized max variable with lowest integer that the code allows, and maxIdx as the lowest index, i.e. -1. After that, we have used a for loop to traverse the array. Then using if block we have compared the array element with max to find the largest element.

Also, we have stored the index of the maximum element in the variable maxIdx. Finally, when the iterations of the loop is over, we have printed our required results.

In the main function, we have taken user input for the array and passed it to the MaxInArray() one by one as elements.

Question 5:

Problem statement

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, def 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.

Example:

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.

Code: 

#include<iostream>
using namespace std;
int FindAutoCount(char *n)
{
	int valueCount[10]={0},freq[10]={0};
	int count=0;
	for(int i=0;n[i]!='\0';i++)
		valueCount[n[i]-'0']++;
	for(int i=0;i<10;i++)
		if(valueCount[i]>0)
			count++;
	for(int i=0;n[i]!='\0';i++)
		valueCount[i]=valueCount[i]-(n[i]-'0');
	for(int i=0;i<10;i++)
	{
		if(valueCount[i]!=0)
			return 0;
	}
	return count;
}
int main()
{
	char str[11];
	scanf("%s",str);
	cout<<FindAutoCount(str);
}

Explanation: 

In this problem, the question clearly mentions what is an autobiographical number. Thus, we just need to follow how to find if the number is autobiographical or not and we will get our result.

First, we have defined the function that the problem statement has specified.

Then, we have traversed through the number user has entered as string. Because the program takes string input.

Hence, we have used three for loops to calculate the required numbers in the number. That is, the number of zeroes, ones, etc. And, we have stored them into valueCount[i] array.

Now, if this valueCount[] array has some element as 0, the number will not be an autobiographical number. Also, if it is not true, we have our autobiographical number.

Conclusion:

Thus, we are at the end of our coding questions for Accenture. In this post you have gone through the important questions for the Accenture coding round. There are many other coding questions too. Make sure to go through them. But, remember every question takes a test on your basic coding skills and concepts. So, being thorough with all the beginner level coding concepts is important.

Hope this article and questions helped you. We will see you next time with newer posts like this.

Stay tuned and happy coding!

Leave a Comment

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