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 :
- Declare an array of size ‘n’ and store Li * Ri for all the movies.
- 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'.
- Here if we fetch values from 'R' using the indexes from the list {0 2}, we'll get {2 1}
- 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.