Sharing the SIG CodeSignal I just did — same as usual, 70 minutes, 4 questions. Overall not hard, didn't need much in the way of algorithms, but there was a decent amount of code to write, and within the limited time you had to get all the little details right. Not sure if the questions are fixed — I know people who got different questions, so it might not be for the same position.
The first two questions were easy, solved in a bit over ten minutes.
Question 3 gives a matrix and asks you to rotate it clockwise turns (1<=turns<=4) times. Rotation rule: the numbers on the two diagonals stay fixed, and the four regions split off by the diagonals rotate. For example:
1
2
3
4
5
2
1
9
6
3
7 0
4
8 1
5
2
4
1
9
6
4 3 2
1
becomes
1
5 7 2
5
4
1
0
6
2
3 4
4
9
3
2
2
8
1
4
6
9 1 3
1
You can just simulate it directly, no special algorithm needed. I handled it triangle by triangle — for each of the four triangles, I stored the values from outside to inside into a vector, then filled them into the next triangle. There's probably a cleaner way to do it, but I didn't have time to think it through carefully, and since there were only four of them, I just brute-forced it. The row/column variables for storing and writing were easy to mix up while coding; otherwise there was nothing especially hard about it.
Question 4 gives a stream of operations and a diff value. Each operation either adds a number ("+x", where x is a number) or removes all copies of a number ("-x"). After each operation you output how many tuples satisfy the condition: for a tuple x, y, z, x-y == y-z == diff. Also no special algorithm needed. I kept a count of how many times each number appears, and for each operation's number I calculated how many new tuples it could produce, then added or subtracted that count.
This was the third time I've done a CodeSignal, and I finally got a perfect score — really happy about it.
Discussion
Loading comments…