由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - FB Phone Interview Failed by a simple question
相关主题
palindrome int这个recursive能再java上实现么?leetcoede新题Valid Palindrome
请教一个Palindrome Partition问题leetcode 一道题 valid palindrome
大家帮忙看看我的Palindrome II 的解法palindrome partioning II
求教一个, Leetcode 题.请问大牛们Leetcode Palindrome Number 这道题(思路很简单,就是程序写不对)
interleave string 的题目这个Palindrome的Check的代码还有什么可以改进的?
Facebook电话面试总结Facebook 今天的电面
leetcode里的Palindrome partition问题leetcode Palindrome Partitioning
回文数的问题G四次电面面经
相关话题的讨论汇总
话题: return话题: string话题: left话题: start话题: end
进入JobHunting版参与讨论
1 (共1页)
j******8
发帖数: 746
1
FB phone interview, one simple coding question to judge if a string is a
Palindrome.
Gave the Java code of recursive method, then being asked space complexity,
which is O(n). Then gave non-recursive method, which uses constant space. He
seemed satisfied and the interview was over.
But I was told the failure after 2 days. Can anyone suggest what happened on
the earth?
n******n
发帖数: 12088
2
这题用递归没必要啊。

He
on

【在 j******8 的大作中提到】
: FB phone interview, one simple coding question to judge if a string is a
: Palindrome.
: Gave the Java code of recursive method, then being asked space complexity,
: which is O(n). Then gave non-recursive method, which uses constant space. He
: seemed satisfied and the interview was over.
: But I was told the failure after 2 days. Can anyone suggest what happened on
: the earth?

b**********5
发帖数: 7881
3
我记得我去twitter interview的时候, 和我店面的人吃中饭。 然后那个店面的人告
诉我, 他如果觉得你的答案是从网上抄得, 有的时候一个字也不变, 他
automatically reject。。。
我snapchat也两个题, 都答了出来, 也被据。。。 我也没抄什么。。。

He
on

【在 j******8 的大作中提到】
: FB phone interview, one simple coding question to judge if a string is a
: Palindrome.
: Gave the Java code of recursive method, then being asked space complexity,
: which is O(n). Then gave non-recursive method, which uses constant space. He
: seemed satisfied and the interview was over.
: But I was told the failure after 2 days. Can anyone suggest what happened on
: the earth?

s******7
发帖数: 1758
4
FB电面都是leetcode常见题
起码得做两道才能保证过关
一道加follow up多半死菜菜
没办法,大家都刷题刷得bar高了
d*****5
发帖数: 1920
5
recursive space 我觉得是O(n^2), 堆栈里是 n + (n - 2) + (n - 4)...
不一定对,大牛指点下。
再说用recursive感觉没必要。 String长了容易出问题。
b**********5
发帖数: 7881
6
其实, 我觉得这种面, 都看不出能不能够写code。 我最近一个面的一个小公司,
直接就叫我带上laptop, 然后在IDE上写spring MVC的 REST API。。。
当然给我边写能边google。。。 我一边写, 他一边看着我google什么。。。

【在 s******7 的大作中提到】
: FB电面都是leetcode常见题
: 起码得做两道才能保证过关
: 一道加follow up多半死菜菜
: 没办法,大家都刷题刷得bar高了

n******n
发帖数: 12088
7
不是n^2。除非你每次都复制那个串。传两个数组下标就够了

【在 d*****5 的大作中提到】
: recursive space 我觉得是O(n^2), 堆栈里是 n + (n - 2) + (n - 4)...
: 不一定对,大牛指点下。
: 再说用recursive感觉没必要。 String长了容易出问题。

b**********5
发帖数: 7881
8
不过, 我觉得吧, 有的时候, 面试官不flexible些的, 一看你的面相, 或者声音
不爽, 就据了。 feedback 这个yes or no, 就一念之差。。。
d*****5
发帖数: 1920
9
你说的对,看LZ是怎么写的了。

【在 n******n 的大作中提到】
: 不是n^2。除非你每次都复制那个串。传两个数组下标就够了
n******n
发帖数: 12088
10
如果那么写,挂了也不冤

【在 d*****5 的大作中提到】
: 你说的对,看LZ是怎么写的了。
相关主题
Facebook电话面试总结leetcoede新题Valid Palindrome
leetcode里的Palindrome partition问题leetcode 一道题 valid palindrome
回文数的问题palindrome partioning II
进入JobHunting版参与讨论
j********l
发帖数: 325
11
这个题目的话,直接用iterative做呀,否则没时间搞第二道题。

He
on

【在 j******8 的大作中提到】
: FB phone interview, one simple coding question to judge if a string is a
: Palindrome.
: Gave the Java code of recursive method, then being asked space complexity,
: which is O(n). Then gave non-recursive method, which uses constant space. He
: seemed satisfied and the interview was over.
: But I was told the failure after 2 days. Can anyone suggest what happened on
: the earth?

f*****d
发帖数: 2285
12
This question is well known for FB interview.
The interviewers are looking for the most simple and effective code.
Search online for the most simple and effective solution.
b**********5
发帖数: 7881
13
boolean isPalinRecursiveHelper(String s, int[] left, int right) {
if (right >= s.length()) return true;
if (left[0] > right) return true;
boolean isPalin = isPalinRecursiveHelper(s, left, right+1);
if (isPalin==false) return false;
isPalin = (s.charAt(left) == s.charAt(right));
left[0] = left[0]+1;
return isPalin;
}
boolean isPalindrome(String s) {
String sTrimmed = s.trim();
int[] left = new int[1]; left[0] = 0;
return isPalinRecursiveHelper(s, left, 0);
}
b**********5
发帖数: 7881
14
是不是这个?
public boolean isPalindrome(String s) {
int n = s.length();
int i=0; int j = n-1;
while (i <= j) {
while (i < j && !Character.isLetterOrDigit(s.charAt(i)))
i++;
while (i < j && !Character.isLetterOrDigit(s.charAt(j)))
j--;
if (i <= j && Character.toLowerCase(s.charAt(i)) == Character.
toLowerCase(s.charAt(j)))
i++; j--;
else
return false;
}
return true;
}

【在 f*****d 的大作中提到】
: This question is well known for FB interview.
: The interviewers are looking for the most simple and effective code.
: Search online for the most simple and effective solution.

l******n
发帖数: 1250
15
面你的是白人吧, 他们也看面相,如果你没有跟他们深度交流,就可能被挂
P****2
发帖数: 197
16
这题一看就是5分钟热身的。。
l*****8
发帖数: 1083
17
这题真是热身题,两头往中间夹逼做判断就好了,一个循环而已

He
on

【在 j******8 的大作中提到】
: FB phone interview, one simple coding question to judge if a string is a
: Palindrome.
: Gave the Java code of recursive method, then being asked space complexity,
: which is O(n). Then gave non-recursive method, which uses constant space. He
: seemed satisfied and the interview was over.
: But I was told the failure after 2 days. Can anyone suggest what happened on
: the earth?

n******n
发帖数: 12088
18
太罗嗦。三五行足矣
你这是升级版,忽略标点、大小写。

【在 b**********5 的大作中提到】
: 是不是这个?
: public boolean isPalindrome(String s) {
: int n = s.length();
: int i=0; int j = n-1;
: while (i <= j) {
: while (i < j && !Character.isLetterOrDigit(s.charAt(i)))
: i++;
: while (i < j && !Character.isLetterOrDigit(s.charAt(j)))
: j--;
: if (i <= j && Character.toLowerCase(s.charAt(i)) == Character.

e********u
发帖数: 587
19
我觉得应该是那种smoke test让楼主你热身的, 让你不要太紧张, suppose 10分钟甚至
5分钟搞定的, 结果你一热身题做到结束,而且还用他没期待到的不太好的recursive
way, 被挂也正常.
最近准备FB, 也看的比较多的面经,FB这种LC原题,要上来就是bugfree的最优解,才保险
.
b**********5
发帖数: 7881
20
靠, 那你写个不罗嗦的。。。

【在 n******n 的大作中提到】
: 太罗嗦。三五行足矣
: 你这是升级版,忽略标点、大小写。

相关主题
请问大牛们Leetcode Palindrome Number 这道题(思路很简单,就是程序写不对)leetcode Palindrome Partitioning
这个Palindrome的Check的代码还有什么可以改进的?G四次电面面经
Facebook 今天的电面DP通项公式
进入JobHunting版参与讨论
S*******C
发帖数: 822
21
这题用递归即使只传下标也不能通过长String的oj
有没有什么改进方法
我这种写法应该是O(N) time, O(N) space的吧
Runtime Error Message: Line 12: java.lang.StackOverflowError
public boolean isPalindrome(String s) {
if (s == null || s.length() < 2)
return true;
if(!rec(s, 0, s.length() - 1))
return false;
return true;
}
private boolean rec(String s, int start, int end){
if(start >= end)
return true;
if (!Character.isLetterOrDigit(s.charAt(start)))
return rec(s, start+1, end);
if(!Character.isLetterOrDigit(s.charAt(end)))
return rec(s, start, end-1);
if (Character.toLowerCase(s.charAt(start)) != Character.toLowerCase(
s.charAt(end)))
return false;
return rec(s, start+1, end-1);
}

【在 n******n 的大作中提到】
: 不是n^2。除非你每次都复制那个串。传两个数组下标就够了
S*******C
发帖数: 822
22
你的答案质量稍稍有待提高,FB对答案质量要求很高的。
我给你看个最优解
public boolean isPalindrome2(String s) {
if (s == null || s.length() < 2)
return true;
int start = 0, end = s.length() - 1;
while (start < end) {
while (start < end && !Character.isLetterOrDigit(s.charAt(start)
))
start++;
while (start < end && !Character.isLetterOrDigit(s.charAt(end)))
end--;
if (Character.toLowerCase(s.charAt(start++)) != Character.
toLowerCase(s.charAt(end--)))
return false;
}
return true;
}

【在 b**********5 的大作中提到】
: 靠, 那你写个不罗嗦的。。。
y*****e
发帖数: 712
23
天你用不用把大数据case也贴上来。。。。。太吓人了

Prowel,

【在 S*******C 的大作中提到】
: 这题用递归即使只传下标也不能通过长String的oj
: 有没有什么改进方法
: 我这种写法应该是O(N) time, O(N) space的吧
: Runtime Error Message: Line 12: java.lang.StackOverflowError
: public boolean isPalindrome(String s) {
: if (s == null || s.length() < 2)
: return true;
: if(!rec(s, 0, s.length() - 1))
: return false;
: return true;

b**********5
发帖数: 7881
24
你这code, 和我这code, 有他妈的区别么?!

start)

【在 S*******C 的大作中提到】
: 你的答案质量稍稍有待提高,FB对答案质量要求很高的。
: 我给你看个最优解
: public boolean isPalindrome2(String s) {
: if (s == null || s.length() < 2)
: return true;
: int start = 0, end = s.length() - 1;
: while (start < end) {
: while (start < end && !Character.isLetterOrDigit(s.charAt(start)
: ))
: start++;

s*****r
发帖数: 43070
25
你咋这么喜欢pass in int[],别人看着会很费劲,尽量使用final

【在 b**********5 的大作中提到】
: boolean isPalinRecursiveHelper(String s, int[] left, int right) {
: if (right >= s.length()) return true;
: if (left[0] > right) return true;
: boolean isPalin = isPalinRecursiveHelper(s, left, right+1);
: if (isPalin==false) return false;
: isPalin = (s.charAt(left) == s.charAt(right));
: left[0] = left[0]+1;
: return isPalin;
: }
: boolean isPalindrome(String s) {

S*******C
发帖数: 822
26
虽然有很小的区别,但面试官不满意你也没办法
if (i <= j && Character.toLowerCase(s.charAt(i)) == Character.
toLowerCase(s.charAt(j)))
i++; j--;
else
return false;
这里可以2句并一句的

【在 b**********5 的大作中提到】
: 你这code, 和我这code, 有他妈的区别么?!
:
: start)

b**********5
发帖数: 7881
27
你他妈的是在Google干么? 这里用final有用么? 你是要modify那个left的。。。
滚回去学了Java在说!

【在 s*****r 的大作中提到】
: 你咋这么喜欢pass in int[],别人看着会很费劲,尽量使用final
b**********5
发帖数: 7881
28
这种都是借口了。 如果面试官要在这里fail你, 他本来就是要fail你。。。

【在 S*******C 的大作中提到】
: 虽然有很小的区别,但面试官不满意你也没办法
: if (i <= j && Character.toLowerCase(s.charAt(i)) == Character.
: toLowerCase(s.charAt(j)))
: i++; j--;
: else
: return false;
: 这里可以2句并一句的

c**a
发帖数: 324
29
尼玛报错信息也打出来
刷屏啊
c****h
发帖数: 344
30
你这是FB,所以觉得很不爽。
我之前有个面试,约了,改时间,来来回回好几次,然后最后终于面了,不到10分钟。
大概是那句话说错了,或者人根本一开始就不打算招。
相关主题
请教一道面试题请教一个Palindrome Partition问题
Interleave Strings那个题目有O(n)时间 O(1)空间算法么?大家帮忙看看我的Palindrome II 的解法
palindrome int这个recursive能再java上实现么?求教一个, Leetcode 题.
进入JobHunting版参与讨论
s*****r
发帖数: 43070
31
你的left和right是两端的position吗,为毛开始都是0,为毛在循环里面都是增量,为
毛不在recursive之前检测,还少一个结束的case,left==right
你是故意写成这样还是本来就如此啊

【在 b**********5 的大作中提到】
: 你他妈的是在Google干么? 这里用final有用么? 你是要modify那个left的。。。
: 滚回去学了Java在说!

I*******m
发帖数: 10
32
这个是前几天有人问我,我的答案:
public boolean isPalandrome(String s)
{
if (s != null)
{
for (int i= 0; i < s.length()/2; i++)
{
if (s.charAt(i) != s.charAt(s.length() - i -1))
{
return false
}
}
}
return true;
}
a******n
发帖数: 103
33
bool isPalindrome(string s){
return help(s,0,s.size()-1);
}
bool help(string &s, int left, int right){
if (left>=right)
return true;
return s[left]==s[right] && help(s,left+1,right-1);
}
s*****r
发帖数: 43070
34
女学霸你好

【在 a******n 的大作中提到】
: bool isPalindrome(string s){
: return help(s,0,s.size()-1);
: }
: bool help(string &s, int left, int right){
: if (left>=right)
: return true;
: return s[left]==s[right] && help(s,left+1,right-1);
: }

l*****k
发帖数: 1059
35
我interview别人很久了。如果interview提前结束,那么肯定是
interviewer觉得不需要继续了。也就是说,要么特别好,要么
特别烂。这个很容易分辨。
有人说我都做出来了为什么还被拘,这个原因多了。最常见的一点,
你的code太烂或者有bug自己没看出来。 还可能是他觉得你的反应
太快太假。或者英语太烂他听不明白等等。
没啥办法,move on吧。Good luck next time.
S*******C
发帖数: 822
36
这个没有考虑大小写字母和去除非字母
leetcode oj上面的题需要考虑这2个
你改一下看看能不能过oj

【在 a******n 的大作中提到】
: bool isPalindrome(string s){
: return help(s,0,s.size()-1);
: }
: bool help(string &s, int left, int right){
: if (left>=right)
: return true;
: return s[left]==s[right] && help(s,left+1,right-1);
: }

a******n
发帖数: 103
37
bool isPalindrome(string s) {
return help(s,0,s.size()-1);
}
bool help(string &s, int left, int right){
if (left>=right)
return true;
while (left left++;
}
while (right>=0 && !isValid(s,right))
right--;
return (s[left]==s[right] || abs(s[left]-s[right])=='a'-'A') && help
(s, left+1,right-1);
}
bool isValid(string & s, int i)
{
if ((s[i]>='0' && s[i]<='9') || (s[i]>='a' && s[i]<='z') || (s[i]>='
A' && s[i]<='Z'))
return true;
return false;
}

【在 S*******C 的大作中提到】
: 这个没有考虑大小写字母和去除非字母
: leetcode oj上面的题需要考虑这2个
: 你改一下看看能不能过oj

a******n
发帖数: 103
38
其实我是无业女学渣,求工作求refer

【在 s*****r 的大作中提到】
: 女学霸你好
S*******C
发帖数: 822
39
这个答案是对的,也能通过OJ
但改成JAVA版就是不能过大的test case
public boolean isPalindrome(String s) {
if (s == null || s.length() < 2)
return true;
return rec(s, 0, s.length() - 1);
}
private boolean rec(String s, int start, int end){
if(start >= end)
return true;
while (start < end && !Character.isLetterOrDigit(s.charAt(start)))
start++;
while (start < end && !Character.isLetterOrDigit(s.charAt(end)))
end--;
return Character.toLowerCase(s.charAt(start)) == Character.
toLowerCase(s.charAt(end))
&& rec(s, start+1, end-1);
}

【在 a******n 的大作中提到】
: bool isPalindrome(string s) {
: return help(s,0,s.size()-1);
: }
: bool help(string &s, int left, int right){
: if (left>=right)
: return true;
: while (left: left++;
: }
: while (right>=0 && !isValid(s,right))

a******n
发帖数: 103
40
大的test case,stack就爆掉了。
这道题还是不要recursive的好。

【在 S*******C 的大作中提到】
: 这个答案是对的,也能通过OJ
: 但改成JAVA版就是不能过大的test case
: public boolean isPalindrome(String s) {
: if (s == null || s.length() < 2)
: return true;
: return rec(s, 0, s.length() - 1);
: }
: private boolean rec(String s, int start, int end){
: if(start >= end)
: return true;

相关主题
求教一个, Leetcode 题.leetcode里的Palindrome partition问题
interleave string 的题目回文数的问题
Facebook电话面试总结leetcoede新题Valid Palindrome
进入JobHunting版参与讨论
b**********5
发帖数: 7881
41
你自己去看吧。 后面那个recursive, 不是真的recursive solution。 我如果给你
个限制, 就是你一开始不知道string 的length怎么办?

【在 s*****r 的大作中提到】
: 你的left和right是两端的position吗,为毛开始都是0,为毛在循环里面都是增量,为
: 毛不在recursive之前检测,还少一个结束的case,left==right
: 你是故意写成这样还是本来就如此啊

b**********5
发帖数: 7881
42
这么说吧, 如果给你个char* in C, 然后还不告诉你这个char*有多长, 只告诉你
end是 \0, 要recursive, 你怎么做?
e*l
发帖数: 11
43
isLetterOrDigit算常用的方法嗎?
b**********5
发帖数: 7881
44
算啊
我以前的team, 还特别爱用google guava的library, String。isNullOrEmpty!

【在 e*l 的大作中提到】
: isLetterOrDigit算常用的方法嗎?
Y*****2
发帖数: 38613
45
You are all too smart

【在 b**********5 的大作中提到】
: 你自己去看吧。 后面那个recursive, 不是真的recursive solution。 我如果给你
: 个限制, 就是你一开始不知道string 的length怎么办?

h****3
发帖数: 89
46
感觉是不是楼主忘了考虑特殊情况?
比如说问清楚特殊字符要不要考虑 ? 比如 #xx# 算不算数
数字要不要考虑, 飞数字字母的情况能不能算做palindrome ?
有可能你写的code是对的,但面试官期待你会考虑到一些特殊情况,至少写code前先把
特殊情况怎么处理交代清楚
j******8
发帖数: 746
47
主要是没有及时赶到家,路上交通堵塞。所以时间很紧,问了一个问题就没时间了。

【在 h****3 的大作中提到】
: 感觉是不是楼主忘了考虑特殊情况?
: 比如说问清楚特殊字符要不要考虑 ? 比如 #xx# 算不算数
: 数字要不要考虑, 飞数字字母的情况能不能算做palindrome ?
: 有可能你写的code是对的,但面试官期待你会考虑到一些特殊情况,至少写code前先把
: 特殊情况怎么处理交代清楚

1 (共1页)
进入JobHunting版参与讨论
相关主题
G四次电面面经interleave string 的题目
DP通项公式Facebook电话面试总结
请教一道面试题leetcode里的Palindrome partition问题
Interleave Strings那个题目有O(n)时间 O(1)空间算法么?回文数的问题
palindrome int这个recursive能再java上实现么?leetcoede新题Valid Palindrome
请教一个Palindrome Partition问题leetcode 一道题 valid palindrome
大家帮忙看看我的Palindrome II 的解法palindrome partioning II
求教一个, Leetcode 题.请问大牛们Leetcode Palindrome Number 这道题(思路很简单,就是程序写不对)
相关话题的讨论汇总
话题: return话题: string话题: left话题: start话题: end