GoCalf Calf 的自留地 · 昙花一现

medium

  • 45. Jump Game II

    #Problem You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0]. Each element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at nums[i], you …

    medium todo
  • 2948. Make Lexicographically Smallest Array by Swapping Elements

    #Problem You are given a 0-indexed array of positive integers nums and a positive integer limit. In one operation, you can choose any two indices i and j and swap nums[i] and nums[j] if |nums[i] - nums[j]| <= limit. Return the …

    medium
  • 1267. Count Servers that Communicate

    #Problem You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communicate if they are on the same row …

    medium
  • 1561. Maximum Number of Coins You Can Get

    #Problem There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows: In each step, you will choose any 3 piles of coins (not necessarily consecutive). Of your choice, Alice will pick the pile with …

    medium
  • 2017. Grid Game

    #Problem You are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots are playing a game on this matrix. Both robots initially start at (0, 0) and want …

    medium
  • 2661. First Completely Painted Row or Column

    #Problem You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat both contain all the integers in the range [1, m * n]. Go through each index i in arr starting from index 0 and paint the cell in mat …

    medium
  • 2266. Count Number of Texts

    #Problem Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below. telephoneIn order to add a letter, Alice has to press the key of the corresponding digit i times, where i is the position of the …

    medium
  • 3097. Shortest Subarray With OR at Least K II

    #Problem 跟 3095. Shortest Subarray With OR at Least K I 一模一样,只是问题规模更大。 https://leetcode.cn/problems/shortest-subarray-with-or-at-least-k-ii/ Constraints: 1 <= nums.length <= 2 * 10⁵ 0 <= nums[i] <= 10⁹ 0 <= k <= 10⁹ #Test Cases python 复制 …

    medium
  • 2683. Neighboring Bitwise XOR

    #Problem A 0-indexed array derived with length n is derived by computing the bitwise XOR (⊕) of adjacent values in a binary array original of length n. Specifically, for each index i in the range [0, n - 1]: If i = n - 1, then derived[i] = …

    medium
  • 2425. Bitwise XOR of All Pairings

    #Problem You are given two 0-indexed arrays, nums1 and nums2, consisting of non-negative integers. There exists another array, nums3, which contains the bitwise XOR of all pairings of integers between nums1 and nums2 (every integer in nums1 …

    medium
  • 2429. Minimize XOR

    #Problem Given two positive integers num1 and num2, find the positive integer x such that: x has the same number of set bits as num2, and The value x XOR num1 is minimal. Note that XOR is the bitwise XOR operation. Return the integer x. The …

    medium
  • 3066. Minimum Operations to Exceed Threshold Value II

    #Problem You are given a 0-indexed integer array nums, and an integer k. In one operation, you will: Take the two smallest integers x and y in nums. Remove x and y from nums. Add min(x, y) * 2 + max(x, y) anywhere in the array. Note that …

    medium
  • 2657. Find the Prefix Common Array of Two Arrays

    #Problem You are given two 0-indexed integer permutations A and B of length n. A prefix common array of A and B is an array C such that C[i] is equal to the count of numbers that are present at or before the index i in both A and B. Return …

    medium
  • 3223. Minimum Length of String After Operations

    #Problem You are given a string s. You can perform the following process on s any number of times: Choose an index i in the string such that there is at least one character to the left of index i that is equal to s[i], and at least one …

    medium
  • 2116. Check if a Parentheses String Can Be Valid

    #Problem A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true: It is (). It can be written as AB (A concatenated with B), where A and B are valid parentheses …

    medium
  • 2275. Largest Combination With Bitwise AND Greater Than Zero

    #Problem The bitwise AND of an array nums is the bitwise AND of all integers in nums. For example, for nums = [1, 5, 3], the bitwise AND is equal to 1 & 5 & 3 = 1. Also, for nums = [7], the bitwise AND is 7. You are given an array of …

    medium
  • 1400. Construct K Palindrome Strings

    #Problem Given a string s and an integer k, return true if you can use all the characters in s to construct k palindrome strings or false otherwise. https://leetcode.com/problems/construct-k-palindrome-strings/ Example 1: Input: s = …

    medium
  • 916. Word Subsets

    #Problem You are given two string arrays words1 and words2. A string b is a subset of string a if every letter in b occurs in a including multiplicity. For example, "wrr" is a subset of "warrior" but is not a subset of "world". A string a …

    medium
  • 3297. Count Substrings That Can Be Rearranged to Contain a String I

    #Problem You are given two strings word1 and word2. A string x is called valid if x can be rearranged to have word2 as a prefix. A prefix of a string is a substring that starts from the beginning of the string and extends to any point …

    medium
  • 1186. Maximum Subarray Sum with One Deletion

    #Problem Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that …

    medium
  • 53. Maximum Subarray

    #Problem Given an integer array nums, find the subarray with the largest sum, and return its sum. A subarray is a contiguous non-empty sequence of elements within an array. https://leetcode.com/problems/maximum-subarray/ Example 1: Input: …

    medium
  • 1769. Minimum Number of Operations to Move All Balls to Each Box

    #Problem You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the iᵗʰ box is empty, and '1' if it contains one ball. In one operation, you can move one ball from a box to an adjacent box. Box i is …

    medium
  • 2274. Maximum Consecutive Floors Without Special Floors

    #Problem Alice manages a company and has rented some floors of a building as office space. Alice has decided some of these floors should be special floors, used for relaxation only. You are given two integers bottom and top, which denote …

    medium
  • 2381. Shifting Letters II

    #Problem You are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [startᵢ, endᵢ, directionᵢ]. For every i, shift the characters in s from the index startᵢ to the index endᵢ (inclusive) forward if …

    medium
  • 848. Shifting Letters

    #Problem You are given a string s of lowercase English letters and an integer array shifts of the same length. Call the shift() of a letter, the next letter in the alphabet, (wrapping around so that 'z' becomes 'a'). For example, shift('a') …

    medium
  • 2241. Design an ATM Machine

    #Problem There is an ATM machine that stores banknotes of 5 denominations: 20, 50, 100, 200, and 500 dollars. Initially the ATM is empty. The user can use the machine to deposit or withdraw any amount of money. When withdrawing, the machine …

    medium
  • 1930. Unique Length-3 Palindromic Subsequences

    #Problem Given a string s, return the number of unique palindromes of length three that are a subsequence of s. Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once. A palindrome is a …

    medium
  • 2270. Number of Ways to Split Array

    #Problem You are given a 0-indexed integer array nums of length n. nums contains a valid split at index i if the following are true: The sum of the first i + 1 elements is greater than or equal to the sum of the last n - i - 1 elements. …

    medium
  • 816. Ambiguous Coordinates

    #Problem We had some 2-dimensional coordinates, like "(1, 3)" or "(2, 0.5)". Then, we removed all commas, decimal points, and spaces and ended up with the string s. For example, "(1, 3)" becomes s = "(13)" and "(2, 0.5)" becomes s = …

    medium
  • 436. Find Right Interval

    #Problem You are given an array of intervals, where intervals[i] = [startᵢ, endᵢ] and each startᵢ is unique. The right interval for an interval i is an interval j such that startⱼ >= endᵢ and startⱼ is minimized. Note that i may equal j. …

    medium
  • 731. My Calendar II

    #Problem You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a triple booking. A triple booking happens when three events have some non-empty intersection (i.e., some moment is …

    medium
  • 581. Shortest Unsorted Continuous Subarray

    #Problem Given an integer array nums, you need to find one continuous subarray such that if you only sort this subarray in non-decreasing order, then the whole array will be sorted in non-decreasing order. Return the shortest such subarray …

    medium