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.


Monday, March 11, 2013

Javascript Tutorial

http://www.scribd.com/doc/48750547/AJS

Nice presentation touches main concept of the language.


Saturday, March 9, 2013

Function Literal vs Function definition


Function Literal

var Class = function () {};
vs

Function Definition
function Class () {};


the former is "hoisted" to the top of the current scope before execution. For the latter, the variable declaration is hoisted, but not the assignment. For example:
// Error, fn is called before the function is assigned!
fn();
var fn = function () { alert("test!"); } 

// Works as expected: the fn2 declaration is hoisted above the call
fn2();
function fn2() { alert("test!"); }


http://stackoverflow.com/questions/4508313/advantages-of-using-prototype-vs-defining-methods-straight-in-the-constructor

Adding methods to a class vs adding methods to a class's prototype

https://www.quora.com/JavaScript/What-are-advantages-to-adding-methods-to-a-class-vs-adding-methods-to-a-classs-prototype

Snippet 1 (Adding methods to a class)

var myClass = function(prop1, prop2) {
    this.prop1 = prop1;
    this.prop2 = prop2;
    
    this.method1 = function() {//blah}
    this.method2 = function() {//blahblah}
}

Snippet 2 (Adding methods to a class's prototype)


var myClass = function(prop1, prop2) {
    this.prop1 = prop1;
    this.prop2 = prop2;
}
myClass.prototype.method1 = function() {//blah}
myClass.prototype.method2 = function() {//blahblah}


Snippet 1

  • Two functions are created for every construction of 
    myClass
  • can give you access to private variables and constructor arguments

Snippet 2


  • the two functions are created once: when the prototype is filled.
  • gives better memory usage
  • Methods that inherit via the prototype chain can be changed universally for all instances
  • For instance, you can extend the built-in String object by adding a trim function to it and all future instance of that object will share the trim function.

http://stackoverflow.com/questions/4508313/advantages-of-using-prototype-vs-defining-methods-straight-in-the-constructor