• + 0 comments

    Java Simple Code /* Saving page no as key in hashMap, value as pages turns(steps) pageNo steps 0 0 1 0

                    2         1
                    3         1
    
                    4         2
                    5             2
    so on....*/
    

    Java Simple Code import java.util.*;

    public class DrawingBookPages { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); //no of pages in book int p = sc.nextInt(); // page to turn to

        int steps = 0;
        Map<Integer, Integer> hmap = new HashMap<>();
        for(int i=0; i<=n; i++){
            hmap.put(i, steps);
            i++;
            if(i<=n) hmap.put(i, steps);
            steps++;
        }
        System.out.println(Math.min(hmap.get(p), hmap.get(n)-hmap.get(p)));
    }
    

    }