1
const binarySearch = (arr, target) => {3
let right = arr.length - 1;5
while (left <= right) {6
const mid = Math.floor((left + right) / 2);7
if (arr[mid] === target) {10
if (arr[mid] < target) {20
var maxEnvelopes = function (envelopes) {21
envelopes.sort((a, b) => (a[0] === b[0] ? b[1] - a[1] : a[0] - b[0]));22
const sub = [envelopes[0][1]];24
for (let envelope of envelopes) {25
if (envelope[1] > sub[sub.length - 1]) {26
sub.push(envelope[1]);28
const replaceIndex = binarySearch(sub, envelope[1]);29
sub[replaceIndex] = envelope[1];