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:

1
2
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:

1
2
3
4
5
6
7
8
9
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.