Question: You are given an ' m x n ' matrix where each cell represents either an alphabetical character ( denoted by ' a ' to

You are given an 'm x n' matrix where each cell represents either an alphabetical character (denoted by 'a' to 'z') or a wildcard character (denoted by '*').
You have a starting amount of energy, 'E'.
You are allowed to move only in these directions - right, left, down, or up. Each move costs 1 unit of energy.
A
Your task is to search for the sequence of characters from the given character array in the target 2-D matrix while managing your energy.
You can only move to adjacent cells if you have sufficient energy.
You can match wildcard character '*' to any character in the given input array.
Write a function 'search_with_energy' that takes the sequence of characters, matrix, and the initial energy as input. And returns either 0 or 1 bases on the following constraints
If you run out of energy before searching is completed, return 0.
If you aren't able to find the given sequence of characters,return 0.
If you can find the given sequence of characters, return 1.
You can use a cell in 2-D matrix for matching only once.
You can't use the same cell for matching different positionsfrom given character sequence. However, you can movethrough already matched cell.
Additional Constraints:
1<= n, m <=100
1<= energy <=10000

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!