FizzBuzz is a fun game mostly played in elementary school. The rules are simple: when your turn arrives, you say the next number. However, if that number is a multiple of five, you should say the word “fizz” (preferably with a French accent) instead. If the number is a multiple of seven, you should say […]
A commonly asked puzzle at Java interviews is – find the missing number from a series or array of numbers. This puzzle has been asked in Amazon.com. In this Java puzzle, you have a series of numbers start (e.g. 1….N) and exactly one number in this series is missing. You have to write a java […]
Writing a program to calculate factorial in java – can be a coding exercise during java interviews. It’s always better to have idea of how to build such factorial program. Let’s go through such three ways: 1) Calculate Factorial Using Iteration Simple and most basic version. Good to know but not right to use for […]
Learn to write Java program to reverse a String. We will first see how to reverse string and the we will also see how to reverse the words in String.
Algorithm: given a list of strings, return all the strings with the nth longest length in that list for example: list – Yuri, Ron, Interview, Longest, List, Contain and nth = 1 will return just “Interview” whereas nth = 2 will return both “Longest” and “Contain”. Though solution to “How to find the kth largest […]
A string is said to be complete if it contains all the characters from a to z. Given a string, check if it complete or not. e.g. Sample Input 3 wyyga qwertyuioplkjhgfdsazxcvbnm ejuxggfsts Sample Output NO YES NO Solution using for loop and indexOf() I wrote a quick function which is able to find this […]
Puzzle: Chandu is very fond of strings. (Or so he thinks!) But, he does not like strings which have same consecutive letters. No one has any idea why it is so. He calls these strings as Bad strings. So, Good strings are the strings which do not have same consecutive letters. Now, the problem is […]
Puzzle: Given an input array of n positive integers where the integers are in random order. Each number in that array can occur many times. You need to find all the distinct duplicate elements and put all those elements in an array i.e. output1. If no number is duplicate in input1 , then output1 should […]
Puzzle : I have given a below map with the following below options, Option A) System.out.println(map.put(“test key 3”, “test value 3”)); Answer) This prints the output as = test value 3 Option B) System.out.println(map.put(“test key 4”, “test value 4”)); Answer) This prints the output as = null; Can anyone please explain why option b is […]
This is most common interview question in java now-a-days. There are many techniques to find duplicate elements in array in java like using Collections.frequency(). I am writing yet another solution which is much easier and fast. Here an array of integers is having 10 integers and 1 and 8 are duplicate integers. You need to […]
Many of you must have played HiLo game in your childhood. Game may be some sort of similar to it, if not exactly same. It was fun, right?? So what if we are adult now? Let’s play this game once again in our own way. Let’s build a java program for this and start playing […]
We all have used syntax’s like i += j and i = i + j thousands of times in our day to day programming. In first sight, they both look similar. In fact, they will result in same output in almost all of the cases in practical cases. But, to surprise you they are not […]
This is a very common interview question. You are asked that if you have a linked list in which you can traverse only in one direction, and if that linked list has a loop in it, how you will detect it?? Well, if you don’t know the answer then don’t be demoralize. My personal opinion […]
A palindrome is a word, phrase, number, or other sequence of units that may be read the same way in either direction, generally if used comma, separators or other word dividers are ignored. [Not mandatory] Similarly, palindrome numbers are those numbers which represent same number if all digits are reversed (Underscores can be ignored in […]
We all know how to create objects of any class. Simplest method to create object in Java is using new keyword. Let’s explore other methods to create object without new keyword in Java. Table of contents Using Class.forName() and Class.newInstance() ClassLoader loadClass() Using Object.clone() Deserialization Using reflection Note: In given examples, I am writing pseudo […]
Learn to identify dead code and unreachable code in Java, with example. It may be asked in your Java interview coding problems as a puzzle. Let’s sovle it.