Thursday, February 14, 2013

Technical Interview Questions

Hi all. I would like to share with you some technical interview questions I’ve collected over the years. It’s best you work out the answers to these questions yourself. If you cheat, you will only hurt your company and yourself. I’m only including questions I myself have solved. I will NOT give out any answers because I think that's a disservice to the community.
In each category, the questions are arranged from simple to advanced

Arrays 1-D

  • Reverse an array of integers.
  • Shuffle Cards.
  • Bubble Sort an array of integers.
  • Find element in an array of integers using binary search.
  • Remove duplicates from sorted array of integers. Pad remaining cells with zeros
  • Remove duplicates from unsorted array of integers. Pad remaining cells with zeros
  • Find first element in array that is duplicated/not duplicated.
  • Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it.
  • Given an array t[100] which contains numbers between 1..99. Return the duplicated value. Use only one iteration, one int to store intermediate results.
  • Given an array containing both positive and negative integers, find the sub-array with the largest sum. What if you don’t want negative numbers in the returned sub-array?
  • Implement the following function, FindSortedArrayRotation(int [] arr). arr is an array of unique integers that has been sorted in ascending order, then rotated by an unknown amount X, where 0 <= X <= (arrayLength - 1). An array rotation by amount X moves every element array[i] to array[(i + X) % arrayLength]. Can it be done in less than linear time?

Arrays 2-D (Matrix)

  • Transpose a square matrix. I.e. interchange the rows and columns.
  • Given an int array, zero out the vertical and horizontal column containing a zero.
  • Find saddle point. A matrix is said to have a saddle point if entry arr[r, c] is the smallest value in the ith row and the largest value in the jth column. A matrix may have more than one saddle point.
  • Find plateau. A matrix is said to have a plateau point if entry arr[r, c] is the largest value in both the rth row and the cth column. A matrix may have more than one saddle point.
  • Write a routine that prints out a 2-D array in spiral order!

Binary Search Tree

  • Insert node into binary search tree.
  • Delete node from binary search tree.
  • Write a function to find the depth of a binary tree.
  • Find Lowest Common Ancestor, given: Node LCA(Node root, int left, int right);
  • Print elements in-order (L, C, R).
  • Convert BST into a linked list.

Linked Lists

  • Insert element into linked list.
  • Delete element from linked list.
  • Delete alternate nodes in doubly linked list.
  • Find middle element.
  • Merge two sorted lists.
  • Remove duplicates in sorted list.
  • Find if list is circular. (No begining or end node
  • Find Mth to last element in linked list.
  • Reverse linked list.
  • Delete the nth node, given a link to that node. You have no access to the previous node for the exercise.

Queues & Stacks

  • Implement a queue only with stacks.

Text Strings

  • Given a string s, find character c and return its position.
  • Write a function to check if a given string is a palindrome. Ignore white spaces. Ex. “Able was I ere I saw Elba”
  • Given an arbitrary string, return a string with no duplicate characters. String RemDup(String s)
  • Given two strings S1 and S2, remove characters in S2 that appear in S1.
  • Given two strings, write a function that would print characters in the first string that are not in the second string and also print characters in the second string that are not in the first string.
  • Reverse words in String. (I am Sam) => (Sam am I)

Bit Operations

  • Multiply num by 7 without using multiplication (*) operator.
  • Find number of set bits in an integer.
  • There are two integers, ‘a’ and ‘b’. Swap the contents without using a temp variable.
  • Print integer in base 2.General
  • Find nth factorial. (0, 1, 2, 3) => (1, 1, 2, 6)
  • Find nth Fibonacci number. (1, 2, 3, 4, 5, 6) => (1, 1, 2, 3, 5, 8)
  • Print integer one digit at a time, without storing any intermediate results.
  • Given the time in hours an minutes, find the angle between the hour hand and the minute hand.
  • Write a function that takes as its arguments 3 integers > 0. If the product of the integers is even, then return the one with the lowest value, else show 0.
  • Parse integer from string.

Recursion

  • Print numbers from 1 to 100 and then 100 to 1 without any for or while loops.
  • Print linked list in reverse order.
  • Reverse a singly linked list recursively.
  • Find nth factorial. (0, 1, 2, 3) => (1, 1, 2, 6)
  • Find nth Fibonacci number. (0, 1, 2, 3) => (1, 1, 2, 6)
  • Sum the digits in a number. int sumOfDigits(int x); (If x is 2345, return 9 [2 + 3 + 4 + 5])
  • Count the number of set bits in an array of integers without loops.
  • Print all permutations in a string.
  • Count square clusters in grid.
  • Find way out of maze.
I hope you have fun with these problems.

No comments:

Post a Comment