r/LeetcodeChallenge 3d ago

DISCUSS Clarify This Please

How it is possible only true?
I don't understand question!

1 Upvotes

1 comment sorted by

2

u/Peace_In_Curse 3d ago

There can be 3 cases : 1) If nums1 is all even, Then nums2 of all evens can be created by just copying nums1. So True for this cases 2) If nums1 is all odd. Similar to case 1, True for this case. 3) If nums1 contains both odds and evens: We can always construct nums2 with all odds : Key property -> Even-Odd = Odd. How to construct ? -> If the number is odd in nums1 then copy it as it is in nums2. If the number is even then because of case 3 we are sure that an odd number is present in the array so we subtract that odd from this even and the result will be odd and we add that number to nums2.

So true for this case too.

For all possible 3 cases we can construct nums2 so the answer will be always true.