Skip to content

Document CalculateMaxOfMin #5038

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

Conversation

mvouzikis
Copy link

@mvouzikis mvouzikis commented Feb 5, 2024

…teMaxofMin.java file

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@vil02 vil02 changed the title I added some descriptive javadoc and commments throughout the Calcula… Document CalculateMaxOfMin Feb 5, 2024
@vil02
Copy link
Member

vil02 commented Feb 5, 2024

@mvouzikis thanks for your contribution, the comments look good. However, there is a bug in the existing/original code. Since you have it fresh - would you like to fix it?

As far as I see, the current code simply returns the maximum of the input array (the test cases are wrong!). Consider the input {1, 1, 5, 1}. The sub arrays are:

{1} -> min: 1,
{1, 5} -> min: 1,
{1, 5, 1} -> min: 1,

So the result should be max{1, 1, 1} = 1.

@siriak, @BamaCharanChhandogi: please have a look

@siriak
Copy link
Member

siriak commented Feb 5, 2024

Isn't it always equal to the first element? If not, please provide a counterexample.

@siriak
Copy link
Member

siriak commented Feb 5, 2024

I probably don't understand the problem statement.

@mvouzikis
Copy link
Author

If no progress is made, I can check it tomorrow run some examples and see where the bug lies

@BamaCharanChhandogi
Copy link
Member

@mvouzikis thanks for your contribution, the comments look good. However, there is a bug in the existing/original code. Since you have it fresh - would you like to fix it?

As far as I see, the current code simply returns the maximum of the input array (the test cases are wrong!). Consider the input {1, 1, 5, 1}. The sub arrays are:

{1} -> min: 1,
{1, 5} -> min: 1,
{1, 5, 1} -> min: 1,

So the result should be max{1, 1, 1} = 1.

@siriak, @BamaCharanChhandogi: please have a look

The code is correct.
{1,1,5,1}

[1] -> 1
[1, 1] -> 1
[1, 1, 5]  -> 1
[1, 1, 5, 1]  -> 1
[1, 1, 5, 1]  -> 1
[1, 5]  -> 1
[1, 5, 1] -> 1
[5] -> 5
[5, 1] -> 1
[1] -> 1

Output will be: 5(max)

@vil02
Copy link
Member

vil02 commented Feb 6, 2024

I think this method is finding the maximum of minima of all subarrays (of any length). In this case it is simply the max (because it is enough to consider arrays of length 1), so @BamaCharanChhandogi is correct.

@siriak: if this problem would only consider arrays of the type (python notation) arr[0:1], arr[0:2], arr[0:3], ..., then the result will be always arr[0] (because min(arr[0:n]) >= min(arr[0:n], arr[n]) = min(arr[0:n+1])).

I think that the real problem should be finding maximum of minima of sub arrays of given length.

I suggest to remove current implementation and create a new PR with a correct one. @mvouzikis would you like to do that?

Copy link

github-actions bot commented Mar 8, 2024

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!

@github-actions github-actions bot added the stale label Mar 8, 2024
Copy link

Please reopen this pull request once you have made the required changes. If you need help, feel free to ask in our Discord server or ping one of the maintainers here. Thank you for your contribution!

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

Successfully merging this pull request may close these issues.

4 participants