FastPrepGenerate Fixed-Size Combinations
Problems/Generate Fixed-Size Combinations

Generate Fixed-Size Combinations

Microsoft logoMicrosoft● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This exercise comes from a reported onsite prompt to print combinations after the candidate first generated permutations. We chose the range of numbers, the fixed size, alphabetical order and the limits to make the backtracking task something you can run. Our version is about 76% the same as the reported question.

Given integers n and k, return every combination of k distinct values chosen from 1 through n.

List values inside each combination in increasing order, and return the combinations in lexicographic order. A combination differs from a permutation: changing only the order of the same chosen values does not create a new result.

Function

combinations(n: int, k: int) → int[][]

Examples

Example 1

n = 4k = 2return = [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]

Each unordered pair appears once in lexicographic order.

Example 2

n = 5k = 5return = [[1,2,3,4,5]]

Choosing all available values produces one combination.

Constraints

  • 1 <= n <= 20.
  • 1 <= k <= n.
  • The number of returned combinations does not exceed 10000.

Source note: The source image is a source-neutral excerpt of the author-reported prompt.

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Count Complete Tic-Tac-Toe GamesDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
  • Phone Keypad Letter CombinationsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Generate Circular Student ArrangementsAmazon · ONSITE INTERVIEW
  • Inventory Outfit CombinationsRoblox · ONSITE INTERVIEWRoblox interview questions
  • All Subsequences with Sum KExpedia · ONSITE INTERVIEWExpedia interview questions
  • Enumerate Grid PathsMotive · ONSITE INTERVIEWMotive interview questions
  • Permutations of Character PositionsPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
  • Partition into Equal-Sum GroupsPalo Alto Networks · ONSITE INTERVIEWPalo Alto Networks interview questions
  • Binary Tree Target-Sum PathsByteDance · PHONE SCREENByteDance interview questions
  • Permutations IILinkedIn · PHONE SCREENLinkedIn interview questions

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[][] combinations(int n, int k) {
      // Write your code here.
    }
}
Checking account…