Interview questions (Rejected) | Sololearn: Learn to code for FREE!


Interview questions (Rejected)

I was asked to solve these problems recently in a interview for Android Developer. I was rejected for the job. 1. I thought I solved it but solution was only correct for given condition 2. Wasn't able to solve, but had an idea what I needed to do to solve the problem and based on mostly how I implemented these later 3. Simplest one, I was supposed to solve it but couldn't Please do suggest If any solution is still not correct and if there's any shorter or better way of solving these problems.

2/16/2020 7:04:35 PM

Ashutosh Dubey

10 Answers

New Answer


For 1 to 0 and 0 to 1 int a = 0; System.out.println(a ^ 1);


It is an older code about getting second highest value: On which codes are you still struggling?


For second largest don't use sorting, the interviewer is looking for 1 pass algo, so see Denise Roßberg code


This might be helpful for you to know some new classes and methods that make your life easier.


Ashutosh Dubey Yes. I understood. Only 2nd one need time to answer... Integer. MIN_VALUE gives -2147483648. Not 0.... ...... For 2nd. If you don't need to prove by Program, then, Actually, for the 2nd 0ne, is about permutations so, FOR 2 forming substrings, if no.of letter to be formed is considered an n, then n(n-1)/2 is the answer.. For ex a a, in your example, there are 3 a's so 3*2/2=3 If 10 a, then 10*9/2=40 is the answer.... See this..


For 1st problem, I just sort the array in descending order and prints the 2nd element.. 2nd am not understood clearly.. 3rd: Find max and 2 for loops is enough... for(int i=1;i<=max;i++){ for(int j=1;j<=i;j++) System.out.print("*") ; System.out.println();} 4th: !param...


Avinesh Thanks for answering That's the first thing I thought also But as it was an Job Interview I wasn't allowed to use some built in Java classes or methods And also I had to solve it on paper.


Ashutosh Dubey yes I get that. You could have simply used bubble sort and then have printed the second last value in the array like arr[arr.length-2].


Jayakrishna in 2nd you have to print number of times two a's are forming a substring from a given string from left to right For ex. in bbabbbaba Total substrings for any two a's are "abbbaba", "abbba", "aba" So answer is 3 For 3rd You can check my output to get a better understanding of how the output should be For 4th I've renamed the title


The last one can simply be 1 - value wrapped in an abs() function.