We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Implementation
- Fair Rations
- Discussions
Fair Rations
Fair Rations
Sort by
recency
|
728 Discussions
|
Please Login in order to post a comment
for Python3 Platform
Java:
Python 3 more at https://github.com/pakbungdesu/dsa-hackerrank.git
Code in Python 3 n = int(input()) breads = list(map(int, input().split()))
minimum = 0 if breads[0]%2 == 1: minimum+=2 breads[0]+=1 breads[1]+=1 for index in range(1 ,n-1): if breads[index] %2 == 0: continue breads[index]+=1 breads[index+1]+=1 minimum+=2
if breads[n-1] %2 == 0: print(minimum) else: print('NO')
Here is my c++ solution: you can watch the explanation here : https://youtu.be/pAzUgM52d60
Whithout the if