@@ -0,0 +1,1833 @@
+import java.io.*;%0Aimport java.util.*;%0Aimport java.text.*;%0Aimport java.math.*;%0Aimport java.util.regex.*;%0A%0Apublic class Solution %7B%0A/* Head ends here */%0Astatic void displayPathtoPrincess(int n, String %5B%5D grid)%0A%7B%0A    int size = n*n;%0Aint ppos_i = 0;%0Aint mpos_i = 0;%0Aint ppos_j = 0;%0Aint mpos_j = 0;%0A%0Achar %5B%5D%5B%5Dfinal; %0Atarget = new char%5Bn%5D%5B%5D; %0Afor(int i=0;i%3Cn;i++) %0Atarget%5Bi%5D = grid%5Bi%5D.toCharArray();     %0A    %0A    %0Afor(int i = 0; i %3C n; i++)%0A%7B%0A   // System.out.println();%0A    for(int j = 0; j%3Cn; j++)%0A%7B  %0A    //System.out.print(target%5Bi%5D%5Bj%5D);%0A    %0A    if (final%5Bi%5D%5Bj%5D == 'p')  %0A    %7Bppos_i = i; ppos_j = j;%7D%0A    %0A    if (final%5Bi%5D%5Bj%5D == 'm')%0A      %7Bmpos_i = i; mpos_j = j;%7D   %0A    %0A%7D%0A%7D%0A    %0A /*ppos_i = ppos/n;%0A ppos_j = ppos%25n;%0A mpos_i = mpos/n;%0A mpos_i = mpos%25n;%0A */%0A %0A %0A    %0A    while(ppos_i != mpos_i) %0A    %7B    %0A     /*System.out.print(ppos_i);%0A     System.out.print(ppos_j); %0A     System.out.println();   %0A     System.out.print(mpos_i);%0A     System.out.print(mpos_j); */  %0A    %0A    if (mpos_i %3C ppos_i )%0A    %7B  %0A        System.out.println(%22DOWN%22);%0A        %0A        mpos_i = mpos_i + 1;%0A    %7D%0A    else %0A    %7B %0A       System.out.println(%22UP%22);%0A      %0A       mpos_i= mpos_i - 1;%0A      // System.out.println( mpos_j);%0A    %7D%0A    %7D          %0A    %0A    while(ppos_j != mpos_j)%0A    %7B%0A          %0A      if(mpos_j %3C ppos_j)%0A    %7B    System.out.println(%22RIGHT%22);%0A         %0A         mpos_j++;%0A    %7D%0A     else%0A     %7B%0A         System.out.println(%22LEFT%22);%0A         %0A          mpos_j--;%0A     %7D%0A        %0A    %7D  %0A    %0A        %0A        %7D%0A    %0A/* Tail starts here */%0Apublic static void main(String%5B%5D args) %7B%0A        Scanner in = new Scanner(System.in);%0A        int m;%0A        m = in.nextInt();%0A        String grid%5B%5D = new String%5Bm%5D;%0A        for(int i = 0; i %3C m; i++) %7B%0A            grid%5Bi%5D = in.next();%0A        %7D%0A%0A    displayPathtoPrincess(m,grid);%0A    %7D%0A%7D%0A

Create solution.java