Programming Articles

Page 1424 of 2547

Minimum removal to make palindrome permutation in C++

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

Problem statementGiven a string S, we have to find minimum characters that we can remove to make any permutation of the string S a palindromeExampleIf str = “abcdba” then we remove to 1 character i.e. either ‘c’ or ‘d’.Algorithms1. There can be two types of a palindrome, even length, and odd length palindromes 2. We can deduce the fact that an even length palindrome must have every character occurring even number of times 3.An odd palindrome must have every character occurring even number of times except one character occurring odd number of time 4. Check the frequency of every character ...

Read More

Printing Pyramid in C++

Ajay yadav
Ajay yadav
Updated on 11-Mar-2026 514 Views

This article yields a “pyramid-like structure” as an output using the C++ programming code. In which the pyramid height and space are being determined by traversing double for loop constructs as following;Example#include using namespace std; int main() {    int space, rows=6;    for(int i = 1, k = 0; i

Read More

Convert min Heap to max Heap in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 811 Views

In this tutorial, we will be discussing a program to convert min heap to max heap.For this we will be provided with the array representation of the min heap. Our task is to convert that given min heap to max heap in O(n) time complexity.Example#include using namespace std; //converting a given subtree into a heap void convert_arrayheap(int arr[], int i, int n){    int l = 2*i + 1;    int r = 2*i + 2;    int largest = i;    if (l < n && arr[l] > arr[i])       largest = l;    if (r < ...

Read More

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

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

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

Read More

Construct a frequency array of digits of the values obtained from x^1, x^2, ....., x^nn in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 188 Views

Suppose we have two integers x and n. We have to find the array such that it contains the frequency of index numbers occurring in (x^1, x^2, … x^(n – 1), x^n). So if x = 15 and n = 3, then output will be [0, 1, 2, 2, 0, 3, 0, 1, 0, 0]. As we know that x^1 to x^n, the values are 15, 225 and 3375. So the frequency array is 0, 1, 2, 2, 0, 3, 0, 1, 0, 0To solve this, we will follow these steps −Maintain the frequency count array to store the counts ...

Read More

Construct a graph from given degrees of all vertices in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 399 Views

Suppose we have a list of vertices, and their degrees are given. We have to generate one undirected graph from that degree sequence. It will not include loop or multiple edges. So if the degree sequence is like [2, 2, 1, 1], then the graph can be likeTo solve this, we will follow these steps −Define adjacency matrix adj to store the graphfor each vertex i, dofor each vertex j that is valid, and next to iif the degree of vertex i and j are more than zero, then connect themdisplay the matrix.Example#include #include using namespace std; void ...

Read More

Convert singly linked list into circular linked list in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 650 Views

In this tutorial, we will be discussing a program to convert a singly linked list into circular linked list.For this we will be provided with a singly linked list. Our task is to take the elements of that list and get it converted into a circular linked list.Example#include //node structure of linked list struct Node {    int data;    struct Node* next; }; //converting singly linked list //to circular linked list struct Node* circular(struct Node* head){    struct Node* start = head;    while (head->next != NULL)       head = head->next;    //assigning start to the ...

Read More

C++ Program for Expressionless Face Pattern printing

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 381 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

Convert singly linked list into XOR linked list in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 362 Views

In this tutorial, we will be discussing a program to convert a singly linked list into XOR linked list.For this we will be provided with a singly linked list. Our task is to take the elements of that list and get it converted into a XOR linked list.Example#include using namespace std; //node structure of linked list struct Node {    int data;    struct Node* next; }; //creation of new node Node* newNode(int data){    Node* temp = new Node;    temp->data = data;    temp->next = NULL;    return temp; } //printing singly linked list void print(Node* head){ ...

Read More
Showing 14231–14240 of 25,466 articles
Advertisements