Data Structures & AlgorithmsModerateProduct-company MCQ pattern
How many distinct non-empty substrings does the string ABAB have?
- A. 7
- B. 8
- C. 6
- D. 10
Correct answer: A. 7
There are 4 × 5/2 = 10 substrings by position, but A, B and AB each appear twice, so the distinct ones are A, B, AB, BA, ABA, BAB, ABAB = 7.
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
- What is the KMP failure (LPS) array for the pattern AABAACAABAA?
- The reversal algorithm rotates an array LEFT by k: reverse the first k elements, reverse the rest, then reverse the whole array. What is…
- Which statement about a doubly linked list compared with a singly linked list is FALSE?
- How many of these statements are correct? (i) Merge sort is stable. (ii) Heap sort runs in O(n log n) even in the worst case. (iii) Quick…
- What is the time complexity of this code fragment? c int count = 0; for (int i = 1; i < n; i = 2) for (int j = 0; j < i; j++) count++;
- What is the time complexity of this code fragment? c for (int i = 1; i <= n; i++) for (int j = i; j <= n; j += i) work(); // O(1)