Articles on Trending Technologies

Technical articles with clear explanations and examples

Count of numbers having only 1 set bit in the range [0, n] in C++

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

We are given a number and the task is to calculate the count of numbers from the range 0 till the given number let’s say, num having exactly one set bitSet bits in a binary number is represented by 1. Whenever we calculate the binary number of an integer value then it is formed as the combination of 0’s and 1’s. So, the digit 1 is known as set bit in the terms of the computer.Input − int num = 15Output − Count of numbers having only 1 set bit in the range [0, 15] are − 4Explanation − The ...

Read More

How to replace numbers with ordinal strings for a survey in an R vector?

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

The easiest way to replace numbers with ordinal strings is using ifelse function. The ifelse function in R works as ifelse(test_expression, x, y). Here, test_expression must be a logical vector or an object that can be coerced to logical). The return value is a vector with the same length as test_expression.Example1> x1 x1Output[1] 1 1 1 0 1 0 0 1 1 1 0 0 1 0 1 0 0 1 1 0 0 1 1 1 1 0 0 0 0 1 1 1 0 1 1 0 1 [38] 0 1 1 0 0 1 0 1 1 ...

Read More

Find the Sum of Radio button values jQuery?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 546 Views

Let’s say we have marks records and we need to sum them. The records are displayed in Radio Button −Marks1 75 {          if (evnt.checked) {             total = total + parseInt(evnt.value);             return;          }       });       secondMark.forEach((evnt) => {          if (evnt.checked) {             total = total + parseInt(evnt.value);             return;          }       });       ...

Read More

Program to find length of longest set of 1s by flipping k bits in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 270 Views

Suppose we have a binary list, so here only 1s and 0s are available and we also have another number k. We can set at most k 0s to 1s, we have to find the length of the longest sublist containing all 1s.So, if the input is like nums = [0, 1, 1, 0, 0, 1, 1] k = 2, then the output will be 6, as we can set the two middle 0s to 1s and then the list becomes [0, 1, 1, 1, 1, 1, 1].To solve this, we will follow these steps −zeros := 0, ans := ...

Read More

Program to check we can find four elements whose sum is same as k or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 166 Views

Suppose we have a list of numbers called nums and a value k, we have to check whether there are four unique elements in the list that add up to k.So, if the input is like nums = [11, 4, 6, 10, 5, 1] k = 25, then the output will be True, as we have [4, 6, 10, 5] whose sum is 25.To solve this, we will follow these steps −sort the list numsn := size of numsfor i in range 0 to n − 4, dofor j in range i + 1 to n − 3, dol := ...

Read More

Count the number of elements in an array which are divisible by k in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 1K+ Views

We are given with an array of positive integer numbers and an integer variable k. The task is to calculate the count of the number of elements in an array which is divisible by the given value k.Input − int arr[] = {4, 2, 6, 1, 3, 8, 10, 9}, k = 2Output − Count the number of elements in an array which are divisible by 2 are − 5Explanation − we will divide the elements in an array by a value k and check whether the reminder is 0 or not. So, 4 is divisible by 2, 2 is ...

Read More

How to find the column number of minimum values in each row for a data frame in R?

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

To find the column number of minimum values in each row for a data frame, we can use apply function but if we want to return the output in tabular form then matrix function should be used. For example, if we have a data frame df then our problem can be solved by using the code: as.matrix(apply(df, 1, which.min)).ExampleConsider the below data frame:> set.seed(37) > x1 x2 x3 x4 x5 df1 df1Outputx1 x2 x3 x4 x5 1 1 2 4 9 3 2 0 5 8 10 4 3 1 3 8 6 1 4 1 5 5 8 1 ...

Read More

How to find the sum of corresponding elements in multiple vectors even if they contain NA’s in R?

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

If we have multiple vectors then the sum of the corresponding elements can be found by using rowSums functions and the vectors can be combined by using cbind so that R can easily read the corresponding elements. But if there are NA values in one or more vectors then we also need to add na.rm=TRUE argument.Exampleset.seed(100) x1

Read More

How to add and remove names on button click with JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 3K+ Views

To create, use add() method, whereas to delete created and appended element, you can use remove(). Following is the code −Example Document Add A New Name AddName    var givenName = document.querySelector('#name')    var btnClass = document.querySelector('#addNameButton')    var listOfName = document.querySelector('#listOfName')    btnClass.addEventListener('click', () => {       var actualName = givenName.value       if (actualName.length != 0) {          var createAnHTMLList = `${actualName}Remove Name`          listOfName.innerHTML += createAnHTMLList ...

Read More

How to find the rank of a matrix in R?

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

The rank of a matrix is defined as the maximum number of linearly independent vectors in rows or columns. If we have a matrix with dimensions R x C, having R number of rows and C number of columns, and if R is less than C then the rank of the matrix would be R. To find the rank of a matrix in R, we can use rankMatrix function in Matrix package.Loading Matrix package −library(Matrix)ExampleM1

Read More
Showing 3531–3540 of 61,248 articles
« Prev 1 352 353 354 355 356 6125 Next »
Advertisements