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 StatesGiven 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
Repleroydperry, Backend Developer at AppNexus
I am from the USA. I am 27 year old. I drive the train for my company Monk Home Funding ...
Repsuejnagel, Virus Researcher at Email Customer Service
Hello, I am Sue . I am a chief information officer at Vernon. I am responsible for providing the global communications ...
Repsharoneruther, AT&T Customer service email at ABC TECH SUPPORT
I am Sharon, from Bethlehem USA. I am working as a Park naturalist in Sammy's Record Shack company. I ...
Reptaniajclover, Analyst at Amdocs
Hi, I am Tania from Tuckahoe USA, I am working as a Public relations representative in Gamble-Skogmo company. I like ...
Repjesselblagg9, Cloud Support Associate at 247quickbookshelp
Hello, I am Jesse and I live in Springfield, USA. I am working in a company as an engineering technician ...
Repbarrietrosado, abc at ABC TECH SUPPORT
Hi, I am Barrie, from Ualapue USA. I believe that every challenge has a solution - and I take great satisfaction ...
Repmariawharris2, 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 ...
Repmarisamsan7, Cloud Support Associate at ADP
Hi, I am Photoengraver from an CO,USA. I am a girl with a strong desire to travel the world ...
RepHi, I am Anne from Portsmouth, USA. I have been working as a freelance digital illustrator specialized in 3D character ...
Repmarywwaldrop7, Computer Scientist at Chelsio Communications
I am Mary ,working in the field of training and development coordinator for three years, focusing on teaching English as ...
Repgarycsroka, Backend Developer at Axiom Sources
Hi I’m Gary, an average 19 year old in a state college who sees life as an adventure.Provide ...
This is brute force right?
- Aspire November 26, 2014