🎯 Maximum Distance After Converting Characters (Golang)
IntuitionThe key insight is that to maximize distance, we want to try each possible pair of directions (NE, NW, SE, SW) and see which one gives us the maximum f
# Intuition
The key insight is that to maximize distance, we want to try each possible pair of directions (NE, NW, SE, SW) and see which one gives us the maximum favorable moves. For each pair, we want to:
1. Count moves that are already going in our target directions
2. Use our K operations to convert opposing moves when possible
3. Take a penalty for opposing moves we can't convert

# Approach
1. Try all possible direction pairs (NE, NW, SE, SW)
2. For each pair:
   - Keep track of moves that help us go in our target directions
   - When we see a target direction (e.g., N or E for NE pair), increment our count
   - When we see an opposing direction:
     - If we have K left: convert it to help us (increment count)
     - If no K left: it works against us (decrement count)
   - Track the maximum favorable count at each step
3. The maximum value across all direction pairs gives us our answer

For example, with "NNSE" and k=1:
- For NE pair:
  - N: target direction (+1)
  - N: target direction (+1)
  - S: opposing, but can convert with k (+1)
  - E: target direction (+1)
  - Maximum = 4

# Complexity
- Time complexity: $$O(n)$$
  - We have 4 fixed direction pairs
  - For each pair, we process the string once
  - Total: O(4 * n) = O(n)

- Space complexity: $$O(1)$$
  - We only use a few variables regardless of input size
  - The directions array is fixed size (4 pairs)

# Code
```golang []
func maxDistance(s string, k int) int {
	maxDist := 0
	directions := [][2]string{
		{"N", "E"},
		{"N", "W"},
		{"S", "E"},
		{"S", "W"},
	}

	for _, d := range directions {
		remainingK := k
		favorableCount := 0

		for _, move := range s {
			moveStr := string(move)
			if moveStr == d[0] || moveStr == d[1] {
				// This move is already going in our target direction
				favorableCount++
			} else {
				// This move is going in the opposite direction
				if remainingK > 0 {
					// We can convert this opposing move to our target direction
					remainingK--
					favorableCount++
				} else {
					// Can't convert, this move works against our target direction
					favorableCount--
				}
			}
			maxDist = max(maxDist, favorableCount)
		}
	}

	return maxDist
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

```
['Go']