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
version: '2' | |
services: | |
hub: | |
image: selenium/hub | |
ports: | |
- "4444:4444" | |
firefox: | |
image: selenium/node-firefox | |
volumes: |
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
""" | |
Given a target, find the list of numbers that sum to the target | |
""" | |
def targetSum(a,k): | |
s={0:[]} | |
res = [] | |
for x in a: | |
ns=dict(s) | |
for j in s: | |
if j+x == k: |
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
""" | |
Deep copy linked list with random pointers | |
""" | |
class Node(): | |
def __init__(self,val): | |
self.val = val; | |
self.random = None | |
self.next = None |
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
def morris_tree_traversal(root): | |
current = root | |
result = [] | |
while current is not None: | |
if current.left is None: | |
result.append(current.val) | |
current = current.right | |
else: | |
pre = current.left | |
while(pre.right is not None and pre.right is not current): |
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
""" | |
Dynamic Programming | Set 27 (Maximum sum rectangle in a 2D matrix) | |
http://www.geeksforgeeks.org/dynamic-programming-set-27-max-sum-rectangle-in-a-2d-matrix/ | |
The idea is that to rotate the matrix and use kadane's maxSumArray and | |
add the lists one by one to get the maximum sum of the matrix | |
""" | |
import sys | |
def maxSumSubArray(arr): |
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 hashlib import md5 | |
from Crypto.Cipher import AES | |
from Crypto import Random | |
import base64 | |
import os | |
def derive_key_and_iv(password, salt, key_length, iv_length): | |
d = d_i = '' | |
while len(d) < key_length + iv_length: |