1) Fibonacci in Java:
The input will be number n and the output should be sum for 0 to n. for example
for n =4 the result should be 0+1+2+3+4 = 10
2) String Reverse
The input String "abcde" should return "edcba".
3) Reversing a linked list in Java
Here is example of revering the linked list in java using recursive function:
4) Find the missing number in Java
You have an array of numbers from 1 to 100 (both inclusive). The size of the array is 100. The numbers are randomly added to the array, but there is one random empty slot in the array. What is the quickest way to find that slot as well as the number that should be put in the slot?
Try it for practice. please suggest the answer .
[Trick sum of n numbers is n*(n+1)/2]
5) Write a substring function in Java
String test= "AA BB CC BB BB CC BB";
String[]{"BB", "CC", "AA"}
Result shd be BB=4; CC=2 and AA=1
Since B occurred 4 times C did 2 times and A only 1 time.
This basic problem can be asked in different ways like, You have multiple words in new paper and find out the frequency of words in one page of news paper?
6) Reverse a String in Java
Reverse the String by java function without recursion and with recursion
7) Find one string inside another in Java
We can use String.indexOf( subString ) and it will return the first index of substring;
for Last Index : lastIndexOf(String str)
8) Algo for finding largest number in Array of Integer
Easy one, Check the integer one by one and find the largest number.
9) Java Runtime method invocation question:
Example : Tell the output of this
Answer is : 20 .
10) Suppose you have a large file with lots of words. How would you find the unique words and their count? What kind of data structure u will use? What will be the time complexity and space complexity?
We need to take care of two things counting the words and second duplicate. the best performance will be using hash function.
11) A train is one mile long. It travels at the rate of one mile a minute through a tunnel which is also one mile long. Can you say how long it will take for the train to pass completely through the tunnel?
Answer : 2 minutes
it will take two minutes if you count the time for it to completely pass through the tunnel. One minute to pass through the tunnel and another one minute to drag itself out of the tunnel completely so two minutes nice question though well logical.
12) Convert String = "98989" into an integer without using any library functions in java.
Give fastest way to do it and explain why your method is best.
// converting string to number using ascii code
13) Write a program to shuffle a deck of 52 cards and shuffle them equally to 4 players.
Answer this puzzle by comments.
Given n stairs, how many number of ways can you climb if u use either 1 or 2 at a time?
for example you have 4 stairs and you can climb like
1,1,1,1
1,1,2
1,2,1
2,1,1
2,2
so in overall 5 ways for 3 stairs.
nice blog thanks company jobs
ReplyDeleteHello There,
DeleteSmokin hot stuff! You’ve trimmed my dim. I feel as bright and fresh as your prolific website and blogs!
I’m using log4j, in a program there are different inputs, in each thread.
I had added logging in program.
I need log file for each thread.
How to log each thread in separate file through log4j.
In complex or multi-tier applications, a proper attack strategy needs to be developed in order to identify performance bottlenecks. For example, sometimes tuning JDBC configuration improves the performance.
I read multiple articles and watched many videos about how to use this tool - and was still confused! Your instructions were easy to understand and made the process simple.
Grazie,
Kevin
The problem statement of "4) Find the missing number" is vague, could you please refine / clarify it?
ReplyDeleteIn Java 1.6 uses the Generics.....to put like this
DeleteSet numberSet = new HashSet();
In java using the generics
Deletepackage com.bangalore;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
public class MissingNumber {
public static void main(String...strings){
Set num = new HashSet();
// Max number in the sequence
int k = 50;
// put the numbers
for(int i=0;i<=50;i++){
num.add(i);
}
// Remove random number
int i = (new Random()).nextInt(50);
System.out.println(" Removing number -->"+i);
num.remove(i);
// find the current sum
int sum =0;
for(int m : num){
sum= sum +m;
}
// Find the missing number
int l = ((k)*((k+1))/2)- sum;
System.out.println(" Missing number -->"+l);
}
}
The first example seems different from fibonacci series. If It is 0+1+2+3+4 +.. n
ReplyDeleteShouldnt it be
private static int getSeriesResut(int n) {
int sum = 0;
for (int i = 1; i <= n; i++) {
sum = sum + i;
}
return sum;
}
This comment has been removed by the author.
DeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
DeleteFor Fibonacci Series ... using iteration seems to be much more performant than recursion.
ReplyDeleteBoth methods are compared here: https://gist.github.com/josseyj/9062009
the card suffling example will give the same result every time you run it as you are neither suffling the deck nor using the temp variable.
ReplyDeleteadding Collections.shuffle(deck) would sufficce for your example
Very Intresting Blog...
ReplyDeleteSEO packages San Francisco
Hi,
ReplyDeleteVisit sanfranciscowebstudio.com for best web design, web development , SEO services and internet marketing services. Please Visit SEO services San Francisco
Thank you for this Information !!
ReplyDeleteLINUX INTERVIEW QUESTIONS
Linux FTP vsftpd Interview Questions
SSH Interview Questions
Apache Interview Questions
Nagios Interview questions
IPTABLES Interview Questions
Ldap Server Interview Questions
LVM Interview questions
Sendmail Server Interview Questions
Read more at Linux Troubleshooting
Very Nice ... visit more java interview questions
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteInterview Puzzles
ReplyDeleteQuestion 9:
ReplyDeleteIt has compilation errors.The methods add in base and derived class have return type void.
this is nice article about java basic programs .
ReplyDeletethanks
Banner stands and portable displays are versatile, powerful marketing tools. Maximize your success at your next trade show by following these simple steps.Seo Services San Antonio
ReplyDeleteGood Collection I do not know Why you have not given these JAVA Puzzles (Almost All Companies Ask these)
ReplyDeleteYou can read from here
http://codinginterviewquestionsans.blogspot.com/2018/03/java-puzzles-expressive-puzzlers.html
Really something Grate in this article Thanks for sharing this. We are providing Online Training Classes. After reading this slightly I am changed my way of introduction about my training to people.
ReplyDeleteBest Linux training in Noida
Linux Training Institute in Noida
Shell Scripting Training Institute in Noida
good content man
ReplyDeleteIt is so nice blog. I was really satisfied by seeing this blog.
ReplyDeleteworkday training
workday online training
workday course
Find Missing Number Java simple code ::
ReplyDeletepackage Code_brush_Up;
import java.util.Scanner;
public class FindMissingNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int arr[] = new int[n-1]; //the length of the array should be n-1
for(int i = 0;i<arr.length;i++){
arr[i] = sc.nextInt();
}
int totalN = n*(n+1)/2; //to find the sum of 1 to n
int totalArrSum =0;
for(int i = 0;i<arr.length;i++){ //to find the sum of all element in array
totalArrSum += arr[i];
}
int diff = totalN - totalArrSum;
System.out.println("Missing elemtn is "+diff);
}
}
Mastering math doesn't have to be a daunting task. math games 66 has redefined the learning experience by making it fun and engaging. Whether you're a student looking to enhance your math skills or an adult wanting to refresh your knowledge
ReplyDelete