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
Portal / GitHub Optional!! getTotalNumberOfWords() getTotalUniqueWords() get20MostFrequentWords() get20MostInterestingFrequentWords() get20LeastFrequentWords() getFrequencyOfWord() getChapterQuoteAppears() generateSentence() Extra : getAutocompleteSentence(), findClosestMatchingQuote() PDF summarizing your findings from running the methods above
(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
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
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 define ‘neighbors’ Example Input: 1100 1100 0010
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 define ‘neighbors’ - top, left, right, bottom Example Input: 1100 1100 0010
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 define ‘neighbors’ - top, left, right, bottom Example Input: 1100 1100 0010
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 define ‘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
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 define ‘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
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 define ‘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 infinite loop! Example Input: 1100 1100 0010
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 define ‘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
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 define ‘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
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 define ‘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
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 define ‘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
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
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)
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};
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
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