Programming Articles

Page 3 of 2545

How to print a large number of values in R without index?

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

Whenever we print any vector then the left-hand side of the R window shows indexing, even if we have one value in the vector the index will be there. For example, if we print a vector that has value equal to 2 then the print output will be [1] 2, here [1] represents the index. If we want to print the vector without index then cat function can be used as shown in the below examples.Example1x1

Read More

Maximum Sum Increasing Subsequence using DP in C++ program

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 277 Views

In this problem, we are given an array arr[] of size n. Our task is to create a program to find the maximum Sum Increasing Subsequence using DP in C++.Problem Description − To find the maximum sum increasing subsequence, we will be creating a subsequence in which the next element is greater than the current element.Let’s take an example to understand the problem, Inputarr[] = {4, 2, 3, 6, 5, 9}Output20ExplanationIncreasing subsequence with maximum sum: {2, 3, 6, 9} = 2 + 3 + 6 + 9 = 20Solution ApproachTo solve the problem using a dynamic Program Approach. We will ...

Read More

Find number of subarrays with even sum in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 425 Views

In this problem, we are given an array arr[] consisting of N elements. Our task is to find the subarray with even sum.Let’s take an example to understand the problem,Inputarr[] = {2, 1, 3, 4, 2, 5}Output28ExplanationThe subarrays are −{2}, {4}, {2}, {2, 4}, {2, 2}, {1, 3}, {1, 5}, {3, 5}, {4, 2}, {2, 1, 3}, {2, 1, 5}, {2, 3, 5}, {2, 4, 2}, {1, 3, 4}, {1, 3, 2}, {1, 4, 5}, {1, 2, 5}, {3, 4, 5}, {3, 2, 5}, {2, 1, 3, 4}, {2, 1, 3, 2}, {2, 3, 4, 5}, {2, 3, 2, 5}, {2, 4, 2, 5}, {1, 3, 4, 2}, {1, 4, 2, 5}, {3, 4, 2, 5}, {2, 1, 3, 4, 2}, {2, 1, 3, 4, 2, 5}Solution ApproachA simple solution to the problem is using the direct method which is by calculating all subarray and their sums. And the increase count for the subarray with even sum. And at last return count.Program to illustrate the working of our solution,Example#include using namespace std; int countEvenSumSubArray(int arr[], int n){    int evenSumCount = 0, sum = 0;    for (int i=0; i

Read More

How to change the repeated row names and column names to a sequence in a matrix in R?

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

To change the repeated row names and column names to a sequence, we first need to read those names in a vector then set them to row names and column names with make.unique function. For example, if a matrix has row names defined as A, B, A, B, A then it can be converted into A, B, A.1, B.1, A.2.Example1M1

Read More

What is the difference between creating a matrix by using matrix function or as.matrix function in R?

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

The difference between as.matrix and matrix function is that nrow argument or ncol argument are not helpful with as.matrix function but with matrix function we can use them. Therefore, we can actual define a matrix with matrix function but if we have a data frame or data table then it can be converted to matrix by using as.matrix function.Examples of creating matrix with as.matrix and matrix functionExample1M

Read More

Find maximum possible stolen value from houses in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 778 Views

In this problem, we are given n houses with some values in them. Our task is to Find the maximum possible stolen value from houses.Problem Description − We have an array houses[] that consist of the values that are in each house. A thief robs the houses but he cannot steal from two adjacent houses as neighbours know about the theft. We need to find the maximum possible value that can be stolen by the thief from the house without getting caught.Let’s take an example to understand the problem, Inputhouses[] = {5, 2, 1, 6, 7, 9, 4, 3}Output23ExplanationThe max ...

Read More

Find maximum value of Sum( i*arr[i]) with only rotations on given array allowed in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 221 Views

In this problem, we are given an array arr[] consisting of n elements. We need to Find maximum value of Sum( i*arr[i]) with only rotations on a given array allowed. For find the maximum sum of (i*arr[i]), we can perform any number of rotations.Let’s take an example to understand the problem, Inputarr[] = {4, 1, 3, 7, 2}Output43ExplanationWe will rotate the array once to get the maximum value, After rotation array will be {2, 4, 1, 3, 7}Sum = 0*2 + 1*4 + 2*1 + 3*3 + 4*7 = 0 + 4 + 2 + 9 + 28 = 43Solution ...

Read More

Find maximum XOR of given integer in a stream of integers in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 229 Views

In this problem, we are given Q queries each of which is one of the following type, Type 1 − insertion (1, i) to add the element with value i, in your data structure.Type 2 − findXOR (2, i), to find the XOR of all elements of the data structure with the element i.The data structure should contain only 1 element initially which will be 0.Let’s take an example to understand the problem, InputQueries: (1, 9), (1, 3), (1, 7), (2, 8), (1, 5), (2, 12)Output15 15ExplanationSolving each query, (1, 9) => data structure => {9} (1, 3) => data ...

Read More

Find Maximum XOR value of a sub-array of size k in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 623 Views

In this problem, we are given an array arr[] consisting of n elements and an integer k. Our task is to find the Maximum XOR value of a sub-array of size k.Let’s take an example to understand the problem, Inputarr[] = {3, 1, 6, 2 ,7, 9} k = 3Output12ExplanationAll subarray and the xor of all element of size k, {3, 1, 6} = 4 {1, 6, 2} = 5 {6, 2, 7} = 3 {2, 7, 9} = 12Solution ApproachA simple solution to the problem is by using two loops. One to iterate over the array and other to ...

Read More

How to concatenate two or more vectors in R?

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

The concatenation of vectors can be done by using combination function c. For example, if we have three vectors x, y, z then the concatenation of these vectors can be done as c(x,y,z). Also, we can concatenate different types of vectors at the same time using the same same function.Example1set.seed(999) x1

Read More
Showing 21–30 of 25,445 articles
Advertisements