Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: Count the triples of indices i < j < k in [2, 5, 1, 7, 3, 4, 6] with a[i] + a[j] + a[k] ≤ 12.
- A. 15
- B. 120
- C. 20
- D. 35
Correct answer: C. 20
Brute force over the 35 triples finds 20 with sum ≤ 12 (sort plus two pointers does it in O(n²)). Using < 12 gives 15, counting ordered triples multiplies by 3! (120), and 35 counts every triple.
More Coding Interview Problems questions
- Problem: How many integers n with 1 ≤ n ≤ 500 satisfy n mod 3 = n mod 5 ?
- Problem: A matrix of size 4×4 is filled row-wise with 1 to 16 (row 0 holds 1–4, row 1 holds 5–8, and so on). It is rotated 90 degrees…
- Problem: In the string "racecarbanana", find the number of distinct palindromic substrings of length at least 3.
- Problem: On a line of 12 cells (1–12), a robot starts at cell 1. Each second it moves to the cell i+3 if that cell is still ≤ 12 and not…
- Problem: A string is built by writing the first 15 positive integers in binary, concatenated in order (1, 10, 11, 100, ..., 1111). How…
- Problem: A sorted array [1, 3, 3, 5, 8, 8, 8, 13, 21] is searched for the value 8 using the standard lower-bound binary search (find the…