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();              
     }

}

Wednesday, January 30, 2013

Working with third-party controls in Microsoft applications

DevExpress - .NET controls:
DevExpress controls are very sophisticated and easy to implement without much scripting or server side validations. Dev-Express Gridview controls comes handy when we try to get Excel kind of feeling for a grid in asp.net application. Filtering, sorting, Searching, pivoting every thing is done with setting up simple properties. In my experience i used DevExpress controls in 3 different companies i worked.

   When i was working in OOCL USA Inc, their agreement builder project was using DevExpress controls intensively. Like the same HP is using Dev Express controls for their deal manager and other applications. 
My current company also uses the same product for one of their automation project. 

   One of our developer was struggling to implement column level edit for specific fields. I spent some time found the below work around. Check CodePoject for the work around i posted. In my free time i try to post small tips to forums like code project to help other developers as well.

But IMHO even though the tools are handy, we cannot compromise on performance of application. These type of controls some times uses update panel kind of AJAX controls which decreases the website performance drastically. We should make use of proper java script libraries and write robust applications rather than using heavy controls.




My Experience With Open Source Projects - Part3 (Tamil PC trust and TSDF)

Tamil Virtual University:
      As we started progressing translation, we decided to apply for government funding. Tamil Virtual University was funding few language computing projects. So we decided to approach them and get the funding. We drafted proper proposal and how to commercialize etc and approached TVU.

TamilPC Trust:
      After couple of meetings with officials we got 1.25 lakhs fund from TVU for this project. We formed Tami PC trust and decided to deposit the money on behalf of tamil PC truns. For all team members localization project is not a full time project so we decided to hire some one who can help full time in this project. Hariram Aethrya from Sun micro systems joined with us to help us. He was a software engineer at Sun Microsystems and worked in Bayarea, california before. At present he is running his own "Vedic School" at Kumbakonam.

New member to the team:
     We decided spend the money for paying salary(I will not say that it is salary... for his experience and accomplishment he might have got 10 times more than what we offered) and rent a computer for linux translation.

     Same time Vaseegaran (KDE Maintainer gave his access for us to check in our Localization effort). For GNOME i got CVS access to check in files, translation was in full swing. We cracked the unknowns like OO compilation, Kernal compilation etc. But the translation was progressing very slow.

Then I decided to get Students force to complete the work.
My Experience Continues....

Tuesday, January 29, 2013

My Experience With Opensource Projects - Part 2 (Birth Of ZhaKanini)

New Members to the team:
K M Leela (Web designer at Sterling info tech) also joined in the team. She is good at graphical designing and animation. Later Mr ShanthaKumar  also joined in the team. His skill set is writing proposals, marketing etc. It is decided that Ma. Sivakumar and I will take care of technical and translation aspect of  the project. 

Birth Of Zhakanini:

We decided to name the distribution. Since Writer Sujatha is leading the effort we didn't find it difficut to name the product. He just said "Zha Kanini". With the help of Leena the logo was designed and Tamil PC teams Zha Kanini  project kick started.

OO translation and BharathyOO team:
First phase we decided to translate Open Office. We downloaded Open Office from Sun Microsystem web site and there were procedure to extract strings. I had a seperate server at Dishnet office and decided to install linux in that computer to do extraction and string parsing to make po files. The string extraction was very simple and we make a big excel file with several thousand strings to be translated. We took printout and spiral bind the printout as book and gave it to Sujatha sir. Sir used to translate at-least 100 words per day. We made a disctionary with his translation. While we were in progress we came to know that CDAC started OO Tamil translation. We tried to share our translations but after few back and forth iterations we decided to stay away and make progress in our translation effort.
.... My Experience will continue