You are viewing a single comment's thread. Return to all comments →
And you can easily make solution "sparse" to conserve memory on big arrays, just replace
arr = Array.new(N + 1, 0)
with
arr = Hash.new(0)
and
arr.each do |value|
1.upto(N) do |n| value = arr[n]
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
And you can easily make solution "sparse" to conserve memory on big arrays, just replace
arr = Array.new(N + 1, 0)
with
arr = Hash.new(0)
and
arr.each do |value|
with
1.upto(N) do |n| value = arr[n]