அல்கோரிதம்greedy

Greedy — உள்ளூர் தேர்வு

TT
Testlaa Team
May 14, 20261 min read

Local best — proof / counterexample.

Try this in Python

tasks = [(1, 3), (2, 5), (4, 6)]  # (start, end)
tasks.sort(key=lambda x: x[1])
count = 0
end = -1
for s, e in tasks:
    if s >= end:
        count += 1
        end = e
print(count)

Key takeaways

  • Exchange proof template.
  • Sanity brute.
  • Sort key justify.

Tags:

GreedyPythonமாணவர்கள்