Question 51
MediumWhat is the longest common subsequence of 'ABCBDAB' and 'BDCABA' in length?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What is the longest common subsequence of 'ABCBDAB' and 'BDCABA' in length?
5
3
4
6
Sign up free to see the answer and a step-by-step explanation.
Which data structure is used for fast prefix lookups, such as autocomplete?
Stack
Trie
Heap
Queue
Sign up free to see the answer and a step-by-step explanation.
A string of 26 lowercase letters is checked for being a pangram. What extra space is needed with a boolean array?
O(log n)
O(n²)
O(n)
O(1) (26 flags)
Sign up free to see the answer and a step-by-step explanation.
What does the Z-algorithm compute for a string s?
The reverse of s
The longest palindrome
For each position i, the length of the longest substring starting at i that matches a prefix of s
The number of vowels
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
s = "babad"
best = ""
for c in range(len(s)):
for l, r in ((c, c), (c, c + 1)):
while l >= 0 and r < len(s) and s[l] == s[r]:
l -= 1; r += 1
if r - l - 1 > len(best):
best = s[l + 1:r]
print(best)
bab
aba
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of the KMP string-matching algorithm for a text of length n and pattern of length m?
O(n log m)
O(n + m)
O(m²)
O(n × m)
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
p = "ababc"
pi = [0] * len(p)
k = 0
for i in range(1, len(p)):
while k and p[i] != p[k]:
k = pi[k - 1]
if p[i] == p[k]:
k += 1
pi[i] = k
print(pi)
[0, 0, 1, 2, 0]
[0, 0, 0, 1, 2]
Sign up free to see the answer and a step-by-step explanation.
How does the Rabin–Karp algorithm compare a pattern with substrings of the text quickly?
By comparing every character every time
Using a suffix tree only
Using a rolling hash, updated in O(1) as the window slides
By sorting the text
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
a, b = "abcd", "cdab"
print(len(a) == len(b) and b in a + a)
False
Error
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
s = "abab"
best = 0
for k in range(1, len(s)):
if s[:k] == s[-k:]:
best = k
print(best)
1
3
Sign up free to see the answer and a step-by-step explanation.
ba
babad
[1, 1, 2, 3, 1]
[0, 1, 2, 3, 0]
True
None
2
4