由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - bing的screening question,没回音了,帮忙看问题在哪
相关主题
一道小题cc1501.3题,请帮忙测试下代码
Microsoft screening programming problem讨论一下FB的经典题read和readline吧
large file的一道题请问大牛们关于Regular expression matching
[合集] G家onsite面经fb 电面
regex 用DP做对不对啊?急问F家面试一题
wildcard string matching,谁有最简洁的非递归解法?问个Zenefits电面题目,他家好难。。。
贡献一个G家电面Regular expression matching 在什么输入下时间复杂度是O(2^n)?
H1B 概率最低事多少(对于adv degree)facebook电面题目
相关话题的讨论汇总
话题: ileft话题: ch1话题: abcdefg话题: ch2话题: iright
进入JobHunting版参与讨论
1 (共1页)
s*******f
发帖数: 1114
1
using System;
using System.Collections.Generic;
using System.Text;
namespace MSC
{
class Program
{
//“bool F(string s, char ch1, char
ch2, int n)”
//The function determines whether
or not there exists an occurrence of
//ch1 and ch2 separated by a
distance of no more than n in the given
//string s, where s is ascii and
user entered (your function needs
//to work on any input.) The
function must be efficient and
//**optimized** for both space and
time. Please state what the
//complexity of your solution is.
//The time complexity of this
solution is O(N), where N is s.length,
//because the function only scan
the string 1 time.
//The space complexity is O(1),
since no additional data structures
//are used, except some local
variables.
static bool F(string s, char ch1,
char ch2, int n)
{
if (string.IsNullOrEmpty(s) ||
n < 1)
return false;
if (ch1 == ch2)
{
int iLeft = s.IndexOf(ch1);
if (-1 == iLeft)
{
return false;
}
int iRight = s.IndexOf(ch1,
iLeft + 1);
while (-1 != iRight)
{
if (iRight - iLeft <=
n)
{
return true;
}
else
{
iLeft = iRight;
iRight =
s.IndexOf(ch1, iLeft + 1);
}
}//while
}//if
else
{
int iLeft = int.MaxValue;
char chLeft = '\0';
int i = 0;
for (; i < s.Length; ++i)
{
if (s[i] == ch1 || s[i]
== ch2)
{
iLeft = i;
chLeft = s[i];
break;
}
}
++i;
for (; i < s.Length; ++i)
{
if (s[i] == ch1 || s[i]
== ch2)
{
if (chLeft == s[i])
{
iLeft = i;
}
else
{
if (i - iLeft
<= n)
{
return
true;
}
iLeft = i;
chLeft = s[i];
}
}//if
}//for
}//else
return false;
}//end
static void Main(string[] args)
{
Console.WriteLine(F("abcdefg",
'b', 'd', 2));
Console.WriteLine(F("abcdefg",
'b', 'd', 20));
Console.WriteLine(F("abcdefg",
'b', 'e', 1));
Console.WriteLine();
Console.WriteLine(F("abcdefg",
'a', 'b', 0));
Console.WriteLine(F("acbabcd",
'a', 'b', 1));
Console.WriteLine(F("abcdefg",
'x', 'y', 20));
Console.WriteLine(F("abcdefg",
'\0', 'e', 20));

Console.WriteLine(F("abc\0defg", '\0', 'e',
2));
Console.WriteLine();
Console.WriteLine(F("abcdefga",
'g', 'g', int.MaxValue));
Console.WriteLine(F("abcdefga",
'z', 'z', 20));
Console.WriteLine(F("abcdefga",
'a', 'a', 7));

Console.WriteLine(F("abcdefgaa", 'a', 'a',
1));
Console.WriteLine();
Console.WriteLine(F("a", 'a',
'a', 20));
Console.WriteLine(F("a", 'a',
'b', 20));

Console.WriteLine(F("abccccccdefga", 'c',
'e', 2));

Console.WriteLine(F("abccccccdefga", 'c',
'e', 1));
Console.WriteLine(F("abcdefg",
'a', 'g', int.MinValue));
Console.WriteLine();
Console.WriteLine(F("a牛cdefg",
'牛', 'd', 2));
Console.WriteLine(F("a牛马defg",
'牛', '马', 1));
Console.WriteLine(F("a马啊马
defg", '马', '马', 2));
Console.WriteLine(F("a马啊马
defg", '马', '马', 1));
}
}
}
s*********l
发帖数: 103
2
Question:
Does the order of ch1 and ch2 matter?
Suggestions:
(1) Make a class to represent test cases containing input, expected output
, and also provide a test method that evaluates a test case by calling the
function to be tested
(2) Organize your test cases, specify what scenario you want to test using
each test case
(3) After running your test program, you should know how many cases failed
and what are these failure cases.
s*******f
发帖数: 1114
3
the order of ch1 and ch2 --no matter.
u are right. I haven't QA experience.


cases containing input, expected output
evaluates a test case by calling the
what scenario you want to test using
you should know how many cases failed

【在 s*********l 的大作中提到】
: Question:
: Does the order of ch1 and ch2 matter?
: Suggestions:
: (1) Make a class to represent test cases containing input, expected output
: , and also provide a test method that evaluates a test case by calling the
: function to be tested
: (2) Organize your test cases, specify what scenario you want to test using
: each test case
: (3) After running your test program, you should know how many cases failed
: and what are these failure cases.

1 (共1页)
进入JobHunting版参与讨论
相关主题
facebook电面题目regex 用DP做对不对啊?
Time complexitywildcard string matching,谁有最简洁的非递归解法?
有人面了Amazon Intern的吗贡献一个G家电面
leetcode 上的 two sumH1B 概率最低事多少(对于adv degree)
一道小题cc1501.3题,请帮忙测试下代码
Microsoft screening programming problem讨论一下FB的经典题read和readline吧
large file的一道题请问大牛们关于Regular expression matching
[合集] G家onsite面经fb 电面
相关话题的讨论汇总
话题: ileft话题: ch1话题: abcdefg话题: ch2话题: iright