75 Accenture
75 Accenture
75 Accenture
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:
Input:
r: 7
unit: 2
n: 8
arr: 2 8 3 5 7 4 1 2
Output:
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.
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:
The function accepts a string str as its argument. The string str consists of binary digits eparated with an
alphabet as follows:
Note:
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
– At least 4 characters
– At least one numeric digit
– At Least one Capital Letter
– Must not have space or slash (/)
– Starting character must not be a number
Assumption:
Input string will not be empty.
Example:
Input 1:
aA1_67
Input 2:
a987 abC012
Output 1:
1
Output 2:
0
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.
Question 5 :
(Asked in Accenture OnCampus 11 Aug 2022, Slot 2)
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:
Input
n:4
m:20
Output
90
Explanation
int main ()
{
int n, m;
int result;
cin >> n;
cin >> m;
result = differenceofSum (n, m);
cout << result;
return 0;
}
Question:6
(Asked in Accenture OnCampus 11 Aug 2022, Slot 3)
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 element from the even positions and second smallest from the odd position of given ‘arr’
Assumption:
Input
arr:3 2 1 7 5 4
Output
Explanation
arr:1 8 0 2 3 5 6
Sample Output
if (length <= 3)
{
return 0;
}
int main ()
{
vector < int >arr = { 3, 2, 1, 7, 5, 4 };
return 0;
}
Question:7
(Asked in Accenture OnCampus 12 Aug 2022, Slot 1)
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 pair
NOTE
Input
sum:9
size of Arr = 7
Arr:5 2 4 3 9 7 1
Output
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
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;
}
Accenture coding questions
Question:8
(Asked in Accenture OnCampus 12 Aug 2022, Slot 2)
N-base notation is a system for writing numbers that uses only n different symbols, This symbols are the
first n symbols from the given notation list(Including the symbol for o) Decimal to n base notation are (0:0,
1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:A,11:B and so on upto 35:Z)
The function accept positive integer n and num Implement the function to calculate the n-base equivalent
of num and return the same as a string
Steps:
Divide the decimal number by n,Treat the division as the integer division
Write the the remainder (in n-base notation)
Divide the quotient again by n, Treat the division as integer division
Repeat step 2 and 3 until the quotient is 0
The n-base value is the sequence of the remainders from last to first
Assumption:
1 < n < = 36
Example
Input
n: 12
num: 718
Output
4BA
Explanation
num Divisor quotient remainder
718 12 59 10(A)
59 12 4 11(B)
4 12 0 4(4)
Sample Input
n: 21
num: 5678
Sample Output
CI8
Question:9
(Asked in Accenture Offcampus 1 Aug 2021, Slot 1)
The function accepts a string “str” of length ‘n’, that contains alphabets and hyphens (-). Implement the
function to move all hyphens(-) in the string to the front of the given string.
Example :-
Input:
str.Move-Hyphens-to-Front
Output:
—MoveHyphenstoFront
Explanation:-
The string “Move-Hyphens -to-front” has 3 hyphens (-), which are moved to the front of the string, this
output is “— MoveHyphen”
Sample Input
Str: String-Compare
Sample Output-
-StringCompare
C++ C Java Python
Run
#include<bits/stdc++.h>
using namespace std;
string MoveHyphen (string s, int n)
{
int count = 0;
for (int i = 0; i < n;)
{
if (s[i] == ’-’)
{
count++;
s.erase (i, 1);
}
else
i++;
}
while (count--)
{
s = ’-’ + s;
}
return s;
}
int main ()
{
string s;
cin >> s;
int n = s.size ();
cout << MoveHyphen (s, n);
return 0;
}
Accenture coding questions
Question:10
(Asked in Accenture Offcampus 1 Aug 2021, Slot 2)
Problem Statement
A carry is a digit that is transferred to left if sum of digits exceeds 9 while adding two numbers from
right-to-left one digit at a time
The functions accepts two numbers ‘num1’ and ‘num2’ as its arguments. You are required to calculate
and return the total number of carries generated while adding digits of two numbers ‘num1’ and ‘ num2’.
Example:
Input
Num 1: 451
Num 2: 349
Output
2
Explanation:
Adding ‘num 1’ and ‘num 2’ right-to-left results in 2 carries since ( 1+9) is 10. 1 is carried and (5+4=1) is
10, again 1 is carried. Hence 2 is returned.
Sample Input
Num 1: 23
Num 2: 563
Sample Output
Problem Statement
The function accepts a string ‘ str’ of length n and two characters ‘ch1’ and ‘ch2’ as its arguments .
Implement the function to modify and return the string ‘ str’ in such a way that all occurrences of ‘ch1’ in
original string are replaced by ‘ch2’ and all occurrences of ‘ch2’ in original string are replaced by ‘ch1’.
Note:
Input:
Str: apples
ch1:a
ch2:p
Output:
paales
Explanation:
‘A’ in original string is replaced with ‘p’ and ‘p’ in original string is replaced with ‘a’, thus output is paales.
int main ()
{
char a[100];
char b, c;
int len;
cin >> a;
cin >> b;
cin >> c;
return 0;
}
Question:12
(Asked in Accenture Offcampus 2 Aug 2021, Slot 1)
Problem Statement
The function accepts 3 positive integers ‘a’ , ‘b’ and ‘c ‘ as its arguments. Implement the function to
return.
( a+ b ) , if c=1
( a – b ) , if c=2
( a * b ) , if c=3
(a / b) , if c =4
Assumption : All operations will result in integer output.
Example:
Input
c :1
a:12
b:16
Output:
Since ‘c’=1 , (12+16) is performed which is equal to 28 , hence 28 is returned.
Sample Input
c:2
a : 16
b : 20
Sample Output
-4
int main()
{
int x, y, z;
int result;
cin >> x;
cin >> y;
cin >> z;
result = operationChoices(x, y, z);
cout << result;
return 0;
}
Question:13
(Asked in Accenture Offcampus 2 Aug 2021, Slot 2)
Problem Statement
You have to find and return the number between ‘a’ and ‘b’ ( range inclusive on both ends) which has the
maximum exponent of 2.
The algorithm to find the number with maximum exponent of 2 between the given range is
Loop between ‘a’ and ‘b’. Let the looping variable be ‘i’.
Find the exponent (power) of 2 for each ‘i’ and store the number with maximum exponent of 2 so faqrd in
a variable , let say ‘max’. Set ‘max’ to ‘i’ only if ‘i’ has more exponent of 2 than ‘max’.
Return ‘max’.
Assumption: a <b
Note: If two or more numbers in the range have the same exponents of 2 , return the small number.
Example
Input:
7
12
Output:
8
Explanation:
Exponents of 2 in:
7-0
8-3
9-0
10-1
11-0
12-2
Question : 14
(Asked in Accenture Offcampus 2 Aug 2021, Slot 3)
Problem Statement
The function accepts 2 positive integer ‘m’ and ‘n’ as its arguments.You are required to calculate the sum
of numbers divisible both by 3 and 5, between ‘m’ and ‘n’ both inclusive and return the same.
Note
0 < m <= n
Example
Input:
m : 12
n : 50
Output
90
Explanation:
The numbers divisible by both 3 and 5, between 12 and 50 both inclusive are {15, 30, 45} and their sum is
90.
Sample Input
m : 100
n : 160
Sample Output
510
You are required to input the size of the matrix then the elements of matrix, then you have to divide the
main matrix in two sub matrices (even and odd) in such a way that element at 0 index will be considered
as even and element at 1st index will be considered as odd and so on. then you have sort the even and
odd matrices in ascending order then print the sum of second largest number from both the matrices
Example
int main() {
int arr[100];
int length, i, j, oddlen, evenlen, temp;
int odd[50], even[50];
printf("Enter the length of the array: ");
scanf("%d", &length);
if (length % 2 == 0) {
oddlen = length / 2;
evenlen = length / 2;
} else {
oddlen = length / 2;
evenlen = (length / 2) + 1;
}
return 0;
}
Accenture coding questions
Question : 16
Instructions: You are required to write the code. You can click on compile and run anytime to check
compilation/execution status. The code should be logically/syntactically correct.
Problem: Write a program in C to display the table of a number and print the sum of all the multiples in it.
Test Cases:
Test Case 1:
Input:
5
Expected Result Value:
5, 10, 15, 20, 25, 30, 35, 40, 45, 50
275
Test Case 2:
Input:
12
Expected Result Value:
12, 24, 36, 48, 60, 72, 84, 96, 108, 120
660
Question: Write a program in C such that it takes a lower limit and upper limit as inputs and print all the
intermediate palindrome numbers.
Test Cases:
TestCase 1:
Input :
10 , 80
Expected Result:
11 , 22 , 33 , 44 , 55 , 66 , 77.
Test Case 2:
Input:
100,200
Expected Result:
101 , 111 , 121 , 131 , 141 , 151 , 161 , 171 , 181 , 191.
Question : 18
Instructions: You are required to write the code. You can click on compile & run anytime to check the
compilation/ execution status of the program. The submitted code should be logically/syntactically correct
and pass all the test cases.
Ques: The program is supposed to calculate the sum of distance between three points from each other.
For
x1 = 1 y1 = 1
x2 = 2 y2 = 4
x3 = 3 y3 = 6
return 0;
}
Question : 19
Find the maximum value and its index in the array
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:
Input:
23 45 82 27 66 12 78 13 71 86
Output:
86
Explanation:
C++ C Java
Run
#include<bits/stdc++.h>
using namespace std;
void MaxInArray (int arr[], int length)
{
int max = INT_MIN, index = -1;
for (int i = 0; i < length; i++)
{
if (arr[i] > max)
{
max = arr[i];
index = i;
}
}
cout << max << endl << index;
}
int main ()
{
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
MaxInArray (arr, n);
return 0;
}
Accenture coding questions
Question : 20
Autobiographical Number
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.
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:
Example:
Input:
n: “1210”
Output:
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.
C++ C Java
Run
#include<bits/stdc++.h>
using namespace std;
int FinndAutoCount (string n)
{
int sum = 0;
set < char >st;
for (int i = 0; i < n.size (); i++)
{
sum += (n[i] - ’0’);
st.insert (n[i]);
}
if (sum != n.size ())
return 0;
return st.size ();
}
int main ()
{
string n;
cin >> n;
cout << FinndAutoCount (n);
return 0;
}