## Interviews

#### Popular Linkedin Interview Question List 1, Closest K nodes to a target in BST? (Do it in O(n)?)

``````
vector closestKValues(TreeNode* root, double target, int k) {
vector res;
inorder(root, target, k, res);
return res;
}
void inorder(TreeNode *root, double target, int k, vector &res) {
if (!root) return;
inorder(root->left, target, k, res);
if (res.size() < k) res.push_back(root->val);
else if (abs(root->val - target) < abs(res - target)) {
res.erase(res.begin());
res.push_back(root->val);
} else return;
inorder(root->right, target, k, res);
}
``````

2, Nested List sum?

3, III. Square root of a number?

``````
int sqrt(int x) {
if (x == 0)
return x;
int left = 1, right = x;
while (true) {
int mid = (left + right) / 2;
if (mid > x / mid)
right = mid - 1;
else if (mid + 1 > x / (mid + 1))  //mid < x / mid
return mid;
else                                      //mid < x / mid
left = mid + 1;
}
}
``````

4, Expression operators? Add signs (+, -, *, /) to a string to form target

``````
``````

5, Top trending posts in last 5m, 1H, 1Day?

``````
``````