Leetcode Problem 2032. Two Out of Three

2032. Two Out of Three

Leetcode Solutions

Using Frequency Count and Set

  1. Initialize three frequency arrays freq1, freq2, and freq3 of size 101 (since numbers range from 1 to 100).
  2. Iterate through each number in nums1, nums2, and nums3, incrementing the corresponding index in the respective frequency array.
  3. Initialize an empty set result to store the distinct numbers present in at least two arrays.
  4. Iterate through the range of possible numbers (1 to 100) and for each number, check if it appears in at least two frequency arrays.
  5. If the condition is met, add the number to the result set.
  6. Convert the result set to a list and return it.
UML Thumbnail

Using HashSets to Record Unique Values

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...