I am doing a Hackerrank challenge 'Manasa and Stones'
I have already done an Looping solution but it took to much time solving tree levels and I need a recursive solution I guess.
function stones(n, a, b) {
var arr = [0,0];
var rresult = recursive(0,a,b,arr,n)
return rresult;
}
function recursive(n,a,b,arr,end){
if (n == end){ return arr }
else {
let arr2 = arr.map(function(x) {
return x * 2;
});
arr = arr.map(function(x) {
return x * 2;
});
arr = arr.join(arr2)
recursive(n,a,b,arr,end)
}
}
It should be working as expected to solve https://www.hackerrank.com/contests/microverse-coding-challenges/challenges/manasa-and-stones/problem (I don't from expect you to do a solution I need to know why my issue is there * It doesn't make sense)
all my code => https://github.com/Macatuz/MHackerrankSamples/blob/master/Manasa_and_Stones.js
elsecode inrecursivedoes not return anything, chances arerresultwill more often than not beundefined(except when stones is called with first argument == 0) - in all other cases however, I believe you'll end up with an infinite recursion, sincen == endwill never be true (once you fix the issue as noted in the answer below)