NetApp Interview Question for Member Technical Staffs


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
2
of 4 vote

This problem is given in "Programming Interview Exposed". You can use recursion to solve it. Shamelessly copying the code :)

void doPrintTelephoneWords( int[] phoneNum, int curDigit, char[] result ){
if( curDigit == PHONE_NUMBER_LENGTH ){
    System.out.println( new String( result ) );
   return;
}
for( int i = 1; i <= 3; i++ ){
   result[ curDigit ] = getCharKey( phoneNum[curDigit], i );
    doPrintTelephoneWords( phoneNum, curDigit + 1, result );
     if( phoneNum[curDigit] == 0 || phoneNum[curDigit] == 1) 
     return;
}
}

static final int PHONE_NUMBER_LENGTH = 7;
void printTelephoneWords( int[] phoneNum ){
  char[] result = new char[ PHONE_NUMBER_LENGTH ];
 doPrintTelephoneWords( phoneNum, 0, result );
}

- Abhi January 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 3 vote

Well.. I remember the famous "Prison Break" Breakdown with the question.. ;)
Anyways.. I guess the algo Approach would be Something like this

Vector<char> words[27];

For each element1 in {abc}
For each element2 in {def}
For each element3 in {ghi}
if(dictonary(element1element2element3))
Word[index++]= element1element2element3;
end loop
end loop
end loop

Assuming dictonary is a function returning true if word exist else false.

O(n3).. time compexity.. ;(

- hprem991 January 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Use Recursion. Assume 1 = A,B,C,D,E than your Algorithm will give On^5 complexity.

- Abhi January 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@ Abhi : Recursive solution will also have the same complexity right O(n^5) in the example given by you. But I guess iterative solution will save the extra stack creation "time as well as space".

- bansalnvn January 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If the length of given input is n then complexity of the correct answer for this question will be 3^n not n^3

- sonesh January 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class MobileNumberPadProblem {

	static String[] s = new String[5];
	int n = s.length - 1;
	static int k = 0;

	public static void main(String[] args) {
		s[0] = "abcd";
		s[1] = "def";
		s[2] = "ghi";
		s[3] = "jkl";
		s[4] = "mno";
		combi();
	}

	static void combi() {
		new MobileNumberPadProblem().get(s[0], "", 0);
		System.out.println("\n" + k);
	}

	void get(String s1, String t, int i) {
		for (int j = 0; j < s1.length(); j++) {
			t = t + s1.charAt(j);
			if (i < n) {
				i++;
				get(s[i], t, i);
				i--;
				t = t.substring(0, t.length() - 1);
				continue;
			}
			System.out.print(t + " ");
			k++;
			t = t.substring(0, t.length() - 1);
		}
	}

}

- Rocko January 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
void print(string str[], int in, int l, int len, char arr[], char que[])
{
int i;
if(l==len)
{
for(i=0;i<l;i++)
{
cout<<arr[i];
}
cout<<endl;
return;
}
for(i=0;i<str[que[in]-'0'].length();i++)
{
arr[l]=str[que[in]-'0'][i];
print(str,in+1,l+1,len,arr,que);

}

}


int main()
{
char s[1001],t[1001];
string str[1001];
str[1]="abc";
str[2]="def";
str[3]="ghi";
str[4]="jkl";
str[5]="mno";
str[6]="pqr";
str[7]="stu";
str[8]="vwx";
str[9]="yz";
cout<<"Enter the string";
cin>>s;
char arr[1001];
print(str,0,0,strlen(s),arr,s);

}

- nightswan July 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

void Calculate(int number){
char arr1[3]={'a','b','c' };
char arr2[3]={'d','e','f' };
char arr3[3]={'g','h','i' };
int count =0;
for(int i=0;i<sizeof(arr1);i++){
for(int j=0;j<sizeof(arr2);j++){
for(int k=0;k<sizeof(arr3);k++){
cout<<arr1[i]<<arr2[j]<<arr3[k]<<endl;
count ++;
}
}
}
cout<<count<<endl;

}

- Anonymous January 30, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More