I was interviewed in Sep, 2021.
- Q1. Buy and Sell Stock - III
Given an array "prices". In "prices" the ith element is the price of the stock on the ith day. Your task is to find maximum profit at the end of the ith day. You may complete at max 2 transactions.
You can perform a transition with these conditions -
1. Not allowed to engage in more than 1 transaction at a time, which means if you have bought stock then you can buy another stock before selling the first stock. 2. If you bought a stock at ‘X’ price and sold it at ‘Y’ price then the profits ‘Y - X’.
It is not compulsory to perform an exact '2' transaction.
The first line of input contains an integer 'T' denoting the number of test cases. The first line of each test case contains a single integer 'N', 'N' denotes the length of array ‘prices’. The second line of each test case contains an 'N' space-separated integers, in which every integer denotes an element of the array "prices".
For each test case, you need to print the maximum profit made by selling the stocks.
You do not need to print anything; it has already been taken care of.
1 <= T <= 50 1 <= N <= 10^4 0 <= A[i] <= 10^9 Time limit: 1 second
- Q2. Pairwise Sum of Hamming Distance
You are given an array ARR having N integers. Your task is to find the sum of Hamming Distance for each pair of the array elements.
Hamming Distance for two given integers 'A' and 'B' is defined as the minimum number of bits that needs to be toggled to make both the integers equal.
Consider A=4 and B=7 Binary representation of 4 = 100 Binary representation of 7 = 111 For the given example, if we flip the values of the last two least significant bits of A to 1 then A will become 7. As we can change the value of A to B by 2 flips. Therefore the Hamming Distance, in this case, is 2.
The first line of input contains an integer ‘T’ denoting the number of test cases. The first line of each test case contains an integer ‘N’ denoting the number of elements in the array. The second line of each test contains 'N' space-separated integers denoting the array elements.
For each test case, return the sum of Hamming Distance for all the pairs.
You are not required to print anything just implement the given function.
1 <= T <= 10 1 <= N <= 10^4 0 <= ARR[i] <=10^9 Time limit: 1 second
- Q3. Next Greater Element
For a given array/list of integers of size N, print the Next Greater Element(NGE) for every element. The Next Greater Element for an element X is the first element on the right side of X in the array, which is greater than X. If no greater elements exist to the right of X, consider the next greater element as -1.
For the given array [7, 12, 1, 20] - The next greater element for 7 is 12. - The next greater element for 12 is 20. - The next greater element for 1 is 20. - There is no greater element for 20 on the right side. Output: [12, 20, 20, -1]
The first line of input contains an integer 'N' representing the size of the array/list. The second line of input contains 'N' single space-separated integers representing the elements of the array/list.
Output Format :
The only line of output contains 'N' single space-separated integers representing the Next Greater Element for each element.
You do not need to print anything explicitly, it has already been taken care of.
1 <= N <= 10^5 1 <= ARR[i] <= 10^9 Time Limit: 1 sec
- Q4. Left View Of Binary Tree
Given a binary tree. Print the Left View of the Tree.
If the input tree is as depicted in the picture:
The Left View of the tree will be: 2 35 2
Input format :
Elements in the level order form. The input consists of values of nodes separated by a single space in a single line. In case a node is null, we take -1 in its place. For example, the input for the tree depicted in the below image would be :
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Level 1 : The root node of the tree is 1 Level 2 : Left child of 1 = 2 Right child of 1 = 3 Level 3 : Left child of 2 = 4 Right child of 2 = null (-1) Left child of 3 = 5 Right child of 3 = 6 Level 4 : Left child of 4 = null (-1) Right child of 4 = 7 Left child of 5 = null (-1) Right child of 5 = null (-1) Left child of 6 = null (-1) Right child of 6 = null (-1) Level 5 : Left child of 7 = null (-1) Right child of 7 = null (-1) The first not-null node (of the previous level) is treated as the parent of the first two nodes of the current level. The second not-null node (of the previous level) is treated as the parent node for the next two nodes of the current level and so on. The input ends when all nodes at the last level are null (-1).
The above format was just to provide clarity on how the input is formed for a given tree. The sequence will be put together in a single line separated by a single space. Hence, for the above-depicted tree, the input will be given as: 1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output Format :
The only line of output will print the data of in the Left View of the Tree separated by a single space.
0 <= N <= 10^5 1 <= data <= 10^5 Where ‘N’ is the total number of nodes in the binary tree, and 'data' is the value of the binary tree node. Time limit: 1sec
- Q5. Basic HR Questions
Show me your id card
Relocation related questions
Which tech you are using
Some questions around projects
What's the famous food in the ongole ?
Who is your favorite hero ?
Cognizant interview Rounds:Round 1
Round type - Online Coding Interview
Round duration - 180 minutes
Round difficulty - Easy
Round type - Video Call
Round duration - 30 minnutes
Round difficulty - Hard
Round type - HR Round
Round duration - 10 minutes
Round difficulty - Medium
Tip 1 : practice more on programming
Tip 2 : just first learn basics and go for advance
Tip 3 : the questions on database are more important that can increases more package just well prepare on sql
Tip 1 : everything should be format in a nice way don't add colors to resume keep it simple
Tip 2 : first name-->address->education->experience->projects/open source->achievements