Raft commit index from matchIndex
Your task
In Raft, the leader advances its commit index using replication progress and the term-safety rule. You are given the number of servers n (the leader plus followers; the leader counts as having replicated everything), match_index: a list of length n giving the highest log index known replicated on each server (the leader's own entry equals its last log index), log_terms: a list where log_terms[i] is the term of log entry at 1-based index i+1 (so log_terms has length = leader's last log index), and current_term. Return the highest log index idx (1-based) such that a MAJORITY of servers have match_index >= idx AND log_terms[idx-1] == current_term. If no such index exists, return 0. This is the rule that prevents committing entries from prior terms by counting alone.
Examples
raft_commit_index(n: int, match_index: list[int], log_terms: list[int], current_term: int) -> intraft_commit_index(3, [3, 3, 2], [1, 2, 2], 2)3