FastPrepAlternating Parity Permutations
Problems/Alternating Parity Permutations

Alternating Parity Permutations

Goldman Sachs logoGoldman Sachs● MediumINTERNOA

Updated Jul 2026

QuestionFunctionExamples

Problem statement

An e-commerce company is writing a fuzzer to test a piece of its software. They need a list of numbers with alternating parity, that is, one of them is odd and the other one is even.

An alternating parity permutation is a permutation in which any two adjacent elements have different parity. For example, [1,2,3,4], [1], and [3,2,1] exhibit alternating parity, while [1,3,2] and [4,2,1,3] do not.

For a given integer n, return all alternating parity permutations of the first n positive integers in lexicographically ascending order. Each permutation contains n elements. For example, the first four permutations where n = 10 are:

1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 10 9 8
1 2 3 4 5 6 9 8 7 10
1 2 3 4 5 6 9 10 7 8

Function

alternatingParityPermutations(n: int) → int[][]

Examples

Example 1

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

The values of the array are from 1 to n. The following are alternating parity permutations of the first 4 positive integers, sorted. Any other permutation will result in adjacent elements sharing the same parity.

More Goldman Sachs Online Assessment questions

  • Design Hash MapOA · PHONE SCREEN · Seen Nov 2026
  • Maximum Ones After K OperationsOA · Seen Nov 2026
  • Palindrome CounterOA · Seen Oct 2026
  • Longest Palindromic SubsequenceOA · Seen Oct 2026
  • Count Redundant File BackupsOA · Seen Oct 2026
  • Minimum Distinct Prefix CostOA · Seen Oct 2026
  • Merge Overlapping IntervalsOA · Seen Sep 2026
  • Data ReorganizationOA · Seen Jul 2026
  • Threshold AlertsOA · Seen Jul 2026
  • Find the Winner of an Array GameOA · Seen Jun 2026

Similar questions at other companies

  • Count Legal Outfit CombinationsDuolingo · OADuolingo interview questions
  • Expand Attribute CombinationsPinterest · PHONE SCREENPinterest interview questions
  • Generate Circular Student ArrangementsAmazon · ONSITE INTERVIEW
  • Winning Draws for a Mahjong HandZip · PHONE SCREENZip interview questions
  • Inventory Outfit CombinationsRoblox · ONSITE INTERVIEWRoblox interview questions
  • Partition into Equal-Sum GroupsPalo Alto Networks · ONSITE INTERVIEWPalo Alto Networks interview questions
  • Count One-Swap Number PairsCapital One · OACapital One interview questions
  • Count Overlapping Square PairsRamp · OARamp interview questions
  • Find Valid SET Card TriplesSnowflake · OA · PHONE SCREENSnowflake interview questions
  • Two Tribes from Taller-Person CountsIntuit · OAIntuit interview questions
All Goldman Sachs interview questionsSee Goldman Sachs hiring insights
Saved
class Solution {
    public int[][] alternatingParityPermutations(int n) {
      // write your code here
    }
}
Checking account…