run time 0ms Beat 100%
IntuitionApproachComplexity
Time complexity: O(n)

Space complexity: O(1)
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: **O(n)**
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: **O(1)**
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int maximumDifference(vector<int>& nums) {
         int n = nums.size();


    int min_element = nums[0];
    int max_diff = -1; // Initialize to -1 to indicate no valid pair found

    for (int i = 1; i < n; i++) {
        if (nums[i] > min_element) {
            max_diff = max(max_diff, nums[i] - min_element);
        } else {
            min_element = nums[i];
        }
    }


   return max_diff;       
    }
};
```
['C++']