0% found this document useful (0 votes)
9 views

Company Specific Java questions

The document presents a series of programming problems that require the implementation of recursive methods in Java. Each problem includes a description, input and output formats, and sample test cases. The problems cover various topics such as finding last non-zero digits of factorials, counting unique sums of powers, determining positions in a queue, and more.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Company Specific Java questions

The document presents a series of programming problems that require the implementation of recursive methods in Java. Each problem includes a description, input and output formats, and sample test cases. The problems cover various topics such as finding last non-zero digits of factorials, counting unique sums of powers, determining positions in a queue, and more.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

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

Testcase 2 Input : 180

Testcase 2 Output : 128

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

7. Peter at Challenger Series


The Table tennis Challenger Series is the springboard to fame for the future stars of professional
table tennis. Peter is very passionate towards table tennis and made his debut in the first league
match of the Series against a prominent player Horejsi.
Peter found some statistics of matches which described who won the points in order. A game
shall be won by the player first scoring 11 points except in the case when both players have 10
points each, then the game shall be won by the first player subsequently gaining a lead of 2
points. Could you please help Peter find out who the winner was from the given statistics? (It is
guaranteed that statistics represent always a valid, finished match.)
Input Format :
First and only line of the input consists of a binary string S, which describes a match. '0' means
Peter lose a point, whereas '1' means he won the point.
Output Format :
Output on a separate line a string describing who won the match. If Peter won then print "Win"
(without quotes), otherwise print "Lose" (without quotes).
Refer sample input and output for formatting specifications.

Testcase 1 Input : 0101111111111

Testcase 1 Output : Win

Testcase 2 Input : 11100000000000

Testcase 2 Output : Lose

8. Nela's Birthday and Colorfull Balloons


Nella is an eight-year-old princess who will inherit the kingdom of Castlehaven. It is her birthday
today and her Dad, the King of Castlehaven has arranged for a grand party.Nella loves colorful
balloons and so her Dad planned to decorate the entire palace with balloons of the colors that
Nella loved. So he asked her about her color preferences. The sophisticated princess that Nella is,
she likes only two colors — amber and brass. Her Dad bought n balloons, each of which was
either amber or brass in color. You are provided this information in a string s consisting of
characters 'a' and 'b' only, where 'a' denotes that the balloon is amber, where 'b' denotes it being
brass colored. When Nella saw the balloons, she was furious with anger as she wanted all the
balloons of the same color. In her rage, she painted some of the balloons with the opposite color
(i.e., she painted some amber ones brass and vice versa) to make all balloons appear to be the
same color. It took her a lot of time to do this, but you can probably show her the right way of
doing so, thereby teaching her a lesson to remain calm in difficult situations, by finding out the
minimum number of balloons needed to be painted in order to make all of them the same color.
Input Format :
The first and only line of input contains a string s.
Output Format :
Output a single line containing an integer — the minimum number of flips required.
Refer sample input and output for formatting specifications.
Testcase 1 Input : ab
Testcase 1 Output : 1
Testcase 2 Input : baaba

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.

Testcase 1 Input : acab

Testcase 1 Output : Yes


Testcase 2 Input : abc
Testcase 2 Output : No

You might also like