Data Structures & AlgorithmsModerateTCS NQT · string basics
Problem: What is the longest common prefix of the list ['flower', 'flow', 'flight']? Run the code.
Problem: What is the longest common prefix of the list ['flower', 'flow', 'flight']? Run the code.
import os print(os.path.commonprefix(['flower', 'flow', 'flight']))What is printed?
- A. flow
- B. fl
- C. f
- D. flo
Correct answer: B. fl
Only 'fl' is shared by all three words, since the third letter differs ('o' versus 'i'). The trap 'flo' is shared by the first two words only.
More Coding Interview Problems questions
- Problem: What does the following print? python print(' '.join('the sky is blue'.split()[::-1]))
- Problem: Which statement about Hall's theorem for a bipartite graph with sides L and R is correct?
- Problem: Which claim about the complexity of deciding 2-SAT (satisfiability of clauses with at most two literals) is correct?
- Problem: Which of the following problems is NP-complete (decision version)?
- Problem: For Dijkstra on a graph with V vertices and E edges, which pairing of data structure and running time is correct?
- Problem: For a set of 40 items split into two halves of 20, the meet-in-the-middle approach solves subset-sum queries in roughly which time?