/**
 * Given a list of complex numbers represented as strings in Kotlin,
 * this function should return the common components present in all the complex numbers.
 *
 * @param complexNums A list of complex numbers represented as strings.
 * @return A set of common components present in all complex numbers.
 *
 * Example:
 * findCommonComponents(listOf("1+2j", "2-3j", "4+1j", "-1+5j")) returns setOf("j", "+")
 */
fun findCommonComponents(complexNums: List<String>): Set<Char> {

    // Convert the complex numbers to a set of unique components
    val complexComponents = mutableSetOf<Char>()
    for (complexNum in complexNums) {
        for (char in complexNum) {
            if (char.isLetter() || char in listOf('+', '-')) {
                complexComponents.add(char)
            }
        }
    }

    // Find common components appearing in all complex numbers
    var commonComponents = complexComponents.toSet()
    for (complexNum in complexNums) {
        commonComponents = commonComponents.intersect(complexNum.toSet())
    }

    return commonComponents
}
/**
 * Given a list of complex numbers represented as strings in Kotlin,
 * this function should return the common components present in all the complex numbers.
 *
 * @param complexNums A list of complex numbers represented as strings.
 * @return A set of common components present in all complex numbers.
 *
 * Example:
 * findCommonComponents(listOf("1+2j", "2-3j", "4+1j", "-1+5j")) returns setOf("j", "+")
 */
fun findCommonComponents(complexNums: List<String>): Set<Char> {
/**
 * Given a list of complex numbers represented as strings in Kotlin,
 * this function should return the common components present in all the complex numbers.
 *
 * @param complexNums A list of complex numbers represented as strings.
 * @return A set of common components present in all complex numbers.
 *
 * Example:
 * findCommonComponents(listOf("1+2j", "2-3j", "4+1j", "-1+5j")) returns setOf("j", "+")
 */
fun findCommonComponents(complexNums: List<String>): Set<Char> {

    // Convert the complex numbers to a set of unique components
    val complexComponents = mutableSetOf<Char>()
    for (complexNum in complexNums) {
        for (char in complexNum) {
            if (char.isLetter() || char in listOf('+', '-')) {
                complexComponents.add(char)
            }
        }
    }

    // Find common components appearing in all complex numbers
    var commonComponents = complexComponents.toSet()
    for (complexNum in complexNums) {
        commonComponents = commonComponents.intersect(complexNum.toSet())
    }

    return commonComponents
}