`{"id":"6de1f2e8-a937-49ea-94de-f8c4d9da1bce","name":"Min Squares","description":"1. You are given a number N.\r\n2. You have to find the minimum number of squares that sum to N.\r\n3. You can always represent a number as a sum of squares of other numbers.\r\n For eg -> In worst case N can be represented as (1*1) + (1*1) + (1*1)..... N times. ","inputFormat":"An integer N","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= N &lt;= 10^5","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(int n){\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tSystem.out.println(solution(n));\r\n\t}\r\n\r\n\r\n\t\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"35","sampleOutput":"3\r\n","questionVideo":"https://www.youtube.com/embed/aZuQXkO0-XA?end=80","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"c52c91e3-ae66-477e-8613-9ef1b8079660","name":"Min Squares","slug":"min-squares","type":1}],"next":{"id":"4025a4a7-4862-499d-aad3-7e38026e2928","name":"MIN SQUARES MCQ","type":0,"slug":"min-squares-mcq"},"prev":{"id":"ad952588-20d1-4d17-82b2-5ab453844aa6","name":"Boolean Parenthesization","type":3,"slug":"boolean-parenthesization"}}}`

# Min Squares

1. You are given a number N. 2. You have to find the minimum number of squares that sum to N. 3. You can always represent a number as a sum of squares of other numbers. For eg -> In worst case N can be represented as (1*1) + (1*1) + (1*1)..... N times.

`{"id":"6de1f2e8-a937-49ea-94de-f8c4d9da1bce","name":"Min Squares","description":"1. You are given a number N.\r\n2. You have to find the minimum number of squares that sum to N.\r\n3. You can always represent a number as a sum of squares of other numbers.\r\n For eg -> In worst case N can be represented as (1*1) + (1*1) + (1*1)..... N times. ","inputFormat":"An integer N","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= N &lt;= 10^5","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(int n){\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tSystem.out.println(solution(n));\r\n\t}\r\n\r\n\r\n\t\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"35","sampleOutput":"3\r\n","questionVideo":"https://www.youtube.com/embed/aZuQXkO0-XA?end=80","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"c52c91e3-ae66-477e-8613-9ef1b8079660","name":"Min Squares","slug":"min-squares","type":1}],"next":{"id":"4025a4a7-4862-499d-aad3-7e38026e2928","name":"MIN SQUARES MCQ","type":0,"slug":"min-squares-mcq"},"prev":{"id":"ad952588-20d1-4d17-82b2-5ab453844aa6","name":"Boolean Parenthesization","type":3,"slug":"boolean-parenthesization"}}}`

Editor

# Min Squares

easy

1. You are given a number N. 2. You have to find the minimum number of squares that sum to N. 3. You can always represent a number as a sum of squares of other numbers. For eg -> In worst case N can be represented as (1*1) + (1*1) + (1*1)..... N times.

1 <= N <= 10^5

## Format

An integer N

### Output

Check the sample output and question video.

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}35`

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}3 ```

Question Video

Discussions

Show Discussion

Related Resources