Skip to content

Commit 8d2b05c

Browse files
committed
variable change
1 parent c11743e commit 8d2b05c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

scheduling/weighted_interval_scheduling.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
from __future__ import annotations
88

99

10-
def latest_non_conflict(jobs: list[tuple[int, int, int]], n: int) -> int:
10+
def latest_non_conflict(jobs: list[tuple[int, int, int]], indx: int) -> int:
1111
"""
1212
This function finds the latest job that does not conflict with
13-
the current job at index `n`.
13+
the current job at index `indx`.
1414
The jobs are given as (start_time, end_time, weight), and the
1515
jobs should be sorted by end time.
1616
It returns the index of the latest job that finishes before the
@@ -21,8 +21,8 @@ def latest_non_conflict(jobs: list[tuple[int, int, int]], n: int) -> int:
2121
>>> latest_non_conflict([(1, 3, 50), (3, 4, 60), (5, 9, 70)], 2)
2222
1
2323
"""
24-
for j in range(n - 1, -1, -1):
25-
if jobs[j][1] <= jobs[n][0]:
24+
for j in range(indx - 1, -1, -1):
25+
if jobs[j][1] <= jobs[indx][0]:
2626
return j
2727
return -1
2828

@@ -44,14 +44,14 @@ def find_max_weight(jobs: list[tuple[int, int, int]]) -> int:
4444
200
4545
"""
4646
# Sort jobs based on their end times
47-
jobs.sort(key=lambda x: x[1])
47+
jobs.sort(key=lambda ele : ele[1])
4848

4949
# Initialize dp array to store the maximum weight up to each job
50-
n = len(jobs)
51-
dp = [0] * n
50+
length = len(jobs)
51+
dp = [0] * length
5252
dp[0] = jobs[0][2] # The weight of the first job is the initial value
5353

54-
for i in range(1, n):
54+
for i in range(1, length):
5555
# Include the current job
5656
include_weight = jobs[i][2]
5757
latest_job = latest_non_conflict(jobs, i)

0 commit comments

Comments
 (0)