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.
- Prepare
- Algorithms
- Implementation
- Drawing Book
- Discussions
Drawing Book
Drawing Book
+ 0 comments def pageCount(n, p): # Write your code here if p%2==0: start = 1+(p-2)//2 end = (n-p)//2 if p%2==1: start = (p-1)//2 end = (n+1-p)//2 return min(start,end)
+ 0 comments JavaScript :
function pageCount(n, p) { // Write your code here let min = 1; let max = n % 2 == 0 ? n : n - 1 for(let i = 0; i <= n ; i++){ if(min >= p || max <= p){ return i } min += 2; max -= 2; } }
+ 0 comments def pageCount(n, p): # Write your code here if p == 1 or n==p: return '0' else: if (n-p)< p: if n-p <=1 and p %2 !=0: return '1' else: return (n-p)//2 else: return p//2
+ 0 comments def pageCount(n, p): is_odd = n % 2 != 0 if p > n/2: if is_odd and n-p <= 1: return 0 return math.ceil((n-p-1)/2) if is_odd else math.ceil((n-p)/2) return math.ceil((p-1)/2)
+ 0 comments C#
public static int pageCount(int n, int p) { if (n % 2 == 1) n--; int l2R = 0, r2L = 0; for (int i = 1; i < p; i += 2) l2R++; for (int i = n; i > p; i -= 2) r2L++; return Math.Min(l2R, r2L); }
Load more conversations
Sort 1899 Discussions, By:
Please Login in order to post a comment