Got asked this question, how do you solve?
Anonymous User
531

I really didn't understand what exactly it was asking and I struggled to get a solution.

# We define a 2D point P(x,y) is a dominant if you cannot find another point P'(x', y') which satisfies (x'<=x && y' < y || x' < x && y' <= y).

# Your task is to find out the dominants in the graph. The graph will be empty at the beginning. We will give a list of points and add a point to the graph sequentially. Output the number of dominants after adding every point to the graph. For more details, please check the example #0.

# Constraints:
# The number of Points N: 0 < N < 100000
# 0 < x, y < 10^9

# Example #0:
# Input:
# [(11, 20), (20, 10), (20, 10), (100, 20), (1, 1)]
# Output:
# [1, 2, 3, 3, 1]


# Notes:
# We first add (11,20) to the graph --> Dominant [(11,20)], -> 1
# (20, 10) --> Dominants [(11, 20), (20, 10)] -> 2
# (20, 10) --> Dominants [(11, 20), (20, 10), (20, 10)] -> 3 
# (100, 20) --> Dominants [(11, 20), (20, 10), (20, 10)] since (100,20) is dominated by  (11, 20) and (20, 10). Hence (100, 20) is not a dominating point.  -> 3 
# (1, 1) --> Dominant [(1, 1)]. Since other points are dominated by (1, 1) in the graph  -> 1
  
# Example #1:
# Input:
# [(100, 200)]
# Output:
# [1]

# Example #2:
# Input: 
# [(100, 200), (101, 202)]
# Output:
# [1, 1]

# Example #3:
# Input: 
# [(100, 200), (200, 100)]
# Output:
# [1, 2]
Comments (1)