Skip to content
Discussion options

You must be logged in to vote

We need to find the maximum MEX (minimum excluded non-negative integer) of an array after performing any number of operations where we can add or subtract a given value from any element. The key insight is that each element can be transformed to any non-negative integer that shares the same remainder when divided by the given value.

Approach

  1. Modular Arithmetic: Each element in the array can be transformed into any non-negative integer that has the same remainder modulo the given value. This means that for each remainder class, we can generate a sequence of non-negative integers (e.g., r, r + value, r + 2*value, etc.).
  2. Frequency Count: We count how many elements fall into each remainder c…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Oct 16, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Oct 16, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants