3045. Count Prefix and Suffix Pairs II
You are given a 0-indexed string array
words.Let’s define a boolean function
isPrefixAndSuffixthat takes two strings,str1andstr2:
isPrefixAndSuffix(str1, str2)returnstrueifstr1is both a prefix and a suffix ofstr2, andfalseotherwise.For example,
isPrefixAndSuffix("aba", "ababa")istruebecause"aba"is a prefix of"ababa"and also a suffix, butisPrefixAndSuffix("abc", "abcd")isfalse.Return an integer denoting the number of index pairs
(i*,* j)such thati < j, andisPrefixAndSuffix(words[i], words[j])istrue.
You are given a
m x n0-indexed 2D matrixmat. From every cell, you can create numbers in the following way:
- There could be at most
8paths from the cells namely: east, south-east, south, south-west, west, north-west, north, and north-east.- Select a path from them and append digits in this path to the number being formed by traveling in this direction.
- Note that numbers are generated at every step, for example, if the digits along the path are
1, 9, 1, then there will be three numbers generated along the way:1, 19, 191.Return the most frequent prime number greater than
10out of all the numbers created by traversing the matrix or-1if no such prime number exists. If there are multiple prime numbers with the highest frequency, then return the largest among them.Note: It is invalid to change the direction during the move.
3043. Find the Length of the Longest Common Prefix
You are given two arrays with positive integers
arr1andarr2.A prefix of a positive integer is an integer formed by one or more of its digits, starting from its leftmost digit. For example,
123is a prefix of the integer12345, while234is not.A common prefix of two integers
aandbis an integerc, such thatcis a prefix of bothaandb. For example,5655359and56554have a common prefix565while1223and43456do not have a common prefix.You need to find the length of the longest common prefix between all pairs of integers
(x, y)such thatxbelongs toarr1andybelongs toarr2.Return the length of the longest common prefix among all pairs. If no common prefix exists among them, return
0.
3042. Count Prefix and Suffix Pairs I
You are given a 0-indexed string array
words.Let’s define a boolean function
isPrefixAndSuffixthat takes two strings,str1andstr2:
isPrefixAndSuffix(str1, str2)returnstrueifstr1is both a prefix and a suffix ofstr2, andfalseotherwise.For example,
isPrefixAndSuffix("aba", "ababa")istruebecause"aba"is a prefix of"ababa"and also a suffix, butisPrefixAndSuffix("abc", "abcd")isfalse.Return an integer denoting the number of index pairs
(i, j)such thati < j, andisPrefixAndSuffix(words[i], words[j])istrue.