Java: Which practice avoids a common mistake with Deque for Sliding Window Maximum?

Difficulty:

Medium

Questions:

1

Time Limit:

2 minutes

Passing Score:

100%

Question

Which practice avoids a common mistake with Deque for Sliding Window Maximum?

  1. Ignore the Deque for Sliding Window Maximum issue and rely on team discipline instead of APIs or contracts.
  2. Silence the Deque for Sliding Window Maximum problem by using raw types, broad catches, or shared mutable state.
  3. Do not forget to evict indices that fall out of the window before trusting the front element as the answer.
  4. Prefer the version of Deque for Sliding Window Maximum that makes behavior less predictable as long as the code compiles.

Hint

Look for the option that protects correctness instead of hiding the problem.

Answer and rationale

Correct answer: C. Do not forget to evict indices that fall out of the window before trusting the front element as the answer.

Do not forget to evict indices that fall out of the window before trusting the front element as the answer. This is a common failure mode in real Java code and a frequent interview follow-up.

Track: Java