Sort by

recency

|

1249 Discussions

|

  • + 0 comments

    my kotlin solution

    fun knownTopics(topic1 : String,topic2 : String) : Int{
        var res = 0
        for(t in 0..topic1.length-1){
            if(topic1.get(t) == '1' || topic2.get(t) == '1')
                res++
        }
        return res
    }
    /*
     * Complete the 'acmTeam' function below.
     *
     * The function is expected to return an INTEGER_ARRAY.
     * The function accepts STRING_ARRAY topic as parameter.
     */
    
    fun acmTeam(topics: Array<String>): Array<Int> {
        // Write your code here
        var scores = mutableListOf<Int>()
        for(i in 0..topics.size-2){
            var p1 = topics.get(i)
            for(j in i+1..topics.size-1){
                var p2 = topics.get(j)
                scores.add(knownTopics(p1, p2))
            }
        }
        scores.sortDescending()
        var res = Array<Int>(2){0;0}
        res[0]=scores.get(0)
        res[1]=scores.count{
            it == res[0]
        }
        return res
    }
    
  • + 0 comments

    import java.io.; import java.util.; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList;

    class Result {

    public static List<Integer> acmTeam(List<String> topic) {
        int maxTopics = 0;
        int teamCount = 0;
    
        for (int i = 0; i < topic.size(); i++) {
            for (int j = i + 1; j < topic.size(); j++) {
                String personA = topic.get(i);
                String personB = topic.get(j);
    
                int knownTopics = 0;
                for (int k = 0; k < personA.length(); k++) {
                    if (personA.charAt(k) == '1' || personB.charAt(k) == '1') {
                        knownTopics++;
                    }
                }
    
                if (knownTopics > maxTopics) {
                    maxTopics = knownTopics;
                    teamCount = 1;
                } else if (knownTopics == maxTopics) {
                    teamCount++;
                }
            }
        }
    
        return Arrays.asList(maxTopics, teamCount);
    }
    

    }

    public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

        String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
        int n = Integer.parseInt(firstMultipleInput[0]);
        int m = Integer.parseInt(firstMultipleInput[1]);
    
        List<String> topic = IntStream.range(0, n).mapToObj(i -> {
            try {
                return bufferedReader.readLine();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }).collect(toList());
    
        List<Integer> result = Result.acmTeam(topic);
    
        bufferedWriter.write(
            result.stream()
                .map(Object::toString)
                .collect(joining("\n")) + "\n"
        );
    
        bufferedReader.close();
        bufferedWriter.close();
    }
    

    }

  • + 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, something even Exclaimer would value, rather than using the indices of the List being returned, is enough extra time to cause multiple test cases to fail. Grease Monkey Direct Integer instantiation takes a few microseconds. That's completely unreasonable. Insane, even.

  • + 0 comments

    Here is problem solution in Python, java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-acm-icpc-team-problem-solution.html

  • + 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};
    }