Programming Articles

Page 308 of 2544

Column Sort of a Matrix in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have a matrix, we have to sort each of the columns in ascending order.So, if the input is like1121316641118then the output will be1646118112131To solve this, we will follow these steps −R := row count of matrix, C := column count of matrixres := matrix of same size as given matrix and fill with 0for col in range 0 to C, dovalues := take the elements as a vector of matrix[col]for row in range 0 to R, dores[row, col] := delete last element from valuesreturn resLet us see the following implementation to get better understanding −Exampleclass Solution:    def ...

Read More

Program to sort each diagonal elements in ascending order of a matrix in C++

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

Suppose we have n x m matrix Mat, we have to sort this Mat diagonally in increasing order from top-left to the bottom right, so that all elements in the diagonals are sorted. So if the input matrix is like −331122121112The output matrix will be −111112221233To solve this, we will follow these steps −Define a method called solve(), this will take si, sj and matrix matn := number of rows and m := number of columnsmake an array called tempi:= si and j := sj, and index := 0while i < n and j < m, doinsert m[i, j] into ...

Read More

Generate random number from 0 &ndash; 9 in PHP?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 561 Views

To generate random number in PHP, use rand(). Let’s say the following is our input −$storedValue ='0123456789';And we want to display a random value from the above values.Example OutputThis will produce the following outputThe random value=3

Read More

Common Words in Two Strings in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 6K+ Views

Suppose we have two strings s0 and s1, they are representing a sentence, we have to find the number of unique words that are shared between these two sentences. We have to keep in mind that, the words are case-insensitive so "tom" and "ToM" are the same word.So, if the input is like s0 = "i love python coding", s1 = "coding in python is easy", then the output will be 2 as there are 2 common words, ['python', 'coding']To solve this, we will follow these steps −convert s0 and s1 into lowercases0List := a list of words in s0s1List ...

Read More

Program to find sum each of the diagonal path elements in a binary tree in Python

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

Suppose we have a binary tree, we have to find the sum of each of the diagonals in the tree starting from the top to bottom right.So, if the input is likethen the output will be [27, 18, 3] as the diagonals are [12, 15], [8, 10], [3]. So the sum values are [27, 18, 3]To solve this, we will follow these steps −Define a function traverse() . This will take node, numLeft, outputif node is null, thenreturnif numLeft >= size of output , theninsert data of node at the end of outputotherwise, output[numLeft] := output[numLeft] + data of nodeif ...

Read More

PHP fetch a specific value that begins with a given number from a string with letters and numbers?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 213 Views

Let’s say the following is our string with letters and numbers −$value ="1045632245555fghjklm67535454663443gfdjkbvc9890000006777743";We ant a specific value beginning from 989 i.e.−9890000006777743ExampleFor this, use substr() along with strpos(). OutputThe actual value is=1045632245555fghjklm67535454663443gfdjkbvc9890000006777743 The filter value is=9890000006777743

Read More

Connell sequence in Python

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

Suppose we have a number n, we have to find the nth term of Connell sequence. The Connell sequence is as follows: 1. Take first odd integer: 1 2. Take next two even integers 2, 4 3. Then take the next three odd integers 5, 7, 9 4. After that take the next four even integers 10, 12, 14, 16 And so on.So, if the input is like 12, then the output will be 21To solve this, we will follow these steps −i := 1while quotient of (i *(i + 1) / 2) < n + 1, doi := i ...

Read More

Program to count number of ways we can throw n dices in Python

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

Suppose we have a number n, number of faces, and a total value, we have to find the number of ways it is possible to throw n dice with faces each to get total. If the answer is very large mod the result by 10**9 + 7.So, if the input is like n = 2 faces = 6 total = 8, then the output will be 5, as there are 5 ways to make 8 with 2 6-faced dice: (2 and 6), (6 and 2), (3 and 5), (5 and 3), (4 and 4).To solve this, we will follow these ...

Read More

Manipulate for loop to run code with specific variables only PHP?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 286 Views

Let’s say the following is our array −$marks=[45,67,89,34,98,57,77,30];And we want the output like this with only selected values45 67 89 68 98 57 77 60Above, we multiplied marks less than 40 with 2, rest kept the entire array same.ExampleThe PHP code is as follows OutputThis will produce the following outputThe Marks are as follows 45 67 89 68 98 57 77 60

Read More

Display game is in BUY or TRY mode PHP conditions?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 94 Views

For such conditional evaluation, use PHP if(), else if() and else.ExampleThe PHP code is as follows OutputGAME IS IN BUY MODE

Read More
Showing 3071–3080 of 25,433 articles
« Prev 1 306 307 308 309 310 2544 Next »
Advertisements