Skip to content

Instantly share code, notes, and snippets.

View jhidajat's full-sized avatar
🧠

Jeremy Hidajat jhidajat

🧠
View GitHub Profile
@jhidajat
jhidajat / search_phrase.py
Last active May 14, 2022 01:34
Search Phrase
"""
Implement an data structure that takes in a dictionary [doc_id] = doc_content
which contains a method search(word) and returns a list of document IDs containing the word.
Followup: update the data structure such that it also contains a method search_phrase(phrase) that
returns the document ids containing the phrase.
"""
from collections import defaultdict
"""
You have one chocolate bar that consists of some chunks. Each chunk has its own sweetness given by the array sweetness.
You want to share the chocolate with your k friends so you start cutting the chocolate bar into k + 1 pieces using k cuts, each piece consists of some consecutive chunks.
Being generous, you will eat the piece with the minimum total sweetness and give the other pieces to your friends.
Find the maximum total sweetness of the piece you can get by cutting the chocolate bar optimally.
"""
def maximizeSweetness(self, sweetness: List[int], k: int) -> int:
@jhidajat
jhidajat / companies.txt
Created April 26, 2022 23:40
List of companies to apply
Delphix
Booking
Kayak
Expedia
NerdWallet
Venmo
GoDaddy
Grubhub
Turo
Atlassian
class Solution {
public int canCompleteCircuit(int[] gas, int[] cost) {
int n = gas.length;
int total_tank = 0;
int curr_tank = 0;
int starting_station = 0;
for (int i = 0; i < n; ++i) {
total_tank += gas[i] - cost[i];
curr_tank += gas[i] - cost[i];
@jhidajat
jhidajat / get_combi.py
Last active August 8, 2021 23:31
Get the combination of possible outcome of input string s, which contains 0,1,?
def get_combi(s):
return get_combi_with_refixes([], s)
"""
The idea is to assume you have a calculated array of strings that you need
to append to. if its a ?, you "branch out" adding more to the array. When
suffix is empty, that means you have successfully recursed through the whole
string.
"""
def get_combi_with_prefixes(prefixes, suffix):
@jhidajat
jhidajat / download_flags.py
Created November 26, 2020 22:38
Download flags locally
import urllib
import os
country_codes = ['ad',
'ae',
'af',
'ag',
'ai',
'al',
'am',
from botocore.vendored import requests
def lambda_handler(event, context):
API_ENDPOINT_URL = event.get('api_endpoint_url')
DATA = event.get('data')
S3_BUCKET = event.get('s3_bucket')
S3_FILE_OBJECT_DIR_KEY = event.get('s3_file_object_dir_key')
PROJECT_ID = event.get('project_id')
JOB_ID = event.get('job_id')
OCTOPUS_SERVER_URL = event.get('octopus_server_url')
@jhidajat
jhidajat / firebase.js
Last active October 18, 2020 08:00
Sign In / Sign Up Template
import * as firebase from 'firebase/app'
import 'firebase/auth'
import {
FIREBASE_APIKEY,
FIREBASE_APPID,
FIREBASE_AUTHDOMAIN,
FIREBASE_DATABASEURL,
FIREBASE_MEASUREMENTID,
FIREBASE_MESSAGINGSENDERID,
FIREBASE_PROJECTID,
func (c *ContentServiceComponent) UpdateSourceRep(req respondAPI.UpdateSourceRepRequest, authSpec AuthenticationSpec) (*respondAPI.UpdateSourceRepResponse, error) {
GeneralLogger.Printf("Request Payload for /UpdateSourceRep:\n"+
"{\n"+
"\tSourceId: %v,\n"+
"\tReputation: %v,\n"+
"}",
req.SourceId, req.Reputation)
now := time.Now().UnixNano()
func ProcessNode(node, spec) {
...
return ContentNodeWithDisplay{...}
}
type ProcessArgs {
node *ContentNode
spec ProcessNodeSpec
}