Server Side Programming Articles

Page 526 of 2109

Program to find number of string we can make where 'a' can be 'a' or 'b', and 'b' remains 'b'in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 310 Views

Suppose we have a string s with only "a" and "b". "a"s can stay "a" or turn into "b", but "b"s can not be changed. We have to find the number of unique strings that we can make. So, if the input is like s = "baab", then the output will be 4, as we can make these strings − ["baab", "babb", "bbab", "bbbb"] Approach The key insight is that only characters 'a' can be transformed. Each 'a' has 2 choices (remain 'a' or become 'b'), while 'b' characters remain unchanged. If we have n occurrences of ...

Read More

Program to check a number is ugly number or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 959 Views

An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. In other words, an ugly number can be expressed as 2i × 3j × 5k where i, j, and k are non-negative integers. So, if the input is like n = 18, then the output will be True, as 18's prime factors are 2 and 3 (18 = 2 × 32). Algorithm To solve this, we will follow these steps − If n ≤ 0, then return False (ugly numbers are positive) Create a list of factors [2, ...

Read More

Program to create one triangle stair by using stars in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 735 Views

Suppose we have a number n, we have to create a string representing stairs with n steps. Each line in the string is separated by a newline separator, forming a triangle pattern with stars. So, if the input is like n = 5, then the output will be ? * ** *** **** ***** Algorithm To solve this, we will follow these steps ? Initialize an empty string For each step from 0 to n-1: Add (n-i-1) number of spaces for ...

Read More

Program to check whether given matrix is Toeplitz Matrix or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 792 Views

A Toeplitz matrix is a square matrix where every diagonal descending from left to right has the same value. In other words, all elements along each diagonal from top-left to bottom-right are identical. So, if the input matrix is like: 7 2 6 3 7 2 5 3 7 Then the output will be True because each diagonal has consistent values. Algorithm To check if a matrix is Toeplitz, we follow these steps: For each row i except the last one, do: For each ...

Read More

Program to find the product of three elements when all are unique in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 666 Views

Sometimes we need to find the product of three numbers, but only when all numbers are unique. If any two numbers are equal, they should not contribute to the final product. So, if the input is like x = 5, y = 4, z = 2, then the output will be 40, as all three numbers are distinct so their product is 5 * 4 * 2 = 40. However, if x = 5, y = 5, z = 2, the output would be 2 since only z is unique. Algorithm To solve this, we will follow ...

Read More

Program to find final text in an editor by performing typing and backspacing in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 214 Views

Suppose we have a string that represents characters typed into an editor, where the symbol "

Read More

Program to find number of tasks can be finished with given conditions in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 416 Views

Suppose we have a list of tasks and another list of people. The tasks[i] determines the amount of strength required to perform the ith task. And the people[i] determines the amount of strength the ith person has. We need to find the maximum number of tasks that can be finished if one person can perform at most one task. So, if the input is like tasks = [4, 3, 9, 15], people = [10, 5, 3, 2], then the output will be 3. The first person (strength 10) can perform task requiring 9, second person (strength 5) can perform ...

Read More

Program to find minimum number of operations required to make one number to another in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 475 Views

Given two numbers start and end (where start < end), we need to find the minimum number of operations required to convert start to end using these operations: Increment by 1 Multiply by 2 For example, if start = 5 and end = 11, the output will be 2. We can multiply 5 by 2 to get 10, then add 1 to get 11. Algorithm The key insight is to work backwards from the end number. Instead of thinking "how to reach end from start", we think "how did we reach end from start" ...

Read More

Program to find any two numbers in a list that sums up to k in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 908 Views

Suppose we have a list of numbers called nums and we have another number k, we have to check whether any two numbers present in the list add up to k or not. Same elements must not be used twice, and numbers can be negative or 0. So, if the input is like nums = [45, 18, 9, 13, 12], k = 31, then the output will be True, as 18 + 13 = 31. Approach To solve this, we will follow these steps − temp_set := a new set ...

Read More

Program to find the sum of all digits of given number in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

Finding the sum of digits of a number is a common programming problem. We need to extract each digit from the number and add them together without converting the number to a string. So, if the input is like num = 512, then the output will be 8, as 8 = 5 + 1 + 2. To solve this, we will follow these steps ? Initialize sum = 0 while num is not equal to 0, do ...

Read More
Showing 5251–5260 of 21,090 articles
« Prev 1 524 525 526 527 528 2109 Next »
Advertisements