Hafeezul Kareem

Hafeezul Kareem

258 Articles Published

Articles by Hafeezul Kareem

Page 17 of 26

Delete N nodes after M nodes of a linked list in C++ program

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 946 Views

In this tutorial, we are going to learn how to delete N nodes after M nodes in a linked list.Let's see the steps to solve the problem.Write a struct Node for the linked list node.Initialize the linked list with the dummy data.Write a function to delete N nodes after M nodes.Initialize a pointer with the head pointer.Iterate till the end of the linked list.Move the pointer to the next node until M nodes.Delete the N nodesMove the pointer to the next nodePrint the linked listExampleLet's see the code.#include using namespace std; struct Node {    int data;    Node ...

Read More

Deleting a binary tree using the delete keyword in C++ program

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 3K+ Views

In this tutorial, we are going to learn how to delete a binary tree using the delete keyword.We are going to use a destructor member function to delete the binary. The destructor member function is invoked automatically when the object goes out of the scope or it is destroyed by calling delete.The destructor member function has the name as a class with tilde (~) before it.Let's see the steps to solve the problem.Write a class called Node.Write a constructor function that accepts data for the node.Write a destructor function.Delete the left node.Delete the right node.Print the current node data.Initialize the ...

Read More

Find winner of an election where votes are represented as candidate names in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 887 Views

In this tutorial, we are going to write a program that finds the election winner. We will have an array of votes that each candidate got in the election. Let's see an example.Input {"A", "B", "C", "B", "A", "C", "D", "D", "A", "B", "D", "B", "A", "C", "D"}Output AHere, A and B got the same number of votes. In that case, we have to select the winner based on the alphabetical order of their names.Let's see the steps to solve the problem.Initialize an array of string with dummy data.Initialize a map with string as key and int as value.Iterate over the votes ...

Read More

Find zeroes to be flipped so that number of consecutive 1's is maximized in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 189 Views

In this tutorial, we are going to find the zeroes count that need to be flipped to get maximum number of consecutive 1's in the array.We are going to use the sliding window approach to solve the problem. Let's see the steps to solve the problem.Initialize the array and max zeroes to be flipped.Initialize window starting, ending indexes along with the length.Store the max sub array of consecutive 1's length and starting index.Iterate over the array until ending indexes crosses the array length.If the zeroes count is less than the max zeroes count then increment the ending index and zeroes ...

Read More

Finding sum of digits of a number until sum becomes single digit in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 9K+ Views

In this tutorial, we are going to write a program that sums digits of the given number until it becomes a single digit. Let's see an example.Input −4543Output −7Let's see the steps to solve the problem.Initialize a number.Initialize the sum to 0.Iterate until the sum is less than 9.Add each digit of the number to the sum using modulo operatorPrint the sumExampleLet's see the code.#include using namespace std; void findTheSingleDigit(int n) {    int sum = 0;    while(n > 0 || sum > 9) {       if(n == 0) {          n = sum;          sum = 0;       }       sum += n % 10;       n /= 10;    }    cout

Read More

First digit in factorial of a number in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 225 Views

In this tutorial, we are going to write a program the finds the first digit of a factorial. Let's see an example.Input − 7Output − 5Let's see the steps to solve the problem.Initialize the numberFind the factorial of the number.Divide the number until it becomes a single digit.ExampleLet's see the code.#include using namespace std; void findFirstDigitOfFactorial(int n) {    long long int fact = 1;    for (int i = 2; i = 10) {       fact = fact / 10;    }    cout

Read More

First N natural can be divided into two sets with given difference and co-prime sums in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 194 Views

In this tutorial, we have to find whether the natural numbers from 1 to n is divided into two halves or not. It has to satisfy the following conditions.The absolute difference between the two series sum should be m.And the GCD of two sums should be 1 i.e.., co-primes.The sum of first n natural numbers is (n*(n+1))/2. We can find the sumOne and sumTwo as we have total sum and difference m. See the below equations.sumOne + sumTwo = (n*(n+1))/2 sumOne - sumTwo = mExampleCheck whether the absolute sum is equal to m or not. And then check for GCD.#include ...

Read More

First triangular number whose number of divisors exceeds N in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 251 Views

In this tutorial, we are going to find a triangular number whose number of divisors are greater than n.If the sum of natural numbers at any point less than or equal to n is equal to the given number, then the given number is a triangular number.We have seen what triangular number is. Let's see the steps to solve the problem.Initialize the numberWrite a loop until we find the number that satisfies the given conditions.Check whether the number is triangular or not.Check whether the number has more than n divisors or not.If the above two conditions are satisfied then print ...

Read More

First uppercase letter in a string (Iterative and Recursive) in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 725 Views

In this tutorial, we are going to learn how find the first uppercase letter in the given string. Let's see an example.Input −TutorialspointOutput −TLet's see the steps to solve the problem using iterative method.Initialize the string.Iterate over the string.Check whether the current character is uppercase or not using isupper method.If the character is uppercase than return the current character.ExampleLet's see the code.#include using namespace std; char firstUpperCaseChar(string str) {    for (int i = 0; i < str.length(); i++)       if (isupper(str[i])) {          return str[i];       }       return ...

Read More

Fixed (or static) Partitioning in Operating System in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 1K+ Views

In this tutorial, we are going to learn about the fixed partitioning in the operating system.Fixed partitioning is one to manage the memory in operating system. It's an old technique. It divides the memory into equal blocks. The size of each block is predefined and can not be changed.The memory is used for the contiguous processes.ExampleLet's see the sample program that allocates memory based on the process size.#include using namespace std; int main() {    int blockNumber = 5, processesNumber = 3;    int blockSize[5] = {4, 4, 4, 4, 4}, processSize[3] = {1, 2, 3};    int flags[5], allocation[5]; ...

Read More
Showing 161–170 of 258 articles
« Prev 1 15 16 17 18 19 26 Next »
Advertisements