Need help to findout a testcase that fails for my approach for the problem MOVIEWKN.

Hi.
I was trying to solve the problem Movie Weekend_MOVIEWKN with the below mentioned approach but for some reason, it shows WA. If anyone can provide a corner-case, it will be appreciated.

Steps :

  1. Declare an array of size ‘n’ and store Li * Ri for all the movies.
  2. Find max in above array and store the corresponding indexes (if multiple) in a list.
    Here by corresponding index I mean, say L = {2 1 4 1} and R = {2 2 1 2} then L*R = {4 2 4 2}. So I'm storing 0 and 2 as indexes as they correspond to the movie with max (Li * Ri) with similar indexes pointing to the same movie in array 'R'.
4. Now get the corresponding values from array 'R' having the index values from the list and we'll get the Ratings of the max(Rating * Length) movie(s).
    Here if we fetch values from 'R' using the indexes from the list {0 2}, we'll get {2 1}
6. Finally find the max value in this new array and return the index of the very first occurrence as a 1-based array.
    So in this case, that will be 1 and the very first occurrence is returned as it will have the minimum index value.

So that’s it for my approach. The code is given here[JAVA].
Thanks in advance.

1 Like

For this case your code gives movie 1 instead of movie 5:

6
2 1 4 1 2 3
2 4 1 4 6 4
1 Like

Good presentation of your method, with links to code and problem. Great example of how to ask this sort of question. +1.

Oh…i see. Thanks a lot.