cswork / OAOpen practice workspace

OtherOA #15

Most Unique Elements (Part 2 :)

Estimated MediumJudge-ready

Topics (AI-labelled)HashingStrings

You are given a list of strings and a boolean useJaccard. When false, use Part 1's highest-character-frequency ratio and select all strings with the lowest ratio; when true, use Part 3's average multiset Jaccard similarity and select all strings with the lowest average. Finally, return the characters that appear only in the selected group of strings.

Input

The input is a JSON object: {"strings":[non-empty strings...],"useJaccard":true or false}. Site limits: 2≤number of strings≤80, each string has length≤1000, and the total length≤10000; characters are handled as Unicode code points.

Output

Output a JSON string. The selected strings are concatenated in input order, keeping repeated characters in their original order within each string, and excluding only characters that also appear in unselected strings.

Example 1

Input:

{"strings": ["aba", "ab", "abbcdd"], "useJaccard": false}

Output:

"cdd"

Example 2

Input:

{"strings": ["baa", "abbc", "ab"], "useJaccard": true}

Output:

"c"

Example 3

Input:

{"strings": ["a", "a", "aa"], "useJaccard": true}

Output:

""

Example 4

Input:

{"strings": ["aaab", "aabb", "abbb", "cccc"], "useJaccard": true}

Output:

"cccc"

Example notes

The Part 1/Part 3 branch computes a score for each string; compare the lowest score and ties using exact fractions, then filter out characters that appear in unselected strings.

Editorial

Loading solution…