View rotation.py
This file contains 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
class Rotation: | |
@staticmethod | |
def is_substring(s1, s2): | |
"""Checks if s2 is a substring of s1 | |
Args: | |
s1 (string) string input | |
s2 (string) rotation of s1 |
View zero_matrix.py
This file contains 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
class Matrix: | |
@staticmethod | |
def zero(M, m, n): | |
"""Zeroes out the whole row and column if one elements is found to be zero. | |
Args: | |
M (array) of m rows and n columns | |
m (int) of rows | |
n (int) of columns |
View matrix_rotate.py
This file contains 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
class Matrix: | |
@staticmethod | |
def rotate(m, n): | |
"""Rotates a matrix m of n x n size""" | |
# reverse each row of the matrix | |
for i in range(n): | |
m[i] = m[i][::-1] |
View sample_crypto_aes.js
This file contains 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
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/core-min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/sha256.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/enc-base64.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script> | |
<script> | |
function toWordArray(str){ | |
return CryptoJS.enc.Utf8.parse(str); | |
} | |
function toString(words){ |
View compressed_string.py
This file contains 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
""" | |
String Compression: Implement a method to perform basic string | |
compression using the counts of repeated characters. For example, | |
the string aabcccccaaa would become a2blc5a3. If the "compressed" | |
string would not become smaller than the original string, your | |
method should return the original string. You can assume the | |
string has only uppercase and lowercase letters (a -z). | |
""" | |
def compress(inputstr): | |
if len(inputstr) == 0: |
View hired.py
This file contains 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 main(msg): | |
convert = map(chr, msg) | |
print("".join(list(convert))) | |
if __name__ == '__main__': | |
msg = [76, 101, 116, 116, 104, 101, 98, 101, 115, 116, 115, 116, 97, 114, 116,117, 112, 115, 97, 112, 112, 108, 121, 116, 111, 121, 111, 117, 0] | |
main(msg) |
View love_rectangles.py
This file contains 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 find_overlap(r1, r2, axis, result): | |
if axis is 'x': | |
start = 'x' | |
distance = 'width' | |
elif axis is 'y': | |
start = 'y' | |
distance = 'height' | |
p1 = r1[start] |
View even_elements.py
This file contains 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 even_elements(l): | |
""" | |
Given a list, this function returns a new list | |
with the with items found in the even indexes only | |
""" | |
if len(l) == 0: | |
return l |
View find_mode.py
This file contains 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 find_mode(l): | |
if len(l) == 0: | |
return "ZeroLength" | |
l.sort() | |
sums = {} |
View next_bigger.py
This file contains 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 next_bigger(l): | |
""" | |
This function returns a modified list | |
by appending a new element that is | |
bigger than the max element of the list | |
l = [], returns l[0] |
NewerOlder