LeetCode Entry
3963. Create Grid With Exactly One Path
Any maze with single path
3963. Create Grid With Exactly One Path easy substack youtube
https://dmitrysamoylenko.com/leetcode/

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1524
Problem TLDR
Any maze with single path
Intuition
Top row and rigthmost column is free, others are walls
Approach
- repeat and string concatenation works the same on Rust and Kotlin
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(n)\)
Code
fun createGrid(m: Int, n: Int) =
List(m){if (it<1)".".repeat(n) else "#".repeat(n-1)+"."}
pub fn create_grid(m: i32, n: i32) -> Vec<String> {
(0..m).map(|i| if i<1{ ".".repeat(n as usize)}else{"#".repeat(n as usize-1)+"."}).collect()
}
Comments