Skip to content

Commit 6d90207

Browse files
More leetcode
1 parent 9ca600f commit 6d90207

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

Interview/Algorithm/LeetCode_for_embedded_advanced.md

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Facebook Phone Screen Preparation
1+
## Advance Leetcode questions
22
### Leetcode/Lintcode Algorithm Questions List
33

44
***Linked List:***
@@ -59,18 +59,90 @@
5959
10. First Bad Version v
6060
11. Count and Say v
6161
12. Maximum Number of Occurrences of a Substring v
62+
13. Maximum Subarray v
63+
14. Move Zeroes v
6264

6365
***Math:***
6466
1. Add Binary v
6567
2. Plus One v
6668
3. Add strings v
6769
4. Fibonacci Number v
6870
5. Pow(x, n)
71+
6. Divide Two Integers v
6972

7073
***Matirx:***
7174
1. Give the center of a matrix and then draw circle
75+
76+
***Data Structure:***
77+
1. Insert Delete GetRandom O(1) v
78+
2. LRU
7279

7380
### Impplementations
81+
Divide Two Integers
82+
```c++
83+
class Solution {
84+
public:
85+
int divide(int dividend, int divisor) {
86+
long long n=dividend, m=divisor;
87+
if(n <= INT_MIN && m == -1) return INT_MAX;
88+
89+
int sign = (n < 0) ^ (m < 0) ? -1: 1;
90+
91+
n=abs(n);
92+
m=abs(m);
93+
94+
long long q=0, temp=0;
95+
96+
for(int i=31; i>=0; i--){
97+
if(temp + (m << i) <= n){
98+
temp += m << i;
99+
q += 1 << i; // q |= 1 << i;
100+
}
101+
}
102+
return sign * q;
103+
}
104+
};
105+
```
106+
Move Zeroes
107+
```c++
108+
class Solution {
109+
public:
110+
void moveZeroes(vector<int>& nums) {
111+
int lastNonZeroFoundAt = 0;
112+
// If the current element is not 0, then we need to
113+
// append it just in front of last non 0 element we found.
114+
for (int i = 0; i < nums.size(); i++) {
115+
if (nums[i] != 0) {
116+
nums[lastNonZeroFoundAt++] = nums[i];
117+
}
118+
}
119+
// After we have finished processing new elements,
120+
// all the non-zero elements are already at beginning of array.
121+
// We just need to fill remaining array with 0's.
122+
for (int i = lastNonZeroFoundAt; i < nums.size(); i++) {
123+
nums[i] = 0;
124+
}
125+
}
126+
};
127+
```
128+
Maximum Subarray
129+
```c++
130+
class Solution {
131+
public:
132+
int maxSubArray(vector<int>& nums) {
133+
int n = nums.size();
134+
int sum = nums[0];
135+
int max_v = sum;
136+
137+
for (int i = 1; i < n; i++) {
138+
sum = max(nums[i], sum+nums[i]);
139+
max_v = max(sum, max_v);
140+
}
141+
142+
return max_v;
143+
}
144+
};
145+
```
74146
Maximum Number of Occurrences of a Substring
75147
```c++
76148
class Solution {

Interview/Company/apple.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Apple On-site interview process
2+
3+
```45 minutes per round```
4+
5+
### 1st round
6+
- Hiring Manager round
7+
- Two people
8+
- Talk about resume - 30 Minuts
9+
- Implement atoi()
10+
11+
### 2nd round
12+
- Two people
13+
- Given a 1-D array (matrix) and coordinate of center and radius, then draw the circle (mark all 1 in the circle area matrix).
14+
- Tips: Search 2D array
15+
- Calculate coordinate and calculate distance with the center
16+
17+
### 3rd round
18+
- Two people
19+
- GPIO sensor interrupt question:
20+
- Given 8 sensor on the wheel, Calculate distance travel by the wheel
21+
- forward/backward? -> 8 bit pattern
22+
23+
### 4th round
24+
- Two people
25+
- Implement Ring Buffer
26+
27+
### 5th round
28+
- Two people
29+
- Talk about resume for a long time
30+
- WERID QUESTION:
31+
- #def HIGH_THRES 100
32+
- #def DELTA_THRES 0.2
33+
- Given api call_alarm(), check_data(double temp, time_t timestamp)
34+
- Question: if temp > HIGH_THRES or delta_val > DELTA_THRES, call call_alarm()
35+
- What concerns do you have? what if the data reading is very noisy?
36+
37+
38+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@
380380
9. [Lyft](Interview/Company/lyft.md)
381381
10. [FaceBook](Interview/Company/facebook.md)
382382
11. Zoox
383-
12. Apple
383+
12. [Apple](Interview/Company/apple.md)
384384

385385
### H. Mock Tests
386386
1. [Computer networks mock tests](https://www.geeksforgeeks.org/quiz-corner-gq/#Computer%20Networks%20Mock%20Tests)

0 commit comments

Comments
 (0)