Monday, 13 July 2015

Coding Interview Question on Metro Smart Card System


Click HERE to see the complete interview process at sapient

Problem Statement :
Our Company has been asked to implement Metro Smart Card System (MSCS) for Delhi City. For this application assume there is a single metro line covering 10 stations linearly.

The stations name are A1,A2,A3,A4,A5,A6,A7,...A10. The travel can be in any direction from any station except A1 and A10.

Travelers have smart card that behave just like any other regular debit card that has an initial balance when purchased. Travelers swipe in when they enter a metro station and swipe out when they exit. Card balance is automatically updated at swipe out.

Objective :

Objective of this exercise is to create an automated system that has following functionality.

Card should have a minimum balance of Rs. 50 at swipe-in. At swipe-out, system should calculate the fare based on below strategies. The fare must be deducted from the card. Card should have the sufficient balance otherwise user should not be able to exit.

Weekday - Rs 7 * (Number of stations travelled)
Weekend - Rs 5.5 * (Number of station traveled if it is Saturday or Sunday )
(* there could be more such fare strategies in future).

Additionally system needs to have functionality to generate some statistics/report defined below. So system needs to provide following API.


  • API to get total foot-fall(swipe-in + swipe-out) for a given station.
  • API to generate a "per-card report" on demand. It should print the following information on console.
      Card<number> used to travel from <source_station> to station <destination_station>. Fare is Rs<x> and balance on card is Rs<x>.

CLICK Code Sample   to download the sample code for this problem.
Above code sample is created by using command line design pattern which is appropriate for this problem. However this is just for reference and you could practice this problem to find more appropriate solution.
 

Friday, 10 July 2015

Java Interview Questions at Sapient for Global Markets


The interview process at Sapient Global Markets has following rounds of interview for Global Markets domain for java/j2ee developers for about 3 to 8(approx) years of experience.

Round 1: Technical Written Test (Time 1 Hour app.)

This test contains a set of 30-40 objective type questions based on core java. This test checks your skills on core java(Note: this test contains advance java questions for Sapient Nitro but not for Global Markets domain). Candidate should have good command over core java to crack this test. Passing percentage is may vary from 50% to 65%. Good number of questions are asked from following topics.

Multi-threading : practice upon creating threads in different ways, understand the wait(), notify() concepts in deep, re-entrant locks.. etc.

Polymorphism: method overriding and over-loading syntax and concepts.

Inheritance : Good understanding on implementing interface or Abstract classes and all the rules/syntax for implementing an interface or extending abstract classes. Some questions on up cast or downcast etc.

Enum : expect 1 or 2 questions on Enum.

This is an online test and its preparation will take some time depending upon candidate's command over above topics. One book that could be referred for its preparation is "SCJP Sun Certified Programmer for Java 6 or 7 Study Exam 310-065 Guide" by Kathy Sierra.

Round 2 : Coding Exercise (Time 2.5 to 3 Hours approx)

You will be asked to design code based upon the given problem. (refer below example). This is another round that tests your knowledge basically on following skills and marking will be done for each of these sections. So don't miss any of the following sections during coding.

1) Design logic : correct use of interfaces and abstract classes or correct design pattern is used or not based upon given problem.
2) Best practices: correctly name packages and classes using correct conventions. Data members should be private or final as required, methods should be public and don't forget to flaunt the use of try-catch at various points, add proper and clean comments, code indentation etc.
3) Test Cases: Do write at least 2-3 junit test cases if it is asked in the problem. It has got separate cutoff. 
4) Database Storage/ DAO : You can use Spring Transaction or JPA or Hibernate to show data storage part, although it might not be mentioned in problem directly but at least design DAO to show that you have good knowledge of frameworks.
5) It Must Run Anyhow: Make sure that code is running and showing some output on console. It has separate cutoff.
6) Assumptions :You will be asked in problem statement to make assumptions on some part of the code. Its good practice to write down your assumptions in comments.

Following is an example of Designing Delhi Metro Railway System that was asked recently. 

Click HERE to see example.

Round 3 : Face To Face Discussion (30-45 minutes)

This is the final technical round that you need to crack. 

1) Questions from Coding Exercise :  Interviewer will have the complete code written by you from the second round and he is definitely going to throw some questions on it like 

     -- Have you used any design pattern to write the code ?
     -- What modifications should I make in your classes to make them immutable.
     -- There could be numerous questions asked based on your written code if you have not written correct code by following the above process then you will score low.
     -- However if you have followed all the required steps then there would not be much questioning further on coding exercise.