FastPrepCount Permutations Without Three Equal Parities in a Row
Problems/Count Permutations Without Three Equal Parities in a Row

Count Permutations Without Three Equal Parities in a Row

Google logoGoogle● HardINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand review of a Google SWE internship in 2026 describes this parity-permutation counting problem from a 60-minute online assessment. We rebuilt that input values are distinct, the input limits, and the function signature. Our version is about 94% the same as the reported question.

You are given an array nums of pairwise distinct integers.

Return the number of permutations of all elements in which no three consecutive values are all even and no three consecutive values are all odd. Return the answer modulo 1000000007.

Function

countParitySafePermutations(nums: int[]) → int

Examples

Example 1

nums = [1,2]return = 2

Both permutations are valid.

Example 2

nums = [1,3,5,2]return = 12

The single even value can occupy either middle position. For each valid parity pattern, the three odd values can be arranged in 3! ways.

Example 3

nums = [1,3,5]return = 0

Every permutation has three consecutive odd values.

Constraints

  • 1 <= nums.length <= 500.
  • -1000000000 <= nums[i] <= 1000000000.
  • All values in nums are distinct.

More Google Online Assessment questions

  • Minimum Operations to Make a SubsequenceOA · Seen Nov 2026
  • Book Reading EveningsOA · Seen Nov 2026
  • Count Score CategoriesOA · Seen Nov 2026
  • Minimum Cars for Rental RequestsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Shortest Path in a Binary MatrixOA · Seen Nov 2026
  • Robot Assembly Line ConflictsOA · Seen Oct 2026
  • Assign LockerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Biggest Number From DigitsOA · Seen Oct 2026
  • Consolidate On-Call RotationsOA · PHONE SCREEN · Seen Oct 2026
  • Decreasing SubsequencesOA · Seen Sep 2026

Similar questions at other companies

  • At Most K Jumps with Quadratic Transition CostInfosys · OA
  • Optimize Discount Selection Under a Point BudgetPalantir · OA
  • Count Nondecreasing Digit-Sum ArraysMicrosoft · OA
  • Pressure-Isolation Shutdown OrderIntuit · OA
  • Stable Workload Redistribution TreesTower Research Capital · OA
  • Jump Game with Prime-3 StepsUber · OA
  • Count Good SubsequencesFlexport · OA
  • Sum of Compressed Number for All SubarraysWells Fargo · OA
  • Count Perfect BreaksAtlassian · OA
  • Enough Muffins for the LineSusquehanna International Group (SIG) · OA
See Google hiring insights
Saved
class Solution {
    public int countParitySafePermutations(int[] nums) {
        // Write your code here.
    }
}
Checking account…