coderz.py

Keep Coding Keep Cheering!

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 value of π to three decimal places.

January 17, 2025 | dsa, DSA Sheet, Google | No comments

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 s that contains at most k distinct characters.

January 16, 2025 | Amazon, dsa, DSA Sheet | No comments

Staircase Climbing Ways

There is a staircase with N steps, and you can ascend either 1 step or 2 steps at a time. Write a function to calculate the number of unique ways to climb the staircase. The sequence of steps matters.

January 11, 2025 | Amazon, Data Structure, dsa | No comments

Autocomplete System Implementation

Build an autocomplete system that, given a query string s and a set of possible query strings returns all strings from the set that start with s as a prefix.

January 10, 2025 | dsa, DSA Sheet, Twitter | No comments

Job Scheduler Implementation

Design a job scheduler that accepts a function f and an integer n. The scheduler should execute the function f after a delay of n milliseconds.

January 9, 2025 | Apple, dsa, DSA Sheet | No comments

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 such that no two numbers are adjacent in the list. The input may contain zero or negative values. For example, [2, 4, 6, 2, 5] should return 13, since we pick 2, 6, and 5. [5, 1, 1, 5] should return 10, since we […]

January 7, 2025 | Airbnb, dsa, DSA Sheet | No comments

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 the root of a binary tree, determine how many unival subtrees it contains.

For example, the following tree has 5 unival subtrees:

January 6, 2025 | Binary Tree, dsa, DSA Sheet, Google | No comments

Count Decoding Ways for Encoded Messages

Problem Statement (Asked By Facebook) Given the mapping a = 1, b = 2, …, z = 26, and an encoded message, count the number of possible ways to decode it. For example, the message ‘111’ would give 3, since it could be decoded as ‘aaa’, ‘ka’, and ‘ak’. You can assume that the messages […]

January 5, 2025 | DP, dsa, DSA Sheet, Facebook | No comments

Implement an XOR Linked List

An XOR-linked list is a memory-efficient version of a doubly linked list. Instead of each node storing separate next and prev pointers, each node contains a single field called both, which stores the result of the XOR operation on the memory addresses of the next and previous nodes.

January 4, 2025 | dsa, DSA Sheet, Google | No comments

Construct and Deconstruct a Pair

Problem Statement (Asked By Jane Street) The function cons(a, b) creates a pair of two elements. Implement two functions: For instance: Below is the implementation of cons: Your task is to define the car and cdr functions. Disclaimer: Try solving the problem on your own first! Use this solution only as a reference to learn and […]

January 3, 2025 | dsa, DSA Sheet, Jane Street | No comments

Advertisement