Programming Articles - Page 820 of 3363

Find the maximum possible value of the minimum value of modified array in C++

sudhir sharma
Updated on 24-Jan-2022 12:57:38

459 Views

In this problem, we are given an array arr[] of size n and a number S. Our task is to Find the maximum possible value of the minimum value of the modified array.Here, are the rules to modify the array, The difference between the sum of the array elements before and after modification should be S.Negative values in the modified array are not allowed.If the modified array, the minimum values of the array need to be maximized.The modification of the array can be done by increasing or decreasing any element of the array.Using these constraints, we need to find the ... Read More

Maximum occurrence of prefix in the Array in C++

sudhir sharma
Updated on 24-Jan-2022 12:49:31

281 Views

In this problem, we are given an array of characters all in lowercase. Our task is to Maximum occurrence of prefix in the Array.We need to count the occurrence of non-empty prefixes whose occurrence count is maximum.Let’s take an example to understand the problem, Input : string = “xyyzkxyyzk” Output : 2Solution ApproachThe logic is to visualize that the prefix of an array must always, obviously, contain the first character of the string and so would be its repeating occurrences. And the first character of a string is obviously a prefix with the least number of characters. So the maximum ... Read More

Find the number of divisors of all numbers in the range [1, n] in C++

sudhir sharma
Updated on 24-Jan-2022 12:46:16

875 Views

In this problem, we are given a number N. Our task is to find the number of divisors of all numbers in the range [1, n].Let’s take an example to understand the problem,Input : N = 7 Output : 1 2 2 3 2 4 2Solution ApproachA simple solution to the problem is by starting from 1 to N and for every number count the number of divisors and print them.Example 1Program to illustrate the working of our solution#include using namespace std; int countDivisor(int N){    int count = 1;    for(int i = 2; i

Find the number of different numbers in the array after applying the given operation q times in C++

sudhir sharma
Updated on 24-Jan-2022 12:36:02

205 Views

In this problem, we are given a number N which is the size of an array consisting of all zeros and Q queries each of the following type −update(s, e, val ) -> this query will update all elements from s to e (both inclusive) to val.Our task is to find the number of different numbers in the array after applying the given operation q timesLet’s take an example to understand the problem, Input : N = 6, Q = 2 Q1 = update(1, 4, 3) Q2 = update(0, 2, 4) Output : 2ExplanationInitial array, arr[] = {0, 0, ... Read More

Find the number of boxes to be removed in C++

sudhir sharma
Updated on 24-Jan-2022 12:26:25

225 Views

In this problem, we are given an array arr[] in which each element represents a pile of boxes (each of unit height). Our task is to find the number of boxes to be removed.The person is standing at index 0 of the array at the height of the pile of boxes and he needs to move to the end of the array. The condition to move from one pile to the next is by jumping to the next.Jump is possible only when the next pile is at the same height or is at height less than it. If the height ... Read More

Find the Nth term of the series 9, 45, 243,1377…in C++

sudhir sharma
Updated on 24-Jan-2022 12:18:13

213 Views

In this problem, we are given an integer value N.Our task is to Find the nth term of the series −9, 45, 243, 1377, 8019, …Let’s take an example to understand the problem,Input : N = 4 Output : 1377Solution ApproachA simple solution to find the problem is by finding the Nth term using observation technique. On observing the series, we can formulate as follow −(11 + 21)*31 + (12 + 22)*32 + (13 + 23)*33 … + (1n + 2n)*3nExampleProgram to illustrate the working of our solution#include #include using namespace std; long findNthTermSeries(int n){    return ( ( (pow(1, n) + pow(2, n)) )*pow(3, n) ); } int main(){    int n = 4;    cout

Find the nth term of the series 0, 8, 64, 216, 512,... in C++

sudhir sharma
Updated on 24-Jan-2022 10:58:49

382 Views

In this problem, we are given an integer value N. Our task is to find the nth term of the series −0, 8, 64, 216, 512, 1000, 1728, 2744…Let’s take an example to understand the problem, Input: N = 6 Output: 1000Solution ApproachTo find the Nth term of the series, we need to closely observe the series. The series is the cube of even numbers, where the first term is 0.So, the series can be decoded as −[0]3, [2]3, [4]3, [6]3, [8]3, [10]3…For ith term, T1 = [0]3 = [2*(1-1)]3T2 = [2]3 = [2*(2-1)]3T3 = [4]3 = [2*(3-1)]3T4 = [6]3 ... Read More

Find the nth term of the given series 0, 0, 2, 1, 4, 2, 6, 3, 8, 4… in C++

sudhir sharma
Updated on 24-Jan-2022 08:37:36

495 Views

In this problem, we are given an integer value N. Our task is to Find the nth term of the given series −0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8, 18, 9, 20, 10… Let’s take an example to understand the problem, Input − N = 6 Output − 2Solution ApproachTo find the Nth term of the series, we need to closely observe the series. It is the mixture of two series and odd and even terms of the series. Let’s see each of them, At even positions −T(2) = 0T(4) ... Read More

How to apply linear transformation to the input data in PyTorch?

Shahid Akhtar Khan
Updated on 20-Jan-2022 08:21:13

902 Views

We can apply a linear transformation to the input data using the torch.nn.Linear() module. It supports input data of type TensorFloat32. This is applied as a layer in the deep neural networks to perform linear transformation. The linear transform used −y = x * W ^ T + bHere x is the input data, y is the output data after linear transform. W is the weight matrix and b is biases. The weights W have shape (out_features, in_features) and biases b have shape (out_features). They are initialized randomly and updated during the training of a Neural Network.Syntaxtorch.nn.Linear(in_features, out_features)Parametersin_features - It ... Read More

How to upsample a given multi-channel temporal, spatial or volumetric data in PyTorch?

Shahid Akhtar Khan
Updated on 20-Jan-2022 08:28:44

1K+ Views

A temporal data can be represented as a 1D tensor, and spatial data as 2D tensor while a volumetric data can be represented as a 3D tensor. The Upsample class provided by torch.nn module supports these types of data to be upsampled. But these data must be in the form N ☓ C ☓ D (optional) ☓ H (optional) ☓ W (optional), Where N is the minibatch size, C is the numberchannels, D, H and W are depth, height and width of the data, respectively. Hence, to upsample a temporal data (1D), we need it to be in 3D in ... Read More

Advertisements