Question 21
EasyWhich of these words are anagrams of each other?
- 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
Which of these words are anagrams of each other?
listen and silent
tinsel and tinsels
listen and listing
silent and salient
Sign up free to see the answer and a step-by-step explanation.
Which of these is a palindrome?
lever
label
leave
level
Sign up free to see the answer and a step-by-step explanation.
Which string comes first in lexicographic (dictionary) order: 'apple' or 'apply'?
apply
It cannot be decided
They are equal
apple
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
print('Python'[1:4])
yth
tho
Pyt
ytho
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of checking whether a string of length n is a palindrome?
O(log n)
O(1)
O(n²)
O(n)
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
print('ab' * 3)
Error
ab ab ab
ab3
ababab
Sign up free to see the answer and a step-by-step explanation.
In the worst case, how long does naive (brute-force) pattern matching take for a text of length n and a pattern of length m?
O(m)
O(n·m)
O(log n)
O(n + m)
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
print(sorted("listen") == sorted("silent"))
False
True
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
s = "aaabbc"
out, i = "", 0
while i < len(s):
j = i
while j < len(s) and s[j] == s[i]:
j += 1
out += s[i] + str(j - i)
i = j
print(out)
aaabbc
3a2b1c
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
s = "abcabcbb"
seen, start, best = {}, 0, 0
for i, ch in enumerate(s):
if ch in seen and seen[ch] >= start:
start = seen[ch] + 1
seen[ch] = i
best = max(best, i - start + 1)
print(best)
3
2
Sign up free to see the answer and a step-by-step explanation.
Error
None
a3b2c1
abc
5
4