Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
How many substrings of "cbaebabacd" of length 3 are anagrams of "abc" (contain exactly the same letters with the same counts, in any order)?
- A. 2
- B. 3
- C. 0
- D. 1
Correct answer: A. 2
Slide a fixed window of length |p| and keep a letter-count map; each window whose counts equal the pattern's counts is a match. Counting exact occurrences of the pattern string (in the given order) gives a smaller number.
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
- In "abababaabab", what is the maximum number of NON-OVERLAPPING occurrences of "aba" that can be chosen (left to right, each occurrence…
- A stack starts empty. The operations are ['push', 'push', 'pop', 'push', 'push', 'pop', 'push', 'push', 'push', 'pop', 'push']. How many…
- From "bcabcdbac" delete exactly 3 letters (the rest keep their order). What is the lexicographically LARGEST string you can obtain?
- In [3, 4, 9, 5, 6, 2, 1, 7, 8], what is the length of the longest subsequence (keeping the order) in which every pair of consecutive…
- What is the minimum number of pieces needed to split "abacdcbaxyzyx" into contiguous pieces where every piece is a palindrome?
- You may increase any element of [5, 3, 2, 10, 4] by any amount (increases only). What is the minimum total increase needed to make the…