Engineer Interview Questions
engineer interview questions shared by candidates
Top Interview Questions
Assume a matrix of integers they are sorted in boh row and column vice .. how do u find a given number from the matrix in a optimal way? 10 AnswersLet the matrix is n*m matrix. Then O(n log m) solution is trivial (binary search in each row). There is a easy O(n+m) solution too. The idea is to start from upper right corner (mat[0][m-1]) and traverse toward lower left corner (mat[n-1][0]). On the way check each entry and depending on whether larger go left or down. If there is a solution you will find it on the way. Or you will arrive to a point where you can no longer move without going out of the matrix. Either way you will check at most O(n+m) entries thus the solution in O(n+m). I think it could be done even better than in O(n+m). Instead of starting at the upper right corner do a binary search on last column and find the biggest element that is still smaller than the given number. Say it's gonna be A[i, m-1]. Now we could throw away all rows up to an including i (since A[i, m-1] is larger than all of these elements) and the last column. Repeat everything for a smaller matrix of size (n - i, m - 1); To elaborate a little on dp's idea and add my take on it I would do a binary search on the last column to find the interval where the number is in. This interval will be one row within the matrix (assuming the value is not in the last column) and to find the interval should be O(log n). Then I would do a binary search on the row that remains which should cost O(log m). Combined that would be O(log n) + O(log m). Let me know what you guys think of this solution. Show more responses Anonymous, consider the matrix and you are searching for 9. Using this new algorithm we would look at rows 2 and 3 since 8 < 9 < 10 and completely miss 9 in the last row. (1 3 5 7) (2 3 6 8) (3 5 8 10) (6 9 11 12) dp, what do you do if the first element in the last column is already larger than the target? I.e. there may be no number that is smaller that the target. You could throw away that column, but that's it, I think. If so, the worst case becomes O(m). What if you did a binary search on the diagonal.... A better solution than O[log(mn)] is unlikely. An mxn array can be laid in memory as a m*n one dimensional array at its base form. So a matrix sorted by row and column simply means this mxn one dimensional array is sorted. A binary search will get you the result in O[log(mn)], that is the fastest solution available. How about this. for m columns - do binary range_search. As in, start with m/2 th column, if the number is in this range...col(0) O (log(m+n)) oops, there is a catch.... If the number is in a range, it can be in that column, or any of the columns towards left of it....and in some cases, if its in the range.. it can still be on any columns on right..... need to tweak a bit more. Ok writing this 3rd time , no one will see this but for the sake of it, Using radix sort Take 10 buckets and enter all numbers respectively. For example all numbers unit digit with 9 will in 9 number bucket. Just divide the given number (input) and into parts , using mod operator. And using the divided number"s unit digit find that index in the bucket. Tada . Radix sort way the. Linear search way to find the number Complexity O ( n ) Phew |
out of 25 horses select the fastest three in minimum number of races where in each race there would be exactly five horses. 10 Answers6 races i think it could be 6 races... first five races taking 5 horses each,and then the 6th ace taking the 1st horse of each of the previous race,den select the fastest three among them. would be 5 races if a stop watch is given..... however solutions given before are wrong since the horse coming 2nd in the first race might be faster than the horses that come first in the subsequent race :) hence we have to assume that a timer is provided Show more responses umesh no timer has been provided and it would be 7 races :) 11 races First 5 races taking 5 horses in each race. Next 5 races taking in each race horses which have come first, horses which have come second, third, fourth and fifth....... Final 11th race out of 5 which have won in second set of races to find fastest 3 6 Race would be wrong answer. What if in one group all the 5 horses are fastest of all others. Then from first round of 5 races we might lose those 2nd and 3rd ones. My answer is also 11 Races. Round one - 5 Races -------------------- Including all 25 horses. 5 each race. Left with -> 15 horses [Take 1st,2nd & 3rd from each race. Which would be total of 5*3=15 horses.] Round two - 3 Races [ Grouping any 5 of 15 horses left] ------------------- Left with -> 9 horses [Take 1st,2nd & 3rd from each race. which would be total of 3*3=9 horses.] Round three - 1 Race. ---------------- Take any 5 horses of 9 horses left Left with -> 7 horses 3 (1st 2nd and 3rd) + 4 (remaining ones) = 7 horses Round four - 1 Race. ---------------- Take any 5 out of 7 Left with -> 5 Round Five - 1 Race ---------- Race of 5 horses left 7 races: Split the 25 into 5 groups and make them race, this would be 5 races. Take the fastest horse of each group and make them race (6th race). Let's label the initial group of the top 3 horses of the 6th as a, b, c. The possible candidate for the 3 fastest are: a[1], a[2], a[3], b[1], b[2], c[1] We just need one last race to determine the top, the race would be between a[2], a[3], b[1], b[2], c[1]. The final result is a[1] then the top 2 of the 7th race. Easy: Correct answer is 11 but much easier method: 1. One race among 5 horses to find the fastest 3. 20 horses left not raced yet. 2. Now keep the 3 fastest horses you found and add two other horses out of 20 horses left to the race, again select the fastest 3. 3. Keep doing this for all 20 horses by selecting 2 of the horses left to race against the fastest 3 always. 1 race (to find the fastest 3) + 10 races (20/2 races to test all other 20 horses) = 11 races Constant Time - 7 Races 5 Races among 5 each. 6th Race for all third place holders 7th Race for Winner of sixth race +two people who defeated him in 1st race + two people who defeated the second place winner in 6th race. Best Case - 6 Races (3 place winner of 1st race against other 20 and he wins all the time) Worst Case - 11 Races( Make the fastest 3 of each race run against the other 2 each time) |
10 people can share a bucket of coins equally. A monkey steals one coin. The no of coins are one less than equal share. one person after the other tries to take the coin but monkey kills them(killing spree?? :-)). each time a person dies the no of coins are always one short of equal share. what were the no of coins originally?. 12 AnswersI wont give the answer. Hint : know who divides you ;-) if monkey steal one coin then as per your ans coins==9. then one person dies so 9%9 is==0. which is not possible. it is not 20 also just to give a bigger hint.:-) Show more responses Exact answer is 30 coins. Since each time monkey kills one person. This is correct for 10 coins as well suppose initial coins were 30 then money steals one coin so #coins = 29. now 10 people are there and the no of coins are 1 less than equal share i.e if 30 coins were there 3 per person but only 29 coins are there. so this case is ok. lets look for 9 people, since monkey kills one guy. now for 9, 29 is not one short of equal share because 9*3 ==27 , 9*4 == 36 neither of which satisfy the condition. so 30 cannot be the original coins. same thing for 8,7,6,.. 10 coins cannot be the original. Please read the question carefully.. this hint will be the closest to the answer, keep this part of the question in mind : "each time a person dies the no of coins are always one short of equal share". I think it is 2520 i.e.LCM of 2-10 I think 2520 is perfect sweet:-) nice ans. also think of 10! since the numbers in factorial are the remaining people after each iteration(2x3x4x5x6x7x8x9x10) and they form factors of the factorial number. and the factorial - 1 will always be one less than equal share. this fits the solution:-) Multiples of 2520 will be the answer Yes any Common multiple of the factors is a solution. Answer is pretty simple: m%10=0 -----case 1 Lets assume n=m-1 Since the remainder is always same , when n is divider by any number from 10 to 1.. n%10 = n%9=.........=1 That means n+1 is completely divisible by all numbers from 10 to 1.. (Since it gives common remainder).. n + 1= Lcm of (1 to 10) = 2520 But we assumed n = m-1, so m -1+1 =m = 2520 One or more comments have been removed. |
Java Developer at WebKul was asked...
Write a program for odd input the pattern output will as below n=1 *-* n=3 ***** *** *---* *** ***** 11 Answersimport java.util.Scanner; public class Pattern{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=n;i>=2;i--){ for(int j=1;j<=2*n-(i-1);j++){ System.out.print(" "); } for(int k=1;k<=2*i-1;k++){ System.out.print("*"); } System.out.println(); } for(int i=1;i<=n-1;i++){ System.out.print(" "); } System.out.print("*"); for(int i=1;i<=n;i++){ System.out.print("-"); } System.out.print("*"); System.out.println(); for(int i=2;i<=n;i++){ for(int j=1;j<=n-i;j++){ System.out.print(" "); } for(int k=1;k<=2*i-1;k++){ System.out.print("*"); } System.out.println(); } } } import java.util.*; class Pattern { public static void main(String arr[]) { Scanner input=new Scanner(System.in); System.out.print("enter the "); int n=input.nextInt(); int p=n; for(int i=1;i=1;j--) { System.out.print("*"); } System.out.print(" "); p--; } for(int k=1;k<=n;k++) { System.out.print("_"); } System.out.print(" "); for(int m=1;m<=n;m++) { for(int l=1;l<=2*m-1;l++) { System.out.print("*"); } System.out.print(" "); } } } code for c language #include #include int main() { int n=10,i,j,k,l,m,o; for(i=1;i<=n;i++) { for(j=1;j<=n+i;j++) { if(i==n) { for(k=1;k<=n-1;k++) printf(" "); printf("*"); for(m=1;m<=n;m++) printf(" "); // printf("*"); break; } printf(" "); } for(o=1;o<=2*(n-i)+1;o++) printf("*"); printf("\n"); } for(i=1;i Show more responses import java.util.Scanner; class New3 { public static void main(String ... args) { Scanner sc =new Scanner(System.in); int n=sc.nextInt(); for(int j=n,p=1;j>=2;j--,p++) { for(int i=1;i<=n+p;i++) System.out.print(" "); for(int k=1;k<=2*j-1;k++) System.out.print("*"); System.out.println(""); } for(int i=1;i<=n-1;i++) System.out.print(" "); System.out.print("*"); for(int i=1;i<=n;i++) System.out.print("-"); System.out.print("*"); System.out.println(""); int q=n-2; for(int j=2;j<=n;j++) { for(int i=1;i<=q;i++) System.out.print(" "); q--; for(int k=1;k<=2*j-1;k++) System.out.print("*"); System.out.println(""); } } } import java.util.Scanner; public class Webu { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("enter the no"); int n=sc.nextInt(); for (int i = n; i >1; i--) { for(int j=1;j1){ for (int l =1 ; l <=2*i-1; l++) { System.out.print("*"); } System.out.println(" "); } } } } import java.util.Scanner; public class webu { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("enter the no"); int n=sc.nextInt(); for (int i = n; i >1; i--) { for(int j=1;j1){ for (int l =1 ; l <=2*i-1; l++) { System.out.print("*"); } System.out.println(" "); } } } } import java.util.Scanner; public class webu { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("enter the no"); int n=sc.nextInt(); for (int i = n; i >1; i--) { for(int j=1;j1){ for (int l =1 ; l <=2*i-1; l++) { System.out.print("*"); } System.out.println(" "); } } } } import java.util.Scanner; public class Pattern { public static void main(String ... args){ Scanner sc =new Scanner(System.in); int n=sc.nextInt(); for(int i=0;i import java.util.Scanner; class Pattern2 { public static void main(String a[]) { System.out.print("Enter the Number "); Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=0;i0;j--) { System.out.print("*"); } System.out.println(); } for(int i=0;i for swift answer func designPattern6(number:Int){ for i in 1...((number * 2) - 1){ if i%2 == 0{ print("") }else{ for j in 1...((number * 2) - 1){ if j >= (((number * 2) + 1) - i)/2 && j <= ((number * 2) - i){ print("*", terminator: "") }else{ print(" ", terminator: "") } } } print("") } } n=int(input()) for i in range(n): if(n==1): print("* "*(n+1)) elif(n==3): print( " "*i+"*"*(2*n-1-2*i)) else: print(" ") for i in range(n): if(n==3): print(""*(i+1)+"*"*(n+2*i-2)) |
Java Developer at Naaptol was asked...
written test on basic java you can crack if you are average concept in java. 10 AnswersBut what is the need of exam no result came 2 months have passed i suggest never go and waste your time. you are right . I have never seen any interview experience that got job offer . at every end of year they have walkin drive . Thats look suspicious . At everytime when you go for interview they ask for reference. It might be true that they hire people who have strong refrence what was date of walkin in pune ?? Show more responses There is no way to communicate with them..I tried sending mail to Hemant Jog...bt couldn't ..it says the email account you tried to reach is disabled.something is fishy about this company....not at all trustworthy company.dont attend any walkin drive.they don't give a sht. Yes I got call. May be they call only those people who cracks Aptitude They may have high cut off. Why aren't they answering our calls n mails..... As far as aptitude is concerned.... There isn't any transparency whether they r selecting on scores or through reference.....make everyones results public..so we'll come to know if they have actually considered our apti results or not I attended third round.. Anyone got call for third round?? When you attend the 3rd round and when you gave the 2nd round When you gave the 2nd round and 3rd round? |
Support Engineer at Collabera was asked...
face to face. based on what you say 10 AnswersHi one of my friend attended the same interview and selected but no offer letter yet. Please let me know if you get any information on this... when did you attend? what post is it? my interview was for support engineer and collabera is outsourcing company. once you clear face to face round or cleared. you have to meet them again for training. they wont be sending any offer letters. You just have to go n meet them. Am telling you again they wont send offer letter. you have to go n meet them on the date they told you during your face to face round. After reaching tell them the recruiter name/one who took face to face round. You have to under go training their for 4 weeks and they will again test you based on training (3 chances will be given to you to clear test) and then they place you to their clients and pay roll will be of collabera. Hi, Thanks for reply. the interview is for service desk. They said there will be training for 3 weeks on behalf of HCL. The interview was on April 30.On the day of interview they said that they are going to send an offer letter in 3 days.When we contacted them 10 days later from date of interview,it was told it will take some more time. but its already 48 days Still waiting for offer letter...On your suggestion i will check on the next working day but we are not aware about recruiter name....Please let me know what else we can do. Thank you, Show more responses Go in person and contact them. Tell them that you guys are there for training and they will ask you for contact person and tell the person name who took your interview (name of the person who told you that he will send offer letter). Normally they wont send any offer letters in collabera, they will tell you meet them next week. just tell the name of the person who took interview on that day. If it has been 48 days, then your batch mates who got selected on that day would have undergone training and even be working in HCL :D. DOnt delay go and ask in person and tell them that your their for training( remember saying this when the receptionist asks you and even write the name of interviewer who took interview 48 days back). hi..even i am applied through staffing agency. they trained me and my batch in staffing agency office for 10 days to improve communication skills and the interview conducted on 6/08/2016 with clients(HCL). and waaiting for the result..what if we couldnt clear that interview..and what could be the further process.. you havent mentioned it clearly, if you got selected in collabera and then they provided training for you or you attended some training with other institute? If collabera people are training you, then dont worry even though if you fail they will provide you with 2 chances more within that you have to clear. hi as you said they gave two chances.fist time this july 1st week and second time 2nd week.unfortunately am not selected.do they give one more chance.they gave 4 weeks of trainig on communication Even i dont about 3 or 4rth chance. because i didnt join there and as per the HR he told that he will be giving 2-3 chances and i asked him what if we fail there and he told they will do their best in providing training and testing and we shuld clear itseems. and i think he will provid third chance and if you request him they might give you another one. Could you please help me in understanding the type of employment they offer, I am experience candidate and they are telling me that training have to undergone , what happen if I am not able to clear training according to them and also prospect about job security after i start working on project they mention . FIrst thing, your working for collabera clients not directly the company, training would be based on the profile they hired you for. Even though your experienced you might have to under go training because of clients specs requirements. 3 chance would be given for you i think you have to clear that within 40 days of training. Even am not sure of job security. Firstly u will be working under collabera payroll and after 1 yr, there are chances that you can go to clients payroll (Depends upon client and work you do).. all de best. Drop mail if you need any assistance. all de best |
Senior Software Engineer at Amazon was asked...
You are given a fixed number of 5 rupee, 10 rupee, 20 rupee and 50 rupee stamps. Now given an amount for sending a parcel, you should design an algorithm to come out with the minimum number of stamps that should be used for attaining that amount. For example, if the parcel costed 30 rupees, it could be attained using one 20 rupee stamp and one 10 rupee stamp OR using three 10 rupee stamps OR using one 20 rupee stamp and two 5 rupee stamps OR using one 10 rupee stamp and four 5 rupee stamps OR using two 10 rupee stamps and two 5 rupee stamps. However, the minimum number of stamps is the case of one 20 rupee stamp and one 10 rupee stamp where only two stamps are used. The case where no solution is possible should also be handled, for example, a parcel amount of exactly 33 rupees cannot be attained. 9 AnswersThe solution is attained using dynamic programming. The basic idea is that the minimum number of stamps used for attaining an amount x, is 1+minimum of (minimum number of stamps for attaining x-5, minimum number of stamps for attaining x-10, minimum number of stamps for attaining x-20,minimum number of stamps for attaining x-50). You can try to solve this first by assuming that an unlimited number of 5 rupee, 10 rupee, 20 rupee and 50 rupee stamps are available. And then you can take into account that only a fixed number of these stamps are available. And what is the time involved to get this done? I really liked the question.Simple to read but involves good amount of logic. I ve written down the algorithm but i believe i took more time than i initially thought i would take. I understand what the interviewer is trying to test and I know how to solve it, but what about more realistic scenario where parcel postage cost would be beyond given values like 3 units of currency or 37 units of currency. Show more responses In this specific case, dynamic programming is overkill. There's a better optimal substructure here: The stamp with greatest value less than parcel cost minus stamp values already committed minimize the total of stamps. 1. find the stamp <= cost from highest stamp cost 2. num of found_stamp = found_stamp/cost, rem_stamp = found_stamp % cost 3. Do 1, then 2 until rem_stamp ==0 (done) or rem_stamp < least stamp available (not possible case) In the previous ans, after step 3 if rem_stamp !=0, go back to step 1, find next_stamp < cost (but smaller than value of found_stamp in previous iteration) i=0; boolean solPossible = false; do { if(cost % notes[i] == 0) solPossible = true; else i++; } while(!solPossible && (i void sendParsal(int cost) { int[] avlstm={50,20,10,5}; int i=0; while(cost>=5) { while(cost>=avlstm[i]) { System.out.println(avlstm[i]); cost=cost-avlstm[i]; } i++; } if(cost!=0) { System.out.println("Solution not possible."); } } void Foo(int cost) { if (cost % 5 != 0) Console.WriteLine("Not possible"); else if (cost stampCosts = new List() { 50, 20, 10, 5 }; int count = 0; while (cost > 0) foreach (int stampCost in stamptCosts) if (cost >= stampCpst) { cost -= stampCost; Console.WriteLine("Stamp: " + stampCost); count++; break; } } Console.WriteLine("Count: " + count); } |
Software Engineer at Google was asked...
Can't disclose the exact question because of NDA, but here's some food for thought: 3 can be written as 1+1+1, 1+2, 2+1 4 can be written as 1+1+1+1, 1+1+2, 2+2, 1+2+1, 2+1+1, 3+1, 1+3 Given an integer, how many possible expressions exist? (1+2 and 2+1 are different) 8 AnswersThere are total 2 ^(n-1)-1 expressions exist for any integer to be written on the basis of integers < the given Integer. Like for n=3, total 2^(3-1)-1= 3 expressions. For 4, 7 expressions exist and so on. No f(1) = 0 f(2) = 1 f(n) = Σf(i) + (n-1), where i = 1 to n-1, n>2 Show more responses Ader Lee: Shouldn't it be: f(n) = Σf(i) + (n-1), , where i = 1 to n-2, n>2 (i ranges from 1 to n-2, not n-1) f(1) = 0 and f(i) = i - 1 + sum_{i = 0}^{i - 1} f(i) Writing it down helps to find the sum: f(1) = 0(0) f(2) = 1 + 0(1) f(3) = 2 + 1 + 0(3) f(4) = 3 + 3 + 1 + 0(7) f(5) = 4 + 7 + 3 + 1 + 0(15) The first term(i - 1) equals the number of second terms and the second terms are the sum of 2 powers - 1 from 0 to (i - 2) so f(i) = 2^{i - 1} - 1 Also there is a neat normal form to generate all variations. For the sake of simplicity I show it for i = 4: Start from 1 + 1 + 1 + 1 and for j in 1 to i - 1 add together j and (j + 1) and write down the numbers and mark the added number in the next iteration. | | | 2 + 1 + 1 1 + 2 + 1 1 + 1 + 2 From the marked numbers to (last - 1) run j and do the same as before. The first generates 2 more, the second 1 more and the last one none. gen by first | | 3 + 1 2 + 2 gen by second: | 1 + 3 We could also generate the one element sum(4) from the first one but it's not needed in the problem. Also this representation looks nicer in a tree form but I can only type text here. The marks moved to the begining of the rows since the forum probably has some nice mangling algorithm. I hope you can figure out how the normalisation works. Might post some python code which does this later. a coin change problem with little modification will do . |
Data structures and Algorithms related 2 AnswersIam ready plz tell me which type of question put up in interview |
Software Engineer at Google was asked...
How many rotations does earth make on its axis while going around the sun for one year. 10 AnswersDepends on the Leap Year or non Leap Year 365 for Non Leap Year 366 for Leap Year The question is flawed. It should either ask how many days earth takes in one revolution around sun, or how many days are in a year. The leap year is something imaginary humans have concocted to make the calendars look good. You can't say once is 4 years earth takes an extra day to go around the sun. It's to get you thinking about casting... the calender is a double casted to an int! Show more responses 365.25 / yr I wouldn't say 365/ 366 leap year. Jain has a point.^ It's either 364.25 or 366.25 depending on whether the earth spins in the same direction as it goes around the sun or not (I don't remember which it is and can't deduce it from the information that's available to me without looking it up). Imagine if the Earth did not spin at all on its axis so it would seem as if a year was equivalent to one day. It will take the Earth rotating either 264.24 or 366.25 times depending on the direction to seem like the 365.25 days that it does take. Every year it takes 365.25 rotations but while making calendar we ignore that 0.25 for 3 years and add an extra day in 4th year. <b>365.25 is WRONG!!!</b> Actually <b>Anonymous</b> is right! Just think about this (lay it out on your desk): <ul> <li>How many days would there be if the earth would not revolve around its axis?</li> <li>How many days would there be if it turned once around it's axis?</li> <li>Now do again one, change the direction the earth revolves it's axis, but keep going the same direction around the sun ...</li> </ul> The concrete right answer is 366.25 Here you find details on the exact number (with other proof): :) This question makes no sense. It's other way around, only when earth complete one round, we call it a year. To make human calculations easy, we introduced leap yrs. One or more comments have been removed. |
See Interview Questions for Similar Jobs
- Software Engineer
- Test Engineer
- QA Engineer
- Software Development Engineer In Test
- Senior Software Engineer
- Software Test Engineer
- Software Development Engineer
- Software Development Engineer In Test (SDET)
- Software Developer
- Senior QA Engineer
- Business Analyst
- Analyst
- Quality Assurance Engineer
- Software QA Engineer
- Software Engineer II
- Senior Software Developer
- QA Analyst