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 java.awt.*; | |
import java.util.function.Consumer; | |
import java.util.function.Function; | |
import java.util.stream.Stream; | |
public class Camera { | |
private Function<Color, Color> filter; | |
public Camera(){ |
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 make_squares(arr): | |
squares = [0 for x in range(len(arr))] | |
frontPointer = 0 | |
backPointer = len(arr) - 1 | |
for resultIndex in range(len(arr)): | |
frontSquare = arr[frontPointer] * arr[frontPointer] | |
backSquare = arr[backPointer] * arr[backPointer] | |
if frontSquare >= backSquare: |
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 java.util.*; | |
class Interval { | |
int start; | |
int end; | |
public Interval(int start, int end) { | |
this.start = start; | |
this.end = end; | |
} |
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 Node: | |
def __init__(self, value, next=None): | |
self.value = value | |
self.next = next | |
def has_cycle(head): | |
fast_pointer = head | |
slow_pointer = head | |
while fast_pointer is not None and fast_pointer.next is not 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
import hmac | |
import os | |
import hashlib | |
import base64 | |
import unittest | |
__author__ = 'drem' | |
class SecurityUtil(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
def dutch_flag_sort(arr): | |
n = len(arr) | |
frontPointer = 0 | |
backPointer = n - 1 | |
solutionIndex = 0 | |
while solutionIndex <= backPointer: | |
# Swap the 0s | |
if arr[solutionIndex] == 0: | |
swap(solutionIndex, frontPointer, 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
def remove_duplicates(arr): | |
firstPointer = 1 | |
secondPointer = 1 | |
while secondPointer < len(arr): | |
if arr[firstPointer - 1] != arr[secondPointer]: | |
# Replace duplicate with non duplicate | |
arr[firstPointer] = arr[secondPointer] | |
firstPointer += 1 | |
secondPointer +=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
def longest_substring_with_k_distinct(str, k): | |
windowStart = 0 | |
uniqueCharacterCount = {} | |
longestRun = 0 | |
currentRun = 0 | |
uniqueCharacters = 0 | |
for windowEnd in range(len(str)): | |
nextCharacter = str[windowEnd] | |
nextCharacterCount = uniqueCharacterCount.get(nextCharacter) | |
# We have seen this character already to increment its count |
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 math | |
def smallest_subarray_with_given_sum(s, arr): | |
subArrayStart = 0 | |
resultArraySize = math.inf | |
subArraySum = 0 | |
for subArrayEnd in range(0, len(arr)): | |
subArraySum += arr[subArrayEnd] | |
while subArraySum >= s: |
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
# By Drem | |
def max_sub_array_of_size_k(k, arr): | |
maximumSum = 0 | |
currentMaximumSum = 0 | |
subArrayStart = 0 | |
for subArrayEnd in range(len(arr)): | |
maximumSum += arr[subArrayEnd] | |
if subArrayEnd >= k - 1: | |
if maximumSum > currentMaximumSum: |
NewerOlder