Ad
  • Custom User Avatar

    This should be more clear in the description

  • Custom User Avatar

    Others have answered it, but this is a bit of a "gotcha" element to the question.

    With the "earliest pair" and "parse from the left please" statements, I'm trying to hint at the following behavior: Imagine the list doesn't exist until you begin parsing values one-by-one, inserting them as you go along. If your algorithm was capable of finding the first pair that exists as elements get added, that would be the perfect solution.

    Example with k-goldon's set:

    [1]                    # No pair exists to sum 6
    [1, 3]                 # No pair exists to sum 6 
    [1, 3, 0]              # No pair exists to sum 6
    [1, 3, 0, 4]           # No pair exists to sum 6
    [1, 3, 0, 4, 6]        # The 0 and 6 adds up to 6! We're DONE!
    
  • Default User Avatar

    Very questionable use of the phrase "entire pair is earlier". Entire pair is NOT earlier in your example. In the first pair, the first element is earlier, in the second - second is earlier. It seems that the description is matched to the algorithm.

  • Custom User Avatar

    Element with higher position decides of position of pair.
    For example:
    for sum = 6 in [1, 3, 0, 4, 6, 3, 8] there are two pairs: 3, 3 (at pos. 1, 5) and 0, 6 (at 2, 4). (3,3) is at 5 and (0, 6) is at 4. So "entire pair (0, 6) is earlier".

  • Custom User Avatar

    Probably. Nested loops grow extremely fast when the input grows, while flat loops just grow proportionnally.
    See:

    • 3 + 3 + 3 = 9
    • 3 * 3 * 3 = 27
    • 10 + 10 + 10 = 30
    • 10 * 10 * 10 = 1000

    etc.

    I think your question has received an answer :)

  • Custom User Avatar

    Really? if i will have third but not nested loop, will not it time out?

  • Default User Avatar

    are u using python ?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    what is meaning of "entire pair is earlier" ???

  • Default User Avatar

    wrong return on "http://www.googlewww.com" give "com" insted of "googlewww"

  • Default User Avatar

    great codešŸ¤©