CBS’ “Late Show With David Letterman” is picking up ratings steam as it nears the finish line, last week drawing the program’s largest audience for any week in more than four years.

During the May 4-8 frame, “Late Show” — whose guests included President Obama, Reese Witherspoon and Ray Romano — averaged 3.82 million viewers, according to Nielsen. It was up 40% from the same frame a year ago and stood as the most-watched latenight program. NBC’s “Tonight Show Starring Jimmy Fallon” ran second with 3.09 million viewers, and ABC’s “Jimmy Kimmel Live” was third (2.23 million).

This was the largest weekly audience for “Late Show” since February 2011.

“Late Show” still lagged “Tonight Show” in the key 18-49 demo, with the NBC program at a 0.93 rating, followed by “Late Show” (0.64) and “Kimmel” (0.54). The CBS program matched its season high and was up 23% vs. last year while its rivals were both down about 10%.

Letterman, who is retiring from latenight next Wednesday, got a boost on Monday of last week when President Obama’s third and final visit produced the show’s top overnight rating since Obama’s prior appearance in September 2012. And earlier that night, a 90-minute special on CBS, “David Letterman: A Life in Television,” drew 8.1 million viewers.

The higher Letterman ratings on “Late Show” helped boost “Late Late Show with James Corden” to its largest audience since its premiere week (1.43 million).