Data Structures & AlgorithmsModerateInfosys · Wipro pattern
Two pointers start at both ends of the sorted array [1, 3, 4, 6, 8, 11] to find pairs of DIFFERENT positions with sum 12 (move left if the sum is small, right if it is large, both on a match). How many pairs are found?
- A. 3
- B. 2
- C. 1
- D. 0
Correct answer: B. 2
1 + 11 = 12 (match, move both) → 3 + 8 = 11 < 12 → 4 + 8 = 12 (match) → now l and r cross at 6. Pairs: (1, 11) and (4, 8). 6 + 6 would need the same position twice, which is excluded, so '3' is wrong.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A hash map starts with capacity 16 and doubles its capacity whenever the number of keys EXCEEDS 0.75 × capacity. What is its capacity…
- Bubble sort (each pass compares adjacent pairs left to right and swaps if out of order) runs on [6, 2, 9, 1, 5]. What is the array after…
- The array [1, 2, 3, 4, 5, 6] is first rotated RIGHT by 2 positions and then rotated LEFT by 5 positions. What is the result?
- What is the longest common prefix of the strings interview, internet, interval and intern?
- The first k = 4 elements of the queue 1, 2, 3, 4, 5, 6 (front first) are reversed using a stack: dequeue 4 items onto the stack, pop them…
- k sorted lists contain N elements in total. They are merged into one sorted list by repeatedly taking the smallest head from a min-heap…