- DSA
- LLD
- HLD

Q1: Design and implement an Excel Spreadsheet
You are building a library that a frontend team may use to surface a spreadsheet to some users. We want this to be a MVP library that can be expanded in the future if necessary. All data can be stored in memory.
We have the following requirements:
- We need to support integer values and formula values for the plus operator. For example, cell values may be: -9, 2, 3, 100, etc. (maximum of 3 digits per integer) ; =2+8, =100+2, etc. (with exactly two integers)
- We need to be able to reset cells to their default value, by giving the empty string.
- We need to be able to view the spreadsheet, with both the raw and computed values shown. For example, for “=2+8”, the raw value is “=2+8” and the computed value is “10”.
This does not have to look like a real spreadsheet, as long as the values are clear when printed.
Create a print method to print the whole spreadsheet, or return the spreadsheet data as a string.
Q2: Problem Statement: Design a Song Play Analytics System
Design a system to track song plays and generate analytics based on the number of unique listeners per song. Implement the SongAnalytics class with the following methods:
- SongAnalytics()
Initializes the system. - int add_song(string name)
Adds a song to the system, assigns it a unique auto-incrementing ID starting from 1, and returns the assigned ID. - void play_song(int song_id, int user_id)
Records a play event for a song by a user.- If song_id does not exist, output: Error: Song ID <song_id> does not exist. (replace <song_id> with the invalid ID).
- Each user is counted once per song, even if they play it multiple times.
- void print_analytics()
Prints a summary of all songs sorted by the number of unique listeners in descending order.- If two songs have the same number of unique listeners, sort them lexicographically by name in ascending order.
- Each line in the output should follow the format: <song_name> (<count> unique listeners).
Q3: Add driver and per hour rate.
Given a list of delivery drivers, the per hour payment of each driver and a list of deliveries they do, your job is to find the total to be paid to all the driver combined. They were expecting a production quality code approach. I wrote a class and created respective fucntions for:
- Add driver and per hour rate.
- Add delivery (This was epoch seconds)
- Get total to amount to be paid to all drivers.
Scale up: Given a time when we clear payments, output the total that has to be paid. Also, there should be another function that returns the total unpaid.
Q4: Design a Driver Payment Management System
Given a list of delivery drivers, the per hour payment of each driver and a list of deliveries they do, your job is to find the total to be paid to all the driver combined. They were expecting a production quality code approach. I wrote a class and created respective fucntions for:
Add driver and per hour rate.
Add delivery (This was epoch seconds)
Get total to amount to be paid to all drivers.
Scale up: Given a time when we clear payments, output the total that has to be paid. Also, there should be another function that returns the total unpaid.
Q5: Competing Reactions in an Isothermal Reactor
You are running an isothermal reactor which makes zinc oxide nanoparticles for sunblock (B) from a zinc-containing substrate (A). The reaction requires high temperature to achieve good yields within a reasonable residence time. Unfortunately, it also has a side reaction making an unwanted product C, composed of fused zinc oxide particles of the wrong sizes. Since the reaction to make C has a higher activation energy, the ratio of C to B in the output gets worse with increasing temperature.
Reactions: A → B, A → C
import math
# Constants
A0 = 3.0 # M
B0 = 0.0 # M
C0 = 0.0 # M
Ea1 = 6.0 # kcal/mol
Ea2 = 8.0 # kcal/mol
k1 = 30 # 1/s
k2 = 90 # 1/s
# R = gas constant
reactant_cost = 50 # reactant cost, $/M of A
reactor_operating_cost = 200 # reactor operating cost, $/minute
product_benefit = 200 # product benefit, $/M of B
cost_purify_reuse_A = 5 # cost to purify and re-use A, $/M of A
cost_safely_dispose_waste_C = 1 # cost to safely dispose of waste C, $/M of C
def dCdt(A, B, t, T):
return k2 * math.exp(-Ea2 / (R * T)) * A
def dAdt(A, B, t, T):
return -(dBdt(A, B, t, T) + dCdt(A, B, t, T))
def dBdt(A, B, t, T):
return k1 * math.exp(-Ea1 / (R * T)) * A
Find the temperature T and the reactor residence time t_res to maximise the net benefits of the reactor, meaning total benefits minus total costs. Your code should print:
- Optimal reactor conditions T and t_res including units.
- Final concentrations A, B, & C at the optimal conditions
- Net benefit (total benefits minus total costs) per M of A input at the optimal conditions
Hint: The function passed to scipy.optimize.minimize can call other functions inside it, including solving an IVP, as long as it returns a single value at the end (the value which gets minimised).
Follow-up: A plot of A, B, & C vs time at the optimal conditions
Q6: Currency Conversion Rate Calculation Using Exchange Mappings
Question
Paramenters:
- array of currency conversion rates. E.g. [‘USD’, ‘GBP’, 0.77] which means 1 USD is equal to 0.77 GBP
- an array containing a ‘from’ currency and a ‘to’ currency
Given the above parameters, find the conversion rate that maps to the ‘from’ currency to the ‘to’ currency.
Your return value should be a number.
Example:
You are given the following parameters:
- Rates: [‘USD’, ‘JPY’, 110] [‘US’, ‘AUD’, 1.45] [‘JPY’, ‘GBP’, 0.0070]
- To/From currency [‘GBP’, ‘AUD’]
Find the rate for the ‘To/From’ curency. In this case, the correct result is 1.89.
Q7: Design a Data Store to execute
Part 1
Perform a READ, CREATE, UPDATE, DELETE functions
- Create takes a String key and a String value – create(“key”, “val”) – return the stored value. If it exists, call update the function. (Hi Reader, if this feels like an normal over-write, wait until Part 3)
- Read takes a String key – read(“key”) – Returns the stored value, else error, or friendly message.
- Update takes a String key and String value – update(“key”, “val”) – returns the updated value, if it doesn’t exist, return and error or friendly message.
- Delete takes a String key – delete(“key”) and deletes it from the store, else error, or friendly message
Example 1:
– read(“key1”) – returns “No Key associated”
– create(“key1”, “val1”) – returns “val1”
– read(“key1”) – returns “val1”
– update(“key1”, “val2”) – returns “val2”
– read(“key1”) – returns “val2”
– delete(“key1”) – returns “Delete Success”
– read(“key1”) – returns “No key associated”
Part 2
Enable transactions for your data store. A transaction starts with begin() and operations like READ, CREATE, UPDATE, DELETE can take place during this time. After these operation, the transaction is ended by either a commit() that commits everything permanently in the data store or rollback() that reverts everything that was performed during the transaction window. Notice that I highlighted the key-word everything.
Example 1:
– create(“key1”, “val1”)
– create(“key2”, “val2”)
– create(“key3”, “val3”)
– read(“key1”) – returns “val1”
– read(“key2”) – returns “val2”
– read(“key3”) – returns “val3”
– begin() – this begins a transaction
– create(“key3”, “val8”)
– read(“key3”) – returns val8
– create(“key5”, “val5”)
– read(“key5”) – returns val5
– update(“key5”, “val7”
– read(“key5”) – returns val7
– update(“key2”, “val7”
– read(“key2”) – returns val7
– update(“key2”, “val8”
– read(“key2”) – returns val8
– delete(“key1”)
– read(“key1”) – No Key Associated
– commit() – this commits everything
After committing, you should still access the items in the data store with their update values.
– read(“key1”) – returns val8
– read(“key2”) – No Key Associated
– read(“key3”) – returns val8
Example 2: Disregard previous state of the Data Store
– create(“key1”, “val1”)
– create(“key2”, “val2”)
– create(“key3”, “val3”)
– read(“key1”) – returns “val1”
– read(“key2”) – returns “val2”
– read(“key3”) – returns “val3”
– begin() – this begins a transaction
– create(“key3”, “val8”)
– read(“key3”) – returns val8
– create(“key5”, “val5”)
– read(“key5”) – returns val5
– update(“key5”, “val7”
– read(“key5”) – returns val7
– update(“key2”, “val7”
– read(“key2”) – returns val7
– update(“key2”, “val8”
– read(“key2”) – returns val8
– delete(“key1”)
– read(“key1”) – No Key Associated
– rollback() – this rolls back everything
– read(“key1”) – returns val1
– read(“key2”) – returns val2
– read(“key3”) – returns val3
– read(“key5”) – No Key Associated
Part 3
Make the transactions limited. In Part 2, commit() commits everything while rollback() rolls back everything. This part will ensure that you can only –
commit(t) – Commits only the first t transactions.
rollback(t) – rolls back only the last t transactions.
For this part, Please note that only those operations that change the state of our data store are counted as transactions.
Example 1:
– create(“key1”, “val1”)
– create(“key2”, “val2”)
– create(“key3”, “val3”)
– read(“key1”) – returns “val1”
– read(“key2”) – returns “val2”
– read(“key3”) – returns “val3”
– begin() – this begins a transaction
– create(“key3”, “val8”)
– read(“key3”) – returns val8
– create(“key5”, “val5”)
– read(“key5”) – returns val5
– update(“key5”, “val7”
– read(“key5”) – returns val7
– update(“key2”, “val7”
– read(“key2”) – returns val7
– update(“key2”, “val8”
– read(“key2”) – returns val8
– delete(“key1”)
– read(“key1”) – No Key Associated
– commit(2) – this commits only the first two transactions
– read(“key1”) – returns val1
– read(“key2”) – returns val2
– read(“key3”) – returns val8
– read(“key5”) – returns val5
Example 2:
– create(“key1”, “val1”)
– create(“key2”, “val2”)
– create(“key3”, “val3”)
– read(“key1”) – returns “val1”
– read(“key2”) – returns “val2”
– read(“key3”) – returns “val3”
– begin() – this begins a transaction
– create(“key3”, “val8”)
– read(“key3”) – returns val8
– create(“key5”, “val5”)
– read(“key5”) – returns val5
– update(“key5”, “val7”
– read(“key5”) – returns val7
– update(“key2”, “val7”
– read(“key2”) – returns val7
– update(“key2”, “val8”
– read(“key2”) – returns val8
– delete(“key1”)
– read(“key1”) – No Key Associated
– rollback(2) – this rolls back only the last two transactions
– read(“key1”) – returns val1
– read(“key2”) – returns val7
– read(“key3”) – returns val8
– read(“key5”) – returns val7
Q8: Design an Event Tracking and Analytics System
You are asked to design an event tracking and analytics system similar to Amplitude or Mixpanel. The system should allow clients (e.g., websites, mobile apps, backend services) to log events such as “user_signed_in”, “item_purchased”, or “page_viewed”.
Requirements:
Event Ingestion:
Support high-throughput writes from multiple clients.
Ensure events are not lost even under heavy load.
Event Storage:
Store events in a scalable and queryable format.
Handle billions of events with varying schemas (different event properties).
Event Processing:
Support real-time aggregations (e.g., daily active users, funnels, retention).
Provide near real-time insights (latency < a few seconds).
Query System:
Allow flexible queries: by event type, user ID, time range, and custom properties.
Handle ad-hoc analytics queries efficiently.
Scalability & Reliability:
System must scale horizontally.
Ensure data consistency and fault tolerance.