Two people died and 17 were injured when a Brooklyn building collapsed beside an excavation site.