Google | Phone Screen | Number Of Corner Squares
Anonymous User
3800

Write a function that accepts a node as input, which is the upper-left hand corner of zero or more squares and returns the number of squares that can be made from that particular upper-left corner.

class Node {
  int x, y; // coords
  Node up, down, left, right; // references to other connected nodes
}

Example:

Input:
Top-left node:
x=0, y=10
down={reference to node where x=0, y=8}
right={reference to node where x=2, y=10}
up=null
left=null

         2      5      8    10
10	+----+------+------+----+
	|    |      |      |    |
8	+----+------+      |    |
	|    |      |      +----+
6	+----+      |      |    |
	|    +------+------+----+
	|    |             |    |
	|    |             |    |
2	+----+------+------+    |
	|           |           |
0	+-----------+-----------+
                5           10

Output: 3
Explanation: There are 3 squares with top left corner (0, 10):
1: (0, 10) (2, 8)
2: (0, 10) (8, 2) 
3: (0, 10) (10, 10)

Comments (11)