From acadb4dc1beabde3b57fafa896fe8f03901d876e Mon Sep 17 00:00:00 2001 From: Xtha-Sunil Date: Wed, 30 Oct 2024 23:20:30 +0545 Subject: [PATCH] Added solution for furthest point from origin. --- C++/furthest-point-from-origin.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 C++/furthest-point-from-origin.cpp diff --git a/C++/furthest-point-from-origin.cpp b/C++/furthest-point-from-origin.cpp new file mode 100644 index 0000000..f3404e6 --- /dev/null +++ b/C++/furthest-point-from-origin.cpp @@ -0,0 +1,26 @@ +class Solution { +public: + int furthestDistanceFromOrigin(string moves) { + int l=0,r=0,avl=0; + for(auto i:moves){ + if(i=='L'){ + l++; + } + else if(i=='R'){ + r++; + } + else{ + avl++; + } + } + if(l>r){ + l+=avl; + return l-r; + } + else if(r>l){ + r+=avl; + return r-l; + } + return avl; + } +}; \ No newline at end of file