Store all prefixes of numbers from arr1 in a HashSet.

Example for 12345:

We get these prefixes by repeatedly dividing by 10.

Then for every number in arr2, keep removing digits from the end and check if that prefix exists in the set.

Example: