Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 42 of 81

Count elements in a vector that match a target value or condition in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 702 Views

We are given a vector and the task is to calculate the count of those elements in a vector that matches a target value or condition.Vectors are sequence containers that can change size. Container is an object that holds data of the same type. Sequence containers store elements strictly in linear sequence.Vector stores elements in contiguous memory locations and enables direct access to any element using subscript operator []. Unlike arrays, vectors can shrink or expand as needed at run time. The storage of the vector is handled automatically.To support shrink and expand functionality at runtime, vector containers may allocate ...

Read More

Count half nodes in a Binary tree (Iterative and Recursive) in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 504 Views

We are given a binary tree and the task is to calculate the count of half nodes available in a binary tree using iterative and recursive approach. Half nodes are those nodes who have only one child and another child is null. Note that in half nodes we don't consider leaf nodes.Binary Tree is a special data structure used for data storage purposes. A binary tree has a special condition that each node can have a maximum of two children. A binary tree has the benefits of both an ordered array and a linked list as search is as quick ...

Read More

Count full nodes in a Binary tree (Iterative and Recursive) in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 1K+ Views

We are given a binary tree and the task is to calculate the count of full nodes available in a binary tree using iterative and recursive approach. Full nodes are those nodes who have both the children and no child is null. Note that in full nodes we consider nodes with exactly two children.Binary Tree is a special data structure used for data storage purposes. A binary tree has a special condition that each node can have a maximum of two children. A binary tree has the benefits of both an ordered array and a linked list as search is ...

Read More

Count number of binary strings of length N having only 0’s and 1’s in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 601 Views

We are given a number let’s say, num and the task is to calculate the count of binary strings that can be formed through the given number num containing only o’s and 1’s.Binary Number System is one the type of Number Representation techniques. It is most popular and used in digital systems. Binary system is used for representing binary quantities which can be represented by any device that has only two operating states or possible conditions. For example, a switch has only two states: open or close.In the Binary System, there are only two symbols or possible digit values, i.e., ...

Read More

Count number of bits changed after adding 1 to given N in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 252 Views

We are given a number let’s say num and the task is to calculate the total number of bits changed when 1 is added to a number.Binary representation of a number is done by converting the given number into the form of 0’s and 1’s and it is done by various methods. In one method, we calculate the LCM of a given number by 2 and if a reminder is other than 0 then the bit is set to 1 else it will be set to 0.Addition table for bits are0 + 1 = 1 1 + 0 = 1 ...

Read More

Count number of edges in an undirected graph in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 1K+ Views

Given the task is to count the number of edges in an undirected graph. An undirected graph is a set of vertices which are connected together to form a graph, whose all the edges are bidirectional. Undirected graphs can travel in any direction from one node to another connected node.Below is a visual representation of the undirected graph.Now, according to the problem we have to find the number of edges in the undirected graph.Edges in a graph are the lines to which two vertices are joined.Input −insert(graph_list, 0, 1); insert(graph_list, 0, 2); insert(graph_list, 1, 2); insert(graph_list, 1, 4); insert(graph_list, 2, ...

Read More

Count minimum frequency elements in a linked list in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 444 Views

Given the task is to count the minimum frequency elements in a given linked list which is having duplicate elements.A linked list is a data structure in which the data is stored in the serial order, like a list each element is linked to the next element.The frequency of an element in a linked list refers to the number of times an element is occurring in the linked list. According to the problem we have to count the minimum frequency in a linked list.Let us suppose we have a linked list, 1, 1, 3, 1, 3, 4, 6; where the ...

Read More

set vs unordered_set in C++ STL(3)

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 1K+ Views

In this article, let us understand what is set and unordered_set in C++ STL and thereby gain knowledge of difference between them.What is set?A set is an Associative container which contains a sorted set of unique objects of type Key. Each element may occur only once, so duplicates are not allowed. A user can create a set by inserting elements in any order and the set will return a sorted data to the user which means set contains definition for sorting the data which is abstracted from the user.The main reasons when set can be used are −When sorted data ...

Read More

Maximum area of rectangle possible with given perimeter in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 430 Views

Given a perimeter of a rectangle, the task is to find the maximum area of the rectangle with that given perimeter.A rectangle is a type of parallelogram whose opposite sides are equal and parallel.The perimeter of a rectangle is the sum of all sides of a rectangle; we can also say perimeter is the total distance of the outside of the rectangle.The formula to find the perimeter of a rectangle is − Length + Breadth + Length + Breadth or 2(Length + Breadth)Whereas the area of a rectangle is the size of the rectangular object. The formula for finding the ...

Read More

Count entries equal to x in a special matrix in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 406 Views

Given a square matrix, mat[][] let the elements of the matrix me mat[i][j] = i*j, the task is to count the number of elements in the matrix is equal to x.Matrix is like a 2d array in which numbers or elements are represented as rows and columns.So, let's understand the solution of the problem with the help of examples −Input −matrix[row][col] = {    {1, 2, 3},    {3, 4, 3},    {3, 4, 5}}; x = 3Output −Count of entries equal to x in a special matrix: 4Input −matrix[row][col] = {    {10, 20, 30},    {30, 40, 30}, ...

Read More
Showing 411–420 of 809 articles
« Prev 1 40 41 42 43 44 81 Next »
Advertisements