Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: The string "abcdabcd" is examined for windows of length 4 with all four characters distinct. How many such windows are there?
- A. 5
- B. 6
- C. 4
- D. 7
Correct answer: A. 5
Check each length-4 window for distinct letters with a set. Counting distinct windows as strings gives a smaller number because some windows repeat.
More Coding Interview Problems questions
- Problem: What is the minimum number of characters to delete from "programming" so that all remaining characters are distinct (keep one…
- Problem: Compute the longest palindromic prefix of "abacabacaba" (the longest prefix that reads the same backwards). What is its length?
- Problem: What is the length of the longest common substring (contiguous) of "abcdxyz" and "xyzabcd"?
- Problem: From the array [3, 2, 7, 10], choose a subset with no two adjacent indices chosen, maximising the sum. What is the maximum sum?
- Problem: The array [5, 1, 6, 2, 7] must be made strictly increasing by deleting the fewest elements. What is the minimum number of…
- Problem: On the complete graph K4 (vertices 0–3, every pair adjacent), how many walks of exactly 4 edges start at vertex 0? A walk may…