https://medium.com/@msoni6226/cracking-the-coding-interview-book-problem-series-problem-15-a6087ceb7f53