Data Structures & AlgorithmsModerateGATE CS · CAT · MBA placement
Strings "ab" and "cde" are interleaved, keeping the internal order of each string. How many distinct strings can be formed this way?
- A. 5
- B. 12
- C. 20
- D. 10
Correct answer: D. 10
Choosing which 2 of the 5 output positions hold the letters of "ab" gives C(5,2) = 10 interleavings, because the order inside each string is fixed. Counting permutations of all five letters ignores the fixed order, and counting over 4 positions is a slip.
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
- You may delete characters from "sea" and from "eat" to make the two strings equal. Deleting a character costs its ASCII code (for example…
- What is the length of the longest subsequence of [1, 7, 4, 9, 2, 5, 3, 8] whose consecutive differences alternate in sign (each step goes…
- How many contiguous subarrays of [1, 2, 3, 4, 7, 10, 13, 14, 15, 16] are arithmetic (at least 3 elements, with a constant difference…
- What is the length of the longest contiguous substring of the binary string "1100100110111000101" that has equally many 0s and 1s?
- What is the smallest positive period p of the string abcabcabca, meaning the smallest p such that s[i] = s[i+p] for every valid i?
- How many distinct cyclic rotations does the string abcabc have (rotations are the strings obtained by moving a prefix to the end…