balanced brackets hackerrank solution in cpp
C++
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <stack>
using namespace std;
string isBalanced(string s){
stack <char> st;
for(auto c:s){
switch (c){
case '(':
case '{':
case '[':
st.push(c);
break;
case '}':
if(st.empty() || st.top()!='{' )
return "NO";
st.pop();
break;
case ']':
if(st.empty() || st.top()!='[')
return "NO";
st.pop();
break;
case ')':
if(st.empty() || st.top()!='(')
return "NO";
st.pop();
break;
default: break;
}
}
return st.empty() ? "YES":"NO";
}
int main(){
int t;
cin >> t;
for(int a0 = 0; a0 < t; a0++){
string s;
cin >> s;
cout << isBalanced(s) << endl;
}
return 0;
}
Also in C++:
- Title
- how to use a new node c++
- Category
- C++
- Title
- number of islands leetcode code
- Category
- C++
- Title
- switch case sinax c++
- Category
- C++
- Title
- how to declare a function in c++
- Category
- C++
- Title
- c++ show time elapsed
- Category
- C++
- Title
- c++ program for matrix addition
- Category
- C++
- Title
- coping 2d vector in cpp
- Category
- C++
- Title
- what is difference between single inverted and double inverted in programming languages
- Category
- C++
- Title
- can we compare a long long int with int in c++ using max or min functions
- Category
- C++
- Title
- how to iterate through array in c++
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- lisy stl C++
- Category
- C++
- Title
- Check if a Number is Odd or Even using Bitwise Operators
- Category
- C++
- Title
- least number of coins to form a sum
- Category
- C++
- Title
- first prime numbers less than
- Category
- C++
- Title
- basic ex of maps in c++
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- new keyword in cpp
- Category
- C++
- Title
- min in vector c++
- Category
- C++
- Title
- retu7rn this c++
- Category
- C++
- Title
- stringstream in c++ with delimiter
- Category
- C++
- Title
- c++ yes no question
- Category
- C++
- Title
- c++ variable argument
- Category
- C++
- Title
- pow c++
- Category
- C++
- Title
- powers of 2 in cpp
- Category
- C++
- Title
- console colors in C++
- Category
- C++
- Title
- c++ char to string
- Category
- C++
- Title
- how to sort vector in c++
- Category
- C++
- Title
- primos menores que
- Category
- C++
- Title
- knapsack
- Category
- C++
- Title
- new c++
- Category
- C++
- Title
- converting char to int in c++
- Category
- C++
- Title
- binary tree search
- Category
- C++
- Title
- c++ sql
- Category
- C++
- Title
- C++ and endl
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- loop through array c++
- Category
- C++
- Title
- Insert into vector C++
- Category
- C++
- Title
- singleton c++
- Category
- C++
- Title
- border radius layout android xml
- Category
- C++
- Title
- system("pause") note working c++
- Category
- C++
- Title
- Qt asynchronous HTTP request
- Category
- C++
- Title
- counting valleys hackerrank solution in c++
- Category
- C++
- Title
- building native binary with il2cpp unity
- Category
- C++
- Title
- COunt the number of continous subsequences such that the sum is between
- Category
- C++
- Title
- elseif c++
- Category
- C++
- Title
- loop c++
- Category
- C++
- Title
- c++ convert int to cstring
- Category
- C++
- Title
- check if intent has extras
- Category
- C++
- Title
- deque c++
- Category
- C++
- Title
- queue c++
- Category
- C++
- Title
- UPARAM(ref)
- Category
- C++
- Title
- multiple words C++ in same
- Category
- C++
- Title
- error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(s[i] != "b"){
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- binary search stl in c++
- Category
- C++
- Title
- substr in c++
- Category
- C++
- Title
- how to use assrt c++
- Category
- C++
- Title
- how initilaize deffult value to c++ class
- Category
- C++
- Title
- how to sort in descending order c++
- Category
- C++
- Title
- c++ function to find length of array
- Category
- C++
- Title
- accept the noun and the output of plural c++
- Category
- C++
- Title
- preorder traversal
- Category
- C++
- Title
- cube mapping sdl
- Category
- C++
- Title
- getting a random letter in c++
- Category
- C++
- Title
- decimal to hex cpp
- Category
- C++
- Title
- C++ Syntax
- Category
- C++
- Title
- pbds in c++
- Category
- C++
- Title
- c++ vector pop_back
- Category
- C++
- Title
- string substr c++
- Category
- C++
- Title
- c++ looping through a vector
- Category
- C++
- Title
- c++ reading string
- Category
- C++
- Title
- accumulate in cpp
- Category
- C++
- Title
- ue4 c++ enum
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- pass vector by reference c++
- Category
- C++
- Title
- copy a part of a vector in another in c++
- Category
- C++
- Title
- c++ string^ to char*
- Category
- C++
- Title
- c++ do you not inherit constructor
- Category
- C++
- Title
- arrays in C++
- Category
- C++
- Title
- c++ typeid get type name
- Category
- C++
- Title
- monotonic deque
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- passing reference in c++
- Category
- C++
- Title
- ue4 modular character
- Category
- C++
- Title
- newline in c++
- Category
- C++
- Title
- new in c++
- Category
- C++
- Title
- c++ code to print hello world
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- ios_base::sync_with_stdio(false);cin.tie(NULL);
- Category
- C++
- Title
- set mimetype validation in mongoose
- Category
- C++
- Title
- cpp nan value
- Category
- C++
- Title
- stack c++
- Category
- C++
- Title
- initialise 2d vector in c++
- Category
- C++
- Title
- opperanf >> c++
- Category
- C++
- Title
- shortest path with bfs in c++
- Category
- C++
- Title
- modular exponentiation c++
- Category
- C++
- Title
- std string find character c++
- Category
- C++
- Title
- C++ cin cout
- Category
- C++