We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicclassSolution{staticintsolve(intn,intp){inthalfway=n/2;intturns=0;if(p>halfway){// turn from backintrev=n-p;if(rev>1){turns=rev/2;}}else{// turn from frontif(p>1){turns=p/2;}}returnturns;}publicstaticvoidmain(String[]args){Scannerin=newScanner(System.in);intn=in.nextInt();intp=in.nextInt();intresult=solve(n,p);System.out.println(result);}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Drawing Book
You are viewing a single comment's thread. Return to all comments →
What I used to solve it...