Skip to content

Instantly share code, notes, and snippets.

View wpjerrykwok's full-sized avatar
🐻

WP Jerry Kwok wpjerrykwok

🐻
View GitHub Profile
@wpjerrykwok
wpjerrykwok / hackerRank-SQL-basic-join.sql
Last active May 2, 2024 23:22
HackerRank - SQL - Basic Join
/* Ollivander's Inventory */
SELECT w2.id, t.age, t.price, t.power
FROM Wands AS w2
JOIN Wands_Property AS p2 ON w2.code = p2.code
INNER JOIN (
SELECT p.age AS age, MIN(w1.coins_needed) AS price, w1.power AS power
FROM Wands AS w1
JOIN Wands_Property AS p ON w1.code = p.code
WHERE p.is_evil = 0
GROUP BY p.age, w1.power
@wpjerrykwok
wpjerrykwok / hackerRank-SQL-aggregation.sql
Last active May 1, 2024 14:06
HackerRank - SQL - Aggregation
/* Weather Observation Station 20 */
SELECT ROUND(AVG(t.LAT_N), 4)
FROM (
SELECT
LAT_N
, ROW_NUMBER() OVER (ORDER BY LAT_N ASC, ID ASC) AS row_num_asc
, ROW_NUMBER() OVER (ORDER BY LAT_N DESC, ID DESC) AS row_num_desc
FROM STATION) AS t
WHERE
t.row_num_asc IN (t.row_num_desc-1, t.row_num_desc, t.row_num_desc+1)
@wpjerrykwok
wpjerrykwok / hackerRank-SQL-advanced-select.sql
Last active May 1, 2024 00:11
HackerRank - SQL - Advanced Select
/* New Companies */
SELECT
c.company_code
, c.founder
, COUNT(DISTINCT l.lead_manager_code)
, COUNT(DISTINCT s.senior_manager_code)
, COUNT(DISTINCT m.manager_code)
, COUNT(DISTINCT e.employee_code)
FROM Company AS c
LEFT JOIN Lead_Manager AS l ON c.company_code = l.company_code
@wpjerrykwok
wpjerrykwok / hackerRank-SQL-basic-select.sql
Last active April 29, 2024 14:05
HackerRank - SQL - Basic Select
/* Employee Salaries */
SELECT name FROM Employee WHERE months < 10 AND salary > 2000 ORDER BY employee_id ASC
/* Employee Names */
SELECT name FROM Employee ORDER BY name
/* Higher Than 75 Marks */
SELECT Name FROM STUDENTS WHERE Marks > 75 ORDER BY RIGHT(Name, 3), ID
/* Weather Observation Station 12 */
@wpjerrykwok
wpjerrykwok / leetCode-Top-Interview-150-array-169-Majority-Element.py
Created April 25, 2024 13:20
LeetCode - Top Interview 150 - Array - 169. Majority Element
class Solution:
def majorityElement(self, nums: List[int]) -> int:
result = {}
for num in nums:
if num not in result.keys():
result[num] = 1
else:
result[num] += 1
for k in result:
if result[k] > len(nums)/2:
@wpjerrykwok
wpjerrykwok / hackerRank-algorithms-the-Time-in-words.py
Created April 24, 2024 18:34
HackerRank - Algorithms - The Time in Words
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'timeInWords' function below.
@wpjerrykwok
wpjerrykwok / stratascratch_10368_population_density.py
Created April 23, 2024 15:39
StrataScratch 10368 Population Density
# Import your libraries
import pandas as pd
# Start writing code
cities_population.head()
# remove row with non-positive area
cities_population = cities_population[cities_population['area'] > 0]
# calculate population density
@wpjerrykwok
wpjerrykwok / git-notes.md
Last active January 3, 2024 22:13
Git notes

copy repo from GitHub git clone <URL>

stage the file git add.

check file status git status

commit the file