Positive Mex April Lunchtime

getting TLE in my code for subTask 1 but gives AC for subTask 2
what’s wrong with my code?
link to code:

Thanks in Advance!