C++ | O(N) Time | O(1) Space
\nclass Solution {\npublic:\n    int maxScoreSightseeingPair(vector<int>& nums) {\n        int n=nums.size();\n        int prev=nums[0]; //as i<j so we can get 
```\nclass Solution {\npublic:\n    int maxScoreSightseeingPair(vector<int>& nums) {\n        int n=nums.size();\n        int prev=nums[0]; //as i<j so we can get max values at each index and calclulate for i+1\n        int ans=INT_MIN;\n        for(int i=1;i<n;i++){\n            ans=max(ans,prev+nums[i]-i); // main equation (nums[i]+i) +(nums[j]-j)\n            prev=max(prev,nums[i]+i); // maximum prev update to use it in next iterations\n        }\n        return ans;\n        \n    }\n};\n```\n\nTC- O(N)\nSC- O(1)
['Dynamic Programming', 'C', 'C++']