Accenture Coding Part 1
Accenture Coding Part 1
Product of Numbers:
You are given a function.
Int* ProductArray(int* arr, int n);
The function accepts an integer array “arr” of length “n”. Implement the function to modify the given array
such that, value at each index is replaced with product of all integers of the array except for the integer
on that index.
Assumption:
Array index starts from 0
n>1
Each product operation is within the integer range.
Note:
Input and Output arrays are of same length
Example:
Input:
Input:
4 6 5
2 3 7 5
Output:
Output:
30 20 24
105 70 30 42
Explanation:
arr[0] = arr[1]*arr[2]*arr[3]=3*7*5=105 , similarly all other elements are replaced with product of all
integer of the array except the integer on that particular index of array.
Problem Statement:
You are given a function:
Int DesiredArray(int* Arr, int N, int K);
The function accepts an array “Arr” of size “N” and an integer “K”.
You have to find the “K” smallest integers that are not divisible by any of the “N” integers
and return the sum of all “K” integers.
Note: Array won’t contain 1.
Example: Example:
Input: Input:
K : 4 K : 4
N : 5 N : 4
Arr : [2,3,4,5,6]Arr : [3,6,9,12]
Output: Output:
32 12
Explanation: First K-smallest non divisible by Arri integers will be 1,7,11,13. Hence the
sum will be 32.
Problem Statement: Documents
The United Nations Organization released an official document regarding the most important
events from the beginning of time (dated 00-00-0000) with a brief description of the events.
The date of all the events is mentioned in the “DD-MM-YYYY” format.
Find the total number of distinct years referenced in the document.
Input Specification:
Input 1: String containing the content of the document.
Output Specification:
Return the total number of distinct years referenced in the document.
Example 1:
Input : UN was established on 24-10-1945. India got freedom on 15-08-1947.
Output: 2
Explanation: 2 distinct years, 1945 and 1947 have been referenced.
Example 2:
Input: Soon after the World War 2 ended on 02-09-1945, the UN was established on 24-10-1945
Output: 1
Explanation: Only 1 distinct year. i.e. 1945 has been referenced.
Problem Statement: You are given a function, char* MergeStrings(char* str1, char* str2);
The function accepts strings str1 and str2 as its arguments. Implement the function to generate a string by
iterating through each element of given string.
For i=0 , on comparing character at index 0 of input strings, smaller character is placed at index 0 and
larger character is placed at index n-1.
For i=1 , on comparing character at index 0 of input strings, smaller character is placed at index 1 and
larger character is placed at index n-2.
For i=k , on comparing character at index k of input strings, smaller character is placed at index k and
larger character is placed at index n-k-1.
Where k<n and n is the length of output string(Length of str1 + Length of str2)
Assumption: String contains lowercase characters only.
Note: Character ‘x’ is smaller than ‘y’ since it occurs prior in alphabetical series.
Return null if both the strings are null.
Return other string if one of the string is null.
Null refers to None in case of Python.
If Example:
length of the string is Input:
not same, then rest of the characters are added on their original positions.
Input: cape
Str1 : are port
Str2 : denim Output:
Output: aeeimnrd capetrop