Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 2
    Hint: find on an array structure with [ range, value ] as pairs. Commented Apr 3, 2020 at 5:56
  • The brute-force lazy way is to make a hash with 100 keys and just populate all the values. Commented Apr 3, 2020 at 5:56
  • The problem is that this is my masters final year project and I'm looking for the smartest possible way to do it, otherwise, yeah, this is a possible solution Commented Apr 3, 2020 at 6:01
  • 2
    "Smartest" as in "most efficient" depends on a variety of factors. A linear scan will be O(n) while a hash or an array is O(1) which is better, but takes more time to construct and memory to keep around. Commented Apr 3, 2020 at 6:16
  • 1
    Absolutely true. However for that case, the whole algorithm has quite big time and space complexity and this will be a negligible portion of the run time, regardless of how efficient it is. Just didn't want to go with a brute a brute-forcing approach, but go with something at least looking neat. Thanks anyway! Commented Apr 3, 2020 at 6:21