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
watering-plants-ii
easy solution || Faster than others || O(N) time || O(1) space
easy-solution-faster-than-others-on-time-zuju
```\nclass Solution {\npublic:\n int minimumRefill(vector& plants, int capacityA, int capacityB) {\n int start=0,end=plants.size()-1;\n int org
Shristha
NORMAL
2022-08-11T15:46:24.325295+00:00
2022-08-11T15:46:24.325330+00:00
37
false
```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int start=0,end=plants.size()-1;\n int org1=capacityA,org2=capacityB,res=0;\n while(start<end){\n if(capacityA>=plants[start]){\n capacityA-=plants[start];\n ...
1
1
['C', 'C++']
0
watering-plants-ii
cpp || two pointer
cpp-two-pointer-by-prithviraj26-ff0u
\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int i=0,j=plants.size()-1,count=0,tempA=capacit
prithviraj26
NORMAL
2022-05-25T04:16:25.542413+00:00
2022-05-25T04:16:25.542444+00:00
41
false
```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int i=0,j=plants.size()-1,count=0,tempA=capacityA,tempB=capacityB;\n while(i<=j)\n {\n if(i==j)\n {\n if(capacityA>=plants[i]||capacityB>=plants[j])\n ...
1
0
[]
0
watering-plants-ii
Java solution 3ms || Simple and faster than 99.91%
java-solution-3ms-simple-and-faster-than-i7p3
\nclass Solution {\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n \n int n = plants.length;\n int i = 0, j =
ishan_aggarwal
NORMAL
2022-01-29T17:07:20.877317+00:00
2022-01-29T17:07:20.877358+00:00
63
false
```\nclass Solution {\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n \n int n = plants.length;\n int i = 0, j = n - 1;\n int aRefill = 0, bRefill = 0;\n int initialCapacityA = capacityA;\n int initialCapacityB = capacityB;\n \n while...
1
0
['Array']
0
watering-plants-ii
C++ || Easy Solution || Two Pointers || O(N)
c-easy-solution-two-pointers-on-by-kamis-6si3
\n\n\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n \n int n(plants.size()), res(0), aliceC
kamisamaaaa
NORMAL
2022-01-05T06:31:23.675515+00:00
2022-01-05T06:31:23.675561+00:00
101
false
\n\n```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n \n int n(plants.size()), res(0), aliceC(capacityA), bobC(capacityB), alice(0), bob(n-1);\n \n while (alice < bob)\n {\n if (alice == bob)\n {\n ...
1
0
['Two Pointers', 'C']
0
watering-plants-ii
C++ EASY CODE
c-easy-code-by-sricharanbj-rwrj
class Solution {\npublic:\n \n int minimumRefill(vector& plants, int capacityA, int capacityB) {\n \n int n=plants.size();\n if(n==1)\n
SRICHARANBJ
NORMAL
2021-12-29T16:35:01.705323+00:00
2021-12-29T16:35:01.705370+00:00
93
false
class Solution {\npublic:\n \n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n \n int n=plants.size();\n if(n==1)\n {\n return 0;\n }\n \n int bob=n-1;\n int A=capacityA,B=capacityB;\n int count=0;\n for(int i=0;i<n...
1
0
['C']
0
watering-plants-ii
C++ solution || two pointers
c-solution-two-pointers-by-quater_nion-nejy
\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int n=plants.size();\n int a=0;\n int b=n-1;\n int an
quater_nion
NORMAL
2021-12-23T16:52:35.965620+00:00
2021-12-23T16:52:35.965654+00:00
43
false
```\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int n=plants.size();\n int a=0;\n int b=n-1;\n int ans = 0;\n int capA = capacityA;\n int capB = capacityB;\n \n while(a<b){\n if(capA<plants[a]){\n capA=ca...
1
0
[]
0
watering-plants-ii
C++ Easy Solution two pointer O(n)
c-easy-solution-two-pointer-on-by-sanska-6ud5
```\nclass Solution {\npublic:\n int minimumRefill(vector& plants, int capacityA, int capacityB) {\n int ans=0;\n int i=0;\n int j=plant
sanskar_maliwad
NORMAL
2021-12-18T18:57:35.183345+00:00
2021-12-18T18:59:08.385806+00:00
68
false
```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int ans=0;\n int i=0;\n int j=plants.size()-1;\n int alice = capacityA;\n int bob = capacityB;\n while(i <= j){\n if(i != j){\n if(alice < plan...
1
0
['C']
0
watering-plants-ii
Python Very Easy and Fastest Solution
python-very-easy-and-fastest-solution-by-s6g3
\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n \n Alice , Bob = capacityA, capacityB
aaffriya
NORMAL
2021-12-14T06:18:40.961809+00:00
2021-12-14T06:18:40.961861+00:00
130
false
```\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n \n Alice , Bob = capacityA, capacityB\n \n res, i, j = 0, 0, len(plants)-1\n \n while i < j:\n if Alice >= plants[i]:\n Alice -= plants[i]\n...
1
0
['Python']
0
watering-plants-ii
✅ Java - Clean 2 Pointer Simulation
java-clean-2-pointer-simulation-by-welco-slza
\nclass Solution {\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n\t\n int left = 0, right = plants.length - 1;\n in
welcomecurry
NORMAL
2021-12-12T20:51:58.477685+00:00
2021-12-12T20:51:58.477717+00:00
91
false
```\nclass Solution {\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n\t\n int left = 0, right = plants.length - 1;\n int alice = capacityA, bob = capacityB, refills = 0;\n \n while(left <= right)\n {\n if(left == right)\n {\n ...
1
0
['Two Pointers', 'Java']
0
watering-plants-ii
Python 3 two pointers O(n)
python-3-two-pointers-on-by-derek-y-dqnb
```\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n a, b = 0, len(plants) - 1\n waterA,
derek-y
NORMAL
2021-12-12T20:33:19.192126+00:00
2021-12-12T20:33:19.192166+00:00
148
false
```\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n a, b = 0, len(plants) - 1\n waterA, waterB = capacityA, capacityB\n res = 0\n while a < b:\n if waterA < plants[a]:\n res += 1\n waterA = ca...
1
0
['Two Pointers', 'Python', 'Python3']
0
watering-plants-ii
How about this test case
how-about-this-test-case-by-vetty-1ipz
\n[1, 1, 1, 1]\n1\n10000\n\n\nIdeally Bob can water all the plans in one go & number of refills should be 0. However as per accepted code it is 1. Wouldn\'t thi
vetty
NORMAL
2021-12-12T18:01:48.406914+00:00
2021-12-12T18:01:48.406953+00:00
61
false
```\n[1, 1, 1, 1]\n1\n10000\n```\n\nIdeally Bob can water all the plans in one go & number of refills should be 0. However as per accepted code it is 1. Wouldn\'t this be more greeedy?
1
0
[]
0
watering-plants-ii
[C++] using 2 pointers
c-using-2-pointers-by-nikhil_1104-agb7
class Solution {\npublic:\n int minimumRefill(vector& plants, int capacityA, int capacityB) {\n int i = 0, j = plants.size() - 1;\n int refil =
Nikhil_1104
NORMAL
2021-12-12T08:39:48.127097+00:00
2021-12-12T08:39:48.127127+00:00
43
false
class Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int i = 0, j = plants.size() - 1;\n int refil = 0;\n int tempA = capacityA;\n int tempB = capacityB;\n \n while(i <= j) {\n \n if(i == j) {\n ...
1
0
[]
1
watering-plants-ii
C++|100% faster|Full Code Walkthrough|2 pointer approach|O(n) time
c100-fasterfull-code-walkthrough2-pointe-9gxx
Please upvote if you like the solution and any improvements or suggestion are welcomed in the comments.\nIntuition- at each time alice waters 1 plant from left
guptasim8
NORMAL
2021-12-12T07:44:09.159132+00:00
2021-12-14T12:48:57.818896+00:00
59
false
**Please upvote if you like the solution and any improvements or suggestion are welcomed in the comments.**\nIntuition- at each time alice waters 1 plant from left and bob 1 plant from the right. If odd no. of plants alice will water the last plant.\n\n**Time Complexity- O(n)\nSpace Complexity- O(1)**\n\n```\nclass Sol...
1
0
['C', 'C++']
1
watering-plants-ii
SIMPLE BRUTE FORCE
simple-brute-force-by-82877harsh-9tsf
\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n //using a simple brute force\n int ans=0
82877harsh
NORMAL
2021-12-12T07:28:44.041541+00:00
2021-12-12T07:28:44.041582+00:00
47
false
````\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n //using a simple brute force\n int ans=0;\n int a=capacityA;\n int b=capacityB;\n int i=0;\n int j=plants.size()-1;\n while(i<=j)\n {\n if(i==j...
1
0
[]
0
watering-plants-ii
Simple Python Solution | Easy to understand | 2 Pointers
simple-python-solution-easy-to-understan-muvt
\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n capA = capacityA\n capB = capacityB\n
codingtux
NORMAL
2021-12-12T06:53:15.190633+00:00
2021-12-12T06:53:15.190661+00:00
66
false
```\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n capA = capacityA\n capB = capacityB\n \n start = 0\n end = len(plants)-1\n ref = 0\n while start < end:\n if plants[start] <= capA:\n ...
1
0
[]
1
watering-plants-ii
Java | Two Pointers | Simulation | O(n) time and O(1) space solution
java-two-pointers-simulation-on-time-and-7es6
java\nclass Solution {\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n int refill = 0; \n int i = 0, j = plants.leng
liamng
NORMAL
2021-12-12T06:52:52.473120+00:00
2021-12-12T06:52:52.473161+00:00
45
false
```java\nclass Solution {\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n int refill = 0; \n int i = 0, j = plants.length-1; \n int a = capacityA, b = capacityB;\n \n while(i <= j) {\n if (i == j) {\n if (plants[i] > Math.max(a, ...
1
0
['Java']
0
watering-plants-ii
C++ Fun with lambda functions
c-fun-with-lambda-functions-by-carstenh-13sa
\nclass Solution {\npublic:\n\tint minimumRefill(std::vector<int>& plants, int capacityA, int capacityB) {\n\t\tauto const n = static_cast<int>(std::size(plants
carstenh
NORMAL
2021-12-12T06:44:19.318055+00:00
2021-12-12T06:44:19.318087+00:00
108
false
```\nclass Solution {\npublic:\n\tint minimumRefill(std::vector<int>& plants, int capacityA, int capacityB) {\n\t\tauto const n = static_cast<int>(std::size(plants));\n\t\tauto const k = n / 2;\n\n\t\t// Lambda function returning another lambda function\n\t\tauto lambda = [](auto& remains, auto capacity) {\n\t\t\tretur...
1
0
['C']
0
watering-plants-ii
C++ || Simple Solution|| Easy to Understand ||
c-simple-solution-easy-to-understand-by-tjknh
\tclass Solution {\n\tpublic:\n int minimumRefill(vector& p, int ca, int cb) {\n int l=0,r=p.size()-1,a=ca,b=cb;\n int res=0;\n while(l<
kundankumar4348
NORMAL
2021-12-12T06:34:33.603944+00:00
2021-12-12T06:34:33.603987+00:00
61
false
\tclass Solution {\n\tpublic:\n int minimumRefill(vector<int>& p, int ca, int cb) {\n int l=0,r=p.size()-1,a=ca,b=cb;\n int res=0;\n while(l<=r){\n if(l==r){\n if(ca>=p[l] && a>=p[l] && a>=b)\n l++;\n else if(cb>=p[r] && b>=p[r] && b>=a...
1
0
[]
0
watering-plants-ii
Java Solution | Two Pointer | O(n) | 100% faster
java-solution-two-pointer-on-100-faster-t7im8
\npublic int minimumRefill(int[] plants, int capacityA, int capacityB) {\n \n int currentA = capacityA, currentB = capacityB;\n \n i
sourasb
NORMAL
2021-12-12T06:27:51.760038+00:00
2021-12-12T06:29:06.820470+00:00
35
false
```\npublic int minimumRefill(int[] plants, int capacityA, int capacityB) {\n \n int currentA = capacityA, currentB = capacityB;\n \n int i=0,j=plants.length-1;\n int count = 0;\n \n while(i<=j){\n if(i==j){\n if(currentA>=currentB){\n ...
1
0
['Two Pointers', 'Java']
0
watering-plants-ii
Python3, explained like I'm 5 :D
python3-explained-like-im-5-d-by-megzo-3wno
```\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n n = len(plants)\n # they travel til
megzo
NORMAL
2021-12-12T06:01:21.541745+00:00
2021-12-12T06:01:21.541785+00:00
32
false
```\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n n = len(plants)\n # they travel till midpoint\n steps = n//2\n \n # number of refills for alice and bob each\n refilla, refillb = 0, 0\n # amount of water in ea...
1
0
[]
1
watering-plants-ii
[JavaScript] 2105. Watering Plants II
javascript-2105-watering-plants-ii-by-pg-r6lu
---\n\n- Weekly Contest 271 - https://leetcode.com/contest/weekly-contest-271/ranking/83/\n - Q1 answer\n - https://leetcode.com/problems/rings-and-rods/dis
pgmreddy
NORMAL
2021-12-12T04:22:50.362758+00:00
2021-12-13T03:40:33.865780+00:00
199
false
---\n\n- Weekly Contest 271 - https://leetcode.com/contest/weekly-contest-271/ranking/83/\n - Q1 answer\n - https://leetcode.com/problems/rings-and-rods/discuss/1624271/JavaScript-2103.-Rings-and-Rods\n - Q2 answer\n - https://leetcode.com/problems/sum-of-subarray-ranges/discuss/1624314/JavaScript-2104.-Sum-of-...
1
0
['JavaScript']
0
watering-plants-ii
C++ | TWO POINTER | IMPLEMENTATION
c-two-pointer-implementation-by-chikzz-8dpf
PLEASE UPVOTE IF U LIKE MY SOLUTION\n\n\nclass Solution {\n \npublic:\n int minimumRefill(vector<int>& p, int cA, int cB) {\n int n=p.size();\n
chikzz
NORMAL
2021-12-12T04:19:24.432286+00:00
2021-12-12T04:19:24.432324+00:00
141
false
**PLEASE UPVOTE IF U LIKE MY SOLUTION**\n\n```\nclass Solution {\n \npublic:\n int minimumRefill(vector<int>& p, int cA, int cB) {\n int n=p.size();\n int steps=0;\n int i=0,j=n-1;\n int ta=cA,tb=cB;\n while(i<=j)\n {\n if(i==j)\n {\n i...
1
0
[]
1
watering-plants-ii
Python Solution Two Pointers[O(N) solution]
python-solution-two-pointerson-solution-sk2s2
\nTime: O(N), Space: O(1)\n\n\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n alice,bob = 0,le
pratushah
NORMAL
2021-12-12T04:06:49.131544+00:00
2021-12-12T04:33:23.533083+00:00
108
false
\n**Time: O(N)**, **Space: O(1)**\n\n```\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n alice,bob = 0,len(plants)-1\n result,capacity_A,capacity_B = 0,capacityA,capacityB\n while alice < bob:\n if capacity_A < plants[alice]:\n ...
1
0
['Two Pointers', 'Python', 'Python3']
1
watering-plants-ii
Python3, simulation
python3-simulation-by-silvia42-llnk
\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n a=0\n b=len(plants)-1\n waterA=
silvia42
NORMAL
2021-12-12T04:05:25.840532+00:00
2021-12-12T04:05:25.840567+00:00
73
false
```\nclass Solution:\n def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int:\n a=0\n b=len(plants)-1\n waterA=capacityA\n waterB=capacityB\n refills=0\n while a<b:\n if waterA<plants[a]:\n waterA=capacityA\n ...
1
0
[]
0
watering-plants-ii
C++ || O(N) - simple two pointers
c-on-simple-two-pointers-by-dewesh_soc-31pv
\nclass Solution {\npublic:\n int minimumRefill(vector<int>& a, int ca, int cb) {\n int n = a.size();\n int i = 0;\n int j = n-1;\n
dewesh_soc
NORMAL
2021-12-12T04:04:23.209168+00:00
2021-12-12T04:04:23.209190+00:00
53
false
```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& a, int ca, int cb) {\n int n = a.size();\n int i = 0;\n int j = n-1;\n int c = 0 ;\n int ica = ca;\n int icb = cb;\n while(i<=j){\n if(i==j){\n if(ca>cb){\n if...
1
0
['Two Pointers', 'C']
1
watering-plants-ii
Optimal,Simple,Concise
optimalsimpleconcise-by-abhiniveshmitra-dk2y
IntuitionThere's no strateegy to apply we only have to implement what is being asked.ApproachUse 2 pointers to simulatee what is being askedComplexity Time com
abhiniveshmitra
NORMAL
2025-04-07T15:50:22.134539+00:00
2025-04-07T15:50:22.134539+00:00
1
false
# Intuition There's no strateegy to apply we only have to implement what is being asked. # Approach Use 2 pointers to simulatee what is being asked # Complexity - Time complexity: $$O(n)$$ - Space complexity: $$O(1)$$ # Code ```cpp [] class Solution { public: int minimumRefill(vector<int>& plants, int a, int b...
0
0
['Array', 'Two Pointers', 'C++']
0
watering-plants-ii
Optimal,Simple,Concise
optimalsimpleconcise-by-abhiniveshmitra-ky2z
IntuitionThere's no strateegy to apply we only have to implement what is being asked.ApproachUse 2 pointers to simulatee what is being askedComplexity Time com
abhiniveshmitra
NORMAL
2025-04-07T15:50:19.473685+00:00
2025-04-07T15:50:19.473685+00:00
0
false
# Intuition There's no strateegy to apply we only have to implement what is being asked. # Approach Use 2 pointers to simulatee what is being asked # Complexity - Time complexity: $$O(n)$$ - Space complexity: $$O(1)$$ # Code ```cpp [] class Solution { public: int minimumRefill(vector<int>& plants, int a, int b...
0
0
['Array', 'Two Pointers', 'C++']
0
watering-plants-ii
Straightforward Two-Pointer Approach in C++ 🌿💧
straightforward-two-pointer-approach-in-4dcf0
IntuitionTo minimize refills, simulate two gardeners starting from opposite ends of the plant row. At each step, check whether the current amount of water is su
sparkburnfade
NORMAL
2025-04-07T02:15:46.178213+00:00
2025-04-07T02:15:46.178213+00:00
1
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> To minimize refills, simulate two gardeners starting from opposite ends of the plant row. At each step, check whether the current amount of water is sufficient to water the plant. If not, perform a refill. This approach allows precise track...
0
0
['Two Pointers', 'C++']
0
watering-plants-ii
best solution , beats 100%
best-solution-beats-100-by-harsh100-zq3g
IntuitionThe problem requires us to simulate the process of two people (Alice and Bob) watering plants from opposite ends. If either of them runs out of water b
Harsh100_
NORMAL
2025-04-01T19:52:01.491308+00:00
2025-04-01T19:52:01.491308+00:00
4
false
# Intuition The problem requires us to simulate the process of two people (Alice and Bob) watering plants from opposite ends. If either of them runs out of water before watering a plant, they need to refill. The goal is to count the minimum number of refills required. # Approach *Two Pointers Strategy: Use two pointe...
0
0
['C++']
0
watering-plants-ii
brute force 4ms beats 100%
brute-force-4ms-beats-100-by-priyank_jak-0dci
IntuitionApproachComplexity Time complexity: Space complexity: Code
priyank_jakharia
NORMAL
2025-03-24T10:42:17.571351+00:00
2025-03-24T10:42:17.571351+00:00
4
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 complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0
watering-plants-ii
2105. Watering Plants II
2105-watering-plants-ii-by-shubh4m13-bwsm
Complexity Time complexity: O(N) Space complexity: O(1) Code
Shubh4m13
NORMAL
2025-03-22T12:43:16.609922+00:00
2025-03-22T12:43:16.609922+00:00
4
false
# Complexity - Time complexity: O(N) - Space complexity: O(1) # Code ```cpp [] class Solution { public: int minimumRefill(vector<int>& plants, int capacityA, int capacityB) { int Alice = 0; int Bob = plants.size() - 1; int orignial_capA = capacityA; int refill = 0; int orig...
0
0
['C++']
0
watering-plants-ii
Watering Plants II
watering-plants-ii-by-sameer123-n0i5
IntuitionApproachComplexity Time complexity: Space complexity: Code
Sameer123__
NORMAL
2025-03-19T16:13:47.854583+00:00
2025-03-19T16:13:47.854583+00:00
2
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 complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C++']
0
watering-plants-ii
Java using Two Pointers
java-using-two-pointers-by-sachink_mahar-cpsd
IntuitionApproachComplexity Time complexity: O(n) Space complexity: O(1) Code
sachink_maharana
NORMAL
2025-03-12T14:06:35.704012+00:00
2025-03-12T14:06:35.704012+00:00
3
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)$$ -->...
0
0
['Two Pointers', 'Java']
0
watering-plants-ii
Beat 100% Simple Approach
beat-100-simple-approach-by-chandu276754-jq8v
IntuitionComplexity Time complexity: O(N) Space complexity: O(1) Code
chandu2767542
NORMAL
2025-03-06T18:30:38.895607+00:00
2025-03-06T18:30:38.895607+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> ![Screenshot 2025-03-06 at 11.58.30 PM.png](https://assets.leetcode.com/users/images/e99f54b6-aada-4134-a3bd-e509bda0b9fa_1741285810.8521993.png) # Complexity - Time complexity: O(N) <!-- Add your time complexity here, e.g. $$O(n)$$ --> ...
0
0
['Array', 'Simulation', 'C++']
0
watering-plants-ii
easy one!!
easy-one-by-lipikakrishna-ypfs
IntuitionApproachComplexity Time complexity: Space complexity: Code
LipikaKrishna
NORMAL
2025-03-06T16:53:46.773693+00:00
2025-03-06T16:53:46.773693+00:00
3
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 complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0
watering-plants-ii
lol solution 100% beats java morgenshtern
lol-solution-100-beats-java-morgenshtern-rxgj
Code
panic08
NORMAL
2025-02-18T19:23:14.938990+00:00
2025-02-18T19:23:14.938990+00:00
5
false
# Code ```java [] class Solution { public static int minimumRefill(int[] plants, int capacityA, int capacityB) { int curCapA = capacityA; int curCapB = capacityB; int l = 0; int r = plants.length - 1; int c = 0; while (l <= r) { if (l == r && Math.max(...
0
0
['Java']
0
watering-plants-ii
思路记录
si-lu-ji-lu-by-ychhf-rtc0
Intuition一开始没有看到植物需要水的量最大值也就是等于capacityA or B,所以每次取水完了之后不管咋样都是够用的,按照题目条件来,双指针就行 注意当他两到了一个格子之后最大值来浇水,如果小于当前格子也说明不够,也需要补一次水也就是time+=1Code
ychhf
NORMAL
2025-01-21T22:17:10.384902+00:00
2025-01-21T22:17:10.384902+00:00
2
false
# Intuition 一开始没有看到植物需要水的量最大值也就是等于capacityA or B,所以每次取水完了之后不管咋样都是够用的,按照题目条件来,双指针就行 注意当他两到了一个格子之后最大值来浇水,如果小于当前格子也说明不够,也需要补一次水也就是time+=1 # Code ```python3 [] class Solution: def minimumRefill(self, plants: List[int], capacityA: int, capacityB: int) -> int: n = len(plants) l, r = 0, n - 1 a = c...
0
0
['Python3']
0
watering-plants-ii
Watering Plants II
watering-plants-ii-by-mannu9-qigd
Approach Alice start from i=0 Bob start from j=p.length-1 Both Alice and bob move one step , Now all cases possible in their movement Case 1 : Alice and Bob bo
Mannu9_
NORMAL
2025-01-19T02:45:52.666206+00:00
2025-01-19T02:45:52.666206+00:00
10
false
# Approach - Alice start from i=0 - Bob start from j=p.length-1 - Both Alice and bob move one step , Now all cases possible in their movement 1. Case 1 : Alice and Bob both have sufficient water , they will water plant 1. Case 2 : Either Alice or Bob water finished , then refill water can of their and increase refill...
0
0
['Java']
0
watering-plants-ii
2105. Watering Plants II
2105-watering-plants-ii-by-g8xd0qpqty-gh0c
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-18T02:34:36.899173+00:00
2025-01-18T02:34:36.899173+00:00
4
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 complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python3']
0
watering-plants-ii
Easy in c++ beginners friendly
easy-in-c-beginners-friendly-by-_alpha-b-dc0v
IntuitionApproachComplexity Time complexity: Space complexity: Code
_alpha-byte2
NORMAL
2025-01-10T09:54:16.201076+00:00
2025-01-10T09:54:16.201076+00:00
5
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 complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C++']
0
watering-plants-ii
My solution iterates from both ends, refilling cans when needed, and counts total refills.
my-solution-iterates-from-both-ends-refi-hmqt
IntuitionApproachComplexity Time complexity: Space complexity: Code
athinarayanan
NORMAL
2024-12-25T04:41:29.461777+00:00
2024-12-25T04:41:29.461777+00:00
3
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 complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python']
0
watering-plants-ii
Using the two pointer i achieve the solution.
using-the-two-pointer-i-achieve-the-solu-fqyr
IntuitionApproachComplexity Time complexity: Space complexity: Code
athinarayanan
NORMAL
2024-12-24T07:43:03.861651+00:00
2024-12-24T07:43:03.861651+00:00
4
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 complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python']
0
watering-plants-ii
Easy to understand -- C++
easy-to-understand-c-by-paldilip-7xov
Complexity Time complexity: O(n) Space complexity: O(1) Code
paldilip
NORMAL
2024-12-22T05:47:06.223823+00:00
2024-12-22T05:47:06.223823+00:00
7
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 ```cpp [] class Solution { public: int minimumRefill(vector<int>& nums, int capacityA, int capacityB) { int n = nums.size(); ...
0
0
['C++']
0
watering-plants-ii
eazy
eazy-by-harsh_saini_3878-23ah
IntuitionApproachComplexity Time complexity: Space complexity: Code
HARSH_SAINI_3878
NORMAL
2024-12-20T10:50:57.364448+00:00
2024-12-20T10:50:57.364448+00:00
3
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 complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C++']
0
watering-plants-ii
Super simple solution using two pointer C++
super-simple-solution-using-two-pointer-7zr2e
IntuitionApproachComplexity Time complexity: Space complexity: Code
mittalpulkit75
NORMAL
2024-12-15T08:39:41.863272+00:00
2024-12-15T08:39:41.863272+00:00
3
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)$$ --...
0
0
['C++']
0
watering-plants-ii
Easy Two Pointer Approach || C++
easy-two-pointer-approach-c-by-vijay_kun-wu4y
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
vijay_kunigiri17
NORMAL
2024-12-05T03:51:03.159219+00:00
2024-12-05T03:51:03.159263+00:00
1
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)$$ --...
0
0
['C++']
0
watering-plants-ii
C++ | 0ms | Beats 100% 🔥 | Easy to understand
c-0ms-beats-100-easy-to-understand-by-go-qih0
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
goelsaransh30
NORMAL
2024-12-03T21:01:47.448435+00:00
2024-12-03T21:01:47.448473+00:00
1
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 complexity here, e.g. $...
0
0
['C++']
0
watering-plants-ii
Easiest C++ Solution || Beats 100%
easiest-c-solution-beats-100-by-iqrathan-r6dd
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
iqrathanedar
NORMAL
2024-12-02T12:45:53.283435+00:00
2024-12-02T12:45:53.283479+00:00
0
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:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int c...
0
0
['C++']
0
watering-plants-ii
Beats 100%|| C++ solution
beats-100-c-solution-by-aryan_rajput4266-13my
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
Aryan_Rajput4266
NORMAL
2024-12-01T15:33:58.638854+00:00
2024-12-01T15:33:58.638872+00:00
2
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)$$ -->O(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$...
0
0
['C++']
0
watering-plants-ii
C++|| beats 11.31% || TC - O(N) || SC - O(1) || Two pointer
c-beats-1131-tc-on-sc-o1-two-pointer-by-jrjun
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
Aryan_Rajput4266
NORMAL
2024-12-01T15:28:15.076561+00:00
2024-12-01T15:28:15.076587+00:00
1
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)$$ -->O(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$...
0
0
['C++']
0
watering-plants-ii
C++ SOLUTION FOR BEGINNERS
c-solution-for-beginners-by-manikantamuv-nzt7
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
MANIKANTAMUVVA
NORMAL
2024-12-01T12:10:17.182825+00:00
2024-12-01T12:10:17.182868+00:00
2
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)$$ --...
0
0
['C++']
0
watering-plants-ii
O(n) JAVA easy solution
on-java-easy-solution-by-shivangi1-p4wp
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
shivangi1
NORMAL
2024-11-19T06:05:14.070549+00:00
2024-11-19T06:05:14.070576+00:00
8
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)$$ --...
0
0
['Java']
0
watering-plants-ii
Java - Simple solution with less code
java-simple-solution-with-less-code-by-n-y0bg
Intuition\nSimple solution using two pointers with left and right. When the number of plants is odd, the while loop breaks with the left and right pointers meet
ntopno1
NORMAL
2024-10-21T13:34:03.818791+00:00
2024-10-21T13:38:29.526428+00:00
1
false
# Intuition\nSimple solution using two pointers with left and right. When the number of plants is odd, the while loop breaks with the left and right pointers meets in the middle. The calculation needs to be done after the while loop.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```j...
0
0
['Java']
0
watering-plants-ii
Ez solution | 100% Beats
ez-solution-100-beats-by-azenshpis-ml0j
Complexity\nO(n)\nO(1)\n\n# Code\ngolang []\nfunc minimumRefill(plants []int, capacityA int, capacityB int) int {\n l := len(plants)\n if l < 3 {\n
azenshpis
NORMAL
2024-09-30T14:06:15.017579+00:00
2024-09-30T14:06:15.017611+00:00
2
false
# Complexity\nO(n)\nO(1)\n\n# Code\n```golang []\nfunc minimumRefill(plants []int, capacityA int, capacityB int) int {\n l := len(plants)\n if l < 3 {\n return 0\n }\n\n res := 0\n currA, currB := capacityA, capacityB\n i, j := 0, l-1\n for i < j { \n if currA < plants[i] {\n ...
0
0
['Go']
0
watering-plants-ii
Greedy Two Point Traversal. Time: O(n), Space: O(1)
greedy-two-point-traversal-time-on-space-njze
Approach\n Describe your approach to solving the problem. \nTraverse array with two pointers - one from left to right and other right to left until they meet. \
iitjsagar
NORMAL
2024-09-03T19:59:15.748451+00:00
2024-09-03T19:59:15.748481+00:00
1
false
# Approach\n<!-- Describe your approach to solving the problem. -->\nTraverse array with two pointers - one from left to right and other right to left until they meet. \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 spac...
0
0
['Python']
0
watering-plants-ii
Watering Plants II
watering-plants-ii-by-prakashkale-kys8
Intuition\nWatering Plants II\n# Approach\nTwo pointers approach\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\n O(1)\n\n# Code\n```java []\n
Prakashkale
NORMAL
2024-08-24T12:22:23.679643+00:00
2024-08-24T12:22:23.679713+00:00
4
false
# Intuition\nWatering Plants II\n# Approach\nTwo pointers approach\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\n O(1)\n\n# Code\n```java []\nclass Solution {\n public int minimumRefill(int[] plants, int capacityA, int capacityB) {\n int a = capacityA;\n int b = capacityB;\n ...
0
0
['Two Pointers', 'Java']
0
watering-plants-ii
4 ms Beats 98.68%
4-ms-beats-9868-by-sarthak_shishodia20-t5le
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
Sarthak_Shishodia20
NORMAL
2024-08-14T11:22:52.880415+00:00
2024-08-14T11:22:52.880453+00:00
1
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)$$ --...
0
0
['Java']
0
watering-plants-ii
C++ || simulations || single-pass || beginner-friendly || ✅✅🔥🔥
c-simulations-single-pass-beginner-frien-1ksu
\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 complexity here, e.g. O(n) \n
user007pj
NORMAL
2024-08-02T17:10:50.641029+00:00
2024-08-02T17:10:50.641064+00:00
1
false
\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 complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int i = 0;\n...
0
0
['C++']
0
watering-plants-ii
EASY TO UNDERSTAND C++ TWO POINTERS
easy-to-understand-c-two-pointers-by-dhr-h07i
Intuition\nAlice and Bob start watering plants from opposite ends. They both try to water as many plants as possible with their initial capacity. When they can\
Dhruv2816
NORMAL
2024-08-01T17:30:11.077352+00:00
2024-08-01T17:30:11.077385+00:00
0
false
# Intuition\nAlice and Bob start watering plants from opposite ends. They both try to water as many plants as possible with their initial capacity. When they can\'t water a plant, they refill their can. Special care is needed when they meet at the same plant to ensure only one refill is counted if necessary.\n\n# Appro...
0
0
['Array', 'Two Pointers', 'Simulation', 'C++']
0
watering-plants-ii
Simple Two Pointer Method
simple-two-pointer-method-by-tejya2107-bcsv
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
Tejas2107
NORMAL
2024-07-30T05:38:46.885887+00:00
2024-07-30T05:38:46.885923+00:00
3
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 complexity here, e.g. $$O...
0
0
['Two Pointers', 'C++']
0
watering-plants-ii
C++ simple code with while loop || O(n) approach
c-simple-code-with-while-loop-on-approac-dxob
Intuition\nSimple Simulation || Array \n\n# Approach\nTwo pointer\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solu
Siddharth_2905
NORMAL
2024-07-29T13:22:39.507123+00:00
2024-07-29T13:22:39.507160+00:00
0
false
# Intuition\nSimple Simulation || Array \n\n# Approach\nTwo pointer\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n int minimumRefill(vector<int>& plants, int capacityA, int capacityB) {\n int n = plants.size();\n int alice = 0;\n ...
0
0
['C++']
0
watering-plants-ii
Watering Plants 2 -> O(n) O(1)
watering-plants-2-on-o1-by-rupalirajput3-2kma
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
rupalirajput3062000
NORMAL
2024-07-27T18:40:30.014787+00:00
2024-07-27T18:40:30.014809+00:00
1
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 complexity here, e.g. $...
0
0
['Java']
0
watering-plants-ii
scala simulation recursion
scala-simulation-recursion-by-vititov-rzw9
scala\nobject Solution {\n def minimumRefill(plants: Array[Int], capacityA: Int, capacityB: Int): Int =\n def f(iA: Int = 0, iB:Int = plants.length-1, remA:
vititov
NORMAL
2024-07-25T15:42:33.000383+00:00
2024-07-25T15:42:33.000417+00:00
0
false
```scala\nobject Solution {\n def minimumRefill(plants: Array[Int], capacityA: Int, capacityB: Int): Int =\n def f(iA: Int = 0, iB:Int = plants.length-1, remA: Int = capacityA, remB: Int = capacityB, acc:Int = 0): Int = {\n lazy val (refA,remA1) = if(remA>=plants(iA)) (0, remA-plants(iA)) else (1, capacityA-pl...
0
0
['Array', 'Two Pointers', 'Simulation', 'Scala']
0
watering-plants-ii
Easy || Explain basic
easy-explain-basic-by-pntay_orange-yaq6
Explain\n Describe your approach to solving the problem. \n1. Initialization:\n- refill: to count the total number of refills.\n- n: the number of plants.\n- ca
pntay_orange
NORMAL
2024-07-24T14:49:55.407148+00:00
2024-07-24T14:49:55.407180+00:00
0
false
# Explain\n<!-- Describe your approach to solving the problem. -->\n1. Initialization:\n- refill: to count the total number of refills.\n- n: the number of plants.\n- canA and canB: current water levels for person A and person B, respectively.\n\n**2. Iteration:**\n- Loop through the first half of the plants (i from 0 ...
0
0
['C++']
0
watering-plants-ii
Beats 100%, 29 ms
beats-100-29-ms-by-nazar_zakrevski-io9i
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
Nazar_Zakrevski
NORMAL
2024-07-17T14:11:11.437635+00:00
2024-07-17T14:11:11.437656+00:00
1
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 complexity here, e.g. $$...
0
0
['C++']
0
watering-plants-ii
Two pointers using JavaScript
two-pointers-using-javascript-by-yu-othe-soq4
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
yu-other
NORMAL
2024-07-16T13:38:34.797730+00:00
2024-07-16T13:38:34.797756+00:00
2
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)$$ --...
0
0
['JavaScript']
0
permutations
A general approach to backtracking questions in Java (Subsets, Permutations, Combination Sum, Palindrome Partioning)
a-general-approach-to-backtracking-quest-e6b1
This structure might apply to many other backtracking questions, but here I am just going to demonstrate Subsets, Permutations, and Combination Sum.\n\nSubsets
issac3
NORMAL
2016-05-23T15:56:10+00:00
2019-03-09T01:40:57.533322+00:00
668,218
false
This structure might apply to many other backtracking questions, but here I am just going to demonstrate Subsets, Permutations, and Combination Sum.\n\nSubsets : [https://leetcode.com/problems/subsets/][1]\n\n public List<List<Integer>> subsets(int[] nums) {\n List<List<Integer>> list = new ArrayList<>();\n ...
5,758
19
['Backtracking', 'Java']
297
permutations
My elegant recursive C++ solution with inline explanation
my-elegant-recursive-c-solution-with-inl-yci2
This recursive solution is the my first response for this problem. I was surprised when I found no similar solution posted here. It is much easier to understand
xiaohui7
NORMAL
2014-12-10T15:49:39+00:00
2018-10-27T00:07:00.106052+00:00
151,987
false
This recursive solution is the my first response for this problem. I was surprised when I found no similar solution posted here. It is much easier to understand than DFS-based ones, at least in my opinion. Please find more explanations [here][1]. All comments are welcome.\n\n class Solution {\n public:\n v...
874
7
['Recursion', 'Probability and Statistics']
101
permutations
Simple Python solution (DFS).
simple-python-solution-dfs-by-oldcodingf-uu4i
\n # DFS\n def permute(self, nums):\n res = []\n self.dfs(nums, [], res)\n return res\n \n def dfs(self, nums, path, re
oldcodingfarmer
NORMAL
2015-08-11T22:40:34+00:00
2018-10-24T16:45:38.837906+00:00
124,886
false
\n # DFS\n def permute(self, nums):\n res = []\n self.dfs(nums, [], res)\n return res\n \n def dfs(self, nums, path, res):\n if not nums:\n res.append(path)\n # return # backtracking\n for i in xrange(len(nums)):\n self.dfs(nums...
665
10
['Backtracking', 'Depth-First Search', 'Python']
48
permutations
[Python] [4 Approaches] : Visuals + Time Complexity Analysis
python-4-approaches-visuals-time-complex-053h
--------------------------\nApproach 1: Recursive with backtracking (implicit stack)\n--------------------------\n--------------------------\n\nBig-O:\n- Time:
Hieroglyphs
NORMAL
2020-12-30T15:06:14.190598+00:00
2021-08-16T12:58:12.833665+00:00
39,226
false
--------------------------\n**Approach 1: Recursive with backtracking (implicit stack)**\n--------------------------\n--------------------------\n\n**Big-O:**\n- **Time:** `O(N*N!)` \n\t- **Why O(N*N!) and not just O(N!) ?**\n\tMany people are debating in the solution tab whether time-complexity should be `O(N!)` or `O...
553
1
['Backtracking', 'Depth-First Search', 'Breadth-First Search', 'Recursion', 'Iterator', 'Python']
29
permutations
Backtrack Summary: General Solution for 10 Questions!!!!!!!! Python (Combination Sum, Subsets, Permutation, Palindrome)
backtrack-summary-general-solution-for-1-rioz
For Java version, please refer to isssac3's answer.\n\n39. Combination Sum\nhttps://leetcode.com/problems/combination-sum/\n\n def combinationSum(self, candi
dichen001
NORMAL
2016-12-24T05:19:34.592000+00:00
2018-10-21T18:57:51.164860+00:00
105,320
false
For Java version, please refer to [isssac3's answer.](https://discuss.leetcode.com/topic/46162/a-general-approach-to-backtracking-questions-in-java-subsets-permutations-combination-sum-palindrome-partioning)\n\n**39. Combination Sum**\nhttps://leetcode.com/problems/combination-sum/\n```\n def combinationSum(self, ca...
462
3
[]
23
permutations
My AC simple iterative java/python solution
my-ac-simple-iterative-javapython-soluti-du5a
the basic idea is, to permute n numbers, we can add the nth number into the resulting List<List<Integer>> from the n-1 numbers, in every possible position. \n\n
cbmbbz
NORMAL
2014-12-26T02:59:39+00:00
2018-10-25T01:58:22.152367+00:00
89,225
false
the basic idea is, to permute n numbers, we can add the nth number into the resulting `List<List<Integer>>` from the n-1 numbers, in every possible position. \n\nFor example, if the input num[] is {1,2,3}: First, add 1 into the initial `List<List<Integer>>` (let's call it "answer"). \n\nThen, 2 can be added in front or...
401
6
[]
45
permutations
One-Liners in Python
one-liners-in-python-by-stefanpochmann-ptrf
Solution 1: Recursive, take any number as first\n\nTake any number as the first number and append any permutation of the other numbers.\n\n def permute(self,
stefanpochmann
NORMAL
2015-06-27T18:29:27+00:00
2018-10-27T03:28:41.779464+00:00
63,795
false
**Solution 1: *Recursive, take any number as first***\n\nTake any number as the first number and append any permutation of the other numbers.\n\n def permute(self, nums):\n return [[n] + p\n for i, n in enumerate(nums)\n for p in self.permute(nums[:i] + nums[i+1:])] or [[]]\n\n--...
372
18
['Python']
36
permutations
Beats 100% Java with Explanations
beats-100-java-with-explanations-by-grac-gdjk
Thought\nWe think about a searching tree when we apply Backtracking.\n\ne.g.[1, 2, 3]\n 1 -2 -3\n -3 -2\n\n 2 -1 -3\n -3 -1\n\n 3 -1 -2\n
gracemeng
NORMAL
2018-10-10T20:37:05.301275+00:00
2018-10-21T06:21:26.175241+00:00
24,844
false
**Thought**\nWe think about a searching tree when we apply Backtracking.\n```\ne.g.[1, 2, 3]\n 1 -2 -3\n -3 -2\n\n 2 -1 -3\n -3 -1\n\n 3 -1 -2\n -2 -1\n```\nIf we exhausted the current branch, `currResult.size() == nums.length`, we will backtrack.\nTo make sure each element is used once, we esta...
307
2
[]
21
permutations
DFS/backtracking - Python/Java/Javascript, PICTURE
dfsbacktracking-pythonjavajavascript-pic-27eq
Classic combinatorial search problem, we can solve it using 3-step system \n\n1. Identify states\nWhat state do we need to know whether we have reached a soluti
lukskywalkerrr
NORMAL
2020-06-13T20:32:56.400468+00:00
2020-06-17T20:43:48.784015+00:00
49,451
false
Classic combinatorial search problem, we can solve it using 3-step system \n\n1. Identify states\nWhat state do we need to know whether we have reached a solution (and using it to construct a solution if the problem asks for it).\nWe need a state to keep track of the list of letters we have chosen for the current permu...
276
1
['Backtracking', 'Tree', 'Depth-First Search', 'Recursion', 'Java', 'Python3', 'JavaScript']
20
permutations
【Video】Simple Backtracking Solution
video-simple-backtracking-solution-by-ni-9anh
IntuitionUsing backtracking to create all possible combinationsSolution Video⭐️⭐️ Don't forget to subscribe to my channel! ⭐️⭐️■ Subscribe URL http://www.youtub
niits
NORMAL
2024-12-13T04:51:19.192473+00:00
2024-12-13T04:51:19.192473+00:00
24,675
false
# Intuition\nUsing backtracking to create all possible combinations\n\n---\n\n# Solution Video\n\nhttps://youtu.be/J7m7W7P6e3s\n\n### \u2B50\uFE0F\u2B50\uFE0F Don\'t forget to subscribe to my channel! \u2B50\uFE0F\u2B50\uFE0F\n\n**\u25A0 Subscribe URL**\nhttp://www.youtube.com/channel/UC9RMNwYTL3SXCP6ShLWVFww?sub_confi...
224
0
['Array', 'Backtracking', 'C++', 'Java', 'Python3', 'JavaScript']
5
permutations
[Python3] backtracking
python3-backtracking-by-zhanweiting-dd9l
\nclass Solution:\n """\n Level0: []\n level1: [1] [2] [3]\n level2: [1,2] [1,3] [2,1] [2,3] [3,1] [3,2]
zhanweiting
NORMAL
2019-08-17T03:02:07.350288+00:00
2019-08-21T01:31:40.398878+00:00
29,333
false
```\nclass Solution:\n """\n Level0: []\n level1: [1] [2] [3]\n level2: [1,2] [1,3] [2,1] [2,3] [3,1] [3,2]\n level3: [1,2,3] [1,3,2] [2,1,3][2,3,1] [3,1,2][3,2,1] \n \n """\n \n def permute(self, nums: List[int]) -> List[List[int]]:...
165
1
['Backtracking', 'Python', 'Python3']
24
permutations
Backtracking Solution || C++ || Easy To Understand || With explanation
backtracking-solution-c-easy-to-understa-cey0
\nSuppose if give string is ABC then recursive tree like this\n\n\n\n\nclass Solution {\npublic:\n vector<vector<int>> result;\n \n // Backtracking\n
vivek_javiya
NORMAL
2021-06-07T17:59:05.736556+00:00
2021-06-07T17:59:05.736580+00:00
20,591
false
\nSuppose if give string is ABC then recursive tree like this\n![image](https://assets.leetcode.com/users/images/0865f0cf-1f8a-4164-9543-4bf13aebcb59_1623088635.478572.jpeg)\n\n\n```\nclass Solution {\npublic:\n vector<vector<int>> result;\n \n // Backtracking\n void permutation(vector<int> &nums,int i,int ...
160
1
['Backtracking', 'Recursion', 'C', 'C++']
19
permutations
Java Clean Code - Two recursive solutions
java-clean-code-two-recursive-solutions-z2sum
Bottom up? approach - 280ms\n\n public class Solution {\n public List> permute(int[] nums) {\n \t\tList> permutations = new ArrayList<>();\n \t\t
ceilfors
NORMAL
2015-08-31T15:35:33+00:00
2018-10-23T06:44:55.530144+00:00
38,814
false
**Bottom up? approach - 280ms**\n\n public class Solution {\n public List<List<Integer>> permute(int[] nums) {\n \t\tList<List<Integer>> permutations = new ArrayList<>();\n \t\tif (nums.length == 0) {\n \t\t\treturn permutations;\n \t\t}\n \n \t\tcollectPermutations(nums, 0, new ArrayList<>()...
133
1
['Java']
9
permutations
C++ backtracking and nextPermutation
c-backtracking-and-nextpermutation-by-ji-q40z
Backtracking\n\ncpp\nclass Solution {\npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n vector<vector<int>> perms;\n permute(nums,
jianchao-li
NORMAL
2015-06-01T17:30:46+00:00
2018-08-11T13:40:30.647818+00:00
23,306
false
**Backtracking**\n\n```cpp\nclass Solution {\npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n vector<vector<int>> perms;\n permute(nums, 0, perms);\n return perms;\n }\nprivate:\n void permute(vector<int> nums, int i, vector<vector<int>>& perms) {\n if (i == nums.size()...
92
5
['Backtracking']
10
permutations
Share my short iterative JAVA solution
share-my-short-iterative-java-solution-b-9qcb
public List<List<Integer>> permute(int[] num) {\n LinkedList<List<Integer>> res = new LinkedList<List<Integer>>();\n res.add(new ArrayList<Integer
tusizi
NORMAL
2015-03-26T11:26:37+00:00
2015-03-26T11:26:37+00:00
33,113
false
public List<List<Integer>> permute(int[] num) {\n LinkedList<List<Integer>> res = new LinkedList<List<Integer>>();\n res.add(new ArrayList<Integer>());\n for (int n : num) {\n int size = res.size();\n for (; size > 0; size--) {\n List<Integer> r = res.pollFi...
81
1
[]
7
permutations
Short recursive Python solution
short-recursive-python-solution-by-oliwi-qleg
```\nclass Solution(object):\n def permute(self, nums):\n if len(nums) == 1:\n return [nums]\n result = []\n for i in range(l
oliwiam96
NORMAL
2020-03-25T17:55:12.852828+00:00
2020-03-25T17:58:14.924383+00:00
7,541
false
```\nclass Solution(object):\n def permute(self, nums):\n if len(nums) == 1:\n return [nums]\n result = []\n for i in range(len(nums)):\n others = nums[:i] + nums[i+1:]\n other_permutations = self.permute(others)\n for permutation in other_permutations...
74
1
['Python']
8
permutations
🔐 [VIDEO] 100% Unlocking Recursive & Backtracking for Permutations
video-100-unlocking-recursive-backtracki-r9xx
Intuition\nWhen I first looked at this problem, I realized it was a classic case of generating all possible permutations of a given list of numbers. My initial
vanAmsen
NORMAL
2023-08-02T01:01:16.982363+00:00
2023-08-02T13:07:22.508967+00:00
15,759
false
# Intuition\nWhen I first looked at this problem, I realized it was a classic case of generating all possible permutations of a given list of numbers. My initial thought was to use a recursive approach to solve it. Recursive algorithms, especially backtracking, often provide a clean and efficient solution for generatin...
71
3
['C++', 'Java', 'Python3', 'JavaScript', 'C#']
4
permutations
Beats 100% 💥🔥Simple Swapping and Backtracking
beats-100-simple-swapping-and-backtracki-cjlr
PLEASE UPVOTE \uD83D\uDC4D\n\n# Approach\nNot need of an extra array, just use swap on every element.\n Describe your approach to solving the problem. \n\n# Com
ribhav_32
NORMAL
2023-04-04T09:53:44.410710+00:00
2023-04-05T22:57:52.654396+00:00
10,751
false
# **PLEASE UPVOTE \uD83D\uDC4D**\n\n# Approach\n**Not need of an extra array, just use swap on every element.**\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N*N!)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N!)\n<!-- Add your space co...
53
1
['Backtracking', 'C++']
3
permutations
Javascript Backtracking with Explanation beats 99%
javascript-backtracking-with-explanation-iuw2
Here is my simple recursive solution. I\'ve provided many details to why certain things are done which may be more obvious to others. Credits to user isaac3, as
joseph13
NORMAL
2019-05-16T05:05:10.326635+00:00
2019-05-16T05:05:10.326705+00:00
10,235
false
Here is my simple recursive solution. I\'ve provided many details to why certain things are done which may be more obvious to others. Credits to user [isaac3](https://leetcode.com/issac3/), as this is inspired by this [post](https://leetcode.com/problems/combination-sum/discuss/16502/A-general-approach-to-backtracking-...
46
0
[]
4
permutations
[backtracking] Clean C++ recursion with detailed explanation
backtracking-clean-c-recursion-with-deta-h3md
The idea is much like the insertion sort. We start with only the first number, and pick next number from the rest of array, insert it to the front or back posit
zefengsong
NORMAL
2017-07-06T04:41:13.626000+00:00
2017-07-06T04:41:13.626000+00:00
9,427
false
The idea is much like the insertion sort. We start with only the first number, and pick next number from the rest of array, insert it to the front or back position of the first number, and pick the third number, insert it to front or mid or back position of the `[first, second]` array, and so on, until no element left....
46
0
['Backtracking', 'C++']
6
permutations
100% fast || Image +Video Explanation || Backtracking || C++ || Java || Python
100-fast-image-video-explanation-backtra-nete
Intuition\n Describe your first thoughts on how to solve this problem. \nfor every number all the positions are available if it is not filled so we can put anyw
shivam-727
NORMAL
2023-08-02T02:15:49.964866+00:00
2023-08-16T11:15:17.933937+00:00
12,307
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nfor every number all the positions are available if it is not filled so we can put anywhere and recursively call and generate.\n\nFor detailed explanation you can refer to my youtube channel (hindi Language)\nhttps://youtu.be/XUQ0iZ94CGg\...
44
2
['Backtracking', 'Recursion', 'Python', 'C++', 'Java']
4
permutations
✅Easiest 😎 FAANG Method Ever !!! 💥
easiest-faang-method-ever-by-adityabhate-ezov
---\n# PLEASE UPVOTE IF IT HELPS \u2764\uFE0F\n---\n\n# 1) Most Optimal Iterative Approach \uD83D\uDD25\n\n- Time complexity: O(n!+nlogn) ~ O(n!)\n Add your tim
AdityaBhate
NORMAL
2023-01-03T13:46:35.714309+00:00
2023-01-03T13:48:36.498201+00:00
14,744
false
---\n# ***PLEASE UPVOTE IF IT HELPS \u2764\uFE0F***\n---\n\n# 1) Most Optimal Iterative Approach \uD83D\uDD25\n\n- Time complexity: O(n!+nlogn) ~ O(n!)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n```\nclass Solution {\npubli...
44
6
['Array', 'Backtracking', 'Recursion', 'C++', 'Java']
4
permutations
A more general approach to backtracking questions in Python
a-more-general-approach-to-backtracking-pyrn9
Inspired by @issac3 , I write a more general approach to backtracking questions in Python (Subsets, Permutations, Combination Sum,Generate Parentheses, Partitio
gyh75520
NORMAL
2019-05-29T08:32:08.357380+00:00
2019-09-05T12:14:52.690453+00:00
6,495
false
Inspired by @issac3 , I write a more general approach to backtracking questions in Python (Subsets, Permutations, Combination Sum,Generate Parentheses, Partition Equal Subset Sum,Letter Tile Possibilities)\n Thansks for [A general approach to backtracking questions in Java (Subsets, Permutations, Combination Sum, Pali...
43
0
['Backtracking', 'Python3']
3
permutations
Share my three different solutions
share-my-three-different-solutions-by-sh-47si
// method 1: standard backtracing solution\n vector<vector<int> > permute(vector<int> &num) {\n vector<vector<int> > ans;\n permutation(num, 0,
shichaotan
NORMAL
2015-01-04T21:33:10+00:00
2018-09-03T01:09:22.025992+00:00
14,864
false
// method 1: standard backtracing solution\n vector<vector<int> > permute(vector<int> &num) {\n vector<vector<int> > ans;\n permutation(num, 0, ans);\n return ans;\n }\n \n void permutation(vector<int> &num, int begin, vector<vector<int> > &ans) {\n if (begin >= num.size()) {...
43
1
[]
5
permutations
Simple Java Sol
simple-java-sol-by-sarthak_singh-jmz3
\n\nclass Solution {\n public List<List<Integer>> permute(int[] nums) {\n List<List<Integer>> res = new ArrayList<>();\n boolean [] visited = n
Sarthak_Singh_
NORMAL
2022-12-22T07:02:41.909148+00:00
2022-12-22T07:02:41.909189+00:00
9,623
false
\n```\nclass Solution {\n public List<List<Integer>> permute(int[] nums) {\n List<List<Integer>> res = new ArrayList<>();\n boolean [] visited = new boolean[nums.length];\n FindAllPermutation(res,nums, new ArrayList(),visited);\n return res;\n }\n void FindAllPermutation(List<List<I...
41
0
['Java']
0
permutations
python solution|93%| utilized the same logic for problem 39 and 40| with illustration
python-solution93-utilized-the-same-logi-yk4g
It uses the same backtracking algorithm to solve problem 39 and 40. It will be very helpful if you look these 3 question all together. My post on those two ques
bubblecat
NORMAL
2020-08-28T14:31:47.623376+00:00
2021-03-02T04:40:58.787336+00:00
4,948
false
It uses the same backtracking algorithm to solve problem 39 and 40. It will be very helpful if you look these 3 question all together. My post on those two questions also linked below. The chart to illustrate the process is in the bottom.\n\n[39. Combination Sum](https://leetcode.com/problems/combination-sum/discuss/81...
37
1
['Backtracking', 'Recursion', 'Python', 'Python3']
6
permutations
✔️C++||Python||C🔥0ms✅Backtrack with graph explained || Beginner-friendly ^_^
cpythonc0msbacktrack-with-graph-explaine-3nor
Approach\nUse a recursive function backtrack, in the function, we pass in a index.\nIn the function, we use a for loop swap nums[index] with different numbers i
luluboy168
NORMAL
2023-08-02T06:03:01.677735+00:00
2023-08-02T06:03:01.677758+00:00
2,331
false
# Approach\nUse a recursive function `backtrack`, in the function, we pass in a index.\nIn the function, we use a for loop swap `nums[index]` with different numbers in `nums`.\nAfter each swap, call `backtrack` again with `index+1`.\nThen swap back the values, so that we can get every permutations as the graph shown be...
34
1
['Backtracking', 'C', 'C++', 'Python3']
1
permutations
✅ 🔥 0 ms Runtime Beats 100% User🔥|| Code Idea ✅ || Algorithm & Solving Step ✅ ||
0-ms-runtime-beats-100-user-code-idea-al-75jy
\n\n\n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n\n### Intuition :\n- Instead of maintaining a used array or an additional list (te
Letssoumen
NORMAL
2024-11-24T02:11:27.522312+00:00
2024-11-24T02:11:27.522342+00:00
8,176
false
![Screenshot 2024-11-24 at 7.36.10\u202FAM.png](https://assets.leetcode.com/users/images/5c74b8f1-047c-4821-8f17-07f7247ee6b8_1732414081.4559476.png)\n\n\n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n\n### **Intuition** :\n- Instead of maintaining a `used` array or an additional list (`temp`)...
33
3
['Array', 'Backtracking', 'C++', 'Java', 'Python3']
2
permutations
✅☑️ Best C++ 2 Solution Ever || Easy Solution || Backtracking || One Stop Solution.
best-c-2-solution-ever-easy-solution-bac-si6g
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can solve this problem using Array + Backtracking.\n\n# Approach\n Describe your app
its_vishal_7575
NORMAL
2023-02-21T10:07:00.471094+00:00
2023-02-21T11:07:12.401334+00:00
6,373
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can solve this problem using Array + Backtracking.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can easily understand the all the approaches by seeing the code which is easy to understand with comments.\n\...
31
0
['Array', 'Backtracking', 'C++']
1
permutations
Intuitive JavaScript Solution with DFS
intuitive-javascript-solution-with-dfs-b-t61e
\n/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar permute = function(nums) {\n const output = [];\n /**\n * The goal is break down the pro
dawchihliou
NORMAL
2020-05-03T07:00:49.186518+00:00
2020-05-03T07:00:49.186561+00:00
4,752
false
```\n/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar permute = function(nums) {\n const output = [];\n /**\n * The goal is break down the problem by finding permutations in subarrays.\n * So we will maintain a subarray of fixed elements and a subarray for \n * exploring permutations.\n *\n ...
30
1
['Depth-First Search', 'JavaScript']
3
permutations
General Backtracking questions solutions in Python for reference :
general-backtracking-questions-solutions-ntm3
I have taken solutions of @caikehe from frequently asked backtracking questions which I found really helpful and had copied for my reference. I thought this pos
coders-block
NORMAL
2019-11-15T06:17:42.925959+00:00
2019-11-15T06:27:58.118784+00:00
3,796
false
I have taken solutions of @caikehe from frequently asked backtracking questions which I found really helpful and had copied for my reference. I thought this post will be helpful for everybody as in an interview I think these basic solutions can come in handy. Please add any more questions in comments that you think mig...
30
1
['Backtracking', 'Python', 'Python3']
1
permutations
My Java Accepted solution without additional space
my-java-accepted-solution-without-additi-abzn
public class Solution {\n public List<List<Integer>> permute(int[] num) {\n List<List<Integer>> result = new ArrayList<List<Integer>>();\n
adamlhh
NORMAL
2014-11-30T23:25:56+00:00
2018-10-06T21:06:13.546427+00:00
9,459
false
public class Solution {\n public List<List<Integer>> permute(int[] num) {\n List<List<Integer>> result = new ArrayList<List<Integer>>();\n permute(result, num, 0);\n return result;\n }\n \n private void permute(List<List<Integer>> result, int[] array, int...
30
6
[]
9
permutations
✅ C++ || Beginner [Explained] || Backtracking || Clean
c-beginner-explained-backtracking-clean-1lgsg
Approach\n\nThis problem is very similar to finding combinations of a range but here we have to find permutations , and as we know in permutations we ordering m
99NotOut_half_dead
NORMAL
2021-09-20T10:23:51.226272+00:00
2021-09-20T10:24:30.274292+00:00
2,421
false
# ***Approach***\n```\nThis problem is very similar to finding combinations of a range but here we have to find permutations , and as we know in permutations we ordering matters\n\nmeans [1,2,3] != [2,1,3] != [3,2,1]\n\nwe will use visited vector to keep track of already present values in path\nBenifit of using visited...
27
1
['Backtracking', 'C']
4
permutations
[Python] Backtracking - Clean & Concise
python-backtracking-clean-concise-by-hie-3suj
python\nclass Solution:\n def permute(self, nums: List[int]) -> List[List[int]]:\n n = len(nums)\n ans = []\n \n def bt(i):\n
hiepit
NORMAL
2019-03-10T06:57:18.029952+00:00
2024-04-12T21:54:17.749315+00:00
819
false
```python\nclass Solution:\n def permute(self, nums: List[int]) -> List[List[int]]:\n n = len(nums)\n ans = []\n \n def bt(i):\n if i == n:\n ans.append(nums[::])\n return\n \n for j in range(i, n):\n nums[i], n...
26
0
['Backtracking']
1