Find minimum number of distinct elements after removing M items

Here, we are going to find the minimum number of distinct elements after removing M number of items from array. Given: An Array of items, an i’th index element denotes the item id’s and given a number m. Problem: Remove m elements such that there should be minimum distinct id’s left and then print the number … Read more

Program to find number of ways to distribute Objects

Here we’ll first understand the problem of calculation the number of ways to distribute objects into distinct groups, then we’ll implement the same in C++ with the help of example. Given: 2 integers N and R, where N is the number of objects and R is the number of groups. Problem: The task is to calculate … Read more

Program for K Most Recently Used (MRU) Apps in C++

GIVEN: Number k and an array arr[n], containing n number of integer elements which are storing the id’s of the opened apps in a system. PROBLEM: To print the contents of the array when the user using the system presses Alt + Tab exactly K number of times. The position of every id represents different apps in a … Read more

Find Root using Newton-Raphson method in C++

Newton-Raphson Method: The Newton-Raphson method (also known as Newton’s method) is a way to quickly find a good approximation for the root of a real-valued function f(x) = 0f(x)=0. It uses the idea that a continuous and differentiable function can be approximated by a straight line tangent to it. Newton-Raphson formula:               … Read more

Rearrange Array’s Even and Odd values in Ascending order C++

Given: An array of integers with equal number of even and odd values. Problem: Arrange the given array in such a way that odd and even values come in alternate fashion in ascending order respectively. If the smallest value is Even then we have to print Even-Odd pattern. If the smallest value is Odd then we have to print Odd-Even pattern. Examples: Input: … Read more

Sort even number in ascending order and odd number in descending order C++

Given: An array of integers containing even and odd numbers. Problem: For the given array sort even number in ascending order and then sort all the odd numbers in descending order. Then arrange odd numbers first and then arrange the odd numbers. Examples: Input : arr[] = {1, 2, 3, 5, 4, 7, 10} Output : … Read more