Easy C++ solution || Easy approach || Time - O(N)
IntuitionTo maximize the Manhattan distance after up to k changes, we consider four key scenarios that represent different quadrants of movement. These scenario
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
To maximize the Manhattan distance after up to k changes, we consider four key scenarios that represent different quadrants of movement. These scenarios help track the maximum possible sum of directional contributions, which directly translates to the Manhattan distance.

# Approach
<!-- Describe your approach to solving the problem. -->
Four Scenarios: We track four possible directions (NE, NW, ES, SW) which correspond to maximizing combinations of x and y coordinates:

NE: Maximizing x + y (North and East)

NW: Maximizing -x + y (West and North)

ES: Maximizing x - y (East and South)

SW: Maximizing -x - y (West and South)

Dynamic Updates: For each character in the string, we update each scenario's current sum and remaining changes (k). If we can change the direction to benefit the scenario, we do so (using a change), otherwise, we take the original direction's effect.

Track Maximum: After each step, compute the maximum value among all four scenarios and update the global maximum.
# Complexity
Time Complexity: O(n), where n is the length of the string. Each character is processed once with constant time operations for each scenario.

Space Complexity: O(1), as we use a fixed number of variables to track the scenarios and changes.

# Code
```cpp []
class Solution {
public:
    int maxDistance(string s, int k) {
        // Track maximum sum for four scenarios: NW, NE, ES, SW
        int nw = 0, ne = 0, es = 0, sw = 0;
        // Track remaining changes for each scenario
        int nwk = k, nek = k, esk = k, swk = k;
        int maxAns = 0; // The maximum Manhattan distance found

        for (char ch : s) {
            // Update each scenario based on current character and remaining changes
            if (ch == 'N') {
                // For ES scenario: change 'N' to 'E' or 'S' to maximize (x - y)
                if (esk > 0) { es++; esk--; } else es--;
                // For SW scenario: change 'N' to 'W' or 'S' to maximize (-x - y)
                if (swk > 0) { sw++; swk--; } else sw--;
                // NE and NW scenarios benefit from 'N' as is
                ne++;
                nw++;
            } else if (ch == 'S') {
                // For NW scenario: change 'S' to 'N' or 'W' to maximize (-x + y)
                if (nwk > 0) { nw++; nwk--; } else nw--;
                // For NE scenario: change 'S' to 'N' or 'E' to maximize (x + y)
                if (nek > 0) { ne++; nek--; } else ne--;
                // ES and SW scenarios benefit from 'S' as is
                es++;
                sw++;
            } else if (ch == 'E') {
                // For NW scenario: change 'E' to 'W' or 'N' to maximize (-x + y)
                if (nwk > 0) { nw++; nwk--; } else nw--;
                // For SW scenario: change 'E' to 'W' or 'S' to maximize (-x - y)
                if (swk > 0) { sw++; swk--; } else sw--;
                // NE and ES scenarios benefit from 'E' as is
                ne++;
                es++;
            } else if (ch == 'W') {
                // For NE scenario: change 'W' to 'E' or 'N' to maximize (x + y)
                if (nek > 0) { ne++; nek--; } else ne--;
                // For ES scenario: change 'W' to 'E' or 'S' to maximize (x - y)
                if (esk > 0) { es++; esk--; } else es--;
                // NW and SW scenarios benefit from 'W' as is
                sw++;
                nw++;
            }
            // Update the maximum Manhattan distance found so far
            maxAns = max(maxAns, max({nw, ne, es, sw}));
        }
        return maxAns;
    }
};
```
['C++']