The Find Permutation interview question involves reconstructing a permutation of based on a signature string of 'I' (Increase) and 'D' (Decrease). For example, if the string is "ID", you need a permutation of [1, 2, 3] such that the first move is an increase and the second is a decrease. You want to return the lexicographically smallest such permutation.
Google asks the Find Permutation coding problem to test a candidate's ability to use Stack or Greedy logic to handle relative order constraints. It evaluations if you can identify that a sequence of 'D's represents a reversed segment of numbers. It’s a great test of pattern recognition within Array interview patterns.
This problem is best solved using a Stack or Reversing Subarrays.
[1, 2, ... n].Signature: "ID" (Permutation of 1, 2, 3)
[1].3, 2.
Result: [1, 3, 2].
Check: 1 to 3 (Increase), 3 to 2 (Decrease). Smallest possible.Sequences of "Decrease" requirements often imply a Reversal. If you need to stay as small as possible while going down, you should pick the smallest available set of numbers and flip them.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Delete Columns to Make Sorted II | Medium | Solve | |
| Check if a Parentheses String Can Be Valid | Medium | Solve | |
| Minimum Insertions to Balance a Parentheses String | Medium | Solve | |
| Maximum Score From Removing Substrings | Medium | Solve | |
| Minimum Add to Make Parentheses Valid | Medium | Solve |