## Tuesday, February 4, 2014

### How to prepare for an interview - 16

Back to a new set of problems. If you didn't read previous posts start from here. Read previous post here.

Remember you should discuss these solutions with me, and refer if there are mistakes or other good solutions.

Problems

151. Given an array of integers, now we want to erase all 0's (can be other value), and we want the result array condensed, meaning no empty cell in the array.

152. Given a list of words with a same size and a big string that contains one of the permutation of all the words combined(say p), find the start index of the string p in the big string.

153. Print out all prime numbers in a given string. abc2134kd31 -> 2, 13, 3, 3.

154. Generate a new array from an array of numbers. Start from the beginning. Put the number of some number first, and then that number, For example, from array 1, 1, 2, 3, 3, 1 You should get 2, 1, 1, 2, 2, 3, 1, 1.

155. Implement a function rotateArray(vector<int> arr, int r) which rotates the array by r places. Eg 1 2 3 4 5 on being rotated by 2 gives 4 5 1 2 3.

156. Implement a function string balanceParanthesis(string s); which given a string s consisting of some parenthesis returns a string s1 in which parenthesis are balanced and differences between s and s1 are minimum. Eg - "(ab(xy)u)2)" -> "(ab(xy)u)2" - ")))(((" -> "".

157. Write a C function to define strcmp(char *s1, char *s2) to return negative if s1 is smaller, positive if s2 is greater and 0 if they are equal.

158. Write a function that computes log2() using sqrt().

159. Design and implement an algorithm that would correct typos: for example, if an extra letter is added, what would you do?

160. Implement a power function to raise a double to an int power, including negative powers.

Done.