Be Greedy Made Easy! 😆🔥
IntuitionYou start at (0,0) and move based on the given directions (N, S, E, W).
Keep track of your distance from the starting point.
You have k extra moves tha
# Intuition

<!-- Describe your first thoughts on how to solve this problem. -->
You start at (0,0) and move based on the given directions (N, S, E, W).

- Keep track of your distance from the starting point.
- You have k extra moves that can help you go farther.
- At each step, check how far you are and whether using extra moves increases your distance.
- Keep updating the maximum distance you can reach.
- In the end, return the farthest distance possible! 🚀
# Approach
<!-- Describe your approach to solving the problem. -->
**Track Movement**: Start at (0,0) and update x and y based on directions (N, S, E, W).

**Calculate Distance**: After each move, compute the Manhattan distance:

    distance=∣x∣+∣y∣
**Use Extra Moves (k)**: Try extending the distance using extra k moves (each move can add 2 to the distance).

**Keep Track of Maximum Distance**: Update the maximum distance found at each step.

**Return the Maximum**: The farthest distance reached is the answer.
# 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
```python3 []
class Solution:
    def maxDistance(self, s: str, k: int) -> int:
        # (x, y) represents the current position, starting at (0,0)
        x, y = 0, 0  
        
        # Stores the maximum distance from the origin
        maxi = 0  
        
        # Keeps track of the number of moves made
        move_count = 1  
        
        # Loop through each character in the input string
        for direction in s:
            # Move in the respective direction
            if direction == 'N':  # Move up
                y += 1
            elif direction == 'W':  # Move left
                x -= 1
            elif direction == 'S':  # Move down
                y -= 1
            else:  # Move right ('E')
                x += 1
            
            # Calculate the current Manhattan distance from the origin
            curr_distance = abs(x) + abs(y)
            
            # Update the maximum distance considering:
            # - The current distance
            # - The potential extra distance that can be covered using 'k' extra moves
            maxi = max(maxi, curr_distance, min(move_count, curr_distance + (k * 2)))
            
            # Increment the move counter
            move_count += 1  

        # Return the maximum distance reached
        return maxi

```


![upvote2.png](https://assets.leetcode.com/users/images/26e16a56-16a4-4252-8826-57eb0fb98cb2_1738472091.5505302.png)
['Python3']