Tap here to switch tabs
Problem
Submissions

Problem: Count Good Integers on a Grid Path

Try to solve the Count Good Integers on a Grid Path problem.

Statement

You are given two integers l and r, and a string directions.

For any integer x, consider its 1616 digit representation padded with leading zeros if it contains fewer than 1616 digits. These 1616 digits are placed into a 4×44 \times 4 grid in row major order, filling rows from top to bottom and columns from left to right, with the top left cell at (0,0)(0, 0) and the bottom right cell at (3,3)(3, 3).

A path on the grid begins at cell (0,0)(0, 0) and ends at cell (3,3)(3, 3). The path follows the sequence of moves given by directions, where 'D' denotes moving down one cell and 'R' denotes moving right one cell.

An integer x is defined as good if the sequence of digits visited along the path is non decreasing.

Return the count of good integers x such that l ≤x≤\le x \le r.

Constraints:

  • 1≤1 \le l ≤\le r ≤9×1015\le 9 \times 10^{15}

  • directions.length =6= 6

  • directions consists of exactly three 'D' characters and three 'R' characters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Good Integers on a Grid Path

Try to solve the Count Good Integers on a Grid Path problem.

Statement

You are given two integers l and r, and a string directions.

For any integer x, consider its 1616 digit representation padded with leading zeros if it contains fewer than 1616 digits. These 1616 digits are placed into a 4×44 \times 4 grid in row major order, filling rows from top to bottom and columns from left to right, with the top left cell at (0,0)(0, 0) and the bottom right cell at (3,3)(3, 3).

A path on the grid begins at cell (0,0)(0, 0) and ends at cell (3,3)(3, 3). The path follows the sequence of moves given by directions, where 'D' denotes moving down one cell and 'R' denotes moving right one cell.

An integer x is defined as good if the sequence of digits visited along the path is non decreasing.

Return the count of good integers x such that l ≤x≤\le x \le r.

Constraints:

  • 1≤1 \le l ≤\le r ≤9×1015\le 9 \times 10^{15}

  • directions.length =6= 6

  • directions consists of exactly three 'D' characters and three 'R' characters.