data structure

Efficient Order Log Storage

You manage an e-commerce website and need to keep track of the last N order IDs in a log. Design…

8 hours ago

Select a Random Element from a Stream

You are given a stream of elements that is too large to fit into memory. Write an algorithm to select…

3 days ago

Estimate π Using Monte Carlo Method

The formula for the area of a circle is given by πr². Use the Monte Carlo method to approximate the…

3 weeks ago

Longest Substring with K Distinct Characters

Given an integer k and a string s, write a function to determine the length of the longest substring in…

3 weeks ago

Staircase Climbing Ways

There is a staircase with N steps, and you can ascend either 1 step or 2 steps at a time.…

4 weeks ago

Autocomplete System Implementation

Build an autocomplete system that, given a query string s and a set of possible query strings returns all strings…

4 weeks ago

Job Scheduler Implementation

Design a job scheduler that accepts a function f and an integer n. The scheduler should execute the function f…

4 weeks ago

Largest Sum of Non-Adjacent Numbers

Problem Statement (Asked By Airbnb) Given a list of integers, write a function to compute the largest sum of numbers…

4 weeks ago

Count Unival Subtrees in a Binary Tree

A unival tree (short for "universal value tree") is a tree in which all nodes have the same value. Given…

1 month ago

Count Decoding Ways for Encoded Messages

Problem Statement (Asked By Facebook) Given the mapping a = 1, b = 2, ..., z = 26, and an…

1 month ago