Minimize the Number of Perfect Squares Summing to an Integer

Quick Overview

Minimize the Number of Perfect Squares Summing to an Integer. Return the fewest positive perfect-square summands whose sum is n. Reusing the same square is allowed.

Minimize the Number of Perfect Squares Summing to an Integer

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Return the fewest positive perfect-square summands whose sum is n. Reusing the same square is allowed. ```cpp int numSquares(int n); ``` ### Examples ```text n = 18 -> 2 n = 1 -> 1 ``` ### Constraints - 1 <= n <= 10000.

Overview: Minimize the Number of Perfect Squares Summing to an Integer. Return the fewest positive perfect-square summands whose sum is n. Reusing the same square is allowed.

Meta logo
Meta
Date not reported
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return the fewest positive perfect-square summands whose sum is n. Reusing the same square is allowed.

int numSquares(int n);

Examples

n = 18 -> 2
n = 1 -> 1

Constraints

  • 1 <= n <= 10000.