Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3200 - Maximum Height of a Triangle.

    Easy

    You are given two integers red and blue representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1<sup>st</sup> row will have 1 ball, the 2<sup>nd</sup> row will have 2 balls, the 3<sup>rd</sup> row will have 3 balls, and so on.

    All the balls in a particular row should be the same color, and adjacent rows should have different colors.

    Return the maximum height of the triangle that can be achieved.

    Example 1:

    Input: red = 2, blue = 4

    Output: 3

    Explanation:

    The only possible arrangement is shown above.

    Example 2:

    Input: red = 2, blue = 1

    Output: 2

    Explanation:

    The only possible arrangement is shown above.

    Example 3:

    Input: red = 1, blue = 1

    Output: 1

    Example 4:

    Input: red = 10, blue = 1

    Output: 2

    Explanation:

    The only possible arrangement is shown above.

    Constraints:

    • 1 &lt;= red, blue &lt;= 100

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer maxHeightOfTriangle(Integer red, Integer blue)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait