Pages

Tuesday 23 December 2014

Yelp Interview Questions

  1. http://leetcode.com/2011/09/regular-expression-matching.html
  2. How would you design a request dispatcher for load balancing ?
    1. http://www.javaworld.com/article/2077921/architecture-scalability/server-load-balancing-architectures--part-1--transport-level-load-balancing.html 
    2. http://www.javaworld.com/article/2077922/architecture-scalability/server-load-balancing-architectures-part-2-application-level-load-balanci.html 
    3.  
  3. Detect spam reviews on yelp ?
  4. Anagram grouping
  5. Write code to generate all possible case combinations of a given lower-cased string. (e.g. "0ab" -> ["0ab", "0aB", "0Ab", "0AB"])  
    1. http://algorithmsforinterview.blogspot.com/2012/08/print-given-string-in-all-combinations_14.html 
    2. http://coding-interviewq.blogspot.com/2012/04/generate-all-substrings-of-string.html 
    3. http://coding-interviewq.blogspot.com/2012/04/generate-all-permutations-of-string-in.html 
  6. given an array of intervals, return max number of non-overlapping intervals
  7. Longest palindrome substring
    1. http://leetcode.com/2011/11/longest-palindromic-substring-part-i.html 
    2. http://leetcode.com/2011/11/longest-palindromic-substring-part-ii.html 
  8. Given a lower case string ab generate all lower case and upper case combinations
  9. Given a list of strings, write a function to generate longest common prefix of those strings.
  10. Explain SSL
  11. Explain DNS
  12. Given a list of urls, find out the top 5 urls
  13. Regex http://leetcode.com/2011/09/regular-expression-matching.html
  14.  

Friday 19 December 2014

Parsing XML files in JAVA

  1. Use the SAX parser for large files http://stackoverflow.com/questions/15132390/parsing-large-xml-documents-in-java
  2. http://elegantcode.com/2010/08/07/dont-parse-that-xml/
  3. The DOM Parser loads the complete XML content into a Tree structure. And we iterate through the Node and NodeList to get the content of the XML
  4. SAX Parser is different from the DOM Parser where SAX parser doesn’t load the complete XML into the memory, instead it parses the XML line by line triggering different events as and when it encounters different elements like: opening tag, closing tag, character data, comments and so on. This is the reason why SAX Parser is called an event based parser.
  5. StAX stands for Streaming API for XML and StAX Parser is different from DOM in the same way SAX Parser is. StAX parser is also in a subtle way different from SAX parser.
    The SAX Parser pushes the data but StAX parser pulls the required data from the XML.
    The StAX parser maintains a cursor at the current position in the document allows to extract the content available at the cursor whereas SAX parser issues events as and when certain data is encountered.
XMLInputFactory and XMLStreamReader are the two class which can be used to load an XML file. And as we read through the XML file using XMLStreamReader, events are generated in the form of integer values and these are then compared with the constants inXMLStreamConstants.
  1.  

Garbage Collection in Java

Thursday 18 December 2014

Design Pattern Books

Design Pattern CheatSheet

Observer Pattern : The observer pattern defines a one to many relationship between objects so that when one object changes state all the other dependent objects are notified.

Factory Pattern : encapsulates object creatio. Defines an interface for creating an object, but lets subclass decide which class to instantiate. Factory method lets a class defer instantiation to subclasses. 

Adapter Pattern : Converts interfaces of a class to another interface that clients expect. Lets classes work together that wouldnt otherwise because of incompatible interfaces.

Singleton - Use double check locking because the synchronization is only needed for the object instantiation part. If you already have an instance of that object, you dont need to do the synchronization. Declare the instance as static volatile, the constructor as private and a getInstance function as public static. 

Command Pattern : encapsulates a request as an object , thereby letting you parameterize other objects with different requests, queue or log requests and support undoable operations. Light will have OnCommand and OffCommand and it will be there in the remote control. You can queue such incoming commands.Command pattern gives you a way to package a piece of computation or actions and the receiver and store it as a first class object.

Decorator Pattern : Doesnt alter the interface, but add responsibility to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. In the decorator design pattern the class or abstract class that is being extended is also present as a property in the class extending it.

Facade : Make interface simpler. The facade pattern provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher level interface that makes the subsystem easier to use.

Strategy Pattern : Encapsulate interchangeable behavior and use delegation to decide which behavior to use. 

Template Method : Defines the skeleton of an algorithm in a method in an abstract class, deferring some steps to subclasses. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.

A hook is a method that is defined in an abstract class, but only given an empty or default implementation. This gives the subclass the ability to hook into the algorithm at various points, if they wish, a subclass is also free to ignore the hook.

Iterator Pattern : The iterator pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation

Observer Pattern - The observer interface is implemented by all observers. The update method has paramters which are received by all observers when the state of the subject changes.
WeatherData implements the Subject interface which registersObservers, UpdatesObservers, RemovesObservers. It also holds a list of observers.
The ConcreteObserver stores a reference to the subject where it registers. This is not necessarily needed. This functionality is given so that the observer can unregister from the subject if it feels like.

We say that a module has high cohesion when it is designed around a set of related functions and say it has low cohesion when it is designed around a set of unrelated functions. Classes that adhere to a single responsibility principle have high cohesion. Every responsibility of a class is an area of change. More than one responsibility means more than one area of change. 

OO Principles :
  1. Encapsulate what varies (encapsulating object creation is factory, encapsulating method invocation is , encapsulating algorithms is template pattern, encapsulate iteration over different data types is iteration, )
  2. Favor composition over inheritance
  3. Program to interfaces not implementations
  4. Strive for loosely coupled designed between objects that interact
  5. Classes should be open for extension but closed for modification
  6. Depend on abstractions and do not depend on concretions
  7. Only talk to friends (Facade pattern and principle of least knowledge)
  8. Dont call us, we will call you (Hollywood principle, Template)

Principles :
  1. Dependency Inversion : Avoid the use of concrete classes and instead work with as much abstractions as possible.
  2. Principle of least knowledge : Objects should talk to only few friends. The principle prevents our system such that we have large number of classes coupled together so that changes to one part of the system cascade to other parts. When you build a lot of dependencies between many classes you build a fragile system that will be costly to maintain and difficult for others to understand. 
  3. Hollywood Principle : Dependency rots happen when you have high level components depending on low level components depending on high level components depending on sideways components depending on low level components and so on. We allow low level components to hook themselves into a system, but the high level components determine when they are needed and how. In other words, the high level components give the low level components a "Dont call us, we will call you.".
  4. Open Principle : Classes should be open for extension but closed for modification - decorator pattern

Tuesday 16 December 2014

Leetcode : Candy Java


Scan the rating array from left to right and then from right to left. In every scan just consider the rising order (l->r: r[i]>r[i-1] or r->l: r[i]>r[i+1]), assign +1 candies to the rising position.
The final candy array is the maximum (max(right[i],left[i])) in each position.
The total candies is the sum of the final candy array.

Monday 15 December 2014

Leetcode : Maximum Product Subarray

public class Solution { public int maxProduct(int[] A) { if (A == null || A.length == 0) { return 0; } int max = A[0], min = A[0], result = A[0]; for (int i = 1; i < A.length; i++) { int temp = max; max = Math.max(Math.max(max * A[i], min * A[i]), A[i]); min = Math.min(Math.min(temp * A[i], min * A[i]), A[i]); if (max > result) { result = max; } } return result; } }

Monday 15 September 2014

Working with SOAP


  1. Work with the SOAP UI - like postman client for REST based services. It will import the wsdl and give all the calls

Tuesday 9 September 2014

XML Namespaces

  1. XML Namespace is a mechanism to avoid name conflicts by differentiating elements or attributes within an XML document that may have identical names, but different definitions. We will be covering the basics of namespace, including declaration methods, scope, attributenamespace, and default namespace.
  2. http://www.w3schools.com/xml/xml_namespaces.asp

DOM HTML and DOM XML


DOM HTML
  1. Your page is a collection of DOM Nodes. 
  2. Document : The top node in a DOM tree, representing the document itself and appearing just above the html element. 
  3. Element : Any HTML element that corresponds to a tag in HTML code.
  4. Attribute : An attribute of an element, accessible through an element node, but not present directly in the DOM tree.

Monday 8 September 2014

HTML Introduction

  • HTML stands for Hyper Text Markup Language
    1. HTML is a markup language
    2. A markup language is a set of markup tags
    3. The tags describe document content
    4. HTML documents contain HTML tags and plain text
    5. HTML documents are also called web pages
    6. HTML links are defined with the <a> tag:<a href="http://www.w3schools.com">This is a link</a>
    7. The link address is specified in the href attribute.
      Attributes are used to provide additional information about HTML elements.
    8. The element content is between the start and the end tag
      • HTML elements can have attributes
      • Attributes provide additional information about an element
      • Attributes are always specified in the start tag
      • Attributes come in name/value pairs like: name="value"
    9. The HTML <div> element is a block level element that can be used as a container for grouping other HTML elements.
      The <div> element has no special meaning. Except that, because it is a block level element, the browser will display a line break before and after it.

    10. sd

    Javascript Introduction


    1. OnChange wont trigger even if the user navigates through empty form fields, onBlur event solves this problem by always being triggered any time an input selection, or focus, leaves a field.
    2. innerHTML gets all of the content of an element, including any HTML tags.