If you have a better/ different solution, please share your solution in the comment.
Youtube playlist for more coding challenge like this: https://www.youtube.com/watch?v=jzVoFUwlMZg&list=PL13Vva6TJcSsZtUipeopvYnNd0zzg4wbT
Github Code Repository for coding challenge: https://github.com/premaseem/AlgoAndDataStructureInJava/tree/master/src/codechallenge/easy
For details visit: www.premaseem.wordpress.com