Coding interview practice

Post an algorithm interview question, solve the others.

>(1)
>In any language, write a function that tests whether a string contains square square brackets that are nested properly.
>In other words, for every opening bracket there should be a corresponding closing bracket, with no improperly nested brackets between.
>Bonus: Do multiple types of brackets:
< [ ( {

>(2)
>In Python, write a function that takes a string and parses it into nested lists, based on the square brackets.
>You can assume that the square brackets match up appropriately.

>Impossible Challenge:
>Do problem (2) in C++.

Ive recently started applying for jobs n because of my projects ive been getting a ton of interviews for entry level stuff(web dev, jr software, small company software engineer)


So far ive passed every coding challenge no matter the language

HERE ARE MY TIPS FOR succes

Ive been praticing on codewars, i try to figure out the problems thn either give up or look at the correct answer n try to understand every part of it, dont spend more thn 20-30mins per problem

2. Once uve gotten the interview go on glassdoor n search for tht company n look at the vompanies interview question. 9/10 times the question thyll ask u will be there or some form of it.

3. Once uve gotten the interview.Look the companies job listing th u applied to. Look at the tech they listed and thn research why should I use X tech/languague, benefits and cons/ additionally whats a better interview. Often times ull be ask "so u listed ur proficient in X tech/languague which is what we use care to tell us why u use it"
You can now answer with X "tech is great for this and this," (if you found something new tht is way better or can help out) u can say "even though x tech has this con I read/heard Z tech can help with said problem

I clicked this because anime.

>write a program that iterates over a range of numbers and print:
>"Fizz" if the number is a multiple of 3
>"Buzz" if it's a multiple of 5
>"Pop" if it's a multiple of 7
>"Whack" if it's a multiple of 11
>"FizzBuzz" if it's a multiple of 3 and 5 and continue this pattern for all other combinations

(1)
>map each instance of {, [ or ( (and also }, ], )) into 0, 1, 2 respectively
>construct the vector with 0's, 1's and 2's corresponding to the order the brackets appear in the string
>check if the vector is a palindrome
(2)
>in Python
No.

(1):
Given a decorated 3-cobordism M, let \lambda_+/- be the Lagrangian subspaces of the homology spaces H_1(\partial_+/-M,R) that are the kernels of the inclusion homomorphisms H_1(\partial_+/-M,R) → H_1(M,R). Write out a pseudocode that computes the Maslov index \mu(\lambda_+,\lambda_-,\lambda(M)) of the decordated 3-cobordism M.
(2):
Given a semisimple ribbon category V with ground ring (field) C and normalization k = 1 where k is the anomaly, write a pseudocode that implements the Verlinde-Selberg formula to calculate the operator invariant F(H_{ij}) of the Hopf link H_{ij}.

your grammar makes me want to kill myself

nesting doesn't mean symmetrical
you could have something like this:

[ [ [ [a] ] ] [b] ]

which would be valid, but not a palindrome.
> not liking Python
No wonder you are an idiot.

We're not really interested in hiring you, good luck with your programming though.

So just a crazy bunch of nested if-statements?

def checkBrackets(brackets):
myStack = []
i = 0
while(i < len(brackets)):
if brackets[i] in "" and myStack[-1] == "

int bchk(char *str) {
int c=0;
for (int i=0; i

Don't call us, we'll call you.

Aside from the default which is a waste of 2 lines, good job very elegant

bunch of independent if-statements
concatenate a string if the condition meets

s = ''
if n % 3 == 0:
s += 'Fizz'
if n % 5 == 0:
s += 'Buzz'
...

string = gets.chomp
string.chars.to_a!
left_count = 0
string.each do |c|
if left_count < 0
puts "Mismatched brackets"
exit
end
left_count++ if c.eql? '['
left_count-- if c.eql? ']'
end
if left_count != 0
puts "Mismatched brackets"
exit
end

>chomp
>puts
>eql

Huh, so that's Ruby.

i swear to god Sup Forums is the most arrogant board on this site
you're all neets/pajeets but post shit like this

But he's speaking the truth.

...

>2
import ast
lst = ast.literal_eval("string representing nested list goes here")

perl did chomp first I'm sure

Yes. "puts" has been in C, too.

How's your CS graduation?

#1
def balanced_brackets(str):
stack = []
brackets = {'', '[' : ']', '(' : ')', '{' : '}'}
for char in str:
if char in brackets:
stack.append(char)
elif char in brackets.values():
if stack == []:
return False
if brackets[stack.pop()] != char:
return False
return stack == []


I don't understand #2, could you give an example case?

>if brackets[stack.pop()] != char:
you have to manually check the char, to match closing brackets with their counterparts.
[ != ]

(2)
fun('[a[b][][[d]e]]')

would return an actual list of lists:
['a', ['b'], [], [['d'], e]]

I'm indexing into brackets to find the matching closing bracket for an opening bracket.

i.e. if stack.pop() gives '[', then brackets[stack.pop()] gives ']'.

Oh I didn't notice that brackets is a dictionary

1. build PDA

2. I assume the list is already in the right format:
list_as_string = "[[1,2,3],[2,3,4]]"
list = None
exec("list =" + list_as_string)