[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,..
[LeetCode] 2467. Most Profitable Path in a Tree (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. At every node i, there is a gate. You are also given an array of even integers amount, where amount[i] represents:the price needed to open the gate ..
[LeetCode] 2196. Create Binary Tree From Descriptions (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명 You are given a 2D integer array descriptions where descriptions[i] = [parenti, childi, isLefti] indicates that parenti is the parent of childi in a binary tree of unique values. Furthermore, If isLefti == 1, then childi is the left child of parenti.If isLefti == 0, then childi is the right child of parenti. Construct the binary tree described by descriptions and return its root..