Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Given two prime numbers, P1 and P2 , your task is to reach from P1 to P2 by changing only one digit at a time
Given two prime numbers, P1 and P2 , your task is to reach from P1 to P2 by changing only one digit at a time and also the number you get after changing a digit must also be a prime. For example suppose that P1 is 1033 and P2 is 8179 (both primes), we can reach from P1 to P2 in following way :- 1033- > 1733- > 3733- > 3739- > 3779->8779- > 8179. The first digit must be non-zero that is you can not go from 4-digit to 3-digit numbers. Note that there may be multiple way to get to destination but you have to find the way in minimum number of steps. For example the minimum number of steps to get from P1 to P2 in following examples are as follows :- 1033 8179 ANWSER:- 6 1373 8017 ANWSER:- 7 1033 1033 ANWSER:- 0 Hint: Apply BFS
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started