Maximum Length of Pair Chain LeetCode solution in JavaScript
1class Solution {2public:3int findLongestChain(vector<vector<int>>& arr) {45if(arr.size()==1)6{7return 1;8}9vector<pair<int,int>>v;10for(int i=0;i<arr.size();i++)11{12v.push_back({arr[i][0],arr[i][1]});13}14sort(v.begin(),v.end());1516vector<int>dp(v.size(),0);17int ans=INT_MIN;18dp[0]=1;19for(int i=1;i<v.size();i++)20{21int temp=0;22for(int j=i-1;j>=0;j--)23{24if(v[j].second<v[i].first)25{26temp=max(temp,dp[j]);27}28}29dp[i]=1+temp;30ans=max(ans,dp[i]);31}32return ans;33}34};