Here's a more concise way to do it. You can update the table by updating the CTE.;-)
WITH CTE AS(
SELECT *, ROW_NUMBER() OVER( PARTITION BY ID ORDER BY ltr) rn
FROM #tmp
)
UPDATE CTE SET
flag = 'Y'
WHERE rn = 1;
If your rank is not ordered alphabetically, you can simply change the column with the CASE statement in the ORDER BY clause