ARRAYSUB - subarrays
Given an array and an integer k, find the maximum for each and every contiguous subarray of size k.
the number n denoting number of elements in the array then after a new line we have the numbers of the array
and then k in a new line
1 <= k <=n
and each element of the array is between 0 and 10^6
print the output array
1 2 3 1 4 5 2 3 6 3 Output: 3 3 4 5 5 5 6
|Cluster:||Cube (Intel Pentium G860 3GHz)|
|Languages:||All except: SCM chicken|
finally O(n) :-). caused a lot of wa due to silly mistakes. same question came at MAY'15 codechef long challenge.
AC in first go :D
better time through sparse table !!Last edit: 2015-04-15 21:37:37
@Shubham Bansal: Use multiset instead of set.
D Pratap :
Got ACC for O ( N logK)
i was trying to solve dis ques using set stl, showing correct answer for all the test cases i can think of, but showing wrong answer..
While solving using JAVA, it gave me NZEC when used BufferedReader for taking inputs. Got AC using Scanner class and O(n) algo.
Indian Cyber Army (IndiShell):
ac in 1 go with brute force .. !
those getting wrong answer in 5 add spaces between integers
learnt something new known as window sliding!!Last edit: 2015-01-26 12:00:20