Data Structures & AlgorithmsHardProduct placement · Amazon/Microsoft
Using a sliding window with a last-seen index map, what is the length of the longest substring of "beeebdddcbadad" with all characters distinct?
- A. 5
- B. 4
- C. 6
- D. 3
Correct answer: B. 4
When a repeat appears, move the left edge just past that character's previous occurrence (not to the current index). The best window has length 4. Restarting the window from scratch on a repeat gives 4.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the length of the smallest substring of "bcdadddaacbac" that contains every distinct character of the string at least once?…
- Which lower bound holds for every comparison-based sorting algorithm in the worst case?
- What does this loop-counting code print? (Python) python n, c = 12, 0 for i in range(1, n + 1): j = 1 while j <= n: c += 1 j += i print(c)
- Product of all elements except self, using prefix and suffix products (no division). What is printed? python a = [1, 1, 0, 2, -1] n =…
- Every row and every column of this 4 × 4 matrix is sorted ascending (rows separated by ';'): 9 11 16 36; 14 19 37 42; 29 40 45 50; 41 46…
- Every row and every column of this 4 × 4 matrix is sorted ascending (rows separated by ';'): 3 8 19 33; 17 22 35 42; 24 36 49 52; 38 50 53…