Description

Number of Inversions in Sliding Window

Design a hardware module that processes a stream of integers with a sliding window of size k. For each window, count the number of inversions where an inversion is a pair of indices (i, j) such that i < j but nums[i] > nums[j] within the window. Output the inversion count for each complete window as the stream progresses.

Example: For k=3 and stream [3, 1, 2, 4], the windows are [3, 1, 2] with 2 inversions and [1, 2, 4] with 0 inversions.

Source: Original problem (inspired by inversion counting algorithms)

Input

k

4-bit Unsigned Integer
Sliding window size (1-15).

nums

Stream of 32-bit Signed Integer
Stream of signed integers.

Output

Stream of 8-bit Unsigned Integer
Inversion count per window.