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