Mar. 25th, 2020

juan_gandhi: (Default)
object model {
  type MovieId = Long
  type UserId  = Long
  case class View(userId: UserId, movieId: MovieId)
}
import model._

object Solution extends App {
  def diverseMovies(views: Seq[View], numMovie: Int): Set[MovieId] = {
    def choose(except: Set[UserId] = Set.empty): MovieId = {
      views.collect { case view if !except(view.userId) => view }.
            groupBy(_.movieId).mapValues(_.size).maxBy(_._2)._1
    }
    
    def viewersOf(movie: MovieId) =
      views.filter(_.movieId equals movie).map(_.userId).toSet
    
    val result: (List[MovieId], Set[UserId]) =
      ((List.empty[MovieId], Set.empty[UserId])/:(1 to numMovie)) ({
        case ((movies: List[MovieId], ignoredUsers: Set[MovieId]), _) => {
          val movie = choose(ignoredUsers)
          (movie::movies, ignoredUsers ++ viewersOf(movie))
        }
      })
    result._1.toSet
      
  }
}
juan_gandhi: (Default)
"Approximately one half of the patients at Kaiser Permanente’s San Jose hospital are confirmed or suspected cases of the new coronavirus according to a Los Angeles Times report." https://www.msn.com/en-us/news/us/coronavirus-slams-south-bay-kaiser-hospital-report/ar-BB11IeuF?ocid=hplocalnews 

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

June 2025

S M T W T F S
1 2345 6 7
8 9 10 11 121314
15161718 1920 21
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 28th, 2025 11:13 am
Powered by Dreamwidth Studios