Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Kashif-E/8a8d554e8d9ee269249e2cf67470d5bb to your computer and use it in GitHub Desktop.
Save Kashif-E/8a8d554e8d9ee269249e2cf67470d5bb to your computer and use it in GitHub Desktop.
Kotlin programe to find the index in a string where right and left Paranthesis are equal
fun main() {
val str = "()))(()"
str.forEachIndexed { index, _ ->
val str1 = str.substring(0, index)
val str2 = str.substring(index, str.length)
println("str1s $str1")
println("str2 $str2")
if (str1.count { it == '(' } == str2.count { it == ')' }) {
println("equal at $index")
return
}
}
println("not found")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment