0
There is an N x N
square of numbers.
- All columns increase strictly monotonically from top to down
- All rows increase strictly monotonically from left to right
- There is exactly one valid answer for each input.
You are given 2N-1
rows of N
numbers representing rows or columns in this square. The task is to find the row that isn't in the input.
Your Task
Write a program or function that outputs the row or column that isn't in the input.
Input
First, you get the number N
.
Then follow 2N-1
lines of N
space-separated numbers, representing rows or columns of this N x N
square. The lines are given in left-to-right or top-down order. There may be multiple equal lines. It is ok to omit the initial N
from the input, or modify the input format as you like.
3
1 2 3
2 3 5
3 5 6
2 3 4
1 2 3
Output
Your program or function should output a single line of N
numbers; the row or column from the square that was not present in the input. You may change the output format as you please.
3 4 6
This would correspond to one of two squares:
1 2 3 1 2 3
2 3 4 2 3 5
3 5 6 3 4 6
Either way, the output is the same.
Bonus
Your solution should be able to calculate 2 ≤ N ≤ 10
within a minute on a normal computer. If your solution handles the big input, 2 ≤ N ≤ 50
, within a minute, you get -10%
byte count.
Test cases
2
22 222
2 22
22 222
-> 2 22
3
1 2 3
2 3 5
3 5 6
2 3 4
1 2 3
-> 3 4 6
4
11 14 16 22
3 6 9 11
6 7 11 14
9 11 15 19
10 11 19 22
6 7 10 11
3 6 8 10
-> 8 10 15 16
Note that you can simply change what line in these inputs that is omitted, and reorder them in any way you want, to generate new test cases.
This is a simplified version of Google Code Jam 2016 round 1A problem B: Rank and File. The original Google Code Jam problem, where you can get more test cases (but without answers), is available here: https://code.google.com/codejam/contest/4304486/dashboard#s=p1
You should make the N input optional - many languages would just read and discard/ignore it because it can be inferred from the rows. – Mego – 2016-04-23T01:28:40.920
Changed it to allow omitting
N
from input. – Filip Haglund – 2016-04-23T01:30:06.5473
More generally, I think you should adapt your I/O format to be more flexible by letting languages do input and output in their native list types. See Things to avoid when writing challenges.
– xnor – 2016-04-23T01:30:30.473I/O rules further loosened :) – Filip Haglund – 2016-04-23T01:42:27.633
Removed bad testcase. It should follow the original as close as possible, but with a simpler problem statement and only a single testcase per run. – Filip Haglund – 2016-04-23T02:05:26.867
If there's a bonus for test cases of a certain size, you should include such a test case in the question body. – Dennis – 2016-04-23T04:11:06.933
1
This strikes me as a chameleon challenge. Once you solve the puzzle, you find that it's really about cancelling duplicates.
– xnor – 2016-04-23T04:13:41.0071
We also discourage bonuses in code golf
– Alex A. – 2016-04-23T05:38:08.217After reading the answers, I realize this was indeed an accidental chameleon challenge. I did not know about the simple solution, and that's not how I solved it myself. I tried to simplify the description as far as I could. – Filip Haglund – 2016-04-23T10:19:51.467