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; + } +};