Number of times Maximum and minimum value updated during traversal of array | Function to find the count the number of times maximum and minimum value updated ; Update the maximum and minimum values during traversal ; Driver code
def maximumUpdates ( arr ) : NEW_LINE INDENT min = arr [ 0 ] NEW_LINE max = arr [ 0 ] NEW_LINE minCount , maxCount = 1 , 1 NEW_LINE for arr in arr : NEW_LINE INDENT if arr > max : NEW_LINE INDENT maxCount += 1 NEW_LINE max = arr NEW_LINE DEDENT if arr < min : NEW_LINE INDENT minCount += 1 ; NEW_LINE min = arr NEW_LINE DEDENT DEDENT print ( " Number ▁ of ▁ times ▁ maximum ▁ " , end = " " ) NEW_LINE print ( " value ▁ updated ▁ = ▁ " , maxCount ) NEW_LINE print ( " Number ▁ of ▁ times ▁ minimum ▁ " , end = " " ) NEW_LINE print ( " value ▁ updated ▁ = ▁ " , minCount ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 10 , 5 , 20 , 22 ] NEW_LINE maximumUpdates ( arr ) NEW_LINE DEDENT