Best Upward Board Score and Number of Optimal Routes

Quick Overview

Best Upward Board Score and Number of Optimal Routes. Start at S in the bottom-right corner of the square board and reach E in the top-left.

Best Upward Board Score and Number of Optimal Routes

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Start at S in the bottom-right corner of the square board and reach E in the top-left. Each move goes up,left or diagonally up-left to a non-X cell. Other cells contain digits 1 through 9, whose values are collected when visited. Return[maximum score,number of routes attaining it modulo 1000000007], or[0,0] if E is unreachable. S and E contribute 0. ```cpp class Solution { public: vector<int> pathsWithMaxScore(vector<string>& board); }; ``` ### Examples **Example 1:** ```text Input: board = ["E1","2S"] Output: [2,1] Explanation: Moving left through2 and then up collects2. The alternative through1 and the direct diagonal score less. ``` **Example 2:** ```text Input: board = ["E1","1S"] Output: [1,2] Explanation: Either two-step edge route scores1, while the direct diagonal scores0. ``` ### Constraints - The board is square with side length 2 to 100. - E is top-left, S bottom-right, and all other cells are digits 1 through 9 or X. ### Contract considerations Return the two numeric results, not one selected route. Multiple optimal routes do not create output freedom in this pair. ```hint Read the boundary condition Account for tied best routes, obstacles, and an unreachable destination while returning both requested numbers. ``` ### Boundary reminders Return the two numeric results, not one selected route. Multiple optimal routes do not create output freedom in this pair.

Overview: Best Upward Board Score and Number of Optimal Routes. Start at S in the bottom-right corner of the square board and reach E in the top-left.

Google logo
Google
Jun 13, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Start at S in the bottom-right corner of the square board and reach E in the top-left. Each move goes up,left or diagonally up-left to a non-X cell. Other cells contain digits 1 through 9, whose values are collected when visited. Return[maximum score,number of routes attaining it modulo 1000000007], or[0,0] if E is unreachable. S and E contribute 0.

class Solution {
public:
    vector<int> pathsWithMaxScore(vector<string>& board);
};

Examples

Example 1:

Input: board = ["E1","2S"]
Output: [2,1]
Explanation: Moving left through2 and then up collects2. The alternative through1 and the direct diagonal score less.

Example 2:

Input: board = ["E1","1S"]
Output: [1,2]
Explanation: Either two-step edge route scores1, while the direct diagonal scores0.

Constraints

  • The board is square with side length 2 to 100.
  • E is top-left, S bottom-right, and all other cells are digits 1 through 9 or X.

Contract considerations

Return the two numeric results, not one selected route. Multiple optimal routes do not create output freedom in this pair.

Boundary reminders

Return the two numeric results, not one selected route. Multiple optimal routes do not create output freedom in this pair.