Data Structures & AlgorithmsVery hardCodeforces Div2 D · TCS NQT
A gold mine is the grid [[1, 3, 3], [2, 1, 4], [0, 6, 4]]. You start in any cell of the LEFT column and move one column to the right each step, going to the cell up-right, right, or down-right (within the grid). What is the maximum total gold you can collect?
- A. 9
- B. 14
- C. 23
- D. 12
Correct answer: D. 12
Backward DP from the right column: best[r][c] = g[r][c] + max best of the three reachable cells in the next column. Starting from the largest left-column cell greedily can miss a better path through a smaller start.
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 permutations of 0, 1, 2, 3, 4 are alternating, meaning p[0] < p[1] > p[2] < p[3] > p[4]?
- What is the smallest positive integer x such that x! (x factorial) ends with at least 1000 zeros?
- How many substrings of "abcabcb" contain at least one each of the letters a, b and c?
- What is the length of the shortest substring of "aabcbcdbca" that contains every distinct letter appearing in the whole string at least…
- How many contiguous subarrays of [4, 2, 3, 1, 6, 5, 7, 9] satisfy max − min = (length of the subarray) − 1? Count every such subarray…
- What is the length of the longest substring of "bbaacabaacb" that contains EXACTLY two letters 'a'?