Skip to the code
cf.
+10 XP

#172 Largest Square Tile

easy

An image gallery wants to arrange count thumbnails in the largest full square grid it can: a side × side grid with every cell filled. Extra thumbnails are shown on a second screen.

Write squareSide(count) that returns the largest whole number side with side * side <= count.

Don't use Math.sqrt: search for the answer.

Example 1

Input: count = 10
Output: 3

A 3 by 3 grid uses 9 thumbnails. 4 by 4 would need 16.

Example 2

Input: count = 16
Output: 4

16 thumbnails fill a 4 by 4 grid exactly.

Constraints

  • 0 <= count <= 2^31 - 1
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).