Category Archives: Arrays

LCM of given array elements

Given an array of size n, your task is to find the least common multiple or LCM of all the elements of the array. Examples: Input : arr = [ 8, 9, 21] Output : 504 Input : arr = [ 2, 4, 3, 8] Output : 24 RECOMMENDED: Maximum Length Subsequence from Ticket Prices Array Method-1: Prime… Read More »

Count number of pair of elements whose difference is smaller than average difference

Given an array of positive integers we have to find number of pair of elements whose difference is smaller than average difference. Average difference is defined as (max(A)-min(A))/(n-1), where A is the array and max(A),min(A) is the maximum and minimum element of the array. Examples: Input : {9,3,10,2,3} Output : 2 Input : {7,9,5,3,1} Output : 0 RECOMMENDED: Characteristics or… Read More »