tag:blogger.com,1999:blog-2597841815280998418.post392114081133144344..comments2024-03-12T06:45:01.935+01:00Comments on This Thread: Counting couplesMannyhttp://www.blogger.com/profile/07393063644320426727noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-2597841815280998418.post-70900351551870919992013-12-02T12:20:53.158+01:002013-12-02T12:20:53.158+01:00Neat! Instead of counting the ones for each zero, ...Neat! Instead of counting the ones for each zero, you modify on the flight the weight of any single one accordingly to the number of zeros that are depending to it.<br /><br />Nice and elegant solution, thank you for share it.Mannyhttps://www.blogger.com/profile/07393063644320426727noreply@blogger.comtag:blogger.com,1999:blog-2597841815280998418.post-33666636974232719962013-12-02T03:52:53.580+01:002013-12-02T03:52:53.580+01:00For this problem, we can count the times the 1 is ...For this problem, we can count the times the 1 is counted after each 0 and summarize the counts to get the result. <br /><br />For example, the array [ 0, 1, 0, 1, 1], the count of the 1 after each 0 is [ 0, 1, 0, 2, 2]. We summarize the counts for each 1 to get 5. <br /><br />For reducing the space complexity, we can use a variable which is started from 0 to store the current count of 1 and a Anonymoushttps://www.blogger.com/profile/10299912892309377194noreply@blogger.com