Data Structures & AlgorithmsVery hardTCS NQT · Accenture
How many pairs of distinct positions (i, j) with i < j in the string abcdcba satisfy s[i] = s[j]?
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: A. 3
Each letter with frequency f gives f(f-1)/2 pairs: a and b appear twice each, c twice, and d once.
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 the sequence of queue operations enqueue 5, enqueue 3, dequeue, enqueue 8, dequeue, dequeue, enqueue 1, what is the value at the front…
- For the pattern "aabaabaaab" (0-based), what is the value of the KMP prefix function π at the LAST index? π[i] is the length of the…
- How many times does the pattern "aaa" occur in the text "aaaabaaaaab", counting OVERLAPPING occurrences (occurrences may share letters)?
- Using the Z-function (z[i] = length of the longest common prefix of s and s[i..], with z[0] = n), what is the sum of all z-values of…
- What is the length of the longest substring of "pwwkewfabcdbbca" with no repeated character?
- How many DISTINCT substrings (by content, non-empty) does "abcab" have?