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
// 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. |
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
// 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]]++; |
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
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) { |
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 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 |
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
# 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 |
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
""" | |
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 |
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
""" | |
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 |
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
""" | |
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() |
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
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): |
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
# 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 |