## Minimum Moves to Equal Array Elements Leetcode Solution

Problem Statement   In this problem, we are given an array of integers. Also, we are allowed to perform a certain set of operations on this array. In one operation, we can increment ” n – 1″ (all elements except any one) elements in the array by 1. We need to …

## Maximum sum of pairs with specific difference

The problem “Maximum sum of pairs with specific difference” states that you are given an array of integers and an integer K. Then we are asked to find out the maximum sum of independent pairs. We can pair two integers if they have an absolute difference of less than K. …

## Largest subarray with equal number of 0s and 1s

You are given an array of integers. The integers are only 0 and 1 in the input array. The problem statement asks to find out the largest sub-array that can have equal count of 0s and 1s. Example   arr[]={0,1,0,1,0,1,1,1} 0 to 5 (total 6 elements) Explanation From the array position …

## Binary array after M range toggle operations

You are given a binary array, which consists of 0 initially and Q number of queries. The problem statement asks to toggle the values (converting 0s into 1s and 1s into 0s). After the Q queries performed, print the resultant array. Example   arr[] = {0, 0, 0, 0, 0} Toggle(2,4) …

## Queries for counts of array elements with values in given range

Problem Statement   The problem “Queries for counts of array elements with values in given range” states that you have an integer array and two number x and y. The problem statement asks to find out the count of numbers present in array that lies between the given x and y. …

## Text Justification

Problem Statement   The problem “Text Justification” states that you are given a list s[ ] of type string of size n and an integer size. Justify the text such that each line of text consists of size number of characters. You can use space(‘ ‘) as a character to complete …

## Distinct adjacent elements in an array

Problem Statement   Suppose we have an integer array. The problem “Distinct adjacent elements in an array” asks to determine if it is possible to get the array in which all the adjacent numbers are distinct or not by swapping up two adjacent or neighbour elements in an array if it …

## Count subarrays with equal number of 1’s and 0’s

Problem Statement   The problem “Count subarrays with equal number of 1’s and 0’s” states that you are given an array consisting of 0’s and 1’s only. The problem statement asks to find out the count of sub-arrays consisting equal no of 0’s ad 1’s. Example   arr[] = {0, 0, 1, …

## Binary Tree to Binary Search Tree Conversion using STL set

Problem Statement   We are given a binary tree and we need to convert it into a binary search tree. The problem “Binary Tree to Binary Search Tree Conversion using STL set” asks to do conversion using STL set. We have already discussed converting the binary tree into BST but we …

## Find the minimum distance between two numbers

Problem Statement   You have given an array and two numbers called x and y. The problem “Find the minimum distance between two numbers” asks to find out the minimum possible distance between them. The array given can have common elements. You can assume that both x and y are different. …