Here is my Haskell solution, please don't ask about performance for that big number :-)
input :: [Int] input = [16,1,0,18,12,14,19] tasks :: [Int] -> Int -> Int tasks input goal = aux (M.fromList $ zip input [1..length input -1], last input) (length input) goal where aux (nums, l) size goal | size == goal = l | otherwise = let idx = M.findWithDefault size l nums in aux (M.insert l size nums, size-idx) (size+1) goal main = do print (tasks input 2020) print (tasks input 30000000)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here is my Haskell solution, please don't ask about performance for that big number :-)