Day 2: Red-Nosed Reports

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://blocks.programming.dev/ if you prefer sending it through a URL

FAQ

  • Rin@lemm.ee
    link
    fedilink
    arrow-up
    1
    ·
    12 days ago

    What do you think my complexity is?

    I think it could be maybe O(n^2) because the other for loop which tries elements around the first error will only execute a constant of 5 times in the worst case? I’m unsure.

    • hades@lemm.ee
      link
      fedilink
      arrow-up
      3
      ·
      12 days ago

      It’s O(n).

      If you look at each of the levels of all reports, you will access it a constant number of times: at most twice in each call to EvaluateLineSafe, and you will call EvaluateLineSafe at most six times for each report.

    • Gobbel2000@programming.dev
      link
      fedilink
      arrow-up
      3
      arrow-down
      1
      ·
      12 days ago

      It really depends on what your parameter n is. If the only relevant size is the number of records (let’s say that is n), then this solution takes time in O(n), because it loops over records only once at a time. This ignores the length of records by considering it constant.

      If we also consider the maximum length of records (let’s call it m), then your solution, and most others I’ve seen in this thread, has a time complexity in O(n * m^2) for part 2.