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:

Wednesday 14 September 2016

Write a program in JAVA which accept a String address from user and return true if the address contains pincode at any position and return false if the address does not contain any pincode.

This is another tricky question for the job seekers. Concept is pretty simple here. You have to write a boolean method which will validate the address and return true if it finds PINCODE and return false it does not find.

I am using regular expression to solve this approach.

Sample input:
61 B, Palm Avenue, Joy Bijoy Apartment, 1st Floor, Flat No 1D, West Bengal

Output:
Pincode does not exist.

Sample Input:
61 B, Palm Avenue, Joy Bijoy Apartment, 1st Floor, Flat No 1D, West Bengal 700112

Output:
Pincode exist.

Sample Input:
61 B, Palm Avenue, Joy Bijoy Apartment, West Bengal 700112, 1st Floor, Flat No 1D

Output:
Pincode Exist.

Implemented code:




Sample Output 1:


Sample Output 2:


Sample Output 3:


Tuesday 13 September 2016

Write a method in Java which accepts a String argument and returns a number of words in it

One of my friends asked me to solve this. User will give the input through console and our program will show the total no of words present in the string.
Input: 
hello, Sourin whats up,what are you doing
Output:
No of words: 8

Implemented code:



Sample Output:



Producer Consumer Problem using Multithreading in JAVA

One of my  friends had faced this problem during his interview in Subex. Concept is pretty simple here. We have two threads here. Consumer thread can not consume anything unless and until Producer Thread has produced.

There are couple of ways to solve this problem. Here I am using volatile Stack to solve this.

Implemented Code:







Sample Output:





Sunday 4 September 2016

Write a program in JAVA to print EVEN and ODD numbers within a range using multithreading.

I was asked this question in Nokia Networks. You have to write a Java multithreaded program which will take the input range from user and print those numbers as Even or Odd. 


Sample example:
Enter input range: 5
Odd: 1
Even: 2
Odd: 3
Even: 4
Odd: 5

Here is the implemented code:



























Sample Output:



Saturday 3 September 2016

Java Interview Coding Challanges

 Java Coding is an integral part of JAVA INTERVIEW. If you want to shape your career as a JAVA developer, you will be facing most of java coding challenges which I am going to discuss here. I have faced all of these questions during my java interview with different companies like British Telecom, Edge Verbe, JCPenney, GE, Accenture etc..

I will discuss all of these question one after another in my upcoming blog. I hope that will help you out. To solve these, you should have a basic knowledge on JAVA.

Thanks for following my blog. Happy learning.!!!