[C++] O(N) solution - explained w/ comments - beats 100%
Please UPVOTE if this helped you in any way!\ndiscussion and sugestions are welcomed!\nCHEERS!\n\nsee the code underneath for my solution marked with comments o
Please **UPVOTE** if this helped you in any way!\ndiscussion and sugestions are welcomed!\nCHEERS!\n\nsee the code underneath for my solution marked with comments on every step!\n\n# Complexity\n- Time complexity:\nO(N), where N is size of string moves\n\n- Space complexity:\nO(1), constant space complexity\n\n# Code\n```\nclass Solution {\npublic:\n    int furthestDistanceFromOrigin(string moves) {\n        \n        int n = moves.size();\n        int pos=0;  //pos represents final position by moving according to L nad R  \n        int cnt=0;  //cnt is the total no. of blanks \n        \n        for(int i=0; i<n; i++){\n            if(moves[i]==\'L\') pos--; //if char = L do pos=pos-1;  => move left\n            else if(moves[i]==\'R\') pos++; //if char = R do pos=pos+1;  => move right\n            else cnt++; //for blanks\n        }\n        \n        //get the absolute value of pos and add all cnt to that same direction to get max ans!\n        return abs(pos+0) + cnt; \n    }\n};\n```
['String', 'C++']