全站内容
medium
2353. Design a Food Rating System
#Problem Design a food rating system that can do the following: Modify the rating of a food item listed in the system. Return the highest-rated food item for a type of cuisine in the system. Implement the FoodRatings class: …
873. Length of Longest Fibonacci Subsequence
#Problem A sequence x₁, x₂, ..., xₙ is Fibonacci-like if: n >= 3 xᵢ + xᵢ₊₁ == xᵢ₊₂ for all i + 2 <= n Given a strictly increasing array arr of positive integers forming a sequence, return the length of the longest Fibonacci-like subsequence …
1524. Number of Sub-arrays With Odd Sum
#Problem Given an array of integers arr, return the number of subarrays with an odd sum. Since the answer can be very large, return it modulo 10⁹ + 7. https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum/ Example 1: Input: arr = …
1749. Maximum Absolute Sum of Any Subarray
#Problem You are given an integer array nums. The absolute sum of a subarray [numsₗ, numsₗ₊₁, ..., numsᵣ₋₁, numsᵣ] is abs(numsₗ + numsₗ₊₁ + ... + numsᵣ₋₁ + numsᵣ). Return the maximum absolute sum of any (possibly empty) subarray of nums. …
1472. Design Browser History
#Problem You have a browser of one tab where you start on the homepage and you can visit another url, get back in the history number of steps or move forward in the history number of steps. Implement the BrowserHistory class: …
2502. Design Memory Allocator
#Problem You are given an integer n representing the size of a 0-indexed memory array. All memory units are initially free. You have a memory allocator with the following functionalities: Allocate a block of size consecutive free memory …
2467. Most Profitable Path in a Tree
#Problem There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. 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 …
889. Construct Binary Tree from Preorder and Postorder Traversal
#Problem Given two integer arrays, preorder and postorder where preorder is the preorder traversal of a binary tree of distinct values and postorder is the postorder traversal of the same tree, reconstruct and return the binary tree. If …
1261. Find Elements in a Contaminated Binary Tree
#Problem Given a binary tree with the following rules: root.val == 0 For any treeNode: If treeNode.val has a value x and treeNode.left != null, then treeNode.left.val == 2 * x + 1 If treeNode.val has a value x and treeNode.right != null, …
1980. Find Unique Binary String
#Problem Given an array of strings nums containing n unique binary strings each of length n, return a binary string of length n that does not appear in nums. If there are multiple answers, you may return any of them. …