Leetcode Problem 2021. Brightest Position on Street

2021. Brightest Position on Street

Leetcode Solutions

Sweep Line Algorithm

Algorithm

  1. Initialize an empty list events.
  2. For each light in lights, add two events to events: one for the start of the range with a value of +1, and one for the end of the range with a value of -1.
  3. Sort events by position.
  4. Initialize current_brightness to 0, max_brightness to 0, and brightest_position to None.
  5. Iterate through events:
    • Update current_brightness by adding the event's value.
    • If current_brightness is greater than max_brightness, update max_brightness and set brightest_position to the current event's position.
  6. Return brightest_position.
UML Thumbnail

Brute Force with Optimization

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...