Created
July 21, 2025 12:55
-
-
Save enderahmetyurt/8f2ef543cab70a38ec6832eec7bc5d8e to your computer and use it in GitHub Desktop.
Given an array of parts where each part is { name, arrivalDays, assemblyHours }, return the minimum total hours needed to finish assembling all parts, starting from hour 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def minimum_assembly_time(parts) | |
parts | |
.map { |part| part.merge(arrival_hours: part[:arrival_days] * 24) } | |
.sort_by { |part| [part[:arrival_hours], part[:assembly_hours]] } | |
.reduce(0) { |time, part| [time, part[:arrival_hours]].max + part[:assembly_hours] } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment