Hackerrank – Weather Observation Station 4
I have always loved just killing some time on Hackerrank, doing some challenges. And today was no different, but what was funny about it was I got stumped by one of the stupidest and simplest things under the sun. I really believe in software we should always look for the simplest answer, but in my case I couldn’t for the love of me come up with the simplest answer which is:

SELECT COUNT(CITY) - COUNT (DISTINCT City)
FROM STATION ;

However what came out was a rather convoluted attempt: why do we try do something complex when the answer is actually so simple at the end of the day:

SELECT	
	a.cities - a.uniqueCities
FROM (
    SELECT
	count(city) as cities, 
	count(distinct city) as uniqueCities 
    FROM
	station
) a;

looking at some of the answers the where submitted afterwards there where a few interesting ones:

select abs(count(CITY)-count(distinct CITY)) from STATION;

SELECT ((SELECT COUNT(CITY) FROM STATION) - (SELECT COUNT(DISTINCT CITY) FROM STATION)) FROM STATION WHERE ROWNUM=1;

At the end of the Day I suppose we all have days where we take something so simple, but then over complicate it.

I guess we have learnt something just by trying

Leave a Reply

You must be logged in to post a comment.