question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
count-number-of-teams | simple java solution | simple-java-solution-by-amir-ammar-ztks | \tclass Solution {\n\t\tpublic static int numTeams(int[] rating) {\n\t\t\tint n = rating.length;\n\t\t\tint [][] dp = new int[n][2]; // 0 smaller than, 1 greate | amir-ammar | NORMAL | 2022-03-23T20:56:49.821327+00:00 | 2022-03-23T20:56:49.821367+00:00 | 767 | false | \tclass Solution {\n\t\tpublic static int numTeams(int[] rating) {\n\t\t\tint n = rating.length;\n\t\t\tint [][] dp = new int[n][2]; // 0 smaller than, 1 greater than\n\t\t\tint ans = 0;\n\t\t\tfor (int i = 1; i < n; i++) {\n\t\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\t\tif(rating[i] < rating[j]){dp[i][0] += 1;ans+=d... | 4 | 0 | ['Dynamic Programming', 'Java'] | 2 |
count-number-of-teams | Java Solution with Explanation | java-solution-with-explanation-by-am0611-jaxv | \nclass Solution {\n public int numTeams(int[] ratings) {\n int total = 0;\n \n for(int i = 1; i < ratings.length; i++)\n {\n | am0611 | NORMAL | 2022-03-05T22:26:34.454117+00:00 | 2022-04-10T18:14:13.119576+00:00 | 481 | false | ```\nclass Solution {\n public int numTeams(int[] ratings) {\n int total = 0;\n \n for(int i = 1; i < ratings.length; i++)\n {\n // For ascending order -> rating[i] < rating[j] < rating[k]\n int leftLess = 0;\n int rightGreater = 0;\n \n ... | 4 | 0 | ['Java'] | 1 |
count-number-of-teams | C++ easy to understand solution | c-easy-to-understand-solution-by-maitrey-aosp | I tried the brute force solution first and as expected, it showed me an TLE (big discovery! as stupid me previously thought leetcode will give TLE above 10^9 an | maitreya47 | NORMAL | 2021-08-16T07:58:17.527108+00:00 | 2021-08-16T07:58:17.527137+00:00 | 440 | false | I tried the brute force solution first and as expected, it showed me an TLE (big discovery! as stupid me previously thought leetcode will give TLE above 10^9 and not 10^9 itself).\nAnyways, here is the optimal solution that traverses the vector and first calculates the number of ratings that are both less and greater t... | 4 | 1 | ['C', 'C++'] | 0 |
count-number-of-teams | Java O(n^2) and O(N) memory, beats 97% | java-on2-and-on-memory-beats-97-by-larun-tcc3 | For every element e in array \n\t1. For every element b before this where b < e\n - Coutn number of elements before b and less than b\n 2. For ever | larunrahul | NORMAL | 2021-06-22T06:33:44.810903+00:00 | 2021-06-22T06:33:44.810944+00:00 | 253 | false | For every element **e** in array \n\t1. For every element **b** before this where **b < e**\n - Coutn number of elements before b and less than b\n 2. For every element **b** before this where **b > e**\n - Coutn number of elements before b and greather than b\n\n```\npublic int numTeams(int[] ra... | 4 | 0 | [] | 0 |
count-number-of-teams | [DP, O(N^2)] JS Solution | dp-on2-js-solution-by-hbjorbj-lj1m | \n/*\nStringtly increasing subsequence of size 3 or \nStrictly decreasing subsequence of size 3 is a valid team.\nWe need to find all such subsequences.\n*/\nva | hbjorbj | NORMAL | 2021-06-05T02:03:45.186745+00:00 | 2021-06-05T02:03:45.186774+00:00 | 301 | false | ```\n/*\nStringtly increasing subsequence of size 3 or \nStrictly decreasing subsequence of size 3 is a valid team.\nWe need to find all such subsequences.\n*/\nvar numTeams = function(rating) {\n // dp1[i] = number of elements less than rating[i] in rating[0...i-1]\n // dp2[i] = number of elements greater than r... | 4 | 0 | ['JavaScript'] | 0 |
count-number-of-teams | C++ O(n log n) Using binary indexed tree (Fenwick tree) | c-on-log-n-using-binary-indexed-tree-fen-y5j3 | \nclass Solution {\npublic:\n void update(vector<int>&bit,int index,int val)\n {\n while(index < bit.size())\n {\n bit[index] += | objectobject | NORMAL | 2021-06-01T09:39:49.545391+00:00 | 2021-06-01T09:39:49.545426+00:00 | 201 | false | ```\nclass Solution {\npublic:\n void update(vector<int>&bit,int index,int val)\n {\n while(index < bit.size())\n {\n bit[index] += val;\n index += index&(-index);\n }\n }\n int prefix(vector<int>&bit,int index)\n {\n int sum = 0;\n while(index > 0... | 4 | 1 | [] | 0 |
count-number-of-teams | simple C++ sol with explaination || faster than 80% | simple-c-sol-with-explaination-faster-th-598x | We are basically storing the number of elements that are smaller and larger to the left of a particular element in an array dp.\nif in an array ith element is | saiteja_balla0413 | NORMAL | 2021-05-17T13:58:32.362029+00:00 | 2021-05-17T14:00:06.715325+00:00 | 293 | false | We are basically storing the number of elements that are smaller and larger to the left of a particular element in an array dp.\nif in an array ith element is greater than jth element then the number of triplets would be the number of elements less than the jth elements.\nsame would be the case for the decreasing subs... | 4 | 4 | ['Array'] | 0 |
count-number-of-teams | Simple Java Solution comparing optimization with brute-force version | simple-java-solution-comparing-optimizat-gs8w | optimization version\n\n public int numTeams(int[] rating) {\n int res=0;\n for(int i=1; i<rating.length-1; i++) {\n int inc1=0, inc | duck67 | NORMAL | 2021-02-13T14:00:39.153825+00:00 | 2021-02-14T01:59:15.143866+00:00 | 713 | false | 1. optimization version\n```\n public int numTeams(int[] rating) {\n int res=0;\n for(int i=1; i<rating.length-1; i++) {\n int inc1=0, inc2=0;\n int dec1=0, dec2=0;\n for(int j=0; j<rating.length;j++) {\n if(i>j) {\n if(rating[j] < rati... | 4 | 0 | ['Java'] | 1 |
count-number-of-teams | N^2 explained (with pictures) ^^ | n2-explained-with-pictures-by-andrii_khl-j82u | Time O(N^2), space O(N)\n\n\nint numTeams(vector<int>& r) \n{\n\tmap<int, int> m;\n\tfor(auto i{0}; i<size(r); ++i) \n\t{\n\t\tm[r[i]] = i;\n\t\tr[i] = distance | andrii_khlevniuk | NORMAL | 2020-11-23T15:15:09.172014+00:00 | 2021-02-03T20:55:27.880912+00:00 | 757 | false | **Time `O(N^2)`, space `O(N)`**\n\n```\nint numTeams(vector<int>& r) \n{\n\tmap<int, int> m;\n\tfor(auto i{0}; i<size(r); ++i) \n\t{\n\t\tm[r[i]] = i;\n\t\tr[i] = distance(begin(m), m.find(r[i]));\n\t}\n\n int out{0};\n\tfor(auto i{begin(m)}; i!=end(m); ++i)\n\t{\n\t\tauto L = r[i->second];\n\t\tauto R = distance(be... | 4 | 0 | ['C', 'C++'] | 1 |
count-number-of-teams | Python - Optimal solution easy to understand | python-optimal-solution-easy-to-understa-4q4y | python\nclass Solution:\n def numTeams(self, rating: List[int]) -> int:\n N = len(rating)\n\t\tif N < 3:\n return 0\n num_teams = 0\ | reupiey | NORMAL | 2020-11-09T17:27:02.984418+00:00 | 2020-11-09T17:27:02.984465+00:00 | 326 | false | ```python\nclass Solution:\n def numTeams(self, rating: List[int]) -> int:\n N = len(rating)\n\t\tif N < 3:\n return 0\n num_teams = 0\n for i in range(1, N - 1):\n middle = rating[i]\n inferiors_left, inferiors_right, superiors_left, superiors_right = 0, 0, 0, 0... | 4 | 0 | [] | 2 |
count-number-of-teams | Python | Super Easy Method | SortedList (Balanced Binary Tree) | python-super-easy-method-sortedlist-bala-hbnb | Python | Super Easy Method | SortedList (Balanced Binary Tree)\n\n\nfrom sortedcontainers import SortedList\nclass Solution:\n def findLH(self,B,x):\n | aragorn_ | NORMAL | 2020-08-18T22:17:20.104852+00:00 | 2020-10-27T16:44:43.198379+00:00 | 965 | false | **Python | Super Easy Method | SortedList (Balanced Binary Tree)**\n\n```\nfrom sortedcontainers import SortedList\nclass Solution:\n def findLH(self,B,x):\n \'\'\'\n Count number of values higher (H) and lower (L) than "x"\n \'\'\'\n L = B.bisect_left (x)\n ... | 4 | 0 | ['Python', 'Python3'] | 1 |
count-number-of-teams | very simple clear code with O(n^2) | very-simple-clear-code-with-on2-by-mt201-zgkd | class Solution {\npublic:\n int numTeams(vector& rating) {\n \n int smaller1=0,greater1=0,smaller2=0,greater2=0;\n int sum=0;\n \ | mt2019006 | NORMAL | 2020-06-27T08:29:03.187726+00:00 | 2020-06-27T08:29:03.187778+00:00 | 284 | false | class Solution {\npublic:\n int numTeams(vector<int>& rating) {\n \n int smaller1=0,greater1=0,smaller2=0,greater2=0;\n int sum=0;\n \n for(int i=0;i<rating.size();i++)\n {\n smaller1=0;greater1=0;smaller2=0;greater2=0;\n \n for(int j=0;j<i;j... | 4 | 0 | [] | 3 |
count-number-of-teams | Javascript Backtracking | javascript-backtracking-by-fbecker11-sh5o | \n/**\n * @param {number[]} rating\n * @return {number}\n */\nvar numTeams = function (rating) {\n const res = [];\n btk(rating, res);\n return res.length;\n | fbecker11 | NORMAL | 2020-03-30T17:48:01.916136+00:00 | 2020-03-30T18:00:08.095349+00:00 | 1,189 | false | ```\n/**\n * @param {number[]} rating\n * @return {number}\n */\nvar numTeams = function (rating) {\n const res = [];\n btk(rating, res);\n return res.length;\n};\n\nfunction btk(rating, res, arr = [], index = 0) {\n if (arr.length === 3) {\n res.push(arr)\n return;\n }\n\n for (let i = index; i < rating.le... | 4 | 0 | ['Backtracking', 'JavaScript'] | 2 |
count-number-of-teams | Python O(n^2) sol by sliding range [w/ Diagram] 有中文解析文章 | python-on2-sol-by-sliding-range-w-diagra-0hy2 | \u4E2D\u6587\u89E3\u6790\u6587\u7AE0\n\nPython O(n^2) sol by sliding range\n\n---\n\nDiagram and abstract model:\n\n\n\n\n\n---\n\nImplementation:\n\n\nclass So | brianchiang_tw | NORMAL | 2020-03-29T13:02:18.240325+00:00 | 2024-07-29T09:15:57.832050+00:00 | 764 | false | [\u4E2D\u6587\u89E3\u6790\u6587\u7AE0](https://leetcode.com/problems/count-number-of-teams/solutions/555469/python-o-n-2-sol-by-sliding-range-w-diagram/?envType=daily-question&envId=2024-07-29)\n\nPython O(n^2) sol by sliding range\n\n---\n\n**Diagram** and **abstract model**:\n\n {\n ... | 4 | 0 | [] | 1 |
count-number-of-teams | JavaScript, DP O(N^2), BruteForce O(N^3) | javascript-dp-on2-bruteforce-on3-by-hon9-1gn5 | Brute Force\n- Time Complexity: O(N^3)\n- Space Complexity: O(1)\njavaScript\n/**\n * @param {number[]} rating\n * @return {number}\n */\nvar numTeams = functio | hon9g | NORMAL | 2020-03-29T04:23:36.458824+00:00 | 2020-03-30T07:02:44.873412+00:00 | 742 | false | ### Brute Force\n- Time Complexity: O(N^3)\n- Space Complexity: O(1)\n```javaScript\n/**\n * @param {number[]} rating\n * @return {number}\n */\nvar numTeams = function(rating) {\n let y = 0;\n for (let i = 0; i + 2 < rating.length; i++) {\n for (let j = i + 1; j + 1 < rating.length; j++) {\n fo... | 4 | 1 | ['JavaScript'] | 1 |
count-number-of-teams | Clean Python 3, DFS | clean-python-3-dfs-by-lenchen1112-m1ew | Straightforward DFS solution.\n\nTime: C(N, 3) = O(N ^ 3)\nSpace: O(N), deep of dfs tree.\n\nclass Solution:\n def numTeams(self, rating: List[int]) -> int:\ | lenchen1112 | NORMAL | 2020-03-29T04:10:40.953925+00:00 | 2020-03-29T04:24:45.034911+00:00 | 810 | false | Straightforward DFS solution.\n\nTime: `C(N, 3) = O(N ^ 3)`\nSpace: `O(N)`, deep of dfs tree.\n```\nclass Solution:\n def numTeams(self, rating: List[int]) -> int:\n def dfs(i: int, prefix: List[int], increasing: bool) -> int:\n if len(prefix) == 3: return 1\n if i == len(rating): return... | 4 | 1 | [] | 2 |
count-number-of-teams | Java DP | java-dp-by-hobiter-f8ma | \nclass Solution {\n int[] arr;\n public int numTeams(int[] rating) {\n arr = rating;\n return findLarge() + findSmall();\n }\n privat | hobiter | NORMAL | 2020-03-29T04:05:12.552718+00:00 | 2020-03-29T04:24:15.884964+00:00 | 887 | false | ```\nclass Solution {\n int[] arr;\n public int numTeams(int[] rating) {\n arr = rating;\n return findLarge() + findSmall();\n }\n private int findLarge() {\n int[] dp = new int[arr.length];\n // first loop, count of smaller on the left;\n for (int i = 0; i < arr.length; i... | 4 | 0 | [] | 2 |
minimum-moves-to-convert-string | C++ Easy to understand, no change in string | c-easy-to-understand-no-change-in-string-sju5 | When we encounter a \'X\' we will make a move, irrespective of the fact that there might be \'O\'. After the move we will move the pointer by 3 steps since we a | badri7489 | NORMAL | 2021-10-03T05:21:25.267570+00:00 | 2021-10-03T05:21:25.267614+00:00 | 5,313 | false | ### When we encounter a \'X\' we will make a ***move***, irrespective of the fact that there might be \'O\'. After the move we will move the pointer by 3 steps since we are gauranteed that there won\'t be any more \'X\' till the position we have swapped.\n\n```\nint minimumMoves(string s) {\n\tint i = 0, n = s.length()... | 93 | 1 | ['C', 'C++'] | 13 |
minimum-moves-to-convert-string | Java | O(N) greedy with explanation how to come up with the greedy idea | java-on-greedy-with-explanation-how-to-c-gox8 | Many of us can write the correct greedy strategy. But most discussions don\'t tell how it works and why it works here. If you are interested please read the fol | pollux1997 | NORMAL | 2021-10-03T05:07:58.817942+00:00 | 2021-10-04T20:15:37.990561+00:00 | 4,294 | false | Many of us can write the correct greedy strategy. But most discussions don\'t tell how it works and why it works here. If you are interested please read the following part:)\n\nHere\'s my explanation:\n1.Because one move have to change three consecutive characters together. Change \'OOO\' is just a waste of opportuniti... | 59 | 0 | ['Greedy', 'Java'] | 4 |
minimum-moves-to-convert-string | [Python3] scan | python3-scan-by-ye15-1b65 | \n\nclass Solution:\n def minimumMoves(self, s: str) -> int:\n ans = i = 0\n while i < len(s): \n if s[i] == "X": \n | ye15 | NORMAL | 2021-10-03T04:22:24.876321+00:00 | 2021-10-03T04:22:24.876369+00:00 | 2,843 | false | \n```\nclass Solution:\n def minimumMoves(self, s: str) -> int:\n ans = i = 0\n while i < len(s): \n if s[i] == "X": \n ans += 1\n i += 3\n else: i += 1\n return ans \n``` | 36 | 0 | ['Python3'] | 3 |
minimum-moves-to-convert-string | Greedy | greedy-by-votrubac-vyle | When going left-to-right, we must change \'X\' we encounter. When it happen, we advance our pointer two additional steps, and increment the result.\n\nC++\ncpp\ | votrubac | NORMAL | 2021-10-04T03:19:09.669803+00:00 | 2021-10-04T08:06:24.925061+00:00 | 1,296 | false | When going left-to-right, we must change \'X\' we encounter. When it happen, we advance our pointer two additional steps, and increment the result.\n\n**C++**\n```cpp\nint minimumMoves(string s) {\n int res = 0;\n for (int i = 0; i < s.size(); i += s[i] == \'X\' ? 3 : 1)\n res += s[i] == \'X\';\n return... | 24 | 0 | [] | 3 |
minimum-moves-to-convert-string | ✅ Short & Self Explanatory | 3 Approaches | C++ | Beginner friendly | short-self-explanatory-3-approaches-c-be-pyii | 1.recursion\n\nclass Solution {\npublic:\n int minimumMoves(string s,int index=0) {\n if(index >= s.size()){\n return 0;\n }\n | rajat_gupta_ | NORMAL | 2021-10-03T07:46:41.478808+00:00 | 2021-10-03T07:46:41.478839+00:00 | 691 | false | **1.recursion**\n```\nclass Solution {\npublic:\n int minimumMoves(string s,int index=0) {\n if(index >= s.size()){\n return 0;\n }\n \n if(s[index] == \'X\'){\n return minimumMoves(s,index+3)+1;\n }else{\n return minimumMoves(s,index+1);\n }... | 12 | 2 | ['C', 'C++'] | 1 |
minimum-moves-to-convert-string | [Java] O(N) + Easy to understand + Important point | java-on-easy-to-understand-important-poi-mu11 | The important thing that you might be missing in your solution is that you might be counting 3 letter groups, which won\'t give you the correct answer.\n\nWhy?\ | pikachu_approves | NORMAL | 2021-10-06T20:51:45.393674+00:00 | 2021-10-06T20:51:45.393706+00:00 | 1,289 | false | The important thing that you might be missing in your solution is that you might be counting 3 letter groups, which won\'t give you the correct answer.\n\nWhy?\n\nThe reason for this is a test case like this:\n```\n"XXXOXXOXOXO"\n```\n\nSo, if you\'re counting letter groups of 3 at a time, you will count 1 for the firs... | 11 | 0 | ['Greedy', 'Java'] | 1 |
minimum-moves-to-convert-string | Short Java, O(n), 7 lines | short-java-on-7-lines-by-climberig-b8x7 | Walk to the first X, jump three position to the right, walk to the next X, jump... Count the number of jumps.\n```java\n public int minimumMoves(String s) {\n | climberig | NORMAL | 2021-10-03T04:47:12.026084+00:00 | 2021-10-03T05:10:52.761453+00:00 | 570 | false | Walk to the first X, jump three position to the right, walk to the next X, jump... Count the number of jumps.\n```java\n public int minimumMoves(String s) {\n int r = 0;\n for (int i = 0; i < s.length(); i++)\n if (s.charAt(i) == \'X\') {\n r++;\n i += 2;\n ... | 8 | 0 | [] | 1 |
minimum-moves-to-convert-string | Easy Python Solution | Faster than 99% (24 ms) | easy-python-solution-faster-than-99-24-m-dlz5 | Easy Python Solution | Faster than 99% (24 ms)\nRuntime: 24 ms, faster than 99% of Python3 online submissions for Minimum Moves to Convert String.\nMemory Usage | the_sky_high | NORMAL | 2021-10-17T08:55:33.677650+00:00 | 2021-10-17T08:55:33.677678+00:00 | 1,106 | false | # Easy Python Solution | Faster than 99% (24 ms)\n**Runtime: 24 ms, faster than 99% of Python3 online submissions for Minimum Moves to Convert String.\nMemory Usage: 14.2 MB.**\n\n```\nclass Solution:\n def minimumMoves(self, s: str) -> int:\n i, m = 0, 0\n l = len(s)\n\n while i < l:\n ... | 6 | 0 | ['Python', 'Python3'] | 2 |
minimum-moves-to-convert-string | Short 1-liner Python Java Ruby | short-1-liner-python-java-ruby-by-stefan-rind | Ruby:\n\ndef minimum_moves(s)\n s.scan(/X.?.?/).size\nend\n\n\nPython:\n\ndef minimumMoves(self, s: str) -> int:\n return subn(\'X.?.?\', \'\', s)[1]\n\n\nJ | stefan4trivia | NORMAL | 2021-10-03T20:19:11.117992+00:00 | 2021-10-03T21:03:12.133967+00:00 | 164 | false | Ruby:\n```\ndef minimum_moves(s)\n s.scan(/X.?.?/).size\nend\n```\n\nPython:\n```\ndef minimumMoves(self, s: str) -> int:\n return subn(\'X.?.?\', \'\', s)[1]\n```\n\nJava:\n```\npublic int minimumMoves(String s) {\n return s.replaceAll("O*(X?).?.?", "$1").length();\n}\n``` | 6 | 2 | [] | 2 |
minimum-moves-to-convert-string | EASY JAVA SOLUTION O(n) time complexity!!!! | easy-java-solution-on-time-complexity-by-irpj | Approachtake two variables 'i' for iterating through the string elements
and 'step' for keeping track of the no of steps. run a while loop through all the eleme | Mrinmoy_1315 | NORMAL | 2024-12-22T18:41:40.284179+00:00 | 2024-12-22T18:41:40.284179+00:00 | 519 | false |
# Approach
take two variables **'i'** for iterating through the string elements
and **'step'** for keeping track of the no of steps. run a while loop through all the elements of the string. if found an 'X' increment the pointer i an include three consecutive elemnts thereby considering it as a step. Increment **'step'... | 4 | 0 | ['Java'] | 0 |
minimum-moves-to-convert-string | Beats 100% | C++ | beats-100-c-by-manavtore-11b9 | Approach\n1. Initialize moves to 0 for counting moves.\n\n2. Use a loop to traverse the string.\n\n3. When an \'X\' is found, increment moves and skip the next | manavtore | NORMAL | 2024-07-27T09:01:41.704302+00:00 | 2024-07-27T09:01:41.704339+00:00 | 77 | false | # Approach\n1. Initialize moves to 0 for counting moves.\n\n2. Use a loop to traverse the string.\n\n3. When an \'X\' is found, increment moves and skip the next two characters by moving three steps forward (i += 3).\n\n4. If the character is \'O\', move to the next character.\n\n5. Return the total number of moves.\n\... | 4 | 0 | ['C++'] | 0 |
minimum-moves-to-convert-string | simple and easy C++ solution 😍❤️🔥 | simple-and-easy-c-solution-by-shishirrsi-x38g | if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n\nclass Solution {\npublic:\n int minimumMoves(string s) \n {\n int i = 0, ans = 0, | shishirRsiam | NORMAL | 2024-05-26T12:19:38.541601+00:00 | 2024-05-26T12:19:38.541622+00:00 | 258 | false | # if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n```\nclass Solution {\npublic:\n int minimumMoves(string s) \n {\n int i = 0, ans = 0, n = s.size();\n while(i < n)\n {\n while(s[i]==\'0\') i++;\n if(s[i]==\'X\') \n {\n ans++;\n... | 4 | 0 | ['String', 'Greedy', 'C++'] | 0 |
minimum-moves-to-convert-string | Java | While Loop | Simple Logic | java-while-loop-simple-logic-by-divyansh-qu7c | \nclass Solution {\n public int minimumMoves(String s) {\n int i=0,step=0;\n while(i<s.length()){\n if(s.charAt(i)==\'X\'){\n | Divyansh__26 | NORMAL | 2022-09-16T07:55:41.799866+00:00 | 2022-09-16T07:55:41.799910+00:00 | 522 | false | ```\nclass Solution {\n public int minimumMoves(String s) {\n int i=0,step=0;\n while(i<s.length()){\n if(s.charAt(i)==\'X\'){\n i=i+3;\n step++;\n }\n else\n i++;\n }\n return step;\n }\n}\n```\nKindly upvot... | 4 | 0 | ['String', 'Java'] | 1 |
minimum-moves-to-convert-string | C++||Easy to Understand | ceasy-to-understand-by-return_7-negr | ```\nclass Solution {\npublic:\n int minimumMoves(string s)\n {\n int ans=0;\n for(int i=0;i<s.size();i++)\n {\n if(s[i]== | return_7 | NORMAL | 2022-08-22T21:06:56.191054+00:00 | 2022-08-22T21:06:56.191089+00:00 | 341 | false | ```\nclass Solution {\npublic:\n int minimumMoves(string s)\n {\n int ans=0;\n for(int i=0;i<s.size();i++)\n {\n if(s[i]==\'X\')\n {\n ans++;\n i=i+2;\n }\n }\n return ans;\n \n }\n};\n//if you find the sol... | 4 | 0 | ['C'] | 0 |
minimum-moves-to-convert-string | [Python 3] Simple Solution O(n) with Explanation | python-3-simple-solution-on-with-explana-wdax | General idea:\n\nGo through each character. if it\'s X, then we count once and jump to 3 characters ahead; if it\'s O, then we ignore it and go on. In this way, | zhouxu_ds | NORMAL | 2021-12-23T16:35:17.873502+00:00 | 2021-12-23T16:35:17.873528+00:00 | 277 | false | General idea:\n\nGo through each character. if it\'s X, then we count once and jump to 3 characters ahead; if it\'s O, then we ignore it and go on. In this way, we count all the moves.\n\n```\ndef minimumMoves(self, s: str) -> int:\n res, i = 0, 0\n while i < len(s):\n if s[i] == \'X\':\n ... | 4 | 0 | ['Python'] | 0 |
minimum-moves-to-convert-string | Java 0ms 100% faster | java-0ms-100-faster-by-devangsharma7861-au82 | class Solution {\n\n public int minimumMoves(String s){\n \n int step = 0;\n \n \n for(int i = 0; i < s.length(); i++){\n | devangsharma7861 | NORMAL | 2021-11-10T16:19:12.760263+00:00 | 2021-11-10T16:19:12.760293+00:00 | 162 | false | class Solution {\n\n public int minimumMoves(String s){\n \n int step = 0;\n \n \n for(int i = 0; i < s.length(); i++){\n if(s.charAt(i) == \'X\'){\n step++;\n i+=2;\n }\n }\n \n return step;\n }\n} | 4 | 0 | [] | 0 |
minimum-moves-to-convert-string | 2027 | JavaScript 1-Line Solution | 2027-javascript-1-line-solution-by-spork-ws53 | Runtime: 83 ms, faster than 47.58% of JavaScript online submissions\n> Memory Usage: 39.2 MB, less than 17.18% of JavaScript online submissions\n\njavascript\n | sporkyy | NORMAL | 2021-10-13T13:18:43.389043+00:00 | 2021-10-13T13:19:10.712407+00:00 | 353 | false | > Runtime: **83 ms**, faster than *47.58%* of JavaScript online submissions\n> Memory Usage: **39.2 MB**, less than *17.18%* of JavaScript online submissions\n\n```javascript\n const minimumMoves = s => s.match(/X.{0,2}/g)?.length ?? 0;\n ``` | 4 | 0 | ['JavaScript'] | 0 |
minimum-moves-to-convert-string | c++ 100% faster easiest solution || no change in string | c-100-faster-easiest-solution-no-change-cdte9 | int minimumMoves(string s) {\n int ans=0;\n for(int i=0; i<s.size();i=i)\n {\n if(s[i] == \'X\'){\n i= i+3; | gravity2000 | NORMAL | 2021-10-03T04:14:53.322219+00:00 | 2021-10-03T04:14:53.322294+00:00 | 274 | false | int minimumMoves(string s) {\n int ans=0;\n for(int i=0; i<s.size();i=i)\n {\n if(s[i] == \'X\'){\n i= i+3;\n ans++;\n }\n else{\n i++;\n }\n }\n return ans;\n } | 4 | 3 | ['String', 'Sliding Window'] | 0 |
minimum-moves-to-convert-string | Runtime: 0 ms, faster than 100.00% of C++ online submissions | runtime-0-ms-faster-than-10000-of-c-onli-v4vt | \n\tclass Solution {\n\tpublic:\n\t\tint minimumMoves(string s) {\n\t\t\tint n = s.size();\n\t\t\tint ans = 0;\n\t\t\tfor(int i=0;i<n;i++){\n\t\t\t\tif(s[i] == | PiyasaBera | NORMAL | 2022-09-18T12:53:12.960750+00:00 | 2022-09-18T12:53:12.960795+00:00 | 371 | false | \n\tclass Solution {\n\tpublic:\n\t\tint minimumMoves(string s) {\n\t\t\tint n = s.size();\n\t\t\tint ans = 0;\n\t\t\tfor(int i=0;i<n;i++){\n\t\t\t\tif(s[i] == \'X\'){\n\t\t\t\t\tans++;\n\t\t\t\t\ti+=2;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\t}; | 3 | 0 | [] | 2 |
minimum-moves-to-convert-string | EASY TO UNDERSTAND || SIMPLE JAVA CODE | easy-to-understand-simple-java-code-by-p-nqk0 | \nclass Solution {\n public int minimumMoves(String s) {\n int count = 0;\n for (int i = 0; i < s.length(); i++)\n if (s.charAt(i) = | priyankan_23 | NORMAL | 2022-08-31T17:10:20.911573+00:00 | 2022-08-31T17:10:20.911615+00:00 | 195 | false | ```\nclass Solution {\n public int minimumMoves(String s) {\n int count = 0;\n for (int i = 0; i < s.length(); i++)\n if (s.charAt(i) == \'X\') {\n count++;\n i += 2;\n }\n return count;\n }\n}\n``` | 3 | 0 | [] | 0 |
minimum-moves-to-convert-string | C++ with simple explanation | c-with-simple-explanation-by-jaisw7-72zb | I just considered a sliding window of size "3". \n- If the first element in the current window is "O", slide the index by 1\n- Otherwise we slide the index by 3 | jaisw7 | NORMAL | 2021-10-03T17:10:32.866091+00:00 | 2021-10-17T16:42:32.069669+00:00 | 112 | false | I just considered a sliding window of size "3". \n- If the first element in the current window is "O", slide the index by 1\n- Otherwise we slide the index by 3\n\nConsider an example "XXXXX"\n>\tIn the first window, the element at the first index (i=0) is "X"\n\t[ [XXX] XXX] \n\tSo, we convert the string to \n\t[ [OOO... | 3 | 0 | [] | 0 |
minimum-moves-to-convert-string | C++ Simple and Short Solution, 0ms Faster than 100% | c-simple-and-short-solution-0ms-faster-t-ony0 | \nclass Solution {\npublic:\n int minimumMoves(string s) {\n int count = 0, i = 0;\n \n while (i < s.size()) {\n while (s[i] | yehudisk | NORMAL | 2021-10-03T09:05:42.896417+00:00 | 2021-10-03T09:05:42.896458+00:00 | 158 | false | ```\nclass Solution {\npublic:\n int minimumMoves(string s) {\n int count = 0, i = 0;\n \n while (i < s.size()) {\n while (s[i] == \'O\') i++;\n \n if (s[i] == \'X\') {\n count++;\n i += 3;\n }\n }\n \n ... | 3 | 0 | ['C'] | 0 |
minimum-moves-to-convert-string | 100.00 % | 0 ms | C++ | easiest solution possible | 10000-0-ms-c-easiest-solution-possible-b-yrfn | ``` \nclass Solution {\npublic:\n int minimumMoves(string s) {\n int n = s.length() ;\n int cnt = 0;\n for(int i = 0 ; i= n-3){\n | priyanshichauhan1998x | NORMAL | 2021-10-03T05:14:22.607325+00:00 | 2021-10-03T05:14:22.607370+00:00 | 63 | false | ``` \nclass Solution {\npublic:\n int minimumMoves(string s) {\n int n = s.length() ;\n int cnt = 0;\n for(int i = 0 ; i<n;i++){\n if(s[i] == \'X\'){ \n if(i >= n-3){\n cnt++;\n break;\n }\n else {\n i= i+2... | 3 | 0 | ['Math', 'String'] | 0 |
minimum-moves-to-convert-string | Python easy | python-easy-by-abkc1221-0kyf | \nclass Solution:\n def minimumMoves(self, s: str) -> int:\n res = 0\n i = 0\n while i < len(s):\n #if current is X then jump | abkc1221 | NORMAL | 2021-10-03T04:04:39.572141+00:00 | 2021-10-03T04:04:39.572178+00:00 | 320 | false | ```\nclass Solution:\n def minimumMoves(self, s: str) -> int:\n res = 0\n i = 0\n while i < len(s):\n #if current is X then jump 3 positions and count by 1\n if s[i] == \'X\':\n res += 1\n i += 3\n else:\n i += 1\n ... | 3 | 2 | ['Python', 'Python3'] | 0 |
minimum-moves-to-convert-string | C++ || EASY SOLUTION | c-easy-solution-by-vineet_raosahab-0uqm | \nclass Solution {\npublic:\n int minimumMoves(string s) {\n int count=0;\n for(int i=0;i<s.size()-2;i++)\n {\n if(s[i]==\'X\ | VineetKumar2023 | NORMAL | 2021-10-03T04:02:01.238022+00:00 | 2021-10-11T02:08:27.183537+00:00 | 175 | false | ```\nclass Solution {\npublic:\n int minimumMoves(string s) {\n int count=0;\n for(int i=0;i<s.size()-2;i++)\n {\n if(s[i]==\'X\')\n {\n count++;\n s[i]=\'O\';\n s[i+1]=\'O\';\n s[i+2]=\'O\';\n }\n ... | 3 | 0 | [] | 0 |
minimum-moves-to-convert-string | Easiest Solution Ever | easiest-solution-ever-by-johncarter11-tehg | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | AbhiBhingole | NORMAL | 2025-03-24T04:30:26.333156+00:00 | 2025-03-24T04:30:26.333156+00:00 | 118 | false | # Intuition

<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time comp... | 2 | 0 | ['Java'] | 0 |
minimum-moves-to-convert-string | Rust | 0ms | O(n) | beats 100% | rust-0ms-on-beats-100-by-user7454af-n4ni | Intuition\n\n\n# Approach\nWhen an \'X\' is encountered, increment change count, and there are two more converts reamining for the next two indices. Keep decrem | user7454af | NORMAL | 2024-06-29T23:56:55.748174+00:00 | 2024-06-29T23:56:55.748198+00:00 | 129 | false | # Intuition\n\n\n# Approach\nWhen an \'X\' is encountered, increment change count, and there are two more converts reamining for the next two indices. Keep decrementing remaining if its greater than 0 and increment change count only if remaining is 0.\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: ... | 2 | 0 | ['Rust'] | 0 |
minimum-moves-to-convert-string | Simple java code 0 ms beats 100 % | simple-java-code-0-ms-beats-100-by-arobh-odjf | \n# Complexity\n-\n\n# Code\n\nclass Solution {\n public int minimumMoves(String s) {\n char[] ch=s.toCharArray();\n int ctr=0;\n for(in | Arobh | NORMAL | 2024-01-10T15:03:04.245203+00:00 | 2024-01-10T15:03:04.245238+00:00 | 183 | false | \n# Complexity\n-\n\n# Code\n```\nclass Solution {\n public int minimumMoves(String s) {\n char[] ch=s.toCharArray();\n int ctr=0;\n for(int i=0;i<ch.length;i++)\n {\n ... | 2 | 0 | ['Java'] | 0 |
minimum-moves-to-convert-string | 6 lines c++ easy solution | O(n) time | 6-lines-c-easy-solution-on-time-by-wagdy-hlja | Approach\nwhenever we find an \'X\' we will convert it and the following 2 elements (so, no need to check them anyways)\n\n# Complexity\n- Time complexity:\nO(n | WagdySamih | NORMAL | 2023-05-05T00:39:11.889252+00:00 | 2023-05-05T00:40:34.218148+00:00 | 415 | false | # Approach\nwhenever we find an \'X\' we will convert it and the following 2 elements (so, no need to check them anyways)\n\n# Complexity\n- Time complexity:\nO(n)\n- Space complexity:\nO(1)\n# Code\n```\nclass Solution {\npublic:\n int minimumMoves(string s) {\n int sum = 0;\n int sz = s.size();\n ... | 2 | 0 | ['C++'] | 0 |
minimum-moves-to-convert-string | 2027. Run time - 95.42% | Memory - 87% | 2027-run-time-9542-memory-87-by-ramana72-etac | Code\n\nclass Solution:\n def minimumMoves(self, s: str) -> int:\n ind, moves = 0, 0\n n = len(s)\n while ind < n:\n if s[ind | ramana721 | NORMAL | 2023-03-19T06:13:30.708881+00:00 | 2023-03-19T06:13:30.708916+00:00 | 771 | false | # Code\n```\nclass Solution:\n def minimumMoves(self, s: str) -> int:\n ind, moves = 0, 0\n n = len(s)\n while ind < n:\n if s[ind] == \'X\':\n ind += 3\n moves += 1\n else:\n ind += 1\n return moves\n\n``` | 2 | 0 | ['String', 'Greedy', 'Python3'] | 1 |
minimum-moves-to-convert-string | C++ - 2 Solutions - Beats 100 % - Easy | c-2-solutions-beats-100-easy-by-nipunrat-4u5l | # Intuition \n\n\n\n\n\n# Complexity\n- Time complexity:O(n)\n\n\n- Space complexity:O(1)\n\n\n# Code\n\nclass Solution {\npublic:\n int minimumMoves(strin | nipunrathore | NORMAL | 2023-02-06T16:26:42.223596+00:00 | 2023-02-06T16:26:42.223641+00:00 | 617 | false | <!-- # Intuition -->\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n<!-- # Approach -->\n<!-- Describe your approach to solving the problem. -->\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... | 2 | 0 | ['String', 'Greedy', 'C++'] | 0 |
minimum-moves-to-convert-string | Simple C# solution | simple-c-solution-by-khaliljel04-u1sj | Approach\nIf you find \'O\' jump to next letter.\nIf you find \'X\' ignore the next two letters and to the third next and count that as a move.\n\n# Complexity\ | Khaliljel04 | NORMAL | 2022-11-06T22:30:44.459677+00:00 | 2022-11-06T22:30:44.459701+00:00 | 140 | false | # Approach\nIf you find \'O\' jump to next letter.\nIf you find \'X\' ignore the next two letters and to the third next and count that as a move.\n\n# Complexity\n- Time complexity: O(n)\n- Space complexity: O(1)\n\n# Code\n```\npublic class Solution {\n public int MinimumMoves(string s) {\n int moves = 0;\n ... | 2 | 0 | ['C#'] | 0 |
minimum-moves-to-convert-string | c++ | easy to understand | step by step | c-easy-to-understand-step-by-step-by-ven-3ofc | \n\n# Code\n\nclass Solution {\npublic:\n\tint minimumMoves(string s) {\n\t\tint n = s.size();\n\t\tint ans = 0;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tif(s[i] == \' | venomhighs7 | NORMAL | 2022-09-30T12:47:01.901007+00:00 | 2022-09-30T12:47:01.901041+00:00 | 510 | false | \n\n# Code\n```\nclass Solution {\npublic:\n\tint minimumMoves(string s) {\n\t\tint n = s.size();\n\t\tint ans = 0;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tif(s[i] == \'X\'){\n\t\t\t\tans++;\n\t\t\t\ti+=2;\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n};\n``` | 2 | 0 | ['C++'] | 1 |
minimum-moves-to-convert-string | Javascript solution - Easy understanding | javascript-solution-easy-understanding-b-cbat | \nvar minimumMoves = function(s) {\n let move = 0;\n let i = 0;\n while(i<s.length){\n let char = s[i];\n\t\t// incrementing the index if we alr | SathishGunasekaran | NORMAL | 2022-08-02T16:39:22.185831+00:00 | 2022-08-02T16:39:40.289043+00:00 | 318 | false | ```\nvar minimumMoves = function(s) {\n let move = 0;\n let i = 0;\n while(i<s.length){\n let char = s[i];\n\t\t// incrementing the index if we already have \'O\'\n if(char== \'O\'){\n i++;\n }\n\t\t// incrementing the move and index by 3 (Per move = 3 characters)\n if(c... | 2 | 0 | ['Greedy', 'JavaScript'] | 1 |
minimum-moves-to-convert-string | Java Solution | java-solution-by-solved-64ru | \nclass Solution {\n public int minimumMoves(String s) {\n int index = 0;\n int result = 0;\n \n while (index < s.length()) {\n | solved | NORMAL | 2022-03-25T20:24:08.469092+00:00 | 2022-03-25T20:24:08.469121+00:00 | 310 | false | ```\nclass Solution {\n public int minimumMoves(String s) {\n int index = 0;\n int result = 0;\n \n while (index < s.length()) {\n if (s.charAt(index) == \'X\') {\n index = index + 2;\n result++;\n }\n index++;\n }\n ... | 2 | 0 | ['Java'] | 1 |
minimum-moves-to-convert-string | C++ | 3-lines code | Faster than 100% | c-3-lines-code-faster-than-100-by-dhruvj-s6xm | \n int minimumMoves(string s) {\n int ans = 0;\n \n for(int i=0; i<s.size(); i++)\n if(s[i] == \'X\'){\n ans++ | Dhruvjha | NORMAL | 2022-03-07T20:13:30.594484+00:00 | 2022-03-07T20:13:30.594512+00:00 | 196 | false | ```\n int minimumMoves(string s) {\n int ans = 0;\n \n for(int i=0; i<s.size(); i++)\n if(s[i] == \'X\'){\n ans++;\n i += 2;\n } \n return ans;\n }\n``` | 2 | 0 | ['C', 'C++'] | 0 |
minimum-moves-to-convert-string | Java Easy Efficient Fastest Solution | java-easy-efficient-fastest-solution-by-0ywk8 | \nclass Solution {\n public int minimumMoves(String s) \n {\n int moves = 0;\n int i=0;\n \n while(i<s.length()){\n | arpit2304 | NORMAL | 2022-02-10T16:33:38.492838+00:00 | 2022-02-10T16:33:38.492888+00:00 | 255 | false | ```\nclass Solution {\n public int minimumMoves(String s) \n {\n int moves = 0;\n int i=0;\n \n while(i<s.length()){\n if(s.charAt(i)==\'X\'){\n i+=3;\n moves++;\n }else\n i++;\n } \n return moves;\n ... | 2 | 0 | ['Java'] | 2 |
minimum-moves-to-convert-string | Simple Python Solution | simple-python-solution-by-anish_adnani-luu8 | \nclass Solution:\n def minimumMoves(self, s: str) -> int:\n \n moves = 0\n x=0\n while x<=len(s)-1:\n #print(x)\n | anish_adnani | NORMAL | 2021-10-16T19:16:01.539362+00:00 | 2021-10-16T19:16:01.539422+00:00 | 62 | false | ```\nclass Solution:\n def minimumMoves(self, s: str) -> int:\n \n moves = 0\n x=0\n while x<=len(s)-1:\n #print(x)\n if s[x] == \'X\':\n # print("inside")\n moves+=1\n x = x+2\n \n \n x... | 2 | 0 | [] | 0 |
minimum-moves-to-convert-string | [Python3] O(N) | python3-on-by-sacharya1-lxt6 | \tclass Solution:\n\t\tdef minimumMoves(self, s: str) -> int:\n\t\t\tcount=i=0\n\t\t\twhile i<len(s):\n\t\t\t\tif s[i]=="X":\n\t\t\t\t\tcount+=1\n\t\t\t\t\ti+=3 | sacharya1 | NORMAL | 2021-10-05T22:46:42.849544+00:00 | 2021-10-05T22:46:42.849587+00:00 | 125 | false | \tclass Solution:\n\t\tdef minimumMoves(self, s: str) -> int:\n\t\t\tcount=i=0\n\t\t\twhile i<len(s):\n\t\t\t\tif s[i]=="X":\n\t\t\t\t\tcount+=1\n\t\t\t\t\ti+=3\n\t\t\t\telse:\n\t\t\t\t\ti+=1\n\t\t\treturn count | 2 | 0 | [] | 0 |
minimum-moves-to-convert-string | Rust solution | rust-solution-by-bigmih-0tjc | \nimpl Solution {\n pub fn minimum_moves(s: String) -> i32 {\n s.into_bytes()\n .iter()\n .enumerate()\n .filter(|&(_ | BigMih | NORMAL | 2021-10-04T17:07:14.197646+00:00 | 2021-10-04T17:07:14.197737+00:00 | 93 | false | ```\nimpl Solution {\n pub fn minimum_moves(s: String) -> i32 {\n s.into_bytes()\n .iter()\n .enumerate()\n .filter(|&(_, b)| *b == b\'X\')\n .fold((0, 0), |(mut moves, mut next_ind), (ind, b)| {\n if ind >= next_ind {\n moves += 1;... | 2 | 0 | ['Rust'] | 1 |
minimum-moves-to-convert-string | Golang solution with explanation and images | golang-solution-with-explanation-and-ima-7gxw | The idea of this solution is if we are on a \'X\' we can move the index up by three and add one to res.\n\nAn example could be:\n\ninput: s = "XXOXXXOOOXOXOXX" | nathannaveen | NORMAL | 2021-10-04T01:20:40.976848+00:00 | 2021-10-04T01:21:46.001877+00:00 | 114 | false | The idea of this solution is if we are on a `\'X\'` we can move the index up by three and add one to `res`.\n\nAn example could be:\n\n`input: s = "XXOXXXOOOXOXOXX"` *(I tried to capture as many edge cases as I could in this test case)*\n\nWe can start with our index `i = 0`\n\n\n\n`... | 2 | 0 | ['Go'] | 0 |
minimum-moves-to-convert-string | Dynamic Programming O(N) time solution with O(1) space | dynamic-programming-on-time-solution-wit-npt0 | The intuition is that the minimum number of moves depends on the previous values in the string. \nThe problem can be solved via dynamic programming using the fo | shaolao | NORMAL | 2021-10-03T16:51:45.378116+00:00 | 2021-10-03T16:51:45.378165+00:00 | 68 | false | The intuition is that the minimum number of moves depends on the previous values in the string. \nThe problem can be solved via dynamic programming using the following relation.\n\nif current value is \'X\' => then\n`moves[index] = moves[index-3] + 1`\n\nthe reason is that the last three indices will automatically be c... | 2 | 0 | [] | 0 |
minimum-moves-to-convert-string | Easy, 100%, Simple, JAVA,O(1) Solution | easy-100-simple-javao1-solution-by-varis-44jy | class Solution {\n public int helper(String s) {\n int n=s.length(),count=0,i=0;\n while(i<n){\n char ch=s.charAt(i);\n i | varis123 | NORMAL | 2021-10-03T09:45:17.961627+00:00 | 2021-10-03T09:45:17.961668+00:00 | 33 | false | class Solution {\n public int helper(String s) {\n int n=s.length(),count=0,i=0;\n while(i<n){\n char ch=s.charAt(i);\n if(ch==\'X\'){\n count++;\n i+=3;\n }\n else{\n i+=1;\n }\n }\n return count;\... | 2 | 0 | [] | 0 |
minimum-moves-to-convert-string | [ C++ ] Easy | c-easy-by-pk_87-e5a7 | ```\nint minimumMoves(string s) {\n int ans=0;\n for(int i=0; i<s.size(); i++)\n {\n if(s[i] == \'X\')\n {\n | pawan_mehta | NORMAL | 2021-10-03T04:03:00.338160+00:00 | 2021-10-03T04:03:00.338215+00:00 | 209 | false | ```\nint minimumMoves(string s) {\n int ans=0;\n for(int i=0; i<s.size(); i++)\n {\n if(s[i] == \'X\')\n {\n if(i+1<s.size())\n s[i+1]=\'O\';\n if(i+2<s.size())\n s[i+2]=\'O\';\n s[i]=\'O\';\n ... | 2 | 0 | [] | 0 |
minimum-moves-to-convert-string | My Simple C++ and Java Solution | my-simple-c-and-java-solution-by-vishnu2-ptnq | // C++ my simple solution\n \n\tclass Solution {\n\tpublic:\n\t\tint minimumMoves(string s) {\n\t\t\tint count = 0;\n\t\t\tfor(int i = 0; i < s.size(); i++){\n\ | vishnu23kumar | NORMAL | 2021-10-03T04:02:33.033529+00:00 | 2021-10-04T01:45:29.957558+00:00 | 184 | false | // C++ my simple solution\n \n\tclass Solution {\n\tpublic:\n\t\tint minimumMoves(string s) {\n\t\t\tint count = 0;\n\t\t\tfor(int i = 0; i < s.size(); i++){\n\t\t\t\tif(s[i] != \'O\'){\n\t\t\t\t\tcount++;\n\t\t\t\t\ti+=2;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn count;\n\t\t}\n\t};\n\t\n\n// java solution\n\n\tclass Solution... | 2 | 1 | ['C', 'Java'] | 0 |
minimum-moves-to-convert-string | Minimum Moves to Convert String || Beat 100% python || 0ms | minimum-moves-to-convert-string-beat-100-qecf | IntuitionApproachComplexity
Time complexity:O(n)
Space complexity:O(1)
Code | hs024 | NORMAL | 2025-03-30T07:05:18.230755+00:00 | 2025-03-30T07:05:18.230755+00:00 | 58 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
... | 1 | 0 | ['Python3'] | 0 |
minimum-moves-to-convert-string | Java || Runtime 100% || Memory 74% | java-runtime-100-memory-74-by-mohanraj-r-cn8s | Complexity
Time complexity: O(n)
Space complexity: O(1)
Code | Mohanraj-R | NORMAL | 2025-03-01T05:23:57.555917+00:00 | 2025-03-01T05:23:57.555917+00:00 | 198 | false | # Complexity
- Time complexity: $$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: $$O(1)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```java []
class Solution {
public int minimumMoves(String s) {
int count = 0;
int i = 0 ;
int n = s.l... | 1 | 0 | ['Java'] | 0 |
minimum-moves-to-convert-string | 💯 Beats || Easy and Optimal Solution || C++ 🚀 | beats-easy-and-optimal-solution-c-by-dee-nkhi | ✨ Intuition:The task is to determine the minimum number of moves required to convert all 'X' characters in the string s into 'O'. Each move can change up to 3 c | Deepakgariya2004 | NORMAL | 2025-01-10T21:34:01.676910+00:00 | 2025-01-10T21:34:01.676910+00:00 | 107 | false | # ✨ Intuition:
The task is to determine the minimum number of moves required to convert all 'X' characters in the string s into 'O'. Each move can change up to 3 consecutive characters starting from an 'X'. The goal is to count the minimum moves efficiently. 🌟
# 💡 Approach:
1️⃣ Start by initializing i = 0 (pointer),... | 1 | 0 | ['C++'] | 0 |
minimum-moves-to-convert-string | difference between for and while loop aaj sahi maaino mein pata chala :D | difference-between-for-and-while-loop-aa-8c90 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | yesyesem | NORMAL | 2024-09-03T10:19:48.329993+00:00 | 2024-09-03T10:19:48.330017+00:00 | 104 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 0 |
minimum-moves-to-convert-string | Simple Approach using one for loop | simple-approach-using-one-for-loop-by-__-500h | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | __agrim__chauhan__ | NORMAL | 2024-07-27T06:41:55.413064+00:00 | 2024-07-27T06:41:55.413100+00:00 | 9 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 0 |
minimum-moves-to-convert-string | Simple Java Solution using Greedy | O(n) time and O(1) Space | simple-java-solution-using-greedy-on-tim-n7si | Intuition\nTry to be greedy about the utilising the "moves".\n\n# Approach\n1. Maintain a cutOff variable telling you till which index do we have all \'0\'. Ini | ayushprakash1912 | NORMAL | 2024-03-21T18:56:23.733875+00:00 | 2024-03-21T18:56:23.733895+00:00 | 25 | false | # Intuition\nTry to be greedy about the utilising the "moves".\n\n# Approach\n1. Maintain a cutOff variable telling you till which index do we have all \'0\'. Initialise it to -1 in the beginning.\n2. Iterate through the array, and whenever encounter a \'X\'(lest say at index \'i\'), update the value of "moves" by 1(be... | 1 | 0 | ['Greedy', 'Java'] | 0 |
minimum-moves-to-convert-string | ✅ 99% beats || Python3 || While loop | 99-beats-python3-while-loop-by-lutfullo_-tivc | Intuition\n\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n\n Use while.\n\n 1.Assign i pointer to while loop as given words | lutfullo_m | NORMAL | 2023-10-18T09:48:47.014971+00:00 | 2023-10-18T09:48:47.014994+00:00 | 198 | false | # Intuition\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n\n Use while.\n\n 1.Assign i pointer to while loop as given word`s index... | 1 | 0 | ['Python3'] | 0 |
minimum-moves-to-convert-string | Python explained. [Runtime 11 ms, Beats 97.37%] | python-explained-runtime-11-ms-beats-973-er1u | \n\n# Code\n\nclass Solution(object):\n def minimumMoves(self, s):\n """\n :type s: str\n :rtype: int\n """\n \n # | saahilparmar | NORMAL | 2023-04-09T15:41:19.396631+00:00 | 2023-04-09T15:41:19.396660+00:00 | 20 | false | \n\n# Code\n```\nclass Solution(object):\n def minimumMoves(self, s):\n """\n :type s: str\n :rtype: int\n """\n \n # Indexing int.\n ... | 1 | 0 | ['Python'] | 0 |
minimum-moves-to-convert-string | Golang 100% fastest 0ms 2 lines of code | golang-100-fastest-0ms-2-lines-of-code-b-mgjl | \n\nfunc minimumMoves(s string) (res int) {\n for i:=0 ; i < len(s) ; i++ {\n if s[i] == \'X\' { i += 2; res++ }\n }\n return res\n\n}\n\n | gene-rode | NORMAL | 2023-02-27T22:26:40.312043+00:00 | 2023-02-27T22:26:40.312084+00:00 | 36 | false | \n```\nfunc minimumMoves(s string) (res int) {\n for i:=0 ; i < len(s) ; i++ {\n if s[i] == \'X\' { i += 2; res++ }\n }\n return res\n\n}\n\n``` | 1 | 0 | ['Go'] | 0 |
minimum-moves-to-convert-string | simple cpp solution | simple-cpp-solution-by-prithviraj26-slpr | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | prithviraj26 | NORMAL | 2023-01-24T18:49:45.363562+00:00 | 2023-01-24T18:50:01.976039+00:00 | 541 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\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... | 1 | 0 | ['C++'] | 1 |
minimum-moves-to-convert-string | Python3 Neat Code | python3-neat-code-by-piyushsinghgaur-i27a | Code\n\nclass Solution:\n def minimumMoves(self, s: str) -> int:\n ans=i=0\n while i<len(s):\n if s[i]==\'O\':i+=1\n else | piyushsinghgaur | NORMAL | 2023-01-22T07:22:04.070828+00:00 | 2023-01-22T07:22:04.070871+00:00 | 760 | false | # Code\n```\nclass Solution:\n def minimumMoves(self, s: str) -> int:\n ans=i=0\n while i<len(s):\n if s[i]==\'O\':i+=1\n else:\n i+=3\n ans+=1\n return ans\n``` | 1 | 0 | ['Python3'] | 0 |
minimum-moves-to-convert-string | ☑️ Swift Solution | Easy to understand | swift-solution-easy-to-understand-by-clo-3s8g | Since the substitution will not be used later, it can be omitted and only the occurrences can be counted.\nMy best result\nRuntime:\xA02 ms, faster than 100.00% | clothor | NORMAL | 2022-11-01T00:47:30.727921+00:00 | 2022-11-01T00:47:30.727962+00:00 | 29 | false | Since the substitution will not be used later, it can be omitted and only the occurrences can be counted.\nMy best result\nRuntime:\xA0**2 ms**, faster than **100.00%** of Swift online submissions for Minimum Moves to Convert String.\n```\nclass Solution {\n\tfunc minimumMoves(_ s: String) -> Int {\n\t\tvar arr = Array... | 1 | 0 | ['Swift'] | 0 |
minimum-moves-to-convert-string | PHP Simple Solution | php-simple-solution-by-leon888-ovre | \nclass Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minimumMoves($s) {\n $times = 0;\n while (($ | leon888 | NORMAL | 2022-09-16T05:39:32.391516+00:00 | 2022-09-16T05:39:32.391562+00:00 | 24 | false | ```\nclass Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minimumMoves($s) {\n $times = 0;\n while (($start = strpos($s, "X")) !== false) {\n $s = substr($s, $start + 3);\n $times++;\n }\n\n return $times;\n }\n}\n``` | 1 | 0 | ['PHP'] | 0 |
minimum-moves-to-convert-string | Python Solution | python-solution-by-a_shekhar-tty9 | ```\n def minimumMoves(self, s: str) -> int:\n count = 0\n i = 0\n while i < len(s):\n if s[i] == \'X\':\n count | a_shekhar | NORMAL | 2022-09-14T17:19:34.342265+00:00 | 2022-09-14T17:19:34.342298+00:00 | 471 | false | ```\n def minimumMoves(self, s: str) -> int:\n count = 0\n i = 0\n while i < len(s):\n if s[i] == \'X\':\n count += 1\n i += 3\n elif s.count("X") == 0:\n break\n else:\n i += 1\n return count | 1 | 0 | ['Python'] | 0 |
minimum-moves-to-convert-string | Ruby - T O(n), S O(1), 100% 100% | ruby-t-on-s-o1-100-100-by-hoangphanbk10-9xao | ```\n# @param {String} s\n# @return {Integer}\ndef minimum_moves(s)\n n = s.length\n i = 0\n\n result = 0\n while i < n\n if s[i] == \'X\'\n i += 3\ | hoangphanbk10 | NORMAL | 2022-08-25T12:44:04.948402+00:00 | 2022-08-25T12:44:04.948456+00:00 | 14 | false | ```\n# @param {String} s\n# @return {Integer}\ndef minimum_moves(s)\n n = s.length\n i = 0\n\n result = 0\n while i < n\n if s[i] == \'X\'\n i += 3\n result += 1\n else\n i += 1\n end\n end\n\n result\nend | 1 | 0 | ['Ruby'] | 0 |
minimum-moves-to-convert-string | 100% Faster Very SImple o(N) | 100-faster-very-simple-on-by-hustlingfor-ubjn | \nclass Solution(object):\n def minimumMoves(self, s):\n """\n :type s: str\n :rtype: int\n """\n count = 0\n i = 0 | hustlingfornewjob | NORMAL | 2022-08-15T20:20:14.634556+00:00 | 2022-08-15T20:20:14.634604+00:00 | 268 | false | ```\nclass Solution(object):\n def minimumMoves(self, s):\n """\n :type s: str\n :rtype: int\n """\n count = 0\n i = 0\n \n while i < len(s):\n if s[i] == \'O\':\n i+=1\n else:\n count+=1\n i+=3... | 1 | 0 | ['Python'] | 0 |
minimum-moves-to-convert-string | Beats 100% (C++) | beats-100-c-by-ktheron-qf9n | \nclass Solution {\npublic:\n int minimumMoves(string s) {\n int c=0;\n for(int i=0; i<s.length(); i++)\n {\n if(s[i]==\'X\') | KTHERON | NORMAL | 2022-07-19T20:48:24.805763+00:00 | 2022-07-19T20:48:24.805793+00:00 | 164 | false | ```\nclass Solution {\npublic:\n int minimumMoves(string s) {\n int c=0;\n for(int i=0; i<s.length(); i++)\n {\n if(s[i]==\'X\')\n {\n c++;\n s[i]=\'O\';\n if(i+1<s.length())\n s[i+1]=\'O\';\n if(i+2... | 1 | 0 | ['C'] | 0 |
minimum-moves-to-convert-string | 2027. Minimum Moves to Convert String | C#| O(N) | sliding window | 2027-minimum-moves-to-convert-string-c-o-rg2j | \npublic class Solution {\n public int MinimumMoves(string s) {\n\t\tif(s==null || s.Length ==0)\n return 0;\n int windowStart =0; \n | mallikdasari | NORMAL | 2022-06-28T14:06:24.906577+00:00 | 2022-06-28T14:09:36.777133+00:00 | 76 | false | ```\npublic class Solution {\n public int MinimumMoves(string s) {\n\t\tif(s==null || s.Length ==0)\n return 0;\n int windowStart =0; \n int result =0;\n while(windowStart<s.Length){\n if(s[windowStart]== \'O\') \n windowStart++;\n else{\n ... | 1 | 0 | ['Sliding Window'] | 0 |
minimum-moves-to-convert-string | C++ Solution || 0ms || 100% Faster || Greedy | c-solution-0ms-100-faster-greedy-by-anis-a0sv | Code:\n\n\nclass Solution\n{\npublic:\n int minimumMoves(string s)\n {\n int n = s.length();\n int k = 0;\n int i;\n while (i | anis23 | NORMAL | 2022-06-28T12:53:13.311827+00:00 | 2022-06-28T12:53:13.311871+00:00 | 252 | false | **Code:**\n\n```\nclass Solution\n{\npublic:\n int minimumMoves(string s)\n {\n int n = s.length();\n int k = 0;\n int i;\n while (i < n)\n {\n if (s[i] == \'X\')\n {\n k++;\n i += 3;\n }\n else\n ... | 1 | 0 | ['Greedy', 'C', 'C++'] | 0 |
minimum-moves-to-convert-string | C++: Easy to understand, Faster than 100% | c-easy-to-understand-faster-than-100-by-mg9dm | \nint minimumMoves(string s) {\n int res = 0;\n int it=0;\n while(it<s.length()){\n if(s[it] == \'X\'){\n res++; | akshat_1607 | NORMAL | 2022-06-13T13:59:01.067027+00:00 | 2022-06-13T13:59:01.067074+00:00 | 123 | false | ```\nint minimumMoves(string s) {\n int res = 0;\n int it=0;\n while(it<s.length()){\n if(s[it] == \'X\'){\n res++; // if \'X\' is encountered, increment result by 1 and move iterator ahead by 3 \n it+=3;\n }\n else{it++;} // ... | 1 | 0 | ['String', 'C'] | 0 |
minimum-moves-to-convert-string | c++ solution || With Approach || Faster than 100% | c-solution-with-approach-faster-than-100-xyup | APPROACH\ninitilize i=0(iterator), result=0;\niterate string s using while loop till the size of string s \nin string s if we found "X" at any index we will inc | divyanihirulkar247 | NORMAL | 2022-05-27T16:54:49.911357+00:00 | 2022-05-27T17:05:44.460699+00:00 | 64 | false | **APPROACH**\ninitilize i=0(iterator), result=0;\niterate string s using while loop till the size of string s \nin string s if we found "X" at any index we will increase iterator by 3 and result by 1\nif we found "O" then increase iterator by 1 \nreturn result\n```\nclass Solution {\npublic:\n int minimumMoves(strin... | 1 | 0 | [] | 0 |
minimum-moves-to-convert-string | Simple C++ greedy approach | simple-c-greedy-approach-by-priyesh_raj_-ru9n | \n int minimumMoves(string s) {\n int count = 0;\n int i = 0 ;\n while(i<s.size()){\n if(s[i]==\'X\'){\n count | priyesh_raj_singh | NORMAL | 2022-03-22T18:10:22.659042+00:00 | 2022-03-22T18:10:22.659082+00:00 | 51 | false | ```\n int minimumMoves(string s) {\n int count = 0;\n int i = 0 ;\n while(i<s.size()){\n if(s[i]==\'X\'){\n count++;\n i+=3;\n }\n else{\n i++;\n }\n }\n return count; \n }\n``` | 1 | 0 | ['Greedy', 'C'] | 0 |
minimum-moves-to-convert-string | Greedy Algo. | greedy-algo-by-jay_kevadiya-6u3h | class Solution {\npublic:\n int minimumMoves(string s) {\n int ans = 0;\n for (int i = 0; i < s.size(); i += s[i] == \'X\' ? 3 : 1)\n ans += s[i | Jay_kevadiya | NORMAL | 2022-03-18T04:29:45.968078+00:00 | 2022-03-18T04:29:45.968108+00:00 | 36 | false | class Solution {\npublic:\n int minimumMoves(string s) {\n int ans = 0;\n for (int i = 0; i < s.size(); i += s[i] == \'X\' ? 3 : 1)\n ans += s[i] == \'X\';\n return ans;\n}\n}; | 1 | 0 | ['Greedy', 'C'] | 1 |
minimum-moves-to-convert-string | faster than 100% solutions :) | faster-than-100-solutions-by-peeronapppe-vdyp | class Solution {\npublic:\n int minimumMoves(string s) {\n int cnt=0;\n int i=0;\n for(i=0;i<s.length();i++){\n if(s[i]==\'O\ | PeeroNappper | NORMAL | 2022-03-07T14:42:13.457722+00:00 | 2022-03-07T14:42:13.457754+00:00 | 63 | false | class Solution {\npublic:\n int minimumMoves(string s) {\n int cnt=0;\n int i=0;\n for(i=0;i<s.length();i++){\n if(s[i]==\'O\') continue;\n else break;\n }\n for(int j=i;j<s.length();j++){\n if(s[j]==\'O\') continue;\n int a=0;\n ... | 1 | 0 | [] | 0 |
minimum-moves-to-convert-string | Java solution 0ms 100% | java-solution-0ms-100-by-guptashresthy-628i | \nclass Solution {\n public int minimumMoves(String s) {\n int res=0;\n for(int i=0;i<s.length();)\n {\n if(s.charAt(i)==\'X\ | guptashresthy | NORMAL | 2022-03-04T01:02:18.208196+00:00 | 2022-03-04T01:02:18.208237+00:00 | 103 | false | ```\nclass Solution {\n public int minimumMoves(String s) {\n int res=0;\n for(int i=0;i<s.length();)\n {\n if(s.charAt(i)==\'X\')\n {\n i+=3;\n res++;\n }\n else\n i++;\n }\n return res;\n ... | 1 | 0 | ['Java'] | 1 |
minimum-moves-to-convert-string | C++ | Greedy Approach | c-greedy-approach-by-deleted_user-y377 | Hint 2 : Try delaying a move as long as possible.\nExplanation : We can ignore \'O\' as long as possible.\n\t\t\t\t\t\t\t When we encounter \'X\' we have to co | deleted_user | NORMAL | 2022-03-01T07:29:45.260102+00:00 | 2022-03-01T07:29:45.260156+00:00 | 64 | false | **Hint 2 : Try delaying a move as long as possible.**\n**Explanation** : We can ignore \'O\' as long as possible.\n\t\t\t\t\t\t\t When we encounter \'X\' we have to count that as a move. \n\t\t\t\t\t\t\t \n```\nint minimumMoves(string s) {\n int move = 0;\n int i=0;\n while(i<s.size()){\n ... | 1 | 0 | [] | 0 |
minimum-moves-to-convert-string | js greedy | js-greedy-by-jasondecode-ttd6 | ```\nvar minimumMoves = function(s) {\n let i = 0;\n res = 0;\n while (i < s.length) {\n if (s[i] === \'X\') {\n s[i] = \'O\';\n | jasondecode | NORMAL | 2022-02-13T07:56:41.752441+00:00 | 2022-02-13T07:56:57.283604+00:00 | 38 | false | ```\nvar minimumMoves = function(s) {\n let i = 0;\n res = 0;\n while (i < s.length) {\n if (s[i] === \'X\') {\n s[i] = \'O\';\n s[i + 1] = \'O\';\n s[i + 2] = \'O\';\n i += 3;\n res += 1;\n } else {\n i++;\n }\n }\n r... | 1 | 0 | ['Greedy'] | 0 |
minimum-moves-to-convert-string | Simplest Python 3 code | simplest-python-3-code-by-rajatkumarrrr-268a | \nclass Solution:\n def minimumMoves(self, s: str) -> int:\n sl=list(s)\n out=0\n for i in range(0,len(sl)-2):\n if sl[i]=="X | rajatkumarrrr | NORMAL | 2022-01-26T18:17:36.578483+00:00 | 2022-01-26T18:17:36.578527+00:00 | 228 | false | ```\nclass Solution:\n def minimumMoves(self, s: str) -> int:\n sl=list(s)\n out=0\n for i in range(0,len(sl)-2):\n if sl[i]=="X":\n sl[i]="O"\n sl[i+1]="O"\n sl[i+2]="O"\n out+=1\n elif sl[i]=="O":\n ... | 1 | 0 | ['Python3'] | 0 |
minimum-moves-to-convert-string | Java : Simple | java-simple-by-arunkumar_hg-lzcc | \nclass Solution {\n public int minimumMoves(String s) \n {\n int moves = 0;\n int i=0;\n \n while(i<s.length())\n {\n | arunkumar_hg | NORMAL | 2022-01-25T10:59:00.860186+00:00 | 2022-01-25T10:59:00.860228+00:00 | 75 | false | ```\nclass Solution {\n public int minimumMoves(String s) \n {\n int moves = 0;\n int i=0;\n \n while(i<s.length())\n {\n if(s.charAt(i)==\'X\')\n {\n i+=3;\n moves++;\n }else\n {\n i++;\n ... | 1 | 0 | ['Java'] | 0 |
minimum-moves-to-convert-string | Fastest Java Solution | fastest-java-solution-by-saurabh_173-hbvg | ```\nclass Solution {\n public int minimumMoves(String s) \n {\n if(!s.contains("X"))\n return 0;\n else\n {\n | saurabh_173 | NORMAL | 2022-01-23T15:17:29.214628+00:00 | 2022-01-23T15:17:29.214655+00:00 | 75 | false | ```\nclass Solution {\n public int minimumMoves(String s) \n {\n if(!s.contains("X"))\n return 0;\n else\n {\n int count=0;\n int n=s.length();\n for(int i=0;i<n;i++)\n {\n if(s.charAt(i)==\'X\')\n {\n ... | 1 | 0 | ['Java'] | 0 |
minimum-moves-to-convert-string | cpp solution 100%faster and 85% space efficient | cpp-solution-100faster-and-85-space-effi-dgdg | \n int minimumMoves(string s) \n {\n int ans=0;\n for(int i=0;i<s.length();)\n {\n if(s[i]==\'X\')\n {\n | ashutosh2015 | NORMAL | 2022-01-20T16:35:49.789801+00:00 | 2022-01-20T16:35:49.789845+00:00 | 58 | false | ```\n int minimumMoves(string s) \n {\n int ans=0;\n for(int i=0;i<s.length();)\n {\n if(s[i]==\'X\')\n {\n int t=3;\n while(i<s.length()&&t--)\n {\n s[i]=\'0\';\n i++;\n }\n ... | 1 | 0 | ['C'] | 0 |
minimum-moves-to-convert-string | C# LINQ one-liner, O(n) | c-linq-one-liner-on-by-rad0mir-hh29 | \npublic class Solution {\n public int MinimumMoves(string s) \n => s.Aggregate((res: 0, dist: 3), \n (pos, cur) => (pos.res + ( | Rad0miR | NORMAL | 2022-01-17T11:16:43.993789+00:00 | 2022-01-17T11:16:43.993830+00:00 | 224 | false | ```\npublic class Solution {\n public int MinimumMoves(string s) \n => s.Aggregate((res: 0, dist: 3), \n (pos, cur) => (pos.res + (cur == \'X\' && pos.dist > 2 ? 1 : 0), \n (cur == \'X\' && pos.dist > 2 ? 1 : pos.dist + 1)),\n po... | 1 | 0 | [] | 2 |
minimum-moves-to-convert-string | intuitive solution | intuitive-solution-by-feexon-ornk | rust\nimpl Solution {\n pub fn minimum_moves(s: String) -> i32 {\n let (bytes, mut i, mut moves) = (s.as_bytes(), 0, 0);\n while i < bytes.len( | feexon | NORMAL | 2021-12-19T05:30:55.436546+00:00 | 2021-12-19T05:32:34.343465+00:00 | 40 | false | ```rust\nimpl Solution {\n pub fn minimum_moves(s: String) -> i32 {\n let (bytes, mut i, mut moves) = (s.as_bytes(), 0, 0);\n while i < bytes.len() {\n i += match bytes[i] {\n b\'X\' => {\n moves += 1;\n 3\n }\n ... | 1 | 0 | ['Rust'] | 0 |
minimum-moves-to-convert-string | Optimal Solution | optimal-solution-by-code_soham-e2e2 | Greedy Approach\nGiven problem states minimum steps to convert the XO string to only Os.\nAlso, under the constraint of the move described,\nif we choose an ind | code_soham | NORMAL | 2021-12-08T08:00:14.340516+00:00 | 2021-12-08T08:00:14.340551+00:00 | 100 | false | # Greedy Approach\nGiven problem states minimum steps to convert the XO string to only Os.\nAlso, under the constraint of the **move** described,\nif we choose an index for operating, we can absolutely assure that the character in the next 2 consecutive indices will also get resolved to O within that **move**. (making ... | 1 | 0 | ['String'] | 0 |
minimum-moves-to-convert-string | [Python] Greedy Sliding Window | python-greedy-sliding-window-by-dev-josh-1uet | Think about it:\n\n "XOX" is a good deal, because we can convert two X\'s\n "XXX" is also an obvious good deal\n "XXO" is a good deal too\n\nA few bad deals:\n | dev-josh | NORMAL | 2021-10-29T19:22:13.665693+00:00 | 2021-10-29T19:22:13.665715+00:00 | 138 | false | Think about it:\n\n* "XOX" is a good deal, because we can convert two X\'s\n* "XXX" is also an obvious good deal\n* "XXO" is a good deal too\n\nA few bad deals:\n* "OXX"\n\t* This could easily become "XXX" if we slide the window along by one\n\t* Thus, we should only convert "XXO" because we know the next will either b... | 1 | 1 | ['Python', 'Python3'] | 0 |
minimum-moves-to-convert-string | cpp | cpp-by-testing555111-fj60 | \nclass Solution {\npublic:\n int minimumMoves(string s) {\n int ret = 0;\n for (int i=0;i<s.length();i++) {\n if (s[i]==\'X\') {\n | testing555111 | NORMAL | 2021-10-26T08:49:13.976933+00:00 | 2021-10-26T08:49:13.976967+00:00 | 28 | false | ```\nclass Solution {\npublic:\n int minimumMoves(string s) {\n int ret = 0;\n for (int i=0;i<s.length();i++) {\n if (s[i]==\'X\') {\n ret++;\n i+=2;\n }\n }\n return ret;\n }\n};\n``` | 1 | 0 | [] | 0 |
minimum-moves-to-convert-string | Rust | Greedy approach | rust-greedy-approach-by-deleted_user-zr28 | Analysis:\n\nIf we need to flip an \'X\' at an index i, then any \'X\' at indices i+1 and i+2 will also be converted into a \'O\', should those indices exist.\n | deleted_user | NORMAL | 2021-10-25T02:19:19.529680+00:00 | 2021-10-25T02:19:31.037621+00:00 | 65 | false | **Analysis:**\n\nIf we need to flip an \'X\' at an index `i`, then any \'X\' at indices `i+1` and `i+2` will also be converted into a \'O\', should those indices exist.\n\nSo greedily, we can flip any \'X\' into a \'O\', and advance the index by 3. Otherwise flip the index by 1.\n\n**Solution:**\n\n```\nimpl Solution {... | 1 | 0 | ['Greedy', 'Rust'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.