From 5396eb44ce5610cdd7f3a86d8828ce0e50dc8f41 Mon Sep 17 00:00:00 2001 From: Chayan Das <110921638+Chayandas07@users.noreply.github.com> Date: Wed, 16 Nov 2022 22:33:41 +0530 Subject: [PATCH] Create 16 Nov## Sum of Beauty of All Substrings 16 nov --- 16 Nov## Sum of Beauty of All Substrings | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 16 Nov## Sum of Beauty of All Substrings diff --git a/16 Nov## Sum of Beauty of All Substrings b/16 Nov## Sum of Beauty of All Substrings new file mode 100644 index 0000000..5e2d817 --- /dev/null +++ b/16 Nov## Sum of Beauty of All Substrings @@ -0,0 +1,22 @@ +class Solution { + public: + int beautySum(string s) { + // Your code goes here + int res = 0, n = s.length(); + for (int i = 0; i < n; i++) { + vector dp(26); + for (int j = i; j < n; j++) { + dp[s[j] - 'a']++; + int a = 0, b = n; + for (int k = 0; k < 26; k++) { + if (dp[k] > 0) { + a = max(a, dp[k]); + b = min(b, dp[k]); + } + } + res += a - b; + } + } + return res; + } +};