
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Program to find out the vertical area between two points where no point lies and is the widest in Python
Suppose, we are given n number of points as (x, y). A vertical area is an area that is extended infinitely along the y-axis. We have to find out the vertical area between two points such that no other point is inside the area and is the widest.
So, if the input is like pts = [[10,9],[11,11],[9,6],[11,9]], then the output will be 1.
The areas in red and blue are optimal and there are no points inside them.
To solve this, we will follow these steps −
sort the list pts
for i in range 1 to size of pts, do
return the maximum value of (pts[i, 0] - pts[i - 1, 0])
Example
Let us see the following implementation to get better understanding
def solve(pts): pts.sort() return max(pts[i][0] - pts[i - 1][0] for i in range(1, len(pts))) print(solve([[10,9],[11,11],[9,6],[11,9]]))
Input
[[10,9],[11,11],[9,6],[11,9]]
Output
1
- Related Articles
- Program to find out is a point is reachable from the current position through given points in Python
- Program to find out the number of integral coordinates on a straight line between two points in Python
- Program to find out the length between two cities in shortcuts in Python
- Program to Find Out the Maximum Points From Removals in Python
- Program to Find Out the Points Achievable in a Contest in Python
- Python Program to find whether a no is the power of two
- Program to find out the maximum points collectable in a game in Python
- Program to Find the Shortest Distance Between Two Points in C++
- Program to find out the index in an array where the largest element is situated in Python
- Python Program to find whether a no is power of two
- Program to Find Out the Probability of Having n or Fewer Points in Python
- Program to find out the similarity between a string and its suffixes in python
- Program to form smallest number where no two adjacent digits are same in Python
- Program to find out the conversion rate of two currencies in Python
- Program to find out the path between two vertices in a graph that has the minimum penalty (Python)

Advertisements