Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
Grid [[3, 1, 4, 1], [5, 9, 2, 6], [5, 3, 5, 8], [9, 7, 9, 3]]. Starting from any cell in the top row, each step goes to the cell directly below or diagonally below-left or below-right (staying in the grid). What is the maximum sum of a path that reaches the bottom row?
- A. 30
- B. 9
- C. 27
- D. 28
Correct answer: C. 27
Row-by-row DP: each cell takes its value plus the best of the three cells above it that are inside the grid. Starting from a single large cell, or going straight down, misses the diagonal options.
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
- In how many ways can a 3 × 8 rectangle be tiled exactly with 2 × 1 dominoes (horizontal or vertical)?
- How many DIFFERENT values can the sum of three distinct integers chosen from 1 to 9 take?
- What is the length of the longest substring of "aebcdiouxyab" in which the number of vowels (a, e, i, o, u) equals the number of non-vowels?
- How many index pairs (i < j) in [4, 9, 1, 7, 12, 5, 8, 3] satisfy a[i] − a[j] = 3 (exactly 3, in this order)?
- Starting from the number 1, each operation either doubles the current number or adds 1. What is the minimum number of operations needed to…
- How many pairs (i, j) with 1 ≤ i ≤ j ≤ 12 have lcm(i, j) ≤ 12?