Accenture Previous Year Coding Questions, Get Solved Questions

Accenture Previous Year Coding Questions | Accenture Previous Coding Questions and Answers | Accenture Last Year Coding Questions | Accenture Previous Year Coding Questions Pdf download 

Accenture Previous Year Coding Questions: Some of the previous questions helps to get more marks in your examinations or test. Aspirants focussed to prepare the Previous Year Questions for easy to crack the examinations. In the Company of Accenture is released the hiring every month for various eligible candidates. The candidates who applied the Accenture Hiring, they must attend the selection process. The Selection is based on the coding test, assessment test, technical test etc., Candidates eagerly prepare for the Accenture Coding Test Round. Those who will be selected in the Accenture Coding Test, they will be move on further selection process.

The Accenture Previous Coding Questions is helping to achieve the selection round. Continuous practising of the Accenture Previous Coding Questions and answers, it gives idea and got a repeated asked question. Accenture Previous Year Coding Questions and Answers will be uploaded in the official website. Accenture Previous Coding Questions contains programming wise coding questions like Accenture Java Coding questions & Answers, Accenture Python Coding Questions etc., Candidates clearly solved the Accenture Previous Coding Question and Answers/ Accenture Previous Coding questions etc.,

Accenture Previous Year Coding Questions & Answers 

Q) 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:

Input:

  • r: 7
  • unit: 2
  • n: 8
  • arr: 2 8 3 5 7 4 1 2

Output:

4

Explanation:
Total amount of food required for all rats = r * unit

= 7 * 2 = 14.

The amount of food in 1st houses = 2+8+3+5 = 18. Since, amount of food in 1st 4 houses is sufficient for all the rats. Thus, output is 4.

C++ Program
#include<bits/stdc++.h>
using namespace std;
int calculate (int r, int unit, int arr[], int n)
{
  if (n == 0)
    return -1;
  int totalFoodRequired = r * unit;
  int foodTillNow = 0;
  int house = 0;
  for (house = 0; house < n; ++house)
    {
      foodTillNow += arr[house];
      if (foodTillNow >= totalFoodRequired)
	{
	  break;
	}
    }
  if (totalFoodRequired > foodTillNow)
    return 0;
  return house + 1;
}
int main ()
{
  int r;
  cin >> r;
  int unit;
  cin >> unit;
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i)
    {
      cin >> arr[i];
    }
  cout << calculate (r, unit, arr, n);
  return 0;
}

C Program 

#include <stdio.h>

int calculate (int r, int unit, int arr[], int n)
{
  if (n == 0)
    return -1;
  int totalFoodRequired = r * unit;
  int foodTillNow = 0;
  int house = 0;
  for (house = 0; house < n; ++house)
    {
      foodTillNow += arr[house];
      if (foodTillNow >= totalFoodRequired)
	{
	  break;
	}
    }
  if (totalFoodRequired > foodTillNow)
    return 0;
  return house + 1;
}

int main ()
{
  int r;
  scanf ("%d", &r);
  int unit;
  scanf ("%d", &unit);
  int n;
  scanf ("%d", &n);
  int arr[n];
  for (int i = 0; i < n; ++i)
    {
      scanf ("%d", &arr[i]);
    }
  printf ("%d", calculate (r, unit, arr, n));
  return 0;
}
Python Program
def calculate (r, unit, arr, n):
    if n == 0:
        return -1 
        
    totalFoodRequired = r * unit 
    foodTillNow = 0 
    house = 0 
        
    for house in range (n):
        foodTillNow += arr[house] 
        if foodTillNow>=totalFoodRequired:
            break 
    if totalFoodRequired > foodTillNow:
        return 0
    return house + 1
	  
r = int (input ())
unit = int (input ())
n = int (input ())
  
arr = list (map (int, input ().split ()))
print (calculate (r, unit, arr, n))

Java Program

import java.util.*;
class Main
{
  public static int solve (int r, int unit, int arr[], int n)
  {
    if (arr == null)
      return -1;
    int res = r * unit;
    int sum = 0;
    int count = 0;
    for (int i = 0; i < n; i++)
      {
	sum = sum + arr[i];
	count++;
	if (sum >= res)
	  break;
      }
    if (sum < res)
        return 0;
    return count;
  }
  public static void main (String[]args)
  {
    Scanner sc = new Scanner (System.in);
    int r = sc.nextInt ();
    int unit = sc.nextInt ();
    int n = sc.nextInt ();
    int arr[] = new int[n];

    for (int i = 0; i < n; i++)
      arr[i] = sc.nextInt ();
    System.out.println (solve (r, unit, arr, n));
  }
}

Q) Problem Description :
The Binary number system only uses two digits, 0 and 1 and number system can be called 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 eparated 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 to right taking one opearation 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

Input:
str: 1C0C1C1A0B1

Output:
1

Explanation:
The alphabets in str when expanded becomes “1 XOR 0 XOR 1 XOR 1 AND 0 OR 1”, result of the expression becomes 1, hence 1 is returned.

Sample Input:
0C1A1B1C1C1B0A0

Output:
0

C++ Program 
#include<bits/stdc++.h>
using namespace std;
int OperationsBinaryString (char *str)
{
  if (str == NULL)
    return -1;
  int i = 1;
  int a = *str - '0';
  str++;
  while (*str != '\0')
    {
      char p = *str;
      str++;
      if (p == 'A')
	a &= (*str - '0');
      else if (p == 'B')
	a |= (*str - '0');
      else
	a ^= (*str - '0');
      str++;
    }
  return a;
}
int main ()
{
  string s;
  getline (cin, s);
  int len = s.size ();
  char *str = &s[0];
  cout << OperationsBinaryString (str);
}
C+ Program
#include <stdio.h>
#include <string.h>  

int OperationsBinaryString (char *str)
{
  if (str == NULL)
    return -1;
  int i = 1;
  int a = *str - '0';
  str++;
  while (*str != '\0')
    {
      char p = *str;
      str++;
      if (p == 'A')
	a &= (*str - '0');
      else if (p == 'B')
	a |= (*str - '0');
      else
	a ^= (*str - '0');
      str++;
    }
  return a;
}

int main ()
{
  char str[100];
  fgets (str, sizeof (str), stdin);
  int len = strlen (str);
  if (str[len - 1] == '\n')
    {
      str[len - 1] = '\0';	// Remove the newline character
      len--;			// Decrement the length
    }
  int result = OperationsBinaryString (str);
  printf ("%d\n", result);
  return 0;
}
Python Program
def OperationsBinaryString(str):
    a=int(str[0])
    i=1
    while i< len(str):
        if str[i]=='A':
            a&=int(str[i+1])
        elif str[i]=='B':
            a|=int(str[i+1])
        else:
            a^=int(str[i+1])
        i+=2
    return a
str=input()
print(OperationsBinaryString(str))
Java program
import java.util.*;
class Main
{
  public static int operationsBinaryString (String str)
  {
    if (str == null)
      return -1;
    int res = str.charAt (0) - '0';
    for (int i = 1; i < str.length ();)
      {
	char prev = str.charAt (i);
	  i++;
	if (prev == 'A')
	  res = res & (str.charAt (i) - '0');
	else if (prev == 'B')
	  res = res | (str.charAt (i) - '0');
	else
	    res = res ^ (str.charAt (i) - '0');
	  i++;
      }
    return res;
  }
  public static void main (String[]args)
  {
    Scanner sc = new Scanner (System.in);
    String str = sc.next ();
    System.out.println (operationsBinaryString (str));
  }
}

Q) You are given a function,
int findCount(int arr[], int length, int num, int diff);

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.

C++ Program
#include<bits/stdc++.h>
using namespace std;
int findCount (int n, int arr[], int num, int diff)
{
  int count = 0;
  for (int i = 0; i < n; ++i)
    {
      if (abs (arr[i] - num) <= diff)
	{
	  count++;
	}
    }
  return count > 0 ? count : -1;
}
int main ()
{
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i)
    {
      cin >> arr[i];
    }
  int num;
  cin >> num;
  int diff;
  cin >> diff;
  cout << findCount (n, arr, num, diff);
}
C Program
#include <stdio.h>
#include <stdlib.h>

int findCount (int n, int arr[], int num, int diff)
{
  int count = 0;
  for (int i = 0; i < n; ++i)
    {
      if (abs (arr[i] - num) <= diff)
	{
	  count++;
	}
    }
  return count > 0 ? count : -1;
}

int main ()
{
  int n;
  scanf ("%d", &n);
  int arr[n];
  for (int i = 0; i < n; ++i)
    {
      scanf ("%d", &arr[i]);
    }
  int num;
  scanf ("%d", &num);
  int diff;
  scanf ("%d", &diff);
  printf ("%d\n", findCount (n, arr, num, diff));
  return 0;
}
Python Program 
def findCount(n, arr, num, diff):
    count=0
    for i in range(n):
        if(abs(arr[i]-num)<=diff):
            count+=1
    if count:
        return count
    return 0
n=int(input())
arr=list(map(int,input().split()))
num=int(input())
diff=int(input())
print(findCount(n, arr, num, diff))
Java program 
import java.util.*;
class Main
{
  public static int findCount (int arr[], int length, int num, int diff)
  {
    int count = 0;
    for (int i = 0; i < length; i++)
      {
	if (Math.abs (num - arr[i]) <= diff)
	  count++;
      }
    return count > 0 ? count : -1;
  }
  public static void main (String[]args)
  {
    Scanner sc = new Scanner (System.in);
    int n = sc.nextInt ();
    int arr[] = new int[n];
    for (int i = 0; i < n; i++)
      arr[i] = sc.nextInt ();
    int num = sc.nextInt ();
    int diff = sc.nextInt ();

    System.out.println (findCount (arr, n, num, diff));
  }
}

Q) 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

C++ Program 
#include <iostream>

using namespace std;

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; } } if (sum2 > sum1)
    return sum2 - sum1;
  else
    return sum1 - sum2;
}

int main ()
{
  int n, m;
  int result;
  cin >> n;
  cin >> m;
  result = differenceofSum (n, m);
  cout << result;
  return 0;
}
C program 
#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;
	}
    }
  if (sum2 > sum1)
    return sum2 - sum1;
  else
    return sum1 - sum2;
}
int main ()
{
  int n, m;
  int result;
  scanf ("%d", &n);
  scanf ("%d", &m);
  result = differenceofSum (n, m);
  printf ("%d", result);
  return 0;
}
}
Python Program 
n = int(input())
m = int(input())
sum1 = 0
sum2 = 0
for i in range(1,m+1):
    if i % n == 0:
        sum1+=i
    else:
        sum2+=i
print(abs(sum2-sum1))
Java Program 
import java.util.*;
class Solution 
{
    public static int differenceOfSum (int m, int n) 
    {
        int sum1 = 0, sum2 = 0;
        for (int i = 1; i <= m; i++)
        {
            if (i % n == 0)
                sum1 = sum1 + i;
    	    else    
                sum2 = sum2 + i;
        }
        return Math.abs (sum1 - sum2);
    }
  
    public static void main (String[]args) 
    {
        Scanner sc = new Scanner (System.in);
        int n = sc.nextInt ();
        int m = sc.nextInt ();
        System.out.println (differenceOfSum (m, n));
    } 
}
Q) Implement the following Functiondef ProductSmallestPair(sum, arr)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 pairNOTE

  • 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

size of Arr = 7

Arr:5 2 4 3 9 7 1

Output

2

Explanation

Pair of least two element is (2, 1) 2 + 1 = 3 < 9, Product of (2, 1) 2*1 = 2. Thus, output is 2

Sample Input

sum:4

size of Arr = 6

Arr:9 8 3 -7 3 9

Sample Output

-21

C program
#include <iostream>
#include <algorithm>

int productSmallestPair (int *array, int n, int sum)
{
  int answer, temp, i, j, check;
  if (n < 2)
    {
      answer = -1;
    }
  else
    {
      for (i = 0; i < n; i++)
	{			// sorting of array
	  for (j = i + 1; j < n; j++)
	    {
	      if (array[i] > array[j])
		{
		  temp = array[i];
		  array[i] = array[j];
		  array[j] = temp;
		}
	    }
	}
      check = array[0] + array[1];
      if (check <= sum)
	{
	  answer = array[0] * array[1];
	}
      else
	{
	  answer = 0;
	}
    }
  return answer;
}

int main ()
{
  int n, sum, result, i;
  std::cin >> sum;
  std::cin >> n;
  int *array = new int[n];
  for (i = 0; i < n; i++)
    {
      std::cin >> array[i];
    }
  result = productSmallestPair (array, n, sum);
  std::cout << result;
  delete[]array;
  return 0;
}
C Program 
#include<stdio.h>
int productSmallestPair (int *array, int n, int sum)
{
  int answer, temp, i, j, check;
  if (n < 2)
    {
      answer = -1;
    }
  else
    {
      for (i = 0; i < n; i++)	//sorting of array
	{
	  for (j = i + 1; j < n; j++)
	    {
	      if (array[i] > array[j])
		{
		  temp = array[i];
		  array[i] = array[j];
		  array[j] = temp;
		}
	    }
	}
      check = array[0] + array[1];
      if (check <= sum)
	{
	  answer = array[0] * array[1];
	}
      else
	{
	  answer = 0;
	}
    }
  return answer;
}
int main ()
{
  int n, sum, result, i;
  scanf ("%d", &sum);
  scanf ("%d", &n);
  int array[n];
  for (i = 0; i < n; i++)
    {
      scanf ("%d", &array[i]);
    }
  result = productSmallestPair (array, n, sum);
  printf ("%d", result);
  return 0;
}
Java Program 
import java.util.*;
class Main 
{
    public static int productSmallestPair (int arr[], int n, int sum) 
    {
        if (n <2)
            return -1;
        int ans, temp, check;
        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)
    	    {
                if (arr[i] > arr[j])
    	        {
                    temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        check = arr[0] + arr[1];
if (check <= sum)
return arr[0] * arr[1];
else
return 0;
}

public static void main (String[]args)
{
Scanner sc = new Scanner (System.in);
int sum = sc.nextInt ();
int n = sc.nextInt ();
int arr[] = new int[n];

for (int i = 0; i < n; i++)
arr[i] = sc.nextInt ();
System.out.println (productSmallestPair (arr, n, sum));
}
}
Python Program 
n = int(input())
sum1 = int(input())
arr = list(map(int, input().split()))
if n < 2:
    print('-1')
arr = sorted(arr)
for i in range(n-1):
    if arr[i] + arr[i+1] < sum1:
        print(arr[i] * arr[i+1])
        break
else:
    print('0')
Input:
6
4
9 8 3 -7 3 9
Output:
-21
JOB ALERT ON INSTAGRAM FOLLOW NOW>>
JOB ALERT ON YOUR EMAIL DAILY SUBSCRIBE NOW>>

Here candidates got an Accenture Previous Coding questions with solutions/ Accenture Coding Questions 2024 etc., Aspirants or Examiners kindly check the dailyrecruitment.in site for more informative updates.

 

Govt Jobs by Qualifications

Education & Vacancies Salary Apply Link
10th Pass Govt Jobs - 5,000 Vacancies Rs. 5,200 - 63,200 Apply Now
12th Pass Govt Jobs - 18,000+ Vacancies Rs. 5,200 - 92,300 Apply Now
ITI Pass Jobs - 3,500 Vacancies Rs. 5,200 - 35,000 Apply Now
Any Graduate Jobs - 19,100 Vacancies Rs. 5,200 - 92,300 Apply Now
Central Govt Jobs Rs. 5,200 - 17,000 Apply Now
Bank Jobs - 1,000 Vacancies Rs. 5,200 - 29,200 Apply Now
Diploma Jobs - 9,300 Vacancies Rs. 5,200 - 35,000 Apply Now
BTech/BE Jobs - 18,000 Vacancies Rs. 15,000 - 1,00,000 Apply Now
Data Entry Jobs - 1,300 Vacancies Rs. 5,200 - 29,200 Apply Now
Private Jobs Rs. 10,000 - 67,700 Apply Now