Skip to content

Latest commit

 

History

History
17 lines (17 loc) · 641 Bytes

note0497.md

File metadata and controls

17 lines (17 loc) · 641 Bytes
  • Type: Math (random) + binary search
  • Approach:
    1. Init function:
      • Use prefix sum to store the area of each rectangle
    2. Pick function:
      • Find a random area from 1 to the total area
      • Use binary search to search a specific area according to the random area
      • Calculate the coordinates by the area
  • Complexity:
    • Time:
      1. Init:
        • O(n)
      2. Pick:
        • O(logn)
    • Space: O(n)