i***1 发帖数: 95 | 1 Write a program to enumerate all possiblities.
3^6 = 729
Then compare them.
The trick is how to compare two layouts. Another exercise. Done.
Is this a programming position? |
|
i***1 发帖数: 95 | 2 if (the number of element is less than around 20), we can enumerate all
posibilities using bits related method.
else {
//DP. suppose there are N positive numbers V[1] to V[N] and we need to
reach sum S
Possiblity[S,N] stores the final answer
And Possiblity[A,B] stores the number of possibility to sum to A using
the first B numbers
Possiblity[A,B] = possiblity[A-V[B],B-1] + possibility[A,B-1]
} |
|
i*****e 发帖数: 113 | 3 我的解法,楼上有解法,我纯粹做练习的
S(n, k) = S(n-1, k-1) + S(n-1, k)
const int array[LEN]; // global or class member
std::list*> result; // global or class member
void enumerate(int k, int start, const vector& part)
{
if (part.size() == k) { // part.size() is unlikely greater than k
result.push(new vector(part));
return;
}
if (start >= LEN) {
return;
}
vector* v = new vector(part);
v->push_back(array[start]);
enumerat |
|
c**********e 发帖数: 2007 | 4 What is the size of an enumeration type?
a) sizeof(size_t)
b) 2
c) 4
d) sizeof(int)
e) implementation-defined |
|
h*****g 发帖数: 944 | 5 Q1)
what are the variable types in the statement below?
int * x, y;
a) both x and y are of type int *
b) x is of type int* and y is of type int
c) x is of type int and y is of type int*
d) both x and y are of type int
我选的是b
Q2)
which of the following is a correct declaration for a pointer to a function
that returns a double and takes no arguments?
a) double (*ptr_function)(void);
b) double (ptr_function)(void);
c) double ptr_function(void);
d) double *ptr_function(void);
Q3)
Which of the followi... 阅读全帖 |
|
s******5 发帖数: 673 | 6 面试的人说话超级快。。。整个过程一共20分钟
1. your biggest technical challenge.
2. why are you leaving current company?
technical:
1. your favorite data structure...why? (ArrayList, Hashtable) How much time
will you spend to search an element in Hashtable...
2. different between hashmap vs hashtable? any performance different? how to
handle the hash collision? How much time will you spend to search an
element if a collision occurred.
3. what is a good hash function?
4. inheritance vs composition. why use one to ant... 阅读全帖 |
|
l***i 发帖数: 1309 | 7 There are two ways, easy and hard.
The easy way would be using python or java BigInteger
The hard way is to write your own bigint or use GNU GMP.
Actually facebook is evil, in the testcases they just enumerate all primes
less than 500... |
|
y*********e 发帖数: 518 | 8 这个yield return只是一个syntax sugar, 只能用于来写iterator.
尤其是这个面试题,要记住状态,满麻烦的.若是只是想,我就写一个inorder traversal,
那就容易多啦!yield return就是让开发者只需要按照traversal的思路写,然后在访问
每一个节点的时候,yield return下便是了!
比如,这个很简单的例子.给定一个array,来写一个iterator:
int[] intArray;
.......
for (int i = 0; i < intArray.Length; i++)
yield return intArray[i];
编译器会自动把如上的代码转换成,创建一个iterator,然后每执行current()一次,就从
array里面提取一个对象,如下:
class __intArrayEnumerator // C#里面把iterator叫Enumerator
{
private int[] __object;
private int __state;
public int... 阅读全帖 |
|
o******e 发帖数: 81 | 9 5分钟前刚结束,本来约好45分钟的,结果30分钟就结束了,最后我还问了他几个问题
不知道提前结束是好是坏,他说就2个问题,只不过第一个题code写的不clean而且有一
个很严重的bug
上来连寒暄都没有就开始coding,让我纸上写同时电话里念,多少干扰了我的思路
1. string GetCommonPrefix(string[] strs)
我就是index从0起,扫描每个string在index位置的char,如果string结束或者跟第一
个string 在index位置的char不match就break
结果code不是很clean,用了一个while(true)和multi returns,他看来不怎么喜欢。
最大问题是忘了index++,被他指出来死循环了我才发现:(
2. C# iterator (with yield return) for binary tree, in-order
这个比较简单,我问他要递归的还是非递归的,他说递归的不可能work,我说应该work
就给他一个递归的,大概5-6行code
然后告诉他这个不efficient,因为create太多的... 阅读全帖 |
|
F****n 发帖数: 3271 | 10 Logic Theory is not coming from Mathematics, either. The marriage of Logic
and Math is a 20th century event. CS is essential to modern logic theory,
which aims to find out how truth can be manipulated MECHANICALLY (this is a
CS concept). If you know something about today's logic, you will be familiar
with a lot of theories with terms such as "recursively enumerable". That's
the mark of CS. |
|
d*******r 发帖数: 208 | 11 Thanks for sharing. seems current trend of interview prefers permutation and
combination questions. something like print all paths, enumerate all
possibilities. |
|
b******e 发帖数: 3348 | 12 ☆─────────────────────────────────────☆
littlebolt (i love bolt) 于 (Thu Jun 16 14:13:42 2011, 美东) 提到:
签了nda,phone和onsite写一起了
1.把一个字符串转成float,字符串可能是负的一百点三还有个指数E-09这样的
2.反转单链表..
3.给一个整数,求next permutation 就是数字组成一样的 但是比这个数大的最小的一
个数
4.一个很大的文件 怎么去掉duplicate
5. circular sorted array找元素
6.分层打印tree
7.一个字符串,每个字符可以替换成好多其他字符,打印所有可能
8.很简单的一个题,就是会用vector, set, map, pair这些玩意就行了
9.应该还有一个题,不难,但是怎么都想不起来了...
效率很高,拒信很快,move on啦~~
☆─────────────────────────────────────☆
gate (离开之后,再见以前) 于 (Thu Jun 16 14:17:... 阅读全帖 |
|
b*******a 发帖数: 68 | 13 看看我的想法有没有问题,谢谢。
1. 给定一串浮点数,要求转成string, 转化完成后要求假如要排序的话,string的顺
序和对应的原来数的排序一样。
浮点数字符串排序关键是比较函数,或者转换回数字比较,或者直接比较,只要是普通
的表达方法(即不是科学计数法之类),先处理+/-,然后比较小数点所在位置,最后
若位置相同,则依次比较数字字符不就可以了?
4. 有10个unsorted array, 分给10太不同的机器处理,这10台机器之间不能通信,但
可以和总机通信,如何求总的median. 如何减少数据量的传输。
每个node先遍历一遍,统计数字落在不同区间(可根据需要划分)的个数,然后各node
将此信息送到master,master就可以确定golbal medium在哪个区间,再回到各node,各
node进行第二遍scan,把此区间的数字送到master,master再划分更细区间,最后排序。
5. 每个电话号码都对应字母,打印出通过按号码能生成的所有valid的英文词,用作号
码里的单词用,比如1-800-432-JUNK里面的JUNK.
此题目似乎不是很清晰,如果是如... 阅读全帖 |
|
n**********8 发帖数: 188 | 14 可以通过subset sum来证明这个问题是NP-hard:
给定一个subset sum的问题instance:f[1..n]和target_sum,我们可以通过调用avg_
partition的solution来解决这个instance in poly time。方法如下:
1)先假设f中有一个大小为m的subset加起来为target_sum(虽然我们并不知道m是多少
,但我们可以enumerate m = 1..n)
2) 现在给定m,在f的基础上添加3个elements来构造一个新的数组g,然后我们可以证
明把avg_partition的solution在g上run一下,它能找出的解必然和f上subset sum的解
一一对应
2.1)首先加一个数x such that: target_sum/(m+1) 和(SUM(f[1..n])+x-target_sum)
/(n-m+2) 一样大
2.2)其次再加2个数a和b,他们分别为a=10^10*(m+1) 和 b=10^10*(n-m+2),这里10^
10可以换成任何一个非常大或者非常小的数(这样导致它完全不和f里面的数在同... 阅读全帖 |
|
s**x 发帖数: 405 | 15 This is exponential time, but not NP-complete. |
|
s******c 发帖数: 1920 | 16 第二题:
对list1生成一个摘要(比如一个hashtable或者一个bloom filter)
然后在enumerate list2中的每个元素, 检查其是否hit那个摘要, 并记录所有结果为
positive的元素,存入list2'
然后对于list2' 的元素再做一遍摘要来筛一遍list1 得到list1'
这时list1'和list2'的元素已经很相近了,再来分别sort一下,然后来找.
对于巨大的文件, 上述两个筛数的过程可以用mapreduce来完成.
you
will
in
l*
amotized |
|
b******d 发帖数: 1948 | 17 yeah, agree,
Person is a type, same, Disability is another type.
Person has a property, 'disability', of Collection type.
If collection is empty, this is a normal healthy human being.
Disability could be an Enumeration. |
|
p*u 发帖数: 136 | 18 1, get the ending days of N ranges, then sort increase and unique
2, enumerate the sorted days, from lower to higher:
on this day, find out the employees whose ending day is this day: then
according to the events they have attended, decide you should schedule 0, 1
or 2 events on this day; and update the events other employees have attended.
3, get the final number of days to schedule events
but the algorithm complexity is O(NlogN) |
|
p*u 发帖数: 136 | 19 1, get the ending days of N ranges, then sort increase and unique
2, enumerate the sorted days, from lower to higher:
on this day, find out the employees whose ending day is this day: then
according to the events they have attended, decide you should schedule 0, 1
or 2 events on this day; and update the events other employees have attended.
3, get the final number of days to schedule events
but the algorithm complexity is O(NlogN) |
|
l*****a 发帖数: 14598 | 20 估计就是看你对iterator/enumerator的理解/实现吧 |
|
p*****2 发帖数: 21240 | 21
还真是。刚才查了一下,说vector不支持iterator, 还是enumeration, 所以就是考察
从enumeratoion 转到iterator? |
|
l*****a 发帖数: 14598 | 22 wait, vector is from C++/STL,it should support iterator
IEnumerable/Enumerator are from C#.. |
|
d********w 发帖数: 363 | 23 problem: Enumerate points that satisfy the following constraints in 3
dimensions:
1. x + y + z = 1
2. 0 <= x, y, z <= 1
3. x, y and z are multiples of a given increment between 0-1
Example:
increment = 0.5
x y z
-------------
0 0 1
0 .5 .5
0 1 0
.5 0 .5
.5 .5 0
1 0 0 |
|
l***i 发帖数: 1309 | 24 The matrix problem.
If the matrix is not too big, then you can treat all possible 0,1 matrix as
a node and do BFS.
If the matrix is big but one of its dimension is small, say, it is m rows
and n columns, and let n<=m and n <=20
then you can enumerate the first row with 2^20, which maps to a 20 bit
integer, each bit indicates whether button mat[0][j] is pushed or not. Once
you have the first row, the rest rows are determined. This algorithm can do
20 x 1000 within seconds.
Useful observations are... 阅读全帖 |
|
g****y 发帖数: 240 | 25 第二题,只需要把第一个string中的数字map到第二个string的order就好了。
def reorder(str, order_str):
d = {c:i for i, c in enumerate(order_str)}
str = [c for c in str]
def get_key(c):
if c in d:
return d[c]
else:
return len(d)
str.sort(key=get_key)
return "".join(str) |
|
l***i 发帖数: 1309 | 26 In peking2's solution, option 2 seems faster, as number of primes less than
n is about n/ln(n)
for 10M, your number is at most 7 digits, and for each length from 1 to 7,
try to generate all symmetric numbers, this implies you only need to
enumerate 0-9 for at most 4 digits on the left, the other 3 on the right is
fixed. So you have at most 10^4 choices for length=7, and for other length
you have no more. So total numbers to try (they are symmetric) is at most 7
* 10^4 = 10^5
For each number, sin... 阅读全帖 |
|
s*********l 发帖数: 103 | 27 # The most beautiful substring
def f(s):
if len(s) <= 1:
return s
s1, s2 = split(s)
return ''.join(s1 + [c for c in f(s2)])
def split(s):
arr = [c for c in s]
last_seen = {}
max_v = 0
max_ind = -1
for i, c in enumerate(arr):
if c > max_v:
max_v = c
max_ind = i
last_seen[c] = i
i = max_ind - 1
s1 = [max_v]
while (i >= 0):
if last_seen[arr[i]] == i or arr[i] > s1[0]:
if arr[i] in s1:
... 阅读全帖 |
|
s*********l 发帖数: 103 | 28 # The most beautiful substring
def f(s):
if len(s) <= 1:
return s
s1, s2 = split(s)
return ''.join(s1 + [c for c in f(s2)])
def split(s):
arr = [c for c in s]
last_seen = {}
max_v = 0
max_ind = -1
for i, c in enumerate(arr):
if c > max_v:
max_v = c
max_ind = i
last_seen[c] = i
i = max_ind - 1
s1 = [max_v]
while (i >= 0):
if last_seen[arr[i]] == i or arr[i] > s1[0]:
if arr[i] in s1:
... 阅读全帖 |
|
y****9 发帖数: 252 | 29 “不让用循环,不让用递归”这里提供C#解法
Enumerable.Range(1, 100).Sum();
不考算法,不用递归循环,还不考公式,那就考语法糖 |
|
c********t 发帖数: 5706 | 30 这个店面够狠啊,要求很高
如果是我,我就先写出来重复代码的,再简化,否则非陷入到判断逻辑混乱中不可。
先定义method如下, asc是升序, type是enumerate
type=1 找出小于这个key的最大元素
type=2 找出大于这个key的最小元素
type=3 找出这个key本身
type=4 找出小于或者等于这个key的最大元素
type=5 找出大于或者等于这个key的最小元素
int findKey(int[] arr, int key, boolean asc, int type){
}
程序外包给大牛们完成吧。 |
|
n***i 发帖数: 777 | 31 this optimal point must be one of the point on the 2d matrix (equally
optimal is possible if not choose one of the point on the 2D matrix)
enumerate all the cases
meeting |
|
d**********x 发帖数: 4083 | 32 1.
Piece is a general interface, which can be implemented as concrete types,
interface may include possible moves given the settings on board (arguable);
getter for name; getter for display configuration (arguable); color...
Board will store and manage positions of all Pieces. Sierialization may be
required since users could save and resume games. Board provides methods to
move, change, remove, add (for undo) pieces by name/reference/position/
enumeration.
Use patterns like builder pattern to ge... 阅读全帖 |
|
k*********6 发帖数: 738 | 33 感觉不就是enumerate 一堆case吗?还是我没有领悟到精髓。。。 |
|
r*******n 发帖数: 3020 | 34 难道用map reduce?
def map_function(array):
for i, each in enumerate(array):
EmitKeyValue((i,each), 1) // use index and array[index] as key
// to make duplicate elements unique
def reduce_function(key, iterator v):
if sum(v)==4:
EmitKeyValue(key) //this is the key in 4 arrays.
way |
|
b*********s 发帖数: 115 | 35 array hooper
给一个array,每个元素都是大于等于0的数字,每个数字代表可以向右跳的最大步数。
从第一个元素出发,要跳出数组。跟leetcode的jump gameII差不多,区别在于
1. 这里要求跳出数组,leetcode是要求跳到最后一个元素
2. 如果能跳出数组,给出其中一组最少步数的跳法,如不能跳出,输出failure。
leetcode是只要求给出答案能不能跳到最后
examples:
input: 1, 1 output: 0, 1, out
input: 2, 1, 3, 1, 1 output: 0, 2, out
input: 5, 6, 0, 4, 2, 4, 1, 0, 0, 4 output: 0, 5, 9, out
input: 1, 2, 1, 0, 2 output: failure
我的代码是
def hopper(a):
a.append(0)
path = []
cur = 0
maxCenter = 0
maxRange = 0
for i, n in enumerat... 阅读全帖 |
|
p****o 发帖数: 46 | 36 ok, I only had a glimpse on a.append(0), and quickly skip it... :-), have
not written python for quite some time.
then I think it is correct. but personally, I feel it is tricky to append "0
" at the end of input, and also the input has to change. Another
controversial case is the empty input, you will output "out".
Well, maybe the reviewer did not see that "append", or did not think too
much. or there is still something wrong we have not checked out.
Your code is not far from not modifying inpu... 阅读全帖 |
|
l******s 发帖数: 3045 | 37 A validated C# Enumerator solution.
public class EmbeddedList : IEnumerable{
private bool isValue;
private T val;
private IList> ElementList = new List>();
public EmbeddedList() { isValue = false; }
public EmbeddedList(T t) { val = t; isValue = true; }
public void Add(T t){
EmbeddedList newElement = new EmbeddedList(t);
ElementList.Add(newElement);
}
public void Add(EmbeddedList E) { ElementList.Ad... 阅读全帖 |
|
l******s 发帖数: 3045 | 38 A validated C# Enumerator solution.
public class EmbeddedList : IEnumerable{
private bool isValue;
private T val;
private IList> ElementList = new List>();
public EmbeddedList() { isValue = false; }
public EmbeddedList(T t) { val = t; isValue = true; }
public void Add(T t){
EmbeddedList newElement = new EmbeddedList(t);
ElementList.Add(newElement);
}
public void Add(EmbeddedList E) { ElementList.Ad... 阅读全帖 |
|
t**8 发帖数: 4527 | 39 very easy to confirm
a,b (a < b)
c, d (c < d)
1. enumerate a< c, ...... a > c .....
2 . more simple solution
pointX (a, b), pointY (c, d)
because 0 < a < b and 0 < c < d
pointX and pointY is in range less than 45 degree from the vertical
ASIX, mirror PointY to the 45 scope line. etc. compare
two distance |a -c| + |b -d| pretty easy |
|
p**o 发帖数: 3409 | 40 # Q1
import random
def compute_index (input):
counter = {}
for i, x in enumerate(input):
counter.setdefault(x, []).append(i)
indices = max(counter.itervalues(), key=len)
return random.choice(indices)
>>> compute_index([3,7,4,3,6,1,3,6]) |
|
u*******g 发帖数: 224 | 41 十年前学过JAVA, 现在决定从新捡起来。 买了书,翻了一下,很多都能回忆起来了。
但是有些很不熟悉,也许老师当时没有cover 。 我来列一下它的章节,大牛看看我
哪些暂时能跳过不看, 也能应付找工?
我已复习完1-6 章了。 后面的,我打算只看 8 (Packages and Interfaces)和11
(Using I/O). 这样偷懒行吗?大牛指指我那哪些必看? 实在时间紧张。。。
JAVA : A beginner’s Guide (by Herbert Schildt)
1. Java Fundamentals
2. Introducing Data Types and Operat ors
3. Program Control Statements
4. Introducing Classes, Objects, and Methods
5. More Data Types and Operator
6. A Closer Look at Methods and Classes
7. Inheritance
8. ... 阅读全帖 |
|
t***t 发帖数: 6066 | 42 you should read 7,8,9,11,12,13, ignore 10,14,15
7. Inheritance
8. Packages and Interfaces
9. Exception Handling
10. Using I/O
11. Multithreaded Programming
12. Enumerations, Autoboxing and Static Import
13. Generics
14. Applets, Events and Miscellaneous Topics
15. Introducing Swing |
|
p**o 发帖数: 3409 | 43 (Please use monospaced font to read)
Example:
i: 0 1 2 3 4 5 6 7 8 9
S0: a a b x c a b x c b
T0: a b c b
expected output: [5,10)
n=len(S0), m=len(T0)
Collect indices in S0: O(n) time
a: 0 1 5
b: 2 6 9
c: 4 8
I wanted to use dynamic programming,
but I did not find any optimal substructure.
So I chose to backtrack on these indices instead.
T0: a b c b
i: 0 1 2 3 4 5 6 7 8 9
S0: a a b x c a b x c b
S1: a _ b _ c _ b _ _ _ -> [0,7)
S2: a _ b _ c _ _ _ _ b -> [0,10)
S3: a _ b _ _ _ _ _ c b -> [0... 阅读全帖 |
|
f****8 发帖数: 33 | 44 Thanks sharing!
The key point for this problem is that how to discover the neighbor nodes:
Find the neighbor nodes by constructing and searching them in the dict (for
each found node in last round, need 25 x strlen times string comparing),
rather than enumerating all the remain nodes in the dict (for each found
node in last round, need dict.size() comparing). |
|
x*******9 发帖数: 138 | 45 def get_next(needle):
l = len(needle)
nexts = [0 for i in xrange(l + 1)]
nexts[0] = -1
i, j = 0, -1
while i < l:
while j >= 0 and needle[i] != needle[j]:
j = nexts[j]
i += 1
j += 1
nexts[i] = j
return nexts
def get_prefix_match(S):
nexts = get_next(S)
print S
print nexts
for i, u in enumerate(nexts):
if u <= 0:
continue
v = u
print '>>', S[:u], "\t[0...%d]" % u, S[i - u: i], "\... 阅读全帖 |
|
n*n 发帖数: 157 | 46 我常用的 python 内建函数:
len
enumerate
print
sort
range/xrange
map
zip
format
open
close |
|
c******n 发帖数: 4965 | 47 ok, 你意思说 所有dictionary word 在一个hashmap 里面o(1) time 可以决定是不是
存在?
然后穷举S 的所有enumeration(keep letter order), 看是不是match ? |
|
c******n 发帖数: 4965 | 48 G 家的1,2 都是enumeration 来做对吗?
另外毛子那题要可以朝左还是用一样的办法吧? 只要每个cell的weight 没有负值就行 |
|
x*****0 发帖数: 452 | 49 A spreadsheet consists of a two-dimensional array of cells, labeled A1, A2,
etc. Rows are identified using letters, columns by numbers. Each cell
contains either an integer (its value) or an expression. Expressions contain
integers, cell references, and other operators '+', '-', '*', '/' with the
usual rules of evaluation -- note that the input is RPN and should be
evaluated in stack order.
The spreadsheet input is defined as follows:
(a) Line 1: two integers, defining the width and height of th... 阅读全帖 |
|
y**********a 发帖数: 824 | 50
No. It's enumerating lower bound and upper bound of all cases of using 1
machine, any two machines, and all three machines. |
|