**Objective: **Given two integers N and K, Write an algorithm to find subsets of size K from the numbers 1 to N.

**Example:**

N = 5 K = 3 Output: [1, 2, 3] [1, 2, 4] [1, 2, 5] [1, 3, 4] [1, 3, 5] [1, 4, 5] [2, 3, 4] [2, 3, 5] [2, 4, 5] [3, 4, 5] N = 6 K = 5 Output: [1, 2, 3, 4, 5] [1, 2, 3, 4, 6] [1, 2, 3, 5, 6] [1, 2, 4, 5, 6] [1, 3, 4, 5, 6] [2, 3, 4, 5, 6]

**Approach: Use Recursion**

- Given
and subset size*N*.*K* - Start with
= 0,*startNumber*=null*combinationList* - Iterate through
=*i*to*startNumber*.*N*- Put
to*i**combinationList.* - Make a recursive call with
,*startNumber=i+1*and (to process next elements) and*K=K-1**combinationList.* - In tail recursion, backtrack and remove
from the*i*to find more solutions*combinationList* - Base case: if
*K=0*.*combinationList*

- Put

**Complete Code:**

**Output:**

Given Number: 6, subset size K: 5 [1, 2, 3, 4, 5] [1, 2, 3, 4, 6] [1, 2, 3, 5, 6] [1, 2, 4, 5, 6] [1, 3, 4, 5, 6] [2, 3, 4, 5, 6]