'''
Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1.

Note that an integer is said to be common to nums1 and nums2 if both arrays have at least one occurrence of that integer.

 

Example 1:

Input: nums1 = [1,2,3], nums2 = [2,4]
Output: 2
Explanation: The smallest element common to both arrays is 2, so we return 2.
Example 2:

Input: nums1 = [1,2,3,6], nums2 = [2,3,4,5]
Output: 2
Explanation: There are two common elements in the array 2 and 3 out of which 2 is the smallest, so 2 is returned.
 

Constraints:

1 <= nums1.length, nums2.length <= 105
1 <= nums1[i], nums2[j] <= 109
Both nums1 and nums2 are sorted in non-decreasing order.
'''
import unittest

from typing import *

class Solution:
    def getCommon(self, nums1: List[int], nums2: List[int]) -> int:
        start1 = 0
        start2 = 0
        
        while start1 < len(nums1) and start2 < len(nums2):
            if nums1[start1] < nums2[start2]:
                start1 += 1
            elif nums1[start1] > nums2[start2]:
                start2 += 1
            else:
                return nums1[start1]
        return -1

        
class TestSolution(unittest.TestCase):

    def test_case(self):
        examples = (
            (([1,2,3,6], [2,3,4,5]), 2),
        )
        for first, second in examples:
            self.assert_function(first, second)

    def assert_function(self, first, second):
        self.assertEqual(Solution().getCommon(*first), second,
                         msg="first: {}; second: {}".format(first, second))


unittest.main()
