LeetCode Solutions/LeetCoding Challenge/March 2020 LeetCoding Challenge/Russian Doll Envelopes.java
class Solution {
    public int maxEnvelopes(int[][] envelopes) {
        Arrays.sort(envelopes, (a,b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);
        int[] dp = new int[envelopes.length];
        int maNumberOfEnvelopes = 0;
        for(int[] env : envelopes){
            int height = env[1];
            int left = Arrays.binarySearch(dp, 0, maNumberOfEnvelopes, height);
            if(left < 0){
                left = -left - 1;
            }
            if(left == maNumberOfEnvelopes){
                maNumberOfEnvelopes++;
            }
            dp[left] = height;
        }
        return maNumberOfEnvelopes;
    }
}