Questions tagged [max]

Maximum value. Largest, biggest, greatest.

max

max() is a math library function available in many programming environments which returns the entity of greatest value from two or more candidate values.

Do not use for questions about the maximal value of a type, e.g. Long.MAX_VALUE, Integer.MAX_VALUE, etc.

Examples

SQL

SQL MAX() function is one of aggregate functions. It returns the largest value of column.

SELECT MAX(column_name) FROM table_name;

Python

In Python, the native max function identifies the largest element of a set (e.g. a list).

>> max([1, 2, 3])
3

Java

In Java we can use java.lang.Math class to compute maximum value of two arguments.

int maxElement = Math.max(x, y);

To compute maximum element in collection we can use, max() method from java.util.Collections class.

int maxElement = Collections.max(list);

Ruby

In Ruby to compute maximum element of collection we simply use max function.

[4,7].max

Clojure

In Clojure we use max function in the following way.

(max 1 2 3 4)

In above code max is the function name and numbers 1..4 are arguments passed to it. We can also apply the max function to lists.

(apply max [1 2 3 4])

R

In R we have function max.

x <- c(1, 2, 3)
y <- c(4, 5)
z <- c(6, NA)
max(x)
max(y)
max(z)
max(z, na.rm = TRUE)
max(x, y, z, na.rm = TRUE)  ## as same as max(c(x, y, z), na.rm = TRUE)

Rust

In Rust we can use std::cmp::max to compute the maximum value of two arguments.

let max = std::cmp::max(x, y);

We can compute the maximum element in a collection by transforming it into an Iterator and then calling the max method on the iterator.

let max = collection.into_iter().max();
8982 questions
2
votes
0 answers

Fibonacci problem, exceeding the maximum value of int

I m trying to solve https://www.spoj.com/problems/FIBOSUM/ problem. MOD = 1000000007; function copy(a, b) { a[0][0] = b[0][0]; a[0][1] = b[0][1]; a[1][0] = b[1][0]; a[1][1] = b[1][1]; } function multiply(fib, base) { let mat =…
Wojtach
  • 21
  • 1
2
votes
8 answers

Max-Mn Sum JavaScript HackerRank challenge

Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers. For…
Elgun Quliyev
  • 67
  • 2
  • 8
2
votes
2 answers

SQL order results by local max of each group

I am struggling to write a query that returns what I want. The table: |---------------------|------------------|------------------|------------------| | -- filename -- | -- url -- | -- pixels -- | -- id -- …
Some Guy
  • 576
  • 1
  • 4
  • 17
2
votes
3 answers

SQL finding max value of column where another column has got maximum but repetable value

I have following table: id year month 1 2019 9 2 2019 10 3 2019 11 4 2019 12 5 2020 1 6 2020 2 7 2020 3 8 2020 4 I need to select max value of column month but only from where year has got max value. In…
Marcin
  • 63
  • 1
  • 8
2
votes
4 answers

Top highest values in an object (more if there are more max values and they are the same)

Lets suppose I have object like this: var obj = {a : 5, b : 10, c : 15, d : 20, e : 20, f : 25}; I would like to get top 3 highest values - notice that d and e key have the same value and I need to get the keys also, so it would looks…
Proo1931
  • 103
  • 1
  • 12
2
votes
1 answer

How big of a buffer should I create for the longest possible user or group name on Linux?

What is the maximum number of characters that a user name or group name may be on Linux? I need to allocate a buffer and would like to know how much space I need to allocate to guarantee it is large enough for whatever group or user name my…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
2
votes
2 answers

Calculating max/min for every n rows of dataframe in python

I want to calculate the min/max for every n rows of a df, say 10, but using df.rolling(10).max() gives the values for rows 0-9, 1-10, 2-11 etc. I want 0-9, 10-19, 20-29 etc Is there a neat way of doing this for a large dataset? Thanks
user12845343
  • 21
  • 1
  • 2
2
votes
1 answer

Netlogo select min first value of lists of lists

I am looking for a solution in Netlogo to get a value from a list of lists with the minimum pair value. ((value1,value2)(value1,value2)...) As an example I have a list: ListofLists = ((2,3)(5,8)(1,9)) I want to select the list with the minimum…
TEck
  • 21
  • 1
2
votes
2 answers

When a row has a MAX value then get it a string value of "Yes"?

I think this should be a quick one, but how do I get to identify a MAX value of a table and give it a string label "Yes"? I know there is a case statement in this but just need some direction. Example ID Amount Max 110 1000 111 …
2
votes
3 answers

Find the Min Even Integer and Max Even Integer in an Array

int i,max,min; int A[11]; min = A[1]; max = A[1]; for(i=1;i<=10;i++) { if(min > A[i] && A[i]%2 ==0 ) min = A[i]; if(max < A[i] && A[i]%2 ==0 ) max = A[i]; } printf("Minimum Even : %d\n",min); …
Opal Opal
  • 35
  • 1
  • 3
2
votes
0 answers

In LightGBM, what does Max_depth = -1 (no limit) means?

what does no limitation mean when tuning the parameter max_depth in LightGBM? does every tree have different depth ? is there a way to check what is the trained model depth?
Or_K
  • 61
  • 6
2
votes
2 answers

Python - How to find the maximum number comparing to all its neighbors

I have a problem to solve with a Python code. Input ( M ) = 2D array with integer numbers Output (T ) same 2D array but with 0 and 1. Ti,j = 1 if all the neighbors of the integer Mi,j (in the 8 possible directions) are STRICTLY smaller than the…
datascientist
  • 81
  • 1
  • 6
2
votes
5 answers

Select min or max values within one cell (delimited string)

I have a data frame where for each sample the columns can have multiple values, for example: Gene Pvalue1 Pvalue2 Pvalue3 Beta Ace 0.0381, ., 0.00357 0.01755, 0.001385 0.0037, NA , 0.039 …
DN1
  • 234
  • 1
  • 13
  • 38
2
votes
2 answers

SCALA: How to use collect function to get the latest modified entry from a dataframe?

I have a scala dataframe with two columns: id: String updated: Timestamp From this dataframe I just want to get out the latest date, for which I use the following code at the moment: df.agg(max("updated")).head() // returns a row I've just read…
Eve
  • 604
  • 8
  • 26
2
votes
3 answers

finding maximum depth of chapter

everyone . In this case ,I want to conpute the maxximun depth of the chapter.For instance, a book without chapters has height 0 . A book only has chapters with no sections ,the height should be 1.The folowing is xml:
ZAWD
  • 651
  • 7
  • 31