All practice tasks

Coding (Algo)

Count Distinct Batch Orderings

Combinatorics · Medium

A scheduler estimates how many different value sequences can be formed from a small batch. All entries must appear, but equal values are indistinguishable in the output sequence. Enumerating every index permutation would overcount duplicates and waste time.

Count distinct value orderings that use every input occurrence exactly once.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ nums: integer[] }

Fields

  • nums is an array of signed integer labels. Repeated labels must retain their multiplicities.

Output

Return value

  • Return the number of distinct value sequences, not index permutations or the sequences themselves.
  • The empty batch has one empty ordering. If all values are equal, return one.

Constraints

  • 0 <= nums.length <= 18; -1000000000 <= nums[i] <= 1000000000.
  • The final answer is exact and at most 18!, within a safe JSON integer. Use integer arithmetic when dividing factorials.

Examples

Example 1

{
  "nums": [
    1,
    1,
    2
  ]
}

Returns

3

Example 2

{
  "nums": [
    4,
    4,
    4
  ]
}

Returns

1

Required complexity

O(n) frequency updates and factorial operations with O(n) auxiliary space

What this task practices

Count Distinct Batch Orderings is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.