People recommend leetCode more.Should I be doing leetcode or codewars?
People recommend leetCode more.Should I be doing leetcode or codewars?
Doesn't make a difference though, practice is practice. Might be more likely to see a Leet Code problem but all that matters at the end of the day is if you can solve it.People recommend leetCode more.
Also @Neo The Resurrected ONE here's one for you: write a function that validates matching parentheses/braces/brackets.
Input: ()
Output: true
Input: {[]}()
Output: true
Input: (})
Output: false
You can assume the input will only contain a combination of ()[]{}.
you can do both, codewars is easierShould I be doing leetcode or codewars?
Also @Neo The Resurrected ONE here's one for you: write a function that validates matching parentheses/braces/brackets.
Input: ()
Output: true
Input: {[]}()
Output: true
Input: (})
Output: false
You can assume the input will only contain a combination of ()[]{}.
Also @Neo The Resurrected ONE here's one for you: write a function that validates matching parentheses/braces/brackets.
Input: ()
Output: true
Input: {[]}()
Output: true
Input: (})
Output: false
You can assume the input will only contain a combination of ()[]{}.
function matchInput (a) {
let b;
let c;
a.toString('');
if (a.includes('(') && a.includes('[') && a.includes('{') ) {
if (a.includes(')') && a.includes(']') && a.includes('}')) {
b = true;
c = true;
} else {
b = false;
c = false;
}
} else if (a.includes('(') && a.includes('[')) {
if (a.includes(')') && a.includes(']')) {
b = true;
c = true;
} else {
b = false;
c = false;
}
} else if (a.includes('(') && a.includes('{')) {
if (a.includes(')') && a.includes('}')) {
b = true;
c = true;
} else {
b = false;
c = false;
}
} else if (a.includes('{') && a.includes('[')) {
if (a.includes('}') && a.includes(']')) {
b = true;
c = true;
} else {
b = false;
c = false;
}
} else if (a.includes(')') && a.includes(']') && a.includes('}') ) {
if (a.includes('(') && a.includes('[') && a.includes('{')) {
c = true;
b = true;
} else {
c = false;
b = false;
}
} else if (a.includes(')') && a.includes(']')) {
if (a.includes('(') && a.includes('[')) {
c = true;
b = true;
} else {
c = false;
b = false;
}
} else if (a.includes(')') && a.includes('}')) {
if (a.includes('(') && a.includes('{')) {
c = true;
b = true;
} else {
c = false;
b = false;
}
} else if (a.includes('}') && a.includes(']')) {
if (a.includes('{') && a.includes('[')) {
c = true;
b = true;
} else {
c = false;
b = false;
}
} else if (a.includes(')')) {
if (a.includes('(')) {
c = true;
b = true;
} else {
c = false;
b = false;
}
} else if(a.includes('}')) {
if (a.includes('{')) {
c = true;
b = true;
} else {
c = false;
b = false;
}
} else if(a.includes(']')) {
if(a.includes('[')) {
c = true;
b = true;
} else {
c = false;
b = false;
}
} else if (a.includes('(')) {
if (a.includes(')')) {
b = true;
c = true;
} else {
b = false;
c = false;
}
} else if(a.includes('{')) {
if (a.includes('}')) {
b = true;
c = true;
} else {
b = false;
c = false;
}
} else if(a.includes('[')) {
if(a.includes(']')) {
b = true;
c = true;
} else {
b = false;
c = false;
}
} else {
return false;
}
if(b && c ) {
return true;
} else {
return false;
}
}
Alright, breh, I got it.
This is my JavaScript solution.
Code:function matchInput (a) { let b; let c; a.toString(''); if (a.includes('(') && a.includes('[') && a.includes('{') ) { if (a.includes(')') && a.includes(']') && a.includes('}')) { b = true; c = true; } else { b = false; c = false; } } else if (a.includes('(') && a.includes('[')) { if (a.includes(')') && a.includes(']')) { b = true; c = true; } else { b = false; c = false; } } else if (a.includes('(') && a.includes('{')) { if (a.includes(')') && a.includes('}')) { b = true; c = true; } else { b = false; c = false; } } else if (a.includes('{') && a.includes('[')) { if (a.includes('}') && a.includes(']')) { b = true; c = true; } else { b = false; c = false; } } else if (a.includes(')') && a.includes(']') && a.includes('}') ) { if (a.includes('(') && a.includes('[') && a.includes('{')) { c = true; b = true; } else { c = false; b = false; } } else if (a.includes(')') && a.includes(']')) { if (a.includes('(') && a.includes('[')) { c = true; b = true; } else { c = false; b = false; } } else if (a.includes(')') && a.includes('}')) { if (a.includes('(') && a.includes('{')) { c = true; b = true; } else { c = false; b = false; } } else if (a.includes('}') && a.includes(']')) { if (a.includes('{') && a.includes('[')) { c = true; b = true; } else { c = false; b = false; } } else if (a.includes(')')) { if (a.includes('(')) { c = true; b = true; } else { c = false; b = false; } } else if(a.includes('}')) { if (a.includes('{')) { c = true; b = true; } else { c = false; b = false; } } else if(a.includes(']')) { if(a.includes('[')) { c = true; b = true; } else { c = false; b = false; } } else if (a.includes('(')) { if (a.includes(')')) { b = true; c = true; } else { b = false; c = false; } } else if(a.includes('{')) { if (a.includes('}')) { b = true; c = true; } else { b = false; c = false; } } else if(a.includes('[')) { if(a.includes(']')) { b = true; c = true; } else { b = false; c = false; } } else { return false; } if(b && c ) { return true; } else { return false; } }
Alright, breh, I got it.
This is my JavaScript solution.
Code:function matchInput (a) { let b; let c; a.toString(''); if (a.includes('(') && a.includes('[') && a.includes('{') ) { if (a.includes(')') && a.includes(']') && a.includes('}')) { b = true; c = true; } else { b = false; c = false; } } else if (a.includes('(') && a.includes('[')) { if (a.includes(')') && a.includes(']')) { b = true; c = true; } else { b = false; c = false; } } else if (a.includes('(') && a.includes('{')) { if (a.includes(')') && a.includes('}')) { b = true; c = true; } else { b = false; c = false; } } else if (a.includes('{') && a.includes('[')) { if (a.includes('}') && a.includes(']')) { b = true; c = true; } else { b = false; c = false; } } else if (a.includes(')') && a.includes(']') && a.includes('}') ) { if (a.includes('(') && a.includes('[') && a.includes('{')) { c = true; b = true; } else { c = false; b = false; } } else if (a.includes(')') && a.includes(']')) { if (a.includes('(') && a.includes('[')) { c = true; b = true; } else { c = false; b = false; } } else if (a.includes(')') && a.includes('}')) { if (a.includes('(') && a.includes('{')) { c = true; b = true; } else { c = false; b = false; } } else if (a.includes('}') && a.includes(']')) { if (a.includes('{') && a.includes('[')) { c = true; b = true; } else { c = false; b = false; } } else if (a.includes(')')) { if (a.includes('(')) { c = true; b = true; } else { c = false; b = false; } } else if(a.includes('}')) { if (a.includes('{')) { c = true; b = true; } else { c = false; b = false; } } else if(a.includes(']')) { if(a.includes('[')) { c = true; b = true; } else { c = false; b = false; } } else if (a.includes('(')) { if (a.includes(')')) { b = true; c = true; } else { b = false; c = false; } } else if(a.includes('{')) { if (a.includes('}')) { b = true; c = true; } else { b = false; c = false; } } else if(a.includes('[')) { if(a.includes(']')) { b = true; c = true; } else { b = false; c = false; } } else { return false; } if(b && c ) { return true; } else { return false; } }
LOL this is wayyyy too much code. If it feels like it's too much code it probably is.
Yea, this is way to much code man. When you see problems like this first thing you should do is think if there is any data structure that can help solve this problem. For this problem a stack would make the solution way easier.
It doesn't look like it properly accounts for ordering. It looks like it would take )( as valid because both halves are there, but it's invalid because of the ordering.I haven't made it to data structures yet
Im still learning
My solution is long but it does work right?
It doesn't look like it properly accounts for ordering. It looks like it would take )( as valid because both halves are there, but it's invalid because of the ordering.
it was a nice try. Once you start to learn data structures and see this problem again , a lightbulb should turn on right away.