Lab Exam Paper3
Lab Exam Paper3
Problem: Find the smallest index i in a sorted array such that arr[i] ≥ x. Use binary
search.
Constraints: 1 ≤ n ≤ 106 , −109 ≤ x, arr[i] ≤ 109
Sample Input: arr = [1,3,5,6,9], x = 4
Sample Output: 2
1
Question 25: Queue
Problem: Implement a circular queue supporting enqueue, dequeue, f ront, rear, isF ull,
and isEmpty in O(1) time.
Constraints: Capacity 104 , operations 105
Sample Input: enqueue(1), enqueue(2), dequeue(), front()
Sample Output: 2
Problem: Find the lowest common ancestor (LCA) of two nodes in a binary tree.
Constraints: Nodes 104
Sample Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
Sample Output: 3