Data Structures & AlgorithmsHardLeetCode-style · Codeforces Div2 C
A square matrix is [[2, 1, 3], [6, 5, 4], [7, 8, 9]]. A falling path starts in row 0 and goes down one row per step, moving to the cell directly below or diagonally left or right (column changes by at most 1). What is the minimum possible sum of the values on a falling path?
- A. 13
- B. 12
- C. 6
- D. 14
Correct answer: A. 13
Row-by-row DP: each cell gets its value plus the minimum of the (up to three) cells above it. Walking greedily from the smallest top value is a trap: the smallest start can force a large value in the next row.
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 stick of length 9 must be cut at the positions [5, 1, 7, 3]. A cut costs the current length of the stick piece it splits, and the cuts…
- How many binary strings over the alphabet {a, b} of length 6 contain EXACTLY 2 occurrences of the adjacent pair "ab" (occurrences may not…
- How many binary strings of length 9 contain NO occurrence of the substring 010?
- In how many ways can the integer 10 be written as a sum of AT MOST 3 positive integers, where order does not matter (for example 10 = 7 +…
- From [1, 2, 3, 4, 6, 8, 12, 16, 18, 24, 36], choose the largest subset in which every pair of elements (the smaller divides the larger)…
- What is the largest XOR value obtainable as the XOR of a non-empty contiguous subarray of [8, 1, 2, 12, 7, 6]?