In @TianhaoSong's original code, can we ALWAYS depends on this logic to populate the height values into this "dp" array ? It seems to me she is manipulating the returning "index" value for where to put the next height value ?

"

....

for(int[] envelope : envelopes){

int index = Arrays.binarySearch(dp, 0, len, envelope[1]);

if(index < 0)

index = -(index + 1);

dp[index] = envelope[1];

if(index == len)

len++;

}

return len;

"

Russian Doll Envelopes