A horticultural research campus tracks every climate-controlled panel on its greenhouse wall using a grid of catalog tags. The wall is arranged as an n x n grid, and by design it should carry every integer from 1 to n^2 exactly once: one catalog number per panel, no repeats, no gaps. A stamping-machine malfunction duplicated one catalog number onto two different panels and, as a result, skipped another number entirely so that no panel bears it. Given the n x n grid of catalog numbers, determine which number was stamped twice and which number was never stamped.
Print two space-separated integers: the catalog number that appears twice, followed by the catalog number that never appears.
Example 1
Input
2 1 3 2 2
Expected
2 4
Explanation
The 2x2 grid holds the values 1, 3, 2, 2. Among 1..4, the value 2 appears twice (both cells in row 2) and the value 4 never appears anywhere in the grid, so the duplicate is 2 and the missing value is 4.
Example 2
Input
3 9 1 7 8 9 2 3 4 6
Expected
9 5
Explanation
The 3x3 grid holds 9,1,7,8,9,2,3,4,6. Checking 1..9, every value except 5 appears, and 9 appears twice (once in row 1, once in row 2), so the duplicate is 9 and the missing value is 5.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →