51 |
52 |
Tips:
53 |
54 |
55 | - Remember to talk out loud! - Interviewers want to understand how you think and approach problems, so talk out loud while you’re solving problems. Let the interviewer see how you’re tackling the problem, and they just might guide you as well.
56 | - Ask Questions- If you're unsure of the parameters of the question or how to proceed, do be afraid to ask questions or for clarification. Here are the overall topics that we are covering in this page:
57 |
58 |
59 |
60 |
61 | "General Algorithms
62 | Arrays, Hashes and Strings
63 | Lists
64 | Stacks and Queues
65 | Trees and Graphs"
66 |
67 |
68 |
69 |
70 |
Roman Numerals
71 |
72 | Write a method that converts an integer to its Roman numeral equivalent, i.e., 476 => 'CDLXXVI'.
73 | For reference, these are the building blocks for how we encode numbers with Roman numerals:
74 | I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000
75 | Choose Between
76 | Old-school Roman numerals (no subtraction of 4s and 9s)
77 | 4 = IIII, 9 = VIIII etc.
78 | Modern Roman numerals (subtraction)
79 | 4 = IV, 9 = IX, 14 = XIV, 40 = XL, 44 = XLIV, 90 = XC, 944 = CMXLIV
80 |
81 |
82 |
Pig Latin
83 |
84 | Write a method the takes in a string and returns the pig latin equivalent. Pig Latin takes the first consonant, moves it to the end of the word and places “ay” at the end. If the string starts with a consonant do nothing.
85 | “pig” = “igpay”, “banana” = “ananabay”
86 |
87 |
88 |
Shuffle
89 |
90 | Without using a shuffle or sort write your own shuffle method for an array. The method will take an array and returns a new array with all of the elements in a random order. One important property of a good shuffle method is that every permutation is equally likely.
91 |
92 |
93 |
Anagrams
94 |
95 |
96 | An anagram is a word formed by rearranging the letters of another word, e.g., iceman is an anagram of cinema.
97 |
98 | We're going to write a method called anagrams_for that takes as its input a word and an array of words, representing a dictionary, and returns an array consisting of all the anagrams of the input word.
99 |
100 | anagrams_for should return an empty array ([]) if no anagrams are found in the dictionary. You don't have to worry about the order of the returned Array.
101 |
102 |
103 |
Factorial
104 |
105 |
106 |
107 | Write a recursive and iterative solution for a finding the factorial of a number. If you don't remember, the factorial of a non-negative integer n, denoted n! is the product of all positive integers less than . For example, 5! = 5 * 4 * 3 * 2 * 1
108 |
109 |
110 |
Binary vs. Linear Searching
111 |
112 |
113 | Write an example demonstrating Binary Search.
114 | Write an example demonstrating Linear Search.
115 |
116 | Hint: A linear search looks down a list, one item at a time, without jumping. In complexity terms this is an O(n) search - the time taken to search the list gets bigger at the same rate as the list does.
117 |
118 | A binary search is when you start with the middle of a sorted list, and see whether that's greater than or less than the value you're looking for, which determines whether the value is in the first or second half of the list.
119 |
120 |
121 |
122 |
Fibonacci
123 |
124 | Implement an iterative version of the Fibonacci sequence which take an integer n as input and returns the nth Fibonacci number.
125 |
126 | Implement a recursive version of the Fibonacci sequence which take an integer n as input and returns the nth Fibonacci number.
127 |
128 | In mathematics, the Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers in the following integer sequence:[1][2]
129 | 0,1,1,2,3,5,8,13,21,34,55,89,144
130 | By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two.
131 | In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
132 | F_n = F_{n-1} + F_{n-2}
133 |
134 |
135 |
Apple Stock
136 |
137 | I have an array stockPricesYesterday where the keys are the number of minutes into the day (starting with midnight) and the values are the price of Apple stock at that time. For example, the stock cost $500 at 1am, so stockPricesYesterday[60] = 500.
138 |
139 | Write an efficient algorithm for computing the best profit I could have made from 1 purchase and 1 sale of an Apple stock yesterday.
140 |
141 |
142 |
Arrays
143 |
Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?
144 |
145 |
146 |
147 |
Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.)
148 |
149 |
Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer. NOTE: One or two additional variables are fine. An extra copy of the array is not. Write the test cases for this method.
150 |
151 |
Write a method to decide if two strings are anagrams or not.
152 |
153 |
154 |
Lists
155 |
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.
156 |
157 | EXAMPLE
158 |
159 | Input: the node ‘c’ from the linked list a->b->c->d->e
160 | Result: nothing is returned, but the new linked list looks like a->b->d->e
161 |
162 |
163 |
164 |
You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list.
165 |
166 | EXAMPLE
167 | Input: (3 -> 1 -> 5) + (5 -> 9 -> 2)
168 | Output: 8 -> 0 -> 8
169 |
170 |
171 |
172 |
173 | Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.
174 | Circular linked list: A (corrupt) linked list in which a node’s next pointer points to an earlier node, so as to make a loop in the linked list.
175 |
176 | EXAMPLE
177 | input: A -> B -> C -> D -> E -> C [the same C as earlier]
178 | output: C
179 |
180 |
181 |
182 |
183 | Given two different lists of objects, come up with an efficient solution to find the intersection of the two lists.
184 |
185 |
186 |
Trees
187 |
188 | Implement a function to check if a tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that no two leaf nodes differ in distance from the root by more than one.
189 |
190 |
191 |
Given a directed graph, design an algorithm to find out whether there is a route between two nodes.
192 |
193 |
Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height.
194 |
195 |
Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (i.e., if you have a tree with depth D, you’ll have D linked lists).
196 |
197 |
198 |
Stacks
199 |
In the classic problem of the Towers of Hanoi, you have 3 rods and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from top to bottom (e.g., each disk sits on top of an even larger one). You have the following constraints:
200 |
201 | (A) Only one disk can be moved at a time.
202 | (B) A disk is slid off the top of one rod onto the next rod.
203 | (C) A disk can only be placed on top of a larger disk.
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 | Write a program to move the disks from the first rod to the last using Stacks.
213 |
214 |
215 |
216 |
217 | Write a program to sort a stack in ascending order. You should not make any assumptions about how the stack is implemented. The following are the only functions that should be used to write this program: push | pop | peek | isEmpty.
218 |
219 |
220 |
221 |
222 |
223 |
224 |