you give sort array distinct integer nums1 nums2a valid path define followschoose array nums1 nums2 traverse index0traverse current array leave rightIf reading value present nums1 nums2 allow change path array only repeat value consider valid paththe score define sum uniques value valid pathreturn maximum score obtain possible valid path since answer large return modulo 109 7 Example 1input nums1 245810 nums2 4689output 30explanation Valid paths245810 24589 24689 246810 start nums14689 45810 4589 46810 start nums2the maximum obtain path green 246810example 2input nums1 13579 nums2 35100output 109explanation maximum sum obtain path 135100example 3input nums1 12345 nums2 678910output 40explanation there common element nums1 nums2maximum sum obtain path 678910 Constraints1 nums1length nums2length 1051 nums1i nums2i 107nums1 nums2 strictly increase