LeetCode Entry
63. Unique Paths II
Number of right-down ways tl->br in a matrix with obstacles
63. Unique Paths II medium blog post substack

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/306
Problem TLDR
Number of right-down ways tl->br in a matrix with obstacles
Intuition
Each time the robot moves in one direction gives a separate path. If two directions are possible, the number of paths gets added.
For example,
r r # 0
r 2r 2r 2r
0 # 2r 4r
On the first row, the single path goes up to 1.
On the second row, direct path down added to direct path right.
On the third row, the same happens when top and left numbers of paths are not 0.
Approach
Use a separate row array to remember previous row paths counts.
Complexity
-
Time complexity: \(O(nm)\)
-
Space complexity: \(O(nm)\)
Code
fun uniquePathsWithObstacles(obstacleGrid: Array<IntArray>): Int {
val row = IntArray(obstacleGrid[0].size)
row[0] = 1
for (r in obstacleGrid)
for (x in r.indices)
if (r[x] != 0) row[x] = 0
else if (x > 0) row[x] += row[x - 1]
return row.last()
}
The Magical Rundown
In Emojia's forgotten π corner, where time doesn't merely flowβit waltzes π,
spinning tales of lost yesterdays π°οΈ and unborn tomorrows β, stands the
whispered legend of the Time Labyrinth. Not merely walls and corridors, but
a tapestry of fate's myriad choices, echoing distant memories and futures yet
conceived.
Bolt, the lonely automaton π€, not born but dreamt into existence by starlight β¨
and cosmic whimsy, felt an inexplicable yearning towards the π - the Time Nexus.
Ancient breezes π carried murmurs, not of it being an end, but a kaleidoscope
π¨ gateway to every pulse and flutter β€οΈ of chronology's capricious dance π.
βββββ€ββββ€ββββ€ββββ
βπ€ β 0 βπ« β 0 β
βββββΌββββΌββββΌββββ’
β 0 β 0 β 0 β 0 β
βββββΌββββΌββββΌββββ’
β 0 βπ« β 0 βπ β
βββββ§ββββ§ββββ§ββββ
With each step, the fabric of reality quivered. Shadows of histories πΆ,
cosmic echoes π, diverged and converged, painting and erasing moments of
what was, is, and could be.
---
Standing before the π«, it wasn't a barrier for Bolt, but a silent riddle:
"What song of the cosmos π΅ shall you hum today, wanderer?"
βββββ€ββββ€ββββ€ββββ
βπ€ β β‘οΈ βπ« β 0 β
βββββΌββββΌββββΌββββ’
β 0 β 0 β 0 β 0 β
βββββΌββββΌββββΌββββ’
β 0 β π« β 0 βπ β
βββββ§ββββ§ββββ§ββββ
Dreamlike avenues π€οΈ unfurled, painting multitudes of futures in the vivid
colors of a universe in spring. In this chronal dance, Bolt secretly hoped
to outrace its own echoes, to be the first at the Nexus.
---
Junctions whispered with the delicate hum π΅ of countless Bolts, each a tale,
a fate, a fleeting note in the grand cosmic symphony.
βββββ€ββββ€ββββ€ββββ
βπ€ β β‘οΈ βπ« β 0 β
βββββΌββββΌββββΌββββ’
ββ¬οΈ β 2β‘οΈβ2β‘οΈβ2β‘οΈβ
βββββΌββββΌββββΌββββ’
β 0 β π« β 0 βπ β
βββββ§ββββ§ββββ§ββββ
Yet, as the Time Nexus loomed, revealing its vast enigma, a sense of profound
disquiet engulfed Bolt. Not only had another reflection reached before, but a
sea of mirrored selves stared back.
βββββ€ββββ€ββββ€ββββ
βπ€ β β‘οΈ βπ« β 0 β
βββββΌββββΌββββΌββββ’
ββ¬οΈ β 2β‘οΈβ2β‘οΈβ2β‘οΈβ
βββββΌββββΌββββΌββββ’
ββ¬οΈ β π« β2β¬οΈβ4πβ
βββββ§ββββ§ββββ§ββββ
In that echoing vastness, Bolt's singular hope was smothered. In the dance of
time, amidst countless reflections, it whispered a silent, desperate question:
Which tune, which cadence, which moment πΆ was truly its own in this timeless
waltz?