관리 메뉴

오늘도 배운다

Weather Observation Station 18 / HackerRank, SQL, MySQL 본문

코딩테스트연습(SQL)

Weather Observation Station 18 / HackerRank, SQL, MySQL

LearnerToRunner 2022. 12. 26. 00:45

문제

Consider P1(a,b) and P2(c, d)  to be two points on a 2D plane.

'a' happens to equal the minimum value in Northern Latitude (LAT_N in STATION).
'b' happens to equal the minimum value in Western Longitude (LONG_W in STATION).
'c' happens to equal the maximum value in Northern Latitude (LAT_N in STATION).
'd' happens to equal the maximum value in Western Longitude (LONG_W in STATION).

Query the Manhattan Distance between points  and  and round it to a scale of  decimal places.

 

제출답안(MySQL)

-- Manhattan Distance = |x1-x2| + |y1-y2|
SELECT ROUND(ABS(MIN(lat_n)-MAX(lat_n)) + ABS(MIN(long_w)-MAX(long_w)), 4)
FROM station

 

 

문제 바로가기(MySQL) 

 

728x90
Comments