2025-08-17 16:21:20 +0000 UTC

Cells in a Range on an Excel Sheet

Code

class Solution:
    def cellsInRange(self, s: str) -> List[str]:
        cell1, cell2 = s.split(":")
        row1, col1 = cell1[0], int(cell1[1:])
        row2, col2 = cell2[0], int(cell2[1:])
        res = []
        while row1 <= row2:
            for col in range(col1, col2 + 1):
                res.append(f"{row1}{col}")
            row1 = chr(ord(row1) + 1)
        return res