You are given with 2 strings startState and finalState
denoting the initial sequence of digits and the
sequence of digits that unlocks the lock. Both
startState and finalState are of the same length. You
are given with an array of strings deadlock of size n
denoting the number of deadlock sequences. Each
deadlock[i] has the same length as that of startState
and finalState. The lock is circular. You can either
increase a digit or decrease a digit. Each change takes
1 second. Your task is to find the minimum time in
which we can reach the finalState from startState.
Output - 1 if it is not possible to reach finalState due to
deadlocks.
INPUT FORMAT:
The first line of input contains a string startState.
Next line of input contains a string endState.
Next line of input contains an integer n denoting the
size of array deadlock.
Next n línes contain a string denoting deadlock[i].
OUTPUT FORMAT:
Output a single integer denoting the minimum time in
which we can reach the finalState from startState.
Output - 1 if it is not possible to reach final State due to
deadlocks.
CONSTRAINTS:
1 <= |startState) = |finalState) = 1deadlock[i]<= 5
1<= n <= 50000
All the strings contain digits from 0 to 9.
SAMPLE INPUT #1: :
123
313
3
113
213
413
Sample output
3
Answers
Answered by
5
Answer:
2959
a
Thank you
And I am left mam
Similar questions
English,
2 months ago
Math,
2 months ago
Social Sciences,
2 months ago
English,
4 months ago
Math,
4 months ago
Science,
10 months ago
World Languages,
10 months ago
Hindi,
10 months ago