New York City and Northern Virginia will be the homes for Amazon.com Inc.’s second and third headquarters, according to people familiar with the matter, ending a more than yearlong public contest that started with 238 candidates and ended with a surprise split of its so-called HQ2.