# 7T

Android Developer interview questions shared by candidates

## Top Interview Questions

Sort: Relevance|Popular|Date
Android Developer was asked...21 May 2015

### Given an array of ints = [6, 4, 0, 5, 0, 0, 0, 1, 0] move all non zero numbers to the left and zeros to the right. How can you now improve your answer to O(n)?

Just keep pointers to the first and last elements of a new array. private static int[] moveZerosToLeft(int[] arr) { int first = 0; int last = arr.length - 1; int[] newArr = new int[arr.length]; for (int i = 0; i &lt; arr.length; i++) { if (arr[i] == 0) { newArr[last--] = arr[i]; } else { newArr[first++] = arr[i]; } } return newArr; } Less

Since the order doesn't matter. Keep a separate pointer for your array. iterate through the array, for every 0 you find, swap it with the value at array[k], then increment k. This would be O(n) Otherwise, just sort it and return that. Which is O(nlogn) Less

O(n) is the best conceivable time for this type of sort Here's one way to solve it: private static void moveZerosToRight(int[] a) { int rightIndex = a.length - 1; int leftIndex = 0; while (leftIndex &lt; rightIndex) { if (a[rightIndex] == 0) rightIndex--; else { if (a[leftIndex] == 0) { swap(a, leftIndex, rightIndex); rightIndex--; } leftIndex++; } } } private static void swap(int[] a, int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } Less

### 1.Given a string, write a function that return if it is Palindrome. This wasn't asked directly but from interviewer example i was need to understand that this function must ignore all spaces and special symbols. 2. Given an array, write a function that return true if any 3 elements of this array can sum to 0. My first solution was the simplest and far from best which result in O(n^3). Then interviewer asked me to improve to improve it to O(n^2). This give me a hint that i can use Hash to reduce complexity.

As I wrote I used HashSet to store all values so I can for every pair of numbers check if there is negative one in HashSet istead of thrid for so overall complexity will be reduced to n+n^2 which is O(n^2) Less

How do you know you are not using the same number twice? for example: {2,-1,0} you will sum 2+(-1)=1 and search in the hash for (-1) which you will find but you already used it. Less

Ignore my previous answer, copy and paste issue. Time complexity is O(n^2) private static boolean hasThreeElementsSumUpToZero(int[] a) { HashMap cache = new HashMap(); for (int i : a) { if (cache.containsKey(i)) { cache.put(i, cache.get(i) + 1); } else cache.put(i, 1); } for (int i = 0; i 1) return true; } else if (cache.containsKey(target)) return true; } } return false; } Less

### 1.What is latest version of android and whats the new features for developer 2 .Difference bw paracables and serializable 3. what is build.gradle 4.how to switch bw fragment to activity 5. methods of adapter 6. what is request body parameter in network call 7. how we can do migration in room db

Pie (Android 9) API level-28 Upcoming Version Q (Android 10) API level-29

2.Ans In Android we cannot just pass objects to activities. To do this the objects must either implement Serializable or Parcelable interface. Serializable- Serializable is a standard Java interface. You can just implement Serializable interface and add override methods. The problem with this approach is that reflection is used and it is a slow process. This method creates a lot of temporary objects and causes quite a bit of garbage collection. However, Serializable interface is easier to implement. Parcelable- Parcelable process is much faster than Serializable. One of the reasons for this is that we are being explicit about the serialization process instead of using reflection to infer it. It also stands to reason that the code has been heavily optimized for this purpose. 1.Parcelable is faster than Serializable interface 2.Parcelable interface takes more time to implement compared to Serializable interface 3.Serializable interface is easier to implement 4.Serializable interface creates a lot of temporary objects and causes quite a bit of garbage collection 5`Parcelable array can be passed via Intent in android Less

3.Ans. Gradle is a build system (open source) which is used to automate building, testing, deployment etc. “Build.gradle” are scripts where one can automate the tasks. Less

### Write a function that would calculate a Pascal triangle element, given its coordinates.

Generally Pascal's triangle is considered to be 0-indexed, as it is based on combinations. public long Pascal(long n, long r) { if (r &gt; n || r n) return Pascal(n, n - r); if (r == 0) return 1; return n * Pascal(n - 1, r - 1) / r; } Less

private static int nCalc(int n,int k){ return factorial(n) / (factorial(k) * factorial(n-k)); } private static int factorial(int f){ int retval = 1; for (int i=1;i&lt;=f;i++){ retval*=i; } return retval; } Less

public static void main(String[] args) { int r = 5; for (int i = 1 ; i &lt;= r; i ++) { int c = 1; for (int j = 1; j &lt;= i; j ++) { System.out.print(c); c = c * (i - j) / j; } System.out.println(); } } Less

### (this is a little easier to explain if it's drawn out, but I'll try my best to do it here) Given some integer N = 2^k which represents an NxN matrix, write a function that fills the matrix with 'L' shapes, such that the entire matrix is filled except for 1 empty space. For example, a 2x2 matrix would have 3 spaces filled with one of the corners empty. And a 4x4 matrix would have the entire outer row of spaces filled, with the center 4 filled the same way the 2x2 matrix is filled.

No. The smallest thing you're allowed to enter into the graph is an L shape. Forget about the fact that the L shapes filling the graph are represented by bits, because you aren't allowed to fill it in that manner. Also keep in mind that only 30 minutes was given to solve the problem. Less

Do you know in how many days they give the result if one goes through all rounds? Less

Less than a week I believe

### Since i have a working experience of 1 year and 3 months, i was told to join as a Fresher, because i haven&#039;t worked professional working experience in Android Development. And for a fresher, salary is quite less as you can expect. But at the end of the day, you are getting paid while you are at learning stage. Should be enough for a fresher only.

Dude, When you will join them they will say work free for next three month and buy mac book. I think that was one of worst company I worked in my career. Rest is your decision. You can get better job, than this. Parag will tell after one month that "I am not here to full fill my promise". Less

Is it true that one has to buy a MAC with their own money, otherwise considered unworthy? Also, how much is the pay for a fresher? Less

Considering that the Android development is a growing field, i wanted to work on it as a professional FTE. And for that, i compromised with my salary package. Less

### Typical Android Layouts (What's the best way to lay element vertically etc.). Android Lifecycle. LinkedList vs Arrays.

Yes, the answer is (obviously) a Vertical LinearLayout. I had a bit of a brain fart and called it a Linear ListView, which is incorrect. Less

Hello Michael, Have you been in a FB's interview before?

Hi, Yes, I'm the original poster - I got the phone screen but did not go to the next round unfortunately. Less

### Your photo-sharing app displays a system notification when the user receives a photo. Your app should display the photo when the user taps the notification. Which of the following do you need to attach to the Notification object that you pass to NotificationManager? A. An Activity reference B. A PendingIntent C. A BroadcastReceiver D. A Fragment transaction

A.Pending Intent

B. A Pending Intent

### Why are you jumping from the previous company?

Too much work pressure and I have to work during all of the Sundays in the calendar. No leaves from the company itself and even in the case of a leave, they'll cut our pay. So I'm looking for a much better company. Less

Thank you for sharing your wonderful experience.Infact I think you would be the first person complaining about your own current working company to an interviewer which openly reveals your attitude..As far as my knowledge if you do not have a nice attitude towards your company whatever your company’s approach towards you, you will not be hired anywhere.Try this next time.I have had a nice experience with them.Anyway thanks for sharing the info. Less

I got a job elsewhere with much better pay and management. So no issues

### Create an app fetching car details from a server and showing them in a list. Then localize hem in a google map. Also showing all the cars in the map as pins

Project created

How you created the app? What sort of ui and code organisation you adopted that satisfied mytaxi team ? I did created the app with was functional as per their requirements but certainly that was not what they are looking for please let us know Less

Did you use unit tests in your code?