Counting Rock Samples | TCS Codevita 2020 | Function to find the rock samples in the ranges ; Iterate over the ranges ; Driver Code ; Function Call
def findRockSample ( ranges , n , r , arr ) : NEW_LINE INDENT a = [ ] NEW_LINE for i in range ( r ) : NEW_LINE INDENT c = 0 NEW_LINE l , h = ranges [ i ] [ 0 ] , ranges [ i ] [ 1 ] NEW_LINE for val in arr : NEW_LINE INDENT if l <= val <= h : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT a . append ( c ) NEW_LINE DEDENT return a NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 5 NEW_LINE r = 2 NEW_LINE arr = [ 400 , 567 , 890 , 765 , 987 ] NEW_LINE ranges = [ [ 300 , 380 ] , [ 800 , 1000 ] ] NEW_LINE print ( * findRockSample ( ranges , n , r , arr ) ) NEW_LINE DEDENT