Given a list of strings, return the longest common suffix shared by all of them. A suffix is a substring that appears at the end of a string. If there is no common suffix, or the list is null or empty, return an empty string. Comparisons are case-sensitive.

Examples:

Input: strs = ['coding', 'sledding', 'wedding'] Output: 'ding' Explanation: All three words end with 'ding' Input: strs = ['running', 'jumping', 'walking'] Output: 'ing' Explanation: The longest shared ending is 'ing' Input: strs = ['abc', 'xyz'] Output: '' Explanation: No common ending character, so empty string Input: strs = ['hello', 'hello'] Output: 'hello' Explanation: Identical strings share the whole string as a suffix Input: strs = [] Output: '' Explanation: An empty list has no common suffix
Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay November 2026 (Nov 1–15)Sponsored by FLXBL

Contest runs November 1 - 15. Complete challenges to climb the leaderboard!

Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes

Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In