Number of Pairs of Strings With Concatenation Equal to Target

Given an array of digit strings nums and a digit string target, return the number of pairs of indices (i, j) where i != j such that the concatenation of nums[i] + nums[j] equals target.

Example 1
Inputnums = ["777","7","77","77"], target = "7777"
Output4
Valid pairs are (0, 1), (1, 0), (2, 3), and (3, 2), whose concatenations all equal "7777".
Example 2
Inputnums = ["123","4","12","34"], target = "1234"
Output2
Valid pairs are (0, 1) and (2, 3), whose concatenations equal "1234".

Constraints

  • 2 <= nums.length <= 100
  • 1 <= nums[i].length <= 100
  • 2 <= target.length <= 100
  • nums[i] and target consist of digits.
  • nums[i] and target do not have leading zeros.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate