Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • This is not relevant answer for the question asked. i tried this in jsbin and it does not work with input mentioned in question. Commented Aug 2, 2016 at 19:52
  • 2
    Since the question is not 100% clear about the order this algorithm is kind of OK. But it performs badly, since it fully iterates twice over the array. For larger arrays this might be an issue. Commented Jul 15, 2017 at 8:04
  • It won't work if one of the element is 0 in the array. Commented Jun 28, 2022 at 1:29