Great job, it’s clean and straightforward. Two quick tweaks will make it more resilient and streamlined.
- Replace repeated sums with a simple bitmask check.
I didn’t see anyone mention bitmasking yet. Instead of summing and relying on magic numbers, use a bitmask per row/column/box:
You catch duplicates directly — it avoids false positives like “all 5’s” which add up to 45 but don’t make a valid set. This approach gives clear intent, simpler logic, and it runs in a fixed number of checks.int bit = 1 << value; if ((mask[r] & bit) != 0) return false; mask[r] |= bit;
int bit = 1 << value;
if ((mask[r] & bit) != 0) return false;
mask[r] |= bit;
You catch duplicates directly — it avoids false positives like “all 5’s” which add up to 45 but don’t make a valid set. This approach gives clear intent, simpler logic, and it runs in a fixed number of checks.
- Move from static shared state to local variables.
There are multiple static fields (rSum
rSum, cSumcSum, arraysarrays) that clutter mainmainand act as global state. Instead, use method-local variables and return results or throw when invalid. That keeps state contained, makes your code modular, and avoids unintended side-effects.