Role: Software Engineer - iOS Position
Verdict: Rejected (got the response 1 week after asking for update)
This was a Google Meets interview with a Sr. SWE on the iOS team.
Given a target, print all possible parenthesis combination.
For example: target = 3, output =
((())) (3 open, 3 close)
()()()
(())()
()(())
....
Answer:
def shouldSwap(string, start, curr):
for i in range(start, curr):
if string[i] == string[curr]:
return 0
return 1
# Prints all distinct permutations
# in str[0..n-1]
def findPermutations(string, index, n):
if index >= n:
print(''.join(string))
return
for i in range(index, n):
# Proceed further for str[i] only
# if it doesn't match with any of
# the characters after str[index]
check = shouldSwap(string, index, i)
if check:
string[index], string[i] = string[i], string[index]
findPermutations(string, index + 1, n)
string[index], string[i] = string[i], string[index]
def permutationOfString(targetNumber):
preprocessString = "(" * targetNumber + ")" * targetNumber
return findPermutations(list(preprocessString), 0, len(preprocessString)-1)
permutationOfString(3)I wasn't able to get this answer during the interview, leading to a reject.