SpinalHDL
1 / 1
View past submissionsLeaderboard

Description

Countdown

Design a hardware module for the Countdown problem.

Given an array a and a target length k, count how many contiguous subarrays are exactly the sequence k, k - 1, ..., 1.

Hardware I/O Encoding

  • a is a one-dimensional input stream of unsigned 32-bit integers
  • the stream length is at most 50
  • k is a scalar unsigned 32-bit integer input
  • the output is one unsigned 32-bit integer
  • the output value is the number of countdown sequences of length k

Examples

Example 1

  • input a = [7, 4, 3, 2, 1, 4, 3, 2, 1], k = 4
  • output: 2

The subarray [4, 3, 2, 1] appears twice.

Example 2

  • input a = [9, 8, 7, 6, 5, 4, 3, 2, 1], k = 9
  • output: 1

The whole array is one countdown.

Example 3

  • input a = [1, 2, 3, 4], k = 2
  • output: 0

No subarray matches [2, 1].

Source: Google Kick Start 2020 Round C - Countdown

Input

a

Stream of 32-bit Unsigned Integer (up to 50 elements)
Input array of countdown values.

k

32-bit Unsigned Integer
Required countdown length.

Output

32-bit Unsigned Integer
Number of contiguous countdown sequences of length k.