Question 71
HardHow many distinct palindromic subsequences of length 3 does a string of n characters have at most (alphabet size 26)?
- A.
n³
- B.
n²
- C.
26 × 26 = 676
- D.
26
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
How many distinct palindromic subsequences of length 3 does a string of n characters have at most (alphabet size 26)?
n³
n²
26 × 26 = 676
26
Sign up free to see the answer and a step-by-step explanation.
Which algorithm finds all occurrences of many patterns in a text in one pass?
Dijkstra
KMP alone
Binary search
Aho–Corasick
Sign up free to see the answer and a step-by-step explanation.
What does Manacher's algorithm compute in O(n)?
All anagrams
The longest common subsequence
The longest palindromic substring centred at every position
The edit distance
Sign up free to see the answer and a step-by-step explanation.
Why is checking s1 == s2 in Python O(n) in the worst case even though it looks like one operation?
Characters are compared one by one until a difference or the end
Strings are hashed first
Python sorts them
It is always O(1)
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of checking whether two strings are anagrams by sorting?
O(n log n)
O(n²)
O(n)
O(log n)
Sign up free to see the answer and a step-by-step explanation.
Which is the minimum number of characters to insert to make 'abcd' a palindrome?
3
1
4
2
Sign up free to see the answer and a step-by-step explanation.
A string is built with s = s + c in a loop of n steps in Java. What is the total time?
O(n log n)
O(n)
O(n²), since each step copies the whole string
O(1)
Sign up free to see the answer and a step-by-step explanation.
What does a trie node usually store?
A count of vowels
Links to child nodes for each next character and a flag marking the end of a word
The whole word
A hash of the word
Sign up free to see the answer and a step-by-step explanation.
What is the longest common prefix of 'interview', 'internet', 'interval' and 'internal'?
intern
in
int
inter
Sign up free to see the answer and a step-by-step explanation.
Which is the most efficient way to check whether a string has all unique characters, if the alphabet is ASCII?
Sorting, O(n log n)
A 128-entry boolean array, O(n) time and O(1) space
Nested loops, O(n²)
Recursion
Sign up free to see the answer and a step-by-step explanation.