Abhi
BAN USER
- -1of 1 vote
AnswersThis is a interview question which needs to be optimized for time.
- Abhi in India
Suppose you have a 2 dimensional Array and you have a String say "Amazon" inside the Array such that the individual characters can be present from Left to Right, Right to Left, Top to down and down to up.
I will explain with example :
char[][] a = {
{B,B,A,B,B,N},
{B,B,M,B,B,O},
{B,B,A,B,B,Z},
{N,O,Z,B,B,A},
{B,B,B,B,B,M},
{B,B,B,B,B,A}
};
The above Array has two Amazon Strings. You need to return the count of number of such strings present.| Report Duplicate | Flag | PURGE
Amazon SDE-2 - 0of 0 votes
AnswersHow can I find if a String exists in a double dimension Array. For eg. Does CAT exist in
- Abhi in United States
'c','b','k'
'd','a','l'
'g','t','i'
It does exist. What will be an optimal way to do it ?
Assume you don't have to move upwards in the Array.
So in the below Array cat does not exist.
'c','b','t'
'd','a','l'
'g','J','i'| Report Duplicate | Flag | PURGE
Adobe Computer Scientist Algorithm - 0of 0 votes
AnswersFind the occurences of each word in a sentence/
- Abhi in India
e.g :
"Hi I am there, am good"
am=2, good=1,Hi=1, I=1,there=1
Print in sorted order as per count.
If count is same, it should be alphabetically sorted.| Report Duplicate | Flag | PURGE
Adobe Android test engineer Algorithm
Store in a HashMap.
Now override the HashCode method for this String Object. HashCode should work on the principle of the sorted value of the Anagram hence all Anagrams will give you the same HashCode value.
Now override the Equals() method and let it work on the basis of the normal String comparison.
Hence all Anagrams are stored at the same Map location in buckets.
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 );
}
Since the Array is of unknown size you cant use Binary search. Use a variation of it. Assume 1st element is 1, if it is not search for the 2nd element, if that is not 1 search for 4th. Like this you search elements at 1,2,4,8,16,32... location till you find the first 1. Assume you find the first 1 at Kth location than you do a linear search from k/2th location till you find first 1.
- Abhi January 28, 2013The obvious hint for this question is Concurrency. Both Single processor/shared memory hint that it is better to divide the tasks into multiple processes and let the OS try to execute them in parallel(single CPU will not let that happen). Depending on the tasks they might or might not execute in less than 8 hours.
- Abhi January 27, 2013The below URL has information on this : In a nutshell it searches all recent tweets with keywords that might become popular and keeps track of retweets etc.
ignitesocialmedia(dot)com/twitter-marketing/trending-on-twitter-a-look-at-algorithms-behind-trending-topics/
Car Parking is constant in Space. A Car comes and you part it. It goes and its place is taken by another car. There is no such thing as shuffling or FIFO so the answer should be Array. Design Pattern ??
- Abhi January 29, 2013