#2194

Cells in a Range on an Excel Sheet

newbie · 145 · lc easy +13 · verified · 84.2% accepted · 649 likes · top 96%

Description

A cell (r, c) on an Excel sheet is represented as a string "<col><row>" where:

- <col> is the column letter. Column 1 is 'A', column 2 is 'B', and so on.

- <row> is the row number r.

You are given a string s in the format "<col1><row1>:<col2><row2>" where r1 <= r2 and c1 <= c2.

Return the list of all cells (x, y) with r1 <= x <= r2 and c1 <= y <= c2, sorted first by column and then by row within each column.

Example 1:

Input: s = "K1:L2"
Output: ["K1","K2","L1","L2"]
Explanation:
The above diagram shows the cells which should be present in the list.
The red arrows denote the order in which the cells should be presented.

Example 2:

Input: s = "A1:F1"
Output: ["A1","B1","C1","D1","E1","F1"]
Explanation:
The above diagram shows the cells which should be present in the list.
The red arrow denotes the order in which the cells should be presented.

Code

1
2
3