[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Coding interview practice

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 29
Thread images: 10

File: 1489307074478.jpg (124KB, 550x990px) Image search: [Google]
1489307074478.jpg
124KB, 550x990px
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.
>>
File: 1488422823986.png (398KB, 708x1000px) Image search: [Google]
1488422823986.png
398KB, 708x1000px
>>59977543
>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
>>
>>59977543
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
>>
>>59977543
(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}.
>>
>>59977657
your grammar makes me want to kill myself
>>
File: 1489824326063.png (1003KB, 1280x824px) Image search: [Google]
1489824326063.png
1003KB, 1280x824px
>>59977976
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.
>>
>>59977952
>>59977963
We're not really interested in hiring you, good luck with your programming though.
>>
File: 1488407362845.jpg (659KB, 725x990px) Image search: [Google]
1488407362845.jpg
659KB, 725x990px
>>59977799
So just a crazy bunch of nested if-statements?
>>
def checkBrackets(brackets):
myStack = []
i = 0
while(i < len(brackets)):
if brackets[i] in "<[({":
myStack.append(brackets[i])
else:
if brackets[i] == ">" and myStack[-1] == "<":
myStack.pop()
elif brackets[i] == ")" and myStack[-1] == "(":
myStack.pop()
elif brackets[i] == "}" and myStack[-1] == "{":
myStack.pop()
elif brackets[i] == "]" and myStack[-1] == "[":
myStack.pop()
else:
return False
i += 1
if len(myStack) == 0:
return True
else:
return False
def subLists(currList):
leftParan = 1
j = 0
i = 1
newList = []
while(i < len(currList)):
while(leftParan != 0):
if currList[i] == "[":
leftParan += 1
else:
leftParan -= 1
i += 1
i -= 1
newList.append(subLists(currList[j + 1:i]))
j = i + 1
i = i + 2
leftParan += 1
return newList
>>
File: 1490815692310.jpg (12KB, 179x179px) Image search: [Google]
1490815692310.jpg
12KB, 179x179px
>>59977543
int bchk(char *str) {
int c=0;
for (int i=0; i<strlen(str); i++) {
switch (str[i]) {
case '[':
c++;
break;
case ']':
c--;
break;
default:
break;
}

if (c < 0)
return -1;
}

return (c != 0);
}
>>
>>59978123
Don't call us, we'll call you.
>>
>>59978266
Aside from the default which is a waste of 2 lines, good job very elegant
>>
File: 1489971650584.jpg (374KB, 720x1280px) Image search: [Google]
1489971650584.jpg
374KB, 720x1280px
>>59977799
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
>>
File: 1490076597636.png (193KB, 290x750px) Image search: [Google]
1490076597636.png
193KB, 290x750px
>>59980179
>chomp
>puts
>eql

Huh, so that's Ruby.
>>
>>59978288
i swear to god /g/ is the most arrogant board on this site
you're all neets/pajeets but post shit like this
>>
>>59978028
But he's speaking the truth.
>>
File: 1489824582602.png (522KB, 1280x824px) Image search: [Google]
1489824582602.png
522KB, 1280x824px
>>
>>59977543
>2
import ast
lst = ast.literal_eval("string representing nested list goes here")
>>
>>59980206

perl did chomp first I'm sure
>>
>>59982905
>>59980206
Yes. "puts" has been in C, too.
>>
>>59977976
How's your CS graduation?
>>
>>59977543

#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?
>>
>>59984236
>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]]
>>
>>59984329

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 ']'.
>>
File: 1490150603219.jpg (428KB, 600x960px) Image search: [Google]
1490150603219.jpg
428KB, 600x960px
>>59984368
Oh I didn't notice that brackets is a dictionary
>>
>>59977543
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)
Thread posts: 29
Thread images: 10


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.