Professional Documents
Culture Documents
You must correctly implement the function described in the prompt below.
Feel free to test out pieces of code to help you write the solution.
Please thoroughly test that the final code implements the function correctly.
Prompt
Function signature: getEnding(beg: List[int]) -> List[int]
Constraints
Examples
0)
{1, 1, 2, 2}
Returns: {1, 2 }
1)
{5, 6, 6}
Returns: {1, 1, 1 }
2)
{1, 3}
Returns: {1, 1, 2, 1 }
3)
{2, 5, 5, 5, 4, 4, 3}
Returns: {4 }
We need to find the y coordinate for the last vertex that will
generate a convex polygon. Points (3, 1) and (3, 2) would make
the polygon non-convex. Point (3, 3) would break the rules
because there would be three consecutive vertices on the same
straight line. Point (3, 4) is the only valid choice.
4)
{1, 1, 2, 3, 3, 1, 1, 2, 3}
Returns: {-1 }
No matter what the last y-coordinate is, the edge (1, 1)-(2, 3)
intersects the edge (3, 1)-(1, 2), so there is no convex polygon
possible.
In [ ]: