https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Mock%20Interviews/Large%20Search%20Engine%20Company%20/Search%20Engine%20Company%20-%20Interview%20Problems%20-%20SOLUTIONS/Phone%20Screen.ipynb

Phone Screen

This phone screen will consist of a non-technical series of questions about you and the company, and then a second half of a simple technical question to be coded out


Non-Technical Questions

Answer the following questions (2-5 minute responses) technical answers not required, more interested in hearing about your reasoning

 
  • Give me some quick background about you (go over your resume)
  • Why do you want to work here?
  • What's your favorite programming language and why?
  • Where do you see yourself in 5 years?
  • Do you have any questions about the company for me?
 

Solution

There aren't really any "correct" answers here, just make sure you're prepared to answer the following questions about the company you're interviewing with. Be honest, friendly and ready to defend any statements you make with logical arguments to back them up. Note, you should ALWAYS have follow-up questions.

 

Technical Questions

Answer the following question in the Markdown cell below. It's important to note that the cell below does NOT have syntax highlighting, its common in a phone screen interview to be given a text editor hich doesn't have anything more than basic text support

  1. Write a function that computes the Nth fibonacci number
 

Solution

There's many ways to answer this question, you might be required to solve it multiple ways and discuss some pros and cons of each way. Listed below are various solutions

 
 
## Example 1: Using looping technique
def fib(n): a,b = 1,1
for i in range(n-1):
a,b = b,a+b
return a print fib(7) # Using recursion
def fibR(n):
if n==1 or n==2:
return 1
return fib(n-1)+fib(n-2) print fibR(7) ## Example 3: Using generators
a,b = 0,1
def fibI():
global a,b
while True:
a,b = b, a+b
yield a
f=fibI()
f.next()
f.next()
f.next()
f.next()
f.next()
f.next()
print f.next() ## Example 4: Using memoization
def memoize(fn, arg):
memo = {}
if arg not in memo:
memo[arg] = fn(arg)
return memo[arg] ## fib() as written in example 1.
fibm = memoize(fib,7)
print fibm ## Example 5: Using memoization as decorator
class Memoize:
def __init__(self, fn):
self.fn = fn
self.memo = {}
def __call__(self, arg):
if arg not in self.memo:
self.memo[arg] = self.fn(arg)
return self.memo[arg] @Memoize
def fib(n):
a,b = 1,1
for i in range(n-1):
a,b = b,a+b
return a
print fib(7)
 
 
 
 
13
13
13
13
13
 

Below is a table depicting averaged relative performance time in seconds over 10 runs to caluclate the 15000th fibonacci number.

Fib(n=15000)
loops recursion generators memoization memoization as decorator
45 87 58 44 43
47 88 58 42 42
51 92 60 44 43
43 87 58 42 43
48 92 61 42 44
45 87 59 43 44
44 85 57 42 44
44 87 62 43 43
48 86 59 42 43
45 91 61 45 45
46 88.2 59.3 42.9 43.4 (Avg)
 

Good Job!

Fibonacci number的更多相关文章

  1. Buge's Fibonacci Number Problem

    Buge's Fibonacci Number Problem Description snowingsea is having Buge’s discrete mathematics lesson, ...

  2. [UCSD白板题] The Last Digit of a Large Fibonacci Number

    Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...

  3. [UCSD白板题 ]Small Fibonacci Number

    Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...

  4. (斐波那契总结)Write a method to generate the nth Fibonacci number (CC150 8.1)

    根据CC150的解决方式和Introduction to Java programming总结: 使用了两种方式,递归和迭代 CC150提供的代码比较简洁,不过某些细节需要分析. 现在直接运行代码,输 ...

  5. 求四百万以内Fibonacci(number)数列偶数结果的总和

    又对啦...开心~~~~ 只是代码可能不符合PEP标准什么的... Each new term in the Fibonacci sequence is generated by adding the ...

  6. Algorithms - Fibonacci Number

    斐波那契数列(Fibonacci Number)从数学的角度是以递归的方法定义的: \(F_0 = 0\) \(F_1 = 1\) \(F_n = F_{n-1} + F_{n-2}\) (\(n \ ...

  7. 【LEETCODE】44、509. Fibonacci Number

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  8. 【leetcode】509. Fibonacci Number

    problem 509. Fibonacci Number solution1: 递归调用 class Solution { public: int fib(int N) { ) return N; ...

  9. fibonacci number & fibonacci sequence

    fibonacci number & fibonacci sequence https://www.mathsisfun.com/numbers/fibonacci-sequence.html ...

随机推荐

  1. SQL SERVER2008 DBX Error: Driver could not be properly initialized

    raised exception class TDBXError with message 'DBX Error:  Driver could not be properly initialized. ...

  2. VB 调用动态链接库

    作为一种简单易用的Windows开发环境,Visual Basic从一推出就受到了广大编程人员的欢迎.它使 程序员不必再直接面对纷繁复杂的Windows消息,而可以将精力主要集中在程序功能的实现上,大 ...

  3. ABAP-面向对象的开发

    转载:https://blog.csdn.net/zhongguomao/article/details/70266246 在程序中, 对象的识别和寻址是通过对象引用来实现的,对象引用变量可以访问对象 ...

  4. iOS Hardware Guide

    来自U3D文档 Hardware models The following list summarizes iOS hardware available in devices of various g ...

  5. PageUtil 分页

    /** * 分页工具类 * @author Administrator * */ public class PageUtil { /** * 生成分页代码 * @param targetUrl 目标地 ...

  6. scala -- 传名参数

    object Test{ def main(args: Array[String]): Unit = { def test(code : => Unit){// 传名参数 不计算函数值,而是把函 ...

  7. spring ioc xml配置

    一个完整的spring xml配置:是把action,service,dao以及其它的资源性配置(如basedao)和公共性配置(如连接数据库)配置在resource.xml中,这样就有四个xml配置 ...

  8. Spring Boot logback

    前言 今天来介绍下spring Boot如何配置日志logback,我刚学习的时候,是带着下面几个问题来查资料的,你呢 如何引入日志? 日志输出格式以及输出方式如何配置? 代码中如何使用? 正文 Sp ...

  9. dubbo 多协议和多注册中心

    一.配置dubbo多协议模式 1.默认协议 Dubbo缺省协议采用单一长连接和NIO异步通讯,适合于小数据量大并发的服务调用,以及服务消费者机器数远大于服务提供者机器数的情况.Dubbo缺省协议不适合 ...

  10. FastDFSClient工具类 文件上传下载

    package cn.itcast.fastdfs.cliennt; import org.csource.common.NameValuePair; import org.csource.fastd ...