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
# A simple cheat sheet of Spark Dataframe syntax | |
# Current for Spark 1.6.1 | |
# import statements | |
#from pyspark.sql import SQLContext | |
#from pyspark.sql.types import * | |
#from pyspark.sql.functions import * | |
from pyspark.sql import functions as F | |
#SparkContext available as sc, HiveContext available as sqlContext. |
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
# BST is a linked data structure in which each node is an object. | |
# In addition to a key and satellite data, each node contains attributes left, right, and p | |
# that point to the nodes corresponding to its left child and its parent. | |
# BST property | |
# x is a node in BST if y is any node in a left subtree than y.key <= x.key if y is any node in a right subtree | |
# than y.key >= x.key | |
class Node(object): |
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
""" | |
Rooted tree with unbounded branching, left child - right sibling representation backed by 4 arrays. | |
""" | |
class UnboundedTree(object): | |
def __init__(self): | |
self.root = 0 | |
self.storage = [ |
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 MinHeap(object): | |
def __init__(self): | |
self.storage = [] | |
def add(self, val): | |
self.storage.append(val) | |
self._percolate_up() | |
def get_min(self): |
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
# Linked lists are data structures made of chained elements connected either with one or with two others. | |
from collections import namedtuple | |
# Singly linked list node (immutable) | |
_Node = namedtuple('Node', ['value', 'next']) | |
# or mutable | |
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 parentheses_combinations_brute_force_1(n): | |
ans = [] | |
def generate_all(candidate): | |
if len(candidate) == 2 * n: | |
if is_valid(candidate): | |
ans.append(''.join(candidate)) | |
else: | |
candidate.append(')') | |
generate_all(candidate) |
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 solveNQueens(n): | |
""" | |
Returns all possible combinations of N queens placement. | |
:type n: int | |
:rtype: List[List[str]] | |
""" | |
board = [['.'] * n for _ in range(n)] | |
solutions = [] |
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
import sys | |
import collections | |
Node = collections.namedtuple('Node', ['value', 'next']) | |
def check_palindrome_n2(head_node): | |
seen = [] | |
if not head_node.next: | |
return True |
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
package io.qameta.htmlelements.handler; | |
import com.google.common.base.Throwables; | |
import org.openqa.selenium.support.ui.Clock; | |
import org.openqa.selenium.support.ui.SystemClock; | |
import java.util.List; | |
import java.util.concurrent.TimeUnit; | |
import java.util.function.Supplier; |
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
package io.qameta.htmlelements.handler; | |
import io.qameta.htmlelements.context.Context; | |
import io.qameta.htmlelements.context.Store; | |
import io.qameta.htmlelements.exception.MethodInvocationException; | |
import io.qameta.htmlelements.exception.NotImplementedException; | |
import io.qameta.htmlelements.extension.TargetModifier; | |
import java.lang.reflect.InvocationHandler; | |
import java.lang.reflect.InvocationTargetException; |