一亩三分地论坛

 找回密码
 Sign Up 注册获取更多干货
码农求职神器Triplebyte:
不用海投,内推多家公司面试
Airbnb 数据科学职位
in analytics and inference
游戏初创公司
招聘工程师、Designer和游戏策划
游戏初创公司DreamCraft招聘工程师、UIUX Designer和游戏策划
电商初创公司Good Days
招聘SDE/UI/TPM实习生
把贵司招聘信息放这里
查看: 1902|回复: 3
收起左侧

Linkedin intern 题目

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

() @ - -  |

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

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

x
bool isNumber(string number){
    int i = 0;
    // head spaces.鏈枃鍘熷垱鑷1point3acres璁哄潧
    while (number[i] == ' ')
        i++;
    // + / - symbol
    if(number[i] == '+' || number[i] == '-')
        i++;
    int nDigit = 0, nPoint = 0;. From 1point 3acres bbs
    while ((number[i] <= '9' && number[i] >= '0') || s[i] == '.'){
        if (number[i] == '.'). visit 1point3acres.com for more.
            nPoint++;
        else
            nDigit++;
        i++;.1point3acres缃
    }
    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;
}. from: 1point3acres.com/bbs

10.. 1point 3acres 璁哄潧
e5
-0.23
-e
-+



Thus, given the sequence (1, 2, -4, 1, 3, -2, 3, -1) it should return 5.
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);
    }
    return ans;. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
}
. From 1point 3acres bbs
// 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);
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);. 鍥磋鎴戜滑@1point 3 acres
     }. 1point3acres.com/bbs
    /**. Waral 鍗氬鏈夋洿澶氭枃绔,
     * 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,. visit 1point3acres.com for more.
     * the method should return true for 4, -1, and 9, but false for 10, 5, and 0
     
     example: (5, 5, 6, 6) // return true;
     example: (5, 6, 7, 8) // return false;
     test(10) => (5, 5) 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
     */
    . 鍥磋鎴戜滑@1point 3 acres
    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.. visit 1point3acres.com for more.
                return true;
        }
        return false;*/
.鐣欏璁哄潧-涓浜-涓夊垎鍦        if (sum.find(val) != sum.end())
.鏈枃鍘熷垱鑷1point3acres璁哄潧            return true;
        else
            return false;
    }
};

. from: 1point3acres.com/bbs
//// Ads Slot Selection Problem

position   price  . 1point 3acres 璁哄潧
slot0      $0.10
slot1      $0.20
slot2      $0.05
slot3      $0.08
slot4      $0.05
slot5      $0.09

// dp[i]:. from: 1point3acres.com/bbs
// 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;. From 1point 3acres bbs

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];
        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);
. 1point3acres.com/bbs        dp[0] = price[lo];
        dp[1] = price[lo + 1]; 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
        dp[2] = price[lo] + price[lo + 2];
        // dp[i]: maximum value of the sum including price[i]
        for (int i = lo + 3; i < hi; i++). Waral 鍗氬鏈夋洿澶氭枃绔,
            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]); -google 1point3acres
    }
    double maxPrice2(vector<double>price){
        int n = price.size();. from: 1point3acres.com/bbs
        if (n == 0) return 0;.1point3acres缃
        if (n == 1) return price[0];
        . 1point3acres.com/bbs
        return max(maxPrice(price, 0, n - 2), maxPrice(1, n - 1));.1point3acres缃
    }
    . Waral 鍗氬鏈夋洿澶氭枃绔,
};

// 1. maxPrice(price, 0, n - 2)
// 2. maxPrice(price, 1, n - 1);
// 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, 2018-1-19 00:23

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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