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
import unittest | |
import time | |
from copy import deepcopy | |
# O (N) | |
def string_rotation_algo(s1: str, s2: str) -> bool: | |
s1 = sorted(s1); | |
s2 = sorted(s2); | |
return True if s1 == s2 else False |
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
import unittest | |
import time | |
from copy import deepcopy | |
# O (MXN) | |
def zero_matrix_algo(matrix): | |
new_matrix = deepcopy(matrix) | |
for index_row, row in enumerate(matrix): |
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
import unittest | |
import time | |
from copy import deepcopy | |
# O (NxN) | |
def rotate_matrix_algo(matrix): | |
"""rotates a matrix 90 degrees clockwise""" | |
new_matrix = deepcopy(matrix) |
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
import unittest | |
import time | |
# O (N) | |
def string_compression_algo(main_word: str) -> str: | |
count = 0 | |
compressed = '' | |
last_char = main_word[0] if len(main_word) > 0 else '' | |
if last_char == '': |
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
import unittest | |
def one_way_pythonic(main_word: str, edited_work: str) -> bool: | |
diff = set(list(main_word)) - set(list(edited_work)) | |
return False if len(diff) > 1 else True | |
# O (N) | |
def one_way_algo(main_word: str, edited_work: str) -> bool: | |
count = 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
import unittest | |
def url_ify_pythonic(sentence: str) -> str: | |
return sentence.strip().replace(' ', '%20') | |
# O (N) | |
def url_ify_algo(sentence: str) -> str: | |
txt = '' | |
is_first_char = True |
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
import unittest | |
# O (N) | |
def check_permutation_using_sorted(word1: str, word2: str) -> bool: | |
word1, word2 = sorted(word1), sorted(word2) | |
if len(word1) > len(word2): | |
for i in range(0, len(word2)): | |
if word1[i] != word2[i]: | |
return False | |
return True |
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 collections import defaultdict | |
import time | |
from typing import List | |
import random | |
import unittest | |
def is_unique_char_using_dict(word: str) -> bool: | |
dict = {} | |
for char in word: | |
if char in dict: |
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
#!/bin/python3 | |
import math | |
import os | |
import random | |
import re | |
import sys | |
class SinglyLinkedListNode: | |
def __init__(self, node_data): |
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
#!/bin/python3 | |
import math | |
import os | |
import random | |
import re | |
import sys | |
class SinglyLinkedListNode: | |
def __init__(self, node_data): |
NewerOlder