So idea:
You iterate over the smallest array, at each step, you are in one of 3 situations
arr1[i] == arra2[j] // you increment i and j because of the invariant, that says the arrays are sorted, so if you found a match you can safely increment.
arr1[i] < arr2[j] // since at index i we have the smallest element, we increment that one because being sorter we ca safely increment until we hit what is at index j or greater
arr1[i] < arr2[j] // same as above only for j
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Python solution, not in a nice format, and assuming the input are two integer arrays:
So idea:
You iterate over the smallest array, at each step, you are in one of 3 situations
arr1[i] == arra2[j] // you increment i and j because of the invariant, that says the arrays are sorted, so if you found a match you can safely increment.
arr1[i] < arr2[j] // since at index i we have the smallest element, we increment that one because being sorter we ca safely increment until we hit what is at index j or greater
arr1[i] < arr2[j] // same as above only for j