First negative integer in every window of size k | Python3 code for First negative integer in every window of size k ; skip out of window and positive elements ; check if a negative element is found , otherwise use 0 ; Driver code
def printFirstNegativeInteger ( arr , k ) : NEW_LINE INDENT firstNegativeIndex = 0 NEW_LINE for i in range ( k - 1 , len ( arr ) ) : NEW_LINE INDENT while firstNegativeIndex < i and ( firstNegativeIndex <= i - k or arr [ firstNegativeIndex ] > 0 ) : NEW_LINE INDENT firstNegativeIndex += 1 NEW_LINE DEDENT firstNegativeElement = arr [ firstNegativeIndex ] if arr [ firstNegativeIndex ] < 0 else 0 NEW_LINE print ( firstNegativeElement , end = ' ▁ ' ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 12 , - 1 , - 7 , 8 , - 15 , 30 , 16 , 28 ] NEW_LINE k = 3 NEW_LINE printFirstNegativeInteger ( arr , k ) NEW_LINE DEDENT