C++ Simple Maths
IntuitionTry making max horizontal and max vertical for any given point using k.Complexity
Time complexity:  O(n)

Space complexity:  O(n)
Code
# Intuition
Try making max horizontal and max vertical for any given point using k.


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

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

# Code
```cpp []
class Solution {
public:
    int maxDistance(string s, int k) {
        unordered_map<char,int>mp;
        int ans = 0,temp,temp_k,max_vert,min_vert,max_horz,min_horz;

        for(int i=0;i<s.size();i++){
            mp[s[i]]++;

            max_vert = max(mp['N'],mp['S']);
            min_vert = min(mp['N'],mp['S']);

            max_horz = max(mp['E'],mp['W']);
            min_horz = min(mp['E'],mp['W']);

            // distribute k to maximise score

            // Case 1: start distribution from verticals.
            temp_k = k;
            temp = max_vert+(min(min_vert,temp_k))-max(0,min_vert-temp_k);
            temp_k = max(0,k-min_vert);
            temp+= max_horz+(min(min_horz,temp_k))-max(0,min_horz-temp_k);
            ans = max(ans,temp);

            // Case 2 : start distribution from horizontals
            temp_k = k;
            temp = max_horz+(min(min_horz,temp_k))-max(0,min_horz-temp_k);
            temp_k = max(0,k-min_horz);
            temp+= max_vert+(min(min_vert,temp_k))-max(0,min_vert-temp_k);
            ans = max(ans,temp);
        }

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