Maximum of a Section X28271


Statement
 

pdf   zip

html

Given a sequence of integers, we specify a “section” of it using two integers a and b. This is exactly as in the related problem Identifying Sections: the section is the part of the sequence that starts immediately after the first occurrence of a, if any, and ends immediately before the first occurrence of b after the first occurrence of a, if any.

For instance, given the sequence 6, 5, 1, 2, 1, 4, 3, 5, 4, 3, 5, 1 with a = 1 and b = 5 we specify the subsequence 2, 1, 4, 3 that starts just after the first 1 and ends just before the first 5 after that 1.

Write a program that finds the maximum value of a specified section. In the case above, it would be 4. The input indicates first a and b, in one line, separated with whitespace; the subsequent line (or lines) constitute the sequence.

In the related problem Identifying Sections, we knew the length of the sequence beforehand, and we had several cases. Those two aspects change here, as does the handling of empty sections: if a does not appear in the sequence, of if it appears but b does not appear subsequently, your program must print "nonexistent section"; if they appear but there are no intervening numbers, your program must print "empty section"; otherwise, your program must print "maximum is: " followed by the corresponding maximum value.

Public test cases
  • Input

    1 5
    6 0 1 2 1 4 3 5 4 3 5 1
    

    Output

    maximum is: 4
    
  • Input

    7 5
    6 0 1 2 1 4 3 5 4 3 5 1
    

    Output

    nonexistent section
    
  • Input

    5 7
    6 0 1 2 1 4 3 5 4 3 5 1
    

    Output

    nonexistent section
    
  • Input

    2 1
    6 0 1 2 1 4 3 5 4 3 5 1
    

    Output

    empty section
    
  • Input

    6 7
    6 8 1 2 1 4 3 5 4 3 5 7
    

    Output

    maximum is: 8
    
  • Information
    Author
    José Luis Balcázar
    Language
    English
    Official solutions
    Python
    User solutions