commit b4e26b007ed978c31c66a9e43723e62e2eaa77cd
parent 3b2920e26f66274cb802292defe63ea445288b9a
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sat, 2 Dec 2023 19:25:04 +0000
Daily Problem
Diffstat:
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/Problems/1160.cpp b/Problems/1160.cpp
@@ -0,0 +1,27 @@
+class Solution {
+ static int count[27];
+ static inline bool valid(const string &word) {
+ static int cnt[27];
+ memset(cnt, 0x00, sizeof(count));
+ for (const char c : word) {
+ const int idx = c & 0x1F;
+ if (++cnt[idx] > count[idx]) return false;
+ }
+ return true;
+ }
+
+ public:
+ int countCharacters(const vector<string> &words, const string &chars) const {
+ memset(count, 0x00, sizeof(count));
+ for (const char c : chars)
+ count[c & 0x1F]++;
+
+ int res = 0;
+ for (const auto &word : words) {
+ if (valid(word)) res += word.size();
+ }
+ return res;
+ }
+};
+
+int Solution::count[27];
diff --git a/README.md b/README.md
@@ -550,6 +550,7 @@ for solving problems.
| 1143 | Medium | [Longest Common Subsequence](Problems/1143.cpp) |
| 1146 | Medium | [Snapshot Array](Problems/1146.cpp) |
| 1148 | Easy | [Article Views I](Problems/1148.cpp) |
+| 1160 | Easy | [Find Words That Can Be Formed by Characters](Problems/1160.cpp) |
| 1161 | Medium | [Maximum Level Sum of a Binary Tree](Problems/1161.cpp) |
| 1162 | Medium | [As Far from Land as Possible](Problems/1162.cpp) |
| 1170 | Medium | [Compare Strings by Frequency of the Smallest Character](Problems/1170.cpp) |