[LeetCode] 2570. Merge Two 2D Arrays by Summing Values (Python)
·
알고리즘/LeetCode
난이도: EasyProblem DescriptionYou are given two 2D integer arrays nums1 and nums2.nums1[i] = [idi, vali] indicate that the number with the id idi has a value equal to vali.nums2[i] = [idi, vali] indicate that the number with the id idi has a value equal to vali.Each array contains unique ids and is sorted in ascending order by id. Merge the two arrays into one array that is sorted in ascending ord..
[LeetCode] 2460. Apply Operations to an Array (Python)
·
알고리즘/LeetCode
난이도: EasyProblem DescriptionYou are given a 0-indexed array nums of size n consisting of non-negative integers. You need to apply n - 1 operations to this array where, in the ith operation (0-indexed), you will apply the following on the ith element of nums:If nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. Otherwise, you skip this operation.After performing all the ..
[LeetCode] 1092. Shortest Common Supersequence (Python)
·
알고리즘/LeetCode
난이도: HardProblem Description Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them. A string s is a subsequence of string t if deleting some number of characters from t (possibly 0) results in the string s. Problem ExampleExample 1:Input: str1 = "abac", str2 = "cab"Output: "cabac"Explanatio..
[LeetCode] 873. Length of Longest Fibonacci Subsequence (Python)
·
알고리즘/LeetCode
난이도: MediumProblem DescriptionA sequence x1, x2, ..., xn is Fibonacci-like if:n >= 3xi + xi+1 == xi+2 for all i + 2 Given a strictly increasing array arr of positive integers forming a sequence, return the length of the longest Fibonacci-like subsequence of arr. If one does not exist, return 0. A subsequence is derived from another sequence arr by deleting any number of elements (including none)..
[LeetCode] 1749. Maximum Absolute Sum of Any Subarray (Python)
·
알고리즘/LeetCode
난이도: MediumProblem Description You are given an integer array nums. The absolute sum of a subarray [numsl, numsl+1, ..., numsr-1, numsr] is abs(numsl + numsl+1 + ... + numsr-1 + numsr). Return the maximum absolute sum of any (possibly empty) subarray of nums. Note that abs(x) is defined as follows:If x is a negative integer, then abs(x) = -x.If x is a non-negative integer, then abs(x) = x. Probl..
[LeetCode] 1524. Number of Sub-arrays With Odd Sum (Python)
·
알고리즘/LeetCode
난이도: MediumProblem DescriptionGiven an array of integers arr, return the number of subarrays with an odd sum. Since the answer can be very large, return it modulo 109 + 7.  Problem ExampleExample 1:Input: arr = [1,3,5]Output: 4Explanation: All subarrays are [[1],[1,3],[1,3,5],[3],[3,5],[5]]All sub-arrays sum are [1,4,9,3,8,5].Odd sums are [1,9,3,5] so the answer is 4.Example 2:Input: arr = [2,4,..