Fair Rations

Sort by

recency

|

23 Discussions

|

  • + 0 comments

    If Bi can go beyond 10 then why they have mentioned 1<=Bi<=10. Because of that I thought Max loaves that one subject can have was 10.

  • + 0 comments

    //MY SOLUTION

    import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;

    public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int B[] = new int[N];
        int count=0;
        boolean flag=true;
        for(int B_i=0; B_i < N; B_i++)
        {
            B[B_i] = in.nextInt();
        }
        for(int i=0;i<N;i++)
        {
            if(B[i]%2!=0)
            {
                B[i]++;
                count++;
    
                if(i==0)
                {
                    B[i+1]++;
                    count++;
                }                                     
                else if(i==(N-1))
                {
                     B[i-1]++;
                     count++;
                }
                else
                {
                    B[i+1]++;
                    count++;
                }     
            }    
        }    
        for(int i=0;i<N;i++)
        {
            if(B[i]%2!=0)
            {
                flag=false;
            }    
        }
        if(flag)
            System.out.println(count);
        else
            System.out.println("NO");
    }
    

    }

  • + 1 comment

    Hey, why no gaming reference in this problem?

  • + 0 comments

    well, I didnot sign up for this contest. And I did this in a tricky way.

    View the submission at

    https://www.hackerrank.com/contests/hourrank-9/challenges/fair-rations/submissions/code/6009102

  • + 0 comments

    int main() { int N,i,l=0;; int B[100]; printf("enter no of people in a row"); scanf("%d",&N); printf("enter of loafs given to each individual"); for(i=1;i<=N;i++) { scanf("%d",B[i]); } for(i=1;i<=N;i++) { l=l+(B[i]/N); } if(l%2==0) { printf("%d",l); } else{ printf("NO"); } return 0; } after submitting it shows segmentation fault at each case what is segmentation fault????