Found 26504 Articles for Server Side Programming

Program to determine if two strings are close in Python

Arnab Chakraborty
Updated on 06-Oct-2021 07:40:53

475 Views

Suppose we have two strings, s and t, we have to check whether s and t are close or not. We can say two strings are close if we can attain one from the other using the following operations −Exchange any two existing characters. (like abcde to aecdb)Change every occurrence of one existing character into another existing character, and do the same with the other characters also. (like aacabb -> bbcbaa (here all a's are converted to b's, and vice versa))We can use the operations on either string as many times as we want.So, if the input is like s ... Read More

Program to find out the vertical area between two points where no point lies and is the widest in Python

Arnab Chakraborty
Updated on 06-Oct-2021 07:37:22

170 Views

Suppose, we are given n number of points as (x, y). A vertical area is an area that is extended infinitely along the y-axis. We have to find out the vertical area between two points such that no other point is inside the area and is the widest.So, if the input is like pts = [[10, 9], [11, 11], [9, 6], [11, 9]], then the output will be 1.The areas in red and blue are optimal and there are no points inside them.To solve this, we will follow these steps −sort the list ptsfor i in range 1 to size ... Read More

Program to find out the inheritance order in a family in Python

Arnab Chakraborty
Updated on 06-Oct-2021 07:34:03

2K+ Views

Suppose, there is a family that consists of members from different generations. Such as the family has a father, his children, and their grandmother. But births and deaths happen in each family.The eldest member of the family is considered the head. So, when the 'head' member dies, their direct successor or their children becomes the head. We implement three functions, the first one is used when a child is born into the family. The function takes the parent's name and child's name as input and adds them to the record.The second function is used when there is a death. It ... Read More

Program to find minimum jumps to reach home in Python

Arnab Chakraborty
Updated on 06-Oct-2021 07:36:01

433 Views

Suppose there is an array called forbidden, where forbidden[i] indicates that the bug cannot jump to the position forbidden[i], and we also have three values a, b, and x. A bug's home is at position x on the number line. It is at position 0 initially. it can jump by following rules −Bug can jump exactly a positions to the right.Bug can jump exactly b positions to the left.Bug cannot jump backward twice in a row.Bug cannot jump to any forbidden positions given in the array.Bug can jump forward beyond its home, but it cannot jump to positions numbered with ... Read More

Program to find out the minimum rotations needed to maximize the profit from a Ferris wheel in Python

Arnab Chakraborty
Updated on 06-Oct-2021 07:30:39

204 Views

Suppose there is a Ferris wheel with four cabins and each cabin can contain four passengers. The wheel rotates counter-clockwise, and for each rotation, it costs 'run' amount of money. We now have an array 'cust' that contains n items and each item i signifies the number of people waiting to get into the Ferris wheel before the i-th rotation. To board the wheel, each customer has to pay an amount of money 'board', and that much money is for one anti-clockwise rotation of the wheel. The people waiting in line should not wait if there is any vacant seat ... Read More

Program to find minimum deletions to make string balanced in Python

Arnab Chakraborty
Updated on 06-Oct-2021 07:28:25

581 Views

Suppose we have a string s with only two characters 's' and 't'. We can delete any number of characters of s to make the string balanced. We can say, s is balanced when there is no pair of indices (i, j) such that i < j and s[i] = 't' and s[j]= 's'. We have to find the minimum number of deletions needed to make s balanced.So, if the input is like s = "sststtst", then the output will be 2 because we can either, remove the characters at indices 2 and 6 ("sststtst" to "sssttt"), or remove the ... Read More

Program to find maximum profit by selling diminishing-valued colored balls in Python

Arnab Chakraborty
Updated on 06-Oct-2021 07:18:13

279 Views

Suppose we have an array called, inventory, where inventory[i] represents the number of balls of the ith color we have initially. We also have a value called orders, which represents the total number of balls that the customer wants. we can sell the balls in any order. In our inventory there are different colored balls, customers want balls of any color. Now the values of the balls are special in nature. Each colored ball's value is the number of balls of that color we have in our inventory. So if we currently have 6 blue balls, the customer would pay ... Read More

Program to find out the farthest building a parkour artist can reach in Python

Arnab Chakraborty
Updated on 06-Oct-2021 07:13:44

188 Views

Suppose, there are n number of houses of different heights and a parkour artist wants to go from one house to another with help of some bricks and ladders. The heights of the houses are given to us as an array. Each brick is a unit length tall and we are given a handful of those. We can use the ladders and the bricks only once. We have to find out the furthest building the parkour artist can go to.So, if the input is like heights = [5, 8, 7, 6, 2, 3, 1, 4], bricks = 3, ladders = ... Read More

Program to check subarrays can be rearranged from arithmetic sequence or not in Python

Arnab Chakraborty
Updated on 06-Oct-2021 07:09:18

190 Views

Suppose we have sequence of numbers nums, and another two arrays l and r of size m, these l and r are representing range queries like [l[i], r[i]]. We have to find a Boolean sequence ans, where ans[i] is true when the subarray nums[l[i]], nums[l[i] + 1], ... nums[r[i] - 1], nums[r[i]] can be arranged to generate an arithmetic sequence, otherwise false.A sequence is said to be arithmetic, if it consists of at least two elements, and the difference between every two consecutive elements is the same. For example, some arithmetic sequences are: [2, 4, 6, 8, 10], [5, 5, ... Read More

Program to find minimum moves to make array complementary in Python

Arnab Chakraborty
Updated on 05-Oct-2021 13:26:17

360 Views

Suppose we have an array nums of even length another value limit. In one move, we can replace any value from nums with another value between 1 and limit, inclusive. The array is said to be complementary if for all indices i, nums[i] + nums[n-1-i] equals the same number. So we have to find the minimum number of moves required to make nums complementary.So, if the input is like nums = [1, 4, 2, 3] limit = 4, then the output will be 1 because in one move we can make element at index 1 to 2, so array will ... Read More

Advertisements