Skip to content

Instantly share code, notes, and snippets.

View rjvitorino's full-sized avatar

Ricardo Vitorino rjvitorino

View GitHub Profile
@rjvitorino
rjvitorino / daily_temperatures.py
Created June 24, 2024 08:37
Cassidoo's interview question of the week: a function that takes an array of daily temperatures and returns an array where each element is the number of days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.
from typing import List
from typing import Tuple
def daily_temperatures(temperatures: List[int]) -> List[int]:
"""
Calculates, for each day, the number of days expected until a warmer temperature.
If there is no future day for which a temperature is warmer, a 0 is returned.
:param temperatures: List of daily temperatures.
:return: List where each element is the number of days to wait for a warmer temperature.
@rjvitorino
rjvitorino / unique_sum.py
Created June 19, 2024 09:12
Cassidy's interview question of the week (20240401 - April fools!): Given an array of numbers, add all of the values together but only if the number does not repeat a digit.
def has_unique_digits(number: int) -> bool:
"""
Check if the given number has all unique digits.
Args:
number (int): The number to check.
Returns:
bool: True if all digits are unique, False otherwise.
"""
@rjvitorino
rjvitorino / sort_vowels.py
Created June 17, 2024 09:30
Cassidoo's interview question of the week: a function that takes a list of names and returns the names sorted by the number of vowels in each name in descending order. If two names have the same number of vowels, sort them alphabetically.
from typing import List
def count_vowels(name: str) -> int:
"""Helper function to count the number of vowels in a name."""
vowels = "aeiouAEIOU"
return sum(1 for char in name if char in vowels)
def clean_names(names: List[str]) -> None:
"""Helper function to remove non-string elements from the list."""
@rjvitorino
rjvitorino / four_sum.py
Last active June 10, 2024 11:03
Cassidoo's interview question of the week: a function that takes an array of integers and a target sum, and returns all unique quadruplets [a, b, c, d] in the array such that a + b + c + d = target
from itertools import combinations
from typing import List
def four_sum(nums: List[int], target: int) -> List[List[int]]:
"""
Finds all unique quadruplets in the list that sum up to the target value.
Args:
nums (List[int]): The list of integers.
target (int): The target sum for the quadruplets.
@rjvitorino
rjvitorino / only_evens.py
Last active June 7, 2024 17:47
Cassidoo's interview question of the week: a function that takes an array of integers and returns a new array containing only the even numbers, and sorted.
from typing import List
def only_evens(numbers: List[int]) -> List[int]:
"""
Returns a sorted list of even numbers from the input list.
Args:
numbers (list of int): List of integers.
Returns:
list of int: Sorted list of even integers.
"""