0% found this document useful (0 votes)
6 views2 pages

Lab Exam Paper3

The document presents a set of competitive coding exam questions focusing on various data structures and algorithms, including binary search, linked lists, stacks, queues, and trees. Each question outlines a specific problem, constraints, sample input, and expected output. The problems range from finding indices in arrays to implementing data structures and evaluating expressions.

Uploaded by

sreekantha reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Lab Exam Paper3

The document presents a set of competitive coding exam questions focusing on various data structures and algorithms, including binary search, linked lists, stacks, queues, and trees. Each question outlines a specific problem, constraints, sample input, and expected output. The problems range from finding indices in arrays to implementing data structures and evaluating expressions.

Uploaded by

sreekantha reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Competitive Coding Exam: Set 3 (Difficult Level)

Question 21: Binary Search

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

Question 22: Singly Linked List


Problem: Reverse a linked list in groups of size k.
Constraints: 1 ≤ n ≤ 105 , 1 ≤ k ≤ n
Sample Input: 1→2→3→4→5, k = 2
Sample Output: 2→1→4→3→5

Question 23: Doubly Linked List


Problem: Implement a text editor with the following operations: insert, delete, move cursor
left/right. Use a doubly linked list.
Constraints: 1 ≤ operations ≤ 105
Sample Input: insert(’a’), insert(’b’), left(), insert(’x’)
Sample Output: ”axb”

Question 24: Stack


Problem: Check if a given string containing brackets is valid. Also, return the length of
the longest valid bracket substring.
Constraints: Length 105
Sample Input: (()())(
Sample Output: Yes, 6

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

Question 26: Tree


Problem: Construct a binary tree from inorder and postorder traversal.
Constraints: 1 ≤ n ≤ 104 , unique values
Sample Input: inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]
Sample Output: Root = 3

Question 27: Binary Search


Problem: Given an array of integers and a number k, find the kth smallest pair distance
using binary search.
Constraints: 2 ≤ n ≤ 105 , 1 ≤ k ≤ n(n−1)
2
Sample Input: nums = [1,3,1], k = 1
Sample Output: 0

Question 28: Stack

Problem: Evaluate a reverse Polish notation (postfix) expression.


Constraints: Tokens 104
Sample Input: [”2”,”1”,”+”,”3”,”*”]
Sample Output: 9

Question 29: Queue


Problem: Given a list of tasks with cooldown time, determine minimum time to finish all
tasks.
Constraints: 1 ≤ tasks ≤ 104 , cooldown n ≤ 100
Sample Input: tasks = [A,A,A,B,B,B], n = 2
Sample Output: 8

Question 30: Tree

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

You might also like