Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The string "abcabcbb" is scanned and for each position the length of the longest run of distinct characters starting at that position is recorded. What is the maximum of these recorded lengths?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Starting from each index and extending until a repeat gives each run; the maximum equals the longest substring with distinct characters. Recording the run from the first index alone gives a shorter value.
More Coding Interview Problems questions
- Problem: Dijkstra's algorithm in an undirected graph with edges 0-1 (2), 1-2 (2), 0-2 (5), 2-3 (1), 1-3 (6). How many vertices have a…
- Problem: The string "xyyxzzyx" is examined for palindromic substrings of length 4 or more. How many such palindromic substrings are there…
- Problem: A binary string is "good" if it has no two consecutive zeros. How many good strings of length 7 begin with 1 and end with 1?
- Problem: A process list is [3, 7, 2, 9] with priorities; the CPU always runs the largest value next and runs it for its full value, then…
- Problem: How many subarrays of [2, 4, 6, 1, 3, 5] have all elements even or all elements odd?
- Problem: The number 9 is written in base 3 as 100. How many numbers from 1 to 100 have a base-3 representation with no digit 2?