Data Structures & AlgorithmsModerateGATE CS · TCS NQT
In how many ways can a 2 × 9 board be tiled exactly with 2 × 1 dominoes (placed vertically) and 2 × 2 squares, with no overlaps and no gaps? Rotations of a piece count as different placements only when they are different positions.
- A. 34
- B. 55
- C. 60
- D. 512
Correct answer: B. 55
Look at the leftmost column: it is either one vertical domino (leaving a 2 × (n−1) board) or half of a 2 × 2 square (leaving 2 × (n−2)). That gives the Fibonacci recurrence f(n) = f(n−1) + f(n−2).
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 ≤ 1000 are perfect squares or perfect cubes (or both)?
- Intervals (inclusive integer ranges) are [(1, 3), (2, 5), (4, 9), (6, 7), (8, 12), (9, 10)]. What is the minimum number of intervals whose…
- A binary string is "10110010". Flipping position i costs weight[i] = [3, 1, 4, 1, 5, 9, 2, 6]. You want the string to alternate (0101…
- How many contiguous subarrays of the binary array [1, 0, 1, 1, 0, 0, 1, 0] contain equally many 0s and 1s? (Non-empty subarrays only.)
- A string of brackets is ')))(()(' where '(' opens and ')' closes. What is the minimum number of brackets that must be removed to make the…
- How many elements of [2, 5, 1, 4, 3] have no strictly smaller element anywhere to their right?