#2194
Easy Algorithms Cells in a range on an excel sheet
String
84.2% acceptance
Feb 25, 2026
649
100
A cell (r, c) of an excel sheet is represented as "".
You are given a string s = ":" where r1 <= r2 and c1 <= c2.
Return the list of cells (x,y) such that r1 <= x <= r2 and c1 <= y <= c2,
sorted by columns then rows.
Solution
Rust
Time O(n²)
Space O(n)
impl Solution {
pub fn cells_in_range(s: String) -> Vec<String> {
let bytes = s.as_bytes();
let c1 = bytes[0];
let r1 = bytes[1];
let c2 = bytes[3];
let r2 = bytes[4];
let mut result = Vec::new();
for c in c1..=c2 {
for r in r1..=r2 {
result.push(format!("{}{}", c as char, r as char));
}
}
result
}
}