Server Side Programming Articles

Page 374 of 2109

Program to decrypt code to defuse the bomb in Python

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

Suppose there is a bomb that you are going to defuse, and your time is running out! You have a circular array code of length n and have a key k. To decrypt the code, you must replace every number simultaneously based on these rules ? If k > 0 then replace ith number with the sum of next k numbers. If k < 0 then replace ith number with the sum of previous k numbers. If k = 0 then replace ith number with 0. ...

Read More

Program to find maximum in generated array in Python

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

Given a number n, we need to generate an array A of length n + 1 using specific rules and find the maximum value in it. Array Generation Rules The array is built following these rules ? A[0] = 0 A[1] = 1 A[2 * i] = A[i] if 2 ≤ 2 * i ≤ n A[2 * i + 1] = A[i] + A[i + 1] if 2 ≤ 2 * i + 1 ≤ n Example Walkthrough For n = 5, let's see how the array is constructed ? ...

Read More

Program to check we can form array from pieces or not in Python

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

Suppose we have an array nums where all elements are unique and have another array with different smaller arrays called pieces. We have to check whether we can get the main array nums by concatenating the arrays in pieces in any order or not. But we are not allowed to reorder the elements present in each array pieces[i]. So, if the input is like nums = [5, 1, 12, 36, 2, 47, 6] pieces = [[2, 47, 6], [12, 36], [1], [5]], then the output will be True because we can concatenate them in this order [[5], [1], [12, ...

Read More

Program to sort array by increasing frequency of elements in Python

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

Suppose we have an array with some elements where elements may appear multiple times. We have to sort the array such that elements are sorted according to their increasing frequency. Elements that appear fewer times will come first, and when frequencies are equal, larger elements come first. So, if the input is like nums = [1, 5, 3, 1, 3, 1, 2, 5], then the output will be [2, 5, 5, 3, 3, 1, 1, 1] Algorithm Steps To solve this, we will follow these steps ? Create a frequency map to count occurrences of ...

Read More

Program to find largest substring between two equal characters in Python

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

Suppose we have a string s, we have to find the length of the longest substring between two equal letters or elements, excluding the two characters. If we cannot find such substring, then return -1. So, if the input is like s = "level", then the output will be 3 as optimal substrings can be either "lev" or "vel". Algorithm To solve this, we will follow these steps − memo := a new map for i in range 0 to size of s - 1, do if s[i] is in memo, then insert ...

Read More

Program to find mean of array after removing some elements in Python

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

Suppose we have an array called nums, we have to find the mean of the remaining values after removing the smallest 5% and the largest 5% of the elements. So, if the input is like nums = [2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8], then the output will be 4.0 because after removing smallest and largest values, all remaining elements are the same. Algorithm To solve this problem, we will follow these steps − Sort the array nums n := size of ...

Read More

Program to find X for special array with X elements greater than or equal X in Python

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

A special array is one where there exists a number x such that exactly x elements in the array are greater than or equal to x. We need to find this value x, or return -1 if no such value exists. For example, in the array [4, 6, 7, 7, 1, 0], there are 4 numbers (4, 6, 7, 7) that are greater than or equal to 4, making x = 4 the special value. Algorithm To solve this problem, we follow these steps ? Iterate through all possible values of ...

Read More

Program to design parking system in Python

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

Suppose you want to design a parking system. A parking lot has three different kinds of parking spaces − big, medium, and small. Each size has a fixed number of available slots. We'll create a class called ParkingSystem with two methods ? constructor(big, medium, small) − Takes the number of slots available for different spaces and initializes the ParkingSystem object. addCar(carType) − Checks whether there is a parking space of the given carType for the car that wants to park. The three slot types big, medium, and small are represented by 1, 2, and 3 respectively. ...

Read More

Program to find minimum jump needed to return from a folder to home in Python

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

Suppose we have logs where we have a path to enter into folders. There are different symbols that represent navigation operations − "../": Move to the parent folder from current one. (If we are at main folder, do not change location). "./": Remain in the current folder. "x/": Move to the child folder named x. From the logs we need to find the minimum number of operations needed to come back from the last folder where we stop to the main folder. Problem Understanding If the input is like logs = ["Dir1/", "Dir2/", "../", ...

Read More

Program to rearrange spaces between words in Python

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

Sometimes we need to rearrange spaces between words to create uniform spacing. This involves redistributing all spaces evenly between words, with any extra spaces placed at the end. Given a string with words separated by varying numbers of spaces, we need to rearrange the spaces so that there are equal spaces between every pair of adjacent words. If we cannot redistribute all spaces equally, the extra spaces go at the end. Example If the input is " I love programming ", the output will be "I love programming ". The original ...

Read More
Showing 3731–3740 of 21,090 articles
« Prev 1 372 373 374 375 376 2109 Next »
Advertisements