Cognizant Itt Questions
Cognizant Itt Questions
2. Given an integer array nums , print an array answer such that answer[i] is
equal to product of all the elements of nums except nums[i].
Input:
4
1234
Output:
24 12 8 6
3. Given two integers, find the hamming distance between two integers.
Hamming distance between two integers is the number of bits that are
different at the same position in both numbers.
Input:
3 14
Output:
4. Given an integer array nums and an integer K , return the Kth largest
element in the array that is the Kth largest element in the sorted array not
the Kth distinct element.
Input:
321564
2
Output:
Input:
AXY
ADXCPY
Output:
True
6. Given an array ‘ARR’ containing ‘N’ integers’. The task is to find the sum
of the minimum value in ‘SUB’, where ‘SUB’ ranges over every contiguous
subarray of ‘ARR’.
Input:
4
1234
Output:
20
Test case 1:
Subarrays with ‘1’ as their minimum value: [1], [1,2], [1,2,3], [1,2,3,4]. Sum
= 1 + 1 + 1 + 1 = 4.
Subarrays with ‘2’ as their minimum value: [2], [2,3], [2,3,4]. Sum = 2 + 2 +
2 = 6.
Subarrays with ‘3’ as their minimum value: [3], [3,4]. Sum = 3 + 3 = 6.
Subarrays with ‘4’ as their minimum value: [4]. Sum = 4.
The sum over all subarrays is ‘4 + 6 + 6 + 4 = 20’.
Thus, you should return ‘20’ as the answer.
7. Given an input integer ‘N’, print the following binary pattern for it.
Input:
Output:
1111
000
11
0
8. Find all the factors of the given number. . If the entered input is zero then the
output should be “No Factors”. And if the entered input is a negative number
then first convert it to positive and then find its factors.
10.Given an integer array, Remove duplicate elements and print the result.
Input:
122445677
Output:
124567
1.
You have been given a string S of length N. The given string is a binary string which
consists of only 0’s and ‘1’s. Ugliness of a string is defined as the decimal number that
this binary string represents.
Example:
“101” represents 5.
“0000” represents 0.
“01010” represents 10.
There are two types of operations that can be performed on the given string.
Initially, you have been given coins equal to the value defined in CASH. Your task is to
minimize the ugliness of the string by performing the above mentioned operations on it.
Since the answer can be very large, return the answer modulo 10^9+7.
Note:
You can perform an operation only if you have enough number of coins to
perform it.
After every operation the number of coins get deducted by the cost for that
operation.
Input Format
The first line contains an integer, N, denoting the number of character in the
string
The next line contains a string, S, denoting the the binary string
The next line contains an integer, CASH, denoting the total number of coins
present initially
Next will contains an integer, A, denoting the cost to swap two characters.
Then the next line contains an integer, B, denoting the cost to flip a character.
Constraints
Sample Input 1 :
4
1111
7
1
2
Sample Output 1 :
Explanation:
Sample Input 2:
6
111011
7
1
3
Sample Output 2:
Explanation:
First swap 0 with the most significant 1, then use flip twice first on index one and then
on index two “111011”=>”0111111″=>”001111″=>”000111″ the value represented is
7.
Sample Input 3:
6
111011
7
3
2
Sample Output 3:
Explanation:
Flip the 3 most significant characters to get “000011” : the value represented by this
string is 3.N
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2.
Problem Statement :
For example:
If A=[2,4,6,8], then khaled can choose the subset [2,4,8] to achieve XOR=(2 XOR
4 XOR 8)=14.
Khaled wants to maximize the XOR of all the elements he chooses. Your task is to
help khaled to find the max XOR of a subset that he can achieve by choosing at most
N/2 elements?
Input format:
1<=N<=120
1<=A[i]<=10^6
Sample Input 1
2
1
2
Sample Output 1
2
Explanation:
N=2, A=[1,2] khaled can choose the subset[2]. The xor of the elements in the subset
is 2. And the number of elements in the subset is 1 which is less than N/2.
Sample Input 2
4
1
2
4
7
Sample Output 2
Explanation:
N=4, A=[1,2,4,7] Khaled can choose the subset [7]. The xor of the elements in the
subset is 7, and the number of elements in the subset is 1 which is less than N/2.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////