Skip to content

Commit

Permalink
Merge pull request #25 from paxtonfitzpatrick/main
Browse files Browse the repository at this point in the history
added some "refining the problem" notes about short-circuit cases
  • Loading branch information
jeremymanning authored Jul 13, 2024
2 parents ec4d61d + 109be95 commit 7514376
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions problems/2751/paxtonfitzpatrick.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,17 @@

## Refining the problem, round 2 thoughts

- I'll add a "short-circuit" condition where we check whether all robots are moving in the same direction, and if so, return `healths` immediately
- There's another possible circumstance where we could short-circuit early -- if all robots moving leftward start out to the left of all robots that're moving rightward. But I'm not sure this is really worth implementing because we'd need to check this against a sorted `position` list, which would require at least an additional loop to run for all test cases, and would probably end up taking more time overall since I'm willing to bet this scenario appears once, if at all. So I'll forego this.

## Attempted solution(s)

```python
class Solution:
def survivedRobotsHealths(self, positions: List[int], healths: List[int], directions: str) -> List[int]:
if all(d == directions[0] for d in directions):
return healths

sorted_ixs = list(range(len(positions)))
sorted_ixs.sort(key=lambda i: positions[i])
right_movers_stack = []
Expand Down

0 comments on commit 7514376

Please sign in to comment.