Given an array of penalties fine[], an array of car numbers car[], and also the date. The task is to find the total fine which will be collected on the given date. Fine is collected from odd-numbered cars on even dates and vice versa.
 
Example 1:
Input:
N = 4, date = 12
car[] = {2375, 7682, 2325, 2352}
fine[] = {250, 500, 350, 200}
Output:
600
Explantion:
The date is 12 (even), so we collect the
fine from odd numbered cars. The odd
numbered cars and the fines associated
with them are as follows:
2375 -> 250
2325 -> 350
The sum of the fines is 250+350 = 600
 
Example 2:
Input:
N = 3, date = 8
car[] = {2222, 2223, 2224}
fine[] = {200, 300, 400}
Output:
300
Your Task:  
You don't need to read input or print anything. Your task is to complete the function totalFine() which takes the array car[] and fine[] its size N and an integer date as inputs and returns the total fine.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 10^{5}
1 <= Car_{i} <= 10^{5}
1 <= Date <= 10^{5}
1 <= Fine_{i} <= 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Mathematics

Starter code: #User function Template for python3

class Solution:
    def totalFine(self, n, date, car, fine):
        #Code here
    
    
    

Solutions:
class Solution:

	def totalFine(self, n, date, car, fine):
		(d, e) = ([], [])
		for i in range(n):
			if car[i] % 2 == 0:
				d.append(fine[i])
			else:
				e.append(fine[i])
		if date % 2 == 0:
			return sum(e)
		return sum(d)


class Solution:

	def totalFine(self, n, date, car, fine):
		total_fine = 0
		for i in range(n):
			if car[i] % 2 != date % 2:
				total_fine += fine[i]
		return total_fine


class Solution:

	def totalFine(self, n, date, car, fine):
		sum = 0
		if date % 2 == 0:
			for i in range(len(car)):
				if car[i] % 2 == 1:
					sum += fine[i]
			return sum
		if date % 2 == 1:
			for i in range(len(car)):
				if car[i] % 2 == 0:
					sum += fine[i]
			return sum


class Solution:

	def totalFine(self, n, date, car, fine):
		count = 0
		if date % 2 == 0:
			for i in range(n):
				if car[i] % 2 == 1:
					count += fine[i]
			return count
		else:
			for i in range(n):
				if car[i] % 2 == 0:
					count += fine[i]
			return count


class Solution:

	def totalFine(self, n, date, car, fine):
		total_fine = 0
		cars_index = []
		d = False
		if date % 2 == 0:
			d = True
		if d:
			for (i, num) in enumerate(car):
				if num % 2 >= 1:
					cars_index.append(i)
		else:
			for (i, num) in enumerate(car):
				if num % 2 == 0:
					cars_index.append(i)
		for index in cars_index:
			total_fine += fine[index]
		return total_fine


class Solution:

	def totalFine(self, n, date, car, fine):
		ans = 0
		if date % 2 == 0:
			even = True
		else:
			even = False
		for i in range(n):
			if car[i] % 2 == 0 and even == False:
				ans += fine[i]
			elif car[i] % 2 == 1 and even:
				ans += fine[i]
		return ans


class Solution:

	def totalFine(self, n, date, car, fine):
		fine_num = 0
		i = 0
		while i < n:
			if date % 2 == 0:
				for i in range(n):
					if car[i] % 2 != 0:
						add = fine[i]
						fine_num = fine_num + add
						i += 1
				return fine_num
			else:
				for i in range(n):
					if car[i] % 2 == 0:
						add = fine[i]
						fine_num = fine_num + add
						i += 1
				return fine_num


class Solution:

	def totalFine(self, n, date, car, fine):
		k = 0
		if date % 2 == 0:
			for (i, j) in list(zip(car, fine)):
				if i % 2 != 0:
					k = k + j
		else:
			for (i, j) in list(zip(car, fine)):
				if i % 2 == 0:
					k = k + j
		return k


class Solution:

	def totalFine(self, n, date, car, fine):
		sum = 0
		for i in range(n):
			for i in range(n):
				if date % 2 == 0 and car[i] % 2 != 0:
					sum = sum + fine[i]
				elif date % 2 != 0 and car[i] % 2 == 0:
					sum = sum + fine[i]
			return sum


class Solution:

	def totalFine(self, n, date, car, fine):
		if date % 2 == 0:
			ans = 0
			ind = 0
			for i in car:
				if i % 2 != 0:
					ans = ans + fine[ind]
					ind += 1
				else:
					ind += 1
			return ans
		if date % 2 != 0:
			ans = 0
			ind = 0
			for i in car:
				if i % 2 == 0:
					ans = ans + fine[ind]
					ind += 1
				else:
					ind += 1
			return ans


class Solution:

	def totalFine(self, n, date, car, fine):
		AllFine = 0
		for i in range(n):
			if date % 2 == 0 and car[i] % 2 != 0 or (date % 2 != 0 and car[i] % 2 == 0):
				AllFine += fine[i]
		return AllFine


class Solution:

	def totalFine(self, n, date, car, finess):
		fine = 0
		if date & 1:
			for i in range(n):
				if car[i] & 1:
					pass
				else:
					fine += finess[i]
		else:
			for i in range(n):
				if car[i] & 1:
					fine += finess[i]
				else:
					pass
		return fine


class Solution:

	def totalFine(self, n, date, car, fine):
		d = list(zip(car, fine))
		res = 0
		if date % 2 == 0:
			for i in d:
				if i[0] % 2 != 0:
					res += i[1]
		else:
			for i in d:
				if i[0] % 2 == 0:
					res += i[1]
		return res


class Solution:

	def totalFine(self, n, date, car, fine):
		odd = 0
		even = 0
		for i in range(len(car)):
			if car[i] % 2 != 0:
				odd += fine[i]
			else:
				even += fine[i]
		if date % 2 != 0:
			return even
		return odd


class Solution:

	def totalFine(self, n, date, car, fine):
		(sum1, sum2) = (0, 0)
		for i in range(n):
			if car[i] % 2 == 0:
				sum1 += fine[i]
			else:
				sum2 += fine[i]
		if date % 2 == 0:
			return sum2
		else:
			return sum1


class Solution:

	def totalFine(self, n, date, car, fine):
		finee = []
		if date % 2 == 0:
			for i in range(n):
				if car[i] % 2 != 0:
					finee.append(fine[i])
		if date % 2 != 0:
			for i in range(n):
				if car[i] % 2 == 0:
					finee.append(fine[i])
		return sum(finee)


class Solution:

	def totalFine(self, n, date, car, fine):
		(odd_sum, even_sum) = (0, 0)
		for (c, f) in zip(car, fine):
			if c % 2 == 0:
				even_sum += f
			else:
				odd_sum += f
		return even_sum if date % 2 != 0 else odd_sum


class Solution:

	def totalFine(self, n, date, car, fine):
		a = []
		b = []
		if date % 2 == 0:
			for i in range(len(car)):
				if car[i] % 2 != 0:
					a.append(car[i])
					b.append(fine[i])
		else:
			for i in range(len(car)):
				if car[i] % 2 == 0:
					a.append(car[i])
					b.append(fine[i])
		if len(b) == 0:
			return 0
		else:
			for i in range(len(b)):
				return sum(b)


class Solution:

	def totalFine(self, n, date, car, fine):
		l = []
		m = []
		for i in range(n):
			if date % 2 == 0 and car[i] % 2 != 0:
				l.append(fine[i])
			elif date % 2 != 0 and car[i] % 2 == 0:
				m.append(fine[i])
		if date % 2 == 0:
			return sum(l)
		else:
			return sum(m)


class Solution:

	def totalFine(self, n, date, car, fine):
		flag = True if date % 2 == 0 else False
		res = 0
		for i in range(len(car)):
			if flag and car[i] % 2 != 0:
				res += fine[i]
			elif not flag and car[i] % 2 == 0:
				res += fine[i]
		return res


class Solution:

	def totalFine(self, n, date, car, fine):
		total = 0
		if date % 2 == 0:
			for i in range(n):
				if car[i] % 2 != 0:
					total += fine[i]
		else:
			for j in range(n):
				if car[j] % 2 == 0:
					total += fine[j]
		return total


class Solution:

	def totalFine(self, n, date, car, fine):
		evensum = 0
		tot = 0
		for i in range(0, n):
			if car[i] % 2 == 0:
				evensum += fine[i]
			tot += fine[i]
		if date % 2 == 0:
			return tot - evensum
		else:
			return evensum


class Solution:

	def totalFine(self, n, date, car, fine):
		type = 'odd'
		if date % 2 == 0:
			type = 'even'
		sum = 0
		for (c, f) in zip(car, fine):
			if type != 'even':
				if c % 2 == 0:
					sum += f
			elif c % 2 != 0:
				sum += f
		return sum


from collections import Counter

class Solution:

	def totalFine(self, n, date, car, fine):
		s = 0
		if date % 2 == 0:
			for i in range(n):
				if car[i] % 2 != 0:
					s = s + fine[i]
		else:
			for i in range(n):
				if car[i] % 2 == 0:
					s = s + fine[i]
		return s


class Solution:

	def totalFine(self, n, date, car, fine):
		x = 0
		k = []
		sum = 0
		if date % 2 == 0:
			x = 1
		else:
			x = 0
		if x == 1:
			for i in range(n):
				if car[i] % 2 != 0:
					k.append(i)
				else:
					continue
		else:
			for i in range(n):
				if car[i] % 2 == 0:
					k.append(i)
				else:
					continue
		for x in k:
			sum = sum + fine[x]
		return sum


class Solution:

	def totalFine(self, n, date, car, fine):
		even_ans = 0
		odd_ans = 0
		for i in range(n):
			if car[i] % 2 == 0:
				even_ans += fine[i]
			else:
				odd_ans += fine[i]
		if date % 2 == 0:
			return odd_ans
		return even_ans


class Solution:

	def totalFine(self, n, date, car, fine):
		sum = 0
		if date % 2:
			for i in range(n):
				if not car[i] % 2:
					sum += fine[i]
		else:
			for i in range(n):
				if car[i] % 2:
					sum += fine[i]
		return sum


class Solution:

	def totalFine(self, n, date, car, fine):
		car_index = []
		ans = 0
		if date % 2 == 0:
			for i in range(len(car)):
				if car[i] % 2 != 0:
					car_index.append(i)
			for i in car_index:
				ans += fine[i]
		else:
			for i in range(len(car)):
				if car[i] % 2 == 0:
					car_index.append(i)
			for i in car_index:
				ans += fine[i]
		return ans


class Solution:

	def totalFine(self, n, date, car, fine):
		ans = 0
		for i in range(len(car)):
			if date % 2 == 0:
				if car[i] % 2 != 0:
					ans += fine[i]
			elif car[i] % 2 == 0:
				ans += fine[i]
		return ans


class Solution:

	def totalFine(self, n, date, car, fine):
		index = []
		for i in range(len(car)):
			if date % 2 == 0:
				if car[i] % 2 != 0:
					index.append(fine[i])
			elif car[i] % 2 == 0:
				index.append(fine[i])
		return sum(index)


import functools

class Solution:

	def totalFine(self, n, date, car, fine):

		def sumFineForOdd(car1, fine1):
			if car1 % 2 != 0:
				return fine1
			return 0

		def sumFineForEven(car1, fine1):
			if car1 % 2 == 0:
				return fine1
			return 0
		temp = 0
		if date % 2 == 0:
			fineCollected = list(map(sumFineForOdd, car, fine))
			fines = functools.reduce(lambda x, y: x + y, fineCollected)
		else:
			fineCollected = list(map(sumFineForEven, car, fine))
			fines = functools.reduce(lambda x, y: x + y, fineCollected)
		return fines


class Solution:

	def totalFine(self, n, date, car, fine):
		sum1 = 0
		sum2 = 0
		i = 0
		if date % 2 == 0:
			while i <= n - 1:
				if car[i] % 2 != 0:
					sum1 = sum1 + fine[i]
				i += 1
			return sum1
		else:
			while i <= n - 1:
				if car[i] % 2 == 0:
					sum2 = sum2 + fine[i]
				i += 1
			return sum2


class Solution:

	def totalFine(self, n, date, car, fine):
		even = []
		odd = []
		for i in range(0, len(car)):
			if car[i] % 2 == 0:
				even.append(fine[i])
			else:
				odd.append(fine[i])
		if date % 2 == 0:
			s = sum(odd)
			return s
		else:
			s1 = sum(even)
			return s1


class Solution:

	def totalFine(self, n, date, car, fine):
		oddFine = 0
		evenFine = 0
		for i in range(len(car)):
			if car[i] % 2 == 0:
				oddFine += fine[i]
			else:
				evenFine += fine[i]
		if date % 2 == 0:
			return evenFine
		return oddFine