bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1739. Building Boxes

1739. Building Boxes

Leetcode Solutions

Building a Pyramid Base and Adding Extra Boxes

  1. Initialize cur to 0, i to 0, and j to 0. These variables represent the current number of boxes, the total number of boxes on the floor, and the size of the last layer, respectively.
  2. While cur is less than n, increment j by 1, add j to i, and add i to cur.
  3. If cur equals n, return i as the result.
  4. Otherwise, subtract i from cur and j from i.
  5. Reset j to 0.
  6. While cur is less than n, increment j by 1 and add j to cur.
  7. Return the sum of i and j as the final result.
UML Thumbnail

Cumulative Sum and Binary Search

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...