C++ Articles

Page 224 of 597

Minimum removals from array to make max – min <= K in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 443 Views

Problem statementGiven N integers and K, find the minimum number of elements that should be removed such that Amax - Amin

Read More

C++ Program for Expressionless Face Pattern printing

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 383 Views

Given a number n; the task is to create the Expressionless face pattern upto n lines and display the results. Expressionless face is created using special characters, expressionless face using special character seems like: “*_*”.ExampleInput-: n = 6 Output-:Input-: n = 8 Output-: AlgorithmStart Step 1-> In function print_stars(int i)    Loop For j = 1 and j In function print_pattern(int rows)    Loop For i = 1 and i In function int main()    Declare and set rows = 8    Call print_pattern(rows) StopExample#include using namespace std; //function to print stars void print_stars(int i) {    for (int j = 1; j

Read More

Minimum removals in a number to be divisible by 10 power raised to K in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 223 Views

Problem statementGiven two positive integers N and K. Find the minimum number of digits that can be removed from the number N such that after removals the number is divisible by 10K. Print -1 if it is impossible.ExampleIf N = 10203027 and K = 2 then we have to remove 3 digits. If we remove 3, 2 and 7 then number become 10200 which is divisible by 102Algorithm1. Start traversing number from end. If the current digit is not zero, increment the counter variable, otherwise decrement variable K 2. If K is zero, then return counter as answer 3. After ...

Read More

C++ Program for Coefficient of variation

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 751 Views

We are given with an array of float values of size n and the task is to find the coefficient of variation and display the result.What is the coefficient of variation?In statistic measure, coefficient of variation is used to find the range of variability through the data given. In terms of finance, coefficient of variation is used to find the amount of risk involved with respect to the amount invested. If the ratio between standard deviation and mean is low then the risk involved in the investment is also low. Coefficient of variation is the ratio between standard deviation and ...

Read More

C++ Program for Shortest Job First (SJF) scheduling(non-preemptive)

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 7K+ Views

Given process, the burst time of a process respectively and a quantum limit; the task is to find and print the waiting time, turnaround time and their respective average time using Shortest Job First Scheduling non-preemptive method.What is the shortest job first scheduling?Shortest job first scheduling is the job or process scheduling algorithm that follows the nonpreemptive scheduling discipline. In this, scheduler selects the process from the waiting queue with the least completion time and allocate the CPU to that job or process. Shortest Job First is more desirable than FIFO algorithm because SJF is more optimal as it reduces ...

Read More

Minimum steps to delete a string after repeated deletion of palindrome substrings in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 1K+ Views

Problem statementGiven a string containing characters as integers only. We need to delete all character of this string in a minimum number of steps where in one step we can delete the substring which is a palindrome. After deleting a substring remaining parts are concatenated.ExampleIf input string is 3441213 then minimum 2 steps requiredFirst remove 121 from string. Now remaining string is 3443Remove remaining string as it’s palindromeAlgorithmWe can use dynamic programming to solve this problem1. Let dp[i][j] denotes the number of steps it takes to delete the substring s[i, j] 2. Each character will be deleted alone or as ...

Read More

Minimum steps to remove substring 010 from a binary string in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 272 Views

Problem statementGiven a binary string, the task is to count the minimum steps to remove substring 010 from this binary stringExampleIf input string is 010010 then 2 steps are requiredConvert first 0 to 1. Now string becomes 110010Convert last 0 to 1. Now final string becomes 110011Algorithm1. Iterate the string from index 0 sto n-2 2. If in binary string has consecutive three characters ‘0’, ‘1’, ‘0’ then any one character can be changed Increase the loop counter by 2Example#include using namespace std; int getMinSteps(string str) {    int cnt = 0;    for (int i = 0; ...

Read More

Minimum steps to make all the elements of the array divisible by 4 in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 555 Views

Problem statementGiven an array of size n, the task iss to find the minimum number of steps required to make all the elements of the array divisible by 4. A step is defined as removal of any two elements from the array and adding the sum of these elements to the arrayExampleIf input array is {1, 2, 0, 2, 4, 3} then 3 operations are required −1 + 3 = 4 2 + 2 = 4 0 + 4 = 4Algorithm1. Sum of all the elements of the array should be divisible by If not, this task is not possible ...

Read More

Minimum sum falling path in a NxN grid in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 283 Views

Problem statementGiven a matrix A of integers of size NxN. The task is to find the minimum sum of a falling path through A.A falling path will start at any element in the first row and ends in last row.It chooses one element from each next row. The next row’s choice must be in a column that is different from the previous row’s column by at most onesExampleIf N = 2 and matrix is: {    {5, 10},    {25, 15} } then output will be 20 as element 5 and 15 are selectedExample#include #define MAX 2 using namespace ...

Read More

Priority Queue using doubly linked list in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 847 Views

We are given with the data and the priority as an integer value and the task is to create a doubly linked list as per the priority given and display the result.Queue is a FIFO data structure in which the element which is inserted first is the first one to get removed. A Priority Queue is a type of queue in which elements can be inserted or deleted depending upon the priority. It can be implemented using queue, stack or linked list data structure. Priority queue is implemented by following these rules −Data or element with the highest priority will ...

Read More
Showing 2231–2240 of 5,962 articles
« Prev 1 222 223 224 225 226 597 Next »
Advertisements