Ad
  • Custom User Avatar

    There is not much point fitting it all onto one line just because you can. It just makes your code harder to understand.

  • Custom User Avatar

    A minor optimisation could be to set j = i + 1, as to avoid some repeated comparisons, otherwise it looks good

  • Custom User Avatar

    Not every problem needs a hash table. The simplest solution is only 5 lines and it also just so happens to be the most intuitive and readable solution. Respect for the hash table implementation though!

  • Custom User Avatar

    Ignore the comments at the top haha. Was planning something else then forgot to delete them.

  • Custom User Avatar

    That's why they use the term interval, not a set, because it is not a set of integers (for which we can calculate a number of elements) but an interval of real numbers on the number line (which has a length). It get clearer when you get to the examples: interval [1, 5] has a length of 4 and a set {1, 2, 3, 4, 5} would have 5 elements.

  • Custom User Avatar

    It should be more clear that the interval [x, y] includes x, but not y. If you think of the problem in terms of sets, the set of the interval [x, y] = {x, x + 1, x + 2, ... , y - 2, y - 1}. Please correct me if I'm wrong.