Skip to content
Advertisement

Tag: dynamic-programming

Can someone explain canSum to me please

The question states: Write a function canSum(targetSum, numbers) that takes in a targetSum and an array of numbers as arguments. The function should return a boolean indicating whether or not it is possible to generate the targetSum using numbers from the array. You may use an element of an array as many times as needed. You may assume that all

Why does howSum solution work in Javascript but not in Python? (Dynamic programming)

This is a follow-up to this question asked on Stack Overflow. Write a function ‘howSum(targetSum, numbers)’ that takes in a targetSum and an array of numbers as arguments. The function should return an array containing any combination of elements that add up to exactly the targetSum. If there is no combination that adds up to the targetSum, then return None.

Why does this solution work in Javascript but not in Python? (Dynamic programming)

I’m following this tutorial about dynamic programming and I’m struggling to implement memoization in the following problem: *Write a function called canSum(targetSum, numbers) that returns True only if the numbers in the array can sum to the target sum. All the numbers in the array are positive integers and you can use them more than once for the solution. Example:

Maximum Length of Repeated Subarray (leetcode)

I’m looking at this leetcode question, and am having an issue completing the naive approach. I was able to come to an optimal solution here. But I’m not sure what’s wrong with my naive attempt. The question is as follows: Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays. Example:

Advertisement