HARD

Smart Contract Gas Optimizer

BlockchainData Structures & AlgorithmsBlockchainGraphTopological SortOptimization

Problem Description

You are given a series of Ethereum smart contract transactions. Each transaction has a gas cost. Optimize the order of transactions to minimize total gas spent while respecting dependencies. Input: List of transactions with dependencies Output: Optimal order and total gas saved

Example

Input
transactions = [{id:1,gas:100,deps:[]},{id:2,gas:50,deps:[1]},{id:3,gas:75,deps:[1]}]
Output
order: [1,3,2], total_gas: 225

Constraints

Time: 3s
Memory: 512MB