├── Arr_IndexAndElement_Equal └── Readme.md ├── Array_of_Array_Products ├── Pramp.java └── Readme.md ├── BST_Successor └── Readme.md ├── Budget_Cuts └── Readme.md ├── Busiest_Time ├── Pramp.java └── Readme.md ├── Drone_Flight_Planner ├── Pramp.java └── Readme.md ├── Flatten_Dictionary └── Readme.md ├── Getting_Diff_Number ├── Pramp.java └── Readme.md ├── H-Tree └── Readme.md ├── Island_Count └── Readme.md ├── K-Messed_Array_Sort └── Readme.md ├── Matrix_Spiral_Print ├── Pramp.java └── Readme.md ├── Merge_Packages └── Readme.md ├── Quad_Combination └── Readme.md ├── README.md ├── Sentence_Reverse └── Readme.md ├── Shifted_Array_Search └── Readme.md ├── Smallest_Substring ├── Pramp.java └── Readme.md ├── Sudoku_Solver ├── Pramp.java └── Readme.md └── Word_Count_Engine ├── Pramp.java └── README.md /Arr_IndexAndElement_Equal/Readme.md: -------------------------------------------------------------------------------- 1 | #Array Index & Element Equality 2 | 3 | Given an array of sorted distinct integers named arr, write a function that returns an index i in arr for which arr[i] = i or -1 if no such index exists. 4 | 5 | Implement the most efficient solution possible, prove the correctness of your solution and analyze its runtime complexity (in terms of n - the length of arr). 6 | 7 | Examples: 8 | 9 | Given arr = [-8,0,2,5] the function returns 2, since arr[2] = 2 10 | Given arr = [-1,0,3,6] the function returns -1, since no index in arr satisfies arr[i] = i 11 | -------------------------------------------------------------------------------- /Array_of_Array_Products/Pramp.java: -------------------------------------------------------------------------------- 1 | public class Pramp { 2 | public static int[] getAoAP(int[] arr){ 3 | if( arr == null || arr.length == 0) { 4 | return null; 5 | } 6 | int n = arr.length; 7 | int[] result = new int[n]; 8 | result[0] = 1; 9 | for(int i = 1; i < n; i++) { 10 | result[i] = arr[i-1] * result[i-1]; 11 | } 12 | int product = 1; 13 | for(int i = n-2; i >= 0; i--) { 14 | product *= arr[i+1]; 15 | result[i] *= product; 16 | } 17 | 18 | return result; 19 | } 20 | 21 | public static void main(String []args){ 22 | int[] arr = {1, 2, 3, 4, 5}; 23 | arr = getAoAP(arr); 24 | for( int i : arr ) { 25 | System.out.println( i ); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Array_of_Array_Products/Readme.md: -------------------------------------------------------------------------------- 1 | #Array of Array Products 2 | 3 | Given an array of integers arr, write a function that returns another array at the same length where the value at each index i is the product of all array values except arr[i]. 4 | 5 | Solve without using division and analyze the runtime and space complexity 6 | 7 | Example: given the array [2, 7, 3, 4] 8 | your function would return: [84, 24, 56, 42] 9 | (by calculating: [7*3*4, 2*3*4, 2*7*4, 2*7*3]) 10 | -------------------------------------------------------------------------------- /BST_Successor/Readme.md: -------------------------------------------------------------------------------- 1 | #BST Successor Search 2 | 3 | Given a node n in a binary search tree, explain and code the most efficient way to find the successor of n. 4 | Analyze the runtime complexity of your solution. 5 | -------------------------------------------------------------------------------- /Budget_Cuts/Readme.md: -------------------------------------------------------------------------------- 1 | #Award Budget Cuts 2 | 3 | The awards committee had planned to give n research grants this year, out of a its total yearly budget. 4 | However, the budget was reduced to b dollars. The committee members has decided to affect the minimal number of highest grants, by applying a maximum cap c on all grants: every grant that was planned to be higher than c will now be c dollars. 5 | Help the committee to choose the right value of c that would make the total sum of grants equal to the new budget. 6 | 7 | Given an array of grants g and a new budget b, explain and code an efficient method to find the cap c. Assume that each grant is unique. 8 | Analyze the time and space complexity of your solution. 9 | -------------------------------------------------------------------------------- /Busiest_Time/Pramp.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Pramp { 3 | public static long[] getBusiestTime(Data[] arr){ 4 | long[] result = new long[2]; 5 | if( arr == null || arr.length == 0) { 6 | return null; 7 | } 8 | 9 | Arrays.sort(arr); // sort array by time; 10 | int max = 0; 11 | int cur = 0; 12 | int len = arr.length-1; 13 | 14 | 15 | for( int i = 0; i <= len; i++) { 16 | if( arr[i].enter ) { 17 | cur += arr[i].count; 18 | } else { 19 | cur -= arr[i].count; 20 | } 21 | 22 | if( i < len && arr[i].time == arr[i+1].time ){ 23 | continue; 24 | } 25 | 26 | if( cur > max ) { 27 | max = cur; 28 | result[0] = arr[i].time; 29 | 30 | if( i < len ) { 31 | result[1] = arr[i+1].time; 32 | } else { 33 | result[1] = arr[i].time; 34 | } 35 | } 36 | } 37 | 38 | return result; 39 | } 40 | 41 | public static void main(String []args){ 42 | Data[] info = new Data[10]; 43 | info[0] = new Data(1,2,false); 44 | info[1] = new Data(2,2,true); 45 | info[2] = new Data(21,2,true); 46 | info[3] = new Data(13,2,true); 47 | info[4] = new Data(1,2,true); 48 | info[5] = new Data(34,2,false); 49 | info[6] = new Data(3,2,false); 50 | info[7] = new Data(55,2,false); 51 | info[8] = new Data(5,2,true); 52 | info[9] = new Data(8,2,false); 53 | 54 | long[] result = getBusiestTime(info); 55 | System.out.println(result[0] + " to " + result[1]); 56 | } 57 | } 58 | class Data implements Comparable{ 59 | long time; 60 | int count; 61 | boolean enter; 62 | 63 | public Data( long t, int c, boolean e) { 64 | time = t; 65 | count = c; 66 | enter = e; 67 | } 68 | 69 | public int compareTo( Data that ) { 70 | return Long.compare(this.time, that.time); 71 | } 72 | } -------------------------------------------------------------------------------- /Busiest_Time/Readme.md: -------------------------------------------------------------------------------- 1 | #Busiest Time in The Mall 2 | 3 | The mall management is trying to figure out what was the busiest moment in the mall in the last year. 4 | You are given data from the door detectors: each data entry includes a timestamp (seconds in [Unix Epoch](https://en.wikipedia.org/wiki/Unix_time) format), an amount of people and whether they entered or exited. 5 | 6 | Example of a data entry: 7 | { time: 1440084737, count: 4, type: "enter" } 8 | 9 | Find what was the busiest period in the mall on the last year. Return an array with two [Epoch](https://en.wikipedia.org/wiki/Unix_time) timestamps representing the beginning and end of that period. You may assume that the data your are given is accurate and that each second with entries or exits is recorded. Implement the most efficient solution possible and analyze its time and space complexity. -------------------------------------------------------------------------------- /Drone_Flight_Planner/Pramp.java: -------------------------------------------------------------------------------- 1 | public class Pramp { 2 | public static int getStartingFuelBetter(Point[] route){ 3 | if( route == null || route.length == 0) { 4 | return 0; 5 | } 6 | int highestPoint = route[0].z; 7 | for( int i = 1; i < route.length; i++ ) { 8 | highestPoint = Math.max(highestPoint, route[i].z); 9 | } 10 | 11 | return highestPoint - route[0].z; 12 | } 13 | public static int getStartingFuel(Point[] route){ 14 | if( route == null || route.length <= 1) { 15 | return 0; 16 | } 17 | int startingFuel = 0; 18 | int currentFuel = 0; 19 | for( int i = 1; i < route.length; i++ ) { 20 | currentFuel += route[i-1].z - route[i].z; 21 | if( currentFuel < 0 ) { 22 | startingFuel -= currentFuel; 23 | currentFuel = 0; 24 | } 25 | } 26 | 27 | return startingFuel; 28 | } 29 | 30 | public static void main(String []args){ 31 | Point[] route = new Point[5]; 32 | route[0] = new Point( 0, 2, 10); 33 | route[1] = new Point( 3, 5, 0); 34 | route[2] = new Point( 9, 20, 6); 35 | route[3] = new Point( 10, 12, 15); 36 | route[4] = new Point( 10, 10, 8); 37 | 38 | System.out.println(getStartingFuel(route) ); 39 | System.out.println(getStartingFuelBetter(route) ); 40 | } 41 | } 42 | class Point { 43 | int x; 44 | int y; 45 | int z; 46 | public Point(int i, int j, int k) { 47 | x = i; 48 | y = j; 49 | z = k; 50 | } 51 | } -------------------------------------------------------------------------------- /Drone_Flight_Planner/Readme.md: -------------------------------------------------------------------------------- 1 | #Drone Flight Planner 2 | 3 | You are planning the amount of fuel need to complete a drone flight. 4 | 5 | To fly higher, the drone burns 1 liter of fuel per feet. 6 | 7 | However, flying lower charges the drone with the amount of energy equivalent to 1 liter of fuel for every feet. 8 | 9 | Flying sideways takes no energy (only flying up and down takes/charges energy). 10 | 11 | Given an array of 3D coordinates named route, find the minimal amount of fuel the drone would need to fly through this route. 12 | 13 | Explain and code the most efficient solution possible, with the minimal number of actions and variables. 14 | 15 | Example: 16 | 17 | Completing the route 18 | [ {x: 0, y: 2, z:10}, 19 | {x: 3, y: 5, z: 0}, 20 | {x: 9, y:20, z: 6}, 21 | {x:10, y:12, z:15}, 22 | {x:10, y:10, z: 8} ] 23 | requires a minimum of 5 liters of fuel. -------------------------------------------------------------------------------- /Flatten_Dictionary/Readme.md: -------------------------------------------------------------------------------- 1 | #Flatten a Dictionary 2 | 3 | Given a dictionary, write a function to flatten it. Consider the following input/output scenario for better understanding: 4 | 5 | Input: 6 | 7 | { 8 | 'Key1': '1', 9 | 'Key2': { 10 | 'a' : '2', 11 | 'b' : '3', 12 | 'c' : { 13 | 'd' : '3', 14 | 'e' : '1' 15 | } 16 | } 17 | } 18 | 19 | Output: 20 | 21 | { 22 | 'Key1': '1', 23 | 'Key2.a': '2', 24 | 'Key2.b' : '3', 25 | 'Key2.c.d' : '3', 26 | 'Key2.c.e' : '1' 27 | } 28 | -------------------------------------------------------------------------------- /Getting_Diff_Number/Pramp.java: -------------------------------------------------------------------------------- 1 | public class Pramp { 2 | public int getDiffNum(int[] arr){ 3 | int n = arr.length; 4 | if( arr == null || n < 1 ) { 5 | return 0; // 0 is not in an empty array 6 | } 7 | 8 | boolean[] foundNum = new boolean[n+1]; 9 | 10 | for( int i : arr ) { 11 | if( i < foundNum.length ) { 12 | foundNum[i] = true; 13 | } 14 | } 15 | 16 | for( int i = 0; i < foundNum.length; i++ ) { 17 | if( !foundNum[i] ) { 18 | return i; 19 | } 20 | } 21 | 22 | return -1; // array holds more than n+1 unique elements 23 | } 24 | } -------------------------------------------------------------------------------- /Getting_Diff_Number/Readme.md: -------------------------------------------------------------------------------- 1 | #Getting a Different Number 2 | 3 | Given an array arr of n unique non-negative integers, how can you most efficiently find a non-negative integer that is not in the array? 4 | 5 | Your solution should return such an integer or null if arr contains all possible integers. 6 | Analyze the runtime and space complexity of your solution. -------------------------------------------------------------------------------- /H-Tree/Readme.md: -------------------------------------------------------------------------------- 1 | #H-Tree Construction 2 | 3 | Construct an H-tree, given its center (x and y coordinates), starting_length and depth. You can assume that you have a drawLine method. 4 | 5 | As a reminder, [this](https://en.wikipedia.org/wiki/H_tree#/media/File:H_tree.svg) is an example of an H-tree. 6 | 7 | How to construct an H-tree? 8 | 9 | An H-tree can be constructed by starting with a line segment of arbitrary length, drawing two segments of the same length at right angles to the first through its endpoints, and continuing in the same vein, reducing (dividing) the length of the line segments drawn at each stage by √2. 10 | -------------------------------------------------------------------------------- /Island_Count/Readme.md: -------------------------------------------------------------------------------- 1 | #Island Count 2 | 3 | Given a 2D matrix M, filled with either 0s or 1s, count the number of islands of 1s in M. 4 | An island is a group of adjacent values that are all 1s. Every cell in M can be adjacent to the 4 cells that are next to it on the same row or column. 5 | 6 | Explain and code the most efficient solution possible and analyze its runtime complexity. 7 | 8 | Example: the matrix below has 6 islands: 9 | 10 | 0 1 0 1 0 11 | 0 0 1 1 1 12 | 1 0 0 1 0 13 | 0 1 1 0 0 14 | 1 0 1 0 1 15 | 16 | -------------------------------------------------------------------------------- /K-Messed_Array_Sort/Readme.md: -------------------------------------------------------------------------------- 1 | #K-Messed Array Sort 2 | 3 | Given an array arr of length n where each element is at most k places away from its sorted position, 4 | 5 | Plan and code an efficient algorithm to sort arr. 6 | 7 | Analyze the runtime and space complexity of your solution. 8 | 9 | Example: 10 | 11 | n=10, k=2 12 | The element belonging to index 6 in the sorted array, may be at indices 4, 5, 6, 7 or 8 on the given array. 13 | -------------------------------------------------------------------------------- /Matrix_Spiral_Print/Pramp.java: -------------------------------------------------------------------------------- 1 | public class Pramp { 2 | public static void spiralPrint(int[][] M) { 3 | if( M == null || M.length == 0 || M[0] == null || M[0].length == 0) { 4 | return; 5 | } 6 | int lastRow = M.length -1; 7 | int lastCol = M[0].length -1; 8 | 9 | int frstRow = 0; 10 | int frstCol = 0; 11 | 12 | StringBuilder sb = new StringBuilder(); 13 | 14 | while ( frstCol <= lastCol && frstRow <= lastRow ) { 15 | for( int j = frstCol; j <= lastCol; j++ ) { 16 | // Right 17 | sb.append( M[frstRow][j] ); 18 | sb.append( " " ); 19 | } 20 | frstRow++; 21 | 22 | for( int i = frstRow; i <= lastRow; i++ ) { 23 | // Down 24 | sb.append( M[i][lastCol] ); 25 | sb.append( " " ); 26 | } 27 | lastCol--; 28 | 29 | for( int j = lastCol; j >= frstCol; j-- ) { 30 | // Left 31 | sb.append( M[lastRow][j] ); 32 | sb.append( " " ); 33 | } 34 | lastRow--; 35 | 36 | for( int i = lastRow; i >= frstRow; i-- ) { 37 | // Up 38 | sb.append( M[i][frstCol] ); 39 | sb.append( " " ); 40 | } 41 | frstCol++; 42 | } 43 | 44 | System.out.println( sb.toString() ); 45 | } 46 | public static void main(String []args){ 47 | int[][] arr = {{ 1, 2, 3, 4, 5}, 48 | { 6, 7, 8, 9,10}, 49 | {11,12,13,14,15}, 50 | {16,17,18,19,20} }; 51 | spiralPrint(arr); 52 | } 53 | } -------------------------------------------------------------------------------- /Matrix_Spiral_Print/Readme.md: -------------------------------------------------------------------------------- 1 | #Matrix Spiral Print 2 | 3 | Given a 2D array (matrix) named M, print all items of M in a spiral order, clockwise. 4 | 5 | For example: 6 | 7 | M = 1 2 3 4 5 8 | 6 7 8 9 10 9 | 11 12 13 14 15 10 | 16 17 18 19 20 11 | 12 | The clockwise spiral print is: 1 2 3 4 5 10 15 20 19 18 17 16 11 6 7 8 9 14 13 12 -------------------------------------------------------------------------------- /Merge_Packages/Readme.md: -------------------------------------------------------------------------------- 1 | #Merging 2 Packages 2 | 3 | Given a package with a weight limit and an array arr of item weights, how can you most efficiently find two items with sum of weights that equals the weight limit? 4 | 5 | Your function should return 2 such indices of item weights or -1 if such pair doesn't exist. 6 | What is the runtime and space complexity of your solution? 7 | -------------------------------------------------------------------------------- /Quad_Combination/Readme.md: -------------------------------------------------------------------------------- 1 | #Quad Combination 2 | 3 | Given an array of numbers arr and a number S, find 4 different numbers in arr that sum up to S. 4 | 5 | Write a function that gets arr and S and returns an array with 4 indices of such numbers in arr, or null if no such combination exists. 6 | 7 | Explain and code the most efficient solution possible, and analyze its runtime and space complexity. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pramp 2 | A repository containing my solutions to the practice interview questions presented by Pramp 3 | 4 | [![](https://www.pramp.com/img/prampLogo_74px.png)](https://www.pramp.com/ "To Pramp site") 5 | -------------------------------------------------------------------------------- /Sentence_Reverse/Readme.md: -------------------------------------------------------------------------------- 1 | #Sentence Reverse 2 | 3 | You are given an array of characters arr, which consists of sequences of characters separated by space characters. Each space-delimited sequence of characters defines a word. 4 | How can you most efficiently reverse the order of the words in the array? 5 | Explain and implement your solution. Lastly, analyze its time and space complexities. 6 | 7 | For example: 8 | 9 | [ 'p', 'e', 'r', 'f', 'e', 'c', 't', ' ', 'm', 'a', 'k', 'e', 's', ' ', 'p', 'r', 'a', 'c', 't', 'i', 'c', 'e' ] 10 | 11 | would turn into: 12 | 13 | [ 'p', 'r', 'a', 'c', 't', 'i', 'c', 'e', ' ', 'm', 'a', 'k', 'e', 's', ' ', 'p', 'e', 'r', 'f', 'e', 'c', 't' ] 14 | -------------------------------------------------------------------------------- /Shifted_Array_Search/Readme.md: -------------------------------------------------------------------------------- 1 | #Shifted Array Search 2 | 3 | 1. Find a given number num in a sorted array arr: 4 | 5 | arr = [2, 4, 5, 9, 12, 17] 6 | 7 | 2. If the sorted array arr is shifted left by an unknown offset and you don't have a pre-shifted copy of it, how would you modify your method to find a number in the shifted array? 8 | 9 | shiftArr = [9, 12, 17, 2, 4, 5] 10 | 11 | Explain and code an efficient solution and analyze its runtime complexity 12 | if num doesn't exist in the array, return -1 13 | -------------------------------------------------------------------------------- /Smallest_Substring/Pramp.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | public class Pramp { 3 | public static String getSmallestSubString(String str, char[] arr){ 4 | if( arr == null || str == null || 5 | str.length() == 0 || arr.length > str.length()) { 6 | return null; 7 | } 8 | 9 | String result = null; 10 | 11 | HashMap map = new HashMap<>(); 12 | 13 | for( char c : arr ) { 14 | map.put( c, 0); 15 | } 16 | 17 | int head = 0; 18 | int charsToFind=arr.length; 19 | char c; 20 | int stringLength; 21 | 22 | for( int i = 0; i < str.length(); i++ ) { 23 | c = str.charAt(i); 24 | if( map.containsKey( c ) ) { 25 | if( map.get(c) == 0 ) { 26 | charsToFind--; 27 | } 28 | map.put(c, map.get(c) + 1); 29 | } 30 | 31 | while( charsToFind == 0 ) { 32 | stringLength = i - head + 1; 33 | if( result == null || result.length() > stringLength ) { 34 | result = str.substring(head, i + 1); 35 | if( result.length() == arr.length ) { 36 | // early termination since we found smallest possible 37 | return result; 38 | } 39 | } 40 | // shrink our string by advancing the head 41 | c = str.charAt(head); 42 | if( map.containsKey( c ) ) { 43 | map.put(c, map.get(c) - 1); 44 | if( map.get(c) == 0 ) { 45 | charsToFind++; 46 | } 47 | } 48 | head++; 49 | } 50 | } 51 | 52 | return result; 53 | } 54 | 55 | public static void main(String []args){ 56 | String str = "xyyzyzyx"; 57 | char[] arr = {'x','y','z'}; 58 | 59 | System.out.println(getSmallestSubString(str, arr) ); 60 | } 61 | } -------------------------------------------------------------------------------- /Smallest_Substring/Readme.md: -------------------------------------------------------------------------------- 1 | #Smallest Substring of All Characters 2 | 3 | Given an array with unique characters arr and a string str, find the smallest substring of str containing all characters of arr. 4 | 5 | Example: 6 | arr: [x,y,z], str: xyyzyzyx 7 | result: zyx 8 | 9 | Implement your solution and analyze the runtime complexity 10 | -------------------------------------------------------------------------------- /Sudoku_Solver/Pramp.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Pramp { 3 | public static boolean sudokuSolve(int[][] board){ 4 | if( board == null || board.length != 0 || board[0] == null || board[0].length != 9) { 5 | throw new illegalArgumentException(); 6 | } 7 | 8 | Set[] rows = new HashSet[9]; 9 | Set[] cols = new HashSet[9]; 10 | Set[] m3x3 = new HashSet[9]; 11 | for( int i = 0; i < 9; i++) { 12 | rows[i] = new HashSet(); 13 | cols[i] = new HashSet(); 14 | m3x3[i] = new HashSet(); 15 | } 16 | 17 | int value; 18 | int grid; 19 | for( int i = 0; i < 9; i++ ) { 20 | for( int j = 0; j < 9; j++ ) { 21 | value = board[i][j]; 22 | if( value == 0 ) { 23 | continue; 24 | } 25 | grid = get3x3Grid(i,j); 26 | if( rows[i].contains( value ) || 27 | cols[j].contains( value ) || 28 | m3x3[grid].contains( value ) ) { 29 | return false; 30 | } 31 | rows[i].add( value ); 32 | cols[j].add( value ); 33 | m3x3[grid].add( value ); 34 | } 35 | } 36 | 37 | Set legalValues = new HashSet<>(); 38 | for(int i = 1; i <= 9; i++) { 39 | legalValues.add(i); 40 | } 41 | Set tempSet;// = new HashSet<>(); 42 | 43 | for( int i = 0; i < 9; i++ ) { 44 | for( int j = 0; j < 9; j++ ) { 45 | value = board[i][j]; 46 | if( value != 0 ) { 47 | continue; 48 | } 49 | grid = get3x3Grid(i,j); 50 | tempSet = new HashSet<>(); 51 | tempSet.addAll(legalValues); 52 | tempSet.removeAll(rows[i]); 53 | tempSet.removeAll(cols[j]); 54 | tempSet.removeAll(m3x3[grid]); 55 | if( tempSet.size() == 0 ) { 56 | return false; 57 | } 58 | } 59 | } 60 | 61 | 62 | return true;; 63 | } 64 | 65 | public static int get3x3Grid(int i; int j) { 66 | int row = i / 3; 67 | int col = j / 3; 68 | return 3 * row + col; 69 | } 70 | 71 | public static void main(String []args){ 72 | System.out.println(""); 73 | } 74 | } -------------------------------------------------------------------------------- /Sudoku_Solver/Readme.md: -------------------------------------------------------------------------------- 1 | #Sudoku Solver 2 | 3 | Write the function sudokuSolve that checks whether a given sudoku board (i.e. sudoku puzzle) is solvable. If so, the function will returns True. Otherwise (i.e. there is no valid solution to the given sudoku board), returns False. 4 | 5 | In sudoku, the objective is to fill a 9x9 board with digits so that each column, each row, and each of the nine 3x3 sub-boards that compose the board contains all of the digits from 1 to 9. The board setter provides a partially completed board, which for a well-posed board has a unique solution. As explained above, for this problem, it suffices to calculate whether a given sudoku board has a solution. No need to return the actual numbers that make up a solution. 6 | 7 | A sudoku board is represented in a two dimensional 9x9 array with the numbers 1,2,...,9 and blank spaces, and the function should fill the blank spaces with numbers such that the following rules apply: 8 | 9 | 1. In every row of the array, all numbers 1,2,...,9 appear exactly once. 10 | 2. In every column of the array, all numbers 1,2,...,9 appear exactly once. 11 | 3. In every 3x3 sub-board that is illustrated below, all numbers 1,2,...,9 appear exactly once. 12 | 13 | A solved sudoku is a board with no blank spaces, i.e. all blank spaces are filled with numbers that abide to the constraints above. If the function succeeds in solving the sudoku board, it'll return true (false, otherwise). 14 | 15 | Example (more examples can be found [here](http://www.sudokukingdom.com/)): 16 | 17 | ![](https://upload.wikimedia.org/wikipedia/commons/f/ff/Sudoku-by-L2G-20050714.svg) 18 | 19 | A typical Sudoku board setter 20 | 21 | ![](https://upload.wikimedia.org/wikipedia/commons/3/31/Sudoku-by-L2G-20050714_solution.svg) 22 | 23 | The same board with solution numbers marked in red 24 | 25 | Write a readable an efficient code, explain how it is built and why you chose to build it that way. -------------------------------------------------------------------------------- /Word_Count_Engine/Pramp.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Pramp { 3 | public static List getBusiestTime(String doc){ 4 | if( doc == null || doc.length() == 0) { 5 | return null; 6 | } 7 | 8 | Map map = new HashMap<>(); 9 | String[] allWords = doc.toLowerCase().split("[^a-zA-Z]+"); 10 | 11 | for( String s : allWords ) { 12 | if( map.containsKey(s) ) { 13 | map.put( s, map.get(s) + 1 ); 14 | } else { 15 | map.put( s, 1 ); 16 | } 17 | } 18 | 19 | List result = new ArrayList(); 20 | for( String key : map.keySet() ) { 21 | result.add( new Data( key, map.get(key) ) ); 22 | } 23 | Collections.sort(result); 24 | return result; 25 | } 26 | 27 | public static void main(String []args){ 28 | String doc = "practice makes perfect. get perfect by practice. just practice!"; 29 | List result = getBusiestTime(doc); 30 | for( Data d : result) { 31 | System.out.println(d.word + " : " + d.count); 32 | } 33 | } 34 | } 35 | class Data implements Comparable{ 36 | String word; 37 | int count; 38 | 39 | public Data( String w, int c) { 40 | word = w; 41 | count = c; 42 | } 43 | 44 | public int compareTo( Data that ) { 45 | // sorts in descending order 46 | return that.count - this.count; 47 | } 48 | } -------------------------------------------------------------------------------- /Word_Count_Engine/README.md: -------------------------------------------------------------------------------- 1 | #Word Count Engine 2 | 3 | Implement a document scanning engine that receives a text document doc and returns a list of all unique words in it and their number of occurrences, sorted by the number of occurrences in descending order. 4 | 5 | Example: 6 | 7 | for doc: "practice makes perfect. get perfect by practice. just practice!" 8 | 9 | the engine returns the list: { practice: 3, perfect: 2, makes: 1, get: 1, by: 1, just: 1 }. 10 | 11 | The engine should ignore punctuation and white-spaces. 12 | 13 | Find the minimal runtime complexity and analyze it. --------------------------------------------------------------------------------