[reference answer link](https://github.com/wzhishen/cracking-the-coding-interview/blob/master/src/chap17/Q13.java)