Tuesday, April 2, 2013

Link List Algorithm Questions


  1. write a code to remove duplicates from unsorted link list. How would you solve it if temp buffer is not given.
  2. write algo to find nth to last element of singly link list.
  3. implement the algorithm to delete a node in the middle of a singly link list given only access to that node.
  4. write a algo to partition a linked list around a value such that all nodes less than x come before it and all nodes with value greater than x comes after it.
  5. suppose number are represented by singly linked list in reverse order. Eg . 123 is represented as       3->2->1. Write a function which could add these numbers and represent in link list.
  6. suppose number are represented by singly linked list in same order. Eg . 123 is represented as          1->2->3. Write a function which could add these numbers and represent in link list.
  7. Detect the loop in the link list. Also detect the loop node. Eg . a->b->c->d->e->b.   E is pointing to b so there is loop in link list.
  8. Implement a method to check if link list is palindrome.

Array Algorithm Question


  1.  Given an image represented by NxN matrix. Each pixel is represented by 4 bytes. Write a method to rotate image by 90 degree. Can you do in place ?
  2. Write an algo so that if an element in MxN matrix is 0 then entire row and column are set to 0.
  3. Given the array of integer. Find contiguous sequence of array with largest sum. Return sum and also calculate the start and end index of sub-array.
  4. Design algo to find pair of integer in a given array with specified sum.


String Algorithm Questions


  1.  Implement the algo to determine if a string has all unique characters. What is you cannot use additional data structure ?
  2. Implement the string reverse function.
  3. Given two string determine one is permutation of another.
  4. Implement the method to perform basic string compression techniques by using the count of repeated character. For example "aabbbccdddde" can be represented as "a2b3c2d4e1". If compressed string is not smaller than original string then return the original string.
  5. Write a code to check if string s1 is rotation of string s2.(eg. "hello" is rotation of "llohe" ). you have given method "substring" which check one word is substring of another. Use it only once to determine it.
  6. Calculate the occurrence of given word in a book.