In this HackerRank Weather Observation Station 18 problem solution 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 P1 and P2 and round it to a scale of 4 decimal places.
Input Format
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western longitude.
Problem solution MS SQL.
/* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ select convert(decimal(10,4), abs(max(lat_n) - max(long_w)) + abs(min(lat_n) - min(long_w))) from station;
Problem solution in Oracle.
select to_char(abs(min(lat_n) - min(long_w)) + abs( max(lat_n) - max( long_w) ),99999999.9999) from station ;
Problem solution in DB2.
/* Enter your query here and follow these instructions: 1. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. 2. The AS keyword causes errors, so follow this convention: "Select t.Field From table1 t" instead of "select t.Field From table1 AS t" 3. Type your code immediately after comment. Don't leave any blank line. */ select cast(round(ABS(min(lat_n) - max(lat_n)) + ABS( min(long_w)- max(long_w)), 4) as numeric(12,4)) from station;
0 Comments