I came across this questions twice at interview questions, I panicked the first time , but managed to solve part of the use cases on the second time using an iterative way.<