Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11.7 Finding MIN MAX simultaneously. Isn't this a better way ? #223

Closed
Abhilash-Mandlekar opened this issue Nov 6, 2021 · 0 comments
Closed

Comments

@Abhilash-Mandlekar
Copy link

This solution passes all the test cases. It has O(N) time and O(1) space. I wonder if this is more readable solution:

`public static MinMax findMinMax(List A) {
Integer min = Integer.MAX_VALUE;
Integer max = Integer.MIN_VALUE;

for(int n: A){
  if(n<min)
    min = n;
  
  if(n>max)
    max = n;
}
return new MinMax(min, max);

}`

(I was asked this question in an interview and solved this way)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant