Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.22 KB

_3443. Maximum Manhattan Distance After K Changes.md

File metadata and controls

49 lines (36 loc) · 1.22 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : February 04, 2025

Last updated : February 04, 2025


Related Topics : Hash Table, Math, String, Counting

Acceptance Rate : 30.85 %


Solutions

Python

class Solution:
    def maxDistance(self, s: str, k: int) -> int:
        N, S, E, W = 0, 0, 0, 0
        output_max = 0

        for c in s :
            match c :
                case 'N' :
                    N += 1
                case 'S' :
                    S += 1
                case 'E' :
                    E += 1
                case 'W' :
                    W += 1
                case _ :
                    pass

            output_max = max(output_max, abs(N - S) + abs(E - W) + 2 * (min(k, min(N, S) + min(E, W))))

        return output_max