#3556
Sum of Largest Prime Substrings
expert · 1050 · lc medium +32 · 37.8% accepted · 55 likes · top 16%
Description
From all substrings of string s (ignoring leading zeros when parsed as integers), collect every unique prime number they represent. Return the sum of the three largest such primes.
If fewer than three distinct primes exist, return their total. If no primes can be formed, return 0.
Each prime counts once regardless of how many substrings produce it.
Code
1
2
3