Answers to: HAPPYARR - Editorialhttps://discuss.codechef.com/questions/121133/happyarr-editorial<p><strong>Happy Array</strong> </p>
<p><strong>Problem :</strong> <br>
<a href="https://www.codechef.com/MENH2017/problems/HAPPYARR">practice</a> </p>
<p><strong>Tags: Dynamic Programming, Prefix sum.</strong></p>
<p><strong>Author: Shami.</strong><br>
<strong>Tester: Naman</strong></p>
<p>There are multiple ways to look at this problem. </p>
<p>1.<a href="https://en.wikipedia.org/wiki/Longest_increasing_subsequence">Longest Increasing Subsequence</a>
A sequence (not necessarily contiguous) with leading 0s and (possibly) ending with 1s is essentially a weakly increasing subsequence. As such, we can compute the LIS for the array that will give you the answer. </p>
<p>This problem had weak testcases, which allowed O(N^2) LIS solutions to be accepted. However, LIS can be computed in O(Nlog(K)) as well. </p>
<p>2.For each 0, the longest length of happy array is, at least, number of 0s to the left (including itself) and number of 1s to the right. We can use prefix sums to compute the number of 1s at each index and use it to compute the longest possible happy array for each 0. Not using prefix sum array will cause this algorithm to degenerate to O(N^2), which is same as above. </p>enWed, 14 Nov 2018 18:47:11 -0000