Server Side Programming Articles

Page 297 of 2109

Program to find maximum number of eaten apples in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 436 Views

Suppose we have two arrays called apples and days of same length n. There is a special kind of apple tree that grows apples every day for n consecutive days. On the ith day, it grows apples[i] number of apples that will rot after days[i] days. We can take at most one apple a day and want to find the maximum number of apples we can eat. So, if the input is like apples = [1, 2, 3, 5, 2] and days = [3, 2, 1, 4, 2], then the output will be 7 because ? On ...

Read More

Program to find Reordered Power of 2 in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 215 Views

Given a positive integer N, we need to check if we can reorder its digits to form a power of 2. The reordered number must have no leading zeros. For example, if N = 812, we can rearrange it to 128, which is 2^7, so the answer is True. Algorithm To solve this problem, we will follow these steps − Start with i = 1 (which is 2^0) While i ≤ 1000000000, do the following: Convert i to string and sort its digits Convert N to string and sort its digits If both sorted ...

Read More

Program to find maximum binary string after change in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 535 Views

Given a binary string, we can apply two types of operations any number of times to maximize its numeric value: Replace substring "00" with "10" Replace substring "10" with "01" We need to find the maximum possible binary string after applying these operations. Understanding the Problem The key insight is that we want to move as many 1s as possible to the left (higher positions) while keeping at least one 0 in the string. The operations allow us to: "00" → "10": Creates a 1 to the left of a 0 "10" ...

Read More

Program to find maximum average pass ratio in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 268 Views

Suppose we have a list of classes where classes[i] = [pass_i, total_i] represents the number of students who passed and the total number of students in the ith class respectively. We also have extra brilliant students guaranteed to pass any exam they're assigned to. We need to assign these extra students to maximize the average pass ratio across all classes. The pass ratio of a class is passed_students / total_students. The average pass ratio is the sum of all class ratios divided by the number of classes. Algorithm Approach We use a greedy approach with a max-heap ...

Read More

Program to find average waiting time in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 858 Views

Suppose we have an array customers, where customers[i] = [arrival_i, time_i]. Here arrival_i is the arrival time of the ith customer and time_i is the time needed to prepare the order. The cook processes orders sequentially and can only prepare one order at a time. We need to find the average waiting time of all customers. The waiting time for each customer is the total time from arrival until their order is completed. Problem Understanding Let's understand with an example. If the input is customers = [[7, 2], [8, 4], [10, 3], [20, 1]], then ? ...

Read More

Program to find center of star graph in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 639 Views

A star graph is an undirected graph with n nodes where one central node connects to all other n-1 nodes. In this tutorial, we'll learn how to identify the center node of a star graph represented as a list of edges. Understanding the Problem Given a star graph with n nodes labeled from 1 to n, we need to find the center node. The center node appears in every edge since it connects to all other nodes. ...

Read More

Program to find number of restricted paths from first to last node in Python

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

Suppose we have an undirected weighted connected graph with n nodes labeled from 1 to n. A restricted path is a special path from node 1 to node n where the distance to the destination decreases at each step. Specifically, for a path [z0, z1, z2, ..., zk], we need dist(zi) > dist(zi+1) where dist(x) is the shortest distance from node x to node n. We need to find the number of restricted paths from node 1 to node n, returning the result modulo 10^9 + 7. For example, if we have this graph: ...

Read More

Program to find maximum score we can get in jump game in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 793 Views

Suppose we have an array called nums and another value k. We are at index 0. In one move, we can jump at most k steps right without going outside the boundaries of the array. We want to reach the final index of the array. For jumping we get score, that is the sum of all nums[j] for each index j we visited in the array. We have to find the maximum score we can get. So, if the input is like nums = [1, -2, -5, 7, -6, 4] and k = 2, then the output will be ...

Read More

Program to find minimum elements to add to form a given sum in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 427 Views

When working with arrays that have element constraints, we often need to find the minimum number of elements to add to achieve a target sum. This problem involves an array where each element's absolute value is bounded by a limit, and we need to reach a specific goal sum. Problem Statement Given an array nums and two values limit and goal, where |nums[i]| ≤ limit for all elements, we need to find the minimum number of elements to insert so that the array sum equals the goal. The inserted elements must also satisfy the limit constraint. Example ...

Read More

Program to find maximum erasure value in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 238 Views

Suppose we have an array called nums (with positive values only) and we want to erase a subarray containing unique elements. We will get a score that is the sum of subarray elements. We have to find the maximum score we can get by erasing exactly one subarray. So, if the input is like nums = [6, 3, 2, 3, 6, 3, 2, 3, 6], then the output will be 11, because the optimal subarray is either [6, 3, 2] or [2, 3, 6], so the sum is 11. Algorithm To solve this, we will follow these ...

Read More
Showing 2961–2970 of 21,090 articles
« Prev 1 295 296 297 298 299 2109 Next »
Advertisements