Greedy techniques Flashcards

(5 cards)

1
Q

What is the pattern and when is it used in Greedy Techniques?

A

Makes locally optimal choices for global solution.
Use Case: Scheduling, minimum operations.
Example: [No LeetCode match, course example: Jump Game].

Action: Verbalize use case aloud.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the key steps in Greedy Techniques?

A
  1. Identify optimal choice at each step.
  2. Apply choice, update state.
  3. Repeat until solution reached.

Action: Explain steps for Jump Game aloud.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does Greedy Techniques apply to Jump Game?

A

Determine if end reachable in array jumps.
Approach: Track max reachable index, greedily update.

Example: Jump Game. Action: Verbalize solution logic aloud.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the complexity and gotchas in Greedy Techniques?

A

Time: O(n), Space: O(1).
Gotchas: Non-greedy problems, invalid assumptions.

Action: List edge cases for Jump Game aloud.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Provide a visual or code example for Greedy Techniques.

A

```python
from typing import List
def can_jump(nums: List[int]) -> bool:
max_reach = 0
for i in range(len(nums)):
if i > max_reach:
return False
max_reach = max(max_reach, i + nums[i])
if max_reach >= len(nums) - 1:
return True
return True
~~~

Action: Sketch jump path on paper.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly