Problem : https://www.hackerrank.com/challenges/cpp-hello-world/problem
Solution :
1 - #include <iostream>
Problem : https://www.hackerrank.com/challenges/cpp-hello-world/problem
Solution :
1 - #include <iostream>
Problem : https://www.hackerrank.com/challenges/welcome-to-java/problem
Solution : public class Solution {
Question : https://www.hackerrank.com/challenges/variable-sized-arrays/problem
Solution : #include <cmath>
/* Free your memory using this code
for(int i = 0; i < size; ++i)
{
delete[] A[i];
}
delete[] A;
*/
Solution:
int Solution::braces(string A) {
// create a stack
stack<char>s;
// process string char by char
int l = A.length();
for(int i =0;i<l;i++){
char c = A[i];
// if c is ( or operator or operand , we push in s
if(c == '(' || (c >= 'a' && c<='z') || c == '+'||c=='-'||c=='*'||c=='/'){
s.push(c);
}
else{
// else
// pop unless we get opening bracket and check the length of popped elements
// if it is > 1
//else end processing and it is redundant
// (a + b) -> 5
int p = 0;
while(s.empty() == false && s.top()!='('){
p++;
s.pop();
}
s.pop();
if(p>1)continue;
else{
return 1;
}
}
}
return 0;
}
Problem :
Solution :
int Solution::solve(string A) {
int l = A.length();
stack<char>s;
int f = 0;
for(int i =0;i<l;i++){
char c = A[i];
if(c == '('){
s.push(c);
}else{
if(s.empty()){
f = 1;
break;
}
s.pop();
}
}
if(f == 1){
return 0;
}
if(!s.empty()){
return 0;
}
return 1;
}
Problem :