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