Skip to content

Instantly share code, notes, and snippets.

@onpaws
Created November 12, 2019 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onpaws/d0310788b1b695869e687f804aefd2fe to your computer and use it in GitHub Desktop.
Save onpaws/d0310788b1b695869e687f804aefd2fe to your computer and use it in GitHub Desktop.
via https://news.ycombinator.com/item?id=21508927
A semi-common beginning programmer's exercise is to write a program that numbers the lines in a text file.
The naive solution will use O(n) space, while a bit more thought reveals that this can be done in constant
(to be really precise, O(log n) where n is the number of lines in the file) space.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment