Server Side Programming Articles

Page 524 of 2109

Program to find largest sum of any path of a binary tree in Python

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

Suppose we have a binary tree, we have to find the largest sum of any path that goes from the root node to the leaf node. So, if the input is like ? 5 1 9 7 10 6 8 ...

Read More

Program to find circular greater element to the right in Python

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

The circular next greater element problem requires finding the next greater element to the right of each element in an array, with the array treated as circular. If no greater element exists, we assign -1. For example, given [4, 5, 1, 3], the result is [5, -1, 3, 4] because: 4's next greater element is 5 5 has no greater element, so -1 1's next greater element is 3 3's next greater element is 4 (wrapping around) Algorithm Steps We use a stack-based approach with double iteration to handle the circular nature: Initialize ...

Read More

Program to arrange cards so that they can be revealed in ascending order in Python

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

This problem involves arranging cards in a specific order so that when revealed using a particular pattern, they appear in ascending order. The revelation pattern is: remove the top card, then move the next card to the back, and repeat until no cards remain. Understanding the Problem Given cards [1, 2, 3, 4, 5, 6, 7, 8], we need to arrange them as [1, 5, 2, 7, 3, 6, 4, 8] so that the revelation process yields ascending order ? The revelation process works as follows: Remove top card (reveal it) Move the next top card ...

Read More

Program to partition two strings such that each partition forms anagram in Python

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

Suppose we have two non-empty strings s and t that are of the same length. We have to partition them into substrings such that each pair of s and t substring is the same size and they are anagrams of each other. Now find the cut indexes such that it results in the maximum number of cuts of s and t. If no result is found, then return empty list. So, if the input is like s = "bowcattiger" t = "owbactietgr", then the output will be [0, 3, 5, 6, 10], as we can partition the string into ...

Read More

Program to find sum of the sum of all contiguous sublists in Python

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

Given a list of numbers, we need to find the sum of all possible contiguous subarrays and return the result modulo 109 + 7. This problem can be solved efficiently by calculating how many times each element appears in all subarrays. For the input nums = [3, 4, 6], we have these contiguous subarrays: [3], [4], [6], [3, 4], [4, 6], [3, 4, 6]. Their sums are 3, 4, 6, 7, 10, 13 respectively, totaling 43. Understanding the Pattern Instead of generating all subarrays, we can calculate how many times each element contributes to the final sum. ...

Read More

Program to check we can reach end of list by starting from k in Python

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

Suppose we have a list of numbers called nums and another number k. If we start at index k and at any index i, we can go either left or right by exactly nums[i] number of steps. We have to check whether we can reach the end of the list or not. So, if the input is like nums = [0, 0, 2, 1, 3, 3, 1, 1] and k = 2, then the output will be True, as if we start at index 2, then jump to index 4 and then jump to the last index 7. ...

Read More

Program to find how many ways we can climb stairs (maximum steps at most k times) in Python

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

Suppose we have a staircase with n steps and we also have another number k. Initially we are at stair 0, and we can climb up either 1, 2 or 3 steps at a time, but we can only climb 3 stairs at most k times. We need to find the number of ways we can climb the staircase. So, if the input is like n = 5, k = 2, then the output will be 13, as there are different ways we can climb the stairs − [1, 1, 1, 1, 1] [2, 1, 1, 1] ...

Read More

Program to find how many ways we can climb stairs in Python

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

Suppose we have a staircase with n steps, and we can climb up either 1 or 2 steps at a time. We need to find the number of unique ways we can climb the staircase. The order of the steps matters, so each different sequence counts as a unique way. If the answer is very large, we return the result modulo 10^9 + 7. For example, if n = 5, there are 8 unique ways ? 1, 1, 1, 1, 1 2, 1, 1, 1 1, 2, 1, 1 1, 1, 2, 1 1, 1, 1, ...

Read More

Program to find minimum number of busses are required to pass through all stops in Python

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

Suppose we have a list of numbers called nums representing bus stops on a line where nums[i] shows the time a bus must arrive at station i. Since buses can only move forward in time, we need to find the minimum number of buses required to pass through all stops. So, if the input is like nums = [1, 2, 7, 9, 3, 4], then the output will be 2, as one bus can take stops [1, 2, 3, 4] and another can handle [7, 9]. Algorithm To solve this, we will follow these steps ? ...

Read More

Program to find maximum amount we can get by taking different items within the capacity in Python

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

The 0/1 Knapsack problem is a classic optimization problem where we have items with weights and values, and we need to find the maximum value we can obtain within a given weight capacity. Each item can be taken at most once. Given two lists weights and values of the same length and a capacity k, where weights[i] and values[i] represent the weight and value of the i-th item, we need to find the maximum value achievable without exceeding the capacity limit. Problem Example If we have weights = [2, 3, 4], values = [2, 6, 4], and ...

Read More
Showing 5231–5240 of 21,090 articles
« Prev 1 522 523 524 525 526 2109 Next »
Advertisements