Skip to content

Commit 3961f90

Browse files
committed
reorganized all for FAANG planning
1 parent 3e92d47 commit 3961f90

File tree

15 files changed

+121
-0
lines changed

15 files changed

+121
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
# coding-interview-practice
22
For any code games out there, I prefer to work in my preferred IDE and paste in the solution. In order to preserve the work and share with potentially interested people I'm posting my work publicly.
3+
4+
## how to use this repository
5+
6+
### As a hiring manager
7+
8+
One possible use of this code repository is to pre-evaluate the algorithm practise I've done. Within each folder under challenges is a separate coding test. You can within github online look at the coding history tab to view the final code as well as the commits that got me there.
9+
10+
![history tab sample](/images/github-history-tab.png)
11+
12+
### As a student
13+
14+
Take the time to go through the interview study guide planning document to get a sense of the overall flow. Structure will have a recommneded path towards studying broken out into chapters of mastery. After which hopefully you will be ready to take a coding interview.
15+
16+
I have every expeactions from the reading I've done that this can take from 4 months to a year to complete.
17+
18+

challenges/string-to-int/readme.md

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# String to Int <https://leetcode.com/problems/string-to-integer-atoi/>
2+
3+
Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).
4+
5+
The algorithm for myAtoi(string s) is as follows:
6+
7+
1. Read in and ignore any leading whitespace.
8+
1. Check if the next character (if not already at the end of the string) is '-' or '+'. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present.
9+
1. Read in next the characters until the next non-digit charcter or the end of the input is reached. The rest of the string is ignored.
10+
1. Convert these digits into an integer (i.e. "123" -> 123, "0032" -> 32). If no digits were read, then the integer is 0. Change the sign as necessary (from step 2).
11+
1. If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then clamp the integer so that it remains in the range. Specifically, integers less than -231 should be clamped to -231, and integers greater than 231 - 1 should be clamped to 231 - 1.
12+
1. Return the integer as the final result.
13+
14+
## Note:
15+
16+
Only the space character ' ' is considered a whitespace character.
17+
Do not ignore any characters other than the leading whitespace or the rest of the string after the digits.
18+
19+
20+
## Example 1:
21+
22+
```
23+
Input: s = "42"
24+
Output: 42
25+
Explanation: The underlined characters are what is read in, the caret is the current reader position.
26+
Step 1: "42" (no characters read because there is no leading whitespace)
27+
^
28+
Step 2: "42" (no characters read because there is neither a '-' nor '+')
29+
^
30+
Step 3: "42" ("42" is read in)
31+
^
32+
The parsed integer is 42.
33+
Since 42 is in the range [-231, 231 - 1], the final result is 42.
34+
```
35+
36+
## Example 2:
37+
38+
```
39+
Input: s = " -42"
40+
Output: -42
41+
Explanation:
42+
Step 1: " -42" (leading whitespace is read and ignored)
43+
^
44+
Step 2: " -42" ('-' is read, so the result should be negative)
45+
^
46+
Step 3: " -42" ("42" is read in)
47+
^
48+
The parsed integer is -42.
49+
Since -42 is in the range [-231, 231 - 1], the final result is -42.
50+
```
51+
52+
## Example 3:
53+
54+
```
55+
Input: s = "4193 with words"
56+
Output: 4193
57+
Explanation:
58+
Step 1: "4193 with words" (no characters read because there is no leading whitespace)
59+
^
60+
Step 2: "4193 with words" (no characters read because there is neither a '-' nor '+')
61+
^
62+
Step 3: "4193 with words" ("4193" is read in; reading stops because the next character is a non-digit)
63+
^
64+
The parsed integer is 4193.
65+
Since 4193 is in the range [-231, 231 - 1], the final result is 4193.
66+
```
67+
68+
## Example 4:
69+
70+
```
71+
Input: s = "words and 987"
72+
Output: 0
73+
Explanation:
74+
Step 1: "words and 987" (no characters read because there is no leading whitespace)
75+
^
76+
Step 2: "words and 987" (no characters read because there is neither a '-' nor '+')
77+
^
78+
Step 3: "words and 987" (reading stops immediately because there is a non-digit 'w')
79+
^
80+
The parsed integer is 0 because no digits were read.
81+
Since 0 is in the range [-231, 231 - 1], the final result is 0.
82+
```
83+
84+
## Example 5:
85+
86+
```
87+
Input: s = "-91283472332"
88+
Output: -2147483648
89+
Explanation:
90+
Step 1: "-91283472332" (no characters read because there is no leading whitespace)
91+
^
92+
Step 2: "-91283472332" ('-' is read, so the result should be negative)
93+
^
94+
Step 3: "-91283472332" ("91283472332" is read in)
95+
^
96+
The parsed integer is -91283472332.
97+
Since -91283472332 is less than the lower bound of the range [-231, 231 - 1], the final result is clamped to -231 = -2147483648.
98+
```
99+
100+
## Constraints:
101+
102+
0 <= s.length <= 200
103+
s consists of English letters (lower-case and upper-case), digits (0-9), ' ', '+', '-', and '.'.

images/github-history-tab.png

171 KB
Loading

string-to-int/readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# String to Int <https://leetcode.com/problems/string-to-integer-atoi/>
22

3+
## Final score <https://leetcode.com/problems/string-to-integer-atoi/>
4+
35
Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).
46

57
The algorithm for myAtoi(string s) is as follows:

0 commit comments

Comments
 (0)