coderz.py

Keep Coding Keep Cheering!

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

Find the Smallest Missing Positive Integer

Problem Statement (Asked By Stripe) You are given an array of integers. Your task is to find the smallest missing positive integer in O(N) time using O(1) additional space. In other words, identify the smallest positive number that is not present in the array. The array may include: You are allowed to modify the input […]

January 2, 2025 | dsa, DSA Sheet, Stripe | No comments

Serialize and Deserialize a Binary Tree

Given the root of a binary tree, create two functions:

serialize(root) – Converts the binary tree into a string representation.

deserialize(s) – Reconstructs the binary tree from its string representation.

January 1, 2025 | array, dsa, DSA Sheet, Google | No comments

Product of Array Except Self

Problem Statement (Asked By Uber) Given a list of integers, return a new list such that each element at index i of the new list is the product of all the elements in the original list except the one at i. For instance, if the input is [1, 2, 3, 4, 5], the expected output […]

December 30, 2024 | Algorithm, array, Data Structure, dsa, Uber | No comments

Two Sum: Check for Two Numbers with Sum K

Problem Statement (Asked By Google) Given a list of integers and a target number k, determine if there exist two numbers in the list whose sum equals k. For example, given [10, 15, 3, 7] and k = 17, return True because 10 + 7 = 17. Bonus: Can you solve this in a single […]

December 29, 2024 | array, dsa | No comments

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is commonly used to implement priority queues and efficient sorting algorithms like heap sort.

June 10, 2023 | Algorithm, Data Structure | No comments

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is a tree-like data structure used for fast string searching and prefix matching. It allows for the quick retrieval of words or keys connected with each node. The word Trie is derived from reTRIEval, which means finding something or obtaining it.  […]

May 31, 2023 | Data Structure | No comments

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of two nodes, n1 and n2, is the shared ancestor located farthest from the root and has both n1 and n2 as descendants. Properties of the Lowest Common Ancestor: An LCA can be one of the input nodes themselves if one […]

May 30, 2023 | Data Structure | No comments

Advertisement