Found 33676 Articles for Programming

Find the one missing number in range using C++

sudhir sharma
Updated on 11-Feb-2022 11:31:24

579 Views

In this problem, we are given an arr[] of size n. Our task is to find the one missing number in range.The array consists of all values ranging from smallest value to (smallest + n). One element of the range is missing from the array. And we need to find this missing value.Let’s take an example to understand the problem, Inputarr[] = {4, 8, 5, 7}Output6Solution ApproachA simple solution to the problem is by searching the missing element by sorting the array and then finding the first element of range starting from minimum value which is not present in the ... Read More

Maximum occurring character in an input string using C++

sudhir sharma
Updated on 11-Feb-2022 11:27:16

6K+ Views

In this problem, we are given an input string of lowercase characters. Our task is to maximum occurring character in an input string.In case of multiple values with the same frequency of occurrence, we need to print lexicographically smaller values.Let’s take an example to understand the problem, Inputstring = “programming”OutputgSolution ApproachTo find the solution to the problem, we need to sort the read string and then traverse the string so that we could find the character which has maximum occurrence in the string. We would use hashing method (hash table method) to conquer this problem. Traversing and hashing the each ... Read More

Find the number of zeroes using C++

sudhir sharma
Updated on 11-Feb-2022 11:22:03

1K+ Views

In this problem, we are given a binary array bin[] consisting of only 0’s and 1’s. Our task is to find the number of zeroes.The array is sorted i.e. all 0’s are arranged together after 1’s.Let’s take an example to understand the problem, Inputarr[] = {1, 1, 1, 0, 0, 0, 0}Output4Solution ApproachA simple solution to the problem is using the fact that the array is sorted, that is the number of 0’s in the array can be found using the first occurrence of 0 in the array. As after the first occurrence all values will be zero.For finding the ... Read More

Find the number of stair steps using C++

sudhir sharma
Updated on 11-Feb-2022 11:13:14

293 Views

In this problem, we are given a number N denoting the number of bricks provided to create the stair. Our task is to find the number of stair steps.Using the given bricks, we need to create a stair step. Each step takes one more brick that the last step. And the first step is two bricks high. We need to find the number of such steps that can be made from bricks.Let’s take an example to understand the problem, InputN = 40Output3ExplanationStep = 1 ; bricks required = 2; total bricks used = 2 ; bricks remaining = 38Step = ... Read More

Find the number of solutions to the given equation in C++

sudhir sharma
Updated on 11-Feb-2022 11:20:12

457 Views

In this problem, we are given three integer values A, B, C. Our task is to find the number of solutions to the given equation.EquationX = B*Sm(X)^A + Cwhere Sm(X) is the sum of digits of X.We need to count all the values of X such that it satisfies the above equation where X can be any number between 1 to 109.Let’s take an example to understand the problem, InputA = 3, B = 6, C = 4Output3Solution ApproachA solution to solve the problem is by counting the number of values of X. For this, the sum of digits plays ... Read More

Find the number of Islands Using Disjoint Set in C++

sudhir sharma
Updated on 11-Feb-2022 10:58:15

570 Views

In this problem, we are given a 2D binary matrix. Our task is to find the number of islands Using DFS.Island is a ground of 1 or more connected 1’s in the matrix.Let’s take an example to understand the problem, Inputbin[][] = {{ 1 0 0 0}    {0 1 0 1}    {0 0 0 0}    {0 0 1 0}}Output3 ExplanationIslands are :    bin00 - bin11    bin13    bin32Solution ApproachTo find the island from a binary matrix using a disjoint set data structure. To find island count, we will traverse the matrix and do union of ... Read More

Find the number of islands Using DFS in C++

sudhir sharma
Updated on 11-Feb-2022 10:27:51

333 Views

In this problem, we are given a 2D binary matrix. Our task is to Find the number of islands Using DFS.Island is a ground of 1 or more connected 1’s in the matrix.Let’s take an example to understand the problem, Input : bin[][] = {{ 1 0 0 0}    {0 1 0 1}    {0 0 0 0}    {0 0 1 0}} Output : 3 ExplanationIslands are −bin00 - bin11bin13bin32 Solution ApproachTo solve the problem using DFS, we will use the DFS technique for exploring all the neighbours (maximum possible 8 of a number in the matrix) and ... Read More

Program to find Nth Even Fibonacci Number in C++

sudhir sharma
Updated on 11-Feb-2022 07:17:27

605 Views

In this problem, we are given an integer value N. Our task is to find Nth Even Fibonacci Number.Fibonacci Series generates subsequent number by adding two previous numbers. The Fibonacci series starts from two numbers − F0 & F1. The initial values of F0 & F1 can be taken 0, 1 or 1, 1 respectively.Let’s take an example to understand the problem, Input : N = 4 Output : 144Solution ApproachA simple solution to the problem is using the fact that every third number in the fibonacci sequence is even and the sequence of even numbers also follows the recursive ... Read More

numpy.matrix Method in Python

Syed Abeed
Updated on 11-Feb-2022 06:41:54

200 Views

The numpy.matrix method is used to interpret a given input as a matrix. It returns a matrix from an array-like object. Its syntax is as follows −numpy.matrix(data, dtype=None, copy=bool)where, data - It is the input data.dtype - It represents the data type of the output matrix.copy - If the input data is already an ndarray, then this flag copy determines whether the data is to be copied (default behavior), or whether a view is to be constructed.Example 1Let us consider the following example −# import numpy library import numpy as np # matrix function y = np.matrix([[4, 5], [7, ... Read More

numpy.vander Method in Python

Syed Abeed
Updated on 11-Feb-2022 06:34:18

294 Views

The numpy.vander() method is used to generate a Vandermonde (Vander) matrix. A Vander matrix contains a geometric progression in each row, for example, $$\mathrm{A =\begin{bmatrix}1 & 2 & 4 \1 & 3 & 9 \1 & 5 &25\end{bmatrix} or\: B = \begin{bmatrix}1 & 4 & 16 \1 & 6 &36 \end{bmatrix}}$$SyntaxIts syntax is as follows −numpy.vander(x, N=None, increasing=False)ParametersIt accepts the following parameters −x - This is the input array.N - It is the number of columns in the output. By default, it is None.Increasing - If increasing=True, then the power increases from left to right. If increasing=False, then powers are ... Read More

Advertisements