Number of times Maximum and minimum value updated during traversal of array | C # 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
using System ; class GFG { static void maxUpdated ( int [ ] arr ) { int h_score = arr [ 0 ] ; int l_score = arr [ 0 ] ; int i = 1 , j = 1 ; foreach ( int n in arr ) { if ( h_score < n ) { h_score = n ; i ++ ; } if ( l_score > n ) { l_score = n ; j ++ ; } } Console . Write ( " Number ▁ of ▁ times ▁ maximum ▁ value ▁ " ) ; Console . Write ( " updated ▁ = ▁ " + i + " STRNEWLINE " ) ; Console . Write ( " Number ▁ of ▁ times ▁ minimum ▁ value ▁ " ) ; Console . Write ( " updated ▁ = ▁ " + j ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 10 , 5 , 20 , 22 } ; maxUpdated ( arr ) ; } }