paint-brush
Leetcode Problem Hacks: 881 Boats to Save Peopleby@Owen
268 reads

Leetcode Problem Hacks: 881 Boats to Save People

by Owen Collier-Ridge6mJanuary 14th, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

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 Collier-Ridge

Owen Collier-Ridge

@Owen

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

About @Owen
LEARN MORE ABOUT @OWEN'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Owen Collier-Ridge HackerNoon profile picture
Owen Collier-Ridge@Owen
Owen loves coding and writing about coding. Check out his course on APIs https://gum.co/learnapi

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Also published here