Server Side Programming Articles

Page 520 of 2109

Program to check two parts of a string are palindrome or not in Python

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

Suppose we have two strings S and T of same length, we have to check whether it is possible to cut both strings at a common point so that the first part of S and the second part of T form a palindrome. So, if the input is like S = "cat" T = "dac", then the output will be True, as if we cut the strings into "c" + "at" and "d" + "ac", then "c" + "ac" is a palindrome. Algorithm To solve this, we will follow these steps − ...

Read More

Program to check whether we can take all courses or not in Python

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

Suppose we have a 2D matrix where matrix[i] represents the list of prerequisite courses needed to enroll in course i. We need to check whether it is possible to take all courses without encountering circular dependencies. So, if the input is like matrix = [[1], [2], []], then the output will be True, as we can take course 2, then course 1, and then course 0. Algorithm Overview This problem is essentially detecting cycles in a directed graph. We use Depth-First Search (DFS) with two tracking arrays: vis − tracks nodes currently in the DFS ...

Read More

Program to find a sublist where first and last values are same in Python

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

Suppose we have a list of numbers called nums, we have to find the number of sublists where the first element and the last element are same. So, if the input is like nums = [10, 15, 13, 10], then the output will be 5, as the sublists with same first and last element are: [10], [15], [13], [10], [10, 15, 13, 10]. Algorithm To solve this, we will follow these steps − num_sublists := size of nums d := an empty map for each n ...

Read More

Program to find duplicate element from n+1 numbers ranging from 1 to n in Python

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

Suppose we have a list of numbers called nums of length n + 1. These numbers are picked from range 1, 2, ..., n. As we know, using the pigeonhole principle, there must be a duplicate. We have to find that and return it. So, if the input is like [2, 1, 4, 3, 3], then the output will be 3. Approach To solve this, we will follow these steps − l := size of nums temp := l*(l-1) /2 temp_sum := sum ...

Read More

Program to check programmers convention arrangements are correct or not in Python

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

Suppose we have a number n representing programmers looking to enter a convention, and we also have a list of numbers where 1 represents a programmer and 0 represents empty space. The condition is that no two programmers can sit next to each other. We need to check whether all n programmers can enter the convention or not. So, if the input is like n = 2, convention = [0, 0, 1, 0, 0, 0, 1], then the output will be True because we can place 2 more programmers without violating the adjacency rule. Algorithm To solve ...

Read More

Program to find the formatted amount of cents of given amount in Python

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

When dealing with financial calculations in Python, we often need to format amounts from cents to currency format. This involves converting a numeric value representing cents into a properly formatted string with dollars and cents separated by a decimal point, and thousands separated by commas. So, if the input is like n = 123456, then the output will be "1, 234.56". Algorithm To solve this, we will follow these steps − Convert the number to a string to work with digits Handle special cases where the amount is less than $1.00 Separate the dollars and ...

Read More

Program to find the nth row of Pascal's Triangle in Python

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

Pascal's Triangle is a triangular array of numbers where each row represents the binomial coefficients. We need to find the nth row (0-indexed) of this mathematical structure. Understanding Pascal's Triangle Pascal's Triangle follows these rules: The top row contains only [1] Each subsequent row starts and ends with 1 Each interior number is the sum of the two numbers above it 1 1 1 1 2 1 1 3 3 1 ...

Read More

Program to count number of valid pairs from a list of numbers, where pair sum is odd in Python

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

Suppose we have a list of positive numbers, we have to find the number of valid pairs of indices (i, j), where i < j, and nums[i] + nums[j] is an odd number. An important mathematical property: the sum of two numbers is odd only when one number is even and the other is odd. This means we need to count pairs where one element is even and another is odd. So, if the input is like [5, 4, 6], then the output will be 2, as two pairs are [5, 4] and [5, 6], whose sums are ...

Read More

Program to check old and new version numbering are correct or not in Python

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

Version comparison is a common task in software development. We need to compare two version strings in the format "major.minor.patch" to determine if the newer version is actually newer than the older one. So, if the input is like older = "7.2.2", newer = "7.3.1", then the output will be True because 7.3.1 is newer than 7.2.2. Algorithm To solve this problem, we will follow these steps − Split both version strings into lists of major, minor, patch numbers Compare each component (major, minor, patch) from left to right If newer component is greater, return ...

Read More

Program to count number of elements in a list that contains odd number of digits in Python

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

Given a list of positive numbers, we need to count how many elements have an odd number of digits. For example, the number 123 has 3 digits (odd), while 1234 has 4 digits (even). So, if the input is like [1, 300, 12, 10, 3, 51236, 1245], then the output will be 4 because numbers 1, 3, 300, and 1245 have odd digit counts (1, 1, 3, and 4 digits respectively). Algorithm To solve this, we will follow these steps: Initialize counter c = 0 For each ...

Read More
Showing 5191–5200 of 21,090 articles
« Prev 1 518 519 520 521 522 2109 Next »
Advertisements