dian main

=== walmart labs===

 

good morning.

class Store
  Item [100] items
  int length = 0
  public int startingIndex = 0;
  boolean add(Item item)
  Item remove()
  public synchronized boolean add( Item item )
  {
      if( item == null )
      {
          return false;
      }
      if( length < 100 )
      {
          Item[length++] = item;
      }
      return true;
  }
  public int getLength( Item[] )
  {
      if( Item == null )
      {
          return -1;
      }
      int i = 0;
      while( Item[i] != null )
      {
          i++;
      }
      return i;
  }
  public synchronized Item remove( Item[] items )
  {
      if( items == null || length == 0 )
      {
          return null;
      }
      if( startingIndex < 100 )
      {
          Item item = items[startingIndex++];
      }
      // all items have been removed, we need to recycle the array
      else if( startingIndex == 100 )
      {
          length = 0;
          startingIndex = 0;
      }
      return item;
  }
  int [] mergeTwoSortedArrays(int [] array1, int[] array2)
  {
      int i , j = 0;
      int k = 0;
      int[] result = new int[array1.length + array2.length];
      if( array1.length == 0 && array2.length == 0 )
      {
          return null;
      }
      else if( array1.length == 0 )
      {
          while( j < array2.length )
          {
              result[k++] = array2[j];
              j++;
          }
      }
      else if(  array2.length == 0 )
      {
          while( i < array1.length )
          {
              result[k++] = array1[i];
              i++;
          }
      }
      else
      {
           while( i < array1.length && j < array2.length )
          {
              if( array1[i] < array[j] )
              {
                  result[k++] = array[i];
                  i++;
              }
              else if( array1[i] > array[j] )
              {
                  result[k++] = array[j];
                  j++;
              }
          }     
      }
  }

 

 

=== g00gle====

Please use this Google doc to code during your interview. To make hands free coding a little easier, we recommend that you use a headset or a phone with speaker option.

Best,
Google Staffing

Good morning,

<form action=”submit_order” method=”POST”>
<input type=”hidden” name=”item” value=”SKU#12345″ />
<input type=”hidden” name=”price” value=”99.99″ />
<input type=”hidden” name=”user_id” value=”ab831c3fa3″ />
<input type=”hidden” name=”user_notes” value=”document.getElementById(‘user_notes’)” />
<input type=”submit” value=”Buy” />
</form>

window.onreadystatechanged

window.onload = function registerOnclick() {
var elem = document.getElementById(“elem”);
if( elem )
{

elem.addEventListener( “click”, handleOnclick, false );
elem.attacheEvent( “click”, handleOnclick );
elem.onclick = function handleOnclick() {
          elem.style.display = (elem.style.display != “none”) ? “none” : “block”;

}
}

getElementsByClassName = function( className )
{
    var result = [];
    var node = document;
    while( true )

{

    while( node  )
        {

        if( node.hasAttribute( “class “ ) )

        {

            if( node.className == className   )

            {

                result.push( node );

            }

        }

        node = node.nextSibling;

var nodes = []

nodes = node.childNotes;
            for( var i = 0, l = nodes.length; i < l; i++ )
            {

                if( node.hasAttribute( “class “ ) )

        {

            if( node.className == className   )

            {

                result.push( node );

            }

        }

            }

                   }
        }

O(n), space : o(m), in the worst case , o(n)

}

Advertisements
This entry was posted in interview and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s