Wrong program passes task 15 - Maximum of array

Back to General discussions forum

qwerty     2024-07-08 09:57:43

Hello everyone, it seems that wrong program can pass task #15.

x=[int(t)for t in input().split()]
print(max(x[1:-1]), min(x[1:-1]))

I submitted this code several times in row, and it still passes.

And I disagree with task title, we are searching for extremes of array, not just maximum.

qwerty     2024-07-08 10:44:26

Imagine you are transition from 0-based language to 1-based language or vice versa. And you wrongly writing loop from 0 to 299 in 1-based language or loop from 1 to 300 in 0-based language. So it would be nice to have one of the extremes at array border to catch such a case.

moxieman     2024-07-08 12:21:41
User avatar

Hi qwerty!

I'm a little confused why we're surprised that the code you provided would yield a passing result several times in a row. Although you're slicing out the first and last items of the list with x[1:-1], that's only going to yield a failing result if the minimum or maximum values of the list are in the first or last positions, which is relatively unlikely given 300 values. I think it only ~2% of testcases would be sensitive to this error.

And while it is true that the title only covers 50% of the answer, I think it covers 100% of the concept expected to be learned. If you can find one extremum in a set of data, it should be easy to find the other :)

qwerty     2024-07-08 15:23:33

I think it only ~2% of testcases would be sensitive to this error.

Exactly what I was trying to point out! We need this puzzle to be tweaked in such a way that one of the extremes would always be at array border (one of the extremes should be the first or the last element of input sequence).

Rodion (admin)     2024-07-08 17:15:37
User avatar

We need this puzzle to be tweaked in such a way that one of the extremes would always be at array border

I'm honestly against this. You then can modify your wrong program to pick some other subarray and again it will be wrong program with potentially correct answer.

Why should one intentionally write such a queer code? Well, perhaps it may happen if someone is writing a loop in a different language and starts with the wrong index...

But this is not a "competitive programming" website where we try to make a set of very exhaustive tests. Checks here are mostly simple ones, and if you search carefully, you'll probably find multiple situations like these in other problems.

It of course doesn't mean we want to rewrite everything.

I guess though we can keep in mind your frustration with this specific problem and create "advanced" version of it elsewhere, so that user is presented with several dozens of arrays, to pick extrema of them all. On the other hand writing some very whimsical checker for such a trivial task seems a bit wrong way to invest our time :)

About the task title, I fully agree with your disagreement, but let it remain as is - we may expect problem being solved by some school-kids who knows what is "minimum" and "maximum" but "extremum" may be confusing for them.

qwerty     2024-07-09 15:32:31

You then can modify your wrong program to pick some other subarray

Why would I do such a thing? My only concern is 0-based indexing vs 1-based indexing, so I can only skip first element (by wrongly using 1-based indexing), or last element (by wrongly using 0-based indexing).

qwerty     2024-07-09 15:33:51

we may expect problem being solved by some school-kids who knows what is "minimum" and "maximum" but "extremum" may be confusing for them

Maximum and minimum of array will do, then.

Please login and solve 5 problems to be able to post at forum