Skip to content

Instantly share code, notes, and snippets.

View h2rashee's full-sized avatar

Harris Rasheed h2rashee

View GitHub Profile
@h2rashee
h2rashee / WallStreet.py
Created October 27, 2023 21:01
Stytch: Create a system that matches buy and sell offers
import heapq
class MaxHeapObj(object):
def __init__(self, val): self.val = val
def __lt__(self, other): return self.val > other.val
def __eq__(self, other): return self.val == other.val
def __str__(self): return str(self.val)
class MinHeap(object):
@h2rashee
h2rashee / org_chart.py
Last active November 2, 2023 03:07
Given an org chart, debug it and then print it in JSON format
""""
Imagine you've been asked to review, and possibly refactor, the below code (of course, for the purpose of this interview, the code is intentionally poorly written). Think of your interviewer as your pair programming partner. You are expected to lead the exercise, but they are there to help you and provide guidance where appropriate.
Start by understanding and explaining what the code does. Feel free to make small changes as you go. There are also tests at the end that may help.
Next, try to get any failing tests to pass.
From there, come up with a plan for how you might improve the code. There may be both code and performance improvements.
We will block these segments by time, so don't be alarmed if we need to move to the next part.
@h2rashee
h2rashee / worker_referrals.py
Last active November 2, 2023 03:09
Traba: Given a list of workers and who they were referred by, find the worker that has referred the most workers
# ### Context
# At Traba, one way that we've grown our worker pool is by offering incentives for our existing workers to refer people in their network. We'd like to do some analysis on which workers have been responsible for the most worker acquisition.
# ### Prompt
# Given an array of worker id pairs, where the 0th index represents a worker on Traba and the 1st index, if defined, represents the worker that referred the aforementioned worker, write a function that determines which worker is responsible for the most referrals on Traba, direct or indirect.
# ### Examples
@h2rashee
h2rashee / data.json
Last active November 2, 2023 03:08
Traba: Given all work shifts (past and present), workers and existing shift sign ups, determine if a worker can be assigned to a shift
{
"workers": [
{
"id": "e60a8006-c57a-4d2e-9b35-99d88c9499f9"
},
{
"id": "c28c127b-d65e-4e04-926a-085e5809313b"
},
{
"id": "6deebc8e-719b-46ae-a123-aa8fde1a64dd"
@h2rashee
h2rashee / hebbia.py
Last active November 2, 2023 03:09
Hebbia.AI: Given a query, passage and scores of the words in the passage, return a single contiguous selection of the passage.
query = "Why are covid tests useful in the workplace?"
passage = "if it does. Ultimately, tests will help ensure that people can get back to work and will help reestablish public confidence in various sectors."
scores = [0.09, 0.01, 0.0, 0.9, 1.0, 0.4, 0.2, 0.6, 0.7, 0.8, 0.9, 0.9, 0.8, 0.7, 0.6, 0.02, 0.1, 0.01, 0.5, 0.2, 0.3, 0.0, 0.01, 0.00]
# Example of possible picks
# 0.9, 1.0, 0.4
# 0.6, 0.7, 0.8, 0.9, 0.9, 0.8, 0.7, 0.6
@h2rashee
h2rashee / ParkingLot.py
Last active November 2, 2023 03:09
AtoB: Design a Parking lot that can handle multiple vehicle types based on certain rules
# # Design a parking lot
# # Assumptions:
# # - The parking lot can hold motorcycles, cars and vans.
# # - The parking lot has spots of 3 sizes: small spots, medium spots and large
# # spots.
# # - A motorcycle can park in any spot. A car can park in a single medium spot,
# # or a large spot.
# # - A van can park, but it will take up 3 medium spots or a large spot. For the
# # purposes of this exercise, don’t worry about if the medium spots are next to
@h2rashee
h2rashee / member_renewals.py
Last active February 17, 2022 12:42
Determining who hasn't renewed for the new year
import csv
import sys
DEBUG = False
# We process two input CSV files that have the following field names:
LAST_NAME_FIELD = 'Last Name'
FIRST_NAME_FIELD = 'First Name'
EMAIL_FIELD = 'Email Address'
CELL_PHONE_FIELD = 'Cell Phone Number'
@h2rashee
h2rashee / tic_tac_toe.py
Created February 2, 2022 18:52
Build Tic Tac Toe
import copy
BOARD_FORMAT = '{} | {} | {}\n-----------\n{} | {} | {}\n-----------\n{} | {} | {}\n-----------\n'
class TicTacToe:
def __init__(self):
self.board = [[None, None, None], [None, None, None], [None, None, None]]
self.cur_turn = 'X'
def __repr__(self):
@h2rashee
h2rashee / employee_salaries.py
Last active February 9, 2022 14:23
Rippling: Perform operations on employee salaries with certain fields
# Rippling is at its core an employee database.
# Imagine if you’re at the early days of Rippling and you have admins asking for features around
# data reporting.
# The idea is that we want to build a system that allows admins to calculate values across many dimensions.
# Write a function that takes data blob as input (see example below) and calculates the sum
# of salaries in each department.
# [
# {
@h2rashee
h2rashee / employee_rating.py
Last active February 9, 2022 14:23
Rippling: Given an organization structure, find the employee with the highest average rating (including their subordinates)
'''
A(3)
B(3) C(4)
D(1) E(2)
'''
max_avg_rating = 0
max_avg_employee = None