Skip to content
Merged

3010 #11

Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @param {Integer[]} nums
# @return {Integer}
def minimum_cost(nums)
# we have to pick the first one
first = nums[0]
# to get min-cost we need to pick 2 minimum from [1...nums.size] to divide 2 sub-arrays
second = Float::INFINITY
third = Float::INFINITY
nums[1..].each { |num|
if num < second
third = second
second = num
elsif num < third
third = num
end
}

first + second + third
end