- http://leetcode.com/2011/09/regular-expression-matching.html
- How would you design a request dispatcher for load balancing ?
- http://www.javaworld.com/article/2077921/architecture-scalability/server-load-balancing-architectures--part-1--transport-level-load-balancing.html
- http://www.javaworld.com/article/2077922/architecture-scalability/server-load-balancing-architectures-part-2-application-level-load-balanci.html
- Detect spam reviews on yelp ?
- Anagram grouping
- Write code to generate all possible case combinations of a given lower-cased string. (e.g. "0ab" -> ["0ab", "0aB", "0Ab", "0AB"])
- http://algorithmsforinterview.blogspot.com/2012/08/print-given-string-in-all-combinations_14.html
- http://coding-interviewq.blogspot.com/2012/04/generate-all-substrings-of-string.html
- http://coding-interviewq.blogspot.com/2012/04/generate-all-permutations-of-string-in.html
- given an array of intervals, return max number of non-overlapping intervals
- Longest palindrome substring
- http://leetcode.com/2011/11/longest-palindromic-substring-part-i.html
- http://leetcode.com/2011/11/longest-palindromic-substring-part-ii.html
- Given a lower case string ab generate all lower case and upper case combinations
- Given a list of strings, write a function to generate longest common prefix of those strings.
- Explain SSL
- Explain DNS
- Given a list of urls, find out the top 5 urls
- Regex http://leetcode.com/2011/09/regular-expression-matching.html
Apart from coding and design interview questions, this page contains updates on my learnings with Java. It helps me organize my learning. Read about my future self here : https://siliconvalleystories.blogspot.com/
Tuesday, 23 December 2014
Yelp Interview Questions
Friday, 19 December 2014
Parsing XML files in JAVA
- Use the SAX parser for large files http://stackoverflow.com/questions/15132390/parsing-large-xml-documents-in-java
- http://elegantcode.com/2010/08/07/dont-parse-that-xml/
- 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
- 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.
- 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.
Garbage Collection in Java
References :
- http://mechanical-sympathy.blogspot.com/2013/07/java-garbage-collection-distilled.html
- http://www.infoq.com/articles/low-latency-vp
- http://stackoverflow.com/questions/2574579/what-is-your-development-checklist-for-java-low-latency-application
- http://programmers.stackexchange.com/questions/149563/should-we-avoid-object-creation-in-java
- http://mentablog.soliveirajr.com/2012/11/real-time-java-programming-without-gc/
- http://architects.dzone.com/articles/5-tips-proper-java-heap-size
Thursday, 18 December 2014
Design Pattern Books
- Head First design patterns
- http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420/ref=sr_1_1?ie=UTF8&qid=1418969510&sr=8-1&keywords=enterprise+design+patterns
- http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=pd_sim_b_5?ie=UTF8&refRID=1PA3FYGRC0XE9XNGBFC1
- http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672/ref=pd_sim_b_4?ie=UTF8&refRID=1PA3FYGRC0XE9XNGBFC1
- http://www.amazon.com/The-Pragmatic-Programmer-Journeyman-Master/dp/020161622X/ref=pd_sim_b_7?ie=UTF8&refRID=0MSR01BNCHXFFFXPB6FQ
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 :
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 :
- 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, )
- Favor composition over inheritance
- Program to interfaces not implementations
- Strive for loosely coupled designed between objects that interact
- Classes should be open for extension but closed for modification
- Depend on abstractions and do not depend on concretions
- Only talk to friends (Facade pattern and principle of least knowledge)
- Dont call us, we will call you (Hollywood principle, Template)
- Dependency Inversion : Avoid the use of concrete classes and instead work with as much abstractions as possible.
- 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.
- 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.".
- Open Principle : Classes should be open for extension but closed for modification - decorator pattern
Wednesday, 17 December 2014
Convert JSON to Java Objects and vice versa
This post contains performance comparison of relevant libraries.
Add the json here and generate all the classes needed to parse the java objects : http://www.jsonschema2pojo.org/
Parse json array to arraylist of objects : http://www.leveluplunch.com/java/examples/convert-json-array-to-arraylist-of-objects-jackson/
http://www.developer.com/lang/jscript/top-7-open-source-json-binding-providers-available-today.html
Add the json here and generate all the classes needed to parse the java objects : http://www.jsonschema2pojo.org/
Parse json array to arraylist of objects : http://www.leveluplunch.com/java/examples/convert-json-array-to-arraylist-of-objects-jackson/
http://www.developer.com/lang/jscript/top-7-open-source-json-binding-providers-available-today.html
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;
}
}
Saturday, 13 December 2014
Amazon Interview Set 159
- How to implement sets ?
- http://web.cs.wpi.edu/~cs2102/b12/Lectures/bsts-and-avls.html
- http://stackoverflow.com/questions/2630738/c-how-to-implement-set-data-structure
- Quick Sort in Java
- Rotate a 2D array
- Buy and Sell stock
- Kth largest elements in an array
- http://leetcode.com/2010/11/finding-minimum-window-in-s-which.html
- http://www.geeksforgeeks.org/given-sorted-dictionary-find-precedence-characters/
- Generics and Collections in Java
- Head First design patterns
- Effective Java
Thursday, 4 December 2014
Monday, 15 September 2014
Working with SOAP
- 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
- 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.
- http://www.w3schools.com/xml/xml_namespaces.asp
DOM HTML and DOM XML
DOM HTML
- Your page is a collection of DOM Nodes.
- Document : The top node in a DOM tree, representing the document itself and appearing just above the html element.
- Element : Any HTML element that corresponds to a tag in HTML code.
- 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 is a markup language
- A markup language is a set of markup tags
- The tags describe document content
- HTML documents contain HTML tags and plain text
- HTML documents are also called web pages
- HTML links are defined with the <a> tag:<a href="http://www.w3schools.com">This is a link</a>
- The link address is specified in the href attribute.Attributes are used to provide additional information about HTML elements.
- 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"
- 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.
- sd
Javascript Introduction
- 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.
- innerHTML gets all of the content of an element, including any HTML tags.
Friday, 5 September 2014
Payment Glossary
Cardholder Authentication Verification Value. A base64-encoded string sent back with Verified by Visa-enrolled cards that specifically identifies the transaction with the issuing bank and Visa. Standard for collecting and sending AAV data for Verified by Visa transactions. See AAV.
| |
A one-digit reply passed back when the PARes status is a Y or an A. If your processor is ATOS, this must be passed in the authorization, if available.
| |
Account Authentication Value. Unique 32-character transaction token for a 3-D Secure transaction. For MasterCard SecureCode, the AAV is named the UCAF.For Verified by Visa, the AAV is named the CAVV
|
Reference :
- http://apps.cybersource.com/library/documentation/dev_guides/Payer_Authentication_SO_API/html/wwhelp/wwhimpl/common/html/wwhelp.htm#href=glossary.html&single=true
Subscribe to:
Posts (Atom)