一亩三分地论坛

 找回密码
 获取更多干货,去instant注册!

扫码关注一亩三分地公众号
查看: 563|回复: 3
收起左侧

Linkedin intern 题目

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

() @ - -  |

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

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

x
bool isNumber(string number){
    int i = 0;
    // head spaces
    while (number[i] == ' ')
        i++;. 1point 3acres 璁哄潧
    // + / - symbol
    if(number[i] == '+' || number[i] == '-')
        i++;
    int nDigit = 0, nPoint = 0;.1point3acres缃
    while ((number[i] <= '9' && number[i] >= '0') || s[i] == '.'){
        if (number[i] == '.')
. more info on 1point3acres.com            nPoint++;
        else
            nDigit++;
        i++;
    }-google 1point3acres
    if (number[i - 1] == '.') return false;
    if (nPoint > 1) return false;
    if (nDigit < 1) return false;. from: 1point3acres.com/bbs
    while (number[i] == ' ')
        i++;. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
    if (i == number.length()) return true;
    else false;
}

10.-google 1point3acres
e5
-0.23.1point3acres缃
-e
-+



Thus, given the sequence (1, 2, -4, 1, 3, -2, 3, -1) it should return 5.
Maximum sum of the contigous subsequence . 1point3acres.com/bbs
.鐣欏璁哄潧-涓浜-涓夊垎鍦
int maxSubsequence(vector<int>nums){
    int n = nums.size();
    if (n == 0) return 0;
    int ans = nums[0], current = nums[0];. 1point 3acres 璁哄潧
    for (int i = 1; i < n; i++){
        current = max(current + nums[i], nums[i]);
        ans = max(ans, current);
    }
    return ans;. 1point 3acres 璁哄潧
}

// 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);. more info on 1point3acres.com
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.1point3acres缃
     
     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())
            return true;.1point3acres缃
        else
            return false;
    }. 鍥磋鎴戜滑@1point 3 acres
};

.鏈枃鍘熷垱鑷1point3acres璁哄潧
//// Ads Slot Selection Problem

position   price  . 鍥磋鎴戜滑@1point 3 acres
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

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:
.1point3acres缃    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];
        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++)
            dp[i] = price[i] + max(dp[i - 2], dp[i - 3]);// do not consider dp[i - 1];. more info on 1point3acres.com
            // 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){. Waral 鍗氬鏈夋洿澶氭枃绔,
        int n = price.size();
        if (n == 0) return 0;. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
        if (n == 1) return price[0];. 1point3acres.com/bbs
        
        return max(maxPrice(price, 0, n - 2), maxPrice(1, n - 1));
    }. 1point3acres.com/bbs
   
};

// 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 | 显示全部楼层
可以求问最后一题的题目咩?
回复 支持 反对

使用道具 举报

本版积分规则

请点这里访问我们的新网站:一亩三分地Instant.

Instant搜索更强大,不扣积分,内容组织的更好更整洁!目前仍在beta版本,努力完善中!反馈请点这里

关闭

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

手机版|小黑屋|一亩三分地论坛声明 ( 沪ICP备11015994号 )

custom counter

GMT+8, 2016-12-11 18:44

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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