All Questions
142 questions
2
votes
3
answers
868
views
Maximum Sum Without Skipping Two Contiguous Elements
The task is to find the maximum sum of a subsequence of integers from a given list. The subsequence must follow two conditions:
It must be contiguous, meaning the selected elements are in consecutive ...
0
votes
1
answer
337
views
Trouble Solving Maximum Product Subarray
I am trying to solve LeetCode problem 152. Maximum Product Subarray:
Given an integer array nums, find a subarray* that has the largest product, and return the product.
The test cases are generated ...
0
votes
1
answer
84
views
How is it possible to memoize longest divisible subset using only the length (and end position)?
The goal is to find the largest divisible subset. A divisible subset is a subset s.t. for every pair of elements i, j, either i is divisible by j or j is divisible by i. The general approach to solve ...
2
votes
1
answer
69
views
Issue with Memoization in Recursive Function for Finding Combinations Summing to Target
I need to write the following function:
Write a function that takes in a target (int) and a list of ints. The function should return a list of any combination of elements that add up to the target, ...
0
votes
1
answer
274
views
LeetCode - Minimum Falling Path Sum - question on memoization
I am trying to solve this leetcode problem: https://leetcode.com/problems/minimum-falling-path-sum/description
Given an n x n array of integers matrix, return the minimum sum of any falling path ...
1
vote
2
answers
109
views
Dynamic Programming Matrix Calculation Issue
Selling rods business where each rod's price depends on its length. Given a price table T, where T[i] is the price ($) of a rod of length i, the task is to cut a rod of length l into pieces to ...
1
vote
1
answer
269
views
DP array 0th element is initialized as 1 instead of 0
I encountered the LeetCode climbStairs problem:
You are climbing a staircase. It takes n steps to reach the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb ...
1
vote
1
answer
116
views
Getting Run Time error for a Kattis Problem(robotsonagrid)
I am trying to solve this problem (https://open.kattis.com/problems/robotsonagrid).
And when I submit my final code I keep getting a Run Time error in Test case 4. I am not sure what's wrong with my ...
1
vote
0
answers
22
views
Inconsistent output on leetcode and vs code [duplicate]
class Solution:
def combinationSum4(self, nums: List[int], target: int,memo={}) -> int:
if target in memo:
return memo[target]
if target==0:
return 1
...
0
votes
1
answer
52
views
while doing subset sum whose sum equals to B i am not able to get correct result
the code is very simple i am taking or not taking an element from A array and using left i am keeping track left sum it is interview bit problem
Subset Sum Problem!
class Solution:
def solve(self,...
0
votes
2
answers
100
views
What's the difference between these two code fragments?
I'm working on this Leetcode question. I cannot figure out the difference between my commented and uncommented code below. I'm returning an array at the base-case of a recursion, so when I call the dp(...
0
votes
1
answer
261
views
0/1 Knapsack Problem with Dynamic Programming
This is my attempt at the problem asked in this thread. When I try to run it with input egg_weights = (1,5,10,25) and n = 99, it seems to run into an infinite loop. The code seems to give the correct ...
1
vote
3
answers
130
views
Python Dynamic Programming Problem - ( 2 dimension recursion stuck in infinite loop )
In the book "A Practical Guide to Quantitative Finance Interview", there is a question called Dynamic Card Game, 5.3 Dynamic Programming)
The solution according to the book is basically the ...
0
votes
1
answer
49
views
Error: variable not storing modified value on recursion
I am finding count of all the ways a target is reached. In base case, i am updating the value but when returning, it is taking the initial value only. How to change it to updated value, Kindly help me ...
0
votes
1
answer
183
views
maximum word split using Recursion
Given a string s and a dictionary of valid words d, determine the largest number of valid words the string can be split up into using Recursion
I tried solving this problem with the code below but it ...