DEV Community

Mukilan Palanichamy
Mukilan Palanichamy

Posted on

My journey in competitive programming

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:

  1. This is a backtracking problem where we explore all possible permutations of the numbers 1 to n.
  2. For each position i, we check the divisibility condition and only proceed if it’s satisfied.

Image description

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:

  1. This is a grid-based DFS backtracking problem.
  2. You explore all possible paths starting from each cell, keeping track of the gold collected.
  3. Mark cells as visited during a path and unmark them when backtracking.

Image description

Top comments (0)