Missing even and odd elements from the given arrays | Python3 implementation of the approach ; Function to find the missing numbers ; To store the minimum and the maximum odd and even elements from the arrays ; To store the sum of the array elements ; Get the minimum and the maximum even elements from the array ; Get the minimum and the maximum odd elements from the array ; To store the total terms in the series and the required sum of the array ; Total terms from 2 to minEven ; Sum of all even numbers from 2 to minEven ; Total terms from 2 to maxEven ; Sum of all even numbers from 2 to maxEven ; Required sum for the even array ; Missing even number ; Total terms from 1 to minOdd ; Sum of all odd numbers from 1 to minOdd ; Total terms from 1 to maxOdd ; Sum of all odd numbers from 1 to maxOdd ; Required sum for the odd array ; Missing odd number ; Driver code
import sys NEW_LINE def findMissingNums ( even , sizeEven , odd , sizeOdd ) : NEW_LINE INDENT minEven = sys . maxsize ; NEW_LINE maxEven = - ( sys . maxsize - 1 ) ; NEW_LINE minOdd = sys . maxsize ; NEW_LINE maxOdd = - ( sys . maxsize - 1 ) ; NEW_LINE sumEvenArr = 0 ; NEW_LINE sumOddArr = 0 ; NEW_LINE for i in range ( sizeEven ) : NEW_LINE INDENT minEven = min ( minEven , even [ i ] ) ; NEW_LINE maxEven = max ( maxEven , even [ i ] ) ; NEW_LINE sumEvenArr += even [ i ] ; NEW_LINE DEDENT for i in range ( sizeOdd ) : NEW_LINE INDENT minOdd = min ( minOdd , odd [ i ] ) ; NEW_LINE maxOdd = max ( maxOdd , odd [ i ] ) ; NEW_LINE sumOddArr += odd [ i ] ; NEW_LINE DEDENT totalTerms = 0 ; NEW_LINE reqSum = 0 ; NEW_LINE totalTerms = minEven // 2 ; NEW_LINE evenSumMin = ( totalTerms * ( totalTerms + 1 ) ) ; NEW_LINE totalTerms = maxEven // 2 ; NEW_LINE evenSumMax = ( totalTerms * ( totalTerms + 1 ) ) ; NEW_LINE reqSum = ( evenSumMax - evenSumMin + minEven ) ; NEW_LINE print ( " Even ▁ = " , reqSum - sumEvenArr ) ; NEW_LINE totalTerms = ( minOdd // 2 ) + 1 ; NEW_LINE oddSumMin = totalTerms * totalTerms ; NEW_LINE totalTerms = ( maxOdd // 2 ) + 1 ; NEW_LINE oddSumMax = totalTerms * totalTerms ; NEW_LINE reqSum = ( oddSumMax - oddSumMin + minOdd ) ; NEW_LINE print ( " Odd ▁ = " , reqSum - sumOddArr ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT even = [ 6 , 4 , 8 , 14 , 10 ] ; NEW_LINE sizeEven = len ( even ) NEW_LINE odd = [ 7 , 5 , 3 , 11 , 13 ] ; NEW_LINE sizeOdd = len ( odd ) ; NEW_LINE findMissingNums ( even , sizeEven , odd , sizeOdd ) ; NEW_LINE DEDENT