UVM scoreboard interview question

Hi everyone, I’m currently interviewing for DV role at entry level and I was asked below question in one of my interview. I dont have much experience in writing SB so I could not answer the question.

Suppose we have a stream of data bits coming in with START bit and END bit. You need to write a logic to find max value of sum of 3 bits from the stream.

For example: start_bit-> 1-1-2-2-3-3-4-1->end
sum of 1st 3 bits = 1+1+2=4.
then it will move to next position so next sum of 3 bits,
2nd sum = 1+2+2 = 5
3rd sum = 2+2+3=7.
4th sum = 2+3+3 = 8
5th sum = 3+3+4 = 10
6th sum= 3+4+1 = 8
So the max will be 10.

Write a SB run_phase logic for this condition.

Can anyone please guide me how to solve/answer this question?

One way to do that can be -

class my_scb extends uvm_scoreboard;
  `uvm_component_utils(my_scb)
  
  uvm_analysis_imp(my_txn, my_scb) imp_mon;
  bit start_detect;
  bit end_detect;
  local mailbox (my_txn) mbx;
  int data_q [$];
  
  function new(string name = "my_scb", uvm_component parent);
    super.new(name, parent);
    imp_mon = new("imp_mon",this);
    mbx = new();
  endfunction'
  
  function void write(my_txn txn);
    mbx.put(txn);
  endfunction
  
  task run_phase(uvm_phase phase);
    my_txn txn;
    phase.raise_objection(this);
    forever 
      begin
        mbx.get(txn);
        if(txn.start)
          begin
            start_detect = 1;
            data_q.delete();
          end
        if(txn.done)
          begin
            if(start_detect)
              begin
                start_detect =0;
            	end_detect = 1;      
            	max_sum(data_q);
              end
          end
        else if(start_detect)
          begin
            data_q.push_back(txn.data);
          end
      end
    phase.drop_objection(this);
  endtask
  
  function void max_sum(int data_q[$]);
    bit [123:0] max_val;
    bit [123:0] tem_val;
    if(data_q.size() < 3) begin
      `uvm_error("FAIL SUM","not enough data to calculate sum")
    end
    
    else begin 
      for (int i = 0; i <= data_q.size() - 3; i++) begin
        tem_val = data_q[i] + data_q[i+1] + data_q[i+1];
        if(tem_val > max_val) begin
          max_val = tem_val;
        end
  endfunction
endclass

@whizclips
I believe you would run into Tb Timeout issue due to never dropping objection

task run_phase(uvm_phase phase);
    my_txn txn;
    
    forever 
      begin
        mbx.get(txn);
        phase.raise_objection(this); // Raise objection only on fetching a transaction
        if(txn.start)
          begin
            start_detect = 1;
            data_q.delete();
          end
        if(txn.done)
          begin
            if(start_detect)
              begin
                start_detect =0;
            	end_detect = 1;      
            	max_sum(data_q);
              end
          end
        else if(start_detect)
          begin
            data_q.push_back(txn.data);
          end
         phase.drop_objection(this); // Drop objection post processing the fetched transaction
      end
  endtask

Correct! Thanks for the correction