Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: A sorted list of distinct integers is 3, 8, 12, 17, 21, 26, 30. How many pairs (i < j) have a[j] − a[i] exactly equal to 9?
- A. 6
- B. 4
- C. 7
- D. 5
Correct answer: D. 5
Brute force over pairs of the sorted list checks each difference. Using a two-pointer sweep gives the same count on the sorted array.
More Coding Interview Problems questions
- Problem: The value of 3^(3^3) mod 7 is what?
- Problem: A path graph has vertices 1–6 with edges between consecutive vertices. How many pairs of vertices are at distance exactly 2?
- Problem: Consider the directed graph with arcs 1→2, 2→3, 3→4, 4→2, 1→5. Starting from 1, how many distinct vertices are reachable…
- Problem: In the array [9, 2, 6, 4, 7, 1], what is the number of elements that are smaller than every element to their left (strict left…
- Problem: The number 2^10 − 1 has how many distinct prime factors?
- Problem: A text buffer contains "hello world". Each space is replaced by the three characters "%20" (URL-style encoding). What is the…