HackerRank: Find Maximum Index Product ( Stack, DS, Histogram Logic )
HackerRank: Find Maximum Index Product ( Stack, DS ) (Find me on HackerRank @ Handle: BishalG ) Problem Summary: According to problem, you are given an array A of length n . For each index - i in the array, calculate IndexProduct(i) which is defined as: IndexProduct(i) = Left(i) * Right(i). Again, Left(i) and Right(i) has following definition: Left(i) = Index on the left side of the array such that j < i and arr[j] > arr[i] Right(i) = Index on the right side of the array such that j > i and arr[j] > arr[i] If such index does not exist then it would be 0 in both cases. Our task is to find maximum of IndexProduct(i) among all values of i. Solution Idea: I'm explaining here the idea for generating values for Left array. Similar concept can be applied to find the values for Right array. After finding both arrays, we can easily calculate IndexProduct for every i and find the maximum value among them which will be our answer. Calculating Left array: If we think ...
Comments
Post a Comment