Sort by

recency

|

1236 Discussions

|

  • + 0 comments

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

    vector<int> acmTeam(vector<string> topic) {
        int h = 0, cp = 0;
        for(int i = 0; i < topic.size() - 1; i++){
            bitset<500> a = bitset<500>(topic[i]);
            for(int j = i + 1; j < topic.size(); j++){
             bitset<500> b = bitset<500>(topic[j]);
             bitset<500> c = a | b;
             int x = c.count();
             if( x > h){h = x; cp = 1;}
             else if( x == h) cp++;
            }
        }
        return {h, cp};
    }   
    
  • + 0 comments
    // i have chnages the given array from topics -> persons. 
    // now understand, it like if person[i][k] == 1, that means ith person knows the topic k. 
    
    function acmTeam(persons) {
        let max = 0; // max topic that the team know 
        let count = 0; // the team which knows the max topics 
        
        for(let i = 0; i < persons.length; i++) { 
            for(let j = i + 1; j < persons.length; j++) {
                let know = 0; 
                for(let k = 0; k < persons[0].length; k++) {
                    if(persons[i][k] === '1' || persons[j][k] === '1'){
                        know += 1; 
                    }
                }
                
                if(know > max) {
                    max = know; 
                    count = 1; // reset the count for the nex max
                }
                else if(know === max){
                    count += 1; // otherwise increase the count, we found another max 
                }
            }
        }
        return [max, count]; 
    		// should i tell you a secret, >> you are g___r___e__a__t 😍!!
       //  Happy Coding 
    }
    
  • + 0 comments
    // i have chnages the given array from topics -> persons. 
    // now understand, it like if person[i][k] == 1, that means ith person knows the topic k. 
    
    function acmTeam(persons) {
        let max = 0; // max topic that the team know 
        let count = 0; // the team which knows the max topics 
        
        for(let i = 0; i < persons.length; i++) { 
            for(let j = i + 1; j < persons.length; j++) {
                let know = 0; 
                for(let k = 0; k < persons[0].length; k++) {
                    if(persons[i][k] === '1' || persons[j][k] === '1'){
                        know += 1; 
                    }
                }
                
                if(know > max) {
                    max = know; 
                    count = 1; // reset the count for the nex max
                }
                else if(know === max){
                    count += 1; // otherwise increase the count, we found another max 
                }
            }
        }
        return [max, count]; 
    }
    
  • + 0 comments

    The time constraints on these test cases are too tight. As in: for a C# solution the additional time spent to instantiate variables at the start of the method for use and to increase code clarity, rather than using the indices of the List being returned, is enough extra time to cause multiple test cases to fail. Integer insantiation takes a few microseconds.

    That's completely unreasonable. Insane, even.

  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            Scanner in = new Scanner(System.in);
            int N = in.nextInt(); //number of people
            int M = in.nextInt(); //number of topics
            String[] person_info = new String[N];
            
            for (int i = 0; i < N; i++) 
                person_info[i] = in.next();
            long teams = 0;
            long max_covered = 0;
            long matched_topics = 0;
            for (int i = 0; i < N; i++) {
                
                for (int k = i + 1; k < N; k++) {
                    matched_topics = 0;
                    for (int j = 0; j < M; j++) {
               
                        if (person_info[i].charAt(j) - '0' > 0 || person_info[k].charAt(j) - '0' > 0)
                            matched_topics++;
                    }
                    if (matched_topics == max_covered)
                        teams++;
                    else if (matched_topics > max_covered) {
                        max_covered = matched_topics;
                        teams = 1;   
                    }
                }
               
                
                
           
            }
            
            System.out.println(max_covered);
            System.out.println(teams);
            /*for (int i = 0; i < N; i++) {
                System.out.printf("%sn", person_info[i]);
            }*/
            in.close();
        }
    }