Data Structures & AlgorithmsVery hardProduct placement · Amazon/Microsoft
What is the length of the smallest substring of "baddcacdabcbd" that contains every distinct character of the string at least once? (Variable sliding window with a count map.)
- A. 4
- B. 6
- C. 5
- D. 9
Correct answer: A. 4
The string uses 4 distinct letters. Expand right until all are present, then shrink from the left while they remain; the smallest such window has length 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
- A circular queue in an array of size 7 keeps one slot empty to tell full from empty (front = rear means empty; (rear + 1) mod 7 = front…
- A fixed sliding window of length 5 moves over "programmingisfun". What is the maximum number of vowels (a, e, i, o, u) inside any window?
- How many contiguous subarrays of [4, 2, 2, 6, 4, 1, 5] have bitwise XOR equal to 6? (Prefix XORs with a frequency map: add freq[px ^ 6] at…
- What is the minimum number of characters that must be APPENDED to the end of "abacdcab" to make it a palindrome? (Find the longest…
- For [7, 3, 5, 3, 7, 2, 5], definition A returns the element whose FIRST occurrence is earliest among all repeating elements; definition B…
- nums1 = [2, 5, 8, 0, 0, 0] (3 real values plus 3 buffer slots) and nums2 = [3, 6, 9] are merged in place by filling nums1 from the BACK…