34. Find First and Last Position of Element in Sorted Array

Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. You must write an algorithm with O(log n) runtime complexity. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Example 1: Input: nums = [5,7,7,8,8,10], target = 8 Output: [3,4] Example 2: Input: nums = [5,7,7,8,8,10], target = 6 Output: [-1,-1] Example 3: Input: nums = [], target = 0 Output: [-1,-1] Constraints:...

<span title='2021-11-13 00:00:00 +0000 UTC'>November 13, 2021</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;volyx

704. Binary Search

Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You must write an algorithm with O(log n) runtime complexity. 1 2 3 4 5 6 7 8 9 10 11 Example 1: Input: nums = [-1,0,3,5,9,12], target = 9 Output: 4 Explanation: 9 exists in nums and its index is 4 Example 2: Input: nums = [-1,0,3,5,9,12], target = 2 Output: -1 Explanation: 2 does not exist in nums so return -1 Constraints:...

<span title='2021-11-09 00:00:00 +0000 UTC'>November 9, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

981. Time Based Key-Value Store

Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key’s value at a certain timestamp. Implement the TimeMap class: TimeMap() Initializes the object of the data structure. void set(String key, String value, int timestamp) Stores the key key with the value value at the given time timestamp. String get(String key, int timestamp) Returns a value such that set was called previously, with timestamp_prev <= timestamp....

<span title='2021-10-21 00:00:00 +0000 UTC'>October 21, 2021</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;volyx

528. Random Pick with Weight

You are given a 0-indexed array of positive integers w where w[i] describes the weight of the ith index. You need to implement the function pickIndex(), which randomly picks an index in the range [0, w.length - 1] (inclusive) and returns it. The probability of picking an index i is w[i] / sum(w). For example, if w = [1, 3], the probability of picking index 0 is 1 / (1 + 3) = 0....

<span title='2021-10-08 00:00:00 +0000 UTC'>October 8, 2021</span>&nbsp;·&nbsp;4 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

1235. Maximum Profit in Job Scheduling

1235. Maximum Profit in Job Scheduling We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i]. You’re given the startTime, endTime and profit arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range. If you choose a job that ends at time X you will be able to start another job that starts at time X....

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

1428. Leftmost Column with at Least a One

1428. Leftmost Column with at Least a One This problem is an interactive problem.) A row-sorted binary matrix means that all elements are 0 or 1 and each row of the matrix is sorted in non-decreasing order. Given a row-sorted binary matrix binaryMatrix, return the index (0-indexed) of the leftmost column with a 1 in it. If such an index does not exist, return -1. You can’t access the Binary Matrix directly....

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

162. Find Peak Element

162. Find Peak Element A peak element is an element that is strictly greater than its neighbors. Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks. You may imagine that nums[-1] = nums[n] = -∞. You must write an algorithm that runs in O(log n) time. 1 2 3 4 5 6 7 8 9 10 11 Example 1: Input: nums = [1,2,3,1] Output: 2 Explanation: 3 is a peak element and your function should return the index number 2....

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

240. Search a 2D Matrix II

240. Search a 2D Matrix II Write an efficient algorithm that searches for a target value in an m x n integer matrix. The matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each column are sorted in ascending from top to bottom. 1 2 3 4 Example 1: Input: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5 Output: true 1 2 3 4 Example 2: Input: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20 Output: false Constraints:...

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

74. Search a 2D Matrix

74. Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first integer of each row is greater than the last integer of the previous row. 1 2 3 4 Example 1: Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3 Output: true 1 2 3 4 Example 2: Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13 Output: false Constraints:...

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

1898. Maximum Number of Removable Characters

1898. Maximum Number of Removable Characters You are given two strings s and p where p is a subsequence of s. You are also given a distinct 0-indexed integer array removable containing a subset of indices of s (s is also 0-indexed). You want to choose an integer k (0 <= k <= removable.length) such that, after removing k characters from s using the first k indices in removable, p is still a subsequence of s....

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