# Category Archives: Arrays

## Count ways to form minimum product tripletsNovember 1, 2017

Given an array of positive integers. We need to find how many triples of indices (i, j, k) (i < j < k), such that… Read More »

## Program for weighted mean of natural numbers.October 31, 2017

There are given an array of natural numbers and another array with corresponding weight of the number. Then we have to calculate the weighted mean.… Read More »

## Maximum sum subsequence with at-least k distant elements

Given an array and a number k, find a subsequence such that Sum of elements in subsequence is maximum Indices of elements of subsequence differ… Read More »

## Lexicographically smallest permutation with distinct elements using minimum replacementsOctober 30, 2017

Given an array of n positive integers such that each element of integer is from 1 to n. Find the lexicographically permutation that can be… Read More »

## Longest subsequence such that difference between adjacents is one | Set 2

Given an array of size n. The task is to find the longest subsequence such that difference between adjacents is one. Time Complexity of O(n)… Read More »

## Number of NGEs to the rightOctober 29, 2017

Given an array of n integers and q queries, print the number of next greater elements to the right of the given index element. Examples:… Read More »

## Largest Derangement of a Sequence

Given any sequence , find the largest derangement of . A derangement is any permutation of , such that no two elements at the same… Read More »

## Longest subarray having count of 1s one more than count of 0sOctober 28, 2017

Given an array of size n containing 0’s and 1’s only. The problem is to find the length of the longest subarray having count of… Read More »

## Minimum absolute difference of adjacent elements in a circular array

Given n integers, which form a circle. Find the minimal absolute value of any adjacent pair. If there are many optimum solutions, output any of… Read More »

## Even numbers at even index and odd numbers at odd index

Given an array of size n containing equal number of odd and even numbers. The problem is to arrange the numbers in such a way… Read More »

## Array sum in C++ STL

In C++, we can quickly find array sum using accumulate() Output: 30 Sum of vector Output: 30 We can also use a custom function in… Read More »

## Check if an encoding represents a unique binary string

Given an encoding of a binary string of length k, the task is to find if the given encoding uniquely identifies a binary string or… Read More »

## Count frequencies of all elements in array in Python using collections module

Given an unsorted array of n integers which can contains n integers. Count frequency of all elements that are present in array. Examples: Input :… Read More »

## Find the frequency of a number in an arrayOctober 27, 2017

Given an array a[] and an element x, find number of occurrences of x in a[]. Examples: Input : a[] = {0, 5, 5, 5,… Read More »

## Lambda expression in Python to rearrange positive and negative numbers

Given an array of positive and negative numbers, arrange them such that all negative integers appear before all the positive integers in the array. The… Read More »