diff --git a/C++/3223_Minimum-length-of-string-after-operations.cpp b/C++/3223_Minimum-length-of-string-after-operations.cpp new file mode 100644 index 00000000..feac66a6 --- /dev/null +++ b/C++/3223_Minimum-length-of-string-after-operations.cpp @@ -0,0 +1,28 @@ +class Solution +{ +public: + int minimumLength(string s) + { + // Step 1: Initialize a frequency map to count occurrences of each + // character + unordered_map charFreq; + + // Step 2: Count the frequency of each character in the string + for (char currChar : s) + { + charFreq[currChar]++; + } + + // Step 3: Calculate the total length after deletions count + int totalLen = 0; + for (const auto &entry : charFreq) + { + // If frequency is even, we can remove all occurrences + // If frequency is odd, we can remove all but one occurrence + totalLen += (entry.second % 2 == 0) ? 2 : 1; + } + + // Step 4: Return the minimum length after deletions count + return totalLen; + } +}; \ No newline at end of file diff --git a/README.md b/README.md index b2cac739..622f1535 100644 --- a/README.md +++ b/README.md @@ -280,6 +280,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 554 | [Brick Wall](https://leetcode.com/problems/brick-wall/) | [C++](./C++/brick-walls.cpp) | _O(n)_ | _O(n)_ | Medium | | | 146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [Javascript](../JavaScript/146.LRU-Cache.js) | _O(log(n))_ | _O(n)_ | Medium | | | 389 | [Find The Difference](https://leetcode.com/problems/find-the-difference/) | [C++](../C++/Find-The-Difference.cpp) | _O(n)_ | _O(1)_ | Easy | | +| 3223 | [Minimum Length Of String After Operations](https://leetcode.com/problems/minimum-length-of-string-after-operations/) | [C++](../C++/Find-The-Difference.cpp) | _O(n)_ | _O(1)_ | Medium | Hash Table, String, Counting |
@@ -515,6 +516,8 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [Shrimadh V Rao](https://github.com/Shrimadh)
| India | C++ | [GitHub](https://github.com/Shrimadh) | [Shreyas Shrawage](https://github.com/shreyventure)
| India | Python | [CodeChef](https://www.codechef.com/users/shreyventure)
[LeetCode](https://leetcode.com/shreyventure/)
[HackerRank](https://www.hackerrank.com/shreyas_shrawage) | [Surbhi Mayank](https://github.com/surbhi2408)
| India | C++ | [GitHub](https://github.com/surbhi2408) +| [Krishna Kesarwani](https://github.com/KK-is-Coding)
| India | C++ | [GitHub](https://github.com/KK-is-Coding) +
⬆️ Back to Top