6 kyu

Valid Braces

22,889 of 78,247xDranik

Description:

Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return true if the string is valid, and false if it's invalid.

This Kata is similar to the Valid Parentheses Kata, but introduces new characters: brackets [], and curly braces {}. Thanks to @arnedag for the idea!

All input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: ()[]{}.

What is considered Valid?

A string of braces is considered valid if all braces are matched with the correct brace.

Examples

"(){}[]"   =>  True
"([{}])"   =>  True
"(}"       =>  False
"[(])"     =>  False
"[({})](]" =>  False
Algorithms

Stats:

CreatedNov 4, 2013
PublishedNov 5, 2013
Warriors Trained203614
Total Skips32874
Total Code Submissions474631
Total Times Completed78247
JavaScript Completions22889
CoffeeScript Completions228
Haskell Completions1039
C# Completions4869
Python Completions22968
Java Completions8867
Ruby Completions1799
PHP Completions2228
TypeScript Completions2755
Elixir Completions292
C++ Completions5757
Dart Completions685
Rust Completions1698
Swift Completions879
Go Completions2139
Lua Completions191
Scala Completions349
C Completions594
Julia Completions27
COBOL Completions5
Total Stars3354
% of votes with a positive feedback rating92% of 7327
Total "Very Satisfied" Votes6208
Total "Somewhat Satisfied" Votes1001
Total "Not Satisfied" Votes118
Ad
Contributors
  • xDranik Avatar
  • jhoffner Avatar
  • OverZealous Avatar
  • dnolan Avatar
  • bkaes Avatar
  • tko Avatar
  • sv90 Avatar
  • lpierron Avatar
  • adam-tokarski Avatar
  • liuyang1 Avatar
  • sudheer594 Avatar
  • user4190256 Avatar
  • lessonteacher Avatar
  • anter69 Avatar
  • JDeBolt Avatar
  • maevelicious Avatar
  • Chrono79 Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • FArekkusu Avatar
  • konkath Avatar
  • gopheratl Avatar
  • hobovsky Avatar
  • xavierguihot Avatar
  • stellartux Avatar
  • trashy_incel Avatar
  • kirull Avatar
  • akar-0 Avatar
  • KayleighWasTaken Avatar
Ad