I am trying to write program that print maximal points of the input but it is not giving correct output.
Definition of maximal-
Given a set of points P = {p1,p2,...,pn} in 2-space, each represented by its x and y integer coordinates, output the set of the maximal points of P, that is, those points pi, such that pi is not dominated by any other point of P (not both coordinate are dominated)
Example input:
p1(5,7),p2(47,84),p3(89,4),(46,54),(100,1)
Example outut:
p2(47,84),(89,4),(100,1)
The idea of my program is to first sort the point according to x axis then compare the y coordinate.
a=[[5,7],[47,84],[89,4][46,54],[100,1]]
#sort according to x axis
mylist.sort(key=lambda x: x[0])
#compare y coordinate of i to all element right to i
for i in reversed(range(len(a)):
j=i+1
while (j<len(a)):
if(mylist[i][1]>mylist[j][1]):
j+=1
if(j==len(a)):
print(mylist[i])