Question
Which practice avoids a common mistake with Sliding Window on Arrays?
- Ignore the Sliding Window on Arrays issue and rely on team discipline instead of APIs or contracts.
- Silence the Sliding Window on Arrays problem by using raw types, broad catches, or shared mutable state.
- Prefer the version of Sliding Window on Arrays that makes behavior less predictable as long as the code compiles.
- Do not use a fixed grow-only window when the constraint requires shrinking from the left to restore validity.
Hint
Look for the option that protects correctness instead of hiding the problem.
Answer and rationale
Correct answer: D. Do not use a fixed grow-only window when the constraint requires shrinking from the left to restore validity.
Do not use a fixed grow-only window when the constraint requires shrinking from the left to restore validity. This is a common failure mode in real Java code and a frequent interview follow-up.
Track: Java