LeetCode solutions

2144. Maximum Difference Between Increasing Elements

My accepted C++ solution to LeetCode problem 2144, Maximum Difference Between Increasing Elements, running in 0ms.

  • Difficulty: Easy
  • C++
  • Runtime 0ms
  • Memory 11.9MB

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 11.9MB, accepted 2025-12-27.

cpp
class Solution {
public:
    int maximumDifference(vector<int>& nums) {
        int minVal = nums[0], maxDiff = -1;
        for (int i = 1; i < nums.size(); i++) {
            if (nums[i] > minVal) maxDiff = max(maxDiff, nums[i] - minVal);
            minVal = min(minVal, nums[i]);
        }
        return maxDiff;
    }
};

Source