Flexport | Senior SWE | Onsite

Anonymous User
2082
Mar 27, 2023

Phone:

"""
Part 1: canPurchase()
In this game players will have a set of colored tokens (Red, Blue, Green, Black, White). Their objective is to purchase cards using those
tokens.

Cards will have a cost of some number of the above listed colored tokens.
For example a card can cost 2 blue and 1 green token.

If a player has 2 blue tokens and 1 red token they cannot buy the card because they do not have the necessary green currency.
Implement a function that determines if a card can be purchased by a particular player given the current
state.
How you choose to represent the purchase, state, and function signature is up to you.


Part 2: purchase()
Given a “Card” and a “Player" as modeled in part 1, implement a function that is called when a player tries to purchase a card.
It should update the state of the game to reflect what happens when the card is purchased by the given player.


Part 3: Discounts
Now that we have the ability to purchase cards we want to add value to them. Cards now have a color associated with them.
When attempting to purchase a new card the player can use the cards they have previously bought to count as 1 unit of currency matching
the color of the card. You can use a card once per purchase and it does not consume the card.
For example if you have previously bought two green colored cards and have three green tokens in your wallet you would be able to buy a
card that costs three green and still have two green tokens in your wallet.
Update your current implementation to account for these discounts.


Part 4: Gold Tokens
Let's introduce a new color to our game. Now we have the ability to use Gold tokens.
These tokens are special in that they can be used as any color.
For example if you have 2 blue tokens and 1 gold token you can buy a card that costs 1 blue
and 1 red, or you could buy a card that costs 3 blue by spending this gold token.

Update your current implementation to account for this new token type.
"""

Onsite:

Coding:


"""
Task 1:
Instruction
To begin implementing our booking system, we must first determine if orders can be fulfilled.
For now, each order consists of an origin and a destination. Given a network of flights,
create a function to determine if a booking order can be satisfied (a direct flight exists
between origin and destination.
How you choose to model orders, the flights, and the network is totally up to you.
"""

def task1(targetOrigin, targetDestination, flights):
    # Flights is a List<Tuple<origin, destination>>
    return targetOrigin == targetDestination or (targetOrigin, targetDestination) in flights


"""
Task 2: 
Instruction
Now that we can handle direct flights modeled in Part 1, we want to expand our
air network to support more cities. To do this we must adapt our booking system
to handle connecting flights (since not all cities can have a direct flight).
Given a booking order, determine if we can satisfy it through connecting flights.
"""

from collections import defaultdict, deque

def task2(targetOrigin, targetDestination, flights):
    if targetOrigin == targetDestination:
        return True
    graph = defaultdict(list)
    for origin, destination in flights:
        graph[origin].append(destination)
    visited = {targetOrigin}
    queue = deque([targetOrigin])
    while queue:
        currentCity = queue.popleft()
        if currentCity == targetDestination:
            return True
        for nextCity in graph[currentCity]:
            if nextCity not in visited:
                queue.append(nextCity)
                visited.add(nextCity)
    return False
    
"""
Task 3:
Instruction
Now that our booking system can handle connecting flights, we should be adapt our system
to display and book the flight path with the fewest connecting flights. Modify the
function from the previous part to now only return the flight path with the fewest connections
(if one exists).
"""

def task3(targetOrigin, targetDestination, flights):
    if targetOrigin == targetDestination:
        return [targetOrigin]
    
    graph = defaultdict(list)
    for origin, destination in flights:
        graph[origin].append(destination)
    cityToParentCityOnClosestPath = {targetOrigin: None}
    queue = deque([targetOrigin])
    while queue:
        currentCity = queue.popleft()
        if currentCity == targetDestination:
            city = targetDestination
            reversedFlightPath = []
            while city is not None:
                reversedFlightPath.append(city)
                city = cityToParentCityOnClosestPath[city]
            reversedFlightPath.reverse()
            return reversedFlightPath
        for nextCity in graph[currentCity]:
            if nextCity not in cityToParentCityOnClosestPath:
                cityToParentCityOnClosestPath[nextCity] = currentCity
                queue.append(nextCity)
    return []

"""
Task 4:
Instruction
Let us now add the concept of costs to flights. Obviously, it costs money
to have your cargo on each flight. Given an order, determine the cheapest route
(if one exists) to satisfy your order.
"""

from heapq import heappush, heappop
def task4(targetOrigin, targetDestination, flights):
    if targetOrigin == targetDestination:
        return 0
    
    graph = defaultdict(list)
    for origin, destination, cost in flights:
        graph[origin].append((destination, cost))
    heap = [(0, targetOrigin)]
    visited = set()
    while heap:
        currentPrice, currentCity = queue.popleft()
        if currentCity == targetDestination:
            return currentPrice
        for nextCity, travelCost in graph[currentCity]:
            if nextCity not in visited:
                costToGetToNextCity = currentPrice + travelCost
                heappush(heap, (costToGetToNextCity, nextCity)         
    return -1

System Design:

Briefly discuss a project you did and a challenge you encountered in the project.

Design a restaurant reservation system that can primarily serve 2 functions:

  1. list_availabilities
    Lists local restaurants that have a reservation available at a specified time and date.

  2. reserve
    Make a reservation at a restaurant with id - restauraut_id for a group of size - party_size at a given date and time.

The interviewer was very sarcastic and never let me talk. While gathering requirements, I asked if we need to take payments in order to make a reservation. The interviewer responded "Well... doooooo we?" That's why I asked! Are you requiring it or not?

I asked the interviewer whether restaurants can have time windows for reservations and whether those time windows can be structured to start every hour or so.

i.e. Can we say that the table is available for 7 PM - 8 PM, but you can't reserve it for 7:15 PM - whenever you want?

He said it's up to me. It's way easier to use the hourly blocks, so that's what decided to use.
Then the interviewer interrupted me and said that my design won't work if someone wants to make a reservation for 7:15 PM.

Why did he tell me we could do it either way??

Then he told me my data model didn't make sense because we don't need a table for tracking the reservations. So I said if you don't track who owns the reservation, then people could claim each other's reservations and it wouldn't truly be a reservation. He seemed ticked off.

I know he failed me. I wanted to leave 15 minutes into the interview. I have no idea why he bothered interviewing me.

The interviewer was a jerk.

Behavioral:

Talk about a project you're proud of.

Discuss 1 large deliverable in this work.

Where was I starting from, what was the tech like, what was the goal.

The group I was working with. Responsibilities.

Engineers I was working with.

First steps to approaching the project.

High level design proposal and review.

How did I get feedback during the design? What was the challenge during design?

Tradeoffs. How much did tradeoffs disrupt the project?

How do I plan and execute the rest of the rollout.

How did I rally other engineers in the face of a challenge.

A project that I worked on that didn't go well.

How do I make a diverse and inclusive workplace?

How do I onboard to a new engineering system?

Example of conflict during a project.

A time where I created a process change.

A time I got constructive feedback.

What do you hope to learn by working at Flexport?

Comments (3)