We have N coins which need to arrange in form of a triangle, i.e. first row will have 1 coin, second row will have 2 coins and so on, we need to tell maximum height which we can achieve by using these N coins.

Examples:

Input : N = 7 Output : 3 Maximum height will be 3, putting 1, 2 and then 3 coins. It is not possible to use 1 coin left. Input : N = 12 Output : 4 Maximum height will be 4, putting 1, 2, 3 and 4 coins, it is not possible to make height as 5, because that will require 15 coins.

`# Python3 program to find ` `# maximum height of arranged ` `# coin triangle ` ` ` `# Returns the square root of n. ` `# Note that the function ` `def` `squareRoot(n): ` ` ` ` ` `# We are using n itself as ` ` ` `# initial approximation ` ` ` `# This can definitely be improved ` ` ` `x ` `=` `n ` ` ` `y ` `=` `1` ` ` ` ` `e ` `=` `0.000001` `# e decides the accuracy level ` ` ` `while` `(x ` `-` `y > e): ` ` ` `x ` `=` `(x ` `+` `y) ` `/` `2` ` ` `y ` `=` `n` `/` `x ` ` ` ` ` `return` `x ` ` ` ` ` `# Method to find maximum height ` `# of arrangement of coins ` `def` `findMaximumHeight(N): ` ` ` ` ` `# calculating portion inside the square root ` ` ` `n ` `=` `1` `+` `8` `*` `N ` ` ` `maxH ` `=` `(` `-` `1` `+` `squareRoot(n)) ` `/` `2` ` ` `return` `int` `(maxH) ` ` ` ` ` `# Driver code to test above method ` `N ` `=` `12` `print` `(findMaximumHeight(N)) ` ` ` `# This code is contributed by ` `# Smitha Dinesh Semwal ` |

*chevron_right*

*filter_none*

**Output:**

4

Please refer complete article on Maximum height when coins are arranged in a triangle for more details!

## Recommended Posts:

- Check if elements of an array can be arranged satisfying the given condition
- Find all angles of a triangle in 3D
- Check if a triangle of positive area is possible with the given angles
- Python program to find second maximum value in Dictionary
- Python Program for Maximum size square sub-matrix with all 1s
- Python program to find Maximum value from dictionary whose key is present in the list
- Python program to Sort Matrix by Maximum Row element
- Python Program that displays the key of list value with maximum range
- Python program to Sort Tuples by their Maximum element
- Python Program for Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Python Program for Program to Print Matrix in Z form
- Python Program for Program to calculate area of a Tetrahedron
- Python Program for Efficient program to print all prime factors of a given number
- Python Program for Program to find area of a circle
- Python program to check if the list contains three consecutive common numbers in Python
- Python - Maximum product using K elements
- Python | Get first element with maximum value in list of tuples
- Python | Get key with maximum value in Dictionary
- Python | Find maximum length sub-list in a nested list
- Python | Maximum Sum Sublist