Hafeezul Kareem

Hafeezul Kareem

259 Articles Published

Articles by Hafeezul Kareem

Page 8 of 26

Find a number that divides maximum array elements in C++

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

In this tutorial, we are going to find the number that is divided into maximum elements in the given array.Let's see the steps to solve the problem.Initialize the array and a variable to store the result.Iterate over the array.Initialize the counter variable.Iterate over the array again.Increment the counter if the current element is divisible by the array element.Update the result if the current count is maximum.Print the result.ExampleLet's see the code.#include using namespace std; int numberWithMaximumMultiples(int arr[], int n) {    int result = -1;    for (int i = 0; i < n; i++) {       ...

Read More

Find a Number X whose sum with its digits is equal to N in C++

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

In this tutorial, we are going to find a number whose some including with its digits is equal to the given number N.The idea is simple, we are going to check the left and right 100 numbers of the given number. It won't lie out that bound as N ≤ 1000000000 and the sum won't exceed 100.Let's see the steps to solve the problem.Initialize the number.Write a loop that iterates 100 times.Get the n - i and n + i values.Find the sum of the digits and add them.If anyone of them is equal to the N, print them.ExampleLet's see ...

Read More

Find a partition point in array in C++

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

In this tutorial, we are going to find the partition point in an array where all the elements left to the partition point are small and all the elements right to the partition point are large.Let's see the steps to solve the problem.Initialize the array.Iterate over the array.Iterate from 0 to I and check each value whether it is smaller than the current value or not.Iterate from I to n and check each value whether it is larger than the current value or not.If the bot the conditions satisfied, then return the value.Print the partition point.ExampleLet's see the code.#include ...

Read More

Find a peak element in a 2D array in C++

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

In this tutorial, we are going to write a program that finds the peak element in a 2D array.An element is called a peak element if all the elements around it are smaller than the element.Let's see the steps to solve the problem.Initialize the 2D array with dummy data.Iterate over the 2D array.First, check the corner elements of the 2D array.Next, write the conditions for the first and last rows of the 2D array.Now, check for the first and last columns of the 2D array.And finally, check the middle elements.In each case, we have to compare the current element with ...

Read More

Find a peak element in Linked List in C++

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

In this tutorial, we are going to write a program that finds the peak element in the given linked list.The peak element is an element that is greater than the surrounding elements. Let's see the steps to solve the problem.Create a struct node for the linked list.Create the linked list with dummy data.Check for the base cases like whether the linked list is empty or of length 1.Store the first element in a variable called previous.Iterate over the linked list.Check whether the current element is greater than the previous element and the next element.Return if the above condition satisfies.Update the ...

Read More

Find a peak element in C++

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

In this tutorial, we are going to write a program that finds the peak element in the given arrayThe peak element is an element that is greater than the surrounding elements. Let's see the steps to solve the problem.Initialize the array with dummy data.Check for the first element and last element for the peak element condition.Iterate over the array from the second element.Check whether the current element is greater than the previous element and the next element.Return if the above condition satisfies.Print the resultExampleLet's see the code.#include using namespace std; int findPeakElement(int arr[], int n) {    if (n ...

Read More

Find a triplet from three linked lists with a sum equal to a given number in C++

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

In this tutorial, we are going to write a program that finds the triplet in the linked list whose sum is equal to the given number.Let's see the steps to solve the problem.Create a struct node for the linked list.Create the linked list with dummy data.Write three inner loops for three elements which iterate until the end of the linked list.Add the three elements.Compare the sum with the given number.If both are equal, then print the elements and break the loops.ExampleLet's see the code.#include using namespace std; class Node {    public:    int data;    Node* next; }; ...

Read More

Find a triplet that sum to a given value in C++

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

In this tutorial, we are going to write a program that finds the triplet in the array whose sum is equal to the given number.Let's see the steps to solve the problem.Create the array with dummy data.Write three inner loops for three elements which iterate until the end of the array.Add the three elements.Compare the sum with the given number.If both are equal, then print the elements and break the loops.ExampleLet's see the code.#include using namespace std; bool findTriplet(int arr[], int arr_size, int sum) {    for (int i = 0; i < arr_size - 2; i++) {   ...

Read More

Find a value whose XOR with given number is maximum in C++

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

In this tutorial, we are going to write a program that finds the number whose XOR operation with the given number is maximum.We are assuming the number of bits here is 8.The XOR operation of different bits gives you the 1 bit. And the XOR operation between the same bits gives you the 0 bit.If we find the 1's complement of the given number, then that's the number we are looking for.ExampleLet's see the code.#include using namespace std; int findNumberWithMaximumXOR(int X) {    return ((1

Read More

Find all triplets with zero sum in C++

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

In this tutorial, we are going to write a program that finds the triplet in the array whose sum is equal to the given number.Let's see the steps to solve the problem.Create the array with dummy data.Write three inner loops for three elements that iterate until the end of the array.Add the three elements.Compare the sum with 0.If both are equal, then print the elements and break the loops.ExampleLet's see the code.#include using namespace std; void findTripletsWithSumZero(int arr[], int n){    bool is_found = false;    for (int i = 0; i < n-2; i++) {       for ...

Read More
Showing 71–80 of 259 articles
« Prev 1 6 7 8 9 10 26 Next »
Advertisements