data-structures-stacks Flashcards
1
Q
What does the acronym LIFO mean?
A
last in first out
2
Q
What methods are available on a Stack data structure?
A
push, pop, print, peek
3
Q
What must you do to access the value at an arbitrary point in a stack (not just the “top”)?
A
continuously pop until you reach that point in the stack
4
Q
Are braces balanced (interview question: algo challenge)
- take a string containing brackets, braces, parentheses,
- return boolean to say if the string’s braces are balanced
- balanced example: {[[()]]}
- unbalanced example: [{)]
A
solution
- for each char, check if opening brace
- if yes, push it on to stack
- if closing brace,
- if the stack’s top is matching opening brace, pop it
- if the stack’s top is not matching return false