Found 7347 Articles for C++

Minimum number of palindromes required to express N as a sum using C++.

Narendra Kumar
Updated on 31-Oct-2019 07:30:17

143 Views

Problem statementGiven a number N, we have to find the minimum number of palindromes required to express N as a sum of themIf N = 15 then 2 palindromes are required i.e. 8 and 7.Algorithm1. Generate all the palindromes up to N in a sorted fashion 2. Find the size of the smallest subset such that its sum is NExample#include #include #include #include using namespace std; vector table; int createPalindrome(int input, bool isOdd){    int n = input;    int palindrome = input;    if (isOdd)       n /= 10;    while (n > ... Read More

Minimum number of page turns to get to a desired page using C++.

Narendra Kumar
Updated on 31-Oct-2019 07:26:43

422 Views

Problem statementGiven a book of N pages, the task is to calculate the minimum number of page turns to get to a give desired page K.we can either start turning pages from the front side of the book (i.e from page 1) or from the backside of the book (i.e page number N).Each page has two sides, front and back, except the first page, which has only backside and the last page which may only have backside depending on the number of pages of the book.If N = 5 and K = 4 then we have to turn minimum 1 ... Read More

Minimum number of operations required to sum to binary string S using C++.

Narendra Kumar
Updated on 31-Oct-2019 07:24:59

132 Views

Problem statementGiven a binary string str. Find the minimum number of operations required to be performed to create the number represented by str. Only following operations can be performed −Add 2xSubtract 2xIf binary string is “1000” then we have to perform only 1 operation i.e. Add 23If binary string is “101” then we have to perform 2 operations i.e. Add 22 + 20Example#include #include #include using namespace std; int getMinOperations(string s){    reverse(s.begin(), s.end());    int n = s.length();    int result[n + 1][2];    if (s[0] == '0') {       result[0][0] = 0;   ... Read More

Minimum number of operations required to delete all elements of the array using C++.

Narendra Kumar
Updated on 31-Oct-2019 07:21:16

1K+ Views

Problem statementGiven an integer array arr, the task is to print the minimum number of operations required to delete all elements of the array. While deleting element following restriction is imposed −Any element from the array can be chosen at random and every element divisible by it can be removed from the arrayIf arr[] = {2, 4, 15, 10, 8, 5, 3} then 3 operation are required to delete all elements −If we choose 2 then it will delete {2, 4, 10, 8}If we choose 5 then it will remove {5, 15}If we choose 3 then it will remove {3}Algorithm1. ... Read More

Minimum number of operations on an array to make all elements 0 using C++.

Narendra Kumar
Updated on 31-Oct-2019 07:18:01

280 Views

Problem statementGiven an array of size N and each element is either 1 or 0. The task is to calculated the minimum number of operations to be performed to convert all elements to zero. One can perform below operations −If an element is 1, You can change its value equal to 0 then −If the next consecutive element is 1, it will automatically get converted to 0If the next consecutive element is already 0, nothing will happen.If arr[] = {1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1} then 4 operation are required to ... Read More

Minimum number of nodes in an AVL Tree with given height using C++.

Narendra Kumar
Updated on 31-Oct-2019 07:15:22

229 Views

Problem statementGiven the height of an AVL tree, the task is to find the minimum number of nodes the tree can have.If height = 0 then AVL tree can have one 1 node If height = 5 then AVL tree can have minimum 20 nodesAlgorithmIn an AVL tree, we have to maintain the height balance property, i.e. a difference in the height of the left and the right subtrees cannot be more than -1, 0 or 1 for each node. Using this property, we can create below recurrence relation −1. If height = 0 then return 1 2. If height ... Read More

Minimum number of moves to make all elements equal using C++.

Narendra Kumar
Updated on 31-Oct-2019 07:12:57

176 Views

Problem statementGiven an array of N elements and an integer K., It is allowed to perform the following operation any number of times on the given array −Insert the Kth element at the end of the array and delete the first element of the array.The task is to find the minimum number of moves needed to make all elements of the array equal. Print -1 if it is not possibleIf arr[] = {1, 2, 3, 4, 5, 6} and k = 6 then minimum 5 moves are required: Move-1: {2, 3, 4, 5, 6, 6} Move-2: {3, 4, 5, 6, ... Read More

Minimum number of mails required to distribute all the questions using C++.

Narendra Kumar
Updated on 31-Oct-2019 07:04:38

84 Views

Problem statementGiven N questions in a test and K students in the class. Out of the batch of K students, N students memorized exactly one question each. A mail can contain about a maximum of X questions.Find the minimum number of mails required so that the entire class gets to know about all the questionsIf N = 3, K = 3, X = 1 then one has to send 6 mails −Student 1 sends his question to student 2 and student 3 (2 mails), So does student 2 and student 3 so total mails = 2 * 3 = 6AlgorithmThe ... Read More

Minimum number of letters needed to make a total of n in C++.

Narendra Kumar
Updated on 31-Oct-2019 07:02:45

54 Views

Problem statementGiven an integer n and let a = 1, b = 2, c= 3, ….., z = 26. The task is to find the minimum number of letters needed to make a total of nIf n = 23 then output is 1 If n = 72 then output is 3(26 + 26 + 20)Algorithm1. If n is divisible by 26 then answer is (n/26) 2. If n is not divisible by 26 then answer is (n/26) + 1Example#include using namespace std; int minRequiredSets(int n){    if (n % 26 == 0) {       return (n / 26);    } else {       return (n / 26) + 1;    } } int main(){    int n = 72;    cout

Minimum number of items to be delivered using C++.

Narendra Kumar
Updated on 31-Oct-2019 07:00:39

206 Views

Problem statementGiven an array of size, N represents buckets, each array index containing items. Given K tours within which all of the items are needed to be delivered. It is allowed to take items from only one bucket in 1 tour. The task is to tell the minimum number of items needed to be delivered per tour so that all of the items can be delivered within K tours.If there are 5 buckets with item = {1, 3, 5, 7, 9} and 10 tours then we can deliver 3 items per tour By delivering 3 items at a time, 1st ... Read More

Advertisements