Recent site activity

Interview Questions

Online Resources


Book(s)



Here are some common interview questions to help you prepare for technical interviews (from http://www.techinterviews.com/)!

Programming Questions

  1. Design a data structure such that given a stream of numbers, you can find the maximum of the numbers at any point and also all the numbers. [Answer: priority queue or heap?]
  2. Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions. (A solution to this problem is a solution which satisfies the boundary conditions.)
  3. Find the common ancestor of two given nodes in a binary tree, how do you exploit the properties of a given BST for the same problem.
  4. You’re given a function getsort(data) that sorts the data given. The function sorts in place and does not use any extra memory. How do you validate the function with respect to 1) it sorts [Answer: unit testing?] 2) it does not use extra memory
  5. Explain the Traveling Salesman problem? What is an NP-complete problem? What is the Hamiltonian cycle problem?
  6. Find out the least common ancestor in a binary tree.
  7. Write an algorithm to check if a linkedlist is circular:
    node* tortoise(begin), hare(begin);
    while(hare = hare->next)
    {
       
    if(hare == tortoise) { throw std::logic_error("There's a cycle"); }
        hare
    = hare->next;
       
    if(hare == tortoise) { throw std::logic_error("There's a cycle"); }
        tortoise
    = tortoise->next;
    }

    (http://stackoverflow.com/questions/34249/best-algorithm-to-test-if-a-linked-list-has-a-cycle)


Brain Teasers

  1. You are shrunk to the height of a nickel and your mass is proportionally reduced so as to maintain your original density. You are then thrown into an empty glass blender. The blades will start moving in 60 seconds. What do you do?
  2. How would you find out if a machine’s stack grows up or down in memory?
  3. Explain a database in three sentences to your eight-year-old nephew.
  4. How many gas stations would you say there are in the United States?
  5. How many golf balls can fit in a school bus?
  6. How much should you charge to wash all the windows in San Francisco?
  7. How many times a day does a clock’s hands overlap?
  8. How many piano tuners are there in the entire world?
  9. You have eight balls all of the same size. 7 of them weigh the same, and one of them weighs slightly more. How can you find the ball that is heavier by using a balance and only two weighings?
  10. You have five pirates, ranked from 5 to 1 in descending order. The top pirate has the right to propose how 100 gold coins should be divided among them. But the others get to vote on his plan, and if fewer than half agree with him, he gets killed. How should he allocate the gold in order to maximize his share but live to enjoy it? (Hint: One pirate ends up with 98 percent of the gold.)
  11. You have to get from point A to point B. You don’t know if you can get there. What would you do?
  12. Imagine you have a closet full of shirts. It’s very hard to find a shirt. So what can you do to organize your shirts for easy retrieval?
  13. Every man in a village of 100 married couples has cheated on his wife. Every wife in the village instantly knows when a man other than her husband has cheated, but does not know when her own husband has. The village has a law that does not allow for adultery. Any wife who can prove that her husband is unfaithful must kill him that very day. The women of the village would never disobey this law. One day, the queen of the village visits and announces that at least one husband has been unfaithful. What happens?
  14. In a country in which people only want boys, every family continues to have children until they have a boy. if they have a girl, they have another child. if they have a boy, they stop. what is the proportion of boys to girls in the country?
  15. If the probability of observing a car in 30 minutes on a highway is 0.95, what is the probability of observing a car in 10 minutes (assuming constant default probability)?
  16. If you look at a clock and the time is 3:15, what is the angle between the hour and the minute hands?

Java Questions

  1. What is garbage collection? What is the process that is responsible for doing that in java? - Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process
  2. What kind of thread is the Garbage collector thread? - It is a daemon thread.
  3. What is a daemon thread? - These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.
  4. How will you invoke any external process in Java? - Runtime.getRuntime().exec(….)
  5. What is the finalize method do? - Before the invalid objects get garbage collected, the JVM give the user a chance to clean up some resources before it got garbage collected.
  6. What is mutable object and immutable object? - If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …)
  7. What is the basic difference between string and stringbuffer object? - String is an immutable object. StringBuffer is a mutable object.
  8. What is the purpose of Void class? - The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.
  9. What is reflection? - Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions.
  10. What is the base class for Error and Exception? - Throwable
  11. What is the byte range? -128 to 127
  12. What is the implementation of destroy method in java.. is it native or java code? - This method is not implemented.
  13. What is a package? - To group set of classes into a single unit is known as packaging. Packages provides wide namespace ability.
  14. What are the approaches that you will follow for making a program very efficient? - By avoiding too much of static methods avoiding the excessive and unnecessary use of synchronized methods Selection of related classes based on the application (meaning synchronized classes for multiuser and non-synchronized classes for single user) Usage of appropriate design patterns Using cache methodologies for remote invocations Avoiding creation of variables within a loop and lot more.
  15. What is a DatabaseMetaData? - Comprehensive information about the database as a whole.
  16. What is Locale? - A Locale object represents a specific geographical, political, or cultural region
  17. How will you load a specific locale? - Using ResourceBundle.getBundle(…);
  18. What is JIT and its use? - Really, just a very fast compiler… In this incarnation, pretty much a one-pass compiler — no offline computations. So you can’t look at the whole method, rank the expressions according to which ones are re-used the most, and then generate code. In theory terms, it’s an on-line problem.
  19. Is JVM a compiler or an interpreter? - Interpreter
  20. When you think about optimization, what is the best way to findout the time/memory consuming process? - Using profiler
  21. What is the purpose of assert keyword used in JDK1.4.x? - In order to validate certain expressions. It effectively replaces the if block and automatically throws the AssertionError on failure. This keyword should be used for the critical arguments. Meaning, without that the method does nothing.
  22. How will you get the platform dependent values like line separator, path separator, etc., ? - Using Sytem.getProperty(…) (line.separator, path.separator, …)
  23. What is skeleton and stub? what is the purpose of those? - Stub is a client side representation of the server, which takes care of communicating with the remote server. Skeleton is the server side representation. But that is no more in use… it is deprecated long before in JDK.
  24. What is the final keyword denotes? - final keyword denotes that it is the final implementation for that method or variable or class. You can’t override that method/variable/class any more.
  25. What is the significance of ListIterator? - You can iterate back and forth.
  26. What is the major difference between LinkedList and ArrayList? - LinkedList are meant for sequential accessing. ArrayList are meant for random accessing.
  27. What is nested class? - If all the methods of a inner class is static then it is a nested class.
  28. What is inner class? - If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class.
  29. What is composition? - Holding the reference of the other class within some other class is known as composition.
  30. What is aggregation? - It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation.
  31. What are the methods in Object? - clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString
  32. Can you instantiate the Math class? - You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public.
  33. What is singleton? - It is one of the design pattern. This falls in the creational pattern of the design pattern. There will be only one instance for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods … }
  34. What is DriverManager? - The basic service to manage set of JDBC drivers.
  35. What is Class.forName() does and how it is useful? - It loads the class into the ClassLoader. It returns the Class. Using that you can get the instance ( “class-instance”.newInstance() ).
  36. Inq adds a question: Expain the reason for each keyword of
    public static void main(String args[])

Python programming questions


Here are some python programming questions from http://www.coders2020.com/interview/python_interview_questions.

1) Explain about the programming language python?
Python is a very easy language and can be learnt very easily than other programming languages. It is a dynamic object oriented language which can be easily used for software development. It supports many other programming languages and has extensive library support for many other languages.

2) Explain about the use of python for web programming?
Python can be very well used for web programming and it also has some special features which make you to write the programming language very easily. Some of the features which it supports are Web frame works, Cgi scripts, Webservers, Content Management systems, Web services, Webclient programming, Webservices, etc. Many high end applications can be created with Python because of the flexibility it offers.

3) State some programming language features of Python?
Python supports many features and is used for cutting edge technology.
Some of them are
1) A huge pool of data types such as lists, numbers and dictionaries.
2) Supports notable features such as classes and multiple inheritance.
3) Code can be split into modules and packages which assists in flexibility.
4) It has good support for raising and catching which assists in error handling.
5) Incompatible mixing of functions, strings, and numbers triggers an error which also helps in good programming practices.
6) It has some advanced features such as generators and list comprehensions.
7) This programming language has automatic memory management system which helps in greater memory management.
4) How is python interpreted?
Python has an internal software mechanism which makes your programming easy. Program can run directly from the source code. Python translates the source code written by the programmer into intermediate language which is again translated it into the native language of computer. This makes it easy for a programmer to use python.

5) Does python support object oriented scripting?
Python supports object oriented programming as well as procedure oriented programming. It has features which make you to use the program code for many functions other than Python. It has useful objects when it comes to data and functionality. It is very powerful in object and procedure oriented programming when compared to powerful languages like C or Java.

6) Describe about the libraries of Python?
Python library is very huge and has some extensive libraries. These libraries help you do various things involving CGI, documentation generation, web browsers, XML, HTML, cryptography, Tk, threading, web browsing, etc. Besides the standard libraries of python there are many other libraries such as Twisted, wx python, python imaging library, etc.

7) State and explain about Strings?
Strings are almost used everywhere in python. When you use single and double quotes for a statement in python it preserves the white spaces as such. You can use double quotes and single quotes in triple quotes. There are many other strings such as raw strings, Unicode strings, once you have created a string in Python you can never change it again.

8) Explain about classes in python?
Classes are the main feature of any object oriented programming. When you use a class it creates a new type. Creating class is the same as in other programming languages but the syntax differs. Here we create an object or instance of the class followed by parenthesis.

9) What is tuple?
Tuples are similar to lists. They cannot be modified once they are declared. They are similar to strings. When items are defined in parenthesis separated by commas then they are called as Tuples. Tuples are used in situations where the user cannot change the context or application; it puts a restriction on the user.

10) Explain and statement about list?
As the name specifies list holds a list of data items in an orderly manner. Sequence of data items can be present in a list. In python you have to specify a list of items with a comma and to make it understand that we are specifying a list we have to enclose the statement in square brackets. List can be altered at any time.

11) Explain about the dictionary function in Python?
A dictionary is a place where you will find and store information on address, contact details, etc. In python you need to associate keys with values. This key should be unique because it is useful for retrieving information. Also note that strings should be passed as keys in python. Notice that keys are to be separated by a colon and the pairs are separated themselves by commas. The whole statement is enclosed in curly brackets.

12) Explain about indexing and slicing operation in sequences?
Tuples, lists and strings are some examples about sequence. Python supports two main operations which are indexing and slicing. Indexing operation allows you to fetch a particular item in the sequence and slicing operation allows you to retrieve an item from the list of sequence. Python starts from the beginning and if successive numbers are not specified it starts at the last. In python the start position is included but it stops before the end statement.

13) Explain about raising error exceptions
In python programmer can raise exceptions using the raise statement. When you are using exception statement you should also specify about error and exception object. This error should be related to the derived class of the Error. We can use this to specify about the length of the user name, password field, etc.

14) What is a Lambda form?
This lambda statement is used to create a new function which can be later used during the run time. Make_repeater is used to create a function during the run time and it is later called at run time. Lambda function takes expressions only in order to return them during the run time.

15) Explain about assert statement?
Assert statement is used to assert whether something is true or false. This statement is very useful when you want to check the items in the list for true or false function. This statement should be predefined because it interacts with the user and raises an error if something goes wrong.

16) Explain about repr function?
This function is used to obtain a string representation of an object. This function helps you in obtaining a printable representation of the object. This function also makes it possible to obtain specific return from the object. This can be made possible by specifying the repr method in the class.

17) Explain about pickling and unpickling?
Python has a standard module known as Pickle which enables you to store a specific object at some destination and then you can call the object back at later stage. While you are retrieving the object this process is known as unpickling. By specifying the dump function you can store the data into a specific file and this is known as pickling.


Other

Big-O notation:
  1. What is big-O for search time in an array?
    Answer: depends. If you know the index, then 1. If not, then O(n)
  2. What is big-O for lookup in a binary search tree?
    Answer: best case is O(log n), word case is O(n)
  3. What is the big-O for lookup in a heap?
    Answer: O(n)
  4. What is the big-O for Breadth-first search (use queue)?
    Answer: O(n)
  5. How about depth-first search (use stack)?
    Answer: O(V + E) where V is the number of nodes and E is the number of edges

Sorting Algorithms
  1. Bubble Sort - iterate through the list, swapping neighbors if out of order. Stop when no items are out of order. O(n^2)
  2. Selection sort - find the smallest item in the array and place at the beginning. Continue until all items are sorted. O(n^2)
  3. Insertion sort - insert items into the correct position in the array, starting from the beginning. O(n^2)
  4. Quicksort - choose a pivot. Move all items greater than the pivot to the right, move all items less than the pivot to the left. Continue until sorted. O(n log n)
  5. Shellsort - first sort every nth item. Keep decreasing n until the list is sorted. O(n log^2 n)
  6. Mergesort - split the list into smaller lists, sort each side, then recombine. O(n log n)

Actual Interview Questions

Phone Screen
  • binary search - use array or linkedlist - use array
  • best case scenario for hashmap lookup - O(1)
  • worst case scenario for hashmap lookup - O(n)
  • system utilization on Unix - ps command
  • difference between POST and GET

Technical Interview
  • tell me about yourself.
  • what was your favorite thing about school. what was your least favorite thing.
  • what is the difference between inner and outer join?
  • explain how the garbage collector in java works.
  • build a hashmap in python without using dictionary, when adding a new item to this hashmap, do you have to search through every key value to see if it already exists?
  • if you had a directory with 10,000 files, each file containing a name and phone number, how would you replace a certain phone number in all the files?
  • given the apache web server logs, how would you determine the 10 most frequently visited pages? what's the runtime for this algorithm? how could someone else skew the results? what would you do to prevent them from doing so?
  • how would you show all the running processes on a mac (pc or unix, depending on what you use)
  • what language do you like better: python or java (this is assuming you use both)
Front-end Developer position
  • what is a sprite
  • how to decrease the load time of images on a page
  • what is a CDN
  • what is jslint
  • how to create roundy borders in css?
  • how to debug css/html across all browsers?
  • what is one cross-browser issue you've experienced and how did you solve it?
  • what are the 3 ways to apply css to a page? which takes precedence?
  • how to create objects in javascript?
  • what is the different between a constructor and a prototype in javascript?
  • how to create public and private variables in javascript
  • what javascript frameworks have you used?
  • what is z-index in css
  • what types of design patterns do you use (mvc, factory, singleton being examples)
Phone Screen
  • What were your favorite projects and why
  • what design patterns do you use?
  • what's your favorite technology, language, etc
  • what's your experience with mobile apps, objective c (asked because I have mobile development on my resume)
  • Have you worked on any open source projects
  • why do you want to work at ____?
  • send a code sample