Skip to content

Instantly share code, notes, and snippets.

@codecakes
Created June 22, 2016 13:49
Show Gist options
  • Save codecakes/c3f26816a8603d292229d1bebae77f02 to your computer and use it in GitHub Desktop.
Save codecakes/c3f26816a8603d292229d1bebae77f02 to your computer and use it in GitHub Desktop.
Given a list of unsorted integers, find maximum binary string or maximum integer whichever comes highest
fn = (l, lo, hi, b) => {
if (lo<hi) {
mid = parseInt((lo+hi)/2);
fn(l, lo, mid, b);
fn(l, mid+1, hi, b);
}
else {
let c = l[lo].toString(2).match(/1+/gi).join('').length;
console.log(c, l[lo]);
if (b[0] < l[lo]) b[0] = l[lo];
}
};
b = [0];
fn(l, 0, l.length-1, b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment