Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: For the words ["sleep", "steep", "sheep", "creep"] (all of length five), how many unordered pairs differ in exactly one letter position?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
Compare each pair position by position. 'sleep', 'steep' and 'sheep' pairwise differ in one position, while 'creep' differs from each of them in two positions, so the answer is three.
More Coding Interview Problems questions
- 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…
- Problem: For the string "abcabcdab", how many substrings of length 3 occur exactly once?