21 January 2018

usersByContinent

My solution:
CREATE PROCEDURE usersByContinent() 
BEGIN 
  SELECT continent, 
         SUM(users) AS users 
  FROM   countries 
  GROUP  BY continent 
  ORDER  BY users DESC; 
END 

20 January 2018

itemCounts

My solution:
CREATE PROCEDURE itemCounts() 
BEGIN 
  SELECT item_name, 
         item_type, 
         COUNT(*) AS item_count 
  FROM   availableItems 
  GROUP  BY item_name, 
            item_type 
  ORDER  BY item_type, 
            item_name; 
END 

countriesInfo

My solution:
CREATE PROCEDURE countriesInfo() 
BEGIN 
  SELECT COUNT(*)        AS number, 
         AVG(population) AS average, 
         SUM(population) AS total 
  FROM   countries; 
END 

19 January 2018

testCheck

My solution:
CREATE PROCEDURE testCheck() 
  SELECT id, 
         IF (given_answer IS NULL, "no answer", CASE 
         WHEN given_answer = correct_answer THEN "correct" 
         ELSE "incorrect" END) AS checks
  FROM   answers 
  ORDER  BY id; 

newsSubscribers

My solution:
CREATE PROCEDURE newsSubscribers() 
  BEGIN 
    SELECT DISTINCT subscriber 
    FROM   full_year 
    WHERE  full_year.newspaper LIKE "%Daily%" 
    UNION 
    SELECT DISTINCT subscriber 
    FROM   half_year 
    WHERE  half_year.newspaper LIKE "%Daily%" 
    ORDER  BY subscriber ASC; 
  END 

15 August 2017

List Beautifier

My solution:
def listBeautifier(a):
    res = a[:]
    while res and res[0] != res[-1]:
       b, *res, c = res
    return res

Previous

Mex Function

My solution:
def mexFunction(s, upperBound):
    found = -1
    for i in range(upperBound):
        if not i in s:
            found = i
            break
    else:
        found = upperBound

    return found

Previous Next