commit cef25805b9150a9a2d0e541305df8f8cac80ddcd
parent 3eb64dbfb796dd9eee39bcb70a99cb464e6e2402
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Tue, 24 Sep 2024 20:48:06 +0200
Daily Problem
Diffstat:
2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/Problems/3043.cpp b/Problems/3043.cpp
@@ -0,0 +1,26 @@
+class Solution {
+ public:
+ int longestCommonPrefix(const vector<int> &arr1, const vector<int> &arr2) const {
+ unordered_set<int> us;
+ int res = 0;
+
+ for (int n : arr1) {
+ while (n > 0) {
+ us.insert(n);
+ n /= 10;
+ }
+ }
+
+ for (int n : arr2) {
+ while (n > 0) {
+ if (us.count(n)) {
+ res = max(res, (int)log10(n) + 1);
+ break;
+ }
+ n /= 10;
+ }
+ }
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -1335,6 +1335,7 @@ for solving problems.
| 3016 | Medium | [Minimum Number of Pushes to Type Word II](Problems/3016.cpp) |
| 3034 | Medium | [Number of Subarrays That Match a Pattern I](Problems/3034.cpp) |
| 3039 | Medium | [Apply Operations to Make String Empty](Problems/3039.cpp) |
+| 3043 | Medium | [Find the Length of the Longest Common Prefix](Problems/3043.cpp) |
| 3067 | Medium | [Count Pairs of Connectable Servers in a Weighted Tree Network](Problems/3067.cpp) |
| 3068 | Hard | [Find the Maximum Sum of Node Values](Problems/3068.cpp) |
| 3070 | Medium | [Count Submatrices with Top-Left Element and Sum Less Than k](Problems/3070.cpp) |