Not able to code

Not able to code this problem

hi @shubham.gupta29062002,
logic is same as i told above from one island group you need to go to another ,
suppose the size of island would have been 1 only (i.e 1 cell only) then the question becomes shortest path between 2 cell right? so u can use BFS directly.
But here the island group contains more than 1 cell so u r not able to visualize.
Consider whole thing as 1 group and first insert all the members in the queue ( for size 1 u just insert 1 cell but here insert all) now start doing BFS as soon as you reach the other group stop and return the steps you took

same has been implemented here https://ide.codingblocks.com/s/661183 ive commented the above logic here also do a dry run you’ll get it

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.