Sum of Unique Elements
Real-world version: Face Values Held Only OnceThe statement here is our own: the same inputs, outputs and technique.
A stamp album lists the face value of every stamp mounted in it, in mounting order, as the list faces. A face value is called a singleton when exactly one stamp in the album carries it.
Return the total of the singleton face values. A face value carried by two or more stamps contributes nothing at all, not even one copy. Return 0 when the album holds no singleton.
Examples
Example 1
- Input
- faces = [8, 3, 8, 5]
- Output
- 8
Face value 8 is carried by two stamps, so it drops out. The singletons are 3 and 5, which total 8.
Example 2
- Input
- faces = [7, 7, 7, 2]
- Output
- 2
Three stamps carry face value 7, so it is not a singleton. Only 2 is, and the total is 2.
Example 3
- Input
- faces = [6, 6, 6]
- Output
- 0
Every stamp in the album carries the same face value, so the album holds no singleton and the total is 0.
Constraints
- 1 <= faces.length <= 100
- 1 <= faces[i] <= 100
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def sum_singleton_values(faces: list[int]) -> int:public int sumSingletonValues(int[] faces)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's