Skip to content

Instantly share code, notes, and snippets.

@toantd90
Last active April 7, 2023 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toantd90/7c0a8564c577de97f5d0424dc5b576c3 to your computer and use it in GitHub Desktop.
Save toantd90/7c0a8564c577de97f5d0424dc5b576c3 to your computer and use it in GitHub Desktop.
function upperBound(arr, start, end, value) {
while (start <= end) {
const mid = start + Math.floor((end - start) / 2);
if (arr[mid] > value) {
end = mid - 1;
} else {
start = mid + 1;
}
}
return end;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment