Remove Smallest Element for Sum Divisible by 7
EasyP3Coding
Remove exactly one element from nums. You want the sum of the remaining elements to be divisible by 7.
Among the elements whose removal gives such a sum, choose the one with the smallest value and return its index. If several equal values qualify, return the smallest index. If no element works, return -1.
Example 1
- Input
- nums = [3,4,5]
- Output
- 2
Example 2
- Input
- nums = [7,14,21]
- Output
- 0
Example 3
- Input
- nums = [1,2,3]
- Output
- -1
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.