FastPrepFastPrep
Problem Brief

Clean Up Captions

OA

As a TikTok developer, you're working on a project to clean up captions and optimize storage. With millions of captions and hashtags circulating the platform, your task is to detect any overlap between captions on the for_you feed and the following feed. But it's not just about finding common words or hashtags; you need to identify any common substring between the two!

You are given two lists of captions — one from the for_you feed and another from the following feed. For each corresponding pair of captions, your job is to check if any substring appears in both captions. If a common substring is found, you should output "YES"; otherwise, output "NO."

Function Description

Complete the function optimizeStorageByCleaning in the editor.

optimizeStorageByCleaning has the following parameter(s):

  1. String for_you[n]: an array of strings
  2. String following[n]: an array of strings

Returns

String answers[n]: An array of strings where each element is either "YES" or "NO". "YES" indicates that a common substring exists between the corresponding logs in for_you and following, while "NO" indicates that no common substring exists.

1Example 1

Input
for_you = ["ba", "md", "rj"], following = ["af", "ee", "rf"]
Output
["YES", "NO", "YES"]
Explanation
Example 1 illustration

Constraints

Limits and guarantees your solution can rely on.

  • All the strings consist of lowercase English letters only, ascii[a-z].
  • |for_you| = |following|
public String[] optimizeStorageByCleaning(String[] for_you, String[] following) {
  // write your code here
}
Input

for_you

["ba", "md", "rj"]

following

["af", "ee", "rf"]

Output

["YES", "NO", "YES"]

Sign in to submit your solution.