Title: #1739 - Building Boxes - LeetCode JavaScript Solutions
Open Graph Title: #1739 - Building Boxes - LeetCode JavaScript Solutions
X Title: #1739 - Building Boxes - LeetCode JavaScript Solutions
Description: You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this ...
Open Graph Description: You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this ...
X Description: You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this ...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/building-boxes
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/building-boxes","name":"#1739 - Building Boxes - LeetCode JavaScript Solutions","description":"You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this ...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number} n\n * @return {number}\n */\nvar minimumBoxes = function(n) {\n if (n < 4) return n;\n\n let baseSize = 0;\n let totalBoxes = 0;\n const triangular = k => k * (k + 1) / 2;\n\n while (totalBoxes + triangular(baseSize + 1) <= n) {\n baseSize++;\n totalBoxes += triangular(baseSize);\n }\n\n const remaining = n - totalBoxes;\n let extraFloor = 0;\n\n while (triangular(extraFloor) < remaining) extraFloor++;\n\n return triangular(baseSize) + extraFloor;\n};","keywords":"LeetCode 1739, #1739 - Building Boxes, Hard, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/building-boxes |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/building-boxes/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/1739-building-boxes.js |
| Math | https://leetcodejavascript.com/tags/math |
| Greedy | https://leetcodejavascript.com/tags/greedy |
| Binary Search | https://leetcodejavascript.com/tags/binary-search |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow