Skip to content

Commit 63fb129

Browse files
Add behavior questions
1 parent 21f39ce commit 63fb129

File tree

6 files changed

+152
-3
lines changed

6 files changed

+152
-3
lines changed

Interview/Algorithm/Array.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
2. Continuous Subarray Sum
55
3. Random Pick with Weight
66
4. Friends Of Appropriate Ages
7+
5. Trap Rain Water
8+
6. House Robber
79

810

911
## Implementation
@@ -199,4 +201,103 @@ public:
199201
return count;
200202
}
201203
};
204+
```
205+
### **Trap Rain water**
206+
207+
***Big O:*** O(nlog(n)) speed, O(n) space
208+
```
209+
Tips:
210+
Approache 1:
211+
212+
Use stacks.
213+
214+
Approach 2:
215+
216+
Use two pointers.
217+
```
218+
219+
```c++
220+
// Approach 1: stacks
221+
class Solution {
222+
public:
223+
int trap(vector<int>& height)
224+
{
225+
int ans = 0, current = 0;
226+
stack<int> st;
227+
while (current < height.size()) {
228+
while (!st.empty() && height[current] > height[st.top()]) {
229+
int top = st.top();
230+
st.pop();
231+
if (st.empty())
232+
break;
233+
int distance = current - st.top() - 1;
234+
int bounded_height = min(height[current], height[st.top()]) - height[top];
235+
ans += distance * bounded_height;
236+
}
237+
st.push(current++);
238+
}
239+
return ans;
240+
}
241+
};
242+
243+
// Approach 2: two pointers
244+
class Solution {
245+
public:
246+
int trap(vector<int>& height)
247+
{
248+
int ans = 0;
249+
int left = 0, right = height.size()-1;
250+
int left_max, right_max;
251+
left_max = right_max = 0;
252+
253+
while (left < right) {
254+
right_max = max(right_max, height[right]);
255+
256+
if (height[left] < height[right]) {
257+
if (left_max > height[left]) {
258+
ans += (left_max - height[left]);
259+
} else {
260+
left_max = height[left];
261+
}
262+
left ++;
263+
} else {
264+
if (right_max > height[right]) {
265+
ans += (right_max - height[right]);
266+
} else {
267+
right_max = height[right];
268+
}
269+
right --;
270+
}
271+
}
272+
273+
return ans;
274+
}
275+
};
276+
```
277+
### **House Robber**
278+
279+
***Big O:*** O(n) speed, O(n) space
280+
```
281+
Tips:
282+
283+
Dynamic programming with memorization
284+
```
285+
```c++
286+
class Solution {
287+
public:
288+
int rob(vector<int>& nums) {
289+
if(nums.size() <= 1) return nums.size() == 0 ? 0 : nums[0];
290+
291+
vector<int> dp(nums.size(), 0);
292+
293+
dp[0] = nums[0];
294+
dp[1] = max(nums[0], nums[1]);
295+
296+
for (int i = 2; i < nums.size(); i++) {
297+
dp[i] = max(dp[i-2] + nums[i], dp[i-1]);
298+
}
299+
300+
return dp[nums.size()-1];
301+
}
302+
};
202303
```

Interview/Algorithm/LeetCode_for_embedded_advanced.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
19. Continuous Subarray Sum v
6969
20. Random Pick with Weight v
7070
21. Friends Of Appropriate Ages v
71+
22. Trap Rain water v
72+
23. House Robber v
7173

7274
***Math:***
7375
1. Add Binary v

Interview/Behavior/amazon_LP.md

Whitespace-only changes.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
***Describe a situation in which you were able to use persuasion to successfully convince someone to see things your way.***
2+
3+
***Describe a time when you were faced with a stressful situation that demonstrated your coping skills.***
4+
5+
***Give me a specific example of a time when you used good judgment and logic in solving a problem.***
6+
7+
***Give me an example of a time when you set a goal and were able to meet or achieve it.***
8+
9+
***Tell me about a time when you had to use your presentation skills to influence someone's opinion.***
10+
11+
***Give me a specific example of a time when you had to conform to a policy with which you did not agree.***
12+
13+
***Please discuss an important written document you were required to complete.***
14+
15+
***Tell me about a time when you had to go above and beyond the call of duty in order to get a job done.***
16+
17+
***Tell me about a time when you had too many things to do and you were required to prioritize your tasks.***
18+
19+
***Give me an example of a time when you had to make a split second decision.***
20+
21+
***What is your typical way of dealing with conflict? Give me an example.***
22+
23+
***Tell me about a time you were able to successfully deal with another person even when that individual may not have personally liked you (or vice versa).***
24+
25+
***Tell me about a difficult decision you've made in the last year.***
26+
27+
***Give me an example of a time when something you tried to accomplish and failed.***
28+
29+
***Give me an example of when you showed initiative and took the lead.***
30+
31+
***Tell me about a recent situation in which you had to deal with a very upset customer or coworker.***
32+
33+
***Give me an example of a time when you motivated others.***
34+
35+
***Tell me about a time when you delegated a project effectively.***
36+
37+
***Give me an example of a time when you used your fact-finding skills to solve a problem.***
38+
39+
***Tell me about a time when you missed an obvious solution to a problem.***
40+
41+
***Describe a time when you anticipated potential problems and developed preventive measures.***
42+
43+
***Tell me about a time when you were forced to make an unpopular decision.***
44+
45+
***Please tell me about a time you had to fire a friend.***
46+
47+
***Describe a time when you set your sights too high (or too low).***

Interview/Behavior/general.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@
374374

375375
### D. Behavior Question
376376
1. Amazon Leading Principles
377+
2. [Star Method](Interview/Behavior/STAR_Method_Interviews%20(Career%20Questions).pdf)
378+
3. Common Behavior Questions
377379

378380
### E. [Brain Teaser](https://www.geeksforgeeks.org/puzzles/)
379381

0 commit comments

Comments
 (0)