File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -314,6 +314,36 @@ True
314314False
315315```
316316
317+ ** Q6c)** Find the maximum nested depth of curly braces
318+
319+ Unbalanced or wrongly ordered braces should return ` -1 `
320+
321+ Iterating over input string is one way to solve this, another is to use regular expressions
322+
323+ ``` python
324+ >> > max_nested_braces(' a*b' )
325+ 0
326+ >> > max_nested_braces(' {a+2}*{b+c}' )
327+ 1
328+ >> > max_nested_braces(' {{ a+2}*{{ b+{c*d}}+e*d}}' )
329+ 4
330+ >> > max_nested_braces(' a*b+{} ' )
331+ 1
332+ >> > max_nested_braces(' }a+b{' )
333+ - 1
334+ >> > max_nested_braces(' a*b{' )
335+ - 1
336+ ```
337+
338+ * bonus* : empty braces, i.e ` {} ` should return ` -1 `
339+
340+ ``` python
341+ >> > max_nested_braces(' a*b+{} ' )
342+ - 1
343+ >> > max_nested_braces(' a*{b+{}+c*{e*3.14}}' )
344+ - 1
345+ ```
346+
317347<br >
318348
319349## <a name =" misc " ></a >7) Misc
You can’t perform that action at this time.
0 commit comments