GoCalf Calf 的自留地 · 昙花一现

hard

  • 1092. Shortest Common Supersequence

    #Problem Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them. A string s is a subsequence of string t if deleting some number of …

    hard
  • 2296. Design a Text Editor

    #Problem Design a text editor with a cursor that can do the following: Add text to where the cursor is. Delete text from where the cursor is (simulating the backspace key). Move the cursor either left or right. When deleting text, only …

    hard
  • 1028. Recover a Tree From Preorder Traversal

    #Problem We run a preorder depth-first search (DFS) on the root of a binary tree. At each node in this traversal, we output D dashes (where D is the depth of this node), then we output the value of this node. If the depth of a node is D, …

    hard
  • 2209. Minimum White Tiles After Covering With Carpets

    #Problem You are given a 0-indexed binary string floor, which represents the colors of tiles on a floor: floor[i] = '0' denotes that the iᵗʰ tile of the floor is colored black. On the other hand, floor[i] = '1' denotes that the iᵗʰ tile of …

    hard
  • 1728. Cat and Mouse II

    #Problem A game is played by a cat and a mouse named Cat and Mouse. The environment is represented by a grid of size rows x cols, where each element is a wall, floor, player (Cat, Mouse), or food. Players are represented by the characters …

    hard
  • 827. Making A Large Island

    #Problem You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applying this operation. An island is a 4-directionally connected group of 1s. …

    hard
  • 2412. Minimum Money Required Before Transactions

    #Problem You are given a 0-indexed 2D integer array transactions, where transactions[i] = [costᵢ, cashbackᵢ]. The array describes transactions, where each transaction must be completed exactly once in some order. At any given moment, you …

    hard
  • 2920. Maximum Points After Collecting Coins From All Nodes

    #Problem There exists an undirected tree rooted at node 0 with n nodes labeled from 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [aᵢ, bᵢ] indicates that there is an edge between nodes aᵢ and bᵢ in the …

    hard
  • 2218. Maximum Value of K Coins From Piles

    #Problem There are n piles of coins on a table. Each pile consists of a positive number of coins of assorted denominations. In one move, you can choose any coin on top of any pile, remove it, and add it to your wallet. Given a list piles, …

    hard
  • 42. Trapping Rain Water

    #Problem Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. https://leetcode.com/problems/trapping-rain-water/ Example 1: case1Input: height = …

    hard todo
  • 1368. Minimum Cost to Make at Least One Valid Path in a Grid

    #Problem Given an m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j] can be: 1 which means go to the cell to the right. (i.e go from grid[i][j] …

    hard
  • 3414. Maximum Score of Non-overlapping Intervals

    #Problem You are given a 2D integer array intervals, where intervals[i] = [lᵢ, rᵢ, weightᵢ]. Interval i starts at position lᵢ and ends at rᵢ, and has a weight of weightᵢ. You can choose up to 4 non-overlapping intervals. The score of the …

    hard
  • 3298. Count Substrings That Can Be Rearranged to Contain a String II

    #Problem 跟 3297. Count Substrings That Can Be Rearranged to Contain a String I 一模一样,只是多了一个注意点: Note that the memory limits in this problem are smaller than usual, so you must implement a solution with a linear runtime complexity. …

    hard
  • 3410. Maximize Subarray Sum After Removing All Occurrences of One Element

    #Problem You are given an integer array nums. You can do the following operation on the array at most once: Choose any integer x such that nums remains non-empty on removing all occurrences of x. Remove all occurrences of x from the array. …

    hard
  • 3045. Count Prefix and Suffix Pairs II

    #Problem 跟 3042. Count Prefix and Suffix Pairs I 一模一样,但单词数量从 50 提升到 10⁵,同时单词的长度也从 10 提升到 10⁵。 https://leetcode.com/problems/count-prefix-and-suffix-pairs-ii/ Constraints: 1 <= words.length <= 10⁵ 1 <= words[i].length <= 10⁵ words[i] …

    hard
  • 3395. Subsequences with a Unique Middle Mode I

    #Problem 唯一中间众数子序列。 Given an integer array nums, find the number of subsequences of size 5 of nums with a unique middle mode. A subsequence is an array that can be derived from another array by deleting some or no elements without changing …

    hard
  • 3398. Smallest Substring With Identical Characters I

    #Problem You are given a binary string s of length n and an integer numOps. You are allowed to perform the following operation on s at most numOps times: Select any index i (where 0 <= i < n) and flip s[i]. If s[i] == '1', change s[i] to …

    hard
  • 3399. Smallest Substring With Identical Characters II

    跟 3398. Smallest Substring With Identical Characters I 一模一样,只不过 s 的长度上限从 1000 增加到 10⁵。 https://leetcode.com/problems/smallest-substring-with-identical-characters-ii/ 直接用上次的代码没问题(最大堆或二分法均可)。

    hard
  • 3405. Count the Number of Arrays with K Matching Adjacent Elements

    #Problem You are given three integers n, m, k. A good array arr of size n is defined as follows: Each element in arr is in the inclusive range [1, m]. Exactly k indices i (where 1 <= i < n) satisfy the condition arr[i - 1] == arr[i]. Return …

    hard
  • 732. My Calendar III

    #Problem A k-booking happens when k events have some non-empty intersection (i.e., there is some time that is common to all k events.) You are given some events [startTime, endTime), after each given event, return an integer k representing …

    hard
  • 730. Count Different Palindromic Subsequences

    #Problem Given a string s, return the number of different non-empty palindromic subsequences in s. Since the answer may be very large, return it modulo 10⁹ + 7. A subsequence of a string is obtained by deleting zero or more characters from …

    hard
  • 913. Cat and Mouse

    #Problem A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns. The graph is given as follows: graph[a] is a list of all nodes b such that ab is an edge of the graph. The mouse starts at node 1 and goes …

    hard
  • 321. Create Maximum Number

    #Problem You are given two integer arrays nums1 and nums2 of lengths m and n respectively. nums1 and nums2 represent the digits of two numbers. You are also given an integer k. Create the maximum number of length k <= m + n from digits of …

    hard todo
  • 843. Guess the Word

    #Problem You are given an array of unique strings words where words[i] is six letters long. One word of words was chosen as a secret word. You are also given the helper object Master. You may call Master.guess(word) where word is a …

    hard
  • 1639. Number of Ways to Form a Target String Given a Dictionary

    #Problem You are given a list of strings of the same length words and a string target. Your task is to form target using the given words under the following rules: target should be formed from left to right. To form the iᵗʰ character …

    hard
  • 1206. Design Skiplist

    #Problem Design a Skiplist without using any built-in libraries. A skiplist is a data structure that takes O(log(n)) time to add, erase and search. Comparing with treap and red-black tree which has the same function and performance, the …

    hard
  • 1250. Check If It Is a Good Array

    #Problem Given an array nums of positive integers. Your task is to select some subset of nums, multiply each element by an integer and add all these numbers. The array is said to be good if you can obtain a sum of 1 from the array by any …

    hard
  • 1298. Maximum Candies You Can Get from Boxes

    #Problem You have n boxes labeled from 0 to n - 1. You are given four arrays: status, candies, keys, and containedBoxes where: status[i] is 1 if the iᵗʰ box is open and 0 if the iᵗʰ box is closed, candies[i] is the number of candies in the …

    hard
  • 689. Maximum Sum of 3 Non-Overlapping Subarrays

    #Problem Given an integer array nums and an integer k, find three non-overlapping subarrays of length k with maximum sum and return them. Return the result as a list of indices representing the starting position of each interval …

    hard
  • 2493. Divide Nodes Into the Maximum Number of Groups

    #Problem You are given a positive integer n representing the number of nodes in an undirected graph. The nodes are labeled from 1 to n. You are also given a 2D integer array edges, where edges[i] = [aᵢ, bᵢ] indicates that there is a …

    hard
  • 1847. Closest Room

    #Problem There is a hotel with n rooms. The rooms are represented by a 2D integer array rooms where rooms[i] = [roomIdᵢ, sizeᵢ] denotes that there is a room with room number roomIdᵢ and size equal to sizeᵢ. Each roomIdᵢ is guaranteed to be …

    hard
  • 2940. Find Building Where Alice and Bob Can Meet

    #Problem You are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the iᵗʰ building. If a person is in building i, they can move to any other building j if and only if i < j and heights[i] < …

    hard