Finally solved it . Am glad I thought the editorialist approach on my own.
Here is my solution
All the suggestions are welcomed
@taran_1407
Can we also solve this problem using two pointer approach? if yes can anyone guide me in implementing it, please? and if no, can you give viable reasons, please …