Following are some of the interview questions for the post of Software Engineer – New Grad

    • Write a function to return the most repeated character in the string
    • How would you find most repeated word in a document?
    • How would you find most repeated word in a document that is too big to fit in the memory?
    • Add multi threading to the solution of previous problem
    • Given a document, how would you identify which language this document belongs to?
    • How would you scale the solution of the previous problem? What will be the bottlenecks?

    Natural Sorting is the sort order that is used by Windows Explorer to sort names of files.
    If we have strings ["a11", "a2", "a1"] then Array.Sort on strings would return us ["a1", "a11", "a2"] however natural sort requires the order to be ["a1", "a2", "a11"].

    Jeff Atwood suggests on his blog post that it would require 40 lines of C# code.
    Ian Griffith proved that the claim is not quite correct. Nonetheless his code was 20+ lines too.

    Allow me to give you natural sorting in C# using Linq in a single line of code:

    var sorted = items.OrderBy(s => Regex.Replace(s, @"[ \d]", String.Empty))
                      .ThenBy(s => Int32.Parse(Regex.Replace(s, @"\D", String.Empty) + "0"));
    

    To understand why this works, is left as an exercise for you dear reader :)

    And by the way, in Ian’s code the Compare method can be reduced to as under:

     public int Compare(IEnumerable<T> x, IEnumerable<T> y)
    {
                return x.Zip(y, (a, b) => comp.Compare(a, b))
                        .FirstOrDefault(c => c != 0);
    }
    

    Following are some of the questions that I’ve been asked in interview for the position of Software Development Engineer

    • If you had limited memory and you had to sort large no. of items such that all of them don’t fit in memory, how would you sort them? Write algorithm. What will be its complexity?
    • Write a function that calculates Fibonacci number.
    • Write an algorithm to shuffle a deck of cards. What will be its complexity?
    • Rate yourself from 1-10 in C#. Justify the number. What do you need to do to improve this number?
    • Describe the algorithm that generates schedule of interview of given list of candidates that are only available at certain timeslots. Each candidate has to be interviewed 3 times by 3 different interviewers. We also have limited no. of halls to conduct the interview. There should be no collisions/clashes between two interviews. Finally write a function in C# that validates that a certain schedule is valid (also model the schedule).
    • If you’re maintaining a high traffic website and all of a sudden the customers start complaining about performance of the website, how would you find out and fix the issue?
    • What project are you currently working on? How big is the team?
    • Model an elevator simulation. How would the scheduling work? What if there are multiple elevators in the building, how would scheduling be done?
    • You’re given an array of integers and you have to find out all pairs of numbers that sum up to 10.

    This is technical blog but this is a very non technical blog post. I strongly feel it is very necessary to blog about processes of getting your passport stamped by Protectorate of Emigrant office.

    Many people who are about to leave Pakistan to accept foreign employment usually do not know that they can’t leave the country without a stamp by Protectorate of Emigrant office on their passport. The official website of Bureau of Emigration & Overseas Employment is at http://www.beoe.gov.pk/Emigrants_Registration_Method.asp but it isn’t much help in understanding the process and cost involved in getting the protector done.

    Allow me to break the process down in steps

    • Medical Examination: There are certain gcc approved medical centers for conducting the medical examination and giving you fitness report that you have to submit at the protectorate office.In medical examination following test are conducted
      1) Eye sight
      2) Chest X ray
      3) Blood test
      4) Urine test
      5) Physical examination

      They need 4 passport size photographs, photo copy of your passport and ID card.
      Once you give all the tests, you’ll get the report in 2-3 days. It will cost you 3000Rs.

    • NICOP: National ID Card for Overseas Pakistanis is the English version of your ID Card. Once you go there take the pictures, give thumb impressions, fill out form, e.t.c; you get a receipt. This receipt is enough to get your protector done. You get the actual NICOP card after 8 working days. This costs you another 3000Rs.
       
    • Protectorate Office:Now you can go to the office of protectorate, fill out forms and complete the process. You get your stamped passport after a couple of hours. This can cost you between 5000-6000Rs. You have to go to a couple of places to submit chalans.

      Documents required at Protectorate Office are:

      • Original Passport
      • Offer Letter/Contract
      • Copy of VISA
      • Your Picture
      • Photocopy of your sibling, child or wife’s ID card (For insurance)
      • NICOP card or its receipt
      • Medical report (stamped by GAMCA)

    Tips:

    • Keep your original passport and original ID Card with you wherever ever you go or who ever you meet
    • Take at least 20 passport size pictures. Everyone needs them on their form.
    • Take plenty of your ID card photocopies.
    • Leave home with at least 15,000Rs in pocket.

    Another step-by-step explanation of the process is at http://www.wikihow.com/Get-Your-Passport-Stamped-from-Protectorate-of-Emigrants-in-Pakistan

    Though not directly related to protector but its good to get your bachelor degrees attested by HEC and Foreign office. You’ll employer will ask for them.

    Squiggle 2.1 stable and final version has been uploaded on codeplex.
    This version includes broadcast message feature that allows you to send a message to all contacts at once. Its not a group chat feature because the recipients don’t know this message is being sent to others as well.

    Replies sent in response to the broadcast message are shown in the same window, the message was sent from but if you want to continue chatting separately, you can always open up the chat window separately and continue chatting.

    Another feature in this release is that every time a buddy changes status, display name or message; his/her Last updated field in Contact List tooltip changes to the time it last changed. This is helpful to know when someone went away or since how long a person is idle.

    Both of these features were suggested by Aaron Heath. Thanks Aaron.

    Features coming in next release are:

    • Geo distributed network of Squiggle Messenger. Allow people from two different LANs to communicate via bridge
    • Auto update
    • Chat History
    • Buddy Groups

    Hi

    Today we’ve released Squiggle 2.0 final.
    The only thing added after beta is a emoticon button in the chat window; rest are all bug fixes.

    In future versions following features are expected:
    1) Chat History/Log
    2) Auto update feature (Notify you whenever there is an update to squiggle)
    3) An option to send message to all contacts (Maybe a broadcast window)

    Today I was bored so I decided to write code to generate permutations with LINQ.
    According to the article at mathsisfun there are two types of permutations

    1) With repetitions

    2) Without repetitions

    The code for generating permutations with repetitions can be as follows

            static IEnumerable<string> Permutations(int n, params char[] chars)
            {
                if (n > 1)
                    return from a in chars
                           from b in Permutations(n-1, chars)
                           select a+b;
                else
                    return chars.Select(c=>c.ToString());
            }
    

    The code for generating permutations without repetitions can be as follows

            static IEnumerable<string> Permutations(int n, params char[] chars)
            {
                if (n > chars.Length)
                    throw new ArgumentException("chars can not be less than n", "chars");
    
                if (n > 1)
                    return from a in chars
                           from b in Permutations(n-1, chars.Where(c=>c!=a).ToArray())
                           select a+b;
                else
                    return chars.Select(c=>c.ToString());
            }
    

    Note the check on chars length and n in the second version. This is necessary because you cant generate permutations of length 10 without repetitions using only 4 chars.

    That permutation lock picture in the article reminds me of a object oriented hit counter I wrote (which is maybe inappropriately named ‘mechanical clock’).

    The code for hit counter is as follows

        class Clock<T>
        {
            Ring<T> firstRing;
            List<Ring<T>> rings = new List<Ring<T>>();
    
            public Clock(int length, params T[] digits)
            {
                if (digits.Length == 0)
                    throw new ArgumentException("You must provide one or more digits", "digits");
    
                IVisitable<T> left = new NullVisitable<T>();
                for (int i = 0; i < length; i++)
                {
                    var nums = new Digit<T>[digits.Length];
                    for (int j = 0; j < nums.Length; j++)
                        nums[j] = new Digit<T>(digits[j]);
                    var ring = new Ring<T>(nums);
                    ring.Left = left;
                    left = ring;
                    rings.Add(ring);
                }
                this.firstRing = rings.Last();
            }
    
            public IEnumerable<T> GetValue()
            {
                for (int i = 0; i < rings.Count; i++)
                    yield return rings[i].Value;
            }
    
            public void Tick()
            {
                firstRing.Visit();
            }
        }
    

    Every time a clock ticks or a hit occurs on a hit counter, the right most ring moves by one step.
    When the ring reaches its last digit, it turns the ring on its left by one step (just like a clock’s needle work).

        class Ring<T> : IVisitable<T>
        {
            IList<IVisitable<T>> digits;
            int currentNumber;
    
            public Ring(params IVisitable<T>[] digits)
            {
                this.digits = digits.ToList();
            }
    
            public T Value
            {
                get { return digits[currentNumber].Value; }
            }
    
            public IVisitable<T> Left
            {
                get { return digits[0].Left; }
                set { digits[0].Left = value; }
            }
    
            public void Visit()
            {
                currentNumber = (currentNumber + 1) % digits.Count;
                digits[currentNumber].Visit();
            }
        }
    

    Ring as seen on a hit counter/car mileage tracker/permutation lock, is a set of digits

        class Digit<T> : IVisitable<T>
        {
            public T Value { get; set; }
            public IVisitable<T> Left { get; set; }
    
            public Digit(T value)
            {
                Value = value;
                Left = new NullVisitable<T>();
            }
    
            public void Visit()
            {
                Left.Visit();
            }
        }
    

    IVisitable interface represents the behavior of being able to change a value, maybe it should have been named ITurnable that has Turn() instead of visit.
    Null Visitable class represents a static value

        class NullVisitable<T> : IVisitable<T>
        {
            public T Value { get; private set; }
            public IVisitable<T> Left { get; set; }
            public void Visit() { }
        }
    

    This is how you would use the clock

                   var clock = new Clock(5, 0, 1);
                    for (int i = 0; i < 5; i++)
                    {
                        Console.WriteLine(clock.GetValue().AsString());
                        clock.Tick();
                    }
    

    AsString is an extension method which is as follows

           public static string AsString(this IEnumerable<T> items)
            {
                string output = items.Aggregate(new StringBuilder(), (a, x) => a.Append(x)).ToString();
                return output;
            }
    

    The net effect of calling tick repeatedly on the clock is of generating permutations with repetitions. This can be modified to generate permutations without repetitions which is left as an exercise for you.

    We’ve just announced the beta release of Squiggle LAN messenger 2.0

    This new version includes group chat, emoticons and several bug fixes.

    http://squiggle.codeplex.com/releases/view/48760

    Try it out and send your valuable feed back at info [at] overroot [dot] com

    Squiggle Lan Messenger v1.6 has been released.

    Following are the new features:

    • Select font color, type for messages
    • Send buzz (nudge) in conversation
    • Menus for better usability in main and chat window
    • Save conversation in rtf or text format
    • Search contact list
    • Sort contact list
    • Better, stable and more reliable underlying communication framework
    • Machine name is shown in contact tooltip
    • Timestamp is shown against messages

    Grab your copy at http://squiggle.codeplex.com

    After release of v1.5 of Squiggle Lan messenger, we’re working on the following features

    • Better usability (Menu’s on main and chat window)
    • Specifying font size, color and name for messages
    • Search contact list
    • Sort contact list by status or name
    • See machine name in User Information tooltip in Contact List

    Features that we’ll also work on, but we haven’t decided the release for are as follows:

    • Group chat
    • Emoticons

    If you have any ideas or suggestions please feel free to post them on our codeplex page http://squiggle.codeplex.com