Simple Loop Problem| TC:0(n) | SC:0(1) with hints
Intuition\nThink that you are moving one left and then one right and then one step left .So Mathmatically you move one distance i.e.   1 .\n\nUnderscore is just
# Intuition\nThink that you are moving one left and then one right and then one step left .So Mathmatically you move one distance i.e.   1 .\n\nUnderscore is just distance either left or right .\nSo add all Underscore to 1 as above total distance form left and right came.\n\nThis will give you furthest distance.\n\n\n\n# Approach\nhere we use simple iterative approch by taking a for loop.\nStep1-check left and right and increase it\'s left and right count.\n      and dash( _ ) represents both ,so count it seprately.\n\nStep2-Take a difference of left and right in modulus .\n\nStep3-The difference represents how much steps taken form origin by taking left and right.Still We are not counting dash( _ ).\n \nStep4- Now we count dash( _ )  by adding lmove + rmove   and substract  it by total length . So you will get dash ( _ ).\n\nStep 5- Now you have only return int.\n        So total move form Left and right are stored.\n\n(total_LR_dis_move ) tells that how you have travelled from left and right.\nEx- LR , if you move one left and one right . so total is 1-1=0\nyou are now at origin.\n Now add dash( _ ) and total_LR_dis_move .\n\n# Complexity\n- Time complexity:0(n)\n\n- Space complexity0(1):\n\n# Code\n```\nclass Solution {\n      public int furthestDistanceFromOrigin(String s) {\n      int ans=0;\n      int lmove=0;\n      int rmove=0;\n      for(int i=0;i<s.length();i++){\n         char ch= s.charAt(i);\n        if(ch == \'L\'){\n          lmove++;\n        }\n        if(ch==\'R\'){\n            rmove++;\n        }\n      }\n      int dashmove=s.length()-(lmove+rmove); // Step-4\n\n      int total_LR_dis_move=Math.abs(lmove-rmove) // Step-5\n\n      return total_LR_dis_move + dashmove;  \n\n   \n\n    }\n}\n```
['Java']