Skip to content

Instantly share code, notes, and snippets.

View kagan94's full-sized avatar

Leonid Dashko kagan94

  • Tallinn, Estonia
View GitHub Profile
@kagan94
kagan94 / task1_round_A.py
Last active March 24, 2019 18:48
Kick Start 2019 (Round A, problem #1)
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
@kagan94
kagan94 / nested tree structure
Created May 8, 2017 22:25
May be used to print nested category structure with parent_id, category_id attributes
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' => []
];
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 = []
@kagan94
kagan94 / breadth-first output of the b-tree
Last active September 27, 2016 13:53
Breadth-first output of the b-tree
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: