Found 33676 Articles for Programming

C++ Program to find pairs of sequences where sequence holds minimum and maximum elements

Arnab Chakraborty
Updated on 02-Mar-2022 11:23:37

362 Views

Suppose we have three numbers N, M and K. There are N horizontal rows and M vertical rows. We shall write an integer in between 1 and K on each cell, and define sequences A and B, such that −for each i in range 1 to N, A[i] is minimum of all elements in ith rowfor each j in range 1 to M, B[j] is maximum of all elements in jth columnWe have to find the number of pairs (A, B). If the answer is too large, return result mod 998244353.So, if the input is like N = 2; M ... Read More

C++ Program to find out if a palindromic matrix can be made from a given matrix

Arnab Chakraborty
Updated on 02-Mar-2022 11:18:46

399 Views

Suppose, we are given a matrix with dimensions h x w. The matrix contains English letters. We have to create another matrix that will contain palindromic rows and columns, i.e. each row and column would be palindromes. To do that, any arrangement of rows and columns can be done from the given matrix; but no element can be changed, i.e. an 'a' cannot be changed to a 'b'. If that is possible to make a palindromic matrix from the given matrix, we return true; or otherwise, we return false.So, if the input is like h = 4, w = 4, ... Read More

C++ Program to find out number of employees of different skill level to be transferred

Arnab Chakraborty
Updated on 02-Mar-2022 11:13:44

260 Views

Suppose, there are n employees in a company. Each of the employees is given a rank based on their skills. The ranks are numbered from 1 to k. The number of employees having a rank i is given in the array skill, where skill[i] represents the number of employees having rank i. Now, a new branch of the company has opened and employees of different skills have to be transported to that branch. The number of employees to be sent to that branch is m. We have to find a way so that we can transfer m employees of different ... Read More

C++ Program to find out the minimum difference value in n integer pairs

Arnab Chakraborty
Updated on 02-Mar-2022 11:09:42

263 Views

Suppose, we are given two arrays a and b that have a total of n and m values in them respectively. We have to make n or m number of pairs (whichever is minimum) using values from the two arrays. A pair must contain a value from array a and another one from array b. We have to make the pairs in such a way so that the difference of the value in the pairs is minimum and the same. We print the value as output.So, if the input is like n = 4, m = 4, a = {2, ... Read More

C++ Program to find out the sum of shortest cost paths for all given triplets

Arnab Chakraborty
Updated on 02-Mar-2022 11:05:16

319 Views

Suppose, there are n cities and m roads between the cities. The m roads are given to us in an array of roads where the roads are in the format {aource, destination, weight}. Now, we define a triplet (s, t, k) where s, t, and k are cities. Now we have to calculate the minimum time needed to get from city s to city t. To visit t from s, only cities within 1 to k can be visited. If city t is unreachable from s, then we return 0. We have to calculate the minimum time for all triplets ... Read More

Get the Kronecker product of two One-Dimensional Arrays in Python

AmitDiwan
Updated on 02-Mar-2022 10:52:34

266 Views

To get the Kronecker product of two 1D arrays, use the numpy.kron() method in Python Numpy. Compute the Kronecker product, a composite array made of blocks of the second array scaled by the first.The function assumes that the number of dimensions of a and b are the same, if necessary prepending the smallest with ones. If a.shape = (r0, r1, .., rN) and b.shape = (s0, s1, ..., sN), the Kronecker product has shape (r0*s0, r1*s1, ..., rN*SN). The elements are products of elements from a and b, organized explicitly by −kron(a, b)[k0, k1, ..., kN] = a[i0, i1, ..., ... Read More

Get the Kronecker product of two arrays with different dimensions in Python

AmitDiwan
Updated on 02-Mar-2022 10:40:20

335 Views

To get the Kronecker product of two arrays with different dimensionas, use the numpy.kron() method in Python Numpy. Compute the Kronecker product, a composite array made of blocks of the second array scaled by the firstThe function assumes that the number of dimensions of a and b are the same, if necessary, prepending the smallest with ones. If a.shape = (r0, r1, .., rN) and b.shape = (s0, s1, ..., sN), the Kronecker product has shape (r0*s0, r1*s1, ..., rN*SN). The elements are products of elements from a and b, organized explicitly by −# kron(a, b)[k0, k1, ..., kN] = ... Read More

Compute the condition number of a matrix in linear algebra in Python

AmitDiwan
Updated on 02-Mar-2022 10:38:17

2K+ Views

To compute the condition number of a matrix in linear algebra, use the numpy.linalg.cond() method in Python. This method is capable of returning the condition number using one of seven different norms, depending on the value of p.Returns the condition number of the matrix. May be infinite. The condition number of x is defined as the norm of x times the norm of the inverse of x; the norm can be the usual L2-norm or one of a number of other matrix norms. The 1st parameter is x, the matrix whose condition number is sought. The 2nd parameter is p, ... Read More

C++ program to find out the shortest cost path in a given graph for q queries

Arnab Chakraborty
Updated on 02-Mar-2022 11:00:37

553 Views

Suppose, we are given a graph that contains n vertices and is minimally connected. The edges are given to us an array where the edges are given in a {source, dest, weight} format. Now, we are given q number of queries where each query is of the format {source, destination}. We have to find the shortest cost path from the source to the destination via vertex k. We print the cost of the path for each query.So, if the input is like n = 6, q = 3, k = 1, edges = {{1, 2, 2}, {1, 3, 4}, {3, ... Read More

Return the negative infinity Norm of the matrix in Linear Algebra in Python

AmitDiwan
Updated on 02-Mar-2022 10:35:06

268 Views

To return the Norm of the matrix or vector in Linear Algebra, use the LA.norm() method in Python Numpy. The 1st parameter, x is an input array. If axis is None, x must be 1-D or 2-D, unless ord is None. If both axis and ord are None, the 2-norm of x.ravel will be returned. The 2nd parameter, ord is the order of the norm. The inf means numpy’s inf object. The default is None.The 3rd parameter axis, if an integer, specifies the axis of x along which to compute the vector norms. If axis is a 2-tuple, it specifies ... Read More

Advertisements