Task Of Pairing Hackerrank Python Solution
Note: Only Function Code are Provided Below for Task of Pairing Solution. You Only need to Write Function for This Solution
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'taskOfPairing' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts LONG_INTEGER_ARRAY freq as parameter.
#
def taskOfPairing(freq):
count = 0
marker = False
for i in freq:
if i != 0:
count += i // 2
if i % 2 != 0 and marker:
count += 1
marker = False
elif i % 2 != 0:
marker = True
else:
marker = False
return count
if _name_ == '_main_':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
freq_count = int(input().strip())
freq = []
for _ in range(freq_count):
freq_item = int(input().strip())
freq.append(freq_item)
result = taskOfPairing(freq)
fptr.write(str(result) + '\n')
fptr.close()
Ps: The Question is Generated by Hackerrank. We Only Provide/Write Answer of the Given Problems for Educational Purpose Only. Any Queries Regarding Question Drop your Queries Here
Tags:
Hackerrank