Super frustrating OA, passed 9/11 cases (out of memory for the failed cases). Any ideas on how to improve time/space complexity? My implementation was O(N), O(N).