Skip to content

Bug Report for car-fleet #4058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
evanpasko opened this issue Apr 18, 2025 · 1 comment
Open

Bug Report for car-fleet #4058

evanpasko opened this issue Apr 18, 2025 · 1 comment

Comments

@evanpasko
Copy link

Bug Report for https://neetcode.io/problems/car-fleet

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

There are test cases that this solution doesn't account for. When tested, the posted car fleets solution fails. I used leetcode to check the solution, and I've posted the results as a screenshot here:

Image

The problem formulations are identical, so they should in theory pass all test cases.

@evanpasko
Copy link
Author

Upon further review, it seems like the distance calculation needs to be casted to a float in order to achieve accuracy for more "neck-and-neck" cars, as the test case shown above represents.

The solution just needs to be updated to:
stack.append(float(target - p) / s)
instead of
stack.append((target - p) / s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant