code: function longestIncreasingSubsequence(a) {
  	var p = a.slice();
  	var result = [];
  	result[0] = 0;
  	var n = 0;
  	var u;
  	var v;
  	var j;
  
  	for (var i = 0; i < a.length; ++i) {
  		var k = a[i];
  //		if (k > -1) {
  			j = result[n];
  			if (a[j] < k) {
  				p[i] = j;
  				result[++n] = i;
  			} else {
  				u = 0;
  				v = n;
  
  				while (u < v) {
  					j = (u + v) >> 1;
  					if (a[result[j]] < k) {
  						u = j + 1;
  					} else {
  						v = j;
  					}
  				}
  
  				if (k < a[result[u]]) {
  					if (u > 0) {
  						p[i] = result[u - 1];
  					}
  					result[u] = i;
  				}
  			}
  //		}
  	}
  
  	v = result[n];
  
  	while (n >= 0) {
  		result[n--] = v;
  		v = p[v];
  	}
  
  	return result;
  }
docs: https://en.wikipedia.org/wiki/Longest_increasing_subsequence impl borrowed from https://github.com/ivijs/ivi