Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
28-liner: 3 easy examples solution in Clear category for The Final Stone by przemyslaw.daniel
from typing import List
from heapq import heapify, heappush, heappop
from bisect import insort
def final_stone(stones: List[int]) -> int:
while len(stones) > 1:
stones.remove(bigger := max(stones))
stones.remove(smaller := max(stones))
stones.append(bigger - smaller)
return stones.pop() if stones else 0
def final_stone(stones: List[int]) -> int:
stones = sorted(stones)
while len(stones) > 1:
insort(stones, stones.pop() - stones.pop())
return ([0] + stones).pop()
def final_stone(stones: List[int]) -> int:
heapify(stones := [-stone for stone in stones] + [0])
while len(stones) > 1:
heappush(stones, heappop(stones) - heappop(stones))
return -heappop(stones)
July 23, 2022