RGAND Cook Off

Here is what i was going to submit : https://ide.geeksforgeeks.org/aQXyWV3Xwq
Is this correct approach ? Question is locked atm. I was late by 4-5 seconds couldn’t check.