Found 26504 Articles for Server Side Programming

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

Arnab Chakraborty
Updated on 17-May-2021 13:07:17

264 Views

Suppose we have 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 are same, then the median isTo solve this, we will follow these steps −sort the list numsn := size of numsper := quotient of (n*5/100)l2 := subarray of nums from index ... Read More

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

Arnab Chakraborty
Updated on 17-May-2021 13:05:12

470 Views

Suppose we have an array called nums where all elements are either 0 or positive. The nums is considered special array if there exists a number x such that there are exactly x numbers in nums which are larger than or equal to x. And x does not have to be an element in nums. Here we have to find x if the array is special, otherwise, return -1.So, if the input is like nums = [4, 6, 7, 7, 1, 0], then the output will be 4 as there are 4 numbers which are greater or equal to 4.To ... Read More

Program to design parking system in Python

Arnab Chakraborty
Updated on 17-May-2021 13:02:23

3K+ Views

Suppose you want to design a parking system. A parking lot has three different kinds of parking spaces − big, medium, and small. And there are fixed number of slots for each size. Make a class called OurParkingSystem with of two methods −constructor(big, medium, small) − This constructor is taking the number of slots available for different spaces and initializes object of the OurParkingSystem class.addCar(carType) − This method checks whether there is a parking space of given carType for the car that wants to put inside the parking lot.The three slots big, medium, or small, are represented by 1, 2, ... Read More

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

Arnab Chakraborty
Updated on 17-May-2021 13:01:57

345 Views

Suppose we have a logs where we have path to enter into folders, there may be different symbols like −"../" : 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 have to find minimum number of operations needed to come back from last folder where we stop to the main folder.So, if the input is like logs = ["Dir1/", "Dir2/", "../", "Dir2/", "Dir3/", "./"], then the output will be 3from the image we can ... Read More

Program to rearrange spaces between words in Python

Arnab Chakraborty
Updated on 17-May-2021 13:01:33

395 Views

Suppose we have a string s with some words that are placed among some number of spaces. Each words are separated by at least one space. We have to rearrange the spaces so that there are same number of spaces between every pair of adjacent words and the number of spaces between each word is maximized. If we are unable to redistribute all the spaces equally, we can place the extra spaces at the end.So, if the input is like s = " I love programming ", then the output will be "I love programming ", see the spaces are ... Read More

Program to find sum of all odd length subarrays in Python

Arnab Chakraborty
Updated on 17-May-2021 13:01:13

494 Views

Suppose we have an array of positive values called nums, we have to find the sum of all possible odd-length subarrays. As we know a subarray is a contiguous subsequence of the array. We have to find the sum of all odd-length subarrays of nums.So, if the input is like nums = [3, 8, 2, 5, 7], then the output will be The odd-length subarrays are −nums[0] = 3 nums[1] = 8 nums[2] = 2 nums[3] = 5 nums[4] = 7 nums[0..2], so sum = 13 nums[1..3], so sum = 15 nums[2..4], so sum = 14 nums[0..4] = 25 So ... Read More

Program to find number of special positions in a binary matrix using Python

Arnab Chakraborty
Updated on 17-May-2021 13:00:44

295 Views

Suppose we have a binary matrix of order m x n, we have to find the number of special positions in the matrix. A position (i, j) is a special position when mat[i, j] = 1 and all other elements in row i and column j are 0.So, if the input is like10000001000001101000then the output will be 3, here the special positions are (0, 0), (1, 2) and (3, 1).To solve this, we will follow these steps −special := 0for i in range 0 to row count of matrix, doif number of 1s in row matrix[i] is 1, thennumOfOne := ... Read More

Program to replace all question symbols to avoid consecutive repeating characters in Python

Arnab Chakraborty
Updated on 17-May-2021 12:53:59

434 Views

Suppose we have a lowercase string s that contains only letters and '?' character, we have to convert all '?' characters into lower case letters such that the final string will not have any consecutive repeating characters. If there is more than one solution, return any of them.So, if the input is like s = "hel??", then the output will be helab, se first question mark may be anything except 'l' and when first one is given, then second one can be anything except 'a'.To solve this, we will follow these steps −if size of s is same as 1, ... Read More

Program to find diagonal sum of a matrix in Python

Arnab Chakraborty
Updated on 17-May-2021 12:53:35

9K+ Views

Suppose we have a square matrix; we have to find the sum of the matrix diagonals. So only include the sum of all of the elements on the primary diagonal and all the elements on the secondary diagonal and ignore the crossing element.So, if the input is like10596815323812321173then the output will be The primary diagonal elements are [10, 15, 12, 3] sum is 40, secondary diagonal [6, 3, 8, 2] sum is 19, so total sum 59.To solve this, we will follow these steps −m := row count of matrixif m is same as 1, thenreturn matrix[0, 0]count := 0for ... Read More

Program to check pattern of length m repeated K or more times exists or not in Python

Arnab Chakraborty
Updated on 17-May-2021 12:53:11

217 Views

Suppose we have an array nums with positive values, we have to find a pattern of length m that is repeated k or more than k times. Here a pattern is a non-overlapping subarray (consecutive) that consists of one or more values and are repeated multiple times. A pattern is defined by its length and number of repetitions. We have to check whether there exists a pattern of length m that is repeated k or more times or not.So, if the input is like nums = [3, 5, 1, 4, 3, 1, 4, 3, 1, 4, 3, 9, 6, 1], ... Read More

Advertisements