Share
Embed
Transcript
24 slides
-
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 -
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 -
Project Gutenberg Text Analysis on a novel Submission through Course
Portal / GitHub Optional!! getTotalNumberOfWords() getTotalUniqueWords() get20MostFrequentWords() get20MostInterestingFrequentWords() get20LeastFrequentWords() getFrequencyOfWord() getChapterQuoteAppears() generateSentence() Extra : getAutocompleteSentence(), findClosestMatchingQuote() PDF summarizing your findings from running the methods above -
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 -
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 -
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 -
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 -
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 define ‘neighbors’ Example Input: 1100 1100 0010 -
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 define ‘neighbors’ - top, left, right, bottom Example Input: 1100 1100 0010 -
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 define ‘neighbors’ - top, left, right, bottom Example Input: 1100 1100 0010 -
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 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 -
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 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 -
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 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 -
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 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 -
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 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 -
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 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 -
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 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 -
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 -
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) -
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}; -
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 -
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