human
Write me a code to first negative integer in every window of size k and the other steps required given the following:
First negative integer in every window of size k | Function to find the first negative integer in every window of size k.
Loop for each subarray ( window ) of size k.
Traverse through the current window.
If a negative integer is found , then it is the first negative integer for current window . Print it , set the flag and break.
If the current window does not contain a negative integer.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to first negative integer in every window of size k and the other steps required.
 def printFirstNegativeInteger ( arr , n , k ) :
	for i in range ( 0 , ( n - k + 1 ) ) :
		flag = False
		for j in range ( 0 , k ) :
			if ( arr [ i + j ] < 0 ) :
				print ( arr [ i + j ] , end = " ▁ " )
				flag = True
				break
		if ( not ( flag ) ) :
			print ( "0" , end = " ▁ " )
arr = [ 12 , - 1 , - 7 , 8 , - 15 , 30 , 16 , 28 ]
n = len ( arr )
k = 3
printFirstNegativeInteger ( arr , n , k )