DSA Sheet

27 lessons51 min total



  1. Sentence or String Reversal in Python
    Given a string of words, reverse all the words. For example:


    1 min





  2. Array Pair Sum in Python
    Given an integer array, output all the unique pairs that sum up to a specific value k.


    1 min





  3. Find the Missing Element in Python
    Consider an array of non-negative integers. A second array is formed by shuffling the elements of the first…


    2 min





  4. Largest Continuous Sum in Python
    Given an array of integers (positive and negative) find the largest continuous sum.


    1 min





  5. String Compression in Python
    Given a string in the form 'AAAABBBBCCCCCDDEEEE' compress it to become 'A4B4C5D2E4'. For this problem, you can falsely…


    1 min





  6. Unique Characters in String using Python
    Given a string,determine if it is compressed of all unique characters. For example, the string 'abcde' has all…


    1 min





  7. Balanced Parentheses Check in Python
    Given a string of opening and closing parentheses, check whether it’s balanced. We have 3 types of parentheses:…


    1 min





  8. Problems based on bit manipulation
    In the previous topic, we got an introduction to Bit Manipulation in DSA. Let us now look at…


    3 min





  9. Build Array From Permutation
    Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]]…


    4 min





  10. Square Root of Integer
    Given an integer A. Compute and return the square root of A. If A is not a perfect…


    1 min





  11. Product of Array Except Self
    Problem Statement (Asked By Uber) Given a list of integers, return a new list such that each element…


    1 min





  12. Serialize and Deserialize a Binary Tree
    Given the root of a binary tree, create two functions: serialize(root) – Converts the binary tree into a…


    2 min





  13. Find the Smallest Missing Positive Integer
    Problem Statement (Asked By Stripe) You are given an array of integers. Your task is to find the…


    3 min





  14. Construct and Deconstruct a Pair
    Problem Statement (Asked By Jane Street) The function cons(a, b) creates a pair of two elements. Implement two…


    2 min





  15. 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…


    2 min





  16. Count Decoding Ways for Encoded Messages
    Problem Statement (Asked By Facebook) Given the mapping a = 1, b = 2, …, z = 26,…


    2 min





  17. 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…


    2 min





  18. Largest Sum of Non-Adjacent Numbers
    Problem Statement (Asked By Airbnb) Given a list of integers, write a function to compute the largest sum…


    2 min





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


    2 min





  20. Autocomplete System Implementation
    Build an autocomplete system that, given a query string s and a set of possible query strings returns…


    2 min





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


    2 min





  22. Longest Substring with K Distinct Characters
    Given an integer k and a string s, write a function to determine the length of the longest…


    2 min





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


    2 min





  24. 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…


    2 min





  25. Efficient Order Log Storage
    You manage an e-commerce website and need to keep track of the last N order IDs in a…


    2 min





  26. Longest Absolute Path in File System Representation
    Find the length of the longest absolute path to a file within the abstracted file system. The length…


    3 min





  27. Minimum Cost to Paint Houses with K Colors
    A builder plans to construct N houses in a row, where each house can be painted in K…


    2 min