Length of a Document Reached Through a Random Token
Problem statement
A delivery contains documents whose lengths can differ a lot, though some or all may be equal. Document i has lengths[i] tokens.
To check how much PII was missed, a reviewer picks one token uniformly at random from all tokens in the delivery and then reviews the whole document that the token came from.
Is the reviewed document longer than, the same length as, or shorter than the average document in the delivery?
Compare the expected length of the reviewed document with the mean of lengths. Return "longer" if the expected length is greater, "same" if the two are equal, and "shorter" if it is smaller.
Function
compareReviewedDocumentLength(lengths: int[]) → StringExamples
Example 1
lengths = [1,9]return = "longer"There are 10 tokens. The picked token is in the 9-token document with probability 9/10 and in the 1-token document with probability 1/10.
The expected length of the reviewed document is 9 * 9/10 + 1 * 1/10 = 8.2. The average document has (1 + 9) / 2 = 5 tokens, so the reviewed document is longer.
Example 2
lengths = [4,4,4]return = "same"Every document has 4 tokens, so the reviewed document always has 4 tokens, which equals the average.
Example 3
lengths = [100,1,1,1,1]return = "longer"There are 104 tokens and 100 of them are in the long document. The expected length of the reviewed document is (100 * 100 + 4 * 1) / 104 = 10004 / 104, about 96.2.
The average document has 104 / 5 = 20.8 tokens, so the reviewed document is much longer.
Constraints
1 <= lengths.length <= 10^51 <= lengths[i] <= 10^4