Find the max element in subarray

https://hack.codingblocks.com/contests/c/512/504

#include
using namespace std;
int main(){
int n,k;
cin >> n >> k ;
int arr[1000000];

for(int i=0; i<n ;i++){
	cin >> arr[i];
}
int cur=0;
int setmax=0;
for(int i=0 ;i<=n-k ;i++){                  // for transversing till n-k and i++
	for(cur=i ;cur<=k ;cur++){       //starting from i and transversing till k subarray
			
                    setmax=max(arr[cur],arr[cur+1]);
		setmax=max(setmax,arr[cur+2]);
	
              }
}
cout << setmax << endl ;
    return 0;

}

where are the problem in this answer

or i have approched in the wrong way

for(cur=i;cur<i+k;cur++)
setmax=max(arr[cur],setmax)

This should be done.
Your solution uses O(N*K) Approach. It can be optimised to O(N) approach.

can u send me the code for o(n)
or can u just give me hint how can i solve