algorithms

Algorithm implementations
git clone git://git.laack.co/algorithms.git
Log | Files | Refs | README

cinema-seat-allocation-v5.py (961B)


      1 class Solution:
      2     def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
      3         
      4         bitmask = {}
      5         
      6         for seat in reservedSeats:
      7             if bitmask.get(seat[0] - 1) is None:
      8                 bitmask[seat[0] - 1] = 0b0000000000
      9             bitmask[seat[0] - 1] = bitmask[seat[0] - 1] | 2**(seat[1] - 1)
     10         
     11         mask_first = 0b0111100000
     12         mask_second = 0b0001111000
     13         mask_third = 0b0000011110
     14 
     15         count = (n - len(bitmask)) * 2
     16 
     17         for i in bitmask:
     18 
     19             current = bitmask[i]
     20 
     21             first = False
     22             second = False
     23 
     24 
     25             if current & mask_first == 0:
     26                 count += 1
     27                 first = True
     28             
     29             if not first and current & mask_second == 0:
     30                 count += 1
     31                 second = True
     32             
     33             if not second and current & mask_third == 0:
     34                 count += 1
     35 
     36         return count