Easy 4 Lines Code explained
Approach\nThis code calculates the furthest distance from the origin based on the input string of moves. It uses three counters to keep track of the different t
# Approach\nThis code calculates the furthest distance from the origin based on the input string of moves. It uses three counters to keep track of the different types of moves, iterates through the input string to count each type of move, and then calculates the final furthest distance using the counts of left, right, and other moves. The calculated furthest distance is returned as the result of the function\n\n\n# Complexity\n- Time complexity:\n O(n)\n\n- Space complexity:\n O(1)\n\n# Code\n```\nclass Solution {\n    public int furthestDistanceFromOrigin(String moves) {\n        int ll = 0;\n        int rl = 0 ;\n        int sl = 0;\n        for (char move : moves.toCharArray())\n        {\n            if(move == \'L\') ll++;\n            else if(move == \'R\') rl++;\n            else sl++;\n        }\n        return Math.abs(ll-rl) + sl;\n    }\n}\n```
['Java']