907. Sum of Subarray Minimums

907. Sum of Subarray Minimums Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 109 + 7. 1 2 3 4 5 6 7 8 9 10 11 12 13 Example 1: Input: arr = [3,1,2,4] Output: 17 Explanation: Subarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,2,4], [3,1,2,4]....

<span title='2021-08-25 00:00:00 +0000 UTC'>August 25, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

398. Random Pick Index

398. Random Pick Index Given an integer array nums with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array. Implement the Solution class: Solution(int[] nums) Initializes the object with the array nums. int pick(int target) Picks a random index i from nums where nums[i] == target. If there are multiple valid i’s, then each index should have an equal probability of returning....

<span title='2021-08-23 00:00:00 +0000 UTC'>August 23, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

364. Nested List Weight Sum II

364. Nested List Weight Sum II You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. The depth of an integer is the number of lists that it is inside of. For example, the nested list [1,[2,2],[[3],2],1] has each integer’s value set to its depth. Let maxDepth be the maximum depth of any integer....

<span title='2021-08-20 00:00:00 +0000 UTC'>August 20, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

901. Online Stock Span

901. Online Stock Span Design an algorithm that collects daily price quotes for some stock and returns the span of that stock’s price for the current day. The span of the stock’s price today is defined as the maximum number of consecutive days (starting from today and going backward) for which the stock price was less than or equal to today’s price. For example, if the price of a stock over the next 7 days were [100,80,60,70,60,75,85], then the stock spans would be [1,1,1,2,1,4,6]....

<span title='2021-08-19 00:00:00 +0000 UTC'>August 19, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

1762. Buildings With an Ocean View

1762. Buildings With an Ocean View There are n buildings in a line. You are given an integer array heights of size n that represents the heights of the buildings in the line. The ocean is to the right of the buildings. A building has an ocean view if the building can see the ocean without obstructions. Formally, a building has an ocean view if all the buildings to its right have a smaller height....

<span title='2021-08-18 00:00:00 +0000 UTC'>August 18, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

71. Simplify Path

71. Simplify Path Given a string path, which is an absolute path (starting with a slash ‘/’) to a file or directory in a Unix-style file system, convert it to the simplified canonical path. In a Unix-style file system, a period ‘.’ refers to the current directory, a double period ‘..’ refers to the directory up a level, and any multiple consecutive slashes (i.e. ‘//’) are treated as a single slash ‘/’....

<span title='2021-07-26 00:00:00 +0000 UTC'>July 26, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

134. Gas Station

134. Gas Station There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations. Given two integer arrays gas and cost, return the starting gas station’s index if you can travel around the circuit once in the clockwise direction, otherwise return -1....

<span title='2021-07-24 00:00:00 +0000 UTC'>July 24, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

287. Find the Duplicate Number

287. Find the Duplicate Number Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nums, return this repeated number. You must solve the problem without modifying the array nums and uses only constant extra space. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Example 1: Input: nums = [1,3,4,2,2] Output: 2 Example 2: Input: nums = [3,1,3,4,2] Output: 3 Example 3: Input: nums = [1,1] Output: 1 Example 4: Input: nums = [1,1,2] Output: 1 Constraints:...

<span title='2021-07-24 00:00:00 +0000 UTC'>July 24, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

621. Task Scheduler

621. Task Scheduler Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle. However, there is a non-negative integer n that represents the cooldown period between two same tasks (the same letter in the array), that is that there must be at least n units of time between any two same tasks....

<span title='2021-07-24 00:00:00 +0000 UTC'>July 24, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

314. Binary Tree Vertical Order Traversal

314. Binary Tree Vertical Order Traversal Given the root of a binary tree, return the vertical order traversal of its nodes’ values. (i.e., from top to bottom, column by column). If two nodes are in the same row and column, the order should be from left to right. 1 2 3 4 Example 1: Input: root = [3,9,20,null,null,15,7] Output: [[9],[3,15],[20],[7]] 1 2 3 4 Example 2: Input: root = [3,9,8,4,0,1,7] Output: [[4],[9],[3,0,1],[8],[7]] 1 2 3 4 Example 3: Input: root = [3,9,8,4,0,1,7,null,null,null,2,5] Output: [[4],[9,5],[3,0,1],[8,2],[7]] 1 2 3 4 Example 4: Input: root = [] Output: [] Constraints:...

<span title='2021-07-22 00:00:00 +0000 UTC'>July 22, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

515. Find Largest Value in Each Tree Row

515. Find Largest Value in Each Tree Row Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed). 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Example 1: Input: root = [1,3,2,5,3,null,9] Output: [1,3,9] Example 2: Input: root = [1,2,3] Output: [1,3] Example 3: Input: root = [1] Output: [1] Example 4: Input: root = [1,null,2] Output: [1,2] Example 5: Input: root = [] Output: [] Constraints:...

<span title='2021-07-19 00:00:00 +0000 UTC'>July 19, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

791. Custom Sort String

791. Custom Sort String You are given two strings order and s. All the words of order are unique and were sorted in some custom order previously. Permute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a character y in order, then x should occur before y in the permuted string. Return any permutation of s that satisfies this property....

<span title='2021-07-19 00:00:00 +0000 UTC'>July 19, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

1482. Minimum Number of Days to Make m Bouquets

1482. Minimum Number of Days to Make m Bouquets Given an integer array bloomDay, an integer m and an integer k. We need to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden. The garden consists of n flowers, the ith flower will bloom in the bloomDay[i] and then can be used in exactly one bouquet. Return the minimum number of days you need to wait to be able to make m bouquets from the garden....

<span title='2021-07-17 00:00:00 +0000 UTC'>July 17, 2021</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;volyx

475. Heaters

475. Heaters Winter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses. Every house can be warmed, as long as the house is within the heater’s warm radius range. Given the positions of houses and heaters on a horizontal line, return the minimum radius standard of heaters so that those heaters could cover all houses....

<span title='2021-07-17 00:00:00 +0000 UTC'>July 17, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

325. Maximum Size Subarray Sum Equals k

325. Maximum Size Subarray Sum Equals k Given an integer array nums and an integer k, return the maximum length of a subarray that sums to k. If there isn’t one, return 0 instead. 1 2 3 4 5 6 7 8 9 10 11 Example 1: Input: nums = [1,-1,5,-2,3], k = 3 Output: 4 Explanation: The subarray [1, -1, 5, -2] sums to 3 and is the longest. Example 2: Input: nums = [-2,-1,2,1], k = 1 Output: 2 Explanation: The subarray [-1, 2] sums to 1 and is the longest....

<span title='2021-07-16 00:00:00 +0000 UTC'>July 16, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx