Tuesday, July 31, 2018

Huawei OA

Q1: Cannot remember:


Q2: A large package can hold five items, while the small package can hold only one item, The available # of both large and small packages  is limited. All items must be placed in packages and
used packages must be filled up completely. Write a function that calculates the minimum # of packages to hold a given number of items. Return -1, if not possible.

Answer:


cat Q3.cpp
// Search in a BST tree (Leetcode 700)
class Solution {
public:
    TreeNode* searchBST(TreeNode* root, int val) {
        if (!root)
            return nullptr;
        else if (val == root->val)
            return root;
        else if (val > root->val)
            return searchBST(root->right, val);
        else
            return searchBST(root->left, val);
    }
};

Saturday, January 27, 2018

他山之玉 -- 别人的Google 面经


https://github.com/UmassJin/Leetcode/blob/master/Experience/google%E9%9D%A2%E7%BB%8F%E9%9B%86%E5%90%88.py