3906. Count Good Integers on a Grid Path
You are given two integers
landr, and a stringdirectionsconsisting of exactly three'D'characters and three'R'characters.For each integer
xin the range[l, r](inclusive), perform the following steps:
- If
xhas fewer than 16 digits, pad it on the left with leading zeros to obtain a 16-digit string.- Place the 16 digits into a
4 × 4grid in row-major order (the first 4 digits form the first row from left to right, the next 4 digits form the second row, and so on).- Starting at the top-left cell (
row = 0,column = 0), apply the 6 characters ofdirectionsin order:
'D'increments the row by 1.'R'increments the column by 1.- Record the sequence of digits visited along the path (including the starting cell), producing a sequence of length 7.
The integer
xis considered good if the recorded sequence is non-decreasing.Return an integer representing the number of good integers in the range
[l, r].
1 |
|