1503. Last Moment Before All Ants Fall Out of a Plank

We have a wooden plank of the length n units. Some ants are walking on the plank, each ant moves with speed 1 unit per second. Some of the ants move to the left, the other move to the right. When two ants moving in two different directions meet at some point, they change their directions and continue moving again. Assume changing directions doesn’t take any additional time. When an ant reaches one end of the plank at a time t, it falls out of the plank imediately....

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

1546. Maximum Number of Non-Overlapping Subarrays With Sum Equals Target

Given an array nums and an integer target. Return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Example 1: Input: nums = [1,1,1,1,1], target = 2 Output: 2 Explanation: There are 2 non-overlapping subarrays [1,1,1,1,1] with sum equals to target(2)....

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

1027. Longest Arithmetic Subsequence

Given an array nums of integers, return the length of the longest arithmetic subsequence in nums. Recall that a subsequence of an array nums is a list nums[i1], nums[i2], …, nums[ik] with 0 <= i1 < i2 < … < ik <= nums.length - 1, and that a sequence seq is arithmetic if seq[i+1] - seq[i] are all the same value (for 0 <= i < seq.length - 1)....

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

128. Longest Consecutive Sequence

Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. 1 2 3 4 5 Example 1: Input: nums = [100,4,200,1,3,2] Output: 4 Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4. 1 2 3 4 Example 2: Input: nums = [0,3,7,2,5,8,4,6,0,1] Output: 9 Constraints: 0 <= nums....

<span title='2021-09-20 00:00:00 +0000 UTC'>September 20, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

16. 3Sum Closest

Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution. 1 2 3 4 5 6 7 8 9 10 Example 1: Input: nums = [-1,2,1,-4], target = 1 Output: 2 Explanation: The sum that is closest to the target is 2....

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

350. Intersection of Two Arrays II

350. Intersection of Two Arrays II Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order. 1 2 3 4 5 6 7 8 9 10 Example 1: Input: nums1 = [1,2,2,1], nums2 = [2,2] Output: [2,2] Example 2: Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4] Output: [4,9] Explanation: [9,4] is also accepted....

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

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

977. Squares of a Sorted Array

977. Squares of a Sorted Array Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. 1 2 3 4 5 6 7 8 9 10 11 Example 1: Input: nums = [-4,-1,0,3,10] Output: [0,1,9,16,100] Explanation: After squaring, the array becomes [16,1,0,9,100]. After sorting, it becomes [0,1,9,16,100]. Example 2: Input: nums = [-7,-3,2,3,11] Output: [4,9,9,49,121] Constraints: 1 <= nums....

<span title='2021-07-19 00:00:00 +0000 UTC'>July 19, 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

1213. Intersection of Three Sorted Arrays

1213. Intersection of Three Sorted Arrays Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a sorted array of only the integers that appeared in all three arrays. 1 2 3 4 5 6 7 8 9 10 Example 1: Input: arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8] Output: [1,5] Explanation: Only 1 and 5 appeared in the three arrays. Example 2: Input: arr1 = [197,418,523,876,1356], arr2 = [501,880,1593,1710,1870], arr3 = [521,682,1337,1395,1764] Output: [] Constraints:...

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

1329. Sort the Matrix Diagonally

1329. Sort the Matrix Diagonally A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix’s end. For example, the matrix diagonal starting from mat[2][0], where mat is a 6 x 3 matrix, includes cells mat[2][0], mat[3][1], and mat[4][2]. Given an m x n matrix mat of integers, sort each matrix diagonal in ascending order and return the resulting matrix....

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

1099. Two Sum Less Than K

1099. Two Sum Less Than K Given an array nums of integers and integer k, return the maximum sum such that there exists i < j with nums[i] + nums[j] = sum and sum < k. If no i, j exist satisfying this equation, return -1. 1 2 3 4 5 6 7 8 9 10 11 Example 1: Input: nums = [34,23,1,24,75,33,54,8], k = 60 Output: 58 Explanation: We can use 34 and 24 to sum 58 which is less than 60....

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

1897. Redistribute Characters to Make All Strings Equal

1897. Redistribute Characters to Make All Strings Equal You are given an array of strings words (0-indexed). In one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j]. Return true if you can make every string in words equal using any number of operations, and false otherwise. 1 2 3 4 5 6 7 8 9 10 11 12 13 Example 1: Input: words = ["abc","aabc","bc"] Output: true Explanation: Move the first 'a' in words[1] to the front of words[2], to make words[1] = "abc" and words[2] = "abc"....

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

1899. Merge Triplets to Form Target Triplet

1899. Merge Triplets to Form Target Triplet A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet. You are also given an integer array target = [x, y, z] that describes the triplet you want to obtain. To obtain target, you may apply the following operation on triplets any number of times (possibly zero):...

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