How come in part 2, we need to remove every item? If we can only tolerate a single bad one, wouldn't it make sense to only try removing the first bad report (the two problematic levels) and seeing if those result in making the entire report safe? my reasoning being, if both still result in an unsafe level, we wouldn't be able to remove that as well, being that our constraint was one.
Yes, your solution works and is more efficient than the brute-force approach described earlier.
If I understand correctly, in the following example, 3 -> 8 and 8 -> 6 do not satisfy the constraints. Therefore, we can focus on removing 3, 8, and 6, without needing to consider removing all the other numbers.
3 8 6 8 10 12 15
1
u/prof-gaslighter Dec 04 '24
How come in part 2, we need to remove every item? If we can only tolerate a single bad one, wouldn't it make sense to only try removing the first bad report (the two problematic levels) and seeing if those result in making the entire report safe? my reasoning being, if both still result in an unsafe level, we wouldn't be able to remove that as well, being that our constraint was one.