Data Structures & AlgorithmsModerateGATE CS · TCS NQT
How many substrings of length 2 in the string abcabcab occur at least twice in the string (possibly overlapping)?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
Count the occurrences of each length-2 substring in a hash map. Here ab, bc and ca each appear at least twice, and cb, ba do not appear at all.
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 the array [1, 2, 3, 4, 6, 12], how many index pairs i < j have a[j] divisible by a[i]?
- Minimum number of elements to delete from [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] so the remaining sequence is non-decreasing (equal neighbours…
- How many index pairs i < j satisfy a[i] > 2 a[j] for a = [5, 1, 3, 9, 2, 8, 4]?
- How many contiguous subarrays of [2, 4, 3, 1, 5, 7, 6] consist of consecutive integers (all distinct, with max minus min equal to length…
- What is the length of the longest contiguous subarray of [1, 2, 4, 3, 6, 8, 5, 7] whose sum is even?
- Choose two disjoint contiguous windows of length exactly 2 in [1, 2, 9, 4, 5, 1, 8, 3] (the windows may not share an index). What is the…