Find range of values for S in given Array with values satisfying [ arr [ i ] = floor ( ( i * S ) / K ) ] | C # program for the above approach ; Function to find the range of values for S in a given array that satisfies the given condition ; Stores the left range value ; Stores the right range value ; Find the current left range value for S ; Find the current right range value for S ; Updating L value ; Updating R value ; Driver Code
using System ; class GFG { static void findRange ( int [ ] arr , int N , int K ) { int L = Int32 . MinValue ; int R = Int32 . MaxValue ; for ( int i = 0 ; i < N ; i ++ ) { int l = ( int ) Math . Ceiling ( 1.0 * arr [ i ] * K / ( i + 1 ) ) ; int r = ( int ) Math . Ceiling ( ( 1.0 + arr [ i ] ) * K / ( i + 1 ) ) - 1 ; L = Math . Max ( L , l ) ; R = Math . Min ( R , r ) ; } Console . WriteLine ( L + " ▁ " + R ) ; } public static void Main ( ) { int [ ] arr = { 2 , 4 , 6 , 9 , 11 } ; int K = 10 ; int N = arr . Length ; findRange ( arr , N , K ) ; } }