Counting Rock Samples | TCS Codevita 2020 | C # program of the above approach ; Function to find the rock samples in the ranges ; Iterate over the ranges ; Driver Code ; Function call
using System . Collections . Generic ; using System ; class GFG { static void findRockSample ( int [ , ] ranges , int n , int r , int [ ] arr ) { List < int > a = new List < int > ( ) ; for ( int i = 0 ; i < r ; i ++ ) { int c = 0 ; int l = ranges [ i , 0 ] ; int h = ranges [ i , 1 ] ; for ( int j = 0 ; j < arr . Length ; j ++ ) { if ( l <= arr [ j ] && arr [ j ] <= h ) c += 1 ; } a . Add ( c ) ; } foreach ( var i in a ) { Console . Write ( i + " ▁ " ) ; } } public static void Main ( ) { int n = 5 ; int r = 2 ; int [ ] arr = { 400 , 567 , 890 , 765 , 987 } ; int [ , ] ranges = { { 300 , 380 } , { 800 , 1000 } } ; findRockSample ( ranges , n , r , arr ) ; } }