Hafeezul Kareem

Hafeezul Kareem

258 Articles Published

Articles by Hafeezul Kareem

Page 12 of 26

Largest subarray with equal number of 0s and 1s in C++

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

Let's see the steps to complete the program.Initialise the array.Make all zeroes in the array to -1.Have a map an empty map to store the previous indexes.Initialise sum to 0, max length to 0 and ending index to -1.Write a loop that iterates till n.Add current element to sum.If the sum is equal to 0.Update the max length with i + 1.And ending index to i.If the sum is present in previous sums map and i - previousIndexes[sum] is greater than max length.Update the max length and ending index.Else add the sum to the previous indexes map.Print the starting index ...

Read More

Largest sum subarray with at-least k numbers in C++

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

Let's see the steps to complete the program.Initialise the array.Initialise max_sum array of size n.Find the max sum for every index and store it in max_sum array.Compute the sum of all the elements and store it in a variable sum.Write a loop that iterates from i = k to n.Add a[i] - a[i - k] to the sum.Update the result with max of result, sum.Update the result with max of result, sum + max_sum[i - k].ExampleLet's see the code.#include using namespace std; int getMaxSum(int a[], int n, int k) {    int maxSum[n];    maxSum[0] = a[0];    int currentMax ...

Read More

Deletion in a Binary Tree in C++ Program

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

In this tutorial, we are going to learn how to delete a node in a binary tree.The nodes in a binary tree don't follow any order like binary search trees. So, how to arrange the nodes after deleting a node in a binary tree?Well, we will replace the deepest node of the tree with the deleting node. And then we will delete the deepest node from the node.Let's see the steps to solve the problem.Initialize the tree with binary node struct.Write a function (preorder, in order, and postorder) to print the nodes of the tree.Write a function to delete the ...

Read More

Deletions of "01" or "10" in binary string to make it free from "01" or "10" in C++ Program

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

In this tutorial, we are going to write a program that finds the total number of pairs (01 or 10) to free the binary string from the pairs (01 and 10). Let's see an example.Input − 101010001Output − 4In the above example, we have to delete a total of 4 pairs to free the binary string from the pairs (01 and 10).The resultant string after deleting all the pairs is 0.We have to delete all the 01 and 10 pairs from the binary string. So, the total number of pairs to be deleted is the minimum of count(1) and count(0).Let's ...

Read More

Depth of an N-Ary tree in C++ Program

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

In this tutorial, we are going to learn how to find the depth of the n-ary tree.An n-ary tree is a tree in which each node of the tree has no more than n child nodes.We have to find the depth of the n-ary tree. We will be using the vector to store the children of each node in the tree.Let's see the steps to solve the problem.Initialize the tree with dummy data.Write a recursive function to find the depth of the n-ary tree.Initialize a variable to store the max depth of the tree.Iterate over the children of each node.The ...

Read More

Deserium Number with examples in C++ Program

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

In this tutorial, we are going to learn about the deserium numbers with examples.The number whose sum of pow(digit, digitsCount) is equal to the given number is called Deserium number.Let's see the steps to find whether the given number is deserium number or not.Initialize the number.Find the digits count of the number.Initialize a variable to store the sum.Iterate until the number is less than 0.Get the last digit by diving the number with 10.Add the pow(digit, digitsCount) to the sum.If the sum is equal to the number, then it is deserium number else it is not.ExampleLet's see the code.#include ...

Read More

Determine the position of the third person on regular N sided polygon in C++ Program

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

In this tutorial, we are going to learn how to find the position of a third person on a regular N-sided polygon.We have given a regular N-sided polygon. And there are two persons on two different points already. Our task is to find the third point to place the third person such that the distance between the first two persons and the third person is minimized.Let's see the steps to solve the problem.Initialize the N and two points A and B.Initialize the position of the third person, and the minimum sum to find the position.Iterate from 1 to N.If the ...

Read More

Diagonal of a Regular Heptagon in C++ Program

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

In this tutorial, we are going to learn how to find the diagonal of a regular heptagon.We have to find the length of the diagonal of the regular heptagon using the given side. The length of the diagonal of a regular heptagon is 1.802 * s where s is the side of the heptagon.ExampleLet's see the code.#include using namespace std; float heptagonDiagonal(float s) {    if (s < 0) {       return -1;    }    return 1.802 * s; } int main() {    float s = 7;    cout

Read More

Diagonal of a Regular Pentagon in C++ Program

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

In this tutorial, we are going to learn how to find the diagonal of a regular pentagon.We have to find the length of the diagonal of the regular pentagon using the given side. The length of the diagonal of a regular pentagon is 1.22 * s where s is the side of the pentagon.ExampleLet's see the code.#include using namespace std; float pentagonDiagonal(float s) {    if (s < 0) {       return -1;    }    return 1.22 * s; } int main() {    float s = 7;    cout

Read More

Different possible marks for n questions and negative marking in C++ Program

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

In this tutorial, we are going to write a program that finds different possible marks for the given n questions with positive and negative marking.Let's say we have 10 questions and each carries 2 marks for correct answers and -1 marks for a negative answer. Our aim is to find all the possible ways in which a student can score in the exam.Let's see the steps to solve the problem.Initialize the number of questions, positive marks for the correct answer and negative marks for the wrong answer.Initialize a set to store the possible marks.Write two inner loops from 0 to ...

Read More
Showing 111–120 of 258 articles
« Prev 1 10 11 12 13 14 26 Next »
Advertisements