Your question is Looping and Max in Lists. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Affirm's offer-ranking experiments group candidate offer scores into rows. Implement a deterministic simulation that adds pseudo-random noise to every score, finds the strongest offer in each row, and returns the strongest offer overall.
Use this generator for each score, in row-major order:
state = (state * 17 + 43) % 1000
The generated noise is state % 10. For each original score, define adjusted_score = score + noise. For every row, find its maximum adjusted score. Return the row index, column index, adjusted score, and bucket of the overall maximum. The bucket is (adjusted_score % 100) // 10. If multiple offers have the same adjusted score, return the one with the smallest row index, then the smallest column index.
Implement rank_affirm_offers(scores, seed), where scores is a nonempty list of nonempty lists of nonnegative integers, and seed is a nonnegative integer. Return a four-element list: [row_index, column_index, adjusted_score, bucket].
def rank_affirm_offers(scores, seed):