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