The region stretches through Mauritania , Mali , Algeria and Niger , all countries struggling to contain Islamist militant groups .