Data Structures & AlgorithmsModerateGATE CS · DSA
How many distinct non-empty substrings does the string "aaaaa" have, and how many substrings counted by position?
- A. 5 and 5
- B. 5 and 15
- C. 15 and 15
- D. 1 and 15
Correct answer: B. 5 and 15
By position there are n(n + 1)/2 = 15 substrings, but they are just a, aa, aaa, aaaa, aaaaa — 5 distinct strings.
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
- 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…
- A mountain is a contiguous subarray of length ≥ 3 that strictly increases to a single peak and then strictly decreases. What is the length…
- For each day, a monotonic stack finds how many days you must wait for a strictly warmer temperature (0 if never). What is printed? python…