Problem Statement
A description of the problem can be found on Hackerrank.
Solution
2 queries:
One that selects cities
that are ordered by city length
ascending and printed first row containing city
and its length
.
Second is almost the same as first but cities
are ordered descending.
In both queries I used second ordering by name alphabetically ascending because of condition ‘if there are more than one possible cities print the lexicographical smallest.’
I created solution in:
All solutions are also available on my GitHub.
SQL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
select * from ( select city, length(city) from station order by length(city) asc, city asc ) where rownum = 1 union select * from ( select city, length(city) from station order by length(city) desc, city asc ) where rownum = 1; |