Most Popular Actor by Movie Views
Problem statement
Each string in movieViews has the form movieId views. Each string in credits has the form movieId personId role.
For each person credited as an exact actor, sum the views of the distinct movies in which that person has an actor credit. Other roles do not contribute. If a movie-person actor credit is repeated, count that movie once for that person.
Return the person ID with the greatest total. Break ties by the lexicographically smallest person ID. Return the empty string when there is no actor credit for a listed movie.
Function
mostPopularActor(movieViews: String[], credits: String[]) → StringExamples
Example 1
movieViews = ["m1 100","m2 60"]credits = ["m1 p1 actor","m1 p1 director","m2 p2 actor"]return = "p1"Only actor roles count, so p1 receives 100 views and p2 receives 60.
Example 2
movieViews = ["m1 40","m2 40"]credits = ["m1 zoe actor","m2 amy actor"]return = "amy"The totals tie, so the lexicographically smaller person ID wins.
Example 3
movieViews = ["m1 10"]credits = ["m1 p1 director"]return = ""No actor credit is present.
Constraints
0 <= movieViews.length, credits.length <= 2 * 10^5.- Identifiers and roles are nonempty ASCII tokens without spaces.
- Movie IDs in
movieViewsare unique and each view count is between 0 and 10^12.