This post originally appeared on Arjun Rajkumar's blog. Arjun runs web development company based in Bangalore, India.
--
Day 5: Question 1 & Question 2 are from Advent of code:
https://adventofcode.com/2018/day/1/answer
My answers are in the comments.
Top comments (1)
Logic for part 2:
Storing the summed frequencies as a hash as hash key lookup is faster than instead of doing an array.include? each time to check if sum already repeated.
Have to benchmark and test if this is true.
Time is O[n] as has to go thru each line in file multiple times.
Space is O[m] - m is sums.