Sunday 13 August 2017

Write a program in java to do addition between two Linked List

One of my friends had faced this question during his interview with Nokia R&D. you will be given two Linked List and you need to find out the sum between them.
For example, we have two LinkedList L1 and L2

L1    2->5->7

L2    3->5->1

So output would be:
L3 5->0->9

Logic: I have solved this problem using Iterator and while loop. I have taken a carry variable which keeps track between addition of two nodes.



Output:



Saturday 12 August 2017

Write a program in JAVA to left rotate of an array.

This is a common interview question in java. You will be given an array and a number(k) which needs to be rotated.
for example, consider we have an array rotate[]={1,2,3,4,5}; and given input no is: 3.
Output will be: rotate[]={4,5,1,2,3}.

Logic: we will take two arrays, i,e temp and finalArray. Temp array will contain only those elements  upto K. After that we will merge temp array to finalArray.




Output: