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 depth_first(self, root): | |
Q = [root] | |
elems = [] | |
while len(Q): | |
current = Q.pop(0) | |
elems.append(current.data) | |
if current.left is not None: |
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 boyer_moore_horspool(text, pattern): | |
''' | |
:param text: (string) | |
:param pattern: (string) | |
:return: list of indexes where full match occurs | |
''' | |
t_len = len(text) | |
p_len = len(pattern) | |
results = [] |
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
function build_nested_array($records){ | |
/* Build nested array on the menu example */ | |
$menu = array(); | |
$menu_index = array(); | |
foreach ($records as $record){ | |
if($record['parent_id'] == 0) { | |
$menu[] = [ | |
'name' => $record->name, | |
'child' => [] | |
]; |
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 solve(students_needed, skills): | |
skills.sort() | |
min_hours = float('+inf') | |
for i in range(0, len(skills) - students_needed + 1): | |
_range = skills[i: i + students_needed] | |
hours_needed = (max(_range) * students_needed) - sum(_range) | |
if min_hours > hours_needed: | |
min_hours = hours_needed | |
return min_hours |