Created
July 27, 2022 05:15
-
-
Save karlaoh99/c675fd578a0995e9fd5983c2e60ded1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given two arrays A and B, return the indices at | |
which the two arrays intersect. If the two arrays | |
have no intersection at all, return null. | |
*/ | |
function findIntersection(listA, listB) { | |
let iA = listA.length - 1; | |
let iB = listB.length - 1; | |
while (iA >= 0 && iB >= 0) { | |
if (listA[iA] != listB[iB]) | |
break; | |
iA--; | |
iB--; | |
} | |
if (iA == listA.length - 1) return null; | |
return [iA + 1, iB + 1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment