PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Bytedance
  • Coding & Algorithms
  • Site Reliability Engineer

Generate combinations and permutations

Company: Bytedance

Role: Site Reliability Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given two integers n and k, where 1 <= k <= n, write code for two related tasks using the numbers 1 through n: 1. Generate all unique combinations of size k. 2. Generate all unique ordered arrangements of length k using distinct numbers. A number may not be reused within the same result, and the output must not contain duplicate sequences. Explain the approach and analyze the time and space complexity.

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

Return all size-k combinations from numbers 1..n in lexicographic order.

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

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.

Generate Length-K Permutations

Return all ordered length-k arrangements from numbers 1..n without reuse.

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

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Elements Occurring More Than n/3 Times in a Sorted Array - Bytedance (medium)
  • Least Frequently Used (LFU) Cache - Bytedance (hard)
  • Course Schedule Feasibility - Bytedance (hard)
  • Find the Best Word for a Query Suffix - Bytedance (hard)
  • Reverse a Singly Linked List - Bytedance (medium)