Accenture CodingPart2
Accenture CodingPart2
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 length of the string is not same, then rest of the characters are added on their original positions.
Example: Input:
Input: cape
Str1 : are port
Str2 : denim Output:
Output: aeeimnrd capetrop
Problem statement:
Few keys in the keyboards are not working properly. While typing, there are few alphabets that gets included with multiple occurrences. This is has caused huge problem
to the user. Now they have to come up with a feature that removes all these duplicates alphabets within a word. Only those alphabets have to be removed which have
occurred more than once exactly adjacent to each other.
Example:
Input: abciijklma
Output: abcjklma
Explanation: Consider the above string, it contains 2 I’s next to each other. These are the ones that need to be removed. There are also 2 a’s but they are not adjacent to
each other. Hence these should not be removed from the original string.
Problem Statement: Standard Deviation.
Standard Deviation is a quantity expressing by how much the members of a group differ from the mean value for the group. You are required to implement the following function:
float StandardDeviation(int arr[], int n);
The function accepts and array ‘arr’ of ‘n’ positive integers as its arguments. You are required to calculate the Standard Deviation of ‘n’ positive integers in array ‘arr’ and return the same.
Formula Used:
Let sqrt(x) be square root of a positive integer ‘x’.
Average of data set ‘arr[0]’, ‘arr[1]’, ‘arr[2]’, ……….,’arr[n-1]’. (A) = { arr[0] + arr[1] + arr[2]+, ……….,+ arr[n-1]}/n
Standard Deviation for data set arr[0]’, ‘arr[1]’, ‘arr[2]’, ……….,’arr[n-1]’ :
sqrt{ [ (arr[0]-A)^2 + (arr[1]-A)^2 + (arr[2]-A)^2 + …………………………………….. + (arr[n-1]-A)^2 ] / n}
Note: 1) n > 0 2) Round off result upto 2 decimal places.
Input: Input:
arr: 3 8 4 2 5 6 7 arr: 10 15 17
n: 7 n: 3
Output: 2.00 Output: 2.94
Problem Statement: Sum of Successive Elements:
You are required to implement the following function.
def SumSuccessiveElements(arr,n):
The function accepts an array ‘arr’ of length ‘len’ and an integer ‘n’ as its arguments. You are required to calculate the sum of every successive nth element in the array ‘ arr’ and return the
same.
Note:
n>0
If ‘arr’ = NULL (or None in case of Python), return -1
If n > length of ‘arr’, return 0.
Example:
Input: Input:
arr: 10 12 16 1 5 6 3 21 arr: 7 88 12 4 15 71 22 23 20 16
len: 8 len: 10
n: 3 n: 4
Output: Output:
22 27
Explanation: 3rd successive elements in the given array are {16,6}, sum of whom is 22, hence 22 is returned.