Hacker News new | past | comments | ask | show | jobs | submit login

> I mean at least cut the iterations in half by not iterating over the entire range in the inner loop!

The reason I wrote it that way is because the actual common way I find this is in Java where the team wants to use the `stream` api.

IE

    items.stream()
      .filter((item)->items.stream()
        .filter((item2)->item2 != item)
        .findAny((item2)->Object.equals(item.foo, item2.foo)).isPresent())
      .toList();
That's not really super readable or universalizable to other languages.

Even more commonly, instead of doing the `findAny` I often see the trip up being someone doing a `contains` or other O(n) operations on `List` objects inside iterations of that list.

It's this sort of fluent/functional style of programming that often seems to get tripped up on doing n^2 (or more) algorithms.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact