Skip to content

Instantly share code, notes, and snippets.

View jayceazua's full-sized avatar
:octocat:
Focusing

Jayce Azua jayceazua

:octocat:
Focusing
View GitHub Profile
@jayceazua
jayceazua / vmware.py
Last active December 2, 2019 05:50
VMware last coding problem
"""
Compress String
input:
i j
'a 1 2 c 9 b 5 6 c 1'
output:
'a12b56c10'
def island_count(grid):
if not grid:
return 0
nr = len(grid)
nc = len(grid[0])
num_islands = 0
for r in range(nr):
class Node(object):
def __init__(self, val, neighbors):
self.val = val
self.neighbors = neighbors
def clone_Graph(node):
if not node:
return
@jayceazua
jayceazua / fb_solution.py
Last active November 14, 2019 01:54
k most frequent words in a string
import os
from collections import Counter
from operator import itemgetter
def most_freq(input_string, k):
words = get_clean_words_list(input_string)
words = Counter(words)
result = []
for word, freq in words.items():
def find_middle(ll):
even = ll.size % 2 == 0
node = ll.head
if even:
for i in range(ll.size // 2 + 1):
if i == ll.size / 2 - 1:
return node.data, node.next.data
node = node.next
else:
for i in range(ll.size // 2 + 2):
@jayceazua
jayceazua / fibonacci_test.py
Last active May 14, 2019 07:38
Fibonacci Test
import unittest
from fibonacci_resursive import fibonacci
class FiboTest(unittest.TestCase):
def test_fibonacci(self):
assert fibonacci(9) == 34
assert fibonacci(1) == 1
assert fibonacci(2) == 1
assert fibonacci(5) == 3
@jayceazua
jayceazua / fibonacci_memoization.py
Last active May 14, 2019 17:45
SPD_1.4_2.4 Fibonacci Memoization Refactor
import time
# store recent function calls into a dictionary
cache_values = {}
def fibonacci(n):
# check if the given number is less than 0
if n < 0:
# output an error message stating that the number given is incorrect
raise ValueError("Has to be a positive integer!")
# check if the value is in our dictionary
@jayceazua
jayceazua / pseudocode_fibonacci_memoization.md
Last active May 13, 2019 11:05
SPD_1.4_2.4 Refactor Fibonacci Recursive to Dynamic

Refactor Plan - Fibnoacci Memoization

store recent function calls into a dictionary

check if the value is in our dictionary

  • return that value if it is

if that fails you will need to compute the value

@jayceazua
jayceazua / fibonacci_recursive.py
Last active May 14, 2019 17:44
SPD_1.4_2.4 Fibonacci_Recursive
import time
def fibonacci(n):
# check if the given number is less than 0
if n < 0:
# output an error message stating that the number given is incorrect
raise ValueError("Has to be a positive integer!")
# check if the given number is equal to 1 or 2 return 1 if it is
elif n == 0:
return 0
@jayceazua
jayceazua / pseudocode_fibonacci_recursive.md
Last active May 13, 2019 10:55
SPD_1.4_2.4 Pseudocode Fibonacci Recursive

Fibnoacci Recursion

check if the given number is less than 0

  • output an error message stating that the number given is incorrect

check if the given number is equal to 1

  • return the integer 1 if it is