Server Side Programming Articles

Page 1247 of 2109

How to combine matrices having same number of columns in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 379 Views

The matrices that have same number of columns can be combined by rows. For example, if we have five matrices list, each having six columns then those matrices can be converted into a single matric by joining the rows of those matrices. It can be done by using do.call(rbind,”List_of_matrices_object_name”).ExampleConsider the below matrices and their list −M1

Read More

How to create a matrix with random values in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 8K+ Views

Generally, a matrix is created with given values but if we want to create the matrix with random values then we will use the usual method with the matrix function. Random selection in R can be done in many ways depending on our objective, for example, if we want to randomly select values from normal distribution then rnorm function will be used and to store it in a matrix, we will pass it inside matrix function.ExampleM1

Read More

Count Distinct Non-Negative Integer Pairs (x, y) that Satisfy the Inequality x*x + y*y < n in C++

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

We are given a positive integer N. The goal is to count the pairs of distinct non-negative positive integers that satisfy the inequality − x*x + y*y < N.We will start from x=0 to x2 lt; N and y=0 to y2 < N . If any x2 + y2 < N, increase count of pairs.Let us understand with examples −Input − n=4Output − distinct pairs= 4Explanation − pairs will be (0, 0), (1, 1), (0, 1), (1, 0). All these satisfy the inequality x2 + y2 < 4Input −n=2Output − distinct pairs= 3Explanation &minus pairs will be (0, 0), (0, ...

Read More

Count number of Distinct Substring in a String in C++

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

According to the problem we are given a string str, we must count all the substrings in the given string. Substring is a string which is a part of an already existing string whose size may be smaller than or equal to the existing string.Let's understand the problem and its solution with the help of examples.Input − str = "wxyz";Output − count of distinct substring is: 10Explanation − Distinct substrings counted are −wxyz, wxy, wx, w, xyz, xy, x, yz, y, z so their count is 10Input − str = "zzzz"Output − count of distinct substring is: 4Explanation − Distinct ...

Read More

Maximum difference elements that can added to a set in C++

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

According to the problem we are given a set arr[n] where n is the number of integer elements in the set, the task is to find the maximum difference elements which are to be added to obtain the elements in the set. In other words, the difference should be in form of |a-b| where 'a' and 'b' both are in the set and their difference should not be the least. So, we will count the maximum number of differences which are distinct and largest from a set. Let's understand the problem and its solution with help of an example.Input − ...

Read More

Maximize the value of A by replacing some of its digits with digits of B in C++

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

The task is to maximize the value of number A by replacing some of its digits with digits present in another number B. No digits will be replaced if A’s value cannot be maximized.Note − a digit from B can be used only once.Let’s now understand what we have to do using an example −Input A = “1221” B = “1211”Output Maximum value of A possible 2221Explanation − We here select 2 from B and replace it with the first 1 of A. Here it is the only choice as replacing any other digit of A with either 2 or 1 will ...

Read More

Maximizing Probability of one type from N containers in C++

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

Probability Pi= (No. of Favourable Outcomes) / (Total no. of Outcomes).Given is a number N which is the number of containers present. And we have N copies of two numbers X and Y. The task is to divide copies of one number X into N containers such that the probability of drawing a copy of X is maximum. From above it can be seen that to maximize Pi, we can either maximize the numerator ( No. of favourable outcomes) or minimize the denominator(Total no. of Outcomes). This can be done in a manner that only one container has a copy ...

Read More

map::operator[] in C++ STL Program

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

In this article we will be discussing the working, syntax and example of map equal ‘[]’ operator in C++ STL.What is a Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination of key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in the map container are accessed by its unique keys.What is a map equal to ‘[]’ operator?map::operator[] is a reference operator. This operator is used to access the element in the ...

Read More

Queries to answer the X-th smallest sub-string lexicographically in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 246 Views

In this problem, we are given a string str and Q queries. Each Query has a number X. Our task is to create a program to solve the Queries to answer the X-th smallest sub-string lexicographically in C++.Problem DescriptionWe need to find the Xth lexicographically smallest substring for each query i.e. based on alphabetical order sorting we will have to find Xth substring.Let’s take an example to understand the problem, Input: str = “point”Q = 4 query = {4, 7, 2, 13}Output:n, oi, in, poinExplanationAll substrings of str in lexicographical order are−i, in, int, n, nt, o, oi, oin, oint, ...

Read More

Queries to check if it is possible to join boxes in a circle in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 196 Views

In this tutorial, we will be discussing a program to find queries to check if it is possible to join boxes in a circle.For this we will be provided with a circle of boxes running from 1 to n. Our task is to find whether box i can be connected to box j with a rod without intersecting the previous rodes.Example#include using namespace std; //checking if making a circle from boxes is possible void isPossible(int n, int q, int queryi[], int queryj[]) {    int arr[50];    for (int i = 0; i queryj[k]) {                   check = 1;                   break;                }             }          }       }       if (check == 0) {          cout

Read More
Showing 12461–12470 of 21,090 articles
Advertisements