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

84. Largest Rectangle in Histogram

84. Largest Rectangle in Histogram Given an array of integers heights representing the histogram’s bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram. 1 2 3 4 5 6 Example 1: Input: heights = [2,1,5,6,2,3] Output: 10 Explanation: The above is a histogram where width of each bar is 1. The largest rectangle is shown in the red area, which has an area = 10 units....

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

1360. Number of Days Between Two Dates

1360. Number of Days Between Two Dates Write a program to count the number of days between two dates. The two dates are given as strings, their format is YYYY-MM-DD as shown in the examples. 1 2 3 4 5 6 7 8 9 Example 1: Input: date1 = "2019-06-29", date2 = "2019-06-30" Output: 1 Example 2: Input: date1 = "2020-01-15", date2 = "2019-12-31" Output: 15 Constraints: The given dates are valid dates between the years 1971 and 2100....

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

827. Making A Large Island

827. Making A Large Island 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. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Example 1: Input: grid = [[1,0],[0,1]] Output: 3 Explanation: Change one 0 to 1 and connect two 1s, then we get an island with area = 3....

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

1168. Optimize Water Distribution in a Village

1168. Optimize Water Distribution in a Village There are n houses in a village. We want to supply water for all the houses by building wells and laying pipes. For each house i, we can either build a well inside it directly with cost wells[i - 1] (note the -1 due to 0-indexing), or pipe in water from another well to it. The costs to lay pipes between houses are given by the array pipes, where each pipes[j] = [house1j, house2j, costj] represents the cost to connect house1j and house2j together using a pipe....

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

1528. Shuffle String

1528. Shuffle String 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 is the x coordinate of the left edge of the ith building....

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

1266. Minimum Time Visiting All Points

1266. Minimum Time Visiting All Points On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points. You can move according to these rules: In 1 second, you can either: move vertically by one unit, move horizontally by one unit, or move diagonally sqrt(2) units (in other words, move one unit vertically then one unit horizontally in 1 second)....

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

218. The Skyline Problem

218. The Skyline Problem 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 is the x coordinate of the left edge of the ith building....

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

270. Closest Binary Search Tree Value

270. Closest Binary Search Tree Value Given the root of a binary search tree and a target value, return the value in the BST that is closest to the target. 1 2 3 4 Example 1: Input: root = [4,2,5,1,3], target = 3.714286 Output: 4 1 2 3 4 Example 2: Input: root = [1], target = 4.428571 Output: 1 Constraints: The number of nodes in the tree is in the range [1, 104]....

<span title='2021-07-26 00:00:00 +0000 UTC'>July 26, 2021</span>&nbsp;·&nbsp;3 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