Accolite QPP

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Q1 .

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

Q2. Topological Sort


You are given a directed acyclic graph. Your task is to find any topological sorting of the graph.
A directed acyclic graph is a directed graph with no directed cycles.
Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed
edge from u to v, vertex u comes before v in the ordering.
For example-
For the given DAG-

One of the possible topological sort will be- 1 2 3

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?

Q7. What are function pointers and the differences between


normal function and function pointers?

Q8. Explain the diamond problem in Cpp, and how to solve it.

Q9. What are the ways to prevent Instantiation of Class?

Q10. Maximum subarray

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

Q12. Separate negative and positive numbers in a linked list.


Data Structures
Linked List

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

Q17. If not engineering then what?

Q18. How to check for a loop in linked list?


Data Structures
Linked List

Q19. Max multiplication of 3 numbers in an array

Q20. What is finally and will it execute if System.exit() is called?

Q21. Project Explanation which includes Q&A as well.

Q22. Check if a linked list is circular or not


Data Structures
Linked List

Q23. Remove duplicates from Linked List. Both variants.


Data Structures
Linked List

Q24. Intersection of Linked List


You are given two Singly Linked List of integers, which are
merging at some node of a third linked list.
Your task is to find the data of the node at which merging starts. If
there is no merging, return -1.
For example:-
The given Linked Lists, where a1, a2, c1 is the first linked list, b1, b2, b3, c1 is the second linked list, and c1, c2, c3 is the third
linked list which are merging at node c1.

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

Q25. Q25. Rotting Oranges


You have been given a grid containing some oranges. Each cell of
this grid has one of the three integers values:
 Value 0 - representing an empty cell.
 Value 1 - representing a fresh orange.
 Value 2 - representing a rotten orange.
Every second, any fresh orange that is adjacent(4-directionally) to
a rotten orange becomes rotten.
Your task is to find out the minimum time after which no cell has a
fresh orange. If it's impossible to rot all the fresh oranges then
print -1.
Note:
1. The grid has 0-based indexing. 2. A rotten orange can affect the adjacent oranges 4 directionally i.e. Up, Down, Left, Right.

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

Q26. Calculating the depth of a tree


Data Structures

Q27. What are registers in Cpp?


Programming Language
asked in
Software Engineer Interview
View Answer (1)
Q28. Left View of Binary Tree
Given a binary tree. Print the Left View of the Tree.
Example :
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

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

Q29. Reverse Linked List


You are given a Singly Linked List of integers. You need to reverse
the Linked List by changing the links between nodes.
Input Format :
The first line of input contains a single integer T, representing the number of test cases or queries to be run. The first line of
each test case contains the elements of the singly linked list separated by a single space and terminated by -1. Hence, -1
would never be a list element.

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

Q31. Merge K Sorted Arrays


You have been given ‘K’ different arrays/lists, which are sorted
individually (in ascending order). You need to merge all the given
arrays/list such that the output array/list should be sorted in
ascending order.
Input Format :
The first line of input contains an integer T, the number of test cases. The first line of each test case contains an integer that
denotes the value of K. The next 2*K lines of each test case follow: The first line contains an integer ‘N’ denoting the size of the
array. The second line contains N space-separated integers.

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy