FastPrepLongest Common Suffix

Longest Common Suffix

Chainalysis logoChainalysis● EasyNEW GRADOA
Learn

Problem statement

Given an array of strings words, return the longest string that is a suffix of every word. Return the empty string when there is no common suffix.

Function

longestCommonSuffix(words: String[]) → String

Examples

Example 1

words = ["running","jogging","walking"]return = "ing"

Example 2

words = ["cat","dog"]return = ""

Constraints

  • 1 <= words.length <= 1000.
  • 0 <= words[i].length <= 1000.
  • The total number of characters is at most 100000.

More Chainalysis problems

See Chainalysis hiring insights
public String longestCommonSuffix(String[] words) {
  // write your code here
}
words["running","jogging","walking"]
expected"ing"
Checking account…