Organizing Containers of Balls

Sort by

recency

|

617 Discussions

|

  • + 0 comments
    def organizingContainers(container):
        # Write your code here
        n = len(container)
        capacity = []
        type_count = []
        for i in range(n):
            capacity.append(sum(container[i]))
            current_total = 0
            for j in range(n):
                current_total += container[j][i]
                
            type_count.append(current_total)
                      
        return "Possible" if sorted(capacity) == sorted(type_count) else "Impossible"
    
  • + 0 comments

    This problem sucks. It has no relevance in the really real world and is so poorly stated it is more of a 'can i parse this idiots question' versus solve some algorithm. Damn I hate this site

  • + 0 comments

    Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-organizing-containers-of-balls-problem-solution.html

  • + 0 comments

    c# code, O(nlogn)

        public static string organizingContainers(List<List<int>> container)
        {
            int n = container.Count;
            List<long> containerCapacity = new List<long>();
            List<long> ballByTypeCount = new List<long>();
            for (int i = 0; i < n; i++) {
                containerCapacity.Add(0);
                ballByTypeCount.Add(0);
            }
            for (int i = 0; i < n; i++){
                for (int j = 0; j < n; j++){
                    containerCapacity[i] += container[i][j];
                    ballByTypeCount[j] += container[i][j];                
                }
            }
            containerCapacity.Sort();
            ballByTypeCount.Sort();
            for (int i = 0; i < n; i++){
                if (containerCapacity[i] != ballByTypeCount[i])
                    return "Impossible";
            }
            return "Possible";
        }
    
  • + 0 comments
    def organizingContainers(container):
        n = len(container)
        size_of_types = [0] * n
        size_of_containers = [0] * n
    
        for i in range(n):
            size_of_current_container = 0
            for j in range(n):
                size_of_types[j] += container[i][j]
                size_of_current_container += container[i][j]
            
            size_of_containers[i] += size_of_current_container
    
        return "Possible" if sorted(size_of_types) == sorted(size_of_containers) else "Impossible"