All Questions
20 questions
3
votes
0
answers
58
views
Why does my recursive memoization function cause a 'Maximum Call Stack Exceeded' error in JavaScript?
While solving fabonocci problem using recursion and memoization in JavaScript, I got "Maximum Call Stack Exceeded" error when I try to run it with large inputs. To troubleshoot, I copied the ...
3
votes
1
answer
81
views
Return correct value at each iteration- dynamic programming
The problem goes like this:
Geek is going for n day training program. He can perform any one of these three activities Running, Fighting, and Learning Practice. Each activity has some point on each ...
0
votes
1
answer
182
views
Split Array problem. Need help in understanding another approach
I was solving this problem:
Given an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized.
Return the minimized largest sum ...
0
votes
0
answers
91
views
Javascript Time limit exceeded
I am trying to solve a dynamic programming problem on LeetCode using an object (obj) as a cache, but I am encountering a 'time limit exceeded' error if I initialize the object like this:
/**
* @param ...
0
votes
3
answers
80
views
Convert combination of object from Object
I want to covert combination of object from an object. For example:
Example:
var obj1 = {city: "Canada", pincode: [300005, 300006, 300007], locations: ["Toronto", "...
0
votes
1
answer
82
views
How can I add proper memoization to optimize this recursive algorithm
I am looking at this leetcode question where I write a function that takes an array of numbers and output the biggest sum of non-contiguous sub-arrays.
For example, if the array is [1,2,3,1], the ...
0
votes
2
answers
83
views
How does the outer variable in this recursive program not getting reset each time
Below is the program to find the shortest combination to achieve the target sum from a given list of array.
For e.g,
Target sum is 5,
and list of array is [2, 3, 5]
So possible output is [2, 3] and [5]...
0
votes
2
answers
29k
views
I am getting RangeError: Maximum call stack size exceeded error in Javascript
I am trying to solve a problem of leetcode through recursion but I am getting an error saying RangeError: Maximum call stack size exceeded maybe I am doing something wrong.
Problem:
Write an algorithm ...
0
votes
1
answer
152
views
Solve Nim Game Leetcode with Recusion(DP)
I am trying to solve the following leetcode problem of Nim Game.
https://leetcode.com/problems/nim-game/
One simple solution in O(1) is:
var canWinNim = function(n) {
return n%4 !== 0;
};
But ...
1
vote
2
answers
493
views
DFS Combination Sum, How to get only unique results?
I am solving LeetCode #49 Combination Sum. The idea is to find all the unique combinations that sum to the target.
It's fairly straight forward to find the permutations that add to the sum but I'm ...
0
votes
1
answer
74
views
C++: How passed variable in recursive function call behaves? Conditions to correctly modify it?
Could anyone please let me know why the following code in c++ doesn't work?
// count number of ways to construct a target string from a given set of strings
#include "bits/stdc++.h"
using ...
0
votes
1
answer
61
views
DP Solution Not Caching Properly - Time Out Error when input is ~70
I am trying to solve this problem: https://leetcode.com/problems/divisor-game/
My recursion itself seems to work but I get a time out error when the input is large enough ~ 70. I tried doing ...
0
votes
1
answer
177
views
Giving infinite as result when using matrix chain multiplication to find the efficient cost
I am trying to understand Matrix Chain Multiplication. Particularly the problem Given a sequence of matrices, find the most efficient way to multiply these matrices together.
I tried the following but ...
0
votes
3
answers
2k
views
LeetCode #70 Climbing Stairs, How to speed up my solution?
I have a solution to this problem on LeetCode #70 Climbing stairs, My solution is not passing, due to it being slow...
I have added a trampoline utilizing thunks and I've added Memoization, what ...
0
votes
1
answer
3k
views
Recursion: keeping track of a variable in all recursion paths when multiple sub paths are possible
I am trying to count how many times a pattern occurs as a subsequence of a string and also keep the indices where the match happens.
The counting is easy using recursive calls.
function count(str, ...