Hafeezul Kareem

Hafeezul Kareem

259 Articles Published

Articles by Hafeezul Kareem

259 articles

Largest gap in an array in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 03-Dec-2024 340 Views

In this tutorial, we are going to write a program that finds the largest difference between the two elements in the given array. Approach Let's look at the approach we will follow to solve this problem. Firstly, we will initialize the array. Then we will find or search for the max and min elements in the array. And will return max - min. Example Here is the following code for finding the largest gap in an array in C++. #include using namespace std; ...

Read More

Delete a node in a Doubly Linked List in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 03-Dec-2024 7K+ Views

In this tutorial, we are going to learn how to delete a node in the doubly linked list. Approach Let's see the steps to solve the problem. Write struct with data, prev, and next pointers. Write a function to insert the node into the doubly linked list. Initialize the doubly ...

Read More

Create linked list from a given array in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 15-Sep-2023 29K+ Views

In this tutorial, we are going to learn how to create a linked list from the given array.Let's see the steps to solve the problem.Initialize the array with dummy data.Write the struct node.Iterate over the array.Create a new node with the data.Insert the new node into the linked list.Print the linked list.ExampleLet's see the code.#include using namespace std; struct Node {    int data;    Node* next; }; struct Node* newNode(int data) {    Node* node = new Node;    node->data = data;    node->next = NULL;    return node; } void insertNewNode(Node** root, int data) {    Node* ...

Read More

Adding a new column to existing DataFrame in Pandas in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 26-Aug-2023 35K+ Views

In this tutorial, we are going to learn how to add a new column to the existing DataFrame in pandas. We can have different methods to add a new column. Let's all of them.Using ListWe can add a new column using the list. Follow the steps to add a new column.Algorithm1. Create DataFrame using a dictionary. 2. Create a list containing new column data. Make sure that the length of the list matches the length of the data which is already present in the data frame. 3. Add the list to the DataFrame like dictionary element.Let's see one example.Example# importing ...

Read More

Multiples of 3 and 5 without using % operator in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Oct-2021 733 Views

We can find the multiples using % operator without any hurdles. But, the problem states that we can't use % operator.Here, we make use of the + operator. We can get the multiples by adding 3 or 5 to the previous multiple. Let's see an example.Input15Output1 2 3 - Multiple of 3 4 5 - Multiple of 5 6 - Multiple of 3 7 8 9 - Multiple 3 10 - Multiple of 5 11 12 - Multiple of 3 13 14 15 - Multiple of both 3 and 5AlgorithmInitialise the number n.Initialise two number to keep track of next ...

Read More

Number of pairs with Bitwise OR as Odd number in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 26-Oct-2021 290 Views

Given an array, we have to find the number of pairs whose Bitwise OR is an odd number. Let's see the example.Inputarr = [1, 2]Output1 There is only one pair whose Bitwise OR is an odd number. And the pair is (1, 2).AlgorithmInitialise the array with random numbers.Initialise the count to 0.Write two loops to get the pairs of the array.Compute the bitwise OR between every pair.Increment the count if the result is an odd number.Return the count.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; int getOddPairsCount(int arr[], int n) {    int count ...

Read More

Number of pairs whose sum is a power of 2 in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 26-Oct-2021 958 Views

Given an array, we have to find the number of pairs whose sum is a power of 2. Let's see the example.Inputarr = [1, 2, 3]Output1 There is only one pair whose sum is a power of 2. And the pair is (1, 3).AlgorithmInitialise array with random numbers.Initialise the count to 0.Write two loops to get all the pairs of the array.Compute the sum of every pair.Check whether the sum is a power of 2 or not using bitwise AND.Increment the count if the count is a power of 2.Return the count.ImplementationFollowing is the implementation of the above algorithm in ...

Read More

Number of pairs from the first N natural numbers whose sum is divisible by K in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 26-Oct-2021 230 Views

Given numbers N and K, we have to count the number of pairs whose sum is divisible by K. Let's see an example.InputN = 3 K = 2Output1 There is only one pair whose sum is divisible by K. And the pair is (1, 3).AlgorithmInitialise the N and K.Generate the natural numbers till N and store them in an array.Initialise the count to 0.Write two loops to get all pairs from the array.Compute the sum of every pair.If the pair sum is divisible by K, then increment the count.Return the count.ImplementationFollowing is the implementation of the above algorithm in C++#include ...

Read More

Number of ordered points pair satisfying line equation in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 26-Oct-2021 226 Views

The line equation that should be satisfied is y = mx + c. Given an array, m, and c, we have to find the number of order points satisfying the line equation. Let's see an example.Inputarr = [1, 2, 3] m = 1 c = 1Output2The pairs satisfying the line equation are2 1 3 2AlgorithmInitialise the array, m, and c.Write two loops to get all pairs from the array.Check whether the pair is satisfying the line equation or not.We can check the whether the equation is satisfied or not by substituting the values into the line equation.If the pair satisfies ...

Read More

Number of non-negative integral solutions of sum equation in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 26-Oct-2021 261 Views

In this tutorial, we are going to write a program that finds the number non-negative integral solution of sum equation.The sum equation is x + y + z = n. You are given the number n, you need to find the number of solutions for the equation. Let's see an example.Input2Output6Solutions are0 0 2 0 1 1 0 2 0 1 0 1 1 1 0 2 0 0AlgorithmInitialise the number m.Initialise the count to 0.Write three nested loops to get all the combinations of three numbers.Check the validation of the equation.If the current numbers satisfies the equation, then increment ...

Read More
Showing 1–10 of 259 articles
« Prev 1 2 3 4 5 26 Next »
Advertisements