CHRONOS7's blog

By CHRONOS7, history, 16 months ago, In English

We are given an integer k (size of an interval) and an array A. Since we know every element in the array can be a part of at most k intervals of size k, we need to construct an array B where B[i] represents the maximum value of

abs(A[i] — p) — abs(A[i] — q)

over all intervals that A[i] is part of(at most k intervals), here p denotes the maximum value in the interval and q represents the minimum value in the interval.

Expected time complexity is O(n).

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
16 months ago, # |
  Vote: I like it +13 Vote: I do not like it

bc kitna cancer saval hai.

»
16 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

abs(a[i]-p) — abs(a[i]-q)

= (p-a[i]) — (a[i]-q)

= p+q — 2*a[i]