Skip to content

Instantly share code, notes, and snippets.

FWIW: I'm not the author of the content presented here (which is an outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

What's an Effective Engineer?

@phalbert
phalbert / minimal_swaps.py
Last active April 14, 2019 00:19
rearrange the items on the shelf by decreasing popularity rating such that the rating for the i item is always greater than the popularity rating of the (i + 1) item.
"""
Question:
Mary can perform the following minimal sequence of swap operations to
successfully sort all 3 items by decreasing popularity rating: [3, 1, 2] → [3, 2, 1].
Solution:
1. The swap always compares the last element in the array with
the least element in the remaining list e.g.
in the case of [3, 1, 2, 4]...we compare 4 with the minimum value in [3,1,2]
and swap the two if the minimum value is less
@phalbert
phalbert / split_integer.py
Created April 13, 2019 18:53
Split an integer into a roughly equal number of parts
def splitInteger(num,parts):
array = []
for i in range(parts):
if i < num % parts:
value = num // parts + 1
else:
value = num // parts
array.append(value)
return sorted(array)
@phalbert
phalbert / node_compare.py
Created April 13, 2019 18:50
Compares the two trees defined by Nodes a and b and returns true if they are equal in structure and in value and false otherwise.
if a == b:
return True
if a is None or b is None:
return False
if a.val != b.val:
return False
return compare(a.left, b.left) and compare(a.right, b.right)