Category Archives: Array

Mountain Array

Problem Given an array of integers, check if it is a mountain array or not. An array is called a mountain array if: Length of array >= 3 There exists some i with 0 < i < (length of array) – 1 such that: arr[0] < arr[1] < … < arr[i – 1] < arr[i] arr[i] > arr[i… Read More »

Find the minimum index of a repeating element in an array

Problem Given an array of integers, find the first repeating element in it. We need to find the element that occurs more than once and whose index of first occurrence is smallest.  Sample Input [1, 2, 2, 1] Sample Output  1 Explanation 1 is the first one occurring twice. Approach We can use sets to solve this efficiently.… Read More »

Difference Between ArrayList and LinkedList

The list is an abstract data type available in functional programming languages that stores ordered values. It is analogous to arrays in object-oriented programming languages. Lists allow us to store, manipulate, and retrieve data easily. Programming languages that support list data types have their ways of creating lists. We can create a list by inserting data items sequentially… Read More »

Subarray with Sum k

Problem Given an unsorted array arr of size N, find a contiguous subarray that adds to a given number k. Brute Force Approach An easy approach is to go through all subarrays one by one and calculate the total of each subarray. The programme that follows implements the basic solution. Run two loops: the outer loop selects a… Read More »