← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
May 2026

Summary

Google SWE interview focused on permutations. Not much to go on but it was a coding round and the topic was classic algorithmic territory.

Questions Asked (1)

Q1

Generate all permutations of a given array or string.

Algorithms & Data Structures
Author's notes

Permutations is one of those problems where you either know the recursive backtracking pattern cold or you're drawing blanks on a whiteboard.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: whether the input has duplicates, whether the output should be unique permutations, and whether to return a list or print. Then explain a backtracking approach that builds permutations by swapping elements in-place, and analyze time and space complexity. If duplicates are possible, mention how to handle them (e.g., using a set or sorting and skipping duplicates).

Pro tip: At Google, interviewers value clean, bug-free code and strong communication. Before coding, walk through a small example (e.g., [1,2,3]) to demonstrate your thought process, and after coding, test edge cases like empty input, single element, and duplicates.

1. Clarify requirements

Ask about input size, duplicates, output format, and whether permutations should be unique. This shows attention to detail and avoids incorrect assumptions.

2. Choose an approach

Decide between backtracking with swapping, backtracking with a used array, or iterative generation. For interviews, swapping is often preferred for its simplicity and O(1) extra space (excluding recursion stack).

3. Explain the algorithm

Describe how you'll recursively fix each position by swapping the current index with each subsequent index, then recurse. Base case: when the current index reaches the end, add the permutation to the result.

4. Handle duplicates (if applicable)

If duplicates exist, either use a set to store results or sort the array and skip swapping when the same element has already been placed at the current position.

5. Analyze complexity and test

State time complexity O(n * n!) and space O(n) for recursion (plus output). Walk through a small example and test edge cases like empty input, single element, and duplicates.

Key Points to Mention

  • Backtracking algorithm with swapping to generate permutations in-place.
  • Time complexity: O(n * n!) because there are n! permutations and each takes O(n) to copy.
  • Space complexity: O(n) for recursion stack, excluding output storage.
  • Handling duplicates: using a set or sorting and skipping duplicates to avoid repeated permutations.
  • Edge cases: empty array, single element, and arrays with duplicate values.
  • Alternative approaches: backtracking with a used boolean array, or iterative generation using next permutation.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.