Company Specific Java questions
Company Specific Java questions
1. Candy QuizAnto and Jim were best friends. They went to a nearby Super Market to get
some candies, where they saw an on-the-spot event organized for the kids. The event is a
one minute quiz game where two kids can participate and the winners were announced a
basket full of candies. Anto and Jim eagerly participated in the game and managed to
answer most of the questions right. The final question came to them from the host looked
a bit tricky to solve. They wanted your help to answer it and take home the candies. The
question posted to them was to find the last non-zero digit of n! where the event host
gave them the value of ‘n’. Given 'n', write a recursive method to find the last non-zero
digit of n!. Hence create a class named Factorial with the following method.
Create a driver class called Main. In the Main method, obtain input from the user in the
console and display the last non-zero digit of n! by calling the lastNonZeroDigit method
present in the Factorial class
Input Format :
First and only line of the input is an integer ‘n’.
Output Format :
Output the last non-zero digit of n! in a single line.
Sample testcases :
Testcase 1 Input : 5
Testcase 1 Output : 2
Testcase 2 Input : 33
Testcase 2 Output : 8
2. Entrance Test
"Success Academy" has arranged for a entrance test for High School students from rural
villages. Those successful students of the test will be awarded the scholarship for their
IIT/JEE preparations at Success Academy. Sunil, the co-coordinator and founder of the
academy has given one problem for the first stage of the test. The problem goes like this:
Given two integers x and n, find the number of ways to express x as sum of n-th powers
of unique natural numbers. It is given that 1 <= n <= 20.
Sunil himself has not computed the solution of the problem. Write a recursive method to
help him find the answer for the same to evaluate the students.
Hence create a class named NumberofWays with the following method.
Create a driver class called Main. In the Main method, obtain input from the user in the
console and display the number of ways to express x as sum of n-th powers of unique
natural numbers by calling the countWays method present in the NumberofWays class.
Input Format :
The first line of input contains the integer x.
The second line contains the integer n.
Output Format :
Output the number of ways to express x as sum of n-th powers of unique natural
numbers in a single line.
Sample testcases :
Testcase 1 Input :
100
2
Testcase 1 Output :
3
Testcase 2 Input :
100
3
Testcase 2 Output :
1
3. Auditions
"Singing Champs" is a famous reality series. The show organizers have planned to roll
out the show’s 5th season in the coming month. The auditions for the show is announced
at various Cities widely and the organizers have inaugurated the first audition today.
Large mass of people gathered at the venue. Based on the selection procedure for the first
level, all the people are made to stand in a queue. Participants who are standing in the
even positions of the queue are selected initially. Of the selected people a queue is
formed and again out of these only people on even position are selected. This continues
until we are left with one person.
To help them in the selection procedure, the organizers approached you to write a
recursive method for determining the position of that final person in the original queue.
Hence create a class named Position with the following method.
Create a driver class called Main. In the Main method, obtain input from the user in the console
and display the position(original queue) of that person who is left by calling the findPos method
present in the Position class.
Input Format :
First and only line of the input is an integer N that corresponds to the total number of people who
came for the auditions.
Output Format :
Output the position(original queue) of that person who is left.
Testcase 1 Input : 5
Testcase 1 Output : 4
4. Decorative Tiles
Carlton Inn is planning to organize a Food Festival bringing together at one place, a wide
variety of cuisines from across the world on account of Christmas. The Hotel
Management has rented out a hall of an indoor Auditorium for this extravaganza.
The Event hall was of area N*M and the coordinators planned to decorate the hall’s
flooringwith carpet tiles embellishing the opulence of the event. They have infinite
number of tiles of size 2i X 2i, where i = 0, 1, 2,… so on. Their task is to find minimum
number of tiles required to fill the given area with tiles.
Help them accomplish their task by writing a recursive method that finds the minimum
number of tiles required to fill the given area with tiles.
Hence create a class named Tiles with the following method.
Create a driver class called Main. In the Main method, obtain input from the user in the
console and display the minimum count of tiles required by calling the minimumTiles
method present in the Tiles class.
Input Format :
First line of the input is an integer ‘N’.
Second line of the input is an integer ‘M’.
Output Format :
Output an integer in a single line that gives the minimum count of tiles required.
Testcase 1 Input :
5
6
Testcase 1 Output : 9
Testcase 2 Input :
4
4
5. Art Competition
Ocean Awareness Art Competition is a yearly art competition that engages students to
promote the need to preserve, protect, and restore the world’s oceans and aquatic
resources. The Contest was organized at an outdoor auditorium in the City and large mass
of school kids is expected to participate.
Every student participating in the contest will be registered at the venue entrance and be
provided with an enrollment Id. To ensure the safety of the students, the Event organizers
decided to make a disciplined seating arrangement by sticking the students’ enrollment Id
on the chairs. There were N enrollments approximately expected for the contest and
based on this, the event organizers wanted to print the enrollment numbers in white
sheets to stick to the chairs.
You are to help the organizers in taking the printed formats of the enrollment numbers.
Write a recursive method to print the enrollment numbers from 1 to N without the help of
Loops.
Hence create a class named EnrollNumbers with the following method.
Create a driver class called Main. In the Main method, obtain input from the user in the
console and call the printNumbers method present in the EnrollNumbers class.
Input Format :
First line of the input is an integer N.
Output Format :
Output the enrollment numbers from 1 to N without using loops.
Testcase 1 Input : 4
Testcase 1 Output : 1 2 3 4
Testcase 2 Input : 1
Testcase 2 Output : 1
6. Wildcard Matching
Sunil is a little scientist. Sunil has planned to design a wildcard pattern matcher to exhibit at the
"Young Inventors", a tech talent show organized at his school. Sunil wanted to design the
wildcard pattern matcher supporting the wildcard character '?'. The wildcard character '?' can be
substituted by any single lower case English letter for matching. He has two strings X and Y of
equal length, made up of lower case letters and the character '?'.Sunil wants your help in
designing the device, to know whether the strings X and Y can be matched or not. Write a
program to check whether the given strings can be matched or not.
Input Format :
First line of the input contains the string ‘X’.
Second line of the input contains the string ‘Y’.
Output Format :
Output a single line with the word "Yes"(without quotes) if the strings can be matched, otherwise
output "No"(without quotes).
Refer sample input and output for formatting specifications.
Testcase 1 Input :
s?or?
sco??
Testcase 1 Output :
Yes
Testcase 2 Input :
stor?
sco??
Testcase 2 Output :
No
Testcase 2 Output : 2
9.Little Authors
"Little Authors" Slogan Writing Competition was organized for School students at Orchids
Senior School. Any student who is creative and effective in communicating ideas in short, yet
powerful about any instant topic can participate in the competition. The important guideline for
the contest is that the Slogan should contain a string where the number of occurrences of some
character in it is equal to the sum of the numbers of occurrences of other characters in the string.
Write a program to help the event organizers to determine whether the submitted Slogans adhere
to the given condition.
Input Format :
First and only line of input contains one string S consisting of lowercase letters.
Output Format :
Output a single line containing "Yes"(without quotes) if the string satisfies the condition given
above or "No"(without quotes) otherwise.
Refer sample input and output for formatting specifications.