`{"id":"b4f788ef-25f4-44e0-8b0c-e4178407388c","name":"K-partitions","description":"1. You are given two integers n and k, where n represents number of elements and k represents \r\n number of subsets.\r\n2. You have to partition n elements in k subsets and print all such configurations.\r\n\r\nNote -> Check out the question video and write the recursive code as it is intended without \r\n changing signature. The judge can't force you but intends you to teach a concept.","inputFormat":"A number n\r\nA number k","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= n &lt;= 10\r\n1 &lt;= k &lt;= 10","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void solution(int i, int n, int k, int rssf, ArrayList<ArrayList<Integer>> ans) {\r\n\t\t//write your code here\r\n\t\t\r\n\t}\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\tint k = scn.nextInt();\r\n\t\tArrayList<ArrayList<Integer>> ans = new ArrayList<>();\r\n\t\tfor(int i = 0; i < k; i++) {\r\n\t\t\tans.add(new ArrayList<>());\r\n\t\t}\r\n\t\tsolution(1, n, k, 0, ans);\r\n\r\n\t}\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\n2","sampleOutput":"1. [1, 2] [3] \r\n2. [1, 3] [2] \r\n3. [1] [2, 3] \r\n","questionVideo":"https://www.youtube.com/embed/TvvGj1FtHIk?end=170","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":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"a405e351-b799-46b7-a2e8-ded76ed93074","name":"K-partitions","slug":"k-partitions","type":1}],"next":{"id":"9b11fb43-ae7b-4192-a64a-c89e9ad7b62f","name":"k-Partitions MCQ","type":0,"slug":"k-partitions-mcq"},"prev":{"id":"d05856db-a2fe-40f4-8ec0-9854fc499074","name":"Friends Pairing-2 MCQ","type":0,"slug":"friends-pairing-2-mcq"}}}`

# K-partitions

1. You are given two integers n and k, where n represents number of elements and k represents number of subsets. 2. You have to partition n elements in k subsets and print all such configurations. Note -> Check out the question video and write the recursive code as it is intended without changing signature. The judge can't force you but intends you to teach a concept.

`{"id":"b4f788ef-25f4-44e0-8b0c-e4178407388c","name":"K-partitions","description":"1. You are given two integers n and k, where n represents number of elements and k represents \r\n number of subsets.\r\n2. You have to partition n elements in k subsets and print all such configurations.\r\n\r\nNote -> Check out the question video and write the recursive code as it is intended without \r\n changing signature. The judge can't force you but intends you to teach a concept.","inputFormat":"A number n\r\nA number k","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= n &lt;= 10\r\n1 &lt;= k &lt;= 10","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void solution(int i, int n, int k, int rssf, ArrayList<ArrayList<Integer>> ans) {\r\n\t\t//write your code here\r\n\t\t\r\n\t}\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\tint k = scn.nextInt();\r\n\t\tArrayList<ArrayList<Integer>> ans = new ArrayList<>();\r\n\t\tfor(int i = 0; i < k; i++) {\r\n\t\t\tans.add(new ArrayList<>());\r\n\t\t}\r\n\t\tsolution(1, n, k, 0, ans);\r\n\r\n\t}\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\n2","sampleOutput":"1. [1, 2] [3] \r\n2. [1, 3] [2] \r\n3. [1] [2, 3] \r\n","questionVideo":"https://www.youtube.com/embed/TvvGj1FtHIk?end=170","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":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"a405e351-b799-46b7-a2e8-ded76ed93074","name":"K-partitions","slug":"k-partitions","type":1}],"next":{"id":"9b11fb43-ae7b-4192-a64a-c89e9ad7b62f","name":"k-Partitions MCQ","type":0,"slug":"k-partitions-mcq"},"prev":{"id":"d05856db-a2fe-40f4-8ec0-9854fc499074","name":"Friends Pairing-2 MCQ","type":0,"slug":"friends-pairing-2-mcq"}}}`

Editor

# K-partitions

easy

1. You are given two integers n and k, where n represents number of elements and k represents number of subsets. 2. You have to partition n elements in k subsets and print all such configurations. Note -> Check out the question video and write the recursive code as it is intended without changing signature. The judge can't force you but intends you to teach a concept.

## Constraints

1 <= n <= 10 1 <= k <= 10

## Format

### Input

A number n A number k

### Output

Check the sample ouput 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;}3 2```

### 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;}1. [1, 2] [3] 2. [1, 3] [2] 3. [1] [2, 3] ```

Question Video

Discussions

Show Discussion

Related Resources