Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Looping and Max in Lists

MediumPython00:00
Practice interviewer
In session
5 left
00:00

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.

You need to log in / sign up to run or submit.

Problem

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.

Formal Specification

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].

Constraints

  • 1 <= len(scores) <= 10^4
  • 1 <= len(scores[i]) <= 10^4
  • 1 <= total number of scores <= 10^5
  • 0 <= scores[i][j] <= 10^9
  • 0 <= seed <= 10^9

Function Signature

def rank_affirm_offers(scores, seed):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output