## Aspire

BAN USER- 1of 1 vote

AnswersGiven a array of positive integers, find all possible triangle triplets that can be formed from this array.

- Aspire in United States

eg: 9 8 10 7

ans: 9 8 10, 9 8 7, 9 10 7, 7 8 10

Note : array not sorted, there is no limit on the array length| Report Duplicate | Flag | PURGE

Linkedin SDE1 Algorithm - 0of 0 votes

AnswersIn basket ball game for a player to win a game

- Aspire in United States

challenge 1) 2 out of 3 throws should be basket

challenge 2) 4 out of 6 throws should be basket

which challenge should the player choose so that he might have better chance of winning the game?| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer - 1of 1 vote

AnswersIn basket ball game for a player to win a game

- Aspire in United States

challenge 1) 2 out of 3 throws should be basket

challenge 2) 5 out of 8 throws should be basket

which challenge should the player choose so that he might have better chance of winning the game?| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Probability - 1of 1 vote

Answers

- Aspire in United States`Given a String s and a hashmap containing certain decodings for all the characters of alphabet. Find all possible passwords that can be generated by replacing decodings in the string s. Note that decodings of a charachter can only be single charachters Eg: String s="abcde" decodings given a-{1,2,p,o,q} b-{2,y} c-{p} d-{4,a,m,n} e-{9,z,x} h-{1} ' ' ' x-{0} y-{4,k,l} z-{r,5} So possible set passwords will be abcde,1bcde,2bcde,pbcde,obcde,qbcde, //replace a with all possible decodings a2cde,12cde,22cde,p2cde,o2cde,q2cde,aycde,1ycde,2ycde,pycde,oycde,qycde //replace b will all possible decodings a2pde,12pde,22pde,p2pde,o2pde,q2pde,aypde,1ypde,2ypde,pypde,oypde,qypde.....//replace c will all possible decodings`

| Report Duplicate | Flag | PURGE

Amazon SDE1 Algorithm

10 , 9.5 , 9 , 8 , 5 , 2,0.5

int getAllTriangles(int input[])

{

if(input.length<3)

return 0;

int count=0;

sort(input); //assume merge sort

for(int i=0;i<input.length-2;i++)

{

for(j=i+1;j<input.length-1;j++)

{

int index=BinarySearch(input,j,input.length-1); //returns the index of that number

if(index!=-1)

count=count+index-j;

}

}

}

int BinarySearch(int input[],int low,int high)

{

if(low>high)

return -1;

int k=input[low]-input[high];

int mid=(low+high)/2;

if(k<input[mid] && k>=input[mid+1] && mid+1<=high)

return mid;

else if(k<input[mid-1] && k>=input[mid] && mid-1>=low)

return mid-1;

else if(k<input[mid])

return BinarySearch(input,mid+1,high);

else

return BinarySearch(input,low,mid-1);

}

Your algorithm seems partly right. Could you please elaborate in the form of a pseudocode. I believe i,j,k all three can be iterated over the array. So TC is O(n^3) right? My approach was on similar lines but i was doing a binary search to find the 3rd element. The TC I got then was n^2logn. Anyone with a better and simpler approach?

- Aspire November 25, 2014Here is my solution:

char getSmallestLarge(char [] list,char c)

{

SmallestCharacter sc=new SmallestCharacter();

return sc.BinarySearchChar(list,c,0,list.length-1);

}

char BinarySearchChar(char[] list,char c,int low,int high)

{

if(low>high)

return ' ';

if(high-low+1==2)

{

if(list[low]<=c && list[high]>c)

return list[high];

return list[0];

}

if(high-low+1==3)

{

if(list[low]==c)

return list[low+1];

if(list[low+1]==c)

return list[low+2];

if(list[low]<c && list[low+1]>c)

return list[low+1];

if(list[low+1]<c && list[low+2]>c)

return list[low+2];

//default case

return list[0];

}

int mid=low+high/2;

if(list[mid]==c)

return list[mid+1];

else if (list[mid-1]<c && list[mid]>c)

return list[mid];

else if(list[mid]<c && list[mid+1]>c)

return list[mid+1];

else if(list[mid]>c)

return BinarySearchChar(list,c,0,mid-1);

else if(list[mid]<c)

return BinarySearchChar(list,c,mid+1,high);

return list[0];

}

Rep

Rep

Rep**leroydperry**, Backend Developer at AppNexusI am from the USA. I am 27 year old. I drive the train for my company Monk Home Funding ...

Rep**suejnagel**, Virus Researcher at Email Customer ServiceHello, I am Sue . I am a chief information officer at Vernon. I am responsible for providing the global communications ...

Rep**sharoneruther**, AT&T Customer service email at ABC TECH SUPPORTI am Sharon, from Bethlehem USA. I am working as a Park naturalist in Sammy's Record Shack company. I ...

Rep**taniajclover**, Analyst at AmdocsHi, I am Tania from Tuckahoe USA, I am working as a Public relations representative in Gamble-Skogmo company. I like ...

Rep**jesselblagg9**, Cloud Support Associate at 247quickbookshelpHello, I am Jesse and I live in Springfield, USA. I am working in a company as an engineering technician ...

Rep**barrietrosado**, abc at ABC TECH SUPPORTHi, I am Barrie, from Ualapue USA. I believe that every challenge has a solution - and I take great satisfaction ...

Rep**mariawharris2**, Computer Scientist at Adjetter Media Network Pvt Ltd.Hi I am an IT Project Management Professional with 2 years' experience,Handled project development and documentation of copier rentals ...

RepHi, I am Anne from Portsmouth, USA. I have been working as a freelance digital illustrator specialized in 3D character ...

Rep**marywwaldrop7**, Computer Scientist at Chelsio CommunicationsI am Mary ,working in the field of training and development coordinator for three years, focusing on teaching English as ...

Rep**garycsroka**, Backend Developer at Axiom SourcesHi I’m Gary, an average 19 year old in a state college who sees life as an adventure.Provide ...

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

This is brute force right?

- Aspire November 26, 2014