This is one of the interview question.
Given row on N house, each is marked either R or B and each house having some gems.
You have to collect gems from these house with some constraint: You can choose gems from any blue house but you have to choose even number of red house ( either from 2 Red houses or from 4 red houses)
Each time you take gem from one house, you will multiply gems received with gems currently, you have.
You have to choose continuous houses and maximise the product.
You have to return start point and end point of house (remember this should be continuous ).
I can think of O(N^2) solution but not better than that. So, can someone recommend a better algorithm.