Found 7347 Articles for C++

Remove repeated digits in a given number using C++

Prateek Jangid
Updated on 29-Nov-2021 09:44:27

428 Views

In this article, we are given a number n, and we need to remove repeated digits in a given number.Input: x = 12224 Output: 124 Input: x = 124422 Output: 1242 Input: x = 11332 Output: 132In the given problem, we will go through all the digits and remove the repeating digits.Approach to find The SolutionIn the given approach, we will go through all the digits of n from right to left now. We go through digits of n by taking mod of n with 10 and then dividing n with 10. Now our current digit is n ... Read More

Remove Leading Zeros from an Array using C++

Prateek Jangid
Updated on 29-Nov-2021 09:42:10

585 Views

We are provided an array, and we are tasked to remove the leading zeros from the given array and then print the array.Input : arr[] = {0, 0, 0, 1, 2, 3} Output : 1 2 3 Input : arr[] = {0, 0, 0, 1, 0, 2, 3} Output : 1 0 2 3We can make a new array that doesn’t contain the leading zeroes of the previous array in the given problem.Approach to find The SolutionIn this approach, we will go through the array and insert all the numbers but no leading zeros.Example#include using namespace std; ... Read More

Remove Last Node of the Linked List using C++

Prateek Jangid
Updated on 29-Nov-2021 09:36:35

146 Views

We are provided with a singly linked list, and we are tasked to remove the last node from that list. In this problem, we are simply going to traverse through the given list and simply remove the last node.Approach to find The SolutionIn this approach, we go through the given list, and we keep track of the previous node and the current node. Now when our current node becomes the last node, we change previous -> next to NULL and delete the current node.Example#include using namespace std; struct Node {    int data;    struct Node* next; }; ... Read More

Remove First Node of the Linked List using C++

Prateek Jangid
Updated on 26-Nov-2021 11:18:33

163 Views

Given a linked list, we need to remove its first element and return the pointer to the head of the new list.Input : 1 -> 2 -> 3 -> 4 -> 5 -> NULL Output : 2 -> 3 -> 4 -> 5 -> NULL Input : 2 -> 4 -> 6 -> 8 -> 33 -> 67 -> NULL Output : 4 -> 6 -> 8 -> 33 -> 67 -> NULLIn the given problem, we need to remove the first node of the list and move our head to the second element and return the head.Approach to ... Read More

Remove Every K-th Node Of The Linked List

Prateek Jangid
Updated on 26-Nov-2021 11:12:25

395 Views

In this article, we will explain the way to remove every k-th node of the linked list. We must delete every node that sits on the multiple of k, i.e., we have to delete the node on positions k, 2*k, 3*k, etc.Input : 112->231->31->41->54->63->71->85    k = 3 Output : 112->231->41->54->71->85 Explanation: As 3 is the k-th node after its deletion list would be : First iteration :112->231->41->54->63->71->85 Now we count from 41 the next kth node is 63 After the second iteration our list will become : 112->231->41->54->71->85 And our iteration continues like this. Input: 14->21->23->54->56->61    k ... Read More

Remove a Given Word from a String using C++

Prateek Jangid
Updated on 26-Nov-2021 10:46:47

3K+ Views

In this article, we’ll be solving the problem of removing a given word from a given string. For example −Input : str = “remove a given word ”, word = “ remove ” Output : “ a given word ” Input : str = “ god is everywhere ”, word = “ is ” Output : “ god everywhere ”Approach to find The SolutionFor example, we can use a simple approach to remove a word from a string.First, put the given string in 2-D matrix form, where each word is stored in each row.Find the word in the matrix ... Read More

Rearrange an Array to Maximize i*arr[i] using C++

Prateek Jangid
Updated on 26-Nov-2021 10:41:11

834 Views

In this article, we will discuss the problem of rearranging a given array of n numbers. Basically, we have to select elements from the array. For selecting each element, we get some points that will be evaluated by the value of the current element * a number of elements selected before the current element. You should select elements to get maximum points. For Example −Input : arr[ ] = { 3, 1, 5, 6, 3 } If we select the elements in the way it is given, our points will be    = 3 * 0 + 1 * ... Read More

Rearrange An Array In Order – Smallest, Largest, 2nd Smallest, 2nd Largest,. Using C++

Prateek Jangid
Updated on 26-Nov-2021 10:32:44

547 Views

We are given an array; we need to arrange this array in an order that the first element should be a minimum element, the second element should be a maximum element, the third element should be 2nd minimum element, the fourth element should be the 2nd maximum element and so on for example −Input : arr[ ] = { 13, 34, 30, 56, 78, 3 } Output : { 3, 78, 13, 56, 34, 30 } Explanation : array is rearranged in the order { 1st min, 1st max, 2nd min, 2nd max, 3rd min, 3rd max } Input ... Read More

Rearrange an Array in Maximum Minimum Form using C++

Prateek Jangid
Updated on 26-Nov-2021 10:26:52

203 Views

We are given a sorted array. We need to arrange this array in maximum, minimum form, i.e., the first element is the maximum element, the second element is the minimum element, the third element is 2nd maximum element, the fourth element is 2nd minimum element, and so on, for example −Input : arr[ ] = { 10, 20, 30, 40, 50, 60 } Output : { 60, 10, 50, 20, 40, 30 } Explanation : array is rearranged in the form { 1st max, 1st min, 2nd max, 2nd min, 3rd max, 3rd min } Input : arr [ ... Read More

Rank of All Elements in an Array using C++

Prateek Jangid
Updated on 26-Nov-2021 10:20:02

971 Views

In the given problem, we need to rank all the given elements of an array, with the smallest number having the smallest rank and the largest having the largest rank. We also need to change the ranks of a number depending on their frequencies, for examples −Input : 20 30 10 Output : 2.0 3.0 1.0 Input : 10 12 15 12 10 25 12 Output : 1.5, 4.0, 6.0, 4.0, 1.5, 7.0, 4.0 Here the rank of 10 is 1.5 because there are two 10s present in the given array now if we assume they both take ... Read More

Advertisements