solution for CTCI, mostly in Python