Question about the area of container

  • 0

    For Input: [1,1]

    I thought the container size is 2, but answer is 1. I am confused.

  • 2

    The input [1,1] means the top points are (1,1) and (2,1). Each point has a line travelling down to the x-axis, meaning the lines are ((1,1),(1,0)) and ((2,1),(2,0)). The question then asks what the maximum area of the container is, when the container's sides are the lines. There are only two lines from the input, so the sides are those two. The y-axis cannot be used as another line.

    The area is the width times the height.

    Width = P2.x - P1.x = 2 - 1 = 1

    Height = min(P1.y, P2.y) = min(1,1) = 1

    A = W*H = 1*1 = 1

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.