Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    2040 - Kth Smallest Product of Two Sorted Arrays\.

    Hard

    Given two sorted 0-indexed integer arrays nums1 and nums2 as well as an integer k, return the <code>k<sup>th</sup></code> ( 1-based ) smallest product of nums1[i] * nums2[j] where 0 &lt;= i &lt; nums1.length and 0 &lt;= j &lt; nums2.length.

    Example 1:

    Input: nums1 = 2,5, nums2 = 3,4, k = 2

    Output: 8

    Explanation: The 2 smallest products are:

    • nums10 \* nums20 = 2 \* 3 = 6

    • nums10 \* nums21 = 2 \* 4 = 8

    The 2<sup>nd</sup> smallest product is 8.

    Example 2:

    Input: nums1 = -4,-2,0,3, nums2 = 2,4, k = 6

    Output: 0

    Explanation: The 6 smallest products are:

    • nums10 \* nums21 = (-4) \* 4 = -16

    • nums10 \* nums20 = (-4) \* 2 = -8

    • nums11 \* nums21 = (-2) \* 4 = -8

    • nums11 \* nums20 = (-2) \* 2 = -4

    • nums12 \* nums20 = 0 \* 2 = 0

    • nums12 \* nums21 = 0 \* 4 = 0

    The 6<sup>th</sup> smallest product is 0.

    Example 3:

    Input: nums1 = -2,-1,0,1,2, nums2 = -3,-1,2,4,5, k = 3

    Output: -6

    Explanation: The 3 smallest products are:

    • nums10 \* nums24 = (-2) \* 5 = -10

    • nums10 \* nums23 = (-2) \* 4 = -8

    • nums14 \* nums20 = 2 \* (-3) = -6

    The 3<sup>rd</sup> smallest product is -6.

    Constraints:

    • <code>1 <= nums1.length, nums2.length <= 5 * 10<sup>4</sup></code>

    • <code>-10<sup>5</sup><= nums1i, nums2j<= 10<sup>5</sup></code>

    • 1 &lt;= k &lt;= nums1.length * nums2.length

    • nums1 and nums2 are sorted.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public class Solution.Companion
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Long kthSmallestProduct(IntArray nums1, IntArray nums2, Long k)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait