I am trying this problem. The way I do it is similar to the mentioned one. Also, the program has produced the same outputs for sample cases and some special cases of testing out of the land.
Would anyone kindly tell more special logics or checkings I missed out?