Arrays !

Most of the interview questions that I have come across involve some kind of array manipulations. Here are a few common interview questions based on arrays:

1. Given an array consisting of 0s and 1s sort it in one-pass

This problem is similar to the partition step of Quicksort, where elements less than or equal to the pivot are on the left side of the eventual location of the pivot and the elements greater than the pivot are to its right. Similarly, in this case we partition such that all 0s appear before all 1s. The code is as below.

void ColorSort2(vector<int> &arr)
{
  int sz = arr.size();
  int i=0, j=0;
  while(j<sz)
  {
    while(j<sz && arr[j] == 1)
    {
      j++;
    }
    if(j<sz)
      swap(arr[i++], arr[j]);
  }
}

2. Given an array consisting of 0s,1s,2s sort it in one-pass [Dutch national flag algorithm]

The problem is similar to the previous problem. This is because, it can be mapped to a different partition approach of Quicksort, where we divide the entire array into three parts. The left part consists of the elements lesser than the pivot, the center corresponds to the elements equal to the pivot and the right part consists of elements  greater than the pivot. The code is as below.

void ColorSort3(vector<int> &arr)
{               
      int sz = arr.size();
      int i=0, j=0, k = sz-1;
      while(j<=k)
      {
            while(j <= k && arr[j] == 1)
                  j++;
            if(j>k)
                  break;
            if(arr[j] == 0)
                  swap(arr[j++], arr[i++]);
            else if(arr[j] == 2)
                  swap(arr[j], arr[k--]);
      }                         
}                  

3. Given an array consisting of equal number of positive and negative numbers, rearrange them so that negative numbers are in even positions and positive numbers are in odd position.

The problem is similar to the previous 2 problems which are modified versions of the Quicksort partitioning scheme. In this problem, we use a similar scheme where we partition elements in even and odd positions instead of partitioning left and right of the pivot as is the case in the standard Quicksort partitioning scheme.

void alternate_positive_negative(int arr[], int n)//Where n is the size of the array
{
	int i=0, j = 1;
	while(i<n && j<n)
	{
		while(i<n && a[i]<0){i+=2;} //If a negative element is in the even position move to the next even position
		while(j<n && a[j]>0){j+=2;}//If a positive element is in the odd position move to the next odd position
		if(i< n && j<n)
		{
			swap(a[i], a[j]);//If we find an (i,j) such that a positive element is in even position and a negative element is in the even position - swap the two elements.
			i+=2;
			j+=2;
		}
	}
}

4.  An array A[] consists of positive and negative numbers such that the sum of all elements is 0. Now if you start with an index 'k' in each array and do the following summation, SUMMATION (Ak), where Ak is the value at index k of array A, where 'k' increments and wraps back all the way to k-1, the final sum value will be zero. Question: Find a suitable 'k' such that during any point in the summation, SUMMATION(Ak) is always non negative. Find such a 'k' in O(n) time.

For eg. consider an array A[0] = {a,b,c,d}. If k=1, the summations start with 1 and are a[1] followed by a[1]+a[2], a[1]+a[2]+a[3] and wrapping around a[1]+a[2]+a[3]+a[0].

Now, k is valid if
a[1]>=0,
a[1]+a[2] >=0,
a[1]+a[2]+a[3]>=0 and
a[1]+a[2]+a[3]+a[4]>=0.

Find such a valid k in O(N).

int FindIndex(int arr[], int nums)
{
	int start = 0, end;
	while(arr[start]<0)start++; //Start with some k = start, such that arr[start]>=0
	int sum = arr[start];
	end = start+1; //End indicates that all elements from [start, end) have been scanned. The interval wraps around the left as well as the right end
	while(start!=end)
	{
		sum = sum+arr[end]; //Increment end, as long as sum>=0
		end = (end+1)%nums;
		while(sum<0) //If sum < 0
		{
			start--; 
			if(start<0)
				start = nums-1;
			sum = sum+arr[start]; //Decrement start till sum >=0. If sum >=0, all SUMMATIONS from [start, end) are positive. Please note that, the interval wraps around the left and right endpoints as seen previously.
		}
	}
	return start;
}

5. Given 123, 1+2 = 3;
Given 123410, 1+2+3+4 = 10; Thus, given a number can an equation be formed. Only +/= can be used.

Here, we divide the work into 2 functions. In the driver function we generate all possible values that can appear on the right hand side. Thus, in the above example (123410) the values that can appear on the right hand side are: 0, 10, 410, 3410, 23410. The 2nd function checks if an equivalent value can be obtained as a sum of some combination of the remaining digits and ‘+’ signs. The code is as below. Maintain a state variable for better performance.

bool CanFormN(char *string, int end, int n)
{
        if(n == 0 && end == -1)
                return true;
        if(end == -1)
                return false;
        char temp = string[end+1];
        string[end+1] = 0;
        for(int i = end;i>=0;i--)
        {
                int num = atof(string+i);
                if(num>n)
                        break;
                if(CanFormN(string, i-1, n-num)
                {
                        string[end+1] = temp;
                        return true;
                }
        }
        string[end+1] = temp;
        return false;
}

bool CanEquationBeFormed(char *string)
{
        int num = strlen(string);
        for(int i = num-1;i>0;i--)
        {
                int n = atoi(string+i);
                if(CanFormN(string, i-1, n))
                        return true;
        }
}

Bit Magic !

This post contains a set of frequently asked interview/written questions (with their answers) which require some sort of interesting bit manipulations.

1] Is my system Big-Endian or Little-Endian ?
So to answer this question, we’ll first understand what the terms actually mean. Now, Little Endian means that the lower order byte of the number is stored in memory at the lowest address, and the higher order byte is stored at the highest address. That is, in a Little-Endian the little end comes first.

Below are a couple of ways to determine if the data representation in your system in Big-Endian or Little-Endian. In both approaches, what we attempt to find out is which end comes first. If the LSB comes first then the representation is Little-Endian else it is Big-Endian.

union nn{
	int a;
	unsigned char b[4];
};
int main()
{
	int n = 1;
	if(*((unsigned char *)(&n)) == 1)
		printf("Little Endian\n");
	else
		printf("Big Endian\n");

	union nn nd;
	nd.a = 1;
	if(nd.b[0] == 1)
		printf("Little Endian\n");
	else
		printf("Big Endian\n");
}

2] How to get the reverse the sign of an integer ?

void reversesign(int &num)
{
  num = ~num+1
}

3] How to get the absolute value of an integer ?

void absolute(int &num)
{
  int mask = num>>31; //If the number is negative, all bits go 1, else all bits go 0
  num = ((num^mask)+mask&1); //If its positive -> Do nothing, else it is equivalent to 2s complement.
}

4] Rotate an integer n by d.

void Rotate(int &n, int d)
{
  #define INT_SIZE 32
  n =  (n>>d)|(n<<INT_SIZE-d);
}

5] Reverse the bits of an integer.

int Reverse(int rev)
{
  int i = 0, ans = 0;
  while(i<32)
  {
	ans <<= 1;
	ans |= ((rev>>i) & 1);
	i++;
  }
  return ans;
}

6] Unset all bits except the rightmost bit.

void UnsetBits(int &Rightmost){
      Rightmost = (Rightmost&-Rightmost);
}

7] Find the smallest power of 2, greater than Num.

int FindNextPowerOf2(int Num)
{
  while((Num&(Num-1))!=0)
	Num &= (Num-1);
  Num <<= 1;
  return Num;
}

8] Write a macro for setting the jth bit of i equal to k

#define SETJBITK(i, j, k)  i ^= i>>j&1 == k ? 0:1<<j

For greater clarity

#define SETJBITK(i, j, k)  i ^= (i>>j&1 == k ) ? 0:(1<<j) //Is the current bit same as the bit to be set, if it is xor with 0, else flip the bit by xoring with 1<<j.

9] Find the position of MSB

int FindPositionOfMSB(int i)
{
	if(i == 0)
		return 0;
	int left = 31, right = 0, center;
	while(left>right)
	{
		center = (left+right)/2;
		if((i>>left)&1 == 1)
			return left;
		if((i>>center)&1 == 1)
		{
			right = center;
			left -=1;
		}
		else{
			left = center-1;
		}
	}
	return left;
}

10] Find the number of set bits

int FindNumberOfLeadingBits(int i)
{
	int n = 31;
	while(n>=0 && (i>>n)&1!=0)
		n--;
	return 31-n;
}

11] Find the number of Leading bits

int NumberOfSetBits(int i)
{
	int count = 0;
	while(i!=0)
	{
		i&=(i-1);
		count++;
	}
	return count;
}

12] Is the number a power of 2

bool IsPowerOf2(int i)
{
	return (i!=0 && (i=i&(i-1))==0);
}

13] In an array of numbers, each number appear exactly twice except one. Find the non-repeating number.

int FindTheNonRepeatingNumber(vector<int> &Vec)
{
	int a = 0, sz = Vec.size();
	for(int i=0;i<sz;i++)
		a^=Vec[i];
	return a;
}

14] Write a function which returns true if a given number is 1 less than power of 2.

bool IsOneLessThanPowerOf2(int n)
{
   return (n&(n+1)) == 0?true:false;
}

15] Implement x ? y : z as a function: int cond(int x, int y, int z); using only ~, !, ^, &, +, |, <>. The solution must be a single line solution with no extra variables.

int cond(int x, int y, int z)
{
	return (((!(x)<<31)>>31)&z)|((~((!(x)<<31)>>31))&y);
}

The Microsoft Interview !

It started one fine evening in November 2009, I got a mail from Microsoft Research, stating that they wanted to interview me for the position of Research Intern in the Text Mining, Search and Navigation research group (TMSN) now known as Machine Learning and Intelligence (MLI) (This was in response to an application that was made a few months back). An interview was scheduled for the following evening and was based on my current work, basic knowledge of clustering-dimensionality reduction algorithms, system design and stuff. And, couple of days later I got the intern position ! Later, I was told that the internship was sponsored through the India-internship program.

During the internship, we developed Error-Explorer, a visualization and analysis tool for prediction accuracy optimization to support production deployments of machine learning algorithms. The tool is designed to be predictor and domain-independent and can be used with a wide variety of prediction tasks and arbitrary learning algorithms. This was followed by a redesign of a generic machine learning experimentation framework that involves addition of an adaptively extendible (reflection-based) GUI and support for distributed execution on HPC clusters. The internship was a great learning experience most of all because it involved interaction with really smart people and secondly because of the guidance of my mentor and manager.

And that brings us to the topic. After the internship, sometime during late November, 2010 my mentor/manager forwarded my resume and I was contacted by the recruiters a few weeks later. The hiring team sent me some questionnaires regarding my interest in technologies and stuff and then set up a phone interview. The phone interview was pre-dominantly non-technical asking me about technical things that interest me, products groups I am interesting in Microsoft, what I liked and disliked about my internship and some others. There was one technical questions as follows:

We have an application which given 3 sides of a triangle tells us if the triangle is equilateral, isosceles or scalene. I had to test the application. Three weeks later I was contacted by their interview scheduler who would set up the face to face interview. The interview was in Dubai and I was asked to choose 3 days from 28th February-3rd March based on my order of preference.

The interviews were then scheduled on 1st March in the evening slot. Microsoft made arrangements for visa, travel, accommodation and food and the only thing I had to pay for was the taxi (which would be reimbursed later on). A couple of days before the actual interview, there was an interview preparation call in which the recruiter talked about the procedure to be followed during the interview. We were told that about 40 people would be interviewed on 4 days from 28th Feb-3rd Mar., 2011 in two sessions, a morning one and an afternoon one. Thus about 5 people would be interviewed in each session. The groups that were hiring were the Microsoft Business Solutions, Windows Azure, Microsoft Dynamics and Visual studio. There were 2 interviewers from the Microsoft Business division and 1 from each of the other divisions, thus making it a total of 5 interviewers and all of them were at very senior positions in their respective groups.

I was to be interviewed in the afternoon session and reached the Microsoft Dubai office about an hour in advance. As I sat there waiting for the interviews to start I noticed that the office wore a more formal look as compared to Building 99 at Microsoft, where I interned. I was told later that, this was because the Dubai office was a sales office. While we were waiting for interviews to begin, the recruiter again briefed us on the interview procedure. We were told that, each interviewee would have 4 one-to-one interviews of about 45 minutes each and between the interviews there would be a short break when the interviewers discussed about the performance of the people they interviewed.

Interview #1:

1) Tell me about yourself. What do you consider your biggest achievement ?

2) What’s a Heap ? What’s a binary heap ? When do we use one or the other ?

3) What’s a Queue ? Why is it used ? Code an enqueue and a dequeue ?

4) Test a marker

All the interviews required some sort of coding on the white-board.

Interview #2:

1) Given a sequence, draw a BST

2) Find the mth largest member in a BST O(m), O(log n) solutions.

3) Given a number 233->BED, BDD and other words can be formed. How do you convert a number to all possible words (Valid/Invalid). Propose satisfactory Data Structures and and helper functions. Recursive and Non-recursive solutions

Interview #3:

Write a code which given a 3×3 Tic-Tac-Toe board outputs the move to be made. Losing is not an option ! I talked about a reinforcement learning, snapshot approach, minmax approaches. Finally, gave a solution which involved some kind of tree-pruning. Had to code it then.

Interview #4:

1) Given a scenario where you are to build an undo-redo operation for an application that draws shapes how would you implement it. You can resize shapes, change colours and stuff. Talk about Data Structures, OOPS concepts (Abstract Classes, Interfaces)

2) What I did in my internship at MSR.

3) Areas of computer science I like and stuff. Talked about his experience over the years.

They contacted me a couple of days later and informed me that, they would be making an offer for the SDET position in the Microsoft Dynamics Team.

“Some” Interview Problems

So, the following is a list of interview problems I found on various sites which I could not solve or for which I could not find appropriate solutions on various forums. Please post the solutions, if you can solve or have solved any or an argument if it cannot be done.

1. Given a set of positive and negative integers group all the positive integers on one side and negative integers on one side. The numbers should be in the same order they appear.

2. Given an array of integers where some numbers appears once, some numbers appear twice and only one number appears three times, how do you find the number that repeat 3 times. Using extra memory is not allowed.

3. Delete duplicates from a sorted array in O(log n) time and O(1) space.

4. Given an array of ‘n’ random integers. Given an integer 1<=k<=n. Find the k numbers such that the minimum difference of all the possible pairs of k numbers is maximum (maximum among other minimum differences
for various possible selections of k numbers ).

5. Given an array of size n wherein elements keep on increasing monotonically upto a certain location After which they keep on decreasing monotonically, then again keep on increasing, then decreasing again and so on. Sort the array in place (ie. using only O(1) extra memory) [Is there a nice solution that uses the increasing decreasing property ?]

6. There are N nuts and N bolts, all unique pairs of Nuts and Bolts. You cant compare Nut with Nut and a Bolt with Bolt. However, you CAN compare Nut with Bolt. Now how would you figure out matching pairs of nut and bolt from the given N Nut and Bolt.
Is there a O(NlogN) time and O(1) space complexity solution.
[The various forums I have looked at propose a quicksort like solution and all of them seem to be O(N) space.]

7. Given a set of numbers, transform it to an array such that the value at i is the the product of all elements except the element at ai. To be solved with no extra memory.

8. Design a data structure that supports the following two operations on a set S of integers:
a. Insert(x; S), which inserts element x into set S, and
b. DeleteLargerHalf(S), which deletes the largest ceil(|S|/2) elements from S.
Show how to implement this data structure so both operations take O(1) amortized time.

9. Given a>0, compute a-1 without using division.

10. You are given an array of positive integers a[1..n] such that a[1] < a[2] < … a[n]
Given a positive integer C find j and i such that Choose(a[j], a[i]) = C
where Choose(b,a) = b choose a, the binomial coefficient = the number of ways of choosing a balls from a set of b balls. Assume you have a fast Choose(b,a) calculating function at your disposal.

11. You have an integer array of length N, containing values in the range 1,2,3…N^2. Sort the array in O(N) time.
[Solutions on various forums have proposed a radix sort like method as the number of bits to describe the number can now be bounded. However, describing a number upto O(N^2) takes upto 2logN bits and hence, the radix sort will be O(Nk) which is equivalent to O(NlogN).]

Directi Interview

It all started with a friend forwarding my resume to Directi. The HR guys contacted me the next day over the phone and I had a general chat about the company the position and what to expect. I was asked to submit a level 3/4 problem on the careers page after which an interview would be scheduled. That was a Friday. Over, the weekend I submitted the solution to the ARRAYTRM problem and on Tuesday the following week I received a call for telephonic interviews. I had two interviews lined up for me, the first being an algorithm interview and the next one being a tech interview. At exactly, the mentioned time I received a call from the concerned person and the questions were as follows:

Interview #1 [Telephonic] => Algorithm Round:
1) The interviewer asked me about my thesis problem (it was a published work) and my proposed solution. This was followed by an interesting discussion on the same. Interestingly, this is the only interview to date where I was asked about my Masters problem :)

2) The next question was, there are N nuts and N bolts, all unique pairs of Nuts and Bolts. You cant compare Nut with Nut and a Bolt with Bolt. Now ,how would you figure out matching pairs of nut and bolt from the given N Nuts and Bolts.

3) There is a frog who can make jumps of length 3,5,7. There are stones in a river at distances a1, a2… an. The other end of the stream is n distance away. Can the frog cross the stream. What if the frog can make jumps backwards ?

I guess there was another question which I cant recall at this stage. Also, there was a short bit of discussion on my work at MSR. To wrap things up, I asked the interviewer about Skenzo and he briefly explained to me its working ! :)

Interview #2 [Telephonic] => Technical Round:
This was a tech-round and the interviewer asked loads of questions (Loads and Loads of them)
It started with DS:
Difference between hash-table and BST
Difference between B-Tree and BST

Then moved to DB
1) Types of Indexes. If there is a table Employee(Name), how would you retrieve all names starting with ‘a’, ending with ‘a’. Do both queries have same speed of execution. What can be done so that both are equally fast ?
2) What is Normalization ?
3) ACID properties

OS:
Loads of questions (~25-30) covering processes, threads, synchronization, deadlocks, virtual memory. Virtually everything that could be asked was asked.

Interview #3 [Telephonic] => Pair-programming round:
1) Implement sort for a very large file. [Write a complete working code]. The interviewer shared a doc on collabedit.com and was able to see what I coded in real-time.
2) A discussion about my previous job experience.

Interview #4:
1) What you want to do in life ?
2) Consider a huge feed of data like the case of twitter or facebook. Now, how would you go about implementing search (ads) based on keywords. So someone tweets (Want to buy watch) – ads to be shown should be relevant.
3) Given n people live in n houses and at some instant all of them disappear and reappear in some other house. What is the probability that no two meet each other.
4) Number of squares in a nxn grid
5) How does database implement concurrency and consistency in both distributed and local settings.

The interview process was unique in a way that it made you think rather than answering standard interview questions.The next day they made an offer and the iPad that accompanied it was the perfect icing on the cake ! :)

The Facebook Interview

It was early September and after one of the meetings, Dr. Vikram Pudi said “Ho gaya kaam ! ” (Those were not the exacts words though ! ;) ). So, the placement saga started and the first company I applied for was Facebook. A couple of weeks later, the HR contacted me and asked me submit a puzzle on their careers page. A couples of days later and a couple of puzzles later, the HR contacted me again. The first interview was short and she asked the usual HR questions like Why facebook ? Why should we hire you and the like .. ? A couple of simple technical questions like:
1) Time complexity of bubble sort in the best case and
2) I will choose a number between 0-1000, you can guess any number and I will say higher or lower. Maximum number of guesses, that will be required. This was followed by a number of telephonic interviews.
3) How many children does a node of a binary tree have ?

Telephonic Interview #1:
The interviewer introduced himself and talked briefly about the things he worked on, the company culture and then asked me to introduce myself. I talked a bit about my academics, the projects I did at college and what I did during my internship. He then shared a doc on collabedit.com in which I had to write the code and he would be able to look at it in real-time. The questions were:
1) One feature you would add to facebook.
2) Given a rotated sorted array, find a number in the array.

Telephonic Interview #2:
1) Build a Hash-Table, that supports insert, delete, find in O(1) and also removes the variables that have not been accessed for more than k instructions (O(1) too).
2) Given a string, reverse the order of words in the string.
3) A pretty simple SQL query.

Telephonic Interview #3:
1) Given two sorted arrays with space in one of the arrays sufficient for holding all elements, merge the arrays.
2) Given two tables:
Click (pageid, timestamp)
Pageview(pageid, timestamp)
Find the ctr.

Telephonic Interview #4:
Reverse a linked list
Find the square root of a number

The interviewers were quite friendly and the questions were quite simple too. Also, I answered all the questions, but on the way I made a couple of minor boo-boo’s like not handling edge cases, special cases and the like [For e.g. in the square root question, I did not put a check for the negative numbers]. And so, I received a reject after the fourth interview. I believe they were looking for someone who could code well, code fast and code accurately to the extent that, it should compile, run and execute perfectly as expected in the first run itself. Simply put, I couldn’t ;)

My Amazon Interview

It was the early December and Amazon.com was on campus to kick-off campus placements for 2010-11. The interviews were for SDE positions in Amazon.com India Development centers in Chennai, Bangalore and Hyderabad. They started off with an impressive presentation on what they work on in general and the India centers in particular. The placement procedure started off with a written round, an online session with multiple choice questions and coding questions. The online portal was extremely well built and had a very intuitive feel to it. There were about 20 multiple choice questions, 2 coding questions and the maximum time allotted was 90 minutes. There were about 4-5 questions from probability, 1 from automata theory, about 6-7 general programming puzzles(=/== tricks), 2 networks, a couple on threading. The coding questions were:
1) Given a graph as a set of edges, find out if the graph has a cycle and print the cycle starting with the lowest number in that cycle.
2) Given two lists, merge them such that successive nodes from the same list are now alternate (Assume that the lists may not have the same number of nodes in a general case).

Interview #1:
They shortlisted 25 students for the interview rounds and incidentally I was scheduled to go 24th in a list of 25. That meant I had to wait for about four hours after the first interview started for my interview rounds to start. By the time a couple of guys had already completed (read “aced”) two of theirs.

1) Given a tree vertical sum of all nodes.

     1
    / \
  2     3
 / \   / \
4   5 6   7

Vertical-1: nodes-[4] => vertical sum is 4
Vertical-2: nodes-[2] => vertical sum is 2
Vertical-3: nodes-[1,5,6] => vertical sum is 1+5+6 = 12
Vertical-4: nodes-[3] => vertical sum is 3
Vertical-5: nodes-[7] => vertical sum is 7

When you go left, the column number decreases by 1 and increases by one on going right.

2) Find the top k numbers in a large array

Interview #2:
1) Given a tree, does there exist a path such that the sum all nodes on the path is n
2) Given a set of numbers, transform it to an array such that the value at i is the the product of all numbers other than ai. No extra memory
3) Given a sea with islands, and a starting and end point. Find the shortest path a ship can take from starting to ending, so that it does not travel over land.

Interview #3:
1) Given a log of files, with timestamp-pageid information, find all users who visited on exactly 2 days and visited more than 3 distinct pages
2) You have a two way road and there are two sensors. Sensor S1, runs across only the left side of the road and writes to a log file the times whenever a car passes over it. Keep in mind that, for each car there are two times written to corresponding to the times when the front tire crosses the sensor and then back tire. In addition, there is another sensor S2, that runs across the road. Given that, there is no overtaking, and that all cars are D units long and the distance between the two sensors in K, find the speed of all cars.
3) A general discussion on my previous internship at MSR.

Interview#4
1) Given two linked lists do they intersect. Think hard ! [You can do better than the standard solution for where they intersect]
2) Given two words, transform from one to another so that all intermediate words are valid.

They finally made an offer the next day. :)

Another problem with Hadoop “Job.jar could only be replicated to 0 nodes, instead of 1(IO Exception)”

09/02/26 15:50:01 INFO dfs.DFSClient: org.apache.hadoop.ipc.RemoteException: java.io.IOException: File /user/root/temps could only be replicated to 0 nodes, instead of 1
at org.apache.hadoop.dfs.FSNamesystem.getAdditionalBlock(FSNamesystem.java:1120)
at org.apache.hadoop.dfs.NameNode.addBlock(NameNode.java:330)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:452)
at org.apache.hadoop.ipc.Server$Handler.run(Server.java:888)

at org.apache.hadoop.ipc.Client.call(Client.java:715)
at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:216)
at org.apache.hadoop.dfs.$Proxy0.addBlock(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:82)
at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:59)
at org.apache.hadoop.dfs.$Proxy0.addBlock(Unknown Source)
at org.apache.hadoop.dfs.DFSClient$DFSOutputStream.locateFollowingBlock(DFSClient.java:2448)
at org.apache.hadoop.dfs.DFSClient$DFSOutputStream.nextBlockOutputStream(DFSClient.java:2331)
at org.apache.hadoop.dfs.DFSClient$DFSOutputStream.access$1800(DFSClient.java:1743)
at org.apache.hadoop.dfs.DFSClient$DFSOutputStream$DataStreamer.run(DFSClient.java:1920

Everybody as a beginner to hadoop must have got this. There are a number of reasons I know of. The most common is that you have reformatted the namenode leaving it in an inconsistent state. The most common solution is to stop dfs, remove the contents of the dfs directories on all the machines, run “hadoop namenode -format” on the controller, then restart dfs. That consistently fixes the problem for me. This may be serious overkill but it works.

NOTE: You will lose all of the contents of your HDFS file system.
However, this did not solve my problem on this occasion!

Another reason that may be the cause this problem is that there may not be much space on the namenode for its operation which was precisely the problem which I faced. Clear some space for hadoop to launch its operations and you are done.

Happy Hadooping!! :)

Problem with update to KDE 4.2

Well while updating to KDE 4.2 some of you may have aborted the installation only to find later the following the following error later when you try to open YAST2 or install KDE 4.2 again.

YaST got signal 6 at YCP file SlideShow.ycp:76

/sbin/yast2: line 421: 8383 Aborted $ybindir/y2base $module “$@” “$SELECTED_GUI” $Y2_GEOMETRY $Y2UI_ARGS

You have nothing to worry just key in the following commands
zypper refresh
zypper up -t package -r http://download.opensuse.org/repositories/KDE:/KDE4:/Factory:/Desktop/openSUSE_11.0/
And you are done.

You may probably get the following problem…
could not start kdeinit4
Just update kde4 libs and try to go back to the previous kernel if you are using pae.

Worked for me with SUSE 11.

Follow

Get every new post delivered to your Inbox.