HackerRank - Minimum Height Triangle solution
2 min read

HackerRank - Minimum Height Triangle solution

HackerRank - Minimum Height Triangle solution

Given integers  and , find the smallest integer , such that there exists a triangle of height , base , having an area of at least .

image

Input Format

In the first and only line, there are two space-separated integers  and , denoting respectively the base of a triangle and the desired minimum area.

Constraints

Output Format

In a single line, print a single integer , denoting the minimum height of a triangle with base  and area at least .

Sample Input 02 2

Sample Output 02

Explanation 0

The task is to find the smallest integer height of the triangle with base  and area at least . It turns out, that there are triangles with height , base  and area , for example a triangle with corners in the following points: :

image

It can be proved that there is no triangle with integer height smaller than , base  and area at least .

Sample Input 117 100

Sample Output 112

Explanation 1

The task is to find the smallest integer height of the triangle with base  and area at least . It turns out, that there are triangles with height , base  and area , for example a triangle with corners in the following points: .

image

It can be proved that there is no triangle with integer height smaller than , base  and area at least .

Solution in Python

#!/bin/python3

import sys,math

def lowestTriangle(base, area):
    return math.ceil(area*2/base)

base, area = input().strip().split(' ')
base, area = [int(base), int(area)]
height = lowestTriangle(base, area)
print(height)

Enjoying these posts? Subscribe for more


Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

That's okay. But without advertising-income, we can't keep making this site awesome.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add thepoorcoder.com to your ad blocking whitelist or disable your adblocking software.

×