Maximize the number of TV shows that can be watched


  • 1
    P

    Given a TV show guide which is a list of start and end times for each TV show being aired on a given day, return the list which has the maximize shows that can be watched without conflicts.


  • 0
    J

    @Pooja71 Scheduling problem, did you get offer? If they do, I bet they will give you option to join Alexa :P


  • 0
    P

    @JustVirtually Hi, unfortunately they felt I was better suited for a SDE1 position but did not have requirement for the same. So my profile is on hold. Thanks for asking :)


  • 0
    R

    @Pooja71 Wouldn't a greedy algorithm work for this instance?


  • 0
    J

    @rhuang97 Yes, Greedy solution will be always there for every problem. I think for the interview, DP solution is expected (to reduce the time complexity).


  • 0
    P

    @JustVirtually Can you elaborate a little more about your greedy solution?


  • 0
    T

    Correct me in below code that how to add show result to "res" list, Thanks.
    '''
    public List<List<int>> TVShows(List<List<int>> shows)
    {
    List<List<int>> res = new List<List<int>>();
    for (int i = 0; i < shows.Count; i++)
    {
    DP(shows, i, res);
    }
    return res;
    }

        private static List<List<int>> DP(List<List<int>> shows, int show, List<List<int>> res)
        {
    
            for (int i = show; i < shows.Count; i++)
            {
                if (i < shows.Count - 1 && shows[i][1] <= shows[i + 1][0])
                {
                    DP(shows, i + 1, res);
                }
                else if(i == shows.Count)
                {
                    res.Add(shows[i]);
                }
            }
    
            return res;
        }
    

    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.