Created
March 12, 2020 12:17
-
-
Save Lelith/4af31f0d78a68d915884fb493bf18882 to your computer and use it in GitHub Desktop.
non overlapping segments
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
function solution(A, B) { | |
// write your code in JavaScript (Node.js 8.9.4) | |
if(A.length === 1 ){ | |
return 1; | |
} else if(A.length ===0){ | |
return 0; | |
} | |
let nonOverlapping = 1; | |
let prevEnd = B[0]; | |
for (let curr = 1; curr < A.length; curr++){ | |
if (A[curr] > prevEnd){ | |
nonOverlapping++; | |
prevEnd = B[curr]; | |
} | |
} | |
return nonOverlapping; | |
} | |
try { | |
const A = [1,3,7,9,9]; | |
const B = [5,6,8,9,10]; | |
console.log(solution(A,B)); | |
}catch(err){console.log(err)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment