Efficient JS Solution | Fully Explained 💯 | Runtime (57ms) 🔥💯
Intuition\nThis code calculates the furthest distance from the origin (0) based on a sequence of moves (\'L\' for left, \'R\' for right, and any other character
# Intuition\nThis code calculates the furthest distance from the origin (0) based on a sequence of moves (\'L\' for left, \'R\' for right, and any other character for a diagonal move). The goal is to determine the maximum distance reached from the origin after making these moves.\n# Approach\n1. Initialize two distance variables: distance and distance2, both initially set to 0. These represent two hypothetical positions based on different movement scenarios.\n\n2. Iterate through each direction in the moves array.\n\n    - If direction is \'L\', decrement both distance and distance2.\n    - If direction is \'R\', increment both distance and distance2.\n    - For any other direction, decrement distance and increment distance2.\n3. Calculate the maximum of the absolute values of distance and distance2. This represents the furthest distance from the origin.\n\n4. Return the calculated maximum distance.\n# Complexity\n- Time complexity: `O(n)`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: `O(1)`\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * @param {string} moves\n * @return {number}\n */\nvar furthestDistanceFromOrigin = function(moves) {\n    let distance = 0, distance2 = 0;\n    \n    for (let direction of moves) {\n        if (direction === \'L\') distance--, distance2--;\n        else if (direction === \'R\') distance++, distance2++;\n        else distance--, distance2++;\n    }\n    \n    return Math.max(Math.abs(distance), Math.abs(distance2))\n};\n```
['JavaScript']