Next Lexicographic Build Configuration From a Digit Array

Last updated: November 29, 2026

Quick Overview

A build configuration is encoded as an array of digits. Rearrange it in place into the next lexicographically greater permutation; if it is already the largest, rearrange it into the smallest (sorted ascending).

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


A build configuration is encoded as an array of digits. Rearrange it in place into the next lexicographically greater permutation; if it is already the largest, rearrange it into the smallest (sorted ascending).

Asked in Google onsites to test careful array manipulation, framed as enumerating test configurations in order for a CI matrix. The interviewer looks for the pivot, swap, reverse algorithm with a crisp explanation of why the suffix is non-increasing.

What the Interviewer Expects
  • Finds the rightmost index i with a[i] < a[i+1]
  • Finds the rightmost element in the suffix greater than a[i] and swaps
  • Reverses the suffix to make it smallest
  • Handles the fully descending case by reversing everything
  • Explains correctness with the non-increasing suffix invariant
Key Topics to Cover
Permutations
Two Pointers
In-Place Reversal
Arrays
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Generate the previous permutation instead.
  • Return the k-th permutation directly without iterating.
  • How does duplicate digits affect correctness?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list a of digits (duplicates allowed).
  • Output: a modified in place into the next greater permutation, or the ascending order if none exists.
  • O(1) extra space....
High-Level Design

Scan from the right to find the first index i where a[i] < a[i+1]. Everything to the right of i is non-increasing, so that suffix is already its largest arrangement; to get the next permutation ...


Submit Your Answer
Markdown supported