Server Side Programming Articles

Page 451 of 2109

Check if N can be represented as sum of integers chosen from set {A, B} in Python

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

Sometimes we need to check if a target number can be represented as a sum of two given integers A and B, where we can use each integer any number of times. This is a classic dynamic programming problem that can be solved using memoization. Problem Understanding Given a target number and two integers A and B, we need to determine if we can express the target as a linear combination of A and B with non-negative coefficients. For example, if target = 26, A = 5, and B = 7, we can achieve this as 26 = ...

Read More

Check if moves in a stack or queue are possible or nots in Python

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

Stack and queue operations follow a specific order where elements must be pushed before they can be popped. Given a binary list where 1 represents a push operation and 0 represents a pop operation, we need to validate if the sequence of operations is possible without attempting to pop from an empty structure. Problem Understanding The key insight is that at any point during the operations, the number of pop operations cannot exceed the number of push operations. If we encounter more pops than pushes, we're trying to remove elements from an empty stack or queue, which is ...

Read More

Check if mirror image of a number is same if displayed in seven segment displays in Python

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

In seven-segment displays, only certain digits look the same when mirrored horizontally. We need to check if a number appears identical to its mirror image when displayed on such a device. The digits that look the same when mirrored in seven-segment displays are 0, 1, and 8. Other digits like 2, 3, 4, 5, 6, 7, 9 don't have symmetric mirror images. Understanding Seven-Segment Mirror Images .segment { fill: #333; stroke: none; } .text { font-family: ...

Read More

Check if max occurring character of one string appears same no. of times in other in Python

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

When working with string analysis, we sometimes need to check if the most frequently occurring character in one string appears the same number of times in another string. This can be useful in text analysis and pattern matching scenarios. Problem Statement Given two strings s and t, we need to find the most frequent character in string s and check whether that character appears the same number of times in string t. For example, if s = "crosssection" and t = "securesystem", the most frequent character in s is 's' (appears 3 times). Since 's' also appears ...

Read More

Check if Matrix remains unchanged after row reversals in Python

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

When working with matrices, sometimes we need to check if a matrix remains unchanged after reversing each row. This means checking if each row is a palindrome − reads the same forwards and backwards. For example, if we have a matrix like: 686 282 333 After reversing each row, we get the same matrix, so the output will be True. Algorithm To solve this problem, we follow these steps: Get the number of rows in the matrix For each row, use two pointers (left and right) Compare elements from ...

Read More

Check if matrix can be converted to another matrix by transposing square sub-matrices in Python

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

Suppose we have two N X M matrices called mat1 and mat2. In an operation, we can transpose any square sub-matrix in mat1. We have to check whether we can get mat2 from mat1 or not by performing the given operation. The key insight is that transposing square sub-matrices preserves the elements along each diagonal. Elements that can be rearranged among themselves through transpositions must have the same sorted order in both matrices. Example Matrices Consider these input matrices ? Matrix 1 (mat1) 567 123 689 Matrix 2 (mat2) 562 173 689 ...

Read More

Check if matrix A can be converted to B by changing parity of corner elements of any submatrix in Python

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

Suppose we have two N X M binary matrices A and B. In a single operation, we can select a sub-matrix (at least 2x2) and flip the parity of its four corner elements (toggle bits 0↔1). We need to check whether matrix A can be converted to B by performing any number of such operations. Understanding the Problem When we select a 2x2 submatrix and flip its corners, we're essentially performing an XOR operation on four specific positions. The key insight is that we can systematically work through the matrix from bottom-right to top-left, fixing mismatches using operations ...

Read More

Check if lowercase and uppercase characters are in same order in Python

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

Suppose we have a string with only lowercase or uppercase letters. We need to check whether both lowercase and uppercase letters follow the same order respectively. This means if we extract all lowercase letters and all uppercase letters separately, converting the lowercase sequence to uppercase should match the uppercase sequence. So, if the input is like s = "piPpIePE", then the output will be True, as the lowercase letters "piepe" when converted to uppercase become "PIEPE", which matches the extracted uppercase sequence "PIEPE". Algorithm To solve this, we follow these steps ? ...

Read More

Check if linked list is sorted (Iterative and Recursive) in Python

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

A linked list is sorted in non-increasing order when each node's value is greater than or equal to the next node's value. We can check this condition using both iterative and recursive approaches. So, if the input is like L = [15, 13, 8, 6, 4, 2], then the output will be True because 15 ≥ 13 ≥ 8 ≥ 6 ≥ 4 ≥ 2. LinkedList Node Structure First, let's define the basic structure of a linked list node ? class ListNode: def __init__(self, data, next=None): ...

Read More

Check if leaf traversal of two Binary Trees is same in Python

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

Suppose we have two binary trees. We need to check whether the leaf traversal of these two trees is the same or not. The leaf traversal is the sequence of leaf nodes traversed from left to right. So, if the input is like ? Tree 1 2 3 4 5 ...

Read More
Showing 4501–4510 of 21,090 articles
« Prev 1 449 450 451 452 453 2109 Next »
Advertisements