+2

# 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 https://code.sololearn.com/cuDOdEp6UA6C/?ref=app 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 https://code.sololearn.com/cS1Wc80qSAkY/?ref=app https://code.sololearn.com/ctg8q00Df1xY/?ref=app 3. Simplest one, I was supposed to solve it but couldn't https://code.sololearn.com/cQi0ZA44sQOA/?ref=app 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

+5

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

+3

It is an older code about getting second highest value: https://code.sololearn.com/cPJYw5EI8a4a/?ref=app On which codes are you still struggling?

+3

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

+2

This might be helpful for you to know some new classes and methods that make your life easier. https://code.sololearn.com/cm1BFGUBfgWX/?ref=app

+1

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.. https://code.sololearn.com/c9ueM82F1z40/?ref=app

0

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...

0

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.

0

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].

0

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

-1

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