Skip to content

Instantly share code, notes, and snippets.

View jhidajat's full-sized avatar
🧠

Jeremy Hidajat jhidajat

🧠
View GitHub Profile
@jhidajat
jhidajat / PhoneCombinations_1.py
Created March 12, 2018 19:45
START TIME: 2:503:20
"""
DFS
iterate from 0 to 9, and dfs from the source
dfs will take in a source, N, and the adjacencylist, and keeping track of the result
Base Case: if N == 0
Recursion: for child in src: dfs(child, N - 1, res)
NOTE: if source is 5, will not break dfs but will instead not go into for loop. (line 23)
Time: O(3^n) since every worst case, number 4 and number 6 has 3 children, and we need to visit all combinations
@jhidajat
jhidajat / PhoneCombinations_1.py
Last active March 12, 2018 21:18
Time: 2:50 - 3:20 (30 Minutes)
"""
DFS
iterate from 0 to 9, and dfs from the source
dfs will take in a source, N, and the adjacencylist, and keeping track of the result
Base Case: if N == 0
Recursion: for child in src: dfs(child, N - 1, res)
NOTE: if source is 5, will not break dfs but will instead not go into for loop. (line 23)
Time: O(3^n) since every worst case, number 4 and number 6 has 3 children, and we need to visit all combinations
@jhidajat
jhidajat / sameMeaning.py
Last active March 13, 2018 12:46
Time: 5:00 - 5:15 (15 Minutes)
"""
Two lists as the input. List1: stores word pairs with the same meaning, such as [(big, large), (fast, quick)];
List2: stores query pairs, such as [(grass is green, tree is green), (cat is fast, cat is quick)].
Based list1 , figure out if each pair of queries in list2 mean the same thing.
"""
"""
Union find
For every pair, put them inside the same disjoint set
#Subproblem: fewest number of coins to reach amount i
# subprobs: amount
#recurrence: dp[i] = min(dp[i - coin] + 1) for coin in coins
# runtime: O(coins)
# topsort : 0 to amount
# solution: dp[amount]
# TIME: O(amount * coins)
# SPACE: O(amount)
def union(x,y, edges):
rep = [-1] * sizeOfGraph
for edge in edges:
x_rep, y_rep = find(x, rep), find_set(y, rep)
if x_rep == y_rep:
return True
return False
def find(node, rep):
#rep
import React from 'react';
import PropTypes from 'prop-types';
import PositionSection from '../../components/Position/PositionSection';
import color from '../../layouts/color.module.css';
const positionSubSectionListToRender = (positionList) => {
const sectionsInOrder = ['Business and Ops', 'Design', 'Engineering', 'Product'];
return sectionsInOrder
import React from 'react';
import PropTypes from 'prop-types';
import marked from 'marked';
import { TRIBALSCALE_STREET_ADDRESS } from '../utils/constants';
import font from '../layouts/font.module.css';
import color from '../layouts/color.module.css';
import styles from './privacy.module.css';
@import '../../layouts/base.css';
/* column format */
.columnContainer {
max-width: 31.67701863%;
width: 100%;
}
.columnBackgroundImage {
max-width: 100%;
import React from 'react';
import PropTypes from 'prop-types';
import color from '../../layouts/color.module.css';
import animations from '../../layouts/animations.module.css';
import styles from './ventureStudiosTilesLayout.module.css';
const {
layoutContainer,
tileContainer,
'''
BRUTE FORCE:
iterate through each point, label p1=(x1,y1) ------------------------------ O(n)
iterate through next point, label p2 = (x2,y2) -------------------------- O(n)
iterate through remaining points, check if (x1,y2) and (x2, y1) exist-- O(n^2)
F: IGNORE
T: Compare to min_area, update accordingly:
area == min_area: add to list min_rects
area < min_area: min_area = area, replace min_rects
area > min_area: IGNORE