This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cyclic_paths = [] | |
def _transform_to_upper(road_map: dict): | |
road_map_upper = {} | |
for key in road_map.keys(): | |
road_map_upper[key.upper()] = [subKey.upper() for subKey in road_map[key]] | |
return road_map_upper | |
def _validate(road_map: dict, start: str): | |
# Validate map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def transform_to_lower(road_map): | |
'''Helper function to transform map to lower case''' | |
road_map_lower_cased = {} | |
for key in road_map.keys(): | |
road_map_lower_cased[key.lower()] = [subKey.lower() for subKey in road_map[key]] | |
return road_map_lower_cased | |
def pop(previous_points): | |
'''Helper function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num_alpha_map = { | |
2: ['a', 'b', 'c'], | |
3: ['d', 'e', 'f'], | |
4: ['g', 'h', 'i'], | |
5: ['j', 'k', 'l'], | |
6: ['m', 'n', 'o'], | |
7: ['p', 'q', 'r', 's'], | |
8: ['t', 'u', 'v'], | |
9: ['w', 'x', 'y', 'z'], | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import timedelta | |
def convert_to_minutes(time): | |
hours, minutes = time.split(':') | |
return timedelta(hours=int(hours), minutes=int(minutes)).seconds // 60 | |
def get_min_diff(times): | |
min_diff = None | |
for idx, _ in enumerate(times): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Required function | |
def shuffle_class(pupils, pupils_to_move): | |
if pupils == None or type(pupils) != list or len(pupils) == 0 or type(pupils_to_move) != int: | |
return [] | |
# For this solution's approach, normally, we would just take the absolute value of the pupils to move, | |
# but we also take the modulus, just in case, to avoid index out of range edge case, and also avoid round trips | |
to_move = abs(pupils_to_move) % len(pupils) | |
if pupils_to_move == 0 or to_move == 0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Required function | |
def merge_class_ages(class_a, class_b): | |
if (class_a == None and class_b == None) or (type(class_a) != list and type(class_b) != list): | |
return [] | |
if class_a == None and type(class_b) == list: | |
return class_b | |
if type(class_a) == list and class_b == None: | |
return class_a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import reduce | |
def get_products(nums): | |
products = [] | |
if nums == None or len(nums) == 0 or len(nums) == 1: | |
return products | |
for i, el in enumerate(nums): | |
nums_to_multiply = nums[:i] + nums[i+1:] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def binary_search(sorted_nums, val, minimum, maximum): | |
if maximum < minimum: | |
return -1 | |
mid = minimum + ((maximum - minimum) // 2) | |
if val == sorted_nums[mid]: | |
return mid | |
elif val < sorted_nums[mid]: | |
return binary_search(sorted_nums, val, minimum, mid - 1) |