We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8346283 commit 9c6494bCopy full SHA for 9c6494b
Week03/pyramid_niyazi_cetinkaya.py
@@ -1,9 +1,10 @@
1
-def calculate_pyramid_height(number_of_blocks: int) -> int:
2
- height = 0
3
- while True:
4
- if number_of_blocks > height*(height+1)/2:
5
- height = height + 1
6
- else:break
7
- return height
+def calculate_pyramid_height(number_of_blocks):
+ height = 0 # Start with height 0
+
+ # Loop until blocks required for the next level exceed available blocks
+ while (height * (height + 1)) // 2 <= number_of_blocks:
+ height += 1
8
+ return height - 1 # Subtract 1 to get the maximum achievable height
9
10
0 commit comments