Student life at New York City’s specialized high schools in the 1980s and ’90s.

Donna Lennon will never forget when she learned she had won a seat at Stuyvesant High School, one of the nation’s most revered and selective public schools.

Ms. Lennon was sitting in English class in mostly low-income and black East New York, Brooklyn, in the spring of 1981 when a guidance counselor delivered the good news. The class erupted in cheers. “I couldn’t speak,” said Ms. Lennon, now 51 and a lawyer.

Four years later, she graduated from Stuyvesant — then one of the city’s three specialized high schools — alongside Dianne Morales, who said it “was a diamond in the middle of the desert” for students like her.

Ms. Morales, who is Puerto Rican and grew up in Bedford-Stuyvesant, Brooklyn, crammed for exams and completed hours of homework each night, sometimes on long commutes, alongside classmates from every corner of the city.

“All of New York City was new to me,” she said, remembering that she was exposed to loft parties in SoHo and friends’ luxurious apartments near Washington Square Park’s grand marble arch. At Stuyvesant, Ms. Morales, now the chief executive of a nonprofit, said she “learned there was so much more out there for me.”

In interviews, more than a dozen black and Hispanic students who graduated from New York City’s specialized high schools from 1975 to 1995 described the schools as oases for smart children from troubled neighborhoods. But the alumni said they were anguished that the schools have since lost nearly all of their black and Hispanic students.

Black and Hispanic enrollment in the specialized schools has plummeted over the last 40 years.

White enrollment has also fallen while Asian enrollment has ballooned. Among the most drastic shifts: Brooklyn Technical High School’s black population dropped to 6 percent in 2016 from 51 percent in 1982.

The city has designated five additional test-in specialized high schools since 2002, bringing the total to eight, in an attempt to integrate the elite schools. But even those schools have seen a decline in black and Hispanic enrollment over the last decade, which undercuts the idea that simply adding more elite schools will shift demographics. Black and Hispanic students currently represent 70 percent of the school system, but make up just 10 percent of the enrollment in the specialized schools.

When Ms. Lennon found out in March that only seven black students had scored high enough on the specialized school entrance exam to receive an offer to attend Stuyvesant, she logged onto the school’s alumni Facebook page. There, she found her own white and Asian classmates arguing that the decline was because black children did not work as hard as other students, or because their parents did not care as much as others’ did.

“It’s not like I’m new to being black — I understand stereotypes exist,” Ms. Lennon said. But this felt different.

“People are ignoring history,” she added. “No one is asking, ‘What has happened?’”

A black student group’s shrinking presence in the Stuyvesant yearbook through the years 1975 U.N.I.K.U.K.U., the black student union, was Stuyvesant’s “most active ethnic group” in the mid-1970s. 1982 By this year, the group had changed its name to the Black Students League and reported “an upsurge in popularity.” The group planned “to direct its new strength outside the school by providing tutoring and taking political action.” 1993 As the Black Students League’s numbers dwindled, it modified its mission to become “a support group and an open forum for black students.” 2018 The Black Students League and Aspira, the Hispanic student group, were featured together. “What we lack in numbers, we make up for in drive and heart,” the yearbook caption reads.

As a teenager, Thomas Colon proudly wore his Bronx High School of Science jacket on the subway and in his South Bronx neighborhood. He borrowed slang from classmates from all across the city and, for the first time, relished being around students even smarter than he was.

“How racist can you be when the first black kids you meet are in your advanced calculus class?” said Mr. Colon, 58, who is Puerto Rican and now retired from a career in finance. “That was the real beauty of the school.”

Since Mr. Colon graduated in 1978, the specialized school admissions process has been transformed by changes in the city’s demographics, its public school system and the culture around the schools’ entrance exam, which is at the center of the debate over the future of the elite schools.

For years, most who took the admissions test had little to no preparation. Today, test prep is a rapidly expanding local industry. At the same time, many accelerated academic programs in mostly black and Hispanic neighborhoods have closed as Asian immigrants have embraced the specialized high schools as tickets out of poverty.

And in a school system that remains severely racially segregated, many black and Hispanic students have been left in struggling middle schools that sometimes do not even notify them that the elite schools exist.

Mayor Bill de Blasio’s proposal to scrap the decades-old admissions test has sparked an intense backlash and a renewed fight over how to integrate the city’s deeply divided school system.

Stuyvesant has had the smallest percentage of black and Hispanic students of any city high school in recent years.

The mayor’s proposal would replace the exam — currently the sole means of gaining admission to the schools — with a system that offers seats to the top-performing students from every city middle school. If his plan is approved by the State Legislature — an increasingly dim possibility — the specialized schools would be nearly 50 percent black and Hispanic, and Asian students would lose about half their seats.

That would be a significant blow to the Asian students, most of them poor, who have replaced white students as a majority in the specialized schools. From 1970 to 2011, the number of Asia-born immigrants living in New York City increased about eightfold to 843,000 from 105,000. The Asian population of the specialized schools includes Asian-Americans and Asian immigrants.

Though immigration from Latin America and Africa has also increased significantly in the same period, that influx is not reflected in the specialized schools’ makeup. By 2011, New York was home to about 984,000 first-generation immigrants from Latin America and roughly 128,000 immigrants who were born in Africa.

Much more has changed since New York’s most prized public schools began to look less like the city school system as a whole — and the explosion of test preparation may be the biggest shift.

“When I heard about all the test prep courses, I thought, if that was me, there was no way I could have afforded that,” said Dr. Danielle Elliott Range, who grew up in public housing in Far Rockaway, Queens, and graduated from Stuyvesant in 1989.

Dr. Range, now 47 and an associate medical director at Duke University Medical Center, said she sometimes went hungry over the weekend, between school lunches.

Today, it is almost unheard-of for a current student to not have prepared for the test — often at one of the prep centers whose presence in New York City has doubled in the past decade, to 436 in 2017. At Kaplan, a top prep chain, the most basic offering for the specialized school exam is eight group prep sessions for $1,000.

The centers have cropped up to prep students for the SAT, the specialized school test and other high-stakes exams. Some even offer summer classes.

The Bronx, home to the highest concentration of black and Hispanic students, has the fewest test prep centers.

There is a debate over whether the city should expand prep or move away from a focus on standardized exams. As test prep has become all but a prerequisite over the last decade, advanced academic classes have evaporated for many black and Hispanic students.

When Ademola Oyefeso saw that only a tiny number of black and Hispanic students were admitted to the specialized schools this year, he said he was “twice mad.” Mr. Oyefeso, 41, who now works in politics, graduated from Brooklyn Tech in 1995.

“I was upset for those kids, because that’s not the experience I had,” he said. “And I was mad because, as a parent, I wondered how many black and brown kids were just left on the table because their parents didn’t know how to get you into gifted and talented.”

Mr. Oyefeso, like nearly all the other alumni interviewed, attended an accelerated middle school.

A select few middle schools send a large share of students to specialized high schools. Note: Of 594 middle schools, 121 received more than five admissions offers to specialized high schools. Schools with fewer than five offers are not shown because detailed data for these schools was not made available.

About 10 years ago, Michael R. Bloomberg, then the city’s mayor, implemented a citywide test-based threshold for gifted and talented programs in an attempt to diversify them — but the programs soon shed even more black and Hispanic students.

Last year, there were nearly twice as many students in gifted and talented programs in District 2 — which includes mostly wealthy and white Manhattan neighborhoods — as there were in the Bronx, the city’s poorest borough. The Bronx has a total of nine gifted and talented programs, while District 2 alone has eight.

Students enrolled in gifted and talented program by school, 2017-18 100 50 500 Bronx District 7 36 students enrolled Manhattan District 2 1,894 students enrolled Queens Brooklyn Staten Island Students enrolled in gifted and talented program by school 50 100 500 Bronx District 7 36 students enrolled Manhattan District 2 1,894 students enrolled Queens Brooklyn Staten Island

Some families believe that expanding gifted programs to every neighborhood will help integrate schools. Others argue that the programs exacerbate segregation.

Hundreds of charter schools have opened as gifted programs have closed, absorbing tens of thousands of black and Hispanic students into academically rigorous classrooms.

Though some charter students outperform their white suburban peers on state exams, that has not always translated into success on the specialized school test. Since charter students sometimes cannot afford prep or are not steered towards the specialized schools, charters’ track record on elite school admissions has raised questions about whether preparation specific to the entrance exam can outweigh academic prowess or performance on other standardized tests. Specialized school offers to charter students would more than double under Mr. de Blasio’s plan.

Prep for Prep, a training program that helps high-performing black, Hispanic and Asian students get into prestigious New York private schools, accepts only about 200 students a year. Some have argued that Prep for Prep recruits smart black and Hispanic students who might have otherwise attended a specialized school. But even if every Prep for Prep student were accepted into a specialized high school, they would still represent only a small fraction of the schools’ 5,000 or so offers for freshman seats.

A page from the 1982 Stuyvesant yearbook poked fun at the entrance exam.

Leonard Noisette, who graduated from Stuyvesant in 1975 and works in philanthropy, remembered walking to elementary school just three blocks from his childhood home in Jamaica, Queens. That school helped prepare him for the middle school gifted program that he was bused to in another part of the borough.

By the time he got to Stuyvesant, which he said he remembers “very fondly,” he couldn’t help but think of the mostly poor and black classmates he had left behind in Queens.