Count Permutations Without Three Equal Parities in a Row
Updated
Problem statement
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[]) → intExamples
Example 1
nums = [1,2]return = 2Both permutations are valid.
Example 2
nums = [1,3,5,2]return = 12The 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 = 0Every permutation has three consecutive odd values.
Constraints
1 <= nums.length <= 500.-1000000000 <= nums[i] <= 1000000000.- All values in
numsare 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