Data Structures & AlgorithmsHardFlipkart/Uber OA · placement
A fixed window of length 3 slides over s = "bcaacbccbbbbac" with a character-count array. At how many starting positions is the window an anagram (permutation) of "aac"?
- A. 3
- B. 1
- C. 12
- D. 2
Correct answer: D. 2
Compare the window's letter counts with those of "aac" at each of the 12 positions, updating the counts in O(1) per slide. Matching windows: 2; exact copies of the pattern: only 1.
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
- For each element of [16, 4, 2, 19, 10, 6, 29, 9], find the next greater element to its RIGHT (−1 if none), using a monotonic stack. What…
- How many distinct non-empty substrings does the string "aaaaa" have, and how many substrings counted by position?
- Find the index of the first non-repeating character using a frequency table (−1 if none). What is printed? python from collections import…
- A string of length n is searched for a pattern of length m. What are the worst-case times of the naive algorithm and of KMP?
- How many inversions (pairs i < j with a[i] > a[j]) does [35, 33, 31, 3, 20, 18, 13, 4] have? (This is also the number of swaps bubble sort…
- The Dutch national flag algorithm (pointers low, mid, high; 0 → swap with low and advance both; 1 → advance mid; 2 → swap with high and…