Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: A list is [5, 9, 2, 7]. How many pairs (i, j) with i < j have a[i] + a[j] greater than 10?
- A. 4
- B. 5
- C. 3
- D. 6
Correct answer: A. 4
Test all six pairs: 5+9, 5+7, 9+2 and 9+7 exceed 10, while 5+2 and 2+7 do not. The answer is four pairs.
More Coding Interview Problems questions
- Problem: For the words ["sleep", "steep", "sheep", "creep"] (all of length five), how many unordered pairs differ in exactly one letter…
- Problem: The string "abcabc" is processed by replacing each character with its index in the alphabet (a=0, b=1, ..., z=25), and then the…
- Problem: A directed graph on vertices 0–4 has arcs 0→1 (2), 0→2 (6), 1→2 (3), 1→3 (9), 2→3 (1), 3→4 (2), 2→4 (8). What is the length of…
- Problem: Vertices 1–6 of an undirected graph have edges 1-2, 2-3, 4-5, 5-6, 6-4 and 3-1. How many edges are NOT part of any cycle?
- Problem: A rooted tree (root 1) has children 1: [2, 3], 2: [4], 3: [5, 6], 5: [7]. What is the number of nodes at depth 2 (root at depth 0)?
- Problem: The string "mississippi" contains repeated substrings. What is the length of the longest substring that appears at least twice…