From 185d6ac8ff1bc82bd8ade4ae6605f989e1e67c9a Mon Sep 17 00:00:00 2001 From: Krishna Kesarwani <99733616+KK-is-Coding@users.noreply.github.com> Date: Mon, 13 Jan 2025 15:58:30 +0530 Subject: [PATCH 1/2] solution update for leetcode problem 3223 Minimum length of string after operations in cpp --- ...imum-length-of-string-after-operations.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 C++/3223_Minimum-length-of-string-after-operations.cpp 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 From 7e92ba42d4a052307237f649706f100e8a9cea78 Mon Sep 17 00:00:00 2001 From: Krishna Kesarwani <99733616+KK-is-Coding@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:11:40 +0530 Subject: [PATCH 2/2] updated solution with readme.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) 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