《数据科学面试40+真题讲解》,K神本年度最后一次开课


一亩三分地论坛

 找回密码
 Sign Up 注册获取更多干货
码农求职神器Triplebyte:
不用海投,内推你去多家公司面试
Airbnb 数据科学职位
in analytics and inference
天天打游戏、照样领工资,
你要不要来?
把贵司招聘信息放这里
查看: 1854|回复: 3
收起左侧

Linkedin intern 题目

[复制链接] |试试Instant~ |关注本帖
sapphire0315 发表于 2016-2-3 09:20:17 | 显示全部楼层 |阅读模式

() @ - -  |

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看,没有帐号?Sign Up 注册获取更多干货

x
bool isNumber(string number){
    int i = 0;
    // head spaces
    while (number[i] == ' ')
        i++;
    // + / - symbol
    if(number[i] == '+' || number[i] == '-'). more info on 1point3acres.com
        i++;
    int nDigit = 0, nPoint = 0;
    while ((number[i] <= '9' && number[i] >= '0') || s[i] == '.'){
        if (number[i] == '.')
            nPoint++;
        else
            nDigit++;
        i++;.鏈枃鍘熷垱鑷1point3acres璁哄潧
    }
. From 1point 3acres bbs    if (number[i - 1] == '.') return false;
    if (nPoint > 1) return false;
    if (nDigit < 1) return false;. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
    while (number[i] == ' ')-google 1point3acres
        i++;
    if (i == number.length()) return true;
    else false;. more info on 1point3acres.com
}

10.
e5
-0.23
-e
-+



Thus, given the sequence (1, 2, -4, 1, 3, -2, 3, -1) it should return 5.. Waral 鍗氬鏈夋洿澶氭枃绔,
Maximum sum of the contigous subsequence

int maxSubsequence(vector<int>nums){
    int n = nums.size(); 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
    if (n == 0) return 0; 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
    int ans = nums[0], current = nums[0];
    for (int i = 1; i < n; i++){
        current = max(current + nums[i], nums[i]);
        ans = max(ans, current);. From 1point 3acres bbs
    }
    return ans;
}. Waral 鍗氬鏈夋洿澶氭枃绔,

// current: 1, 3, -1, 1, 4, 2, 5, 4
// ans:     1, 3, 3,  3, 4, 4, 5, 5
// maximum subarray: 1,3,-2,3 --> sum = 5
. From 1point 3acres bbs. 鍥磋鎴戜滑@1point 3 acres


class TwoSum {
private:
    unordered_multiset<int>s; // space complexity: O(N);
    unordered_set<int>sum; // space complexity: O(N*N);.鏈枃鍘熷垱鑷1point3acres璁哄潧
public:. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
    /**
     * Stores @param input in an internal data structure.
     */
     void store(int input){.鐣欏璁哄潧-涓浜-涓夊垎鍦
         for (unordered_multiset<int>::iterator iter = s.begin(); iter != s.end(); iter++)
             sum.insert(input + *iter);
         s.insert(input);
     }
    /**
     * Returns true if there is any pair of numbers in the internal data structure which
     * have sum @param val, and false otherwise.
     * For example, if the numbers 1, -2, 3, and 6 had been stored,
     * the method should return true for 4, -1, and 9, but false for 10, 5, and 0
     . From 1point 3acres bbs
     example: (5, 5, 6, 6) // return true;
     example: (5, 6, 7, 8) // return false;
     test(10) => (5, 5)
     */
   
    bool test(int val){
        /*for (unordered_multiset<int>::iterator iter = s.begin(); iter != s.end(); iter++){
            if (s.find(val - *iter) != s.end() && s.find(val - *iter) != iter) // not for same element twice.
                return true;
        }
        return false;*/
        if (sum.find(val) != sum.end()).鏈枃鍘熷垱鑷1point3acres璁哄潧
            return true;
        else
            return false;
    }. visit 1point3acres.com for more.
};. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷


//// Ads Slot Selection Problem

position   price  
slot0      $0.10. from: 1point3acres.com/bbs
slot1      $0.20
slot2      $0.05
slot3      $0.08
slot4      $0.05
slot5      $0.09

// dp[i]:
// dp[0]: 0.1, dp[1] = 0.2, dp[2] = 0.15, dp[3] = 0.2 + 0.08 = 0.28, dp[4] = 0.2 + 0.05 = 0.25, dp[5] = 0.28 + 0.09 = 0.37;

example: select (1, 3, 5) = $0.20
example: select (2, 4) = $0.28
example: select (1,2,3): invalid because two ads cannot be adjacent to each other.鐣欏璁哄潧-涓浜-涓夊垎鍦

input=> double price[]:index = position
output=> total revenue from the selected slots
please maximize the revenue
// input: vector<double>price, vector<int>position;
// output: double;

class Solution{
public:
    double maxPrice(vector<double>price, int lo, int hi){
        int n = price.size();
        if (n == 0) return 0;
        if (n == 1) return price[lo];. 鍥磋鎴戜滑@1point 3 acres
        if (n == 2) return max(price[lo], price[lo + 1]);
        if (n == 3) return max(price[lo + 1], price[lo] + price[lo + 2]);
        vector<double>dp(n);
        dp[0] = price[lo];
        dp[1] = price[lo + 1];. From 1point 3acres bbs
        dp[2] = price[lo] + price[lo + 2];. 鍥磋鎴戜滑@1point 3 acres
        // dp[i]: maximum value of the sum including price[i]-google 1point3acres
        for (int i = lo + 3; i < hi; i++). 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
            dp[i] = price[i] + max(dp[i - 2], dp[i - 3]);// do not consider dp[i - 1];
            // dp[i - 1] will affect dp[i + 1] but not dp[i];
        return max(dp[n - 1], dp[n - 2]);
    }
    double maxPrice2(vector<double>price){
        int n = price.size();
        if (n == 0) return 0;
        if (n == 1) return price[0];
        
        return max(maxPrice(price, 0, n - 2), maxPrice(1, n - 1));
    }
    .鐣欏璁哄潧-涓浜-涓夊垎鍦
};

// 1. maxPrice(price, 0, n - 2)
// 2. maxPrice(price, 1, n - 1);
// return max(maxPrice(price, 0, n - 2), maxPrice(price, 1, n - 1));
. 鍥磋鎴戜滑@1point 3 acres
johnjavabean 发表于 2016-2-3 09:23:13 | 显示全部楼层
lz怎么拿到L家电面的...什么时候内推或者投简历的啊...
回复 支持 反对

使用道具 举报

johnjavabean 发表于 2016-2-3 09:23:30 | 显示全部楼层
另外他家推荐有个OA,lz做了吗?
回复 支持 反对

使用道具 举报

ilyak 发表于 2016-2-3 13:14:40 | 显示全部楼层
可以求问最后一题的题目咩?
回复 支持 反对

使用道具 举报

本版积分规则

关闭

一亩三分地推荐上一条 /5 下一条

手机版|小黑屋|一亩三分地论坛声明

custom counter

GMT+8, 2017-11-18 14:55

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

快速回复 返回顶部 返回列表