Quantcast

袁伟时:中国的奴性和戾气从哪里来?

“芯片大学”虚晃一枪,人才断层问题不能跑步解决

两大中国首富双双被重挫-释放信号强烈

民间帝王赖小民和性感女星舒淇与许晴

深度解读 | 姜文《让子弹飞》

Facebook Twitter

分享到微信朋友圈

点击图标下载本文截图到手机
即可分享到朋友圈。如何使用?

自由微信安卓APP发布,立即下载!
查看原文

每日一练 | Data Scientist & Business Analyst & Leetcode 面试题 293

2018-02-10 数据应用学院 大数据应用 大数据应用

自2017年6月15日起,数据应用学院与你一起温习数据科学(DS)和商业分析(BA)领域常见的面试问题。从2017年10月4号起,每天再为大家分享一道Leetcode算法题。

希望积极寻求相关领域工作的你每天关注我们的问题并且与我们一起思考,我们将会在第二天给出答案。

Day 193 

DS Interview Questions

What is the difference between tuples and lists in Python?

BA Interview Questions

R language:

You have the data.frame ‘mydf’ with four columns like below.

a = c(3,7,NA, 9)

b = c(2,NA,9,3)

f = c(5,2,5,6)

d = c(NA,3,4,NA)


mydf = data.frame(a=a,b=b,f=f,d=d)

mydf

## You want to add another column ‘5’:

## the 5th column contains the value of col b if col a is NA;

## the 5th column contains the value of col d if col b is NA;

## the 5th column contains the value of col f in all other cases. 

LeetCode Questions

Description:

  • Say you have an array for which the ith element is the price of a given stock on day i.

  • Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

Input: [1,2,3,1,6]

Output: 7

欲知答案如何?请见下期分解!

Day 192 答案揭晓

DS Interview Questions

Write the code to sort an array in NumPy by the nth column?


Using argsort () function this can be achieved. If there is an array X and you would like to sort the nth column then code for this will be x[x [: n-1].argsort ()]

BA Interview Questions

R language:

Write a for loop that prints the Displacement (‘disp’) of the ‘mtcars’ dataset.

a. This loop will only print observations of 160 or higher in ‘disp’.

b. This loop will stop as soon as an observation is smaller than 160 in ‘disp’.


data(mtcars)

names(mtcars)

dim(mtcars)


x=mtcars$disp


for(i in 1:length(x)){

  if(x[i]>=160){

    print(x[i])

  }

}


for(i in 1:length(x)){

  if(x[i]>=160){

    print(x[i])

  }else if(x[i]<160){

    break

    }

}


for (i in 1:length(mtcars$disp)){

  if(mtcars$disp[i] < 160) break;

  print(mtcars$disp[i])

  i = i +1

}

Leetcode Questions

Description:

  • Say you have an array for which the ith element is the price of a given stock on day i.

  • If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Input: [7, 1, 5, 3, 6, 4]

Output: 5


Solution:

  • 记录当前遇到的最小值,每次将当前卖出与最小值买入所得利润与最大利润进行比较

Code:

Time Complexity: O(n)

Space Complexity: O(1)



点击“阅读原文”查看数据应用学院核心课程

文章有问题?点此查看未经处理的缓存