Problem Statement Given two integer arrays A and B of size N and M respectively. You begin with a score of 0. You want to perform exactly K operations. On the iᵗʰ operation (1-indexed), you will: Choose one integer x from either the start or the end of any one array, A or B. Remove it from that array Add

# Tag: max

## Remove NaN in a python list using max

In a recent interview I was given the following problem. We have a list l = [NaN, 5, -12, NaN, 9, 0] and we want to replaceNaN with -9 using the max function knowing that max(NaN, -9) = -9. What I have tried is : but the output is still the same list. Can’t figure out how to code this.

## How to get statistics from an array Collection ? (min max, and average)

I have a text file that has a long 2D array as follows: The first element of each has numbers between 1 to 7. I want to read information of second element for all and find the maximum and minimum amount for each group between 1 to 7 separately. For example output like this: What is the most efficient way

## max(*args, key = … ). How to modify key to get just certain values?

I am a bit confused with max(*args, key = ..) function. Imagine I have a following list: my_list = [2, 3, 4, -5, -2, -1]. I want to find maximum value within the negative values in my_list. For this, I am using the following code max(my_list, key = lambda x: x<0), but it gives me -5. Can you please explain

## Trying to compare to values in a pandas dataframe for max value

I’ve got a pandas dataframe, and I’m trying to fill a new column in the dataframe, which takes the maximum value of two values situated in another column of the dataframe, iteratively. I’m trying to build a loop to do this, and save time with computation as I realise I could probably do it with more lines of code. However,

## How to find the maximum x value of a function?

I need to find the maximum x value associated to the maximum y value of the following function that I plot using Python matplotlib module: Hence, the trend is this one: If I use the max() function in such way: It prints only the maximum y value (that in this case is equal to 0.8306243772229114). How can I do to

## Getting the max and min from a dictionary without using max() and min()

I have a dictionary with two values (id and amount): dict={5: [379], 11: [396], 6: [480], 19: [443]} and I want to find the id with the max and min amount from the dictionary without using the max …

## How to replace values in a np 2d array based on condition for every row

I have a numpy 2d array (named lda_fit) with probabilities, where I want to replace the probabilities with 0 or 1, based on the max value in each line. So after all the first line should look like [0,1,0,0], the second like [1,0,0,0] and so on. I have tried, and this works, but only for […]

## Max and Min value for each colum of one Dataframe

Give this dataframe ‘x’: col1 col2 col3 col4 0 5 -2 1 -5 2 -1 9 3 -7 3 5 How I could get a list of pairs with the min and max of each column? The result …