Friday, February 8, 2013

Points to be considered while taking white Board Interviews (Find missing number in an array)

This is one of they Skype interview question
1) Write all test cases
2) Write doc
3) Keep your code as clean as possible
Question : From a given integer array find the missing number. package codingpuzzles;

import java.util.HashMap;

import java.util.Map;

/**

 * From a given integer array (of random numbers), this class returns the first number which is missing.
 * Note:  The array contains positive integers greater than 0.
 */
public class FindFirstMissingNumber {
    public static final int MISSING_NUMBER_LOWER_BOUND = -1;

    public static void main(String[] args) {

        System.out.println("\n Finding the first missing number from an array containing random numbers");

//TEST CASE INPUT DATA

//     int[] inputArray = null;
//     int[] inputArray = {};
//     int[] inputArray = {5, 1, 4, 3, 2};
//     int[] inputArray = {5, 1, 4, 2};
//      int[] inputArray = {1, 1, 4, 3, 2};
//      int[] inputArray = {1, 4, 1, 3, 2};
//      int[] inputArray = {1, 2, 3, 4, 5};
//      int[] inputArray = {1, 2, 3, 4, 5, 7, 1};
//      int[] inputArray = {1, 2, 3, 4, 6, 5, 1};
//      int[] inputArray = {7, 6, 5, 4, 3, 2, 3};
        int[] inputArray = {7, 6, 5, 4, 3, 2, 1};

        try {

            int firstMissingNumber = findFirstMissingNumberInArray(inputArray);        
            if (firstMissingNumber == MISSING_NUMBER_LOWER_BOUND) {
                System.out.println("\n No missing number found");
            } else {
                System.out.println("\n firstMissingNumber: " + firstMissingNumber);        
            }
        } catch(Exception e) {
            e.printStackTrace();
        }    
    }
    
    /**
     * This method would find the first missing number from the integer array which is passed as input.
     * 
     * @param inputArray - The integer array from which the first missing number needs to be found out
     * @return - The first missing number; or -1 is no missing number is found
     * @throws Exception - thrown if the input integer array is null or empty
     */
    public static int findFirstMissingNumberInArray(int[] inputArray) throws Exception {
        int firstMissingNumber = MISSING_NUMBER_LOWER_BOUND;

        if (inputArray == null) {

            Exception exception = new Exception("Invalid input array.  Please provide an input array which is not null");
            throw exception;
        }

        if (inputArray.length == 0) {

            Exception exception = new Exception("Invalid input array.  Please provide an input array which is not empty");
            throw exception;
        }

        Map<Integer, Boolean> map = new HashMap<Integer, Boolean>();


        /**

         * Populate the map with the integers from the input array.
         * This is O(n) as we need to do a linear traversal of the input array.
         */
        for (int i=0; i<inputArray.length; i++) {
            map.put(new Integer(inputArray[i]), Boolean.TRUE);
        }
        System.out.println("\n map: " + map);

        /**
         * Find the first missing number from the input array.
         * This is O(n) as we need to do a linear traversal of all the integers contiguously.
         */
        for (int i=1; i<=inputArray.length; i++) {
            if (!map.containsKey(new Integer(i))) {
            firstMissingNumber = i;
                break; //exit out of the for-loop when the first missing number is found out
            }
        }    

        //Total Big-Oh notation for this method = O(n) + O(n) = 2 x O(n)

        
        return firstMissingNumber;
    }
}

My tech talks

I have spoken in international conferences with various topics of my interest like (Learning Management System, Localization, e-governance projects, Multilingual Search etc)

1) I recently submitted a paper regarding tamil E-learning system for a conference in India( TI 2012 organized by Infitt). Below is the link.
Kalvi: An Adaptive mLearning System 
2) When I was working in Red hat I spoke in in Gnunify event where I got an opportunity to share stage with technical evanglisits like Mr. Brian Behlendorf Co-Founder, Apache Software Foundation, Ms. Danese Cooper Chief Open Source Evangelist, Sun Microsystems Mr. David Axmark ,Co-founder,MySQL (Screen Shot attached). I spoke about how to take a new language and localize it for all opensource products.

3)Spoken in international conference at India(TI 2003) regarding e-governance(I designed and developed e-governance project for registration department)
www.infitt.org/ti2003/papers/58_jayara.pdf

4)While i was working on language computing projects as my hobby projects, I realized that for tamil there are several encoding standards and practices used by various online magazines as well as internet groups. No one is willing to accept one single unified encoding and having hesitation to migrate to Unicode  I always feel that content in internet is knowledge wealth. It should be searchable. Using various encoding and fonts will not help in fetching correct result. I used to recommend Unicode encoding as a standard and migrated one of big language portal to Unicode encoding. Also presented a paper at international conference in Malaysia(TI 2001) about on the fly encoding converter and robust search engine.
Below the link of that tech talk.
www.infitt.org/ti2001/papers/jayaradha.pdf
My dream of using those contents which are already in web never came true. We all started using Unicode and forgot about the contents which were in 8 bit encoding. But still there are lot of contents which are not searchable are staying in the web. 

5) Spoken in several colleges (Anna University, MOP Vaizhnava College etc...) about open source localization projects.

Thursday, February 7, 2013

My Experience with OpenSource projects Part - 4 - Students force



     Since i was working as a full time employee in an organization, it become very difficult for me to Organize the entire translation effort. With in 1 hour lunch time i have to meet students and college Head Of the department get permission.

   I tried to approach Anna university first. Even though they are interested in language computing project the Head of the department denied my proposal. Anna university students are interested in creating Spell checker, Speech recognition software's at that time and not much interested in Linux localization effort.

   Then i got appointment from  Dr Nirmala Prasad Principle of MOP Vishnava College. At first she had some doubt. She asked me are you sure Mr Sujatha Rangarajan is involved in this project. Later she did some background check and gave permission to talk to her MCA students. Most of the students showed interested. After getting overwhelming response, HOD decided to give her computer lab and 40 students for the translation. She gave option for us to choose students based on their "Tamil" and "Computer" proficiency  We installed e-kalappai tamil keyboard driver and po edit for translation in all computers. Gave small test to students and selected 16 students to work on the project.

   Gave one day typing training to students. Worked in MOP Vaishnava College for 2 weeks. The translation was progressing fast. Our dictionary was growing fast. We paid to Mr Felix (Tamil Translator) and requested him to proof read the students work.

     15 days were not enough to complete close to 200,000 strings. So we went to Loyola college MCA students. I gave a presentation about what we are planning to do. The students got more interested and decided to volunteer. We selected 16 students from Loyola College. With Writer Sujatha's involvement we were able to get 40 computers from Dishnet DSL. Sujatha sir wrote article in a famous magazine(Vikatan) and invited all enthusiast to participate in translating Linux.

Celebrities:
On looking at Vikatan article celebrities like James Vasanthan(Famous music director and talk show host) volunteered to contribute . The Tamil PC started growing fast. End of the day we get all files we merge and check-in them.

At the end we reached 100% translation of KDE, GNOME, OpenOffice.

We decided to build the product did alpha release of the product.

My Experience Continues

On Shore/ Off Shore/ Development Sanity Testing Strategy

With the advent of Globalization the current project development model is changed in such a way that people from various part of the world will check in code for the same project. Every day when we check out the code we may want to make sure the current build is stable or not.

For web application there are several ways to make the manual work automated by using various tools.
When i was working for start-up company in silicon valley, there was close to 20 developers check-in code from different part of the world.

So i decided to automate the process by using automation tools. Since it was a .net application i decided to go with Code It Test. I had visual studio 2010 professional at that time and it was not supported and i couldn't make any progress.

If you are interested 

The i decided to shift to Selenium IDE automation. It is a simple fire fox plug-in and easy to install.

Selenium IDE

1) Browse the URL https://addons.mozilla.org/en-us/firefox/addon/selenium-expert-selenium-ide/  using Firefox
2) Go to Firefox menu and click Tools -> Selenium ID. 
3) Choose record and play option
4) Run your test case
5) Stop recording and play your test case.

       Record and play option which comes with that IDE is very handy. It is managers favorite tool. All Development as well as Project managers will like it for its simplicity. Just click and watch the entire show and if there is any error due to latest check-in shoot email.

Selenium Web-drive
Next step is use Web Drive. Understanding of each and element and its functionality is very important to create test cases. To get quick idea of elements and its actions we can use firebugs.
1) Install firebug add-on from https://addons.mozilla.org/en-us/firefox/addon/firebug/
2) Browse the site you want to write test case. It could be your companies internet, intranet site or any web application written in any language.










3) Check the above screen shot to to learn how to find each and every element in a webpage. 
4) Firebugs will help you to understand the elements name or id or class name or action performed on it. Either it is client side java-script call or server side post call etc.
5)Download Selenium web http://code.google.com/p/selenium/downloads/detail?name=selenium-server-standalone-2.28.0.jar&can=2&q=

Open a new eclipse java project. Add the downloaded jar file. Below code is a sample to open amazon.com website and search .

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class AmazonSearchTest {
public static void main(String[] args) throws Exception {
        // The Firefox driver supports javascript 
        WebDriver driver = new FirefoxDriver();
        
        // Go to amazon home page
        driver.get("http://www.amazon.com/");        
  
       // Get Elements for search text box and click button
        driver.findElement(By.id("twotabsearchtextbox")).sendKeys("Sujatha");  
        driver.findElement(By.className("nav-submit-input")).click();              
     }

}