Ad
  • 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

    Not a fan of the trailing closure mid-expression -- but otherwise identical to my solution 👌🏽