Category Archives: Arrays

Find Index of Unique element in Array with duplicate elements

Given an array of size N, print the index of the distinct element from the array, provided the array has only one distinct element and rest other elements are same. Examples: Input: Arr[]={10,10,10,10,20} Output: Distinct Element found at index : 4 Input: Arr[]={7,7,7,0,7,7,7,7} Output: Distinct Element found at index : 3 Approach: Linearly traverse through the array and… Read More »

Maximum Subarray Min-Product

The min-product of an array is equal to the minimum value in the array multiplied by the array’s sum. For example, the array [3,2,5] (minimum value is 2) has a min-product of 2 * (3+2+5) = 2 * 10 = 20. A subarray is a contiguous part of an array. Input: nums = [1,2,3,2] Output: 14 Explanation: The… Read More »

Sum of Floored Pairs

Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.length in the array. The floor() function returns the integer part of the division. Examples: Input: nums = [2,5,9] Output: 10 Explanation: floor(2 / 5) = floor(2 / 9) = floor(5 / 9) = 0 floor(2… Read More »