Skip to content

Commit 5ff4cf6

Browse files
committed
19/12/2020
1 parent 9ecdb43 commit 5ff4cf6

File tree

3 files changed

+63
-40
lines changed

3 files changed

+63
-40
lines changed

Daily-challenge/Dec/18/README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,20 @@ Just do while loop and convert to decimal
3434
## Code
3535
```python
3636
class Solution:
37-
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
38-
if len(intervals) <=1:
39-
return intervals
40-
intervals.sort(key=lambda key: key[0])
41-
i = 0
42-
while i < len(intervals)-1:
43-
if intervals[i][-1] >= intervals[i+1][0]:
44-
intervals[i][-1] = max(intervals[i][-1], intervals[i+1][-1])
45-
intervals.pop(i+1)
37+
def increasingTriplet(self, nums: List[int]) -> bool:
38+
idx = 0
39+
lenz = len(nums)
40+
temp = temp2 = float('inf')
41+
count = 0
42+
for idx in range(lenz):
43+
if nums[idx] <= temp:
44+
temp = nums[idx]
45+
elif nums[idx] <= temp2:
46+
temp2 = nums[idx]
47+
48+
4649
else:
47-
i += 1
48-
return intervals
50+
return True
51+
52+
return False
4953
```

Daily-challenge/Dec/18/sol.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
class Solution:
2-
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
3-
if len(intervals) <=1:
4-
return intervals
5-
intervals.sort(key=lambda key: key[0])
6-
i = 0
7-
while i < len(intervals)-1:
8-
if intervals[i][-1] >= intervals[i+1][0]:
9-
intervals[i][-1] = max(intervals[i][-1], intervals[i+1][-1])
10-
intervals.pop(i+1)
2+
def increasingTriplet(self, nums: List[int]) -> bool:
3+
idx = 0
4+
lenz = len(nums)
5+
temp = temp2 = float('inf')
6+
count = 0
7+
for idx in range(lenz):
8+
if nums[idx] <= temp:
9+
temp = nums[idx]
10+
elif nums[idx] <= temp2:
11+
temp2 = nums[idx]
12+
13+
1114
else:
12-
i += 1
13-
return intervals
15+
return True
16+
17+
return False

Daily-challenge/Dec/19/README.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,53 @@
1-
# Decode String
2-
Given an encoded string, return its decoded string.
1+
# Cherry Pickup II
2+
Given a rows x cols matrix grid representing a field of cherries. Each cell in grid represents the number of cherries that you can collect.
33

4-
The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.
4+
You have two robots that can collect cherries for you, Robot #1 is located at the top-left corner (0,0) , and Robot #2 is located at the top-right corner (0, cols-1) of the grid.
55

6-
You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc.
7-
8-
Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, k. For example, there won't be input like 3a or 2[4].
6+
Return the maximum number of cherries collection using both robots by following the rules below:
97

8+
From a cell (i,j), robots can move to cell (i+1, j-1) , (i+1, j) or (i+1, j+1).
9+
When any robot is passing through a cell, It picks it up all cherries, and the cell becomes an empty cell (0).
10+
When both robots stay on the same cell, only one of them takes the cherries.
11+
Both robots cannot move outside of the grid at any moment.
12+
Both robots should reach the bottom row in the grid.
1013

1114

1215
Example 1:
1316

14-
Input: s = "3[a]2[bc]"
15-
Output: "aaabcbc"
17+
18+
19+
Input: grid = [[3,1,1],[2,5,1],[1,5,5],[2,1,1]]
20+
Output: 24
21+
Explanation: Path of robot #1 and #2 are described in color green and blue respectively.
22+
Cherries taken by Robot #1, (3 + 2 + 5 + 2) = 12.
23+
Cherries taken by Robot #2, (1 + 5 + 5 + 1) = 12.
24+
Total of cherries: 12 + 12 = 24.
1625
Example 2:
1726

18-
Input: s = "3[a2[c]]"
19-
Output: "accaccacc"
27+
28+
29+
Input: grid = [[1,0,0,0,0,0,1],[2,0,0,0,0,3,0],[2,0,9,0,0,0,0],[0,3,0,5,4,0,0],[1,0,2,3,0,0,6]]
30+
Output: 28
31+
Explanation: Path of robot #1 and #2 are described in color green and blue respectively.
32+
Cherries taken by Robot #1, (1 + 9 + 5 + 2) = 17.
33+
Cherries taken by Robot #2, (1 + 3 + 4 + 3) = 11.
34+
Total of cherries: 17 + 11 = 28.
2035
Example 3:
2136

22-
Input: s = "2[abc]3[cd]ef"
23-
Output: "abcabccdcdcdef"
37+
Input: grid = [[1,0,0,3],[0,0,0,3],[0,0,3,3],[9,0,3,3]]
38+
Output: 22
2439
Example 4:
2540

26-
Input: s = "abc3[cd]xyz"
27-
Output: "abccdcdcdxyz"
41+
Input: grid = [[1,1],[1,1]]
42+
Output: 4
2843

2944

3045
Constraints:
3146

32-
1 <= s.length <= 30
33-
s consists of lowercase English letters, digits, and square brackets '[]'.
34-
s is guaranteed to be a valid input.
35-
All the integers in s are in the range [1, 300].<br>
47+
rows == grid.length
48+
cols == grid[i].length
49+
2 <= rows, cols <= 70
50+
0 <= grid[i][j] <= 100 <br>
3651

3752
## Idea
3853
Just do while loop and convert to decimal

0 commit comments

Comments
 (0)