Trolley problem and its variants in Buddhist ethics
Traditionally, worrying about this kind of speculative problems is classified as  a form of delusion. Consider the following Zen story:

Huineng's Flag


  Two Zen monks saw a flag wavering in the wind, and could not help having a philosophical debate:
  -- "It is the flag that is wavering," argued one monk.
  -- "No, it's the wind that is wavering!" insisted the other monk.
  
  Huineng, who happened to pass by, overheard the two monks and remarked, "It's not the flag nor the wind that is wavering. Your minds are wavering!"


In this vein, the most enlightened way to solve the trolley problem would be to stop worrying about it.