beat 100% runtime for swift solution
IntuitionWe are given an array of integers, and we need to find the maximum difference between two elements such that the larger element comes after the smaller
# Intuition
We are given an array of integers, and we need to find the maximum difference between two elements such that the larger element comes after the smaller element. The key idea is to track the minimum value encountered so far as we iterate through the array, and for each element, calculate the difference with this minimum value. We then keep track of the maximum difference found.

# Approach
1. Initialize a variable to keep track of the minimum value encountered so far.
2. Initialize a variable to store the maximum difference found.
3. Iterate through the array. For each element:
   - Update the minimum value if the current element is smaller.
   - Calculate the difference between the current element and the minimum value.
   - Update the maximum difference if the calculated difference is greater.
4. Return the maximum difference found. If no valid difference is found (i.e., array elements are non-increasing), return -1.

# Complexity
- Time complexity: O(n), where n is the number of elements in the array. We only iterate through the array once.

- Space complexity: O(1). We are using a constant amount of extra space.

# Code
```swift []
class Solution {
    func maximumDifference(_ nums: [Int]) -> Int {
        // Initialize the minimum value with the first element
        var minVal = nums[0]
        // Initialize the maximum difference with -1
        var maxDiff = -1
        
        // Iterate through the array starting from the second element
        for i in 1..<nums.count {
            // If the current element is greater than the minimum value,
            // calculate the difference and update maxDiff if needed
            if nums[i] > minVal {
                maxDiff = max(maxDiff, nums[i] - minVal)
            } else {
                // Update the minimum value if the current element is smaller
                minVal = nums[i]
            }
        }
        
        // Return the maximum difference found or -1 if no valid difference
        return maxDiff
    }
}

```
['Swift']