Given an array of integersContinue reading “[Leetcode problems]1477. Find Two Non-overlapping Sub-arrays Each With Target Sum”
arrand an integer
target. You have to find two non-overlapping sub-arrays of
arreach with sum equal
target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum. Return the minimum sum of the lengths of the two required sub-arrays, or return -1 if you cannot find such two sub-arrays. Example 1: Input: arr = [3,2,2,4,3], target = 3 Output: 2 Explanation: Only two sub-arrays have sum = 3 ( and ). The sum of their lengths is 2. Example 2: Input: arr = [7,3,4,7], target = 7 Output: 2 Explanation: Although we have three non-overlapping sub-arrays of sum = 7 (, [3,4] and ), but we will choose the first and third sub-arrays as the sum of their lengths is 2.
Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2. You have the following 3 operations permitted on a word: Insert a character Delete a character Replace a character Example: word1 = 'horse', word2 = 'ros' horse -> rorse (replace 'h' with 'r') rorse -> rose (remove 'r') rose -> ros (remove 'e')Continue reading “[Leetcode problems] 72. Edit Distance”
DFS is a searching algorithm that would go as far as possible before backtracking, and Dynamic Programming, referring to GeeksforGeeks, is an algorithmic paradigm that solves a given complex problem by breaking it into subproblems and stores the results of subproblems to avoid computing the same results again. What are connections do they share? Let me uncover this by a Leetcode problem: 494. Target Sum.Continue reading “Depth-First-Search(DFS) vs Dynamic Programming(DP)”