K37

Combinations of Size K

Junior Level Candidate
Target Time: 15 - 20 Minutes
Type: ARRAY

Problem Statement & Objective

Given two integers n and k, return all possible combinations of k numbers chosen from the range [1, n].

Function Signature (Python)

combine(n: int, k: int) -> list[list[int]]

Input & Output Contract

Output Rule:k elemanlı kombinasyonların listesi.

System Constraints

1 <= n <= 20
1 <= k <= n

Example Execution Walkthrough

n = 4, k = 2 -> [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]

Example Test Scenarios (3)

Example 1
Input:[4,2]
Expected Output:[[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
Example 2: n=1, k=1
Input:[1,1]
Expected Output:[[1]]
Example 3: n=k
Input:[3,3]
Expected Output:[[1,2,3]]
Loading Python Editor...
Input Parameters
[
  4,
  2
]
Expected Output
[
  [
    1,
    2
  ],
  [
    1,
    3
  ],
  [
    1,
    4
  ],
  [
    2,
    3
  ],
  [
    2,
    4
  ],
  [
    3,
    4
  ]
]