Skip to content

Commit 1d6784f

Browse files
committed
back at it
1 parent 70716f7 commit 1d6784f

File tree

4 files changed

+111
-2
lines changed

4 files changed

+111
-2
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from typing import List
2+
3+
4+
# leetcode submit region begin(Prohibit modification and deletion)
5+
class Solution:
6+
def maxTaskAssign(self, tasks: List[int], workers: List[int], pills: int, strength: int) -> int:
7+
8+
N = len(tasks)
9+
M = len(workers)
10+
left = 0
11+
right = N + 1
12+
ans = 0
13+
tasks.sort()
14+
workers.sort()
15+
INF = 10 ** 20
16+
17+
def go(i, j, target):
18+
if i == target:
19+
return 0, 0
20+
if j == M:
21+
return INF, 0
22+
23+
if workers[j] >= tasks[i]:
24+
used, completed = go(i + 1, j + 1, target)
25+
return used, completed + 1
26+
else:
27+
if workers[j] + strength >= tasks[i]:
28+
used_taking, completed_taking = go(i + 1, j + 1, target)
29+
used_taking += 1
30+
completed_taking += 1
31+
used_skipping, completed_skipping = go(i, j + 1, target)
32+
used_ignoring, completed_ignoring = go(i + 1, j, target)
33+
options = [(used_taking, -completed_taking), (used_skipping, -completed_skipping),
34+
(used_ignoring, -completed_ignoring)]
35+
options.sort()
36+
ans_here = options[0]
37+
return ans_here[0], abs(ans_here[1])
38+
39+
return INF
40+
41+
def good(target):
42+
min_pills = go(0, 0, target)
43+
return min_pills < pills
44+
45+
while left < right:
46+
mid = (left + right) // 2
47+
if good(mid):
48+
ans = mid
49+
left = mid + 1
50+
else:
51+
right = mid
52+
return ans
53+
54+
55+
# leetcode submit region end(Prohibit modification and deletion)
56+
57+
58+
class MaximumNumberOfTasksYouCanAssign(Solution):
59+
pass
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# leetcode submit region begin(Prohibit modification and deletion)
2+
class Solution:
3+
def countSymmetricIntegers(self, low: int, high: int) -> int:
4+
dp = [0] * len(str(high))
5+
6+
7+
# leetcode submit region end(Prohibit modification and deletion)
8+
9+
10+
class CountSymmetricIntegers(Solution):
11+
pass
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# leetcode submit region begin(Prohibit modification and deletion)
2+
3+
class Solution:
4+
def answerString(self, word: str, num_friends: int) -> str:
5+
n = len(word)
6+
if num_friends > n:
7+
return ""
8+
if num_friends == 1:
9+
return word
10+
11+
highest_char = max(word) # the best single letter we can start with
12+
best = ""
13+
14+
for i, ch in enumerate(word):
15+
if ch != highest_char:
16+
continue
17+
18+
remaining = num_friends - (i + 1) # friends still waiting to cut
19+
20+
if remaining <= 0:
21+
# everyone has already “cut” in or before this position,
22+
# so we can keep the whole suffix
23+
candidate = word[i:]
24+
else:
25+
# leave at least `remaining` letters after our slice
26+
# end index is exclusive, so this is safe
27+
candidate = word[i:n - remaining]
28+
29+
best = max(best, candidate)
30+
31+
return best
32+
33+
34+
# leetcode submit region end(Prohibit modification and deletion)
35+
36+
37+
class FindTheLexicographicallyLargestStringFromTheBoxI(Solution):
38+
pass

main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from leetcode.editor.en.Q416.PartitionEqualSubsetSum import PartitionEqualSubsetSum
1+
from leetcode.editor.en.Q3403.FindTheLexicographicallyLargestStringFromTheBoxI import \
2+
FindTheLexicographicallyLargestStringFromTheBoxI
23

34
if __name__ == '__main__':
4-
print(PartitionEqualSubsetSum().canPartition([1, 5, 11, 5]))
5+
print(FindTheLexicographicallyLargestStringFromTheBoxI().answerString("gggg", 4))

0 commit comments

Comments
 (0)