Server Side Programming Articles

Page 527 of 2109

Program to find minimum number of operations required to make one string substring of other in Python

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

Suppose we have two strings s and t, we have to find the minimum number of operations required to make t a substring of s. In each operation, we can choose any position in s and change the character at that position to any other character. For example, if s = "abbpqr" and t = "bbxy", then the output will be 2. We can take the substring "bbpq" from s and change 'p' to 'x' and 'q' to 'y' to make "bbxy" a substring. Approach The strategy is to check all possible substrings of s that have ...

Read More

Program to find nth sequence after following the given string sequence rules in Python

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

Suppose we have two strings s, t and another positive number n is also given, we have to find the nth term of the sequence A where: A[0] = s A[1] = t A[n] = A[n - 1] + A[n - 2] when n is even, otherwise A[n] = A[n - 2] + A[n - 1] As an example, if s = "a" and t = "b", then the sequence A would be: ["a", "b", "ba" ("b" + "a"), "bba" ("b" + "ba"), "bbaba" ("bba" + "ba")] ...

Read More

Program to find the maximum width of a binary tree in Python

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

The maximum width of a binary tree is the number of nodes that can fit between the leftmost and rightmost nodes at any level. This includes null nodes that could exist in between. Approach We'll use a depth-first search (DFS) approach where each node is assigned a position index. For any node at position pos, its left child gets position 2*pos and right child gets 2*pos+1. At each level, we track the minimum and maximum positions to calculate the width. Algorithm Steps Create a dictionary to store minimum and maximum positions for each depth level ...

Read More

Program to check whether one string can be 1-to-1 mapped into another string in Python

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

Sometimes we need to check whether one string can be mapped to another string with a 1-to-1 character mapping. This means each character in the first string maps to exactly one character in the second string, and vice versa. For example, if we have strings "papa" and "lili", we can create a valid mapping: "p" → "l" and "a" → "i". The character order remains unchanged. Algorithm To solve this problem, we use two dictionaries to track mappings in both directions ? Create two dictionaries: one for mapping characters from string s to t, another ...

Read More

Program to check whether one value is present in BST or not in Python

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

A Binary Search Tree (BST) is a tree data structure where each node has at most two children, and for each node, all values in the left subtree are smaller and all values in the right subtree are larger. We can efficiently search for a value by comparing it with the current node and moving left or right accordingly. .node { fill: #e8f4fd; stroke: #2196f3; stroke-width: 2; } .text { font-family: Arial; font-size: 14px; text-anchor: middle; fill: #333; ...

Read More

Program to check one string can be converted to other by shifting characters clockwise in Python

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

When working with strings, we sometimes need to check if one string can be transformed into another by shifting characters clockwise in the alphabet. For example, "c" can be converted to "e" using 2 clockwise shifts (c → d → e). In this problem, we have two strings p and q, and a number r representing the maximum allowed shifts. We need to determine if p can be converted to q by shifting characters clockwise at most r times in total. Example If p = "abc", q = "ccc", and r = 3, the answer is True ...

Read More

Program to add two numbers represented as strings in Python

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

Suppose we have two strings S and T, these two are representing integers. We have to add them and find the result in the same string representation. So, if the input is like "256478921657", "5871257468", then the output will be "262350179125", as 256478921657 + 5871257468 = 262350179125. Approach To solve this, we will follow these steps − Convert S and T from string to integer Add the integers: result = S + T Return the result as string Example Let us see the following implementation to get better understanding − ...

Read More

Program to check whether list is strictly increasing or strictly decreasing in Python

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

Suppose we have a list of numbers; we have to check whether the list is strictly increasing or strictly decreasing. A list is strictly increasing if each element is larger than the previous one, and strictly decreasing if each element is smaller than the previous one. So, if the input is like nums = [10, 12, 23, 34, 55], then the output will be True, as all elements are distinct and each element is larger than the previous one, so this is strictly increasing. Algorithm To solve this, we will follow these steps ? If size of nums

Read More

Program to sqeeze list elements from left or right to make it single element in Python

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

Suppose we have a list of numbers called nums, we have to squeeze it from both the left and the right until there is one remaining element. We will return the states at each step. So, if the input is like nums = [10, 20, 30, 40, 50, 60], then the output will be ? [ [10, 20, 30, 40, 50, 60], [30, 30, 40, 110], [60, 150], [210] ] Algorithm To solve this, we will follow these steps ? ret := a list with only ...

Read More

Program to sorting important mails from different mailboxes in Python

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

Suppose we have a list of mailboxes where each mailbox contains a list of strings. Each string represents either "J" for junk, "P" for personal, or "W" for work emails. We need to process each mailbox in round-robin order starting from the first mailbox, filter out junk emails, and return a single sorted list. So, if the input is like mailboxes = [["W", "P"], ["J", "P", "J"], ["W"]], then the output will be ["W", "W", "P", "P"]. In processing order without filtering, we have W → J → W → P → P → J. After filtering out junk ...

Read More
Showing 5261–5270 of 21,090 articles
« Prev 1 525 526 527 528 529 2109 Next »
Advertisements