Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: For the string "abcabcdab", how many substrings of length 3 occur exactly once?
- A. 5
- B. 6
- C. 4
- D. 7
Correct answer: A. 5
Count the frequency of each length-3 substring and tally those with frequency one. Only 'abc' repeats (at positions 0 and 3), so the other five substrings occur exactly once.
More Coding Interview Problems questions
- Problem: How many integers from 1 to 500 are NOT perfect squares and NOT perfect cubes?
- Problem: The dynamic array doubles its capacity whenever it is full, starting from capacity 1. After inserting 9 elements one by one, how…
- Problem: In a binary heap stored in an array with 1-based indexing, the array [1, 3, 2, 7, 4, 5, 6] is a valid min-heap. What is the sum…
- Problem: Vertices 0–5 form a graph with edges 0-1, 1-2, 2-3, 3-0 and 4-5. A BFS from vertex 0 gives each vertex a distance. What is the…
- Problem: A stack-sortable check is applied to the permutation [3, 1, 2]: elements are pushed in order and popped whenever the top equals…
- Problem: The array [5, 2, 8, 2, 9, 1, 5, 5] contains repeated values. How many distinct values appear exactly twice?