Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: Consider the string "xyzzyzyx". How many distinct substrings of length 2 are there?
- A. 5
- B. 6
- C. 4
- D. 7
Correct answer: A. 5
The length-2 substrings are xy, yz, zz, zy, yz, zy, yx, which contain five distinct values. Counting positions gives seven, which overcounts the repeats.
More Coding Interview Problems questions
- Problem: The array [1, 4, 6, 3, 8, 2] is processed by a single pass that tracks the maximum so far. How many elements are records…
- Problem: A set of 10 people is divided into 5 pairs. How many distinct ways are there to form these pairs (unordered pairs, unordered…
- Problem: In the array [5, 8, 3, 7, 2], find the second-largest element.
- Problem: A tree with 5 nodes is given by the parent array p = [−1, 0, 0, 1, 1] (node 0 is the root). How many leaves does it have?
- Problem: The bit pattern 10110 is shifted left by 2 positions and then XOR-ed with the original pattern. What is the decimal value of the…
- Problem: Vertices 0–4 have undirected edges 0-1 (3), 1-2 (1), 2-3 (4), 3-4 (2), 0-4 (6), 1-4 (5). A path's cost is the sum of its edge…