Array contains elements that differ by K correctness proof
My line of thought for deriving this algo:


there is well-known Merge algo (part of Merge Sort) combining two sorted arrays
we can modify it to output only equal elements of arrays (i.e. producing intersection instead of union)
we can further modify it to return true on the first match, and false at the end
and finally, we can modify it to compare elements with given offset k


I suggest you to practice developing algos at leetcode or similar site, it will allow you to come up with similar solutions in a few minutes.