MedianOfTwoSortedArrays, is a LeetCode problem. In this post we will see how we can solve this challenge in Swift

Problem Description

You can find the full details of the problem MedianOfTwoSortedArrays at LeetCode


Primary idea: For arrays of m and n numbers, nums1 and nums2, where m <= n.

          To find an index of mid1 in nums1, to separate the arrays into left and right parts:

 nums1[0, 1, ..., mid1 - 1] | nums1[mid1, mid1 + 1, ..., m]

 nums2[0, 1, ..., mid2 - 1] | nums2[mid2, mid2 + 1, ..., n]

 Make sure:

         count of left = count of right

          max of left <= min of right

Time Complexity: O(log(n + m)), Space Complexity: O(1)

Please check the main.swift snippet for the solution.

This solution originally posted at: Github by @soapyigu