Number of times Maximum and minimum value updated during traversal of array | Java implementation to find the number of times minimum and maximum value updated during the traversal of the array ; Function to find the number of times minimum and maximum value updated during the traversal of the given array ; Increment i if new highest value occurs Increment j if new lowest value occurs ; Driver Code
public class GFG { static void maxUpdated ( int [ ] arr ) { int h_score = arr [ 0 ] ; int l_score = arr [ 0 ] ; int i = 1 , j = 1 ; for ( Integer n : arr ) { if ( h_score < n ) { h_score = n ; i ++ ; } if ( l_score > n ) { l_score = n ; j ++ ; } } System . out . print ( " Number ▁ of ▁ times ▁ maximum ▁ value ▁ " ) ; System . out . print ( " updated ▁ = ▁ " + i + "NEW_LINE"); System . out . print ( " Number ▁ of ▁ times ▁ minimum ▁ value ▁ " ) ; System . out . print ( " updated ▁ = ▁ " + j ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 10 , 5 , 20 , 22 } ; maxUpdated ( arr ) ; } }