Created
June 22, 2016 13:49
-
-
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
This file contains hidden or 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
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