Solution in java | Beats 100.00%of users with Java in run time | O(n) and O(1)
Intuition\n Describe your first thoughts on how to solve this problem. \nWhile reading the question for the first time, it is obvious that we need to take appro
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWhile reading the question for the first time, it is obvious that we need to take appropriate decision regarding the underscore(_), so the first intution is to see what could be the best decision at a given position\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIn this approach I have calculated total left moves, right moves and \nUnderscore moves. Now, if right move is greater than left then we will return right - left + underscore moves, if left is greater than right then return left - right + underscore and if they are equal we will simply return underscores. This solution works because we have to give underscore the value according to maximum movement.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\n    public int furthestDistanceFromOrigin(String moves) {\n         int l=0,r=0;\n         int temp=0;\n    for(int i =0; i<moves.length(); i++){\n        if(moves.charAt(i)==\'L\') l++;\n        else if(moves.charAt(i)==\'R\') r++;\n        else temp++;\n    }\n    if(l>r) return l-r+temp;\n    else if(r>l) return r-l+temp;\n    else return temp;\n    }\n}\n```
['Java']