Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
65 views

A permutations problem (LeetCode), which finds the permutations of an array [1,2,3], is returning an empty array through a backtracking recursive function. The console prints out the following: Input ...
Will Sherman's user avatar
0 votes
0 answers
122 views

I tried updating my code to this version but still, it doesn t work: using System; namespace RecursiveDomino { class Program { static void Main() { int n = Convert....
Bro's user avatar
  • 1
1 vote
1 answer
79 views

I have been following a playlist of Java for data structures and algorithms and I have come across the topic of Backtracking in which a board is given to you along with starting point (0,0) and end ...
Aadit Baldha's user avatar
-2 votes
2 answers
181 views

Currently I am studying Data Structure and Algorithmic thinking with python by Narasimha Karumanchi. But I can't understand one question which is as follows: Q. Generate all the binary strings with n-...
Abhishek Singh's user avatar
-1 votes
1 answer
48 views

I'm new to Java and I'm trying to build a sudoku solver programm using backtracking and an int[][] matrix. Function usage: isSafeSudoku() this function checks whether the digit (from 1 to 9) is safe ...
Vipul's user avatar
  • 1
0 votes
1 answer
65 views

Ok, I have been trying to find the mistake in my code or the place where it changes from the given code. There are two codes here code #1- class Solution { public List<List<Integer>> ...
Rai's user avatar
  • 11
-3 votes
1 answer
84 views

I was solving this task: Let us consider the problem of calculating the number of paths in an n × n grid from the upper-left corner to the lower-right corner such that the path visits each square ...
qdqdqd's user avatar
  • 9
0 votes
2 answers
110 views

Problem : Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target. Each number in ...
yukkk's user avatar
  • 1
1 vote
1 answer
252 views

I am trying to solve LeetCode problem 1601. Maximum Number of Achievable Transfer Requests : We have n buildings numbered from 0 to n - 1. Each building has a number of employees. It's transfer ...
nanosoft's user avatar
  • 3,121
0 votes
1 answer
630 views

I'm currently working on a permutation algorithm in Python, and I'm having trouble understanding how the for loop inside the backtrack function works. I would appreciate it if someone could provide a ...
user avatar
1 vote
1 answer
160 views

In some cases, like the "hasPathSum" problem, where we are checking for a specific condition (e.g., targetSum == 0) at leaf nodes, we don't need manual backtracking. The recursion naturally ...
LaughTale's user avatar
0 votes
1 answer
63 views

#include <iostream> #include <vector> using namespace std; void getAns(char s, vector<char> current, vector<vector<char>> &ans, int n, int i){ if (i >= n) { ...
Chinmay Agarwal's user avatar
1 vote
2 answers
2k views

I am working on LeetCode problem 46. Permutations: Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. I thought to solve this ...
peter todds's user avatar
0 votes
1 answer
2k views

The problem can be accessed from this link https://leetcode.com/problems/optimal-account-balancing/ *** Didn't realize this was only accessible by premium members, here is the problem statement and ...
Kang_the_Conqueror's user avatar
1 vote
1 answer
118 views

I am using recursion with backtracking, i have used multiple recursion call My code snippet : - func test(currentIndex: Int, op: inout [Int]) { if currentIndex > 1 { print("exit ...
Amit's user avatar
  • 675
0 votes
0 answers
26 views

In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the ...
Aniket Ingawale's user avatar
0 votes
0 answers
89 views

I am trying to create a sudoku solver that uses recursive backtracking, however, I am not using any for loops in my program. This makes it difficult since when using the backtracking method, I need to ...
Eric Martin's user avatar
0 votes
2 answers
232 views

I'm having trouble writing a Backtracking algorithm (Sudoku Solver) for my Sudoku project. My idea is to create a 2D array variable "initial" as an initializer array to push into the player'...
Tran Phat Trien's user avatar
0 votes
3 answers
45 views

I was trying a Backtracking problem (SudokuSolver) I am getting an error which no-one could resolve or even understand. Hence I am seeking help here. The problem is as follows: And the main function/...
Parth Khandenath's user avatar
-2 votes
1 answer
39 views

How to update and return count variable to outside of fucntion in python. for input : [[0,0,0],[0,1,0],[0,0,0]] std out : 1 1 #as count is incrementing inside function but in each recursion it's ...
jxswxnth's user avatar
1 vote
1 answer
231 views

class Solution: def generateParenthesis(self, n: int) -> List[str]: ans = [] def backtrack(S, left, right): if len(S) == 2 * n: ans.append(''.join(S))...
R__'s user avatar
  • 87
1 vote
1 answer
656 views

This is a classic backtracking problem , i dont know why we need to copy arr element inside recursive function in order for it to work correctly. If i dont copy. It will return blank array def subsets(...
ms1241721's user avatar
0 votes
1 answer
231 views

I want to print all paths from source node to destination node, and the costs of these paths. So far, I have the following code: // Find all paths from source to destination. void search(Graph* graph, ...
Varnion's user avatar
2 votes
0 answers
233 views

I'm trying to solve the "Coin Change Problem" by implementing a recursive backtracking algorithm which will analyze all possible outcomes and show the optimal combination of coins. ...
Mar's user avatar
  • 43
0 votes
2 answers
147 views

I'm trying to solve a backtracking problem in python. Not only should my code be able to identify and reach the goal, but also output the quickest path to it. The maze is looks like this: xxxxxxx xSx ...
Ashtonville's user avatar

1
2 3 4 5
7