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
swap-adjacent-in-lr-string
Fully explained | C++ ✅ | Easy to Understand ✅
fully-explained-c-easy-to-understand-by-be86h
\n# Approach\n1. First, we need to check if both strings, excluding \'X\', are identical in character order.\n This ensures that the transformation is at leas
Taranum_01
NORMAL
2024-08-12T11:03:47.959422+00:00
2024-08-13T18:08:56.513992+00:00
462
false
\n# Approach\n1. First, we need to check if both strings, excluding \'X\', are identical in character order.\n This ensures that the transformation is at least possible based on character content.\n 2. Next, we iterate through both strings using two pointers. We skip \'X\' characters \n and compare the positions of \...
5
1
['C++']
0
swap-adjacent-in-lr-string
Python O(n) with comments and reasonings
python-on-with-comments-and-reasonings-b-kkw3
\n\nclass Solution:\n \'\'\'\n 1. The order of L and Rs in the start and end must be the same as L and R cannot cross one another. The allowed transformat
cutkey
NORMAL
2022-05-17T09:00:29.884553+00:00
2022-05-17T09:04:06.333359+00:00
517
false
```\n\nclass Solution:\n \'\'\'\n 1. The order of L and Rs in the start and end must be the same as L and R cannot cross one another. The allowed transformations are \n equivalent to an L/R swapping position with an adjacent X (Left X for L and right X for R). In other words L and R can cross an X \n\t (t...
5
0
[]
1
swap-adjacent-in-lr-string
Python One Pass O(N) Time O(1) Space
python-one-pass-on-time-o1-space-by-bz23-4mqz
Observations:\n1. R can only be moved to right\n2. L can only be moved to left\n3. Relative order of R and L cannot be changed\n\nThus, at any given index i, nu
bz2342
NORMAL
2022-01-09T03:15:15.400273+00:00
2022-01-09T03:15:15.400305+00:00
537
false
Observations:\n1. R can only be moved to right\n2. L can only be moved to left\n3. Relative order of R and L cannot be changed\n\nThus, at any given index `i`, number R in `start[:i+1]` >= in ` end[:i+1]`, number of L in `start[:i+1]` <= in `end[:i+1]`. \n\nSolution: go thru start and end from left to right, maintain t...
5
0
['Python']
0
swap-adjacent-in-lr-string
Simplest Python Solution O(n)
simplest-python-solution-on-by-deo_stree-tdt7
\'\'\'\nclass Solution:\n def canTransform(self, start: str, end: str) -> bool:\n \n so , eo , sind, eind = [],[],[],[]\n for i in range
Deo_Street
NORMAL
2021-09-30T06:22:37.434183+00:00
2021-09-30T06:22:37.434214+00:00
1,370
false
\'\'\'\nclass Solution:\n def canTransform(self, start: str, end: str) -> bool:\n \n so , eo , sind, eind = [],[],[],[]\n for i in range(len(start)):\n if start[i] != \'X\':\n so.append(start[i])\n sind.append(i)\n if end[i] != \'X\':\n ...
5
0
['Python', 'Python3']
1
swap-adjacent-in-lr-string
Easy to follow C++ solution
easy-to-follow-c-solution-by-levins-9k1k
We just need to record each \'L\' and \'R\' positions in both string, and compare them. Since \'L\' can only move left and \'R\' can only move right, \'L\' pos
levins
NORMAL
2021-04-25T20:10:44.052182+00:00
2021-04-25T20:11:34.492197+00:00
378
false
We just need to record each \'L\' and \'R\' positions in both string, and compare them. Since \'L\' can only move left and \'R\' can only move right, \'L\' position in end string should be <= that in start string. Similarly \'R\' position in end string should be >= that in start string.\n\n```\nclass Solution {\npubli...
5
0
[]
0
swap-adjacent-in-lr-string
Straightforward Python solution
straightforward-python-solution-by-otoc-rghn
Based on the rules, we can move \'L\' to left, \'R\' to right without crossing any \'L\' or \'R\'.\n\n def canTransform(self, start: str, end: str) -> bool:\
otoc
NORMAL
2019-08-15T22:26:19.925654+00:00
2019-08-15T22:39:07.304204+00:00
394
false
Based on the rules, we can move \'L\' to left, \'R\' to right without crossing any \'L\' or \'R\'.\n```\n def canTransform(self, start: str, end: str) -> bool:\n n = len(start)\n groups_start = [[start[i], i] for i in range(n) if start[i] != \'X\']\n groups_end = [[end[i], i] for i in range(n) i...
5
0
[]
1
swap-adjacent-in-lr-string
5ms Java with Explanations
5ms-java-with-explanations-by-gracemeng-hwid
-- What does either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR" mean?\nL and R cannot go across each other, that i
gracemeng
NORMAL
2018-10-26T23:28:41.250447+00:00
2018-10-26T23:28:41.250517+00:00
433
false
-- What does `either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR"` mean?\nL and R cannot go across each other, that is, their relative order in a string doesn\'t change.\nMeanwhile, we should satisfy either one of cases below: \n```\ncase 1 : L = start[i] = end[j] and i >= j...
5
0
[]
1
swap-adjacent-in-lr-string
Easy C++ Solution || Basic Loops || Easy To Understand For Begineers || proper Comment
easy-c-solution-basic-loops-easy-to-unde-rczo
Read the comment for better understanding of the solution\n\n\nclass Solution {\npublic:\n bool canTransform(string start, string end) {\n string f,s;
Abhisheksaware
NORMAL
2022-08-10T14:59:26.626083+00:00
2022-08-10T14:59:26.626112+00:00
995
false
***Read the comment for better understanding of the solution***\n\n```\nclass Solution {\npublic:\n bool canTransform(string start, string end) {\n string f,s; // to copy only original pattern from the string \n for(int i=0;i<start.size();i++)\n {\n if(start[i]!=\'X\') f+=star...
4
0
['C', 'C++']
0
swap-adjacent-in-lr-string
a joke misunderstanding to me
a-joke-misunderstanding-to-me-by-haoleet-x92v
Not sure if only me, but I first mis-understood the L, R switch can only happen one time, to either left or right position X.\n\nAnd the solution I wrote passed
haoleetcode
NORMAL
2022-08-09T00:11:54.104516+00:00
2022-08-09T00:11:54.104546+00:00
488
false
Not sure if only me, but I first mis-understood the L, R switch can only happen one time, to either left or right position X.\n\nAnd the solution I wrote passed 59/94 test cases @_@\n
4
0
[]
1
swap-adjacent-in-lr-string
[C++] Two pointers solution [Detailed Explanation]
c-two-pointers-solution-detailed-explana-2941
\n/*\n https://leetcode.com/problems/swap-adjacent-in-lr-string/\n \n Things to note:\n 1. Based on the swap patterns, L can be moved to left in pre
cryptx_
NORMAL
2022-06-29T15:50:27.881402+00:00
2022-06-29T15:50:27.881453+00:00
415
false
```\n/*\n https://leetcode.com/problems/swap-adjacent-in-lr-string/\n \n Things to note:\n 1. Based on the swap patterns, L can be moved to left in presence of X\n 2. R can be moved right in presence of X\n \n So that means it is only possible to swap and reach end iff each L in start lies atleast\...
4
0
['C', 'C++']
0
swap-adjacent-in-lr-string
Simple Java one Pass O(N). Moving On A Track
simple-java-one-pass-on-moving-on-a-trac-srb7
Imagine 2 kinds of pawn moving on a track, left pawn and right pawn. You want to push all the left pawns to the left and all the right pawns to the right.\nThe
vipergo
NORMAL
2022-05-27T13:27:52.498069+00:00
2022-05-27T13:27:52.498108+00:00
643
false
Imagine 2 kinds of pawn moving on a track, left pawn and right pawn. You want to push all the left pawns to the left and all the right pawns to the right.\nThe right pawn will block all the left pawns from its right to move left, and the left pawn will block all the right pawns from its left to move right.\n```\nclass ...
4
0
[]
5
swap-adjacent-in-lr-string
Super Crisp || Spoon Feeding explanation || Time = O(n)
super-crisp-spoon-feeding-explanation-ti-0p42
\nclass Solution\n{\n public:\n bool canTransform(string start, string end)\n {\n int si = 0;\n int ei = 0;\n \n while (si
meta_fever
NORMAL
2022-03-16T14:48:11.945464+00:00
2022-03-16T15:19:39.592770+00:00
207
false
```\nclass Solution\n{\n public:\n bool canTransform(string start, string end)\n {\n int si = 0;\n int ei = 0;\n \n while (si < start.size() || ei < end.size())\n {\n\t\t // Skip all \'X\' and find 1st letter after X in \'start\' & \'end\'.\n while (si < start.s...
4
0
[]
1
swap-adjacent-in-lr-string
JAVA O(N) with Stack
java-on-with-stack-by-tmc204-wtvl
\nclass Solution {\n public boolean canTransform(String start, String end) {\n Stack<Integer> L = new Stack(), R = new Stack();\n for (int i =
tmc204
NORMAL
2022-03-13T07:29:15.437070+00:00
2022-03-13T07:29:29.333255+00:00
274
false
```\nclass Solution {\n public boolean canTransform(String start, String end) {\n Stack<Integer> L = new Stack(), R = new Stack();\n for (int i = 0; i < start.length(); i++) {\n if (start.charAt(i) == \'R\')\n R.add(i);\n if (end.charAt(i) == \'L\')\n ...
4
0
[]
1
swap-adjacent-in-lr-string
Java || Explained || Easy to understand
java-explained-easy-to-understand-by-ico-d22v
// Replace all \'X\' in both strings and see if they are SAME then return true\n// Whenever you see \'X\' just update the idx\n\n// TC : O(N) -> N = start.lengt
ICodeToSurvive
NORMAL
2022-01-30T09:01:19.087309+00:00
2022-01-30T09:01:19.087350+00:00
288
false
// Replace all \'X\' in both strings and see if they are SAME then return true\n// Whenever you see \'X\' just update the idx\n\n// TC : O(N) -> N = start.length\n// SC : O(1)\n```\nclass Solution {\n public boolean canTransform(String start, String end) {\n int startIdx = 0;\n int endIdx = 0;\n ...
4
0
[]
0
swap-adjacent-in-lr-string
Simple C++ solution
simple-c-solution-by-ranjan_1997-i260
\nclass Solution {\npublic:\n bool canTransform(string start, string end) {\n if(start.length() == 1)\n return start == end;\n int n
ranjan_1997
NORMAL
2021-05-30T06:00:49.819651+00:00
2021-05-30T06:00:49.819684+00:00
317
false
```\nclass Solution {\npublic:\n bool canTransform(string start, string end) {\n if(start.length() == 1)\n return start == end;\n int n = start.length();\n int i = 0;\n int j = 0;\n while(1)\n {\n while(i<n and start[i] == \'X\')\n i++;\n...
4
0
[]
0
swap-adjacent-in-lr-string
Simple C++ Solution with explanation
simple-c-solution-with-explanation-by-ro-lmve
Idea is that L moves backwards (XL->LX) and R moves forwards (RX->XR) so L is decremented and R is incremented. Parallely at the same position of end string, L
rootkonda
NORMAL
2020-05-04T12:01:38.451912+00:00
2020-05-04T12:10:44.924225+00:00
315
false
Idea is that L moves backwards (XL->LX) and R moves forwards (RX->XR) so L is decremented and R is incremented. Parallely at the same position of end string, L will be incremented and R will be decremented. At any point, if the count of L or R becomes -ve then return false. \n\nNote that L cannot move beyond R and R ca...
4
0
[]
1
swap-adjacent-in-lr-string
C++ Solution with explanation
c-solution-with-explanation-by-mradul-x4va
We can only move "R" backwards and "L" forward as we can convert "XL" to "LX" and "RX" to "XR"\n\n - Maintain count of R\'s found in the "start" string to ma
mradul
NORMAL
2019-12-10T06:54:06.659271+00:00
2019-12-10T06:54:06.659314+00:00
342
false
We can only move "R" backwards and "L" forward as we can convert "XL" to "LX" and "RX" to "XR"\n\n - Maintain count of R\'s found in the "start" string to match with "end"\n - BECAUSE WE CAN ONLY MOVE "R" BACK WE INC THEM WHEN WE FIND THEM IN "start" AND DECREMENT IN "end" (matching step)\n \n - Mai...
4
0
[]
1
swap-adjacent-in-lr-string
One pass O(n) Python, beat 99%, easy to understand
one-pass-on-python-beat-99-easy-to-under-ydzr
The idea is keep a variable count. For start, R plus 1, L minus 1, opposite for end. And they should meet two rules:\n1.The count could not be less than 0.\nOne
pengp17
NORMAL
2019-06-28T06:24:33.737541+00:00
2019-06-28T06:24:33.737588+00:00
500
false
The idea is keep a variable ```count```. For ```start```, R plus 1, L minus 1, opposite for ```end```. And they should meet two rules:\n1.The count could not be less than 0.\nOne example is "XR" and "RX". Remember you can only replace strings in start, not end.\n2.The difference could never be 2 or -2.\nOne example is ...
4
1
[]
1
swap-adjacent-in-lr-string
short and easy solution in C++
short-and-easy-solution-in-c-by-chaitany-5orr
\nclass Solution {\npublic:\n bool canTransform(string s, string e) {\n int i = 0, j = 0, n = s.size(), m = e.size();\n while(i < n || j < m) {
chaitanyya
NORMAL
2023-03-15T06:56:47.771917+00:00
2023-03-15T06:56:47.771949+00:00
955
false
```\nclass Solution {\npublic:\n bool canTransform(string s, string e) {\n int i = 0, j = 0, n = s.size(), m = e.size();\n while(i < n || j < m) {\n while(s[i] == \'X\') i++;\n while(e[j] == \'X\') j++;\n\n if(s[i] != e[j]) return false;\n if(s[i] == \'R\' &&...
3
0
['C', 'C++']
0
swap-adjacent-in-lr-string
c++ | easy | fast
c-easy-fast-by-venomhighs7-7b5s
\n\n# Code\n\nclass Solution {\npublic:\n bool canTransform(string start, string end) {\n \n int i=0, j=0;\n while(i<start.size() && j<e
venomhighs7
NORMAL
2022-11-18T04:50:26.012805+00:00
2022-11-18T04:50:26.012853+00:00
600
false
\n\n# Code\n```\nclass Solution {\npublic:\n bool canTransform(string start, string end) {\n \n int i=0, j=0;\n while(i<start.size() && j<end.size()) {\n \n while(start[i]==\'X\') i++;\n while(end[j]==\'X\') j++;\n \n if(start[i]!=end[j]) re...
3
0
['C++']
2
swap-adjacent-in-lr-string
Python with explanation
python-with-explanation-by-lizihao52100-bf8v
\nclass Solution:\n def canTransform(self, start: str, end: str) -> bool:\n # replace x with empty string to make sure the left R and L are in same or
lizihao52100
NORMAL
2022-03-25T03:23:25.742223+00:00
2022-03-25T03:23:25.742260+00:00
100
false
```\nclass Solution:\n def canTransform(self, start: str, end: str) -> bool:\n # replace x with empty string to make sure the left R and L are in same order\n if start.replace("X","") != end.replace("X",""):\n return False\n n = len(start)\n i = j = 0\n # check the index...
3
0
[]
0
swap-adjacent-in-lr-string
JavaScript (two pointer with comments)
javascript-two-pointer-with-comments-by-lrmw0
\n/**\n* @param {string} start\n* @param {string} end\n* @return {boolean}\n*/\nvar canTransform = function (start, end) {\n const sWithoutX = start.replace(
justin_kunz
NORMAL
2022-03-21T00:53:39.728569+00:00
2022-03-21T00:53:39.728594+00:00
300
false
```\n/**\n* @param {string} start\n* @param {string} end\n* @return {boolean}\n*/\nvar canTransform = function (start, end) {\n const sWithoutX = start.replace(/X/g, \'\');\n const eWithoutX = end.replace(/X/g, \'\');\n\n // start and end text without x\'s should equal\n if (sWithoutX !== eWithoutX) return ...
3
0
['JavaScript']
0
swap-adjacent-in-lr-string
Python O(n) solution with explanation
python-on-solution-with-explanation-by-p-ebj5
idea:\n1. each time we saw a L in end string, it means that we must find a L in start (increase the debtL)\n2. each time we saw a R in end string, it means that
pacificdou
NORMAL
2022-03-09T09:31:53.359285+00:00
2022-03-09T09:31:53.359317+00:00
143
false
idea:\n1. each time we saw a L in end string, it means that we must find a L in start (increase the debtL)\n2. each time we saw a R in end string, it means that we must already found a R in start (decrease the debtR)\n3. in case of RL, L cannot move left of R, so if this L is a matching L, at the time we found this L, ...
3
0
[]
0
swap-adjacent-in-lr-string
A solution that moves 'X' if you find this easier to understand.
a-solution-that-moves-x-if-you-find-this-5pmt
The move is as follows:\n\n1. X can go through R to move to the left\nRRRX. -> XRRR\n\n2. X can go through L to move to the right\nXLLL -> LLLX\n\nNow go from l
x372p
NORMAL
2022-01-22T08:48:12.642656+00:00
2022-01-22T08:53:24.336218+00:00
203
false
The move is as follows:\n\n1. X can go through R to move to the left\nRRRX. -> XRRR\n\n2. X can go through L to move to the right\nXLLL -> LLLX\n\nNow go from left to right, have counter to save number of \'X\' in end minus number of \'X\' in start\n```\ncount = #\'X\' in end - #\'X\' in start\n```\n\nThere could be tw...
3
0
[]
0
swap-adjacent-in-lr-string
C++ two pointers O(n)
c-two-pointers-on-by-bcb98801xx-t10u
The key is that we only can make \'L\' backword and \'R\' forward.\n\nclass Solution {\npublic:\n bool canTransform(string start, string end) {\n int
bcb98801xx
NORMAL
2021-09-14T02:18:43.249333+00:00
2021-09-14T02:18:43.249377+00:00
260
false
The key is that we only can make \'L\' backword and \'R\' forward.\n```\nclass Solution {\npublic:\n bool canTransform(string start, string end) {\n int n = start.size();\n int i = 0, j = 0;\n \n for( ; j < n; j++){\n if (end[j] == \'X\') continue;\n \n wh...
3
0
[]
0
swap-adjacent-in-lr-string
java simple solution o(n)
java-simple-solution-on-by-516527986-yyjy
rnum: there are rnum of \'R\' need to move to right;\nlnum: there are lnum of \'L\' need to move to left;\n\nclass Solution {\n public boolean canTransform(
516527986
NORMAL
2021-04-21T10:54:52.716987+00:00
2021-12-26T12:00:17.246618+00:00
585
false
rnum: there are rnum of \'R\' need to move to right;\nlnum: there are lnum of \'L\' need to move to left;\n```\nclass Solution {\n public boolean canTransform(String start, String end) {\n if (start.length() != end.length()) return false;\n int rnum = 0, lnum = 0;\n for (int i = 0; i < start.le...
3
0
['Java']
1
swap-adjacent-in-lr-string
C++ O(n) time | O(1) space | Explained with examples
c-on-time-o1-space-explained-with-exampl-07e8
Rules: \nXL -> LX\nRX -> XR\nRL is a deadline.(incase it dosen\'t match with \'end\')\nSo check for dangling \'R\' to the right side of \'RL\' (i.e an R not fol
aparna_g
NORMAL
2021-01-22T17:51:48.975824+00:00
2021-01-22T17:51:48.975854+00:00
427
false
Rules: \nXL -> LX\nRX -> XR\nRL is a deadline.(incase it dosen\'t match with \'end\')\nSo check for dangling \'R\' to the right side of \'RL\' (i.e an R not followed by an \'X\' and not matching with end[i])\n***Something like : "XRLXR" and "RXXLL"***\nFor finding unpaired \'L\' iterate from the end, check for a dangli...
3
2
['C', 'C++']
1
swap-adjacent-in-lr-string
Easy Python
easy-python-by-ztyreg-drre
python\nclass Solution:\n def canTransform(self, start: str, end: str) -> bool:\n # Same number of L and R\n if start.replace(\'X\', \'\') != e
ztyreg
NORMAL
2020-08-17T18:45:01.844008+00:00
2020-08-17T18:49:19.768332+00:00
462
false
```python\nclass Solution:\n def canTransform(self, start: str, end: str) -> bool:\n # Same number of L and R\n if start.replace(\'X\', \'\') != end.replace(\'X\', \'\'):\n return False\n # L can only move left and R can only move right\n l_start = [i for i, c in enumerate(star...
3
0
['Python', 'Python3']
0
swap-adjacent-in-lr-string
simple C++ O(N) Stack Solution beats 90%
simple-c-on-stack-solution-beats-90-by-i-dxyw
\nclass Solution {\npublic:\n bool canTransform(string start, string end) {\n stack<pair<char, int>> st1, st2;\n if (start.length() != end.leng
indrajohn
NORMAL
2020-06-24T11:10:38.361056+00:00
2020-06-24T11:10:38.361089+00:00
184
false
```\nclass Solution {\npublic:\n bool canTransform(string start, string end) {\n stack<pair<char, int>> st1, st2;\n if (start.length() != end.length()) return false;\n for (int i = 0; i < start.length(); i++) {\n if (start[i] != \'X\') st1.push(make_pair(start[i], i));\n ...
3
0
[]
0
swap-adjacent-in-lr-string
Really concise and fast C++ code 8ms
really-concise-and-fast-c-code-8ms-by-za-ey0z
\nclass Solution {\npublic:\n bool canTransform(string start, string end) {\n int n = start.length();\n if(n != end.length()) return false;\n
zacharyzyh
NORMAL
2019-07-10T15:21:10.472543+00:00
2019-07-10T15:21:10.472587+00:00
284
false
```\nclass Solution {\npublic:\n bool canTransform(string start, string end) {\n int n = start.length();\n if(n != end.length()) return false;\n int l1 = 0, l2 = 0, r1 = 0, r2 = 0;\n for(int i = 0; i < n; ++i){\n if(start[i] == \'L\') ++l1;\n else if(start[i] == \'R\...
3
0
[]
0
swap-adjacent-in-lr-string
4ms 99% simple C++ solution
4ms-99-simple-c-solution-by-lindawang-mymo
The relative position of R and L can\'t be changed. Since R can only move back and L can only move forward, the position of R in the "end" can\'t be less than i
lindawang
NORMAL
2019-06-01T07:31:46.052280+00:00
2019-06-06T08:55:57.956891+00:00
317
false
The relative position of R and L can\'t be changed. Since R can only move back and L can only move forward, the position of R in the "end" can\'t be less than it in the start, the position of L in the "end" can\'t be larger than that of in the "start". "X"s are like "spaces". \n```\nclass Solution {\npublic:\n bool ...
3
0
[]
3
swap-adjacent-in-lr-string
JavaScript super clean, O(n)
javascript-super-clean-on-by-mildog8-jy45
js\n/**\n * @param {string} start\n * @param {string} end\n * @return {boolean}\n */\nvar canTransform = function(start, end) {\n const N = start.length\n let
mildog8
NORMAL
2019-02-27T09:00:31.942422+00:00
2019-02-27T09:00:31.942487+00:00
252
false
```js\n/**\n * @param {string} start\n * @param {string} end\n * @return {boolean}\n */\nvar canTransform = function(start, end) {\n const N = start.length\n let i = 0\n let j = 0\n \n while (i < N && j < N) {\n while (start[i] === \'X\') i++\n while (end[j] === \'X\') j++\n \n if (\n (start[i] !=...
3
3
[]
1
swap-adjacent-in-lr-string
One pass O(n) Python Solution
one-pass-on-python-solution-by-toby-0njq
We just need to keep track of two counters.\n\nclass Solution:\n def canTransform(self, start: \'str\', end: \'str\') -> \'bool\':\n countR = 0\n
toby
NORMAL
2019-02-21T03:18:33.694037+00:00
2019-02-21T03:18:33.694075+00:00
236
false
We just need to keep track of two counters.\n```\nclass Solution:\n def canTransform(self, start: \'str\', end: \'str\') -> \'bool\':\n countR = 0\n countL = 0\n for idx in range(len(start)):\n if start[idx] == \'R\':\n countR += 1\n if end[idx] == \'L\':\n ...
3
0
[]
1
swap-adjacent-in-lr-string
C++ 10 Line O(n) Solution
c-10-line-on-solution-by-code_report-7i0j
````\n bool canTransform(string start, string end) {\n\n string s, t;\n \n FORI (0, start.size ()) if (start[i] != 'X') s += start[i];\n
code_report
NORMAL
2018-02-04T04:03:24.192000+00:00
2018-02-04T04:03:24.192000+00:00
596
false
````\n bool canTransform(string start, string end) {\n\n string s, t;\n \n FORI (0, start.size ()) if (start[i] != 'X') s += start[i];\n FORI (0, end.size ()) if (end[i] != 'X') t += end[i];\n \n if (s != t) return false;\n else {\n int sR = 0, sL = 0, eR =...
3
1
[]
1
swap-adjacent-in-lr-string
777: Beats 95.06%, Solution with step by step explanation
777-beats-9506-solution-with-step-by-ste-1cq4
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n\ni, j = 0, 0\nn, m = len(start), len(end)\n\nWe create two pointers, i a
Marlen09
NORMAL
2023-10-28T06:14:40.139569+00:00
2023-10-28T06:14:40.139597+00:00
595
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n```\ni, j = 0, 0\nn, m = len(start), len(end)\n```\nWe create two pointers, i and j, to iterate through start and end, respectively. We also store the lengths of start and end in n and m.\n\nWe continue while neither i nor j...
2
0
['Two Pointers', 'String', 'Python', 'Python3']
1
swap-adjacent-in-lr-string
Solution
solution-by-deleted_user-0y63
C++ []\nclass Solution {\npublic:\n bool canTransform(string st, string tar) {\n int n=tar.length();\n int i=0,j=0;\n while(i<=n && j<=n
deleted_user
NORMAL
2023-04-28T07:56:06.584074+00:00
2023-04-28T08:15:25.681804+00:00
789
false
```C++ []\nclass Solution {\npublic:\n bool canTransform(string st, string tar) {\n int n=tar.length();\n int i=0,j=0;\n while(i<=n && j<=n){\n while(i<n && tar[i]==\'X\') i++;\n while(j<n && st[j]==\'X\') j++;\n if(i==n || j==n)\n return i==n && j...
2
0
['C++', 'Java', 'Python3']
0
swap-adjacent-in-lr-string
Simple Java solution | Keep ordering of L, R
simple-java-solution-keep-ordering-of-l-mvy20
The idea is must guarantee:\n- Number of L, R are the same and keep ordering. \n- Number of X on the left of L from end always less than or equal the correspond
thangloi
NORMAL
2022-10-13T05:13:29.897308+00:00
2022-10-13T05:13:29.897351+00:00
1,140
false
The idea is must guarantee:\n- Number of L, R are the same and keep ordering. \n- Number of X on the left of L from `end` always less than or equal the corresponding L from `start`\n- Number of X on the right of R from `end` always more than or equal the corresponding R from `start`\n\nWe can terminate the process earl...
2
0
['Java']
0
swap-adjacent-in-lr-string
simple explanation C++ | two pointers
simple-explanation-c-two-pointers-by-the-yowu
\nclass Solution {\npublic:\n \n // * R and L ka order remains unchanged\n // * L can go only left of X\n // * R can go only right of X\n \n /
thesarimahmed
NORMAL
2022-09-11T18:11:01.918082+00:00
2022-09-11T18:11:01.918131+00:00
386
false
```\nclass Solution {\npublic:\n \n // * R and L ka order remains unchanged\n // * L can go only left of X\n // * R can go only right of X\n \n // logic: use two pointers to find positions of L and R (ptr1 for start and ptr2 for end)\n // the pointers skip all X\'s (consider X\'s as spaces)\n //...
2
0
['Two Pointers', 'C', 'C++']
0
swap-adjacent-in-lr-string
C++ | Easiest code | Clean and easy to understand
c-easiest-code-clean-and-easy-to-underst-yglv
Please upvote\n\nclass Solution {\npublic:\n bool canTransform(string s, string e) {\n int n=s.size(); \n int i=0,j=0;\n while(i<n or j<n)
GeekyBits
NORMAL
2022-07-12T13:41:34.422971+00:00
2022-07-12T13:41:34.423005+00:00
108
false
Please upvote\n```\nclass Solution {\npublic:\n bool canTransform(string s, string e) {\n int n=s.size(); \n int i=0,j=0;\n while(i<n or j<n){\n \n while(i<n and s[i]==\'X\'){\n i++;\n }\n while(j<n and e[j]==\'X\'){\n j++;\...
2
0
[]
0
swap-adjacent-in-lr-string
Simple Java two-pointers solution (no replace( ), no equals(), no StringBuilder)
simple-java-two-pointers-solution-no-rep-mt1y
\nclass Solution {\n public boolean canTransform(String start, String end) {\n \n int p1=0, p2=0;\n \n while(p1 < start.length()
Jumbook
NORMAL
2022-06-15T18:12:15.983668+00:00
2022-06-15T18:15:13.518400+00:00
639
false
```\nclass Solution {\n public boolean canTransform(String start, String end) {\n \n int p1=0, p2=0;\n \n while(p1 < start.length() || p2 < end.length()) {\n while(p1 < start.length() && start.charAt(p1) == \'X\')\n p1++;\n while(p2 < end.length() && e...
2
0
['Two Pointers', 'Java']
0
swap-adjacent-in-lr-string
[Java] Two Pointer One Pass O(n) with Explanation
java-two-pointer-one-pass-on-with-explan-pghd
We have 3 cases to handle:\n1. if Xs are removed, the two strings should be identical.\n2. L cannot go to right.\n3. R cannot go to left.\n\nBased on that we ca
lancewang
NORMAL
2022-05-03T17:18:03.856292+00:00
2022-05-03T17:18:03.856326+00:00
271
false
We have 3 cases to handle:\n1. if Xs are removed, the two strings should be identical.\n2. L cannot go to right.\n3. R cannot go to left.\n\nBased on that we can use two pointers and check Rs and Ls positions.\n\n```\npublic boolean canTransform(String start, String end) {\n char[] s = start.toCharArray();\n char...
2
0
['Two Pointers']
1
swap-adjacent-in-lr-string
Java 2 pointers O(n)
java-2-pointers-on-by-agusg-m7p4
\nclass Solution {\n public boolean canTransform(String start, String end) {\n int f = 0;\n int s = 0;\n while(f < start.length() || s <
agusg
NORMAL
2022-04-17T14:32:20.864939+00:00
2022-04-17T14:32:49.266719+00:00
643
false
```\nclass Solution {\n public boolean canTransform(String start, String end) {\n int f = 0;\n int s = 0;\n while(f < start.length() || s < end.length()) {\n while(f < start.length() && start.charAt(f) == \'X\') f++;\n while(s < end.length() && end.charAt(s) == \'X\') s++;\...
2
0
['Two Pointers', 'Java']
0
swap-adjacent-in-lr-string
FAANG Onsite Interview Problem - Solution - C++ - O(N)
faang-onsite-interview-problem-solution-xxjl1
My friend was asked from one of the FAANG companies.\n\nLogic & Algo\nWe will check all the cases where it should return false, if none matches then we will ret
kshitijSinha
NORMAL
2022-03-23T09:26:37.559790+00:00
2022-03-23T09:34:33.488171+00:00
331
false
My friend was asked from one of the FAANG companies.\n\n**Logic & Algo**\nWe will check all the cases where it should return false, if none matches then we will return true.\nWe will use two pointers, one for start (say, iS), and one for end(say, iE).\nWe will move iS and iE till they are pointing at \'X\'.\nNow, if iS...
2
0
['C']
1
swap-adjacent-in-lr-string
java solution with comments
java-solution-with-comments-by-aryan999-yds1
\npublic boolean swapAdjacentInLRString(String s, String e) {\n\tif(s.length() != e.length()) return false;\n\tint i = 0, j = 0;\n\tchar[] st = s.toCharArray();
aryan999
NORMAL
2022-02-19T13:26:00.034143+00:00
2022-02-19T13:26:00.034178+00:00
165
false
```\npublic boolean swapAdjacentInLRString(String s, String e) {\n\tif(s.length() != e.length()) return false;\n\tint i = 0, j = 0;\n\tchar[] st = s.toCharArray();\n\tchar[] ed = e.toCharArray();\n\twhile(i < st.length || j < ed.length) {\n\t\t// only need to work with \'L\' and \'R\' so ignore \'X\'\n\t\twhile(i < st....
2
0
[]
0
swap-adjacent-in-lr-string
Python 3 with explanation
python-3-with-explanation-by-2mobile-ywkg
\n\nFound idea in discussion, replacing names to make it readable. The first idea is \'RX\' can be replaced only with \'XR\', which means that \'R\' is always m
2mobile
NORMAL
2022-02-01T22:39:09.691416+00:00
2022-02-01T22:39:09.691456+00:00
209
false
\n\nFound idea in discussion, replacing names to make it readable. The first idea is \'RX\' can be replaced only with \'XR\', which means that \'R\' is always moving to the right position if replacement was done. If many replacements done, \'R\' can move to the right so many times until there is a \'L\' on the road or...
2
0
[]
0
swap-adjacent-in-lr-string
[C++] Strict one pass, O(n) time, O(1) space
c-strict-one-pass-on-time-o1-space-by-ti-apn8
\n// IDEA:\n// 1. Observed that for a valid result:\n// a. For each \'R\' in start, you will have to shift it to right\n// without meeting any \'
tinfu330
NORMAL
2021-12-17T02:31:29.884276+00:00
2021-12-17T08:33:02.916811+00:00
352
false
```\n// IDEA:\n// 1. Observed that for a valid result:\n// a. For each \'R\' in start, you will have to shift it to right\n// without meeting any \'L\' in either start or end\n// b. Similar to a, For each \'L\' in end, you will have to shift it\n// to right without meeting any \'R\' in eithe...
2
0
['C', 'C++']
0
swap-adjacent-in-lr-string
Simple Java O(n) solution with O(1) space with explanation
simple-java-on-solution-with-o1-space-wi-r41y
The problem states that cars cannot collide while moving from one position to the other. Hence if we remove the empty lanes both the start and end would look li
shaolao
NORMAL
2021-07-03T06:27:39.057175+00:00
2021-07-03T06:40:01.370915+00:00
359
false
The problem states that cars cannot collide while moving from one position to the other. Hence if we remove the empty lanes both the start and end would look like identical. For Example : \nstart -> `RXXL` end -> `XRXL`. Both of the strings are identical if we remove the empty lanes -> `RL`. This is because no two cars...
2
0
['Two Pointers']
0
swap-adjacent-in-lr-string
Simple one pass solution O(n) c++
simple-one-pass-solution-on-c-by-miaodi1-j5si
\n bool canTransform(string start, string end) {\n int l = 0;\n int r = 0;\n for(int i = 0;i<start.size();i++){\n if(start[i]
miaodi1987
NORMAL
2021-01-31T04:56:15.448409+00:00
2021-01-31T04:56:15.448438+00:00
361
false
```\n bool canTransform(string start, string end) {\n int l = 0;\n int r = 0;\n for(int i = 0;i<start.size();i++){\n if(start[i]==\'R\'){\n r++;\n }\n if(end[i]==\'L\'){\n l++;\n }\n if(l&&r) return false;\n ...
2
0
['C']
1
swap-adjacent-in-lr-string
(Java Stack) Each 'L' and 'R' in 'start' actually corresponds to each other in 'end'
java-stack-each-l-and-r-in-start-actuall-gvto
As the title indicates, each \'L\' and \'R\' in \'start\' should correspond to their counterparts in \'end\'. This is because \'R\' can only move to right blank
getonthecar
NORMAL
2020-09-17T20:39:21.408431+00:00
2020-09-17T20:55:07.393938+00:00
352
false
As the title indicates, each \'L\' and \'R\' in \'start\' should correspond to their counterparts in \'end\'. This is because \'R\' can only move to right blank space \'X\' (if any) and \'L\' can only move to left blank space \'X\' (if any), and they can\'t \'fly over\' each other (e.g. `RL` can\'t be transformed into ...
2
0
['Stack', 'Java']
0
swap-adjacent-in-lr-string
Does anyone understand what the question is asking?
does-anyone-understand-what-the-question-2j76
I don\'t understand the explanation provided by the example. Where did RXXLRXRXL come from? My understanding is that the transformation would start with X\n\n``
johnbaek92
NORMAL
2020-09-09T17:55:25.288796+00:00
2020-09-09T17:55:25.288826+00:00
154
false
I don\'t understand the explanation provided by the example. Where did `RXXLRXRXL` come from? My understanding is that the transformation would start with X\n\n```\nInput: start = "X", end = "L"\nOutput: false\nExplanation:\nWe can transform start to end following these steps:\nRXXLRXRXL ->\nXRXLRXRXL ->\nXRLXRXRXL ->\...
2
0
[]
2
swap-adjacent-in-lr-string
JavaScript Time O(n)
javascript-time-on-by-yuchen_peng-l7gp
\n/**\n * @param {string} start\n * @param {string} end\n * @return {boolean}\n */\nvar canTransform = function(start, end) {\n let R = 0\n let L = 0\n
yuchen_peng
NORMAL
2020-06-20T23:43:13.171700+00:00
2020-06-20T23:43:48.466281+00:00
142
false
```\n/**\n * @param {string} start\n * @param {string} end\n * @return {boolean}\n */\nvar canTransform = function(start, end) {\n let R = 0\n let L = 0\n if (start.length != end.length) {\n return false\n }\n var i = 0\n while (i < start.length) {\n let char_s = start[i]\n let ch...
2
1
[]
1
swap-adjacent-in-lr-string
[Python] Simple One Pass O(N) Solution
python-simple-one-pass-on-solution-by-to-yf6t
Iterate from left to right, to check if there are enough R.\nIterate from right to left, to check if there are enough L.\n\nclass Solution:\n def canTransfor
tommmyk253
NORMAL
2020-06-16T06:53:13.151415+00:00
2020-06-16T06:53:13.151447+00:00
121
false
Iterate from left to right, to check if there are enough ```R```.\nIterate from right to left, to check if there are enough ```L```.\n```\nclass Solution:\n def canTransform(self, start: str, end: str) -> bool:\n L = R = 0\n for i in range(len(start)):\n a, b = start[i], end[i]\n ...
2
0
[]
0
swap-adjacent-in-lr-string
Short and clean JAVA code
short-and-clean-java-code-by-chenzuojing-2j7n
\n\tpublic boolean canTransform(String start, String end) {\n\t\tif (!start.replace("X", "").equals(end.replace("X", ""))) return false;\n\n\t\tint i = 0, j = 0
chenzuojing
NORMAL
2020-04-20T13:21:36.443034+00:00
2020-04-20T13:21:36.443070+00:00
196
false
```\n\tpublic boolean canTransform(String start, String end) {\n\t\tif (!start.replace("X", "").equals(end.replace("X", ""))) return false;\n\n\t\tint i = 0, j = 0;\n\t\tint len = start.length();\n\n\t\twhile (i < len && j < len) {\n\t\t\twhile (i < len && start.charAt(i) == \'X\') i++;\n\t\t\twhile (j < len && end.cha...
2
0
[]
0
swap-adjacent-in-lr-string
Java AC Solution, with explanation
java-ac-solution-with-explanation-by-gup-enxr
\n```\n public boolean canTransform(String start, String end) {\n /\n Core concept - Left should stay in the left and R should stay in the righ
gupibagha
NORMAL
2020-03-08T06:15:21.301468+00:00
2020-03-08T06:15:21.301515+00:00
222
false
\n```\n public boolean canTransform(String start, String end) {\n /**\n Core concept - Left should stay in the left and R should stay in the right\n we traverse both the string ignoring the \'X\'\n If both indices reach the end, we are good, return true.\n If either reaches end mea...
2
0
[]
1
swap-adjacent-in-lr-string
Java O(N), two point.
java-on-two-point-by-sakura-hly-9563
If start can be tansform to end, then\n1. index of i-L in start >= index of i-L in end,\n2. index of i-R in start <= index of i-R in end.\n\nclass Solution {\n
sakura-hly
NORMAL
2019-06-27T10:09:32.273695+00:00
2019-06-27T10:09:32.273737+00:00
238
false
If start can be tansform to end, then\n1. index of i-L in start >= index of i-L in end,\n2. index of i-R in start <= index of i-R in end.\n```\nclass Solution {\n public boolean canTransform(String start, String end) {\n if (start.equals(end)) return true;\n\n int i = 0, j = 0;\n while (i < star...
2
0
[]
0
swap-adjacent-in-lr-string
Readable Javascript Solution
readable-javascript-solution-by-codingba-p44d
Javscript solution of https://leetcode.com/problems/swap-adjacent-in-lr-string/discuss/113789/Simple-Java-one-pass-O(n)-solution-with-explaination\n\nIdea is to
codingbarista
NORMAL
2018-11-12T01:30:38.610301+00:00
2018-11-12T01:30:38.610347+00:00
321
false
Javscript solution of https://leetcode.com/problems/swap-adjacent-in-lr-string/discuss/113789/Simple-Java-one-pass-O(n)-solution-with-explaination\n\nIdea is to get non-X chars and compare their positions\n\n```\nfunction canTransform(start, end) {\n start = start.replace(/X/g, \'\');\n end = end.replace(/X/g, \'\');...
2
2
[]
2
swap-adjacent-in-lr-string
[c++, 10 lines, O(n)] detailed explaination, easy to understand!
c-10-lines-on-detailed-explaination-easy-pym0
The basic idea is to count the number of R in start string, and the number of L in end string. \nThe reason is that when we meet a \'R\' in the end string, we h
strangecloud9
NORMAL
2018-11-09T19:20:19.342509+00:00
2018-11-09T19:20:19.342554+00:00
372
false
The basic idea is to count the number of R in start string, and the number of L in end string. \nThe reason is that when we meet a \'R\' in the end string, we hope there is a \'R\' in the start string before. This is why we need to count the number of R in the start string.\nAnd when we meet a \'L\' in the start string...
2
0
[]
1
swap-adjacent-in-lr-string
Python3 O(n) one pass 112 ms
python3-on-one-pass-112-ms-by-luckypants-s2py
``` class Solution: def canTransform(self, start, end): """ :type start: str :type end: str :rtype: bool """
luckypants
NORMAL
2018-03-04T12:56:49.439173+00:00
2018-03-04T12:56:49.439173+00:00
216
false
``` class Solution: def canTransform(self, start, end): """ :type start: str :type end: str :rtype: bool """ swap = {'R':'X', 'X':'L'} # print("CanTransform: ", start, end) if len(start)!=len(end): return False if ...
2
0
[]
0
swap-adjacent-in-lr-string
O(n) time O(1) space C++
on-time-o1-space-c-by-imrusty-kx8m
Let j be the index that is the first that r[j] != r[i]. Moving i from 0 to n, if r[i] == s[i] then do nothing. When r[i] != s[i], it is only feasible to change
imrusty
NORMAL
2018-02-08T04:35:13.208000+00:00
2018-02-08T04:35:13.208000+00:00
585
false
Let j be the index that is the first that r[j] != r[i]. Moving i from 0 to n, if r[i] == s[i] then do nothing. When r[i] != s[i], it is only feasible to change r to match s if r[i] == 'R' or s[i] == 'L', and one of them is 'X'. In that case the right move is to move r[j] all the way back to i-th position in case r[i] =...
2
0
[]
1
swap-adjacent-in-lr-string
python O(n) solution
python-on-solution-by-erjoalgo-jeiw
both strings must have equal character counts\n for any substring end[:i], the number of R characters must be <= those in start, since Rs only move to the right
erjoalgo
NORMAL
2018-02-04T09:13:07.268000+00:00
2018-02-04T09:13:07.268000+00:00
260
false
* both strings must have equal character counts\n* for any substring `end[:i]`, the number of `R` characters must be `<=` those in `start`, since `Rs` only move to the right\n* for any substring `end[:i]`, the number of `L` characters must be `>=` those in `start`, since `Ls` only move to the left\n* an `L` and an `R` ...
2
0
[]
0
swap-adjacent-in-lr-string
JAVA O(n) Two Pointer Solution
java-on-two-pointer-solution-by-cxu-6rhv
Use two pointer to check the following 2 conditions:\n1. Without 'X', 'L' and 'R' has the same relative position in start and end\n2. For any corresponding 'R'
cxu
NORMAL
2018-02-04T06:12:46.516000+00:00
2018-02-04T06:12:46.516000+00:00
364
false
Use two pointer to check the following 2 conditions:\n1. Without 'X', 'L' and 'R' has the same relative position in start and end\n2. For any corresponding 'R' in start and end, say start[i] and end[j], i <= j, and for any corresponding 'L', i >= j.\n```\npublic boolean canTransform(String start, String end) {\n if ...
2
0
[]
0
swap-adjacent-in-lr-string
Python Regex and Recursion/Iterative versions
python-regex-and-recursioniterative-vers-gyl2
The recursive solution is easy to understand, but the recursive version fails in OJ for huge strings with maximum recursion depth exceeded, hence I converted it
Cubicon
NORMAL
2018-02-04T04:36:41.844000+00:00
2018-02-04T04:36:41.844000+00:00
684
false
The recursive solution is easy to understand, but the recursive version fails in OJ for huge strings with maximum recursion depth exceeded, hence I converted it to iterative version, which gets accepted easily.\n\nLogic:\n\nIf the current character matches, we just increment i.\nIf the current character does not match:...
2
0
[]
1
swap-adjacent-in-lr-string
BEST OPTIMAL SOLUTION✅✅ || 100% BEATS✅
best-optimal-solution-100-beats-by-gaura-0ms2
IntuitionApproachComplexity Time complexity: O(N) Space complexity: O(1) Code
Gaurav_SK
NORMAL
2025-04-11T11:40:24.258576+00:00
2025-04-11T11:40:24.258576+00:00
27
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
['Two Pointers', 'String', 'String Matching', 'C++']
0
swap-adjacent-in-lr-string
100% ACCEPTANCE | USING QUEUES 🏆🚀😻😻😻
100-acceptance-using-queues-by-shyyshawa-1h1j
IntuitionIN THIS PROBLEM WE WILL DONT REALLY HAVE TO SHIFT THE VALUES WE JUST NEED TO MAKE A CHECK ON THEM. WE WILL BE MAINTAINING 2 QUEUES EACH FOR THE TWO WOR
Shyyshawarma
NORMAL
2025-01-24T03:51:45.070262+00:00
2025-01-24T03:51:45.070262+00:00
43
false
# Intuition IN THIS PROBLEM WE WILL DONT REALLY HAVE TO SHIFT THE VALUES WE JUST NEED TO MAKE A CHECK ON THEM. WE WILL BE MAINTAINING 2 QUEUES EACH FOR THE TWO WORDS AND THEN SKIP THE CHARACTER IF IT IS AN 'X' AND KEEP ONLY THE L OR R COUNTER PIECE, AND THEN WE WILL CHECK IF THE NUMBER OF COUNTERPIECES ARE EQUAL OR NOT...
1
0
['C++']
0
swap-adjacent-in-lr-string
Simple N Complexity two Pointer solution
simple-n-complexity-two-pointer-solution-qcu3
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
samiul_bu
NORMAL
2024-10-04T19:51:11.876759+00:00
2024-10-04T19:51:11.876789+00:00
315
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
swap-adjacent-in-lr-string
Beats 100%
beats-100-by-groundzerocro-hs1g
Code\n\nclass Solution {\n fun canTransform(start: String, end: String): Boolean {\n\n val size = start.length\n\n var i = 0\n var j = 0
groundzerocro
NORMAL
2023-12-18T13:11:06.610685+00:00
2023-12-18T13:11:06.610722+00:00
7
false
# Code\n```\nclass Solution {\n fun canTransform(start: String, end: String): Boolean {\n\n val size = start.length\n\n var i = 0\n var j = 0\n\n while (i < size || j < size) {\n while (i < size && start[i] == \'X\') {\n i++\n }\n while (j ...
1
0
['Kotlin']
0
swap-adjacent-in-lr-string
4 Solutions: TLE -> O(n) Space Optimised - Python/Java
4-solutions-tle-on-space-optimised-pytho-1h1a
Intuition\n\nIn spite of the downvotes I actually thought this was a pretty good question, even though only the O(n) passes. \n\nI\'ve heavily commented the cod
katsuki-bakugo
NORMAL
2023-10-04T16:04:10.996543+00:00
2023-12-16T20:13:37.398922+00:00
384
false
> # Intuition\n\nIn spite of the downvotes I actually thought this was a pretty good question, even though only the O(n) passes. \n\nI\'ve heavily commented the code with explanations, and provided the brute force alternatives that don\'t pass for people like me who find those helpful:\n\n---\n\n\n> # DFS (TLE)\n\n```p...
1
0
['Two Pointers', 'Depth-First Search', 'Breadth-First Search', 'Python', 'Java', 'Python3']
0
swap-adjacent-in-lr-string
Python3 simple solution: Beats 100% in speed
python3-simple-solution-beats-100-in-spe-alqs
Intuition\n Describe your first thoughts on how to solve this problem. \nWe keep track of possible Ls and Rs to keep track of, so that they can be accounted for
GodwynLai
NORMAL
2023-09-15T13:27:50.125541+00:00
2023-09-15T13:27:50.125569+00:00
69
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe keep track of possible Ls and Rs to keep track of, so that they can be accounted for by future characters. This is kept track of in the lCount and rCount variables.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->...
1
0
['Python3']
0
swap-adjacent-in-lr-string
Clean and concise C++ code based on Two pointers. One pass, O(N) time, O(1) space.
clean-and-concise-c-code-based-on-two-po-4n3n
Intuition\n Describe your first thoughts on how to solve this problem. \n(1)The relative order of \'X\' and \'R\' in both strings must be the same.\n\n(2-1)For
jianweike
NORMAL
2023-05-17T18:04:20.453803+00:00
2023-05-17T18:04:20.453835+00:00
29
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n(1)The relative order of \'X\' and \'R\' in both strings must be the same.\n\n(2-1)For any \'L\', its position in "start" must to the right of that in "end", b/c \'L\' can only move to left. \n\n(2-2)For any \'R\', then its position in "...
1
0
['C++']
0
swap-adjacent-in-lr-string
C++ (4 ms) with explanation
c-4-ms-with-explanation-by-nandini2208-3c1t
\nbool canTransform(string start, string end) {\n int n=start.size();\n string s1="",s2="";\n\t\t//we take LR from 1st string and LR from 2nd stri
Nandini2208
NORMAL
2023-03-09T06:48:15.304926+00:00
2023-03-09T06:48:15.304960+00:00
310
false
```\nbool canTransform(string start, string end) {\n int n=start.size();\n string s1="",s2="";\n\t\t//we take LR from 1st string and LR from 2nd string if it is not equal it means\n\t\t//count of R & l in both the strings is not equal ex- start="X" end="L"\n\t\t//excluding the below checking we get wrong ...
1
0
['Two Pointers', 'String', 'C++']
0
swap-adjacent-in-lr-string
Easy to understand JavaScript solution
easy-to-understand-javascript-solution-b-tsy8
\tvar canTransform = function(start, end) {\n\t\tlet L = R = 0;\n\n\t\tfor (let index = 0; index < start.length; index++) {\n\t\t\tstart[index] === \'R\' && R++
tzuyi0817
NORMAL
2022-09-11T06:59:02.660945+00:00
2022-09-11T07:01:33.873738+00:00
135
false
\tvar canTransform = function(start, end) {\n\t\tlet L = R = 0;\n\n\t\tfor (let index = 0; index < start.length; index++) {\n\t\t\tstart[index] === \'R\' && R++;\n\t\t\tend[index] === \'L\' && L++;\n\t\t\tif (R > 0 && L > 0) return false;\n\n\t\t\tstart[index] === \'L\' && L--;\n\t\t\tend[index] === \'R\' && R--;\n\t\t...
1
0
['JavaScript']
1
swap-adjacent-in-lr-string
C++||Two Pointers||Easy to Understand
ctwo-pointerseasy-to-understand-by-retur-pouu
```\nclass Solution {\npublic:\n bool canTransform(string start, string end)\n {\n int n=start.size();\n string s1,s2;\n for(int i=0;
return_7
NORMAL
2022-09-04T21:18:25.634776+00:00
2022-09-04T21:18:25.634814+00:00
253
false
```\nclass Solution {\npublic:\n bool canTransform(string start, string end)\n {\n int n=start.size();\n string s1,s2;\n for(int i=0;i<n;i++)\n {\n if(start[i]!=\'X\')\n s1+=start[i];\n }\n for(int i=0;i<n;i++)\n {\n if(end[i]!...
1
0
['Two Pointers', 'C']
0
swap-adjacent-in-lr-string
Easy to Understand Java Solution
easy-to-understand-java-solution-by-star-6g0u
\n\n\nclass Solution {\n public boolean canTransform(String start, String end) {\n String startModified = start.replace("X", "");\n String endModified
starman214
NORMAL
2022-08-17T08:12:39.579586+00:00
2022-08-17T08:12:39.579614+00:00
187
false
\n\n```\nclass Solution {\n public boolean canTransform(String start, String end) {\n String startModified = start.replace("X", "");\n String endModified = end.replace("X", "");\n if (!startModified.equals(endModified)) return false;\n int stR = 0, enR = 0, stL = 0, enL = 0;\n for (int i = 0; i < star...
1
1
['Java']
1
swap-adjacent-in-lr-string
Explain failing test case
explain-failing-test-case-by-maximp4-5esx
Could someone please explain why this test case returns false?\n"LXXL"\n"XLLX"\n\nWe can only transform XL to LX, right?\nSo transform the 2nd XL of start\nand
maximp4
NORMAL
2022-08-04T03:24:44.872434+00:00
2022-08-04T04:04:07.340506+00:00
57
false
Could someone please explain why this test case returns false?\n"LXXL"\n"XLLX"\n\nWe can only transform XL to LX, right?\nSo transform the 2nd XL of start\nand 1st XL of end.\n\n"LX -XL-" -> LX LX\n"-XL- LX" -> LX LX\n\nI must be trippin here\n\nEDIT: Nvm, I think I understand. We can only modifiy one string.
1
0
[]
0
minimum-operations-to-make-all-array-elements-equal
[C++, Java, Python3] Prefix Sums + Binary Search
c-java-python3-prefix-sums-binary-search-u3kj
Intuition\n If there are j numbers in nums that are smaller than query[i], you need to find query[i] * j - sum(j numbers smaller than query[i]) to find incremen
tojuna
NORMAL
2023-03-26T04:04:53.374792+00:00
2023-03-26T19:36:52.754367+00:00
13,376
false
# Intuition\n* If there are `j` numbers in `nums` that are smaller than `query[i]`, you need to find `query[i] * j - sum(j numbers smaller than query[i])` to find increments required in `nums`\n* If there are `k` numbers in `nums` that are greater than `query[i]`, you need to find `sum(k numbers larger than query[i]) -...
113
1
['C++', 'Java', 'Python3']
16
minimum-operations-to-make-all-array-elements-equal
Image Explanation🏆- [Sorting + Prefix Sums + Binary Search] - Easy & Concise
image-explanation-sorting-prefix-sums-bi-ofy1
Video Solution (Aryan Mittal)\n\nMinimum Operations to Make All Array Elements Equal by Aryan Mittal\n\n\n\n# Approach & Intution\n\n\n\n\n\n\n\n# Code\n\n#defi
aryan_0077
NORMAL
2023-03-26T04:58:14.135830+00:00
2023-03-26T06:11:14.820435+00:00
5,278
false
# Video Solution (`Aryan Mittal`)\n\n`Minimum Operations to Make All Array Elements Equal` by `Aryan Mittal`\n![Leetcode Contest5.png](https://assets.leetcode.com/users/images/bea8dd52-30ea-4442-a9f9-a7a366152238_1679811067.7837667.png)\n\n\n# Approach & Intution\n![image.png](https://assets.leetcode.com/users/images/2...
40
1
['Binary Search', 'Sorting', 'Prefix Sum', 'C++']
3
minimum-operations-to-make-all-array-elements-equal
Prefix Sum
prefix-sum-by-votrubac-97lh
To make all elements equal, we need to increase elements smaller than query q, and decrease larger ones.\n \nWe sort our array first, so we can find index i
votrubac
NORMAL
2023-03-26T04:14:08.326007+00:00
2023-03-26T05:08:51.089068+00:00
5,628
false
To make all elements equal, we need to increase elements smaller than query `q`, and decrease larger ones.\n \nWe sort our array first, so we can find index `i` of first element larger than `q`.\n \nThen, we use the prefix sum array to get:\n- sum of smaller elements `ps[i]`.\n- sum of larger elements `ps[-1] - p...
27
1
['C', 'Python3']
4
minimum-operations-to-make-all-array-elements-equal
Optimal Approach || Prefix Sum || Binary Search || Fully Explained Approach || O(N * log N) || C++
optimal-approach-prefix-sum-binary-searc-qqjz
Approach\n- We want to make all the numbers equal to x.\n- There can be two types of numbers in the array ->\n 1. that are <= x (Type 1)\n 2. that are > x (Ty
ChaturvediParth
NORMAL
2023-03-26T05:29:24.483434+00:00
2023-03-26T07:52:31.837728+00:00
1,090
false
# Approach\n- We want to make all the numbers equal to $$x$$.\n- There can be two types of numbers in the array ->\n 1. that are $$<= x$$ (Type 1)\n 2. that are $$> x$$ (Type 2)\n- For numbers of **type 1** $$(<=x)$$, we would increase their value to make them equal to $$x$$.\n Suppose there are $$a$$ numbers that ar...
16
0
['Binary Search', 'Prefix Sum', 'C++']
5
minimum-operations-to-make-all-array-elements-equal
[Java/Python 3] Sort, compute prefix sum then binary search.
javapython-3-sort-compute-prefix-sum-the-eogi
Within each query, for each number in nums, if it is less than q, we need to deduct it from q and get the number of the increment operations; if it is NO less
rock
NORMAL
2023-03-26T04:10:11.512001+00:00
2023-03-28T14:11:53.946603+00:00
2,514
false
Within each query, for each number in `nums`, if it is less than `q`, we need to deduct it from `q` and get the number of the increment operations; if it is NO less than `q`, we need to deduct `q` from the number to get the number of the decrement operations.\n\nTherfore, we can sort `nums`, then use prefix sum to co...
15
0
['Java', 'Python3']
3
minimum-operations-to-make-all-array-elements-equal
Prefix Sum | Easy to Understand | Explained using Example
prefix-sum-easy-to-understand-explained-jzjxy
Intuition\nThe brute force approach would be to iterate through the queries array and for each query, iterate through the nums array to calculate the number of
nidhiii_
NORMAL
2023-03-26T07:18:24.257521+00:00
2023-03-26T07:27:40.081228+00:00
903
false
# Intuition\nThe brute force approach would be to iterate through the queries array and for each query, iterate through the nums array to calculate the number of operations for each element. However, this solution\'s time complexity is O(n*m), which doesn\'t satisfy the given constraint.\n\nAnother way is to calculate ...
13
0
['Prefix Sum', 'C++']
1
minimum-operations-to-make-all-array-elements-equal
EASIEST SOLUTION EVER JUST BINARY SEARCH
easiest-solution-ever-just-binary-search-cmns
Intuition\nTRIPPY\'S CODING TECHNIQUE \nHERE I AM PRESENTING JAVA CODE USE VECTOR IN PLACE OF ARRAY FOR C++\n\n# Approach\nSS APROACH\nJUST SMILE AND SOLVE\n\n#
gurnainwadhwa
NORMAL
2023-03-26T04:43:57.147659+00:00
2023-03-26T04:48:03.658055+00:00
4,213
false
# Intuition\nTRIPPY\'S CODING TECHNIQUE \nHERE I AM PRESENTING JAVA CODE USE VECTOR IN PLACE OF ARRAY FOR C++\n\n# Approach\nSS APROACH\nJUST SMILE AND SOLVE\n\n# Complexity\nNOTHING COMPLEX\n\n# PLEASE UPVOTE\nPLEASE UPVOTE IF I HELPED YOU \nTHANK YOU\nLOVE FOR YOU BY TRIPPY \n\n# Code\n```\nclass Solution {\n publ...
13
1
['Array', 'Binary Search', 'Prefix Sum', 'C++', 'Java']
2
minimum-operations-to-make-all-array-elements-equal
EASIEST SOLUTION EVER JUST BINARY SEARCH
easiest-solution-ever-just-binary-search-e8o8
Intuition\nSIMPLY BINARY SEARCH \n\n# Approach\nSS APROACH\nJUST SMILE AND SOLVE\n\n# Complexity\nNOTHING COMPLEX\n\n# PLEASE UPVOTE\nPLEASE UPVOTE IF I HELPED
gurnainwadhwa
NORMAL
2023-03-26T06:50:38.012393+00:00
2023-03-26T06:50:38.012426+00:00
958
false
# Intuition\nSIMPLY BINARY SEARCH \n\n# Approach\nSS APROACH\nJUST SMILE AND SOLVE\n\n# Complexity\nNOTHING COMPLEX\n\n# PLEASE UPVOTE\nPLEASE UPVOTE IF I HELPED YOU \nTHANK YOU\nLOVE FOR YOU \n\n# Code\n```\nclass Solution {\n public List<Long> minOperations(int[] nums, int[] queries) {\n \n int n = n...
9
0
['Java']
1
minimum-operations-to-make-all-array-elements-equal
C++✅| Binary Search | 4 liner |Easy to Understand🫡a
c-binary-search-4-liner-easy-to-understa-0ari
Intuition\n Describe your first thoughts on how to solve this problem. \nUse binary search to find the position of the element (which we want make all elements
Comrade-in-code
NORMAL
2023-03-26T05:44:18.472342+00:00
2023-03-26T05:44:18.472383+00:00
2,558
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse binary search to find the position of the element (which we want make all elements to this element) in the sorted array. Then, store then answer using the formula in approach section\n\n# Approach\n<!-- Describe your approach to solvi...
9
0
['Array', 'Binary Search', 'Prefix Sum', 'C++']
1
minimum-operations-to-make-all-array-elements-equal
Explained - Prefix sum & Lowerbound || Very simple & Easy to Understand Solution
explained-prefix-sum-lowerbound-very-sim-bzfu
Approach\n\n1. Evaluate prefix sum array\n2. find the index of lower bound of the query q\n3. Once we found the index, the lower half evaluation would take \n
kreakEmp
NORMAL
2023-03-26T06:58:48.907942+00:00
2023-03-26T07:05:16.535363+00:00
1,826
false
# Approach\n\n1. Evaluate prefix sum array\n2. find the index of lower bound of the query q\n3. Once we found the index, the lower half evaluation would take \n (ind * q - v[ind-1]) operations.\n4. Upper half array can be evaluated as equal which take \n (v.back() - v[ind-1]) - ( nums.size() - ind )*q;\n....
7
0
['C++']
1
minimum-operations-to-make-all-array-elements-equal
✔💯DAY 361 || 100% || 0MS || EXPLAINED || DRY RUN || MEME
day-361-100-0ms-explained-dry-run-meme-b-ohgf
Please Upvote as it really motivates me\n# Intuition\n Describe your first thoughts on how to solve this problem. \n##### \u2022\tThe intuition behind this code
ManojKumarPatnaik
NORMAL
2023-03-27T13:20:46.887452+00:00
2023-04-02T12:04:48.482471+00:00
655
false
# Please Upvote as it really motivates me\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n##### \u2022\tThe intuition behind this code is to first sort the input array of numbers and the array of queries. Then, for each query, we calculate the prefix sum of all numbers in the input ar...
6
0
['Python', 'C++', 'Java', 'Python3']
2
minimum-operations-to-make-all-array-elements-equal
Easy c++ solution using binary search and prefix sum.
easy-c-solution-using-binary-search-and-u19f5
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can solve each query in log n time using binary search (upper_bound) and prefix sum
aniketrajput25
NORMAL
2023-03-26T05:48:42.714001+00:00
2023-03-26T05:48:42.714042+00:00
1,180
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can solve each query in log n time using binary search (upper_bound) and prefix sum in sorted array.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Sort the array.\n2. Calculate prefix sum array of size n+1, a...
5
0
['C++']
0
minimum-operations-to-make-all-array-elements-equal
C++ Easy Solution || Beats 100% || Binary Search Approach || 🔥🔥
c-easy-solution-beats-100-binary-search-f5vdz
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
abhi_pandit_18
NORMAL
2023-07-16T19:49:15.369594+00:00
2023-07-16T19:49:15.369613+00:00
54
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)$$ --...
4
0
['Binary Search', 'C++']
0
minimum-operations-to-make-all-array-elements-equal
C++ || BINARY SEARCH || EASY TO UDERSTAND
c-binary-search-easy-to-uderstand-by-gan-xd91
Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(n)\n\n# Code\n\n#define ll long long \nclass Solution {\npublic:\n vector<long long> minOp
ganeshkumawat8740
NORMAL
2023-05-09T04:41:48.031522+00:00
2023-05-09T04:42:50.863240+00:00
1,195
false
# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(n)\n\n# Code\n```\n#define ll long long \nclass Solution {\npublic:\n vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n vector<ll> v;//ans array\n vector<ll> ps;//previous sum array\n sort(nums.begin(...
4
0
['Array', 'Binary Search', 'Sorting', 'Prefix Sum', 'C++']
0
minimum-operations-to-make-all-array-elements-equal
Sort + Prefix Sum + Binary Search
sort-prefix-sum-binary-search-by-fllght-n8ww
Java\n\npublic List<Long> minOperations(int[] nums, int[] queries) {\n List<Long> result = new ArrayList<>();\n Arrays.sort(nums);\n\n long[] prefixSum
FLlGHT
NORMAL
2023-04-07T07:25:20.753800+00:00
2023-04-07T07:25:20.753841+00:00
170
false
# Java\n```\npublic List<Long> minOperations(int[] nums, int[] queries) {\n List<Long> result = new ArrayList<>();\n Arrays.sort(nums);\n\n long[] prefixSum = new long[nums.length];\n for (int i = 0; i < nums.length; ++i) {\n prefixSum[i] = (i > 0 ? prefixSum[i - 1] : 0) + nums[i];\n }\n\n for (i...
4
0
['C++', 'Java']
0
minimum-operations-to-make-all-array-elements-equal
JAVA SOLUTION 100% FASTER || BinarySearch
java-solution-100-faster-binarysearch-by-uucj
Search for all the numbers smaller than the query element the sum total should be number of element*query if sum of all smaller elements is less then we need t
akash0228
NORMAL
2023-03-26T04:56:21.617246+00:00
2023-03-26T05:01:32.300503+00:00
906
false
**Search for all the numbers smaller than the query element the sum total should be number of element*query if sum of all smaller elements is less then we need to add the difference number of time And in the case of larger element we need to subtract the Sum total from sum of larger elements!!!**\n```\nclass Solution...
4
0
['Binary Search', 'Sorting', 'Prefix Sum', 'Java']
0
minimum-operations-to-make-all-array-elements-equal
Beats 98% || Simple C++ Explanation || Binary Search || Prefix Sum
beats-98-simple-c-explanation-binary-sea-5e6m
Intuition\nThe code aims to efficiently find the minimum cost of operations on a sorted array for given queries. The intuition involves traversing the queries v
king0203
NORMAL
2023-12-17T18:00:24.465604+00:00
2023-12-17T18:00:24.465631+00:00
24
false
# Intuition\nThe code aims to efficiently find the minimum cost of operations on a sorted array for given queries. The intuition involves traversing the queries vector once and recognizing the need for a logarithmic time solution. Hence, the idea of using binary search is considered. \n\n# Approach\n In the approach, t...
3
0
['Binary Search', 'Prefix Sum', 'C++']
0
minimum-operations-to-make-all-array-elements-equal
C++
c-by-deepak_2311-8jco
Complexity\n- Time complexity:O(n log n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add your space complexity here, e.g. O(n) \n\n
godmode_2311
NORMAL
2023-04-17T20:19:04.691665+00:00
2023-04-17T20:19:04.691702+00:00
134
false
# Complexity\n- Time complexity:`O(n log n)`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:`O(n)`\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n \n ...
3
0
['Array', 'Binary Search', 'Sorting', 'Prefix Sum', 'C++']
0
minimum-operations-to-make-all-array-elements-equal
SORTING + UPPERBOUND + PREFIX SUM
sorting-upperbound-prefix-sum-by-_kitish-whyi
Intuition\n Describe your first thoughts on how to solve this problem. \nSuppose we have a query \'a\' then we have to know the number of elements which is grea
_kitish
NORMAL
2023-04-05T20:45:37.946186+00:00
2023-06-01T18:04:04.509984+00:00
111
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSuppose we have a query \'a\' then we have to know the number of elements which is greater than \'a\' and less than or equal to \'a\' in nums array and their sum Let\'s if \'b\' number is greater and \'c\' number is less than or equal to ...
3
0
['Array', 'Binary Search', 'Sorting', 'Prefix Sum', 'C++']
1
minimum-operations-to-make-all-array-elements-equal
C++||Most Easy Solution Using Prefix & Suffix Sum and Binary Search
cmost-easy-solution-using-prefix-suffix-odiiv
\ntypedef long long ll;\nclass Solution {\npublic:\n vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n ll m=nums.size();\n
Arko-816
NORMAL
2023-03-26T16:55:22.120352+00:00
2023-03-26T17:06:55.641315+00:00
1,922
false
```\ntypedef long long ll;\nclass Solution {\npublic:\n vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n ll m=nums.size();\n sort(nums.begin(),nums.end());\n vector<ll> suff(m,0);\n vector<ll>pref(m,0);\n vector<ll> ans;\n suff[m-1]=nums[m-1];\n ...
3
0
['Binary Search', 'Prefix Sum']
1
minimum-operations-to-make-all-array-elements-equal
PREFIX & SUFFIX SUM || BINARY SEARCH || C++
prefix-suffix-sum-binary-search-c-by-yas-9hsw
\nclass Solution {\npublic:\n vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n vector<long long int> v;\n sort(nums
yash___sharma_
NORMAL
2023-03-26T06:14:46.029701+00:00
2023-03-26T12:22:19.762383+00:00
790
false
````\nclass Solution {\npublic:\n vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n vector<long long int> v;\n sort(nums.begin(),nums.end());\n vector<long long int> l(nums.size()),r(nums.size());\n l[0] = nums[0];\n r[nums.size()-1] = nums[nums.size()-1]...
3
0
['Binary Search', 'C', 'Sorting', 'Binary Tree', 'Prefix Sum', 'C++']
0
minimum-operations-to-make-all-array-elements-equal
No Binary search, just use sweep line and prefix sum
no-binary-search-just-use-sweep-line-and-h20l
Intuition\nFor a given query x, answer will be sum of left answer and right answer.\nleft answer = x * number of smaller values than x - sum of smaller values t
dush1729
NORMAL
2023-03-26T06:08:56.168786+00:00
2023-03-26T06:10:28.954386+00:00
588
false
# Intuition\nFor a given query `x`, answer will be sum of `left answer` and `right answer`.\n`left answer` = `x` * `number of smaller values than x` - `sum of smaller values than x`\n`right answer` = `sum of bigger values than x` - `x` * `number of bigger values than x`\n\n\n# Approach\nSort both array and queries.\nYo...
3
0
['C++']
0
minimum-operations-to-make-all-array-elements-equal
C++ Sorting + Binary Search + Prefix Sum || Easy To Understand ⭐⭐⭐
c-sorting-binary-search-prefix-sum-easy-z3050
Intuition\n Describe your first thoughts on how to solve this problem. \nPartition the array in set of elements greeater than queries[i] and set of elements sma
Shailesh0302
NORMAL
2023-03-26T05:38:21.791125+00:00
2023-03-26T05:38:21.791161+00:00
143
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nPartition the array in set of elements greeater than queries[i] and set of elements smaller than queries[i]\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nAfter partitioning \nFor smaller set \nrequired value to...
3
0
['C++']
0
minimum-operations-to-make-all-array-elements-equal
Prefix & Suffix + Binary Search | C++
prefix-suffix-binary-search-c-by-tusharb-3c0v
\nclass Solution {\npublic:\n vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n long long n = nums.size();\n sort(nu
TusharBhart
NORMAL
2023-03-26T05:21:36.251542+00:00
2023-03-26T05:27:37.370676+00:00
1,932
false
```\nclass Solution {\npublic:\n vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n long long n = nums.size();\n sort(nums.begin(), nums.end());\n vector<long long> ps(n + 1), ss(n + 1), ans;\n for(int i=1; i<=n; i++) ps[i] = ps[i - 1] + nums[i - 1];\n f...
3
0
['Binary Search', 'Suffix Array', 'Sorting', 'Prefix Sum', 'C++']
0
minimum-operations-to-make-all-array-elements-equal
Detailed Explanation of Code and Approach
detailed-explanation-of-code-and-approac-ewk4
Intuition\n Describe your first thoughts on how to solve this problem. \nMy intuition is simpler just finding the number of element that are smaller than ith el
Unstoppable_1
NORMAL
2023-03-26T04:33:57.970795+00:00
2023-03-26T04:33:57.970839+00:00
421
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMy intuition is simpler just finding the number of element that are smaller than ith element of query and using prefix sum find its sum and similarly for the element that are greater than the ith element of query.Then, calculate the answe...
3
0
['Binary Search', 'Prefix Sum', 'C++']
0
minimum-operations-to-make-all-array-elements-equal
🐍Python Solution: Sort+PrefixSum+BinSearch
python-solution-sortprefixsumbinsearch-b-ipdy
\n\n# Code\n\nclass Solution:\n def minOperations(self, nums: List[int], queries: List[int]) -> List[int]:\n nums.sort()\n prefix_sum = [nums[0
otnyukovd
NORMAL
2023-04-07T07:34:54.855121+00:00
2023-04-07T07:35:08.304264+00:00
1,369
false
\n\n# Code\n```\nclass Solution:\n def minOperations(self, nums: List[int], queries: List[int]) -> List[int]:\n nums.sort()\n prefix_sum = [nums[0]]\n ans = []\n for i in range(1, len(nums)):\n prefix_sum.append(prefix_sum[-1] + nums[i])\n \n for target in queries...
2
0
['Python3']
0