Computer Science, asked by lovelynandy24, 1 year ago

The program must accept two integers N and K as the input. The program must print the minimum possible integer X which can be obtained by modifying at most K digits in N as the output. Note: The number of digits in N and X should be equal without any leading zeros. Boundary Condition(s): 1 <= N <= 10^7 1 <= K <= 7

Answers

Answered by Anonymous
2

Answer:

The below code is written in Java, where the Getnumber class is used to for this problem. The method which is used to find the number is possiblenumber()

  public class Getnumber{  

 static double possiblenumber(int N) {  

       if (N >= 1 && n <= 9) {  

           return n;  

       }  

  Stack<Integer> cells = new Stack<>();  

 for (int i = 9; i >= 2 && N> 1; i--) {  

           while (N% i == 0) {  

          cells .push(i);  

               N= N/ i;  

           }  

       }  

       if (N!= 1) {  

           return -1;  

       }  

    double K= 0;  

       while (!cells .empty()) {  

           K = K* 10 + cells .peek();  

           cells .pop();  

       }

       return K;  

   }  

 static public void main(String[] args) {  

       int N= 100;  

       System.out.println(possiblenumber(N));  

   }  

}  

 

Similar questions