Leetcode Problem Hacks: 881 Boats to Save Peopleby@Owen

Leetcode Problem Hacks: 881 Boats to Save People

tldt arrow
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

The problem is perfectly suited for Count Sort, a special sorting algorithm that works against data that is guaranteed to fit into a fixed range. Count Sort is one of my favorite algorithms because for the right data it is a sort that works in linear time, that’s O(n) in both time and space complexity. My stable count sort solution solved the problem in 552ms and 21.1 MB of memory: #Count Sort count = [ 0 ]*(limit+ 1 ) for i in people: count[i] += 1 p = 0 for p in range(len(people)

Company Mentioned

Mention Thumbnail
featured image - Leetcode Problem Hacks: 881 Boats to Save People
Owen Collier-Ridge HackerNoon profile picture

@Owen

Owen Collier-Ridge

Owen loves coding and writing about coding. Check out his course on APIs https://gum.co/learnapi


Receive Stories from @Owen

react to story with heart

RELATED STORIES

L O A D I N G
. . . comments & more!