Data Structures & AlgorithmsHardTCS NQT · Accenture
What is the length of the longest common prefix of the strings interstellar, internet, interval and intern?
- A. 5
- B. 6
- C. 4
- D. 7
Correct answer: A. 5
Shrink the first string until every other string starts with it. The prefix is inter and is shared by all four strings.
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
- How many integers x with 1 <= x <= 100 satisfy x mod 3 = 2 and x mod 5 = 3?
- How many contiguous subarrays of [7, 1, 6, 13, 8, 2] have a sum congruent to 0 modulo 7?
- How many positive divisors of 720 are perfect squares?
- Two people in a circle of 5 are numbered 1 to 5 and eliminated by repeatedly removing every second person (starting by removing person 2)…
- How many index pairs i < j in the array [1, 2, 3, 4, 5, 6] satisfy gcd(a[i], a[j]) = 1 and a[i] + a[j] is odd?
- What is the number of elements remaining in the list after deleting each element that is smaller than the element immediately before it…