Data Structures & AlgorithmsHardFlipkart/Uber OA · placement
Two pointers start at both ends of the sorted array [3, 4, 5, 6, 8, 17, 18, 23, 26, 27]. How many pairs (i < j) have a[i] + a[j] ≤ 40? (When a[lo] + a[hi] ≤ target, all pairs (lo, lo+1..hi) qualify.)
- A. 1
- B. 36
- C. 37
- D. 38
Correct answer: C. 37
If a[lo] + a[hi] ≤ 40, every j in (lo, hi] also works with lo, so add hi − lo and advance lo; otherwise decrement hi. The total is 37 (of which 1 pairs sum to exactly 40).
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
- What does this loop-counting code print? (Python) python n, c = 20, 0 i = n while i > 0: for j in range(i): c += 1 i //= 2 print(c)
- Rabin–Karp with base 10 and a deliberately small modulus counts true matches and spurious hits (hash equal, text different). What is…
- Using a sliding window with a last-seen index map, what is the length of the longest substring of "beeebdddcbadad" with all characters…
- What is the length of the smallest substring of "bcdadddaacbac" that contains every distinct character of the string at least once?…
- Which lower bound holds for every comparison-based sorting algorithm in the worst case?
- What does this loop-counting code print? (Python) python n, c = 12, 0 for i in range(1, n + 1): j = 1 while j <= n: c += 1 j += i print(c)