Data Structures & AlgorithmsModerateProduct-company MCQ pattern
Using a sliding window, find the length of the longest substring with no repeated character in the string dvdfabcda.
- A. 9
- B. 4
- C. 6
- D. 3
Correct answer: C. 6
The window vdfabc (positions 1–6) has 6 distinct letters; when d arrives the left edge jumps past the earlier d and the window shrinks to fabcd. 4 is the size of the final window (forgetting to keep the maximum), 9 is the whole string and 3 stops at the first repeat (dvd).
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 shortest contiguous subarray of [1, 4, 4, 2, 3, 1, 5] whose sum is at least 9?
- How many contiguous subarrays of [1, 2, 3, −3, 3, 1] have sum exactly 3? (A prefix-sum + hash-map method counts them in O(n).)
- How many UNIQUE triplets (as sets of values, ignoring order) of [−1, 0, 1, 2, −1, −4, −2, 3] sum to 0? (Sort + two pointers, skipping…
- What is the time complexity of this Java method? java String build(int n) { String s = ""; for (int i = 0; i < n; i++) s = s + "a"; return…
- In Python, a list q is used as a queue: items are added with q.append(x) and removed with q.pop(0). If n items pass through the queue…
- What does this function print for the list 1 → 2 → 3 → 4 → 5 → 6? python def f(node): if node is None: return if node.next…