← Back to challenges

Two Product Problem (Part 2)

JavaScriptHardconditionsdata_structuresloops

Instructions

Create a function that takes an array arr and a number n and returns an array of two integers whose product is that of the number n.

Examples

twoProduct([1, 2, 3, 4, 13, 5], 39) ➞ [3, 13]

twoProduct([11, 2, 7, 3, 5, 0], 55) ➞ [5, 11]

twoProduct([100, 12, 4, 1, 2], 15) ➞ undefined

Notes

  • No duplicates.
  • Sort the number.
  • Try doing this with 0(n) time complexity.
  • The array can have multiple solutions, so return the first match you find.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.