↳
Consider a single threaded single processor environment. Do you still need a volatile? Less
↳
Volatile keyword is used during multi-threading when you want the threads to edit this variable value. It ensures that the value of the variable is not cached and is stored directly in the main memory. hence, enabling concurrent usage of the variable by different threads. Less
↳
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 < 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 < 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
↳
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
↳
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
↳
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 > 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<=f;i++){ retval*=i; } return retval; } Less
↳
public static void main(String[] args) { int r = 5; for (int i = 1 ; i <= r; i ++) { int c = 1; for (int j = 1; j <= i; j ++) { System.out.print(c); c = c * (i - j) / j; } System.out.println(); } } Less
↳
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
↳
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
↳
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
↳
A.Pending Intent
↳
B. A Pending Intent
↳
Pending Intent is the answer, Please Confirm
↳
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