Ninja And The Triangle Problem Statement

Ninja is provided with 'N' stars and the task is to construct a triangle such that the 'i'th level of the triangle uses 'i' number of stars. The goal is to make the triangle as tall as possible using the given stars.

Example:

Input:
N = 6
Output:
3
Explanation:

With 6 stars, Ninja can build a triangle with a maximum height of 3 levels: 1+2+3 = 6 stars.

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 10^8
Input:
The first line contains an integer 'T', the number of test cases. Each of the next 'T' lines contains a single integer 'N', the number of stars available.
Output:
For each test case, output a single integer representing the maximum height of the triangle possible with the given stars. Output each result on a separate line.

Note:

No need to print anything. Implement the function to solve the problem.

Be the first one to answer
Add answer anonymously...
Blackrock Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter