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
|
722 Discussions
|
Please Login in order to post a comment
JAVA
public static String fairRations(List B) { int count = 0; for (int i = 0; i < B.size() - 1 ; i++) { if(B.get(i) % 2 != 0){ B.set(i, B.get(i) + 1 ); B.set(i + 1, B.get(i + 1) + 1); count += 2; } } if (B.get(B.size() - 1) % 2 != 0) { return "NO"; } return String.valueOf(count); }
Java
Here is my c++ solution: you can watch the explanation here : https://youtu.be/pAzUgM52d60
Whithout the if
string fairRations(vector B) { int temp = 0; int count = 0; for(int i=0;i
Python 3