Flatten a Multilevel Doubly Linked List Problem

Problem You are given a doubly linked list, which contains nodes that have a next pointer, a previous pointer, and an additional child pointer. This child pointer may or may not point to a separate doubly linked list, also containing these special nodes. These child lists may have one or more children of their own, and so on, to produce a multilevel data structure as shown in the example below. ...

Valid Word Square Problem

Problem Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a valid word square if the k_th row and column read the exact same string, where 0 ≤ k < max(numRows, numColumns). Note: Examples Example 1: $$ \begin{bmatrix} \color{red} a & \color{red} b & \color{red} c & \color{red} d \\ \color{red} b & \color{green} n & \color{green} r & \color{green} t \\ \color{red} c & \color{green} r & \color{blue} m & \color{blue} y \\ \color{red} d & \color{green} t & \color{blue} y & \color{violet} e \end{bmatrix} $$ ...

Add Strings Problem

Problem Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string. You must solve the problem without using any built-in library for handling large integers (such as BigInteger). You must also not convert the inputs to integers directly. Examples Example 1: Input: num1 = "11", num2 = "123" Output: "134" ...

Convert Number to Hexadecimal Number Problem

Convert Number to Hexadecimal Number Problem Problem Given an integer num, return a string representing its hexadecimal representation. For negative integers, two’s complement method is used. All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer except for the zero itself. Note: You are not allowed to use any built-in library method to directly solve this problem. ...

Binary Watch Problem

Binary Watch Problem Problem A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right. For example, the below binary watch reads "4:51". ...

Leaf-Similar Trees Problem

Problem Consider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence. graph TD; A(3) --- B(5) & C(1) B --- D(6) & E(2) E --- F(7) & G(4) C --- H(9) & I(8) style D fill:#4682B4,stroke:#333,stroke-width:2px style F fill:#4682B4,stroke:#333,stroke-width:2px style G fill:#4682B4,stroke:#333,stroke-width:2px style H fill:#4682B4,stroke:#333,stroke-width:2px style I fill:#4682B4,stroke:#333,stroke-width:2px ...

Path Sum 3 - Count paths from parent to child

Problem Given the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum. The path does not need to start or end at the root or a leaf, but it must go downwards (i.e., traveling only from parent nodes to child nodes). Examples Example 1: ...

Subarray Sums Divisible by K Problem

Problem Given an integer array nums and an integer k, return the number of non-empty subarrays that have a sum divisible by k. A subarray is a contiguous part of an array. Examples Example 1: Input: nums = [4,5,0,-2,-3,1], k = 5 Output: 7 Explanation: There are 7 subarrays with a sum divisible by k = 5: [4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3] ...

Maximum Level Sum of a Binary Tree Problem

Problem Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum of all the values of nodes at level x is maximal. Opposite of this problem - Minimum Level Sum of a Binary Tree Problem. Examples Example 1: graph TD A(1) --- B(7) & C(0) B --- D(7) & E("-8") ...

Time Based Key-Value Store Problem

Problem Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key’s value at a certain timestamp. Implement the TimeMap class: TimeMap() Initializes the object of the data structure. void set(String key, String value, int timestamp) Stores the key key with the value value at the given time timestamp. String get(String key, int timestamp) Returns a value such that set was called previously, with timestamp_prev <= timestamp. If there are multiple such values, it returns the value associated with the largest timestamp_prev. If there are no values, it returns "". Examples Example 1: ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy