Data Structures & AlgorithmsHardTCS Digital · Infosys SP
Using a sliding window with a last-seen index map, what is the length of the longest substring of "dbdcccdcbaddad" with all characters distinct?
- A. 6
- B. 4
- C. 5
- 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
- Two strings are isomorphic if characters can be replaced one-to-one to turn one into the other. Version A checks both directions; version…
- Swap every two adjacent nodes of a linked list by relinking (not by swapping values). What is printed? python def swappairs(h): d = p =…
- Count distinct values in every window of size k with a frequency map. What is printed? python from collections import Counter a, k = [3…
- A min-stack keeps a second stack of running minimums. What is printed? python st, mn, out = [], [], [] for op in [7, 5, 7, 5, 5, "pop"…
- A hash-map two-sum returns the first index pair (i, j), i < j, found while scanning left to right. What is printed? python def twosum(a…
- A dynamic array doubles its capacity when full, copying all elements. Starting from capacity 1, what is the total number of element copies…