Accenture Coding Question1
Accenture Coding Question1
Example
Input 1: 1
Input 2: –2
Input 3: 3
Output:
{3.0,–1.0}
Explanation:
On substituting the values of a, b, and c in the formula, the roots will be as follows:
+X = 3.0
-X = –1.0
29. Write a function to find if the given string is a palindrome or
not. Return 1 if the input string is a palindrome, else return 0.
Input:
level
Output:
1
Explanation:
The reverse of the string ‘level’ is ‘level’. As they are the same, the string is a
palindrome.
30. Write a function to check if the given two strings are
anagrams or not. Return ‘Yes’ if they are anagrams, otherwise,
return ‘No’.
Example
Input 1: build
Input 2: dubli
Output:
Yes
Problem Description
Given a range [A, B], find sum of integers divisible by 7 in this range.
Problem Constraints
1 <= A <= B <= 109
Input Format
First argument is an integer A.
Second argument is an integer B.
Output Format
Return an integer.
Example Input
Input 1:
A = 1
B = 7
Input 2:
A = 99
B = 115
Example Output
Output 1:
7
Output 2:
217
Example Explanation
Explanation 1:
Integers divisible by 7 in given range are {7}.
Explanation 2:
Integers divisible by 7 in given range are {105, 112}.
Problem Description
Problem Constraints
1 <= |A| <= 105
1 <= |B| <= 105
Input Format
First argument is a string A.
First argument is a string B.
Output Format
Return an integer.
Example Input
Input 1:
A = 2
B = 10
Input 2:
A = 11
B = 11
Example Output
Output 1:
4
Output 2:
1
Example Explanation
Explanation 1:
210 = 1024, hence last digit is 4.
Explanation 2:
1111 = 285311670611, hence last digit is 1.
Problem Description
Find the number of integers in range [A, B] with last digit C.
Problem Constraints
1 <= A <= B <= 109
0 <= C <= 9
Input Format
Given three integers A, B and C.
Output Format
Return an integer.
Example Input
Input 1:
A = 11, B = 111, C = 1
Input 2:
A = 1, B = 9, C = 0
Example Output
Output 1:
11
Output 2:
Example Explanation
Explanation 1:
The integers are 11, 21, 31, 41, 51, 61, 71, 81, 91, 101, 111
Explanation 2:
Problem Description
Problem Constraints
1 <= |A|, |B| <= 105
1 <= Ai, Bi, C <=109
Input Format
First argument is an integer array A.
Second argument is an integer array B.
Third argument is an integer C.
Output Format
Return an integer.
Example Input
Input 1:
A = [1, 2, 3, 4]
B = [5, 6, 7, 8]
C = 4
Input 2:
Example Output
Output 1:
0
Output 2:
Example Explanation
Explanation 1:
There are no integers greater than C in A.
There are no integers less than C in B.
Explanation 2:
Problem Description
Problem Constraints
1 <= A <= 105
1 <= B <= 20
Input Format
Given two integers A and B.
Output Format
Return an integer, the number of possible sequences modulo 109+7.
Example Input
Input 1:
A = 4, B = 2
Input 2:
A = 4, B = 3
Example Output
Output 1:
4
Output 2:
Example Explanation
Explanation 1:
The possible sequences are {1, 2}, {1, 3}, {1, 4}, {2, 4}.
Explanation 2:
Problem Description
Problem Constraints
1 <= |A| <= 105
Ai = {Lowercase latin alphabets}
Input Format
Given a string A.
Output Format
Return an integer array of length 26.
Array should contain frequency of characters in increasing order of characters.
Example Input
Input 1:
A = "abcdefghijklmnopqrstuvwxyz"
Input 2:
A = "interviewbit"
Example Output
Output 1:
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1}
Output 2:
{0, 1, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0, 1, 1, 0,
0, 0}
Example Explanation
Explanation 1:
Every charcater is present once in the string.
Explanation 2:
Problem Description
Problem Constraints
1 <= Ai <=105
1 <= B×C <= 105
Input Format
First argument is an integer array A.
Second argument is an integer B.
Third argument is an integer C.
Output Format
Return 2D integer array.
Example Input
Input 1:
A = [1, 2, 4, 8]
B = 2
C = 2
Input 2:
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
B = 3
C = 3
Example Output
Output 1:
[[1, 2],
[8, 4]]
Output 2:
[[1, 2, 3],
[8, 9, 4],
[7, 6, 5]]
Problem Description
Given two integers A and B, where A is the first element of the sequence then find Bth element of
the sequence.
If the kth element of the sequence is X then k+1th element calculated as:
Problem Constraints
1 <= A <= 109
1 <= B <= 105
Input Format
Given two integers A and B.
Output Format
Return an integer.
Example Input
Input 1:
A = 1
B = 3
Input 2:
A = 5
B = 6
Example Output
Output 1:
2
Output 2:
Example Explanation
Explanation 1:
The sequence is as follows 1 -> 4 -> 2
Explanation 2:
Problem Description
Given an integer A.
Find the digital root of A.
Digital root is the repeated sum of digits of untill there is only one digit left.
Problem Constraints
1 <= A <= 109
Input Format
Given an integer A.
Output Format
Return an integer.
Example Input
Input 1:
A = 99
Input 2:
A = 100
Example Output
Output 1:
9
Output 2:
Example Explanation
Explanation 1:
99 -> 9+9 = 18 -> 1+8 = 9
Explanation 2:
Problem Description
Problem Constraints
1 <= |A| <= 105
1 <= Ai <= 109
Input Format
Given an integer array A.
Output Format
Return an integer array.
Example Input
Input 1:
A = [1, 2, 3, 4]
Input 2:
A = [9, 9, 9]
Example Output
Output 1:
[24, 12, 8, 6]
Output 2:
Example Explanation
Explanation 1:
[2×3×4, 1×3×4, 1×2×4, 1×2×3]
Explanation 2: