Skip to content
DeepForgeby svx
All problems
EasyData Structuresds-318

Sqrt Decomposition Bucket Layout

Problem

Split n elements into blocks of size b = max(1, isqrt(n)) for square-root decomposition. The number of blocks is ceil(n / b) and the last block holds n - (count - 1) * b elements. Return [b, block_count, last_block_size], or [0, 0, 0] when n is 0.

Hint

math.isqrt gives the exact integer square root without floating-point rounding.

Test cases

case 1
in: [10]
expected: [3,4,1]
case 2
in: [16]
expected: [4,4,4]
case 3
in: [1]
expected: [1,1,1]
case 4
in: [0]
expected: [0,0,0]
Starter codePython
def sqrt_bucket_layout(n):
    # Your code here
    pass

4 test cases · run your code against them in the editor