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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Organizing Containers of Balls
  5. Discussions

Organizing Containers of Balls

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • Ridhuvarshan
    5 years ago+ 29 comments

    Mine works perfectly, simple solution

    int n = in.nextInt();
    int[] a = new int[n];
    int[] b = new int[n];
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            int x = in.nextInt();
            a[i] += x;
            b[j] += x;
        }
    }
    String pts = "Possible";
    for(int i=0;i<n;i++)
    {
        int j=0;
        for(j=i;j<n;j++)
        {
            if(a[i] == b[j])
            {
                int temp = b[j];
                b[j] = b[i];
                b[i] = temp;
                break;
            }
        }
        if(j==n)
        {
            pts = "Impossible";
            break;
        }
    }
    System.out.println(pts);
    
    103|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature