Monday, December 31, 2012

OHCI host controller for usb devices

I got my first driver assignment...Here I have to implement host controller for USB. In a general purpose operating system its a complete layered architecture. Host controllers are implemented in the very generic and stanadard way to support all the standard drivers. In the embedded system the things a bit different. I am not suppose to implement the layered architecture for the above and the implementation is also customized according to our need.
I have two things for the reference:
            1> Datasheet: where all the registers are explained for SOC
            2> Broadcom CFE (Common Firmware Environment), because its a SWARM based board.

We can't use the CFE code directly because our base code design are a lot different. So my main focus is how the CFE done the registers configuration at last, configuring the right registers in the right sequence.
By going through the CFE code it helps me lot to identify the right registers and the sequence. There after it required to write a couple of functions to make the things done.Now the ports are configured for EHCI/OHCI and its working fine.

Happy coding !!

how to prepare for amazon/google

Here I am sharing the Quora post, the post is about how to prepare your self for the best companies in the software industry. People have disscussed and put their exprience and at the same time they are guiding that how to crack it. Please have a look here http://www.quora.com/Job-Interviews/What-should-I-do-in-the-next-6-months-to-get-into-a-company-like-Amazon-Google

Sunday, September 16, 2012

amazon coding challenge interviewstreet

today submitted the modified submission of "Shortest Sub-segment". It took a day to fix the bug in the way I am reading and storing the input...finally got AC :) ....and at the same time my count reached to 4/4.

Happy coding !!

My solution for the "Shortest Sub-segment" is below:

/***************************************************************/
/* author: rs                                                                                                           */
/***************************************************************/
import java.util.*;


class entry{
    String s;
    int v;
}

class entryComparator implements Comparator <entry> {
    public int compare(entry e1, entry e2) {

        int result = 0;
        if(e1.v > e2.v)
        {
             result = 1;
        }
        else if(e1.v < e2.v){
             result = -1;
        }
        return result;
    }
}


public class Solution {

public static HashSet<String> S1;
public static HashSet<String> S2;
public static HashMap<String,Integer> M1;
public static String First;
public static String[] Arr;
public static String[] Arr_p;
public static String[] Arr_k;
public static entry[] K1;
public static int[] K2;
public static int k=0;
public static int min=Integer.MAX_VALUE;
public static int max=Integer.MIN_VALUE;
public static int f_len=Integer.MAX_VALUE;
public static int len=0,end=0,f_end=0;
public static boolean found=false;


 public static void main(String[] args)
 {
  Scanner sc = new Scanner(System.in);
  First = sc.nextLine();

  First = First.replaceAll("[^a-zA-Z| |]", " ");
  First = First.replaceAll("  ", " ");
  Arr=First.split(" ");
  Arr_p=First.split(" ");
  for(int i=0;i<Arr.length;i++)
      Arr[i]=Arr[i].toLowerCase();
  k = sc.nextInt();
  sc.nextLine();

  String tmp;

  /* Initializing the basic data structure */
  M1=new HashMap<String,Integer> ();
  S1=new HashSet<String> ();
  S2=new HashSet<String> ();
  Arr_k=new String[k];
  K1=new entry[k];
  int fix=0;
  /* reading the k words putting in S1,M1 and array Arr_k*/
    for(int i=0;i<k;i++){
      tmp= sc.nextLine().toLowerCase();
   
      if(!S1.contains(tmp))
      {
        M1.put(tmp,fix);
        S1.add(tmp);
        Arr_k[fix++]=new String(tmp);
      }
   
  }//end of for

  K1=new entry[M1.size()];
  for(int i=0;i<fix;i++)
  {
      K1[i]=new entry();
      if(M1.containsKey(Arr_k[i]))
      K1[i].s=Arr_k[i];
      K1[i].v=-1;
  }
  /* copy s1 to s2 */
  S2.addAll(S1);

   int i;
  for(i=0;i<Arr.length;i++)
  {
      if(S2.contains(Arr[i]))
      {
          S2.remove(Arr[i]);
          if(M1.containsKey(Arr[i]))
          {
              int t_int = M1.get(Arr[i]);
              K1[t_int].v=i;
              if(min > i)
                min = i;
              if(max < i)
               max = i;
          }

      }
       else if(M1.containsKey(Arr[i]))
      {
          int t_int=M1.get(Arr[i]);
          K1[t_int].s=Arr[i];
          K1[t_int].v=i;
          if(min > i)
              min = i;
          if(max < i)
              max = i;
       }

      if(S2.isEmpty())
      {
          end=i;
          len=max-min;
          if(f_len > len)
          {
              f_len=len;
              f_end=max;
              if(len == k-1)
                 found=true;
              break;

          }
      }
  }//end of for
  if(found==true)
  {   for(int j=f_end-f_len;j<=f_end;j++)
      {
          System.out.print(Arr_p[j]+" ");
      }
  }
 else if(i==Arr.length && !S2.isEmpty())
  {
     System.out.println("NO SUBSEGMENT FOUND");
 }
 else // now handling the rest of the array
  {   int m_flag=0;
      Arrays.sort(K1,new entryComparator());
      int counter=max+1;
      K2=new int[K1.length];
      for(int p=0;p<K2.length;p++)
      {
          K2[p]=-1;
      }
      entry temp_entry=new entry();
      temp_entry.s=K1[0].s;
      temp_entry.v=K1[0].v;
      if(f_len > K1[K1.length-1].v- K1[0].v)
      {
              f_len=K1[K1.length-1].v- K1[0].v;
              f_end=K1[K1.length-1].v;
              if(f_len == k-1)
              {
                    m_flag=1;
              }


      }
      while(counter < Arr.length && m_flag==0)
      {

          if(Arr[counter].equalsIgnoreCase(temp_entry.s) )//&& M1.containsKey(Arr[counter]))
          {
               K2[M1.get(K1[0].s)]=counter;

               for(int t=0;t<K1.length;t++)
               {
                   if(K2[M1.get(K1[t].s)]!=-1)
                   {
                        K1[t].v=K2[M1.get(K1[t].s)];
                   }
               }
               for(int t=0;t<K2.length;t++)
               {
                    K2[t]=-1;
               }
              Arrays.sort(K1,new entryComparator());

              temp_entry.s=new String(K1[0].s);
              temp_entry.v=K1[0].v;
              if(f_len > K1[K1.length-1].v- K1[0].v)
              {
                    f_len=K1[K1.length-1].v- K1[0].v;
                    f_end=K1[K1.length-1].v;
                    if(f_len == k-1)
                    {
                        break;
                  }


              }
          }
          else if(M1.containsKey(Arr[counter]))
          {
              K2[M1.get(Arr[counter])]=counter;
          }
          counter++;
      }
      for(int j=f_end-f_len;j<=f_end;j++)
      {
          System.out.print(Arr_p[j]+" ");
      }
 }
 }
}

Tuesday, September 11, 2012

code chef September 2012

It's a nice experience. Started with the easy one HORSES, then move to another easy one CKISSHUG, CROWD having the unique pattern(required to generate the pattern in constant time), QNUMBER is about finding the total no. of divisor and CHEFTOWN where c++ stl fails giving tle and require to implement additional data structure to implement min() in (log n) time.

Its a nice experience having math stuffs, with fast I/O, choosing the right data structure .... and caring all the scenarios while writing the solution for all test cases.

Happy Learning ... :)

interviewstreet challenges (solved lucky number ...)

@total count is ten by solving lucky numbers with meeting point,flowers and pair. Lucky number the tougher one required DP with some calculation.... Keep coding :)

Sunday, August 19, 2012

interviewstreet challenge ( string similarity, permutation game, candies )

In this week solving 3 more interesting challenge:
> string similarity: a little bit easy question nlog(n) solution too works, if coded efficiently.
> permutation game: interesting problem, requires DP with memoization.
> candies: its fun to solve it. O(n) solution take 0.08 for the worst case.

Happy Coding ... !!

Sunday, July 29, 2012

FAT (FAT32) file system implementation


Suddenly in our project there is requirement to implement some portion of FAT32 file system...I got a chance and implemented some of the functions like open and write (including some minor bug fixing in the existent function find and read).

Its one of the cool assignment I got. I have the reference code (http://elm-chan.org/fsw/ff/00index_e.html)  to understand the fat file system. Implementing the file system will require good understanding of its data structures as well how the things are organized on physical disk. Internet is full of information about the data structures (http://www.maverick-os.dk/FileSystemFormats/FAT32_FileSystem.html) and good utility like NT disk viewer will help me to map all the information and structures to actual physical disk....by showing the actual disk sector by sector.

Its a nice and awesome experience.... Happy Coding !!

Thursday, May 24, 2012

code sprint interviewstreet

The interviewstreet code sprint comes with a new set of challenging and real time problems....enjoyed a lot to hacking the code checker....ranking the players and an attempt to find the the complexity of a given piece of code by merely scanning the code itself...It remembers me the college time where once I was looking for the implementation of the same problem.

This is my first code sprint when I appear in the fist page and enjoyed the company of top ten :)

Wednesday, February 29, 2012

interviewstreet

And including the changing bit challenge the successful submission count is 4 including(connect the country, string reduction, K difference). It's a great fun and a lot of learning to take the challenges.