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 keyboard_path(word): | |
| path = [] | |
| current = 'a' | |
| for letter in word: | |
| x,y = get_position(current) | |
| nx, ny = get_position(letter) | |
| path += math.abs(nx - x) * ['down' if nx > x else 'up'] | |
| path += math.abs(ny - y) * ['right' if ny > y else 'left'] |
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
| ''' | |
| compute the minimum number of removals in order to make the string palindrome | |
| ''' | |
| def palindromic_substring(word): | |
| dp = [[-1 for _ in range(len(word) + 1)] for _ in range(len(word)+1)] | |
| def count_nr_chars(word, i, j, count): | |
| if dp[i][j] != -1: |
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
| ''' | |
| given a final score in a certain sport, get all the possible scores during | |
| the game. the scoring points are given ahead | |
| ''' | |
| from copy import copy | |
| def get_scores(points, result): | |
| dp = [0 for _ in range(result + 1)] | |
| dp[0] = 1 |
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 shortest_substring(words, text): | |
| total, start, mstart, mend = 0, 0, 0, 0 | |
| min_value = len(text) | |
| counts = defaultdict(int) | |
| for i in range(len(text)): | |
| if text[i] in words: | |
| counts[text[i]] = counts[text[i]] + 1 | |
| if counts[text[i]] == 1: | |
| total = total + 1 | |
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
| async def scrap_exchanges(): | |
| coins = pd.DataFrame.from_csv('crypto/data/coins.csv') | |
| data = defaultdict(lambda:[]) | |
| chunks = [coins[i: i + 5] for i in range(0, len(coins), 5)] | |
| for chunk in chunks[0:10]: | |
| with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: | |
| futures = [loop.run_in_executor(executor, get_exchanges_for_coin, coin.split(":")[0]) for coin in chunk["Coins"]] |
NewerOlder