[HAI] week3 intersection array

https://www.interviewbit.com/problems/intersection-of-sorted-arrays/
This commit is contained in:
2024-12-08 21:12:56 +03:00
parent 656b5c6eb5
commit 807a5ae9cf
4 changed files with 146 additions and 0 deletions
@@ -0,0 +1,20 @@
export function intersectionSortedArray(a: number[], b: number[]): number[] {
let res: number[] = [];
let aI = 0;
let bI = 0;
while (aI < a.length && bI < b.length) {
let aValue = a[aI];
let bValue = b[bI];
if (aValue === bValue) {
res.push(aValue);
aI++;
bI++;
} else {
aValue < bValue ? aI++ : bI++;
}
}
return res;
};