Last active
August 15, 2024 11:40
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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