Skip to main content

All Questions

0 votes
0 answers
66 views

Partition list of numbers into groups that sum to specific sums

I have a list of sums such as [7,6] and a list of numbers that will sum to the list of sums. For instance, [4,3,2,2,2]. Numbers in each list could be randomized. The goal is to return a result array ...
ViridTomb's user avatar
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 ...
Sourya's user avatar
  • 1
1 vote
2 answers
73 views

Return all possible placements of buildings in a city grid using backtracking

I have two inputs An NxM city grid where empty spaces represent vacant lots, and X's represent filled lots e.g X XXX X X XXXX XX X This is in the format List[List[str]] And an integer that ...
Baeby's user avatar
  • 25
0 votes
0 answers
208 views

I have an assignment where I need to check whether I can partition a set into two subset that are equal in sum

I have an assignment where I need to check whether I can partition a set into two subsets that are equal in sum and output the subset as a result. For example [[[1,1,2,2,2,3,5,5,9] gives you a result ...
WhispeR's user avatar
1 vote
1 answer
263 views

Recurive Backtracking: Leet Code - Remove Boxes (Python)

I was working on this leetcode: https://leetcode.com/problems/remove-boxes/ and my answer is only slightly off for certain test cases. Any advice would be appreciated. The problem is outlined as the ...
Jorge's user avatar
  • 31
1 vote
1 answer
3k views

THE HUNGRY FISH problem: Infected Fish can eat another fish having size less that its own. Minimum number of operation required

An evil scientist has developed an injection that induces insatiable hunger in a fish. On giving this injection, a fish of size x can eat another fish of smaller size y (y < x) and become a fish of ...
Rakesh Reddy's user avatar
0 votes
1 answer
500 views

Variable not being changed during recursive backtracking algorithm

I am using recursion and backtracking to solve a problem. I am updating the variable called minimum whenever a certain condition is met. However, despite the minimum variable being updated several ...
Daniel's user avatar
  • 93
0 votes
1 answer
2k views

How to implement backtracking to print the items taken in knapsack(repetition of items allowed)?

I have this list of lists: [['0', 'Cool Blue Marella Jug', '33', '15'], ['1', 'Weight Loss Pack', '55', '16'], ['2', 'Natural Black Vogue Lashes', '10', '6'], ['3', 'Paris Age Perfect Intense ...
Sook Lim's user avatar
  • 551
0 votes
1 answer
640 views

Subset Sum in python using DP

I'm following this link to write a DP solution for Subset problem. def subsetSum(input, target): row, col = len(input)+1, target+1 db = [[False] * col] * row for i in range(row): ...
Satish Jonnala's user avatar
0 votes
1 answer
1k views

python recursion: create all possible sentence of certain length using a key-value dictionary of word

So, let's say we have a dictionary >>> dictionary {'and': ['the'], 'the': ['cat', 'dog'], 'cat': ['and']} We want to create all possible sentences of certain length (say 5 in our case), ...
melatonin15's user avatar
  • 2,289
1 vote
0 answers
546 views

Hashing an unordered list of lists in python

I am coding a backtracking depth first search algorithm that has many answers. I want all of them, but I know I am doing redundant work. (in fact over k! times, where k is the number of sets) I have ...
Kenneth Goodman's user avatar