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 namedtuple | |
TableEntry = namedtuple('Element', 'hash key value') | |
class HashTable(object): | |
DEFAULT_SIZE = 8 | |
EMPTY_VALUE = TableEntry(None, None, None) | |
DELETED_VALUE = TableEntry(None, None, None) | |
LOAD_FACTOR = 2 / 3 | |
MIN_FACTOR = 1 / 3 |
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
#my coderbyte solns, from mock skype interviews | |
def RunLength(string): | |
count =1 | |
ans = "" | |
for i in range(len(string)-1): | |
if string[i] == string[i+1]: | |
count +=1 | |
elif string[i] != string[i+1]: | |
ans += str(count) |
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
//Q1 | |
//Write a function 'transformFirstAndLast' that takes in an array, and returns an object with: | |
//1) the first element of the array as the object's key, and | |
//2) the last element of the array as that key's value. | |
function transformFirstAndLast(array) { | |
//your code here | |
var ans ={} | |
ans[array[0]]=array[array.length-1] | |
return ans |
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
// #52 | |
function getLengthOfThreeWords(word1, word2, word3) { | |
return word1.length+ word2.length+word3.length | |
} | |
//#53 | |
/* | |
Write a function called "joinArrays". | |
Given two arrays, "joinArrays" returns an array with the elements of "arr1" in order, | |
followed by the elementsin "arr2". |
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
// #2 | |
/* | |
Write an "assertArraysEqual" function from scratch. | |
Assume that the arrays in question contain only scalar values (i.e., simple values like strings or numbers). | |
Do not use JSON.stringify(), Array.join(), or any other "convert the array to a string so I can compare two strings" type of technique to implement this. | |
Examples | |
SUCCESS CASE | |
var expected = ['b', 'r', 'o', 'k', 'e', 'n']; | |
var actual = 'broken'.split(''); | |
assertArraysEqual(actual, expected, 'splits string into array of characters'); |
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 convertFracts(lst): | |
n= len(lst) | |
ans =[[0]*2 for _ in range(n)] | |
for i in range(n): | |
ans[i][0]=lst[i][0]/gcd(lst[i][0], lst[i][1]) | |
ans[i][1] = lst[i][1]/gcd(lst[i][0], lst[i][1]) | |
return ans | |
def gcd(a, b): | |
"""Return greatest common divisor using Euclid's Algorithm.""" |
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
#using python 3.5 | |
import functools | |
# standard euclidean algorithm | |
def gcd(a, b): | |
while b: | |
a, b = b, a%b | |
return a | |
# with explicit recursion | |
def gcd_multiple(a, b): |
OlderNewer