推荐:数据科学课程和书籍清单以及培训讲座


一亩三分地论坛

 找回密码
 获取更多干活,快来注册

一亩三分地官方iOS手机应用下载
查看: 1785|回复: 3
收起左侧

Linkedin intern 题目

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

() @ - -  |

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

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

x
bool isNumber(string number){
    int i = 0;-google 1point3acres
    // 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++;
    }
    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.
e5
-0.23
-e
-+
. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷

. 1point3acres.com/bbs
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;. visit 1point3acres.com for more.
}

// current: 1, 3, -1, 1, 4, 2, 5, 4 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
// ans:     1, 3, 3,  3, 4, 4, 5, 5.鏈枃鍘熷垱鑷1point3acres璁哄潧
// maximum subarray: 1,3,-2,3 --> sum = 5



class TwoSum {. from: 1point3acres.com/bbs
private:
    unordered_multiset<int>s; // space complexity: O(N);-google 1point3acres
    unordered_set<int>sum; // space complexity: O(N*N); 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
public:. Waral 鍗氬鏈夋洿澶氭枃绔,
    /**. from: 1point3acres.com/bbs
     * 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
     
     example: (5, 5, 6, 6) // return true;
     example: (5, 6, 7, 8) // return false;. 1point 3acres 璁哄潧
     test(10) => (5, 5)
     */.鏈枃鍘熷垱鑷1point3acres璁哄潧
   
    bool test(int val){
        /*for (unordered_multiset<int>::iterator iter = s.begin(); iter != s.end(); iter++){. from: 1point3acres.com/bbs
            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;. 1point3acres.com/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;
. 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;. 1point3acres.com/bbs
        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];. visit 1point3acres.com for more.
        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];
            // 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));. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
    }
   
};
-google 1point3acres
// 1. maxPrice(price, 0, n - 2).1point3acres缃
// 2. maxPrice(price, 1, n - 1);
// return max(maxPrice(price, 0, n - 2), maxPrice(price, 1, n - 1));
. from: 1point3acres.com/bbs
johnjavabean 发表于 2016-2-3 09:23:13 | 显示全部楼层
关注一亩三分地公众号:
Warald_一亩三分地
lz怎么拿到L家电面的...什么时候内推或者投简历的啊...
回复 支持 反对

使用道具 举报

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

使用道具 举报

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

使用道具 举报

本版积分规则

关闭

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

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

custom counter

GMT+8, 2017-8-17 06:11

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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