Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

1 vote
1 answer
62 views

Why backtracking is giving wrong results in case of 1st question and correct results for 2nd. Leetcode #322 #78 respectively

You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make ...
Ashna kohli's user avatar
0 votes
1 answer
44 views

Leetcode 1255-recursion and backtracking

I dont quite understand why have we used .clone() method when we have a second for loop to restore the letterCount.And when i'm runnig this code without .clone() method its giving me the wrong answer? ...
jonshrey's user avatar
2 votes
0 answers
223 views

minimum number of operations to get a target number

If there is a list of digits in string format, e.g. ["1", "5", "8"], list of valid operations are "+","-", and "*" and a target number. Find ...
Alan's user avatar
  • 471
0 votes
0 answers
57 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
124 views

Leetcode Prob No. 494 Target Sum ,,,,,Getting Runtime Error

In this code,i was getting this error... for input nums = Line 1034: Char 34: runtime error: addition of unsigned offset to 0x6250004d0900 overflowed to 0x6250004cf960 (stl_vector.h) SUMMARY: ...
Reborne's user avatar
2 votes
1 answer
73 views

Efficient Algorithm for Amount allocation problem

I am wondering if there is an efficient way to solve the following question. We have 2 groups of buckets, which is represented by number arrays. The number is the bucket size. The bucket size and the ...
xin's user avatar
  • 21
0 votes
1 answer
48 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
58 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
85 views

N-queen problem code working only till n=4

I am trying to solve the N-queen problem (Given an integer n find all ways of placing n queens on a n*n chess board such that no two queens attack each other) This is my code which works find till n = ...
Priyanshu Sahani's user avatar
0 votes
0 answers
329 views

Finding all possible unique combinations of numbers to reach a given sum

We have a list of numbers, let's say: [ 2, 3, 5 ] and we have a targetSum, let's say: 8 Our goal, then, is to pick numbers from the list in such a way that the sum of the numbers would lead to ...
Pratik Hadawale's user avatar
0 votes
0 answers
36 views

Minimize the maximum value of dynamically built array

I have n blocks , each of them is represented by it its height, i.e block[i] is a height of i.Need to build k towers, in such a way that maximum tower height should be minimized. I`ve implemented by ...
YAKOVM's user avatar
  • 10.1k
1 vote
1 answer
89 views

Maximum non negative product in a matrix

I am trying to solve the following problem on leetcode.com I found a resource asking a similar question but it didn't yield anything plausible. I am able to come up with a recursive backtracking ...
Spindoctor's user avatar
5 votes
1 answer
1k views

Why cannot Rat In a Maze problem be solved by dynamic programming?

The problem I am talking about is the one below : Consider a rat placed at (0, 0) in a square matrix m[ ][ ] of order n and has to reach the destination at (n-1, n-1). The task is to find a sorted ...
Sneha Sharma's user avatar
1 vote
1 answer
142 views

Backtracking problem find number of vehicles for minimal cost

I was trying to solve this problem: School attends competition. There are n students, who all need to arrive at the competition at the same time. The capacity of the bus is 50 students and it costs A ...
sara's user avatar
  • 59
2 votes
1 answer
211 views

Return N Optimal Choices for Multiple Choice Knapsack Variation

Problem I'm trying to return N optimal answers (for an exact number I want 250). From what I understand with dynamic programming is that it will return one most optimal answer. So I believe I have to ...
infamed's user avatar
  • 384

15 30 50 per page
1
2 3 4 5 6