Category Archives: Arrays

Array element moved by k using single movesNovember 14, 2017

Given a list of n integers containing numbers 1-n in a shuffled way and a integer K. N people are standing in a queue to… Read More »

Minimum operations to make the MEX of the given set equal to x

Given a set of n integers, perform minimum number of operations (you can insert/delete elements into/from the set) to make the MEX of the set… Read More »

Make three non-empty sets with negative, positive and 0 products

You are given an array of n distinct integers. Your task is to divide this array into three non-empty sets so as the following conditions… Read More »

Dividing an array into two halves of same sumNovember 13, 2017

Given an even size array of integers. We need to find if it is possible to divide array elements into two sets such that following… Read More »

Products of ranges in an array

Given an array A[] of size N. Solve Q queries. Find the product in range [L, R] under modulo P ( P is Prime). Examples:… Read More »

Minimum replacements to make elements of a ternary array same

Given a ternary array (every element has one the three possible values 1, 2 and 3). Our task is to replace the minimum number of… Read More »

Maximum Unique Element in every subarray of size K

Given an array and an integer K. We need to find the maximum of every segment of length K which has no duplicates in that… Read More »

Largest in array without using conditionals / bitwise / ternary operatorsNovember 12, 2017

Define a function int max(int a[], int n) which returns the largest integer from an integer array consisting of n elements (without using conditionals /… Read More »

Largest increasing subsequence of consecutive integersNovember 10, 2017

Given an array of n positive integers. We need to find the largest increasing sequence of consecutive positive integers. Examples: Input : arr[] = {5,… Read More »

Longest Increasing subarray with one change allowed

Given an array, find the length of the longest increasing subarray (contiguous elements) such that it is possible to change at most one number (change… Read More »

Check whether the given array is perfect or not

There is an array contains some non-negative integers. Check whether the array is perfect or not. An array is called perfect if it is first… Read More »

Find array with k number of merge sort callsNovember 9, 2017

Given two numbers n and k, find an array containing values in [1, n] and requires exactly k calls of recursive merge sort function. Examples:… Read More »

Minimum 1s to lend power to make whole array powerful

Given a binary array and an integer k where every 1 has power and it can lend power to neighbors and itself. A cell with… Read More »

Only integer with positive value in positive negative value in arrayNovember 8, 2017

Given an array of N integers. In the given, for each positive element ‘x’ there exist a negative value ‘-x’, except one integer whose negative… Read More »

Python program to add two matrices

Prerequisite : Arrays in Python, Loops, List Comprehension Program to compute the sum of two matrices and then print it in Python. We can perform… Read More »