When dealing with permutations of a string, one common issue arises: duplicates. For example, with input like "AAB", the total number of permutations would be 6 (3!), but many of them would be repeated. We aim to generate all unique permutations in l...
Solving Sudoku manually is fun — but building a Sudoku solver from scratch in code? That’s where the real magic begins. In this blog, I’ll walk you through how I built an interactive 9x9 Sudoku game with a built-in solver using JavaScript, HTML/CSS, ...
Description: You're given two strings str1 and str2, both of equal length, made up of only the characters 'x', 'y', and 'z'. Your task is to transform str1 into str2 using the minimum number of character replacements, with one constraint: ➡️ At no po...
Today wasn’t my most productive day. The day started with an early morning interview call, and honestly, it didn’t go as expected. That set a dull tone for the rest of the day. I found myself distracted and not fully in the zone. Still, I managed to ...
Problem https://leetcode.com/problems/most-profitable-path-in-a-tree/description/ Leetcode - Most Profitable Path in a Tree Type - DFS/BFS, Tree, Shortest Path, Backtracking Difficulty - Medium Approach && Solution First, I thought “Moving Bob first ...
Introduction Backtracking is a powerful algorithmic technique used for solving problems that involve making a series of decisions and exploring all possible solutions. It’s particularly useful for solving combinatorial problems, such as finding all p...
Backtracking is a fascinating and versatile algorithmic technique. It involves exploring all potential solutions to a problem by recursively attempting to build a solution one step at a time while removing the previous step if it doesn't lead to a va...
class Solution: def maxMoves(self, grid: List[List[int]]) -> int: ans = 0 def traverse(a, b, prevVal): nonlocal count, ans if (a, b) in visited: return visited.add((a, b)) ...
As a weekend project I thought of solving LinkedIn’s Queens game programmatically. (Well idea was to make it solve using ChatGPT, but too many un-knows and thought of solving using classic, vanilla backtracking) For those of you who haven't played (o...
Problem Write a program to solve a Sudoku puzzle by filling the empty cells. (link) A sudoku solution must satisfy all of the following rules: Each of the digits 1-9 must occur exactly once in each row. Each of the digits 1-9 must occur exactly onc...