The Hungarian parliament has elected Peter Magyar as the country's new prime minister, getting the backing of 140 of 199 MPs after a general election.