Greedy Algorithms Python3
\n\n# Time Complexity----->O(NLogN)\n# Space Complexity---->O(1)\n\nclass Solution:\n    def numRescueBoats(self, people: List[int], limit: int) -> int:\n      
\n\n# Time Complexity----->O(NLogN)\n# Space Complexity---->O(1)\n```\nclass Solution:\n    def numRescueBoats(self, people: List[int], limit: int) -> int:\n        sorted_people=sorted(people)\n        left,right,count=0,len(people)-1,0\n        while left<=right:\n            if sorted_people[left]+sorted_people[right]<=limit: //check wheather sum of first and last element equal or less than limit \n                left+=1\n                count+=1\n            else:\n                count+=1 //sum not possible with limit\n            right-=1\n        return count\n        \n```
['Python3']