Skip to content

Instantly share code, notes, and snippets.

View TheSithPadawan's full-sized avatar

rongromi_est TheSithPadawan

  • United States
View GitHub Profile
// notes for binary search lecture
// binary search is also used to search configurations with the following
// properties where we find the first True
// F F F F .... F (T) T T T ... T
// Apply binary search: to check that given the answer, is the configuration valid
/*
Example question: Aggressive cows (SPOJ)
N stalls on a straight line, C cows, no two cows can be tied to one stall.
Find the largest minimum distance of two cows of an assignment.
// https://leetcode.com/problems/longest-substring-without-repeating-characters/
#define um unordered_map
int solve (string s) {
um <char, int> ump;
int left = 0, right = 0;
int maxlen = 0;
int cnt = 0;
while (right < s.length()) {
ump[s[right]]++;
static ListNode *reverse(ListNode *head, int k) {
// TODO: Write your code here
ListNode * dummy = new ListNode(-1);
dummy->next = head;
ListNode * prev = dummy;
ListNode * cur = head;
ListNode * last_node_of_prev_list = prev;
ListNode * last_node_of_cur_list = cur;
while (cur) {
def find_word_concatenation(s, words):
result_indices = []
worddict = dict()
wordlen = len(words[0])
i, j = 0, 0
total = 0
for word in words:
if word not in worddict:
worddict[word] = 0
worddict[word] += 1
# leetcode 30.
def find_word_concatenation(s, words):
result_indices = []
worddict = dict()
wordlen = len(words[0])
i, j = 0, 0
total = 0
for word in words:
if word not in worddict:
worddict[word] = 0
"""
Input: String="oidbcaf", Pattern="abc"
Output: true
Explanation: The string contains "bca" which is a permutation of the given pattern.
"""
"""
general pattern:
make a dict for pattern string
iterate over the right end of the window
"""
OO Design: design data types for Amazon locker and packages
Requirement: Design an optimized algorithm to fit the package in the right locker
"""
import bisect
class Locker:
def __init__(self, x, y , z, **kwargs):
self.length = x
self.width = y
self.height = z
@TheSithPadawan
TheSithPadawan / filesys.py
Created April 3, 2022 18:17
Amazon OO Design Linux Find Command
"""
implemnet linux find command as an api ,the api willl support finding files that has given size requirements and a file with a certain format like
find all file >5mb
find all xml
Assume file class
{
get name()
directorylistfile()
getFile()
@TheSithPadawan
TheSithPadawan / locker.py
Created April 10, 2022 03:56
Amazon Locker OO Design
from enum import ENUM
class LockerSize(ENUM):
# for example.. not necessarily a cube
SMALL = (1, 1, 1)
MEDIUM = (2, 2, 2)
LARGE = (3, 3, 3)
class Locker:
def __init__(self, id, size, **kwargs):
@TheSithPadawan
TheSithPadawan / phrase_search.py
Last active April 15, 2022 03:11
CFLT onsite prep -- inverted index phrase search
# data modeling {word: {doc_id: {positions}}}
from collections import defaultdict
def build_index(sentences):
index = defaultdict(lambda: defaultdict(set))
for docid, sentence in enumerate(sentences):
wordlist = sentence.split(' ')
for pos, word in enumerate(wordlist):
index[word][docid].add(pos)
return index