Caren
July 18, 2018
72

# Week 7 Review, Session 1

July 18, 2018

## Transcript

2. ### HackerRank Assessments Week 0 1 2 3 4 5 6

50th percentile 210 688 330 455 135 380 430 80th percentile 235 855 460 470 175 525 565 max score 245 965 490 475 230 615 580 Last question is usually always a Hard “bonus” question
3. ### Review Week Topics covered in past 3 weeks:   Binary

Trees, Graphs, Strings, Arrays Revisit problems :  Mock Interview Problems  HackerRank assessments  Extra questions on LeetCode Think of different solutions for each problem and their different tradeoffs
4. ### Project Gutenberg Text Analysis on a novel  Submission through Course

Portal / GitHub  Optional!!    getTotalNumberOfWords()  getTotalUniqueWords()  get20MostFrequentWords()  get20MostInterestingFrequentWords()  get20LeastFrequentWords()  getFrequencyOfWord()  getChapterQuoteAppears()  generateSentence()  Extra : getAutocompleteSentence(), ﬁndClosestMatchingQuote() PDF summarizing your ﬁndings from running the methods above

6. ### Number of Islands Given a 2d grid map of '1's

(land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water. Example 1:  Input:  11110  11010  11000  00000    Output: 1 Example 2: Input: 11000 11000 00100 00011 Output: 3
7. ### Number of Islands Iterate through 2D array  - if we

see a 1, add it to the count of islands we’ve seen  - iterate through it’s neighbors so they can be clumped together
8. ### Number of Islands Iterate through 2D array  - if we

see a 1, add it to the count of islands we’ve seen  - iterate through it’s neighbors so they can be clumped together Example Input: 1100 1100 0010
9. ### Number of Islands Iterate through 2D array  - if we

see a 1, add it to the count of islands we’ve seen  - iterate through it’s neighbors so they can be clumped together - we see a ‘1’ , so let’s iterate through it’s  neighbors Example Input: 1100 1100 0010
10. ### Number of Islands Iterate through 2D array  - if we

see a 1, add it to the count of islands we’ve seen  - iterate through it’s neighbors so they can be clumped together - we see a ‘1’ , so let’s iterate through it’s  neighbors  - how should we deﬁne ‘neighbors’ Example Input: 1100 1100 0010
11. ### Number of Islands Iterate through 2D array  - if we

see a 1, add it to the count of islands we’ve seen  - iterate through it’s neighbors so they can be clumped together - we see a ‘1’ , so let’s iterate through it’s  neighbors  - how should we deﬁne ‘neighbors’  - top, left, right, bottom Example Input: 1100 1100 0010
12. ### Number of Islands Iterate through 2D array  - if we

see a 1, add it to the count of islands we’ve seen  - iterate through it’s neighbors so they can be clumped together - we see a ‘1’ , so let’s iterate through it’s  neighbors  - how should we deﬁne ‘neighbors’  - top, left, right, bottom Example Input: 1100 1100 0010
13. ### Number of Islands Iterate through 2D array  - if we

see a 1, add it to the count of islands we’ve seen  - iterate through it’s neighbors so they can be clumped together - we see a ‘1’ , so let’s iterate through it’s  neighbors  - how should we deﬁne ‘neighbors’  - top, left, right, bottom - we see another 1 while visiting the original  1’s neighbors. now we should visit all of this   1’s neighbors Example Input: 1100 1100 0010
14. ### Number of Islands Iterate through 2D array  - if we

see a 1, add it to the count of islands we’ve seen  - iterate through it’s neighbors so they can be clumped together - we see a ‘1’ , so let’s iterate through it’s  neighbors  - how should we deﬁne ‘neighbors’  - top, left, right, bottom - we see another 1 while visiting the original  1’s neighbors. now we should visit all of this   1’s neighbors Example Input: 1100 1100 0010
15. ### Number of Islands Iterate through 2D array  - if we

see a 1, add it to the count of islands we’ve seen  - iterate through it’s neighbors so they can be clumped together - we see a ‘1’ , so let’s iterate through it’s  neighbors  - how should we deﬁne ‘neighbors’  - top, left, right, bottom - we see another 1 while visiting the original  1’s neighbors. now we should visit all of this   1’s neighbors - now we’ve caught ourselves in an inﬁnite loop! Example Input: 1100 1100 0010
16. ### Number of Islands Iterate through 2D array  - if we

see a 1, add it to the count of islands we’ve seen  - iterate through it’s neighbors so they can be clumped together - we see a ‘1’ , so let’s iterate through it’s  neighbors  - how should we deﬁne ‘neighbors’  - top, left, right, bottom - we see another 1 while visiting the original  1’s neighbors. now we should visit all of this   1’s neighbors - we need to keep track of which nodes have been visited Example Input: 1100 1100 0010
17. ### Number of Islands Iterate through 2D array  - if we

see a 1, add it to the count of islands we’ve seen  - iterate through it’s neighbors so they can be clumped together - we see a ‘1’ , so let’s iterate through it’s  neighbors  - how should we deﬁne ‘neighbors’  - top, left, right, bottom - we see another 1 while visiting the original  1’s neighbors. now we should visit all of this   1’s neighbors - we need to keep track of which nodes have been visited  mark visited cells (something not 0 or 1) so we know it’s visited Example Input: 1100 1100 0010
18. ### Number of Islands Iterate through 2D array  - if we

see a 1, add it to the count of islands we’ve seen  - iterate through it’s neighbors so they can be clumped together - we see a ‘1’ , so let’s iterate through it’s  neighbors  - how should we deﬁne ‘neighbors’  - top, left, right, bottom - we see another 1 while visiting the original  1’s neighbors. now we should visit all of this   1’s neighbors - mark visited cells with ‘-1’ Example Input: 1100 1100 0010
19. ### Number of Islands Iterate through 2D array  - if we

see a 1, add it to the count of islands we’ve seen  - iterate through it’s neighbors so they can be clumped together - we see a ‘1’ , so let’s iterate through it’s  neighbors  - how should we deﬁne ‘neighbors’  - top, left, right, bottom - we see another 1 while visiting the original  1’s neighbors. now we should visit all of this   1’s neighbors - mark visited cells with ‘-1’ Example Input: -1100 1 100 0 010
20. ### Number of Islands Iterate through each cell in the matrix

When we see a ‘1’ , do a BFS or DFS to visit the whole ‘island’  mark cells as ‘-1’ once we’ve seen it  increment the number of islands we’ve seen once the whole island is   visited
21. ### Number of Islands Iterate through each cell in the matrix

When we see a ‘1’ , do a BFS or DFS to visit the whole ‘island’  mark cells as ‘-1’ once we’ve seen it  increment the number of islands we’ve seen once the whole island is   visited isValidPosition(int x, int y)
22. ### Number of Islands Iterate through each cell in the matrix

When we see a ‘1’ , do a BFS or DFS to visit the whole ‘island’  mark cells as ‘-1’ once we’ve seen it  increment the number of islands we’ve seen once the whole island is   visited isValidPosition(int x, int y) // possible moves from a current cell  static int[] dx = {-1,0,0,1};  static int[] dy = {0,1,-1,0};
23. ### Mock Interviewing 1) Decide which problems you want to tackle

2) Prepare for your problem (understand different approaches and solutions)  3) Do First Mock Interview  4) Offer feedback  5) Do Second Mock Interview  6) Offer feedback  7) Tackle third problem together When you’re the interviewer, try to take constructive feedback notes for your partner
24. ### Mock Interviewing Showing enthusiasm and being engaged Planning out with

pseudocode / comments It’s great to talk through the problem and your different approaches, but always try running your code!  - It’s great to look at many problems so you can start seeing patterns  but…   - Usually the hardest parts of the problem doesn’t manifest itself until   you try it out