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.
Week testcase allowing false pass an edge case.
when using float for storing time to reach the target, in following testcase fails but solution is still AC due to lack of testcase. changing float to double corrects the solution.
testcase:
target=1000000
position=[2,1]
speed=[999999,1000000]
code (with float)
class Solution {
public:
int carFleet(int target, vector<int>& position, vector<int>& speed) {
vector <pair<int,float>> ti;
for(int i = 0; i < position.size();i++){
ti.push_back({position[i],(target-position[i])/(speed[i]*1.0)});
}
sort(ti.rbegin(),ti.rend());
int ans = 1;
float curr = ti[0].second;
for(int i = 1; i < position.size(); i++){
if(ti[i].second > curr){
ans++;
curr = ti[i].second;
}
}
return ans;
}
};
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.
Week testcase allowing false pass an edge case.
when using float for storing time to reach the target, in following testcase fails but solution is still AC due to lack of testcase. changing float to double corrects the solution.
testcase:
target=1000000
position=[2,1]
speed=[999999,1000000]
code (with float)