每日一练 | Data Scientist & Business Analyst & Leetcode 面试题 302
自2017年6月15日起,数据应用学院与你一起温习数据科学(DS)和商业分析(BA)领域常见的面试问题。从2017年10月4号起,每天再为大家分享一道Leetcode算法题。
希望积极寻求相关领域工作的你每天关注我们的问题并且与我们一起思考,我们将会在第二天给出答案。
DS Interview Questions
Explain what is collaborative filtering?
BA Interview Questions
R language:
Using the following variable:
a=15:10
b=20:15
type a while () loop that computes a vector x=225 224 221 216 209 200,such that
x[1]=a[1]*b[6]
x[2]=a[2]*b[5]
x[3]=a[3]*b[5]
.
.
x[6]=a[6]*b[1]
LeetCode Questions
Description:
Given two integers n and k, return all possible combinations of k numbers out of 1 … n.
Input: n = 4 and k = 2
Output: [[2,4],[3,4],[2,3],[1,2],[1,3],[1,4],]
欲知答案如何?请见下期分解!
Day 201 答案揭晓
DS Interview Questions
Explain what is the criteria for a good data model?Criteria for a good data model includes
It can be easily consumed
Large data changes in a good model should be scalable
It should provide predictable performance
A good model can adapt to changes in requirements
BA Interview Questions
Using the following variables:
x=c(2,4)
# type a while () loop that adds even numbers to x,
# while the length of x is less than 12.
# For example, in the first iteration you get x = 2,4,6, and the third x =2,4,6,8.
a=6
while(length(x)<12){
x<-c(x,a)
a=a+2
}
x
Leetcode Questions
Description:
Input: [1,2,2,1,1,0]
Output:[0,1,1,1,2,2]
Assumptions:
You are not suppose to use the library’s sort function for this problem.
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively
Solution:
典型的Partition题, 最简单的思路是先对0 和 大于 0 做一次partition, 对1和2做一次partition。这样虽然时间复杂度依然是O(n), 但是还有一次遍历的更优方法。
以下方法(Rainbow sort)中,区间[0, l)都是0, 区间(r, end]都是2. 根据该算法可以确定, [l, r)这个区间内全是1. 当跳出循环的时候i = r + 1, 可以确保[0, l) 是0, [l, i) 是1, [i, end]是2. 因为只遍历了一次,所以时间复杂度还是O(n), 空间复杂度O(1)。
Code:
Time Complexity: O(n)
Space Complexity: O(1)
点击“阅读原文”查看数据应用学院核心课程