Ad
  • Custom User Avatar

    "Most applications" is a very subjective phrase. I agree many premature optimizations are evil, but why waste time when the optimization is more like a logical solution than a weird tweak to match certain environment? FYI this solution takes around 500ms for 1 million. Not a huge number in the computer world I would say.

  • Custom User Avatar

    I don't think there's any way to do this in constant time because you're asked to generate a list of m numbers up to an input n. You could absolutely do better than the filter/reduce combo, but I think this gets points for readability.

    At present, this has mn time, where n is the input and m is the number of items that match the criteria of being divisible by both 3 and 5. For most applications, the optimization to n time isn't worth it.

  • Custom User Avatar

    why take O(n) when you can do it in constant time?