• + 0 comments

    Typescript:

    function acmTeam(topic: string[]): number[] {
        // Write your code here
        const arrayOfMaximumTopics: number[] = [];
        let maximumTopics = 0;
        let numberOfTeams = 0;
        let totalAttendees: number = topic.length;
        
        for (let i = 0; i < totalAttendees - 1; i++) {
            for (let j = i + 1; j < totalAttendees; j++) {
                let topicsOfTeam = 0;
                const topicsCurrentAttendee: string[] = topic[i].split("");
                const topicsNextAttendee: string[] = topic[j].split("");
                
                topicsCurrentAttendee.forEach((el, index) => {
                    if (el === '1' || topicsNextAttendee[index] === '1') {
                        topicsOfTeam++;
                    }
                })
               
                if (topicsOfTeam > maximumTopics) {
                    maximumTopics = topicsOfTeam;
                }
                
                arrayOfMaximumTopics.push(topicsOfTeam);
            }
        }
        
        numberOfTeams = arrayOfMaximumTopics.filter(el => el === maximumTopics).length;
        
        return [maximumTopics, numberOfTeams];
    }