Skip to content

Instantly share code, notes, and snippets.

View alex-rogachev's full-sized avatar

Oleksandr Rohachev alex-rogachev

View GitHub Profile
@alex-rogachev
alex-rogachev / solution.rb
Last active February 28, 2019 14:32
Minimum grid path solution
# Given a m x n grid filled with non-negative numbers, find a path from top left
# to bottom right which minimizes the sum of all numbers along its path.
def minimum_path_sum(grid)
m, n = detect_grid_size(grid)
validate_grid!(grid, n)
# Prepare table that contains path cost
path_cost = Array.new(m) { Array.new(n) { 0 } }