Found 7197 Articles for C++

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

Sunidhi Bansal
Updated on 06-Jun-2020 11:49:25

361 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

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

Sunidhi Bansal
Updated on 06-Jun-2020 11:44:04

390 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

Containers in Bootstrap with examples(3)

Sunidhi Bansal
Updated on 06-Jun-2020 11:37:27

444 Views

As the name suggests, a container is used to hold or bind something likewise containers in bootstrap are used for storing or binding the content over a viewport. Containers add padding to the content by providing it margin from all the four sides of a viewport and it can also be altered depending upon the needs. Containers can also be nested inside one another.Now, let us understand each of the class in detailcontainerIn bootstrap, the .container class creates a responsive container with a fixed width in a viewport.It sets the max-width of a container depending upon the size of a ... Read More

set vs unordered_set in C++ STL(3)

Sunidhi Bansal
Updated on 06-Jun-2020 11:32:02

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

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

Sunidhi Bansal
Updated on 06-Jun-2020 11:28:07

398 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

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

Sunidhi Bansal
Updated on 06-Jun-2020 11:23:54

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

Total Hamming Distance in C++

Arnab Chakraborty
Updated on 05-Jun-2020 07:08:20

823 Views

Suppose we have a list of numbers. We have to find the Hamming distance of all pair of given numbers. We know that the Hamming distance between two integers is the number of positions at which the corresponding bits are different.So, if the input is like [4, 14, 17, 2], then the output will be 17.To solve this, we will follow these steps −m := 1^9 + 7Define a function add(), this will take a, b, return ((a mod m) + (b mod m))Define a function mul(), this will take a, b, return ((a mod m) * (b mod m))Define ... Read More

Minimum Genetic Mutation in C++

Arnab Chakraborty
Updated on 05-Jun-2020 07:01:54

316 Views

Suppose we have a gene string. That can be represented by a string whose length is 8, This string is consists of these letters [A, C, G, T]. Now consider we want to investigate about a mutation, where ONE mutation is actually ONE single character changed in the gene string. As an example, "AACCGTTT" is changed like "AACCGTTA" is 1 mutation.We also have a given gene "bank", where all the valid gene mutations are present. A gene must be in the bank to make it a valid gene string.Now suppose we have given 3 things - start, end, bank, our ... Read More

Maximum Score Words Formed by Letters in C++

Arnab Chakraborty
Updated on 04-Jun-2020 11:50:43

258 Views

Suppose we have a list of words, a list of single letters and score for every character. We have to find the maximum score of any valid set of words formed by using the given letters.We may not use all characters in letters and each letter can only be used once. Score of letters 'a', 'b', 'c', ... ,'z' is given by score[0], score[1], ... , score[25] respectively.So, if the input is like words = ["god", "good", "toc", "cat"], letters = [a, g, o, o, d, d, d, c, t, t] and score = [5, 0, 8, 3, 0, 0, ... Read More

Check If It Is a Good Array in C++

Arnab Chakraborty
Updated on 04-Jun-2020 11:47:28

2K+ Views

Suppose we have an array called nums of positive integers. We have to select some subset of nums, then multiply each element by an integer and add all these numbers. The array will be a good array if we can get a sum of 1 from the array by any possible subset and multiplicand.We have to check whether the array is good or not.So, if the input is like [12, 23, 7, 5], then the output will be True, this is because If we take numbers 5, 7, then 5*3 + 7*(-2) = 1To solve this, we will follow these ... Read More

Advertisements