6 kyu
Simple string indices
249 of 2,304KenKamau
Description:
In this Kata, you will be given a string with brackets and an index of an opening bracket and your task will be to return the index of the matching closing bracket. Both the input and returned index are 0-based except in Fortran where it is 1-based. An opening brace will always have a closing brace. Return -1
if there is no answer (in Haskell, return Nothing
; in Fortran, return 0
; in Go, return an error)
Examples
solve("((1)23(45))(aB)", 0) = 10 // the opening brace at index 0 matches the closing brace at index 10
solve("((1)23(45))(aB)", 1) = 3
solve("((1)23(45))(aB)", 2) = -1 // there is no opening bracket at index 2, so return -1
solve("((1)23(45))(aB)", 6) = 9
solve("((1)23(45))(aB)", 11) = 14
solve("((>)|?(*'))(yZ)", 11) = 14
Input will consist of letters, numbers and special characters, but no spaces. The only brackets will be (
and )
.
More examples in the test cases.
Good luck!
Strings
Algorithms
Similar Kata:
Stats:
Created | Dec 3, 2017 |
Published | Dec 4, 2017 |
Warriors Trained | 3811 |
Total Skips | 252 |
Total Code Submissions | 8226 |
Total Times Completed | 2304 |
Python Completions | 689 |
JavaScript Completions | 787 |
Ruby Completions | 91 |
Haskell Completions | 52 |
C++ Completions | 235 |
Crystal Completions | 11 |
Fortran Completions | 14 |
Java Completions | 249 |
NASM Completions | 35 |
Go Completions | 127 |
C Completions | 150 |
Clojure Completions | 9 |
Total Stars | 57 |
% of votes with a positive feedback rating | 93% of 522 |
Total "Very Satisfied" Votes | 456 |
Total "Somewhat Satisfied" Votes | 59 |
Total "Not Satisfied" Votes | 7 |
Total Rank Assessments | 4 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |