'CodeSignal reverseParentheses C# without recursion Failing one case

I'm trying to understand what could possibly fail this logic. There is a hidden test that is failing, however given the guaranteed constraints and the test cases I'm unable to pinpoint what scenario is being failed. Others who have encountered a failing test were for different reasons, IOW the code is surviving those raised failing scenarios.

Here is what they expected: enter image description here

string solution(string inputString) {
    var strToMod = (String.IsNullOrEmpty(inputString)) ? "" : inputString;
    var result = "";
    
    var openParIdx = strToMod.IndexOf('(');
    var closeParIdx = 0;
    var counter = 0;
    while(openParIdx >= 0){
        while(strToMod.IndexOf('(', openParIdx + 1) > -1){
            openParIdx = strToMod.IndexOf('(', openParIdx + 1);
        };
        closeParIdx = strToMod.IndexOf(')', openParIdx + 1);
        var strToModLen = strToMod.Length;
        
        result = strToMod.Substring(0, openParIdx);
        
        var charArray = strToMod.Substring(openParIdx + 1, closeParIdx - openParIdx - 1).ToCharArray();
        Array.Reverse(charArray);
        result += new string (charArray);
        
        if(strToModLen > closeParIdx + 1){
            result += strToMod.Substring(closeParIdx + 1);
        }
        
        strToMod = result;
        openParIdx = strToMod.IndexOf('(');
    }
    
    Console.WriteLine($"{inputString} | {result}");
    
    return result;
}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source