Sometimes, while in competitive programming, we might be facing a problem which is of geometry domain and works with x-y coordinate system. The list of tuple can be used to store the same. And along with this, there might be a problem in which we need point with max value of x axis with similar y axis i.e farthest point on horizontal lines. Let’s discuss certain ways to discuss this problem.
Method : Using list comprehension +
This is a generic brute force method applied to get the max x axis point for common y axis, made as 1 liner using list comprehension. The
max() is used to find the max of x axis element.
The original list is : [(1, 6), (4, 6), (2, 6), (6, 8), (1, 8), (2, 9)] The list after filtering just maximum points on lines : [(4, 6), (6, 8), (2, 9)]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course