We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Precompute the odd and even sized subsequences and put it into two arrays named odd and even.( O(N*2^N+2^N))~ O(N*2^N)
Now go through D queries and in each instance add the odd values and subtract the even value from variable TOTAL as per the range mentioned . (O(M*2^N))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Mehta and the Typical Supermarket
You are viewing a single comment's thread. Return to all comments →
can be done in O(N*2^N + M*2^N)~ O(M*2^N)
Precompute the odd and even sized subsequences and put it into two arrays named odd and even.( O(N*2^N+2^N))~ O(N*2^N)
Now go through D queries and in each instance add the odd values and subtract the even value from variable TOTAL as per the range mentioned . (O(M*2^N))