Maximum difference between first and last indexes of an element in array

Suppose, you have an array of integers. The problem “Maximum difference between first and last indexes of an element in array” asks to find out the difference between the first and last index of each number present in an array such that the difference is being maximum of all. Example …

Read moreMaximum difference between first and last indexes of an element in array

Print modified array after multiple array range increment operations

The problem “Print modified array after multiple array range increment operations” states that you are given an integer array and ‘q’ numbers of queries are given. One integer value “d” is also given. Each query contains two integers, starting value and an ending value. The problem statement asks to find …

Read morePrint modified array after multiple array range increment operations

Minimum number of distinct elements after removing m items

Problem Statement The problem “Minimum number of distinct elements after removing m items” states that you have an array and an integer m. Each element of the array indicates an item id’s. The problem statement asks to remove m elements in such a way that there should be a minimum …

Read moreMinimum number of distinct elements after removing m items

Maximum weight transformation of a given string

Problem Statement The maximum weight transformation of a given string problem states that given a string consisting only of two characters ‘A’ and ‘B’. We have an operation where we can transform string to another string by toggling any character. Thus many transformations are possible. Out of all the possible …

Read moreMaximum weight transformation of a given string

A Space Optimized DP solution for 0-1 Knapsack Problem

Problem Statement We are given a knapsack which can hold some weight, we need to pick some of the items out of given items with some value. The items should be picked such that the value of the knapsack ( total value of picked up items ) should be maximized. …

Read moreA Space Optimized DP solution for 0-1 Knapsack Problem

Largest Sum Contiguous Subarray

Problem Statement You are given an array of integers. The problem statement asks to find out the largest sum contiguous subarray. This means nothing but to find a subarray (continuous elements) which has the largest sum among all other subarrays in the given array. Example arr[] = {1, -3, 4, …

Read moreLargest Sum Contiguous Subarray

Count Pairs Whose Products Exist in Array

In count pairs whose products exist in array problem we have given an array, count all the distinct pairs whose product value is present in the array. Example Input A[]={2, 5, 6, 3, 15} Output Number of distinct pairs whose product exists in the array is: 2 Pairs are: (2, …

Read moreCount Pairs Whose Products Exist in Array