0ms Faster Solution Using Hashmaps
Intuition\n Describe your first thoughts on how to solve this problem. \n- The furthest distance we can reach depends on the difference between the number of \'
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- The furthest distance we can reach depends on the difference between the number of \'R\' and \'L\' moves, as well as how we strategically utilize the \'_\' moves.\n- We don\'t need to track the exact positions after each move; we only need to know the net difference between \'R\' and \'L\' moves to determine the furthest distance.\n![image.png](https://assets.leetcode.com/users/images/60074a0e-8b42-4578-8a7f-a11b9539260b_1706504541.2361991.png)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Count the occurrences of each move: Create a map to efficiently count the occurrences of \'L\', \'R\', and \'_\' moves in the string.\n2. Determine the dominant direction: Check if there are more \'R\' moves or \'L\' moves.\n3. Calculate the furthest distance: Add the number of \'_\' moves to the count of the dominant direction. Subtract the count of the opposite direction to account for the net movement. This gives us the furthest distance from the origin.\n\n# Complexity\n- Time complexity: O(n), where n is the length of the string. We iterate through the string once to count the moves.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n \n- Space complexity: O(1), as the map\'s size is bounded by the three possible characters (\'L\', \'R\', and \'_\'), regardless of the input string\'s length.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfunc furthestDistanceFromOrigin(moves string) int {\n    movesMap := make(map[rune]int)\n    for _, move := range moves {\n        movesMap[move]++\n    }\n    if movesMap[\'R\'] > movesMap[\'L\'] {\n        return movesMap[\'_\'] + movesMap[\'R\'] - movesMap[\'L\']\n    } else {\n        return movesMap[\'_\'] + movesMap[\'L\'] - movesMap[\'R\']\n    }\n    return 0\n}\n```
['Hash Table', 'Go']