Make max elements in B [ ] equal to that of A [ ] by adding / subtracting integers in range [ 0 , K ] | Function that count the number of integers from array B such that subtracting element in the range [ 0 , K ] given any element in A ; To store the count of element ; Traverse the array B ; Traverse the array A ; Find the difference ; If difference is atmost K then increment the cnt ; Print the count ; Driver Code ; Given array A and B ; Given K ; Function call
def countElement ( A , N , B , M , K ) : NEW_LINE INDENT cnt = 0 NEW_LINE for i in range ( M ) : NEW_LINE INDENT currentElement = B [ i ] NEW_LINE for j in range ( N ) : NEW_LINE INDENT diff = abs ( currentElement - A [ j ] ) NEW_LINE if ( diff <= K ) : NEW_LINE INDENT cnt += 1 NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT print ( cnt ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = [ 100 , 65 , 35 , 85 , 55 ] NEW_LINE B = [ 30 , 60 , 75 , 95 ] NEW_LINE N = len ( A ) NEW_LINE M = len ( B ) NEW_LINE K = 5 NEW_LINE countElement ( A , N , B , M , K ) NEW_LINE DEDENT