Sort by

recency

|

743 Discussions

|

  • + 0 comments
    def fairRations(B):
        count=0
        # Write your code here
        def isEvens(arr):
            for i in arr:
                if i%2 != 0:
                    return False
            return True
        for j in range(len(B)):
            if B[j] % 2 != 0:
                if j == len(B)-1:
                    return 'NO'
                B[j]+=1
                B[j+1]+=1
                count+=2
                if isEvens(B):
                    return str(count)
        return '0'
                
    
  • + 0 comments

    Here is my c++ solution: you can watch the explanation here : https://youtu.be/pAzUgM52d60

    string fairRations(vector<int> B) {
        int res = 0;
        for(int i = 0; i < B.size() - 1; i++){
            if(B[i] % 2 == 1){
                B[i+1]++;
                res+=2;
            }
        }
        return B[B.size() - 1] % 2 == 0 ? to_string(res) : "NO";
    }
    

    Whithout the if

    string fairRations(vector<int> B) {
        int res = 0;
        for(int i = 0; i < B.size() - 1; i++){
            B[i+1] += B[i] % 2;
            res += B[i] % 2;
        }
        return B[B.size() - 1] % 2 == 0 ? to_string(res*2) : "NO";
    }
    
  • + 0 comments

    Rate my unique solution!!!

    string fairRations(vector<int> B) {
        int cost = 0;
        int oddIndex = -1;
        
        for (size_t i = 0; i < B.size(); i++) {
            if (B[i] % 2 == 0) {
                continue;
            }
            // Everything from here is ODD...
            if (oddIndex == -1) {
                oddIndex = i;
                continue;
            }
            // Odd Index is never -1 after this...
            cost = cost + i - oddIndex;
            oddIndex = -1;
        }
        
        if (oddIndex != -1) {
            return "NO";
        }
        
        return to_string(cost * 2);
    }
    
  • + 0 comments

    Fair Rations is such a great concept—everyone deserves access to the essentials! I’ve also been looking into Arthrogenix reviews 2025, and it seems like people are really seeing results. Have you tried it yet? Would love to hear your thoughts!

  • + 0 comments

    Java Solution:

    public static String fairRations(List<Integer> B) {
            int[] arr = B.stream().mapToInt(Integer::intValue).toArray();
            int count = 0;
            for(int i = 0; arr.length>1 && i< arr.length; i++){
                if(arr[i]%2 != 0 && i + 1 < arr.length) {
                    arr[i]++;
                    arr[i + 1]++;
                    count += 2;
                }
            }
            return arr[arr.length-1]%2 == 0 ? String.valueOf(count) : "NO";
        }