Importance of sorting

If we are checking every possible configuration for boy to get paired then whats significance of sorting here ?

we are actually not checking every permutation! hence sorting is necessary!
try this if n=5 and m=5
1 2 3 4 5
5 4 3 2 1

at every point either we are selecting a girl or not selecting it so how its not checking every configuration?

We don’t take every permutation (as there are N! permutations), instead we take every possible selection!
think this way : let n=2,m=3
then possible inputs are ; 1,2 and 1,2,3
or 1,2 and 2,1,3
or 2,1 and 3,2,1
or …
now when you sort both arrays, all these inputs become equivalent!
Hence sorting is necessary.
If your doubt is cleared mark it as resolved