Accolite QPP
Accolite QPP
Accolite QPP
Loot Houses
A thief wants to loot houses. He knows the amount of money in each house. He cannot loot two consecutive
houses. Find the maximum amount of money he can loot.
Input Format :
The first line of input contains a single integer 'N' denoting the total number of houses. The second line of input contains 'N'
single space-separated integers, denoting the amount of money in every 'i-th' house.
Output Format :
The only line of output will print the maximum amount of loot that is possible.
Note :
You don’t need to print anything, it has already been taken care of. Just implement the given function.
Constraints :
0 <= 'N' <= 10^5 0 <= 'A[i]' <= 10^4 Where 'A[i]' represents the money present in the 'i-th' house. Time limit: 1 sec
Input Format:
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test case follows. The first line
of each test case contains two single space-separated integers ‘N’, ‘M’, denoting the number of nodes and the number of
edges respectively. The next ‘M’ lines of each test case contain two single space-separated integers ‘U’, ‘V’ each denoting
there is a directed edge from node ‘U’ to node ‘V’.
Output Format:
The only line of each test case will contain N single space-separated integers representing the topological sorting of the graph.
You can print any valid sorting. Print the output of each test case in a separate line. Note: You are not required to print the
expected output, it has already been taken care of. Just implement the function.
Constraints:
1 <= T <= 100 1 <= N <= 5000 0 <= M <= min(5000, (N*(N-1))/2) 1 <= U, V <= N and U != V Time Limit: 1sec
Q3. Total time: 110 mins 1. Find missing and duplicate numbers
from given array(algo, code, optimization, dry run, complexity
analysis) 2. Flatten Binary tree to Linked List Conversion (algo,
code, optimization, dry run, complexity analysis) 3. Find loop in
linkedlist (write function only) 4. AVL tree balancing factor
analysis. 5. What is RDBMS and SQL 6. Difference between sql and
mongodb 7. What is mongoose 8. Difference between react js and
angular js 9. Difference between http and tcp 10. Different
between IPV4 and IPV6 11. What is Deadlock and Race Condition?
12. Tell me what is the use of pointer in function oriented
programming? Why Pointer is not there in Java
Data Structures
Linked List
Algorithms
Programming Language
Q4. Can you make a constructor private in Cpp, if not what error
will you get (Compile Time Error or Runtime Error)
Q5. What is the difference between Binary Tree and Binary Search
Tree
Data Structures
Q6. What are the Dynamic-link library (DLL) in Cpp and its use?
Q8. Explain the diamond problem in Cpp, and how to solve it.
Ninjas has been given an array. He wants to find a subarray such that the sum of all elements in the subarray is
maximum.
Subarray 'A' is greater than sub-array 'B' if sum(A) > sum(B). If two sub-array have the same maximum sum, then
output the subarray that has a larger length.
A subarray means a contiguous part of an array. For example, In 'arr' = [1, 2, 3, 4], [1, 2], [2, 3, 4] are the
contiguous subarry but [1, 3, 4] is not a subarray.
Note:
More than one sub-array can have a maximum sum, in that case, output any.
Input Format:
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. The first line of each test
case contains a single integer ‘N’ denoting the size of the array. The second line of each test case contains ‘N’ space-separated
integers denoting the elements of the array.
Output Format:
For each case, If the returned subarray is correct then print 1, else print 0. The output of each test case will be printed in a
separate line.
Note:
You do not need to input or print anything, and it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 5 1 <= N <= 1000 -99 <= |arr| <= 99 Time limit: 1 sec.
Q11. A tweak to the pair sum problem: there can be any number of
elements that add up to the target
Algorithms
Q13. How can you print names of 4 threads in the given order?
Q14. Delete Kth node from the end of the linked list in single
iteration
Data Structures
Linked List
Q15. Segregate 0's and 1's in array - Dutch National Flag Algo
Again
Algorithms
Q16. Equal Sum Partition along with print that 2 arrays (DP +
matrix printing)
Algorithms
Input Format:
The input format contains three lines consisting of three singly-linked lists. All three lines contain the elements of the singly
linked list separated by a single space and terminated by -1. So first linked list would contain a1, a2, ...an, c1, -1. Similarly, the
second line would contain b1,b2, ...bm, c1, -1. The third line would contain c2, c3, ....ck, -1.
Output format :
The only line of output contains data of the first merged node. If there is no merging output should contain -1. You don't have
to explicitly print by yourself. It has been taken care of.
Constraints :
0 <= N <= 10^5 0 <= M <= 10^5 0 <= K <= 10^5. -10^9 <= data <= 10^9 and data != -1 Time Limit: 1 sec
Data Structures
Linked List
Input Format:
The first line of input contains two single space-separated integers 'N' and 'M' representing the number of rows and columns of
the grid respectively. The next 'N' lines contain 'M' single space-separated integers each representing the rows of the grid.
Output Format:
The only line of output contains a single integer i.e. The minimum time after which no cell has a fresh orange. If it's impossible
to rot all oranges, print -1.
Note:
You are not required to print the expected output, it has already been taken care of. Just implement the function.
Constraints:
1 <= N <= 500 1 <= M <= 500 0 <= grid[i][j] <= 2 Time Limit: 1 sec
Data Structures
Algorithms
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
Explanation :
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).
Note :
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.
Constraints :
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
Data Structures
Output Format :
For each test case, print the reversed linked list. The elements of the reversed list should be single-space separated,
terminated by -1. Print the output of each test case in a separate line.
Note :
You do not need to print anything, just return the head of the reversed linked list.
Constraints :
1 <= T <= 10 1 <= N <= 10^4 0 <= data <= 10^9 Where 'N' is the number of nodes in the linked list. Time Limit: 1 sec
Data Structures
Linked List
Q30. what is level order traversal of tree?Write code for the same.
Data Structures
Output Format :
The first and only line of output contains space-separated elements of the merged and sorted array, as described in the task.
Note :
You don’t have to print anything; it has already been taken care of. Just implement the function.
Constraints :
1 <= T <= 5 1 <= K <= 5 1 <= N <= 20 -10^5 <= DATA <= 10^5 Time Limit: 1 sec
Algorithms