10月28,K神开课讲数据科学,你来吗?


一亩三分地论坛

 找回密码
 获取更多干活,快来注册
Babeltime游戏工作室招工程师、美术和策划
Tubi TV招安卓、前端和机器学习工程师
把贵司招聘信息放这里
查看: 1799|回复: 3
收起左侧

Linkedin intern 题目

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

() @ - -  |

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

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

x
bool isNumber(string number){
    int i = 0;
    // head spaces
    while (number[i] == ' ')
        i++;
    // + / - symbol
    if(number[i] == '+' || number[i] == '-'). Waral 鍗氬鏈夋洿澶氭枃绔,
        i++;
    int nDigit = 0, nPoint = 0;
    while ((number[i] <= '9' && number[i] >= '0') || s[i] == '.'){. 1point 3acres 璁哄潧
        if (number[i] == '.')
            nPoint++;
        else
            nDigit++;
        i++;
.鐣欏璁哄潧-涓浜-涓夊垎鍦    }. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
    if (number[i - 1] == '.') return false;
    if (nPoint > 1) return false;
    if (nDigit < 1) return false;
    while (number[i] == ' ')
        i++;
    if (i == number.length()) return true;
    else false;
}

10..1point3acres缃
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);. visit 1point3acres.com for more.
    }
    return ans;
}

// 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

.鐣欏璁哄潧-涓浜-涓夊垎鍦
. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
class TwoSum {
private:.鐣欏璁哄潧-涓浜-涓夊垎鍦
    unordered_multiset<int>s; // space complexity: O(N);
    unordered_set<int>sum; // space complexity: O(N*N);. From 1point 3acres bbs
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,. From 1point 3acres bbs
     * the method should return true for 4, -1, and 9, but false for 10, 5, and 0
     
     example: (5, 5, 6, 6) // return true;.鏈枃鍘熷垱鑷1point3acres璁哄潧
     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())
            return true;
        else
            return false;
    }
};


//// Ads Slot Selection Problem

position   price  
slot0      $0.10. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
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
. more info on 1point3acres.com
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;
. from: 1point3acres.com/bbs
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];
        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];. From 1point 3acres bbs
        dp[1] = price[lo + 1];
        dp[2] = price[lo] + price[lo + 2];.鏈枃鍘熷垱鑷1point3acres璁哄潧
        // dp[i]: maximum value of the sum including price[i]
        for (int i = lo + 3; i < hi; i++). From 1point 3acres bbs
            dp[i] = price[i] + max(dp[i - 2], dp[i - 3]);// do not consider dp[i - 1];. 鍥磋鎴戜滑@1point 3 acres
            // 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){.1point3acres缃
        int n = price.size();
        if (n == 0) return 0;
        if (n == 1) return price[0];. Waral 鍗氬鏈夋洿澶氭枃绔,
        
        return max(maxPrice(price, 0, n - 2), maxPrice(1, n - 1));
    }
    .鏈枃鍘熷垱鑷1point3acres璁哄潧
};

// 1. maxPrice(price, 0, n - 2)
// 2. maxPrice(price, 1, n - 1);. 1point 3acres 璁哄潧
// return max(maxPrice(price, 0, n - 2), maxPrice(price, 1, n - 1));

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-9-19 21:52

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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