Data Structures & AlgorithmsHardHCLTech · Wipro pattern
Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the longest substring of "BACBBACDACDA" containing at most k = 3 distinct characters?
- A. 12
- B. 7
- C. 6
- D. 3
Correct answer: B. 7
Sliding the window right and shrinking from the left whenever the distinct-character count exceeds k = 3 gives a longest valid window of length 7. Using k = 2 would give 3, and using k = 4 would give 12 — off-by-one errors on the distinct-count bound.
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 does this loop-counting code print? (Python) python n, c = 22, 0 i = 1 while i < n: j = i while j < n: c += 1 j = 2 i += 1 print(c)
- Kadane's algorithm runs on the array [6, 9, 2, 7, -4, -9, -5, 1, 3, 4] to find the maximum sum of a contiguous subarray. What sum does it…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- Using a sliding window of fixed size with a character-frequency count, how many substrings of "BABAAABCC" are anagrams of "AB"?
- The Dutch National Flag algorithm (single pass, three pointers low/mid/high) partitions [0, 2, 2, 2, 1, 1, 2, 2, 0, 1] (values 0, 1, 2…
- A recursive function is defined as f(0) = f(1) = 1 and f(n) = f(n−1) + 2·f(n−2) for n ≥ 2. Using memoization, what is f(10)?