Posts

Showing posts from December, 2017

Answers to number series puzzles

Here are the answers of the post Number series arrangements puzzles. 1. The next number in the series is 16 27 -> abs(2^7 - 27) = 101 101 -> abs(10^1 - 101) = 91 91 -> abs(9^1 - 91) = 82 82 -> abs(8^2 - 82) = 18 18 -> abs(1^8-18) = 17 17 -> abs(1^7) = 16 2. The next number in the series is 13729 8   3 9   9 10  27 11  81 12  243 13  729 3. The missing number in the series is 94310 1   3     2 3   13   4 5   23   6 7   33   8 9   43   10 11 53   12 4. The missing numbers in the series are 37, 37, 40 31 -> 31+3=34 repeat 1 time 34 -> 34+3 = 37 repeat 4 times 37 -> 37+3 = 40 repeat 7 times 5. The next number in the series is 8072 5        8 10      24 20      40 40      56 80      72

Number series arrangement puzzles

In this post I am going to give the number series arrangement puzzles in which you have to find the next element or missing element in the series of numbers given. These questions are an important part of any technical interviews where interviewer wants to check how fast you can think and deduce connections between numbers. 1. What is the next number in the series? 27  101  91 82 18 17 __ 2. What is the next number in the series? 83  99   1027    1181    12243  __ 3. What is the missing number in the series? 132   3134    5236    7338   __   115312 4. What is the missing numbers in the series? 31 34 __ 37 37 __ 40 40 40 __ 40 40 40 5. What is the next number in the series? 58   1024   2040    4056   __ Click  here  for answers

Answers to the most common puzzles in Interviews PART-3

Here are the answers for my last post of Common puzzles in Interviews. 1. Planes will not collide if they all move in same direction (Clockwise or AntiClockwise). So each plane has 2 choice , either clockwise or anticlockwise. So for all the planes we will have 2^5  possibilities. Below are the possibilities for all five planes where C denotes Clockwise and A denotes AntiClockwise CCCCA CCCAA CCAAA : : : : CCCCC : : : AAAAA : : AAAAC So in all we have 32 possibilities and out of those 32 only 2 possible combination (AAAAA & CCCCC) will not result into collision. So probability of planes not getting collide is 2/32 = 1/16. 2. The next number in series is 23. 2 11 -> 2+(1+1) = 4 4 15 -> 4+(1+5) = 10 10 13 -> 10+(1+3) = 14 14 18 -> 14+(1+8) = 23 3. So in one day the net time increased is 1/2 - 1/3 = 0.17 minutes . Clock will become 5 minutes faster in 0.17 * days = 5 days = 5/0.17 = 29.4 days ~ 30 days. So the date will be 30th of May

Some common and most frequently asked puzzles in Interviews Part-3

In this post I will include some more puzzles asked in Interviews very frequently. This is specially for the young graduates who are going to give Interviews in Campus placements. 1.  Five planes are circling near the Airport in such a way that they form pentagon. Assume each plane at the vertices of pentagon and moving. In what ways planes should move such that no planes collide with each other. What is the probability that planes doesn't collide? 2. What is the next number in the series? 2  11  4  15  10  13  14  18 __ 3. In Sahara Desert there is some random house and has One clock in the house. The clock is temperature sensitive. At night it becomes 1/2 minutes fast when it is cold and in day it becomes 1/3 slow when it is hot. We set timing of clock on 1st May. On which date the clock becomes 5 minutes faster? 4. What is the next number in series? 1/5  5  3/6  216  6/2  64  4/4  __ Want some more Number series arrangement puzzles? Click  Here 5. You are Trave

How to parse string into tokens in JAVA?

There is need of breaking strings into tokens from time to time for the JAVA programmers during the development.                   One such example is sending commands to server from console. So you may want to take whole command as String and then perform actions for that command by looking at the first word of string. Suppose, you want to modify the port at which server is listening. So you pass the below command to server from console. Command: modify port 1200 to 1400 So to perform the actions for this command, you can fetch the first word of the string as token and then write your logic of modifying the port. JAVA has class called StringTokenizer which allows to break string into tokens. StringTokenizer methods does not differentiate between identifiers, numbers and quoted string. You can also specify the delimiters during the creation of StringTokenizer or on a per token basis. Usage: String command = "modify port 1200 to 1400" StringToke

What is ConcurrentHashMap in JAVA?

ConcurrentHashMap has same functional specifications as  HashMap and it includes version of methods corresponding to methods of HashMap. Checkout  What is HashMap in JAVA . It can be seen as Hash Map which supports full concurrency of retrievals ie it allows concurrent modification of map using several threads without the need of blocking them. ConcurrentHashMap will only lock the portion of the data while other portion of the data being used by multiple threads.                   Lets take a situation when we are using HashMap and trying to modify the data without using the iterator to modify it Code: RemoveData.java public class RemoveData{ Public void remove (int p){ HashMap<Integer, String> map = new HashMap < Integer, String>(); map.remove(p); } } ConcurrentRemoval.java public class ConcurrentRemoval{ public static class RemoveStuff{ public void removeStuff(){ RemoveData rd =  new RemoveData(); HashMap<Integer, String> hashMap

how to parse xml file in JAVA?

In this post I am going to show how we can parse the xml file in java and fetch the details present inside xml in our JAVA program. It can be helpful where you have large data and does not want to take input from user for the data. Parsing the JSON for data is better technique than xml parsing , but xml parsing is helpful when we dont want to use third party library in our project, because we have JAVA classes to parse the xml file.                   We can parse the xml file using DOM parser, which treat xml tags as nodes of the tree and parse it node by node. details.xml <?xml version="0.1"?> <employee> <manager> <firstname>Walter</firstname> <lastname>White</lastname> <SSID>12345</SSID> <Phone>123456789</phone> </manager> <manager> <firstname>Jesse</firstname> <lastname>Pinkman</lastname> <SSID>54321</SSID> <Phone>987654321&

Client and Server Message exchange JAVA

In this blog post i will be providing a simple program and its explanation about the Client and server communication using sockets in JAVA. We are going to use 2 streams (Input and Output) for the client and for server to read and write data from and to console. We will create client.java which opens a socket using hostname and port and talk to server using the Input and output streams. And then we will create Server.java and create a server socket using the same port and read message from client input stream and write the modified message to client output stream.                   Below is the program for Client and Server message exchange. Client.java public class Client {     public static void main(String args[]){         try {             String host = "localhost";             int port = 1200;             Socket socket = new Socket(host, port);                           //Open the output stream of client to write the message.