• + 0 comments

    Just the do mathematics & it's simple (Code in C# )-

                public static int pageCount(int n, int p)
                        {
                                int shortestRoute = 0;
                                if(n/2 < p){
                                        //Start from back side
                                        if(n%2 != 0){
                                                shortestRoute = (int)(n-p)/2;    
                                        }else{
                                                shortestRoute = (int)((n-p)+1)/2;
                                        }   
                                }
                                else{
                                        //Start from biggining
                                        shortestRoute = (int)p/2;
                                }
    
                                return shortestRoute;
                        }