Challenge: Points on a Rectangle
Scor cont: 30.0 / 30
Submission status: Accepted
Submission score: 1.0
Submission ID: 464726651
Limbaj: python3
Link challenge: https://www.hackerrank.com/challenges/points-on-rectangle/problem
Cerinta
You are given $q$ queries where each query consists of a set of $n$ points on a two-dimensional plane (i.e., $(x, y)$). For each set of points, print `YES` on a new line if all the points fall on the edges (i.e., sides and/or corners) of a [non-degenerate rectangle](https://en.wikipedia.org/wiki/Degeneracy_(mathematics)#Rectangle) which is axis parallel; otherwise, print `NO` instead.
Input Format
The first line contains a single positive integer, $q$, denoting the number of queries. The subsequent lines describe each query in the following format:
1. The first line contains a single positive integer, $n$, denoting the number of points in the query.
2. Each line $i$ of the $n$ subsequent lines contains two space-separated integers describing the respective values of $x_i$ and $y_i$ for the point at coordinate $(x_i, y_i)$.
Output Format
For each query, print `YES` on a new line if all $n$ points lie on the edges of some non-degenerate rectangle which is axis parallel; otherwise, print `NO` instead.
Constraints
- $1 \le q \le 10$
- $1 \le n \le 10$
- $-10^4 \le x, y \le 10^4$
Cod sursa
#!/bin/python3
import math
import os
import random
import re
import sys
def solve(coordinates):
d = dict(coordinates)
y = d.values()
x = d.keys()
min_x = min(x)
max_x = max(x)
min_y = min(y)
max_y = max(y)
ret = "YES"
for el in coordinates:
if (el[0] > min_x) & (el[0] < max_x) & (el[1] > min_y) & (el[1] < max_y):
ret = "NO"
break
return ret
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
q = int(input().strip())
for q_itr in range(q):
n = int(input().strip())
coordinates = []
for _ in range(n):
coordinates.append(list(map(int, input().rstrip().split())))
result = solve(coordinates)
fptr.write(result + '\n')
fptr.close()
HackerRank Geometry – Points on a Rectangle
