Balance parenthesis by removal, generate fibonacci.
Respuestas de entrevistas
Anónimo
12 jul 2017
Remove extra parenthesis with O(N) space and time complexity. Give a good solution to fibonacci that isn't the super complicated one that would take 45 minutes to draft.
Anónimo
24 ago 2017
Fibonacci in O(n) time O(1) space:
public int fibonacci(int n) {
if (n == 1) return 1
int prev = 0, cur = 1;
for(int i = 2; i <= n; i++} {
int tmp = prev;
prev = cur;
cur = prev + cur;
}
return cur;
}
Anónimo
24 ago 2017
Balance Parenthesis
public static String balanceParenthesis(String s) {
StringBuilder str = new StringBuilder(s);
int left = 0;
for(int i = 0; i 0) {
left--;
} else {
str.deleteCharAt(i--);
}
}
}
int right = 0;
for(int i = str.length() - 1; i >= 0; i--) {
if(str.charAt(i) == ')') {
right++;
} else if(str.charAt(i) == '('){
if(right > 0) right--;
else {
str.deleteCharAt(i);
}
}
}
return str.toString();
}
Anónimo
19 ene 2018
Hi can you specify some question that we asked during the on site interview ? What was asked to code in the demo?