LeetCode

    [LeetCode] 1155. Number of Dice Rolls With Target Sum

    1155. Number of Dice Rolls With Target Sum Medium You have n dice and each die has k faces numbered from 1 to k. Given three integers n, k, and target, return the number of possible ways (out of the kn total ways) to roll the dice so the sum of the face-up numbers equals target. Since the answer may be too large, return it modulo 109 + 7. Example 1: Input: n = 1, k = 6, target = 3 Output: 1 Expl..

    [LeetCode] 91. Decode Ways

    91. Decode Ways Medium A message containing letters from A-Z can be encoded into numbers using the following mapping: 'A' -> "1" 'B' -> "2" ... 'Z' -> "26" To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, "11106" can be mapped into: "AAJF" with the grouping (1 1 10 6) "KJF"..

    [LeetCode] 218. The Skyline Problem

    [LeetCode] 218. The Skyline Problem

    218. The Skyline Problem Hard A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return the skyline formed by these buildings collectively. The geometric information of each building is given in the array buildings where buildings[i] = [lefti, righti, heighti]: lefti i..

    [LeetCode] 658. Find K Closest Elements

    658. Find K Closest Elements Medium Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order. An integer a is closer to x than an integer b if: |a - x| < |b - x|, or |a - x| == |b - x| and a < b Example 1: Input: arr = [1,2,3,4,5], k = 4, x = 3 Output: [1,2,3,4] Example 2: Input: arr = [1,2,3,4,5]..

    [LeetCode] 967. Numbers With Same Consecutive Differences

    967. Numbers With Same Consecutive Differences Medium Given two integers n and k, return an array of all the integers of length n where the difference between every two consecutive digits is k. You may return the answer in any order. Note that the integers should not have leading zeros. Integers as 02 and 043 are not allowed. Example 1: Input: n = 3, k = 7 Output: [181,292,707,818,929] Explanati..

    [LeetCode] 19. Remove Nth Node From End of List

    [LeetCode] 19. Remove Nth Node From End of List

    19. Remove Nth Node From End of List Medium Given the head of a linked list, remove the nth node from the end of the list and return its head. Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Example 2: Input: head = [1], n = 1 Output: [] Example 3: Input: head = [1,2], n = 1 Output: [1] Constraints: The number of nodes in the list is sz. 1

    [LeetCode] 113. Path Sum II

    [LeetCode] 113. Path Sum II

    113. Path Sum II Medium Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum. Each path should be returned as a list of the node values, not node references. A root-to-leaf path is a path starting from the root and ending at any leaf node. A leaf is a node with no children. Example 1: Input: root = [..

    [LeetCode] 838. Push Dominoes

    [LeetCode] 838. Push Dominoes

    838. Push Dominoes Medium There are n dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to the left or to the right. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. W..