Generate combinations and permutations
Company: Bytedance
Role: Site Reliability Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's ability to implement combinatorial generation of combinations and permutations using distinct elements, testing understanding of combinatorics, search-space enumeration, and uniqueness constraints within the Coding & Algorithms domain.
Generate Combinations
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: (4,2)
Expected Output: [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
Explanation: All 2-combinations from 1..4.
Input: (3,3)
Expected Output: [[1, 2, 3]]
Explanation: Only one full-size combination.
Hints
- Clarify edge cases before coding.
- Keep the return value deterministic.
Generate Length-K Permutations
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: (3,2)
Expected Output: [[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]]
Explanation: All length-2 permutations from 1..3.
Input: (2,2)
Expected Output: [[1, 2], [2, 1]]
Explanation: Both full permutations.
Hints
- Clarify edge cases before coding.
- Keep the return value deterministic.