Company: Curefit
Difficulty: medium
Count Colorful Paths Problem Description You are given a 2D grid maze of size N*M where each cell contains a color represented by an integer. Your task is to count the number of distinct paths from the top-left corner (0,0) to the bottom-right corner (N-1,M-1) such that you can move only right or down at each step. You cannot revisit any color already present in your current path. In other words, no two cells along a single path can have the same color. Use backtracking to explore all valid paths and count how many satisfy the color-uniqueness condition. Function description: You need to implement the function countColorfulPaths which returns an integer representing the number of valid colorful paths from (0,0) to (N-1,M-1). Examples Example 1: Input: n = 3, m = 3, grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] Output: 6 Explanation: Since all colors (integers) in the grid are distinct, every possible path from start to finish satisfies the condition. There are 6 distinct paths in a 3x3 grid