Please explain why my code is failing for last test case.

Hey,all

Can someone help me in finding the error in logic as my last case is not passing.
Any help would be appreciated.

My logic

I have taken two set one set will contain all the ingredients found on islands is it size comes out not equal to k then we will print sad.

If it’s size becomes equal to k then we will check the size of other set is n if it is n it means we have taken ingredients from every islands so the size becomes n which is equal to no of islands so we will print all.

else we will print sad.

PROBLEM

My Solution