This file contains 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
class Trie(): | |
""" | |
""" | |
def __init__(self, char=None): | |
self.char = char | |
self.children = {} | |
self.count = 1 |
This file contains 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
MODULO = 1000000007 | |
def calc_power_of_two(number): | |
# i have taken 60 as base number for 64 bit processor | |
if number <= 60: | |
# Fastest way to calculate 2^N is to left shift binary 1 to N times | |
return (1 << number) | |
quotient = int(number / 60) % MODULO |
This file contains 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
from six import iteritems | |
def get_all_keys(dictionary): | |
""" | |
Method to get all keys from a nested dictionary as a List | |
Args: | |
dictionary: Nested dictionary | |
Returns: | |
List of keys in the dictionary | |
""" |