Data Structures & AlgorithmsVery hardCodeforces Div2 D · TCS NQT
Target string "abcbc" must be built by concatenating words from the list ['ab', 'bc', 'abc', 'a', 'b', 'c', 'cb']; each word can be reused, and the order of concatenation matters. How many different ways are there to build the target exactly?
- A. 7
- B. 12
- C. 10
- D. 8
Correct answer: C. 10
Let ways[i] be the number of ways to build the prefix of length i: ways[i] = Σ ways[i − |w|] over words w that end exactly at i. Counting only which words occur in the target ignores how many distinct concatenations exist.
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
- A truck carries at most 5 boxes. Box types are given as (number of boxes of this type, units per box): [(1, 3), (2, 2), (3, 1), (2, 4)]…
- How many contiguous subarrays of 2 3 4 1 6 9 have a product divisible by 6?
- How many contiguous subarrays of 5 2 7 1 8 3 6 4 have an ODD length and a sum divisible by 7?
- What is the sum, over all non-empty contiguous subarrays of 5 3 6 1 4, of their XOR values, taken modulo 1000?
- How many arrays of length 3 with entries in {0, 1, 2, 3} have a sum divisible by 4?
- How many ORDERED pairs (i, j) with i ≠ j in 1 4 6 9 10 3 5 satisfy that A[i] + A[j] is divisible by 5?