Freshworks interview question

Island problem using graphs or dp