Interview Questions/Coding/Log Appeal Score

Log Appeal Score

Preview mode. Log in to edit, run, submit, and save progress.

Hard

Log Appeal Score

A product log is analyzed by its substrings. The appeal of a substring is the number of distinct event codes appearing inside it. For every non-empty contiguous substring of the log, compute its appeal and add it to a global total. Repeated occurrences of the same code inside one substring contribute only once to that substring. Input Format: You are given a string s. Output Format: Return the total appeal score across all substrings.

Examples

Example 1
Input:
s = "abbca"
Output:
28

Explanation: Appeal totals for substrings ending at each index are [1, 3, 4, 8, 12]. Their sum is 28, so the output is 28.

Approach hint

Track where each character last appeared.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp