From 2ebd13c24db1c10fe59e36abd7acef28c4da5e3a Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Tue, 24 Sep 2024 20:33:18 +0530 Subject: [PATCH] Create 3043. Find the Length of the Longest Common Prefix --- ...nd the Length of the Longest Common Prefix | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 3043. Find the Length of the Longest Common Prefix diff --git a/3043. Find the Length of the Longest Common Prefix b/3043. Find the Length of the Longest Common Prefix new file mode 100644 index 0000000..82ba321 --- /dev/null +++ b/3043. Find the Length of the Longest Common Prefix @@ -0,0 +1,26 @@ +class Solution { +public: + int longestCommonPrefix(vector& arr1, vector& arr2) { + set st; + for (auto num : arr1) { + while (num > 0) { + st.insert(num); + num /= 10; + } + } + int maxi = 0; + for (auto num : arr2) { + int temp = num; + while (temp > 0) { + + if (st.find(temp) != st.end()) { + int len = (int)log10(temp) + 1; + maxi = max(maxi, len); + break; + } + temp /= 10; + } + } + return maxi; + } +};