|
1 |
| -# hash-practice |
| 1 | +# Hash Table Practice |
| 2 | + |
| 3 | +In this exercise you will complete two coding problems using Hash Tables. |
| 4 | + |
| 5 | +## Learning Goals |
| 6 | + |
| 7 | +By the end of this exercise you should be able to: |
| 8 | + |
| 9 | +- Use a hash table to solve a coding problem |
| 10 | +- Identify how a hash table can produce a more attractive runtime over alternative solutions |
| 11 | + |
| 12 | +## Grouped Anagrams |
| 13 | + |
| 14 | +Given an array of strings, group anagrams together. |
| 15 | + |
| 16 | +### Example |
| 17 | + |
| 18 | +``` |
| 19 | +Input: ["eat", "tea", "tan", "ate", "nat", "bat"], |
| 20 | +Output: |
| 21 | +[ |
| 22 | + ["ate","eat","tea"], |
| 23 | + ["nat","tan"], |
| 24 | + ["bat"] |
| 25 | +] |
| 26 | +``` |
| 27 | + |
| 28 | +Note: |
| 29 | + |
| 30 | +- All inputs will be in lowercase. |
| 31 | +- The order of your output does not matter |
| 32 | + |
| 33 | +## Valid Sudoku |
| 34 | + |
| 35 | +Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: |
| 36 | + |
| 37 | +1. Each row must contain the digits 1-9 without repetition. |
| 38 | +1. Each column must contain the digits 1-9 without repetition. |
| 39 | +1. Each of the 9 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition. |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +Above is a valid Sudoku grid. |
| 44 | + |
| 45 | +The Sudoku board could be partially filled, where empty cells are filled with the character '.'. |
| 46 | + |
| 47 | +**Example 1:** |
| 48 | + |
| 49 | +``` |
| 50 | +Input: |
| 51 | +[ |
| 52 | + ["5","3",".",".","7",".",".",".","."], |
| 53 | + ["6",".",".","1","9","5",".",".","."], |
| 54 | + [".","9","8",".",".",".",".","6","."], |
| 55 | + ["8",".",".",".","6",".",".",".","3"], |
| 56 | + ["4",".",".","8",".","3",".",".","1"], |
| 57 | + ["7",".",".",".","2",".",".",".","6"], |
| 58 | + [".","6",".",".",".",".","2","8","."], |
| 59 | + [".",".",".","4","1","9",".",".","5"], |
| 60 | + [".",".",".",".","8",".",".","7","9"] |
| 61 | +] |
| 62 | +Output: true |
| 63 | +``` |
| 64 | + |
| 65 | + |
| 66 | +**Example 2:** |
| 67 | + |
| 68 | +``` |
| 69 | +Input: |
| 70 | +[ |
| 71 | + ["8","3",".",".","7",".",".",".","."], |
| 72 | + ["6",".",".","1","9","5",".",".","."], |
| 73 | + [".","9","8",".",".",".",".","6","."], |
| 74 | + ["8",".",".",".","6",".",".",".","3"], |
| 75 | + ["4",".",".","8",".","3",".",".","1"], |
| 76 | + ["7",".",".",".","2",".",".",".","6"], |
| 77 | + [".","6",".",".",".",".","2","8","."], |
| 78 | + [".",".",".","4","1","9",".",".","5"], |
| 79 | + [".",".",".",".","8",".",".","7","9"] |
| 80 | +] |
| 81 | +Output: false |
| 82 | +Explanation: Same as Example 1, except with the 5 in the top left corner being |
| 83 | + modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid. |
| 84 | +
|
| 85 | +``` |
0 commit comments