FastPrepReferral Credits After a First Song

Referral Credits After a First Song

Suno logoSuno● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Each referral row [referrer, referredUser] records an invitation. If a user appears as the referred user more than once, only their earliest row is valid. Process creators in order; the first time a referred user creates a song, they receive 100 credits and their valid referrer receives 100 credits.

A referrer can receive credits for at most three referred users, while a referred user's own 100-credit award is unaffected by that cap. Later songs by the same user award nothing. Return [userId, credits] rows for users with positive credits, sorted by user ID.

Function

referralSongCredits(referrals: int[][], creators: int[]) → int[][]

Examples

Example 1

referrals = [[1,2],[1,3],[2,3],[2,5],[3,9]]creators = [2,2,4,2,3,5,8]return = [[1,200],[2,200],[3,100],[5,100]]

Only the first invitation for user 3 is valid; first songs by users 2, 3, and 5 produce the shown balances.

Example 2

referrals = [[10,20]]creators = [20,20]return = [[10,100],[20,100]]

The repeated song event does not issue a second award.

Constraints

  • 0 <= referrals.length, creators.length <= 100000
  • User IDs are positive integers.

More Suno problems

See Suno hiring insights
public int[][] referralSongCredits(int[][] referrals, int[] creators) {
  // Write your code here.
}
referrals[[1,2],[1,3],[2,3],[2,5],[3,9]]
creators[2,2,4,2,3,5,8]
expected[[1,200],[2,200],[3,100],[5,100]]
Checking account…