You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|[Leetcode-1910](https://leetcode.com/problems/remove-all-occurrences-of-a-substring/)| Remove All Occurrences Of A Substring |[c++](./leetcode/1910.remove-all-occurrences-of-a-substring.cpp), [python3](./leetcode/1910.remove-all-occurrences-of-a-substring.py)| Simulation | O\(NM\)| O\(1\)| - |
|[Leetcode-653](https://leetcode.com/problems/two-sum-iv-input-is-a-bst/)| Two Sum Iv Input Is A Bst |[c++](./leetcode/653.two-sum-iv-input-is-a-bst.cpp), [python3](./leetcode/653.two-sum-iv-input-is-a-bst.py)| Two Pointers | O\(NH\)| O\(H\)| - |
|[Leetcode-680](https://leetcode.com/problems/valid-palindrome-ii/)| Valid Palindrome II |[c++](./leetcode/680.valid-palindrome-ii.cpp), [python3](./leetcode/680.valid-palindrome-ii.py)| Two Pointers | O\(N\)| O\(1\)| - |
892
+
|[Leetcode-2105](https://leetcode.com/problems/watering-plants-ii/)| Watering Plants II |[c++](./leetcode/2105.watering-plants-ii.cpp), [python3](./leetcode/2105.watering-plants-ii.py)| Two Pointers | O\(N\)| O\(1\)| - |
890
893
|[Leetcode-1712](https://leetcode.com/problems/ways-to-split-array-into-three-subarrays/)| Ways To Split Array Into Three Subarrays |[c++](./leetcode/1712.ways-to-split-array-into-three-subarrays.cpp), [python3](./leetcode/1712.ways-to-split-array-into-three-subarrays.py)| Two Pointers | O\(N\)| O\(N\)| - |
891
894
|[Lintcode-861](https://www.lintcode.com/problem/k-empty-slots/)| K Empty Slots |[c++](./lintcode/861.k-empty-slots.cpp), [python3](./lintcode/861.k-empty-slots.py)| Two Pointers | O\(N\)| O\(N\)| Leetcode-683 |
892
895
|[Lintcode-3736](https://www.lintcode.com/problem/kth-smallest-subarray-sum/)| Kth Smallest Subarray Sum |[c++](./lintcode/3736.kth-smallest-subarray-sum.cpp), [python3](./lintcode/3736.kth-smallest-subarray-sum.py)| Two Pointers | O\(NlogA\)| O\(1\)| Leetcode-1918 |
|[Leetcode-3386](https://leetcode.com/problems/button-with-longest-push-time/)| Button With Longest Push Time |[c++](./leetcode/3386.button-with-longest-push-time.cpp), [python3](./leetcode/3386.button-with-longest-push-time.py)| Array | O\(N\)| O\(1\)| - |
1441
1444
|[Leetcode-2176](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array/)| Count Equal And Divisible Pairs In An Array |[c++](./leetcode/2176.count-equal-and-divisible-pairs-in-an-array.cpp), [python3](./leetcode/2176.count-equal-and-divisible-pairs-in-an-array.py)| Array | O\(N^2\)| O\(1\)| - |
1442
1445
|[Leetcode-2210](https://leetcode.com/problems/count-hills-and-valleys-in-an-array/)| Count Hills And Valleys In An Array |[c++](./leetcode/2210.count-hills-and-valleys-in-an-array.cpp), [python3](./leetcode/2210.count-hills-and-valleys-in-an-array.py)| Array | O\(N\)| O\(1\)| - |
1446
+
|[Leetcode-3392](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/)| Count Subarrays Of Length Three With A Condition |[c++](./leetcode/3392.count-subarrays-of-length-three-with-a-condition.cpp), [python3](./leetcode/3392.count-subarrays-of-length-three-with-a-condition.py)| Array | O\(N\)| O\(1\)| - |
1443
1447
|[Leetcode-3285](https://leetcode.com/problems/find-indices-of-stable-mountains/)| Find Indices Of Stable Mountains |[c++](./leetcode/3285.find-indices-of-stable-mountains.cpp), [python3](./leetcode/3285.find-indices-of-stable-mountains.py)| Array | O\(N\)| O\(1\)| - |
// You want to water n plants in your garden with a watering can. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i. There is a river at x = -1 that you can refill your watering can at.
8
+
// Each plant needs a specific amount of water. You will water the plants in the following way:
9
+
//
10
+
// Water the plants in order from left to right.
11
+
// After watering the current plant, if you do not have enough water to completely water the next plant, return to the river to fully refill the watering can.
12
+
// You cannot refill the watering can early.
13
+
//
14
+
// You are initially at the river (i.e., x = -1). It takes one step to move one unit on the x-axis.
15
+
// Given a 0-indexed integer array plants of n integers, where plants[i] is the amount of water the ith plant needs, and an integer capacity representing the watering can capacity, return the number of steps needed to water all the plants.
16
+
//
17
+
// Example 1:
18
+
//
19
+
// Input: plants = [2,2,3,3], capacity = 5
20
+
// Output: 14
21
+
// Explanation: Start at the river with a full watering can:
22
+
// - Walk to plant 0 (1 step) and water it. Watering can has 3 units of water.
23
+
// - Walk to plant 1 (1 step) and water it. Watering can has 1 unit of water.
24
+
// - Since you cannot completely water plant 2, walk back to the river to refill (2 steps).
25
+
// - Walk to plant 2 (3 steps) and water it. Watering can has 2 units of water.
26
+
// - Since you cannot completely water plant 3, walk back to the river to refill (3 steps).
27
+
// - Walk to plant 3 (4 steps) and water it.
28
+
// Steps needed = 1 + 1 + 2 + 3 + 3 + 4 = 14.
29
+
//
30
+
// Example 2:
31
+
//
32
+
// Input: plants = [1,1,1,4,2,3], capacity = 4
33
+
// Output: 30
34
+
// Explanation: Start at the river with a full watering can:
35
+
// - Water plants 0, 1, and 2 (3 steps). Return to river (3 steps).
36
+
// - Water plant 3 (4 steps). Return to river (4 steps).
37
+
// - Water plant 4 (5 steps). Return to river (5 steps).
38
+
// - Water plant 5 (6 steps).
39
+
// Steps needed = 3 + 3 + 4 + 4 + 5 + 5 + 6 = 30.
40
+
//
41
+
// Example 3:
42
+
//
43
+
// Input: plants = [7,7,7,7,7,7,7], capacity = 8
44
+
// Output: 49
45
+
// Explanation: You have to refill before watering each plant.
# You want to water n plants in your garden with a watering can. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i. There is a river at x = -1 that you can refill your watering can at.
8
+
# Each plant needs a specific amount of water. You will water the plants in the following way:
9
+
#
10
+
# Water the plants in order from left to right.
11
+
# After watering the current plant, if you do not have enough water to completely water the next plant, return to the river to fully refill the watering can.
12
+
# You cannot refill the watering can early.
13
+
#
14
+
# You are initially at the river (i.e., x = -1). It takes one step to move one unit on the x-axis.
15
+
# Given a 0-indexed integer array plants of n integers, where plants[i] is the amount of water the ith plant needs, and an integer capacity representing the watering can capacity, return the number of steps needed to water all the plants.
16
+
#
17
+
# Example 1:
18
+
#
19
+
# Input: plants = [2,2,3,3], capacity = 5
20
+
# Output: 14
21
+
# Explanation: Start at the river with a full watering can:
22
+
# - Walk to plant 0 (1 step) and water it. Watering can has 3 units of water.
23
+
# - Walk to plant 1 (1 step) and water it. Watering can has 1 unit of water.
24
+
# - Since you cannot completely water plant 2, walk back to the river to refill (2 steps).
25
+
# - Walk to plant 2 (3 steps) and water it. Watering can has 2 units of water.
26
+
# - Since you cannot completely water plant 3, walk back to the river to refill (3 steps).
27
+
# - Walk to plant 3 (4 steps) and water it.
28
+
# Steps needed = 1 + 1 + 2 + 3 + 3 + 4 = 14.
29
+
#
30
+
# Example 2:
31
+
#
32
+
# Input: plants = [1,1,1,4,2,3], capacity = 4
33
+
# Output: 30
34
+
# Explanation: Start at the river with a full watering can:
35
+
# - Water plants 0, 1, and 2 (3 steps). Return to river (3 steps).
36
+
# - Water plant 3 (4 steps). Return to river (4 steps).
37
+
# - Water plant 4 (5 steps). Return to river (5 steps).
38
+
# - Water plant 5 (6 steps).
39
+
# Steps needed = 3 + 3 + 4 + 4 + 5 + 5 + 6 = 30.
40
+
#
41
+
# Example 3:
42
+
#
43
+
# Input: plants = [7,7,7,7,7,7,7], capacity = 8
44
+
# Output: 49
45
+
# Explanation: You have to refill before watering each plant.
// Alice and Bob want to water n plants in their garden. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i.
8
+
// Each plant needs a specific amount of water. Alice and Bob have a watering can each, initially full. They water the plants in the following way:
9
+
//
10
+
// Alice waters the plants in order from left to right, starting from the 0th plant. Bob waters the plants in order from right to left, starting from the (n - 1)th plant. They begin watering the plants simultaneously.
11
+
// It takes the same amount of time to water each plant regardless of how much water it needs.
12
+
// Alice/Bob must water the plant if they have enough in their can to fully water it. Otherwise, they first refill their can (instantaneously) then water the plant.
13
+
// In case both Alice and Bob reach the same plant, the one with more water currently in his/her watering can should water this plant. If they have the same amount of water, then Alice should water this plant.
14
+
//
15
+
// Given a 0-indexed integer array plants of n integers, where plants[i] is the amount of water the ith plant needs, and two integers capacityA and capacityB representing the capacities of Alice's and Bob's watering cans respectively, return the number of times they have to refill to water all the plants.
0 commit comments