Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: A grid of size 3×4 has the cell values 1 to 12 filled row-wise. Starting at the top-left (value 1), you may move right or down only, and you collect the value of every cell you enter. What is the maximum possible sum of collected values to reach the bottom-right cell?
- A. 30
- B. 48
- C. 47
- D. 78
Correct answer: B. 48
Larger values lie lower and to the right, so go down first: 1 → 5 → 9 → 10 → 11 → 12 = 48 (a right/down DP confirms it). Going right first gives the minimum 30, leaving out the start cell gives 47, and 78 adds every cell.
More Coding Interview Problems questions
- For a = [2, -1, 4, -3, 5], which of the following statements is TRUE? A. Some contiguous subarray sums to 7. B. Every prefix sum from the…
- What does this program print? python a = [1, -1, 2, -2, 3] seen = {0: 0} s = 0; out = [] for i, x in enumerate(a, 1): s += x if s in seen…
- What does this program print? python best = None s = 0 for x in [4, -2, -2, 3, -1]: s += x best = s if best is None else max(best, s)…
- Array [1, 3, 2, 6, 4, 5, 7, 8]. How many inversions does it have (index pairs i < j with a[i] > a[j])?
- Sequence [5, 2, 9, 1, 7, 3]. Consider only index pairs i < j with j - i <= 2. What is the largest value of |a[i] - a[j]| over these pairs?
- What is the length of the longest strictly increasing subsequence of [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]? Use the patience-sorting method with…