← All problems

Second Largest

Easy · Sequential · SystemVerilog · VHDL

Design a module that tracks the second-largest of a sequence of unsigned values.

Each cycle without a reset, din is the next value of the sequence. dout is the second-largest value of the sequence so far, counting a repeated value once per appearance (after 9, 9 it is 9), and 0 while the sequence has fewer than two values. dout is registered: it covers the values up to the cycle before.

resetn is a synchronous, active-low reset that empties the sequence.

Open this challenge in the editor →