Simple Beginner Friendly Solution
\n\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\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```\nclass Solution {\n    public int furthestDistanceFromOrigin(String moves) {\n        //FIND MOST OCCURANCE OF \'L\' OR \'R\' TO REPLACE WITH \'_\' LATER.\n        int countL=0;\n        int countR=0;\n        for(int i=0;i<moves.length();i++){\n            if(moves.charAt(i)==\'L\')countL++;\n            else if(moves.charAt(i)==\'R\')countR++;\n        }\n        //IF \'R\' IS MOST OCCURED THEN WE REPLACE ALL \'_\' WITH 1 ELSE -1\n        //WE WILL USE VALUE OF UNDER WHILE TRAVERSING THE STRING\n        int under=countL<=countR?1:-1;\n        //TRAVERSE THE STRING NOW,\n         int position=0;\n         for(int i=0;i<moves.length();i++){\n            if(moves.charAt(i)==\'L\')position--;\n            else if(moves.charAt(i)==\'R\')position++;\n            //USE OF UNDER\n            else position=position+under;\n        }\n        //RETURN ABSOULTE VALUE\n        return Math.abs(position);\n    }\n}\n```
['Java']