1. Beautiful Arrangement:
Given a number n, arrange the numbers from 1 to n into a sequence where, for every position i (1 based index):
Either i % arr[i] == 0 (position divisible by value)
Or arr[i] % i == 0 (value divisible by position).
Key Points:
- This is a backtracking problem where we explore all possible permutations of the numbers 1 to n.
- For each position i, we check the divisibility condition and only proceed if it’s satisfied.
2. Path with Maximum Gold:
You are given a grid of integers where each cell represents the amount of gold at that location. You can move up, down, left, or right, but you cannot revisit a cell or go out of bounds. The task is to find the maximum gold you can collect starting from any cell.
Key Points:
- This is a grid-based DFS backtracking problem.
- You explore all possible paths starting from each cell, keeping track of the gold collected.
- Mark cells as visited during a path and unmark them when backtracking.
Top comments (0)