Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
How many distinct non-empty substrings does the string aaaa have?
- A. 5
- B. 4
- C. 6
- D. 8
Correct answer: B. 4
The distinct substrings are a, aa, aaa and aaaa, so the count is 4. Counting by position would give 10.
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
- An array has only positive integers and you need the longest contiguous subarray whose sum is at most K, with n up to 10^6. Which method…
- How many contiguous subarrays of [3, 1, 4, 1, 5, 9] have a prime sum?
- What is the minimum number of elements to delete from [4, 7, 2, 9, 5] so that the remaining sum is divisible by 3? (The empty remainder is…
- How many index pairs i < j of [1, 2, 4, 6, 7, 9] have a sum strictly between 5 and 10?
- How many index pairs i < j in [2, 5, 3, 4, 1] satisfy a[i] < a[j] and every element strictly between i and j is at most a[j]?
- What is the smallest integer k such that 3k is at least every element of [5, 10, 14, 17]?