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

Trisect All Java Question

The document outlines various Java programming tasks and functions, including calculations related to numbers, strings, and conditions. Each task specifies inputs and expected outputs, such as calculating sums, checking for prime numbers, and manipulating strings. The tasks are designed to enhance programming skills and problem-solving abilities in Java.

Uploaded by

harendraj2ee
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Trisect All Java Question

The document outlines various Java programming tasks and functions, including calculations related to numbers, strings, and conditions. Each task specifies inputs and expected outputs, such as calculating sums, checking for prime numbers, and manipulating strings. The tasks are designed to enhance programming skills and problem-solving abilities in Java.

Uploaded by

harendraj2ee
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

______HARENDRA_______________________________________________________________

Module 1 – Module 5 (JAVA INTERVIEW PROGRAMS)


RunsInSeries
The scores of a batsman in the five matches of a one day international series have been provided.
Calculate the total number of runs the batsman scored in the series.
--------------------------------------------------------------------------------------------------------------------
AddTwoNums
Given two numbers as input, calculate the sum of the numbers
-------------------------------------------------------------------------------------------------------------------
SecondToHours
Given the time in number of seconds, find out how many hours have been completed
-------------------------------------------------------------------------------------------------------------------
HundredsDigit
Given a 4 digit number as input, find the value of its hundreds digit.

RequiredRunRate
A team is chasing the target set in a one day international match. The objective is to compute the
required run rate. The following have provided as input: target, maxOvers, currentScore,
oversBowled.

Make3Digit
Given a digit as input, create a 3 digit number in which all the digits are the same as the input
digit.

MakeDecimal
Given 3 digits a,b and c as input, return a double of the form a.bc

Sum2Digit
Given a 2 digit number as input, compute the sum of its digits. Assume that the number has 2
digits.
AndBooleans
Given three booleans as input, return the and of the all three Booleans

LargerThanOne
Given three numbers as input, num, num1 and num2, return true if num is greater than atleast
one of num1 and num2. Do not use if statement to solve this problem.

11 :- NumberInAscendingOrder
Given 3 numbers - num1, num2 and num3 as input, return true if they are in ascending order.
Important - Do not use if statement in solution.

SumOf4Digits
Given a number as input, compute the sum of its last 4 digits. Assume that the number has at
least 4 digits.
---------------------------------------------------------------------------------------------------------------

AreaOfSquare
You have been given 4 inputs x1,y1,x2 and y2. The points (x1,y1) and (x2,y2) represent the end points of
the diagonal of a square. Return the area of the square.

----------------------------------------------------------------------------------------------------

AddDigitNumbers
Given three digits as input, create a 4 digit number out of each input in which all the digits are
the same. Then add all the 3 numbers and return the value.

SecondsToTime
Given the time of a day in number of seconds, convert it into time in hhmmss format. Note that
the time is past noon, and hence the hours will never be less than 12.
-------------------------------------------------------------------------------------------------------------
Multiple 37 (Module 1 : b)
--------------------------------------------------------------------------------
Given a number n, return true if it is divisible by either 3 or 7.

---------------------------------------------------------------------------------------------
LargestOfThree
Given three numbers as input, return the largest number.
---------------------------------------------------------------------------------------

ScoredCentury
The scores of a batsman in his last three innings have been provided. You have to determine
whether he has scored a century in the last three innings or not. If yes, return true else return
false.
--------------------------------------------------------------------------------------
DaysInMonth
Given the number of the month in 2013 (1 for January, 12 for December), return the number of
days in it.

--------------------------------------------------------------------------------
ChangeCharCase
Given a char as input, if it is an alphabet change its case otherwise return it as it is.
public class

-------------------------------------------------------------------------------------------------
IsDigit
Given a char as input, return true if it is a digit (i.e. between 0 to 9).

MiddleChar
Given three chars as input, return the char that would come in the middle if the chars were
arranged in order. Note that > operator can be used for chars.
------------------------------------------------------------------------------------------------
ArithmeticOps
Two numbers a and b and a char c have been provided as inputs. The char c represents a
mathematical operation namely +,-,*,/,% (remainder). The task is to perform the correct
operation on a and b as specified by the char c.
---------------------------------------------------------------------------------
SameLastDigit
Given 2 non negative numbers a and b, return true if both of them have the same last digit.

------------------------------------------------------------------------------------
LeapYear
Given a year, return true if it is a leap year otherwise return false. Please note that years that are
multiples of 100 are not leap years, unless they are also multiples of 400.
------------------------------------------------------------------------------------------
ComputeGrade
Given the marks of a student in five subjects, compute the overall grade. The grades will be on
the basis of the aggregate percentage. if overall percentage >= 85%, grade is A, if it is >=75% it
is B, >=60% is C, >=45% is D, if it is >=33% it is E else F.

--------------------------------------------------------------------------------------
AddForThird
Given three numbers a, b and c, return true if the sum of any two equals the third number.

------------------------------------------------------------------------------------------
ConsecutiveCentury
Given the scores of a batsman in four innings, return whether he scored at least two centuries or
not.
----------------------------------------------------------------------------------------------

LotteryPrize
Jack bought a lottery ticket. He will get a reward based on the number of the lottery ticket. The
rules are as follows - If the ticket number is divisible by 4, he gets 6 - If the ticket number is
divisible by 7, he gets 10 - If the ticket number is divisible by both 4 and 7, he gets 20 -
Otherwise, he gets 0. Given the number of the lottery ticket as input, compute the reward he will
receive

----------------------------------------------------------------------------------------------

LotteryPrize3
Jack bought 3 lottery tickets. He will get a reward based on the number of the lottery ticket. The
rules are as follows - If the ticket number is divisible by 4, he gets 6 - If the ticket number is
divisible by 7, he gets 10 - If the ticket number is divisible by both 4 and 7, he gets 20 -
Otherwise, he gets 0. Given the numbers of the 3 lottery tickets as input, compute the total
reward he will receive. In this problem define a function to compute the reward given the ticket
number and use that function to calculate the total reward.
----------------------------------------------------------------------------------------------
SameLast2Digits
You have been given 4 numbers as input. Return true if any one the numbers has the same last 2
digits. For e.g. 123455 has the same last 2 digits (5 and 5) whereas 123545 does not (4 and 5). In
this problem, define a function that check whether a number has the same two digits or not and
returns true or false. Use that function to calculate for the 4 numbers.

----------------------------------------------------------------------------------------
SumDivide11
You have been given 4 numbers as input. Return true if you can find 3 numbers among them
whose sum is divisible by 11. In this problem, define a function that takes 3 numbers as input
and returns true if there sum is divisible by 11. Use this function to check for the 4 numbers.

-----------------------------------------------------------------------------------------------
MultipleCheck
Given a number n as input, return true if n is divisible by at least three and not divisible by at
least one of 2,3,5,7 and 11.

------------------------------------------------------------------------------------------
SumLast3
Given a number as input, return the sum of its last 3 digits.
--------------------------------------------------------------------------------
Special20Number
A number is special20 if it is a multiple of 20 or if it is one more than a multiple of 20. Write a
function that return true if the given non-negative number is special20.

----------------------------------------------------------------------------------------------------
Diff25
Given three ints as input , return true if one of them is 25 or more less than one of the other
numbers.

---------------------------------------------------------------------------------------------
LotteryTicket
You have purchased a lottery ticket showing 3 digits a, b, and c. The digits can be 0, 1, or 2. If
they all have the value 2, the result is 10. Otherwise if they are all the same, the result is 5.
Otherwise if both b and c are different from a, the result is 1. Otherwise the result is 0.
--------------------------------------------------------------------------------------
TicketNumbers
You have a green lottery ticket, with ints a, b, and c on it. If the numbers are all different from
each other, the result is 0. If all of the numbers are the same, the result is 20. If two of the
numbers are the same, the result is 10.
------------------------------------------------------------------------------------
Blackjack
Given 2 int values greater than 0, return whichever value is nearest to 21 without being greater
than 21. Return -1 if the values are greater than 21. Also return -2 if both the values are same and
less or equal to 21.
-----------------------------------------------------------------------------------------
Reverse3
Given a 3 digit number as input, reverse it.
-------------------------------------------------------------------------------------------------------
Module 1c
------------------------------------------------------------------------------
SumNumbers
Given a number n as input, output the sum of numbers from 1 to n.
----------------------------------------------------------------------------------------------
SumOfSquares
Given two numbers n1 and n2 such that n2>n1, find sum of squares of all numbers from n1 to n2
(including n1 and n2).
-----------------------------------------------------------------------------------
SumNumbers1
Given a number n as input, find the sum of all numbers from 1 to n which are not divisible by
either 2 or 3.
----------------------------------------------------------------------------------------
NextMultiple37
Given a number num as input, find the smallest number greater than num that is a multiple of
both 3 and 7
-------------------------------------------------------------------------------------------------
CountFactors
Given a number n as input, find the count of its factors other than 1 and n.
---------------------------------------------------------------------------------------
IsPrimeNumber
Given a number n as input, return whether the number is a prime number or not. Please note that
1 is not a prime number.

-------------------------------------------------------------------------------------------
NthPower
Given a number a, compute the nth power of a.

------------------------------------------------------------------------------------
SumOfDigitsWithCount
Given 2 inputs, a number n and the number of digits it has d , find the sum of its digits.
--------------------------------------------------------------------------------------------------
PerfectNumber
A perfect number is a positive integer that is equal to the sum of its factors. For example, 6 is a
perfect number because 6=1+2+3; but 24 is not perfect because 24<1+2+3+4+6+8+12. Given a
number n, the objective is find out whether it is a perfect number or not.
-----------------------------------------------------------------------------------------------
FizzBuzz
A number is considered fizz if it is divisible by 3. It is considered buzz if it is divisible by 5. It is
considered fizzbuzz if it is divisible by both 3 and 5. A fizzbuzz is neither fizz nor buzz. Given
two numbers n1 and n2 such that n2>n1, let f be the number of fizz, b be the number of buzz and
fb be the number of fizzbuzz between n1 and n2(both n1 and n2 are included). Calculate and
return the value of 3*f+5*b-15*fb.

------------------------------------------------------------------------------------------
Is3Den
A number is defined as a 3den if it is a multiple of 3 or has the digit 3 in it. Given a number as
input, determine whether it is a 3den or not.

-------------------------------------------------------------------------------------------
SumOfDigits
Given a number n, find the sum of its digits.
-----------------------------------------------------------------------------------------
CountTheDigit
Given a number n and a digit d as input, find the number of time d occurs in n. You can assume
that the number is non-negative.

LargestDigit
Given a number as input, find the largest digit in it. You can assume that the number is not
negative.

----------------------------------------------------------------------------------------------
FirstDigit
Given a number as input, find the most significant digit in it. You can assume that the number is
not negative.

AnyonePrime
Given three numbers as input, return true if at least one of them is a prime number. For solving
this problem, define a function that checks whether a number is a prime or not and use that
function.
----------------------------------------------------------------------------------------------------
SameFirst
Given three numbers as input, return true if the first digit of any two of them is the same. The
first digit of 2345 is 2, of 981201 is 9. Assume all the numbers are positive integers greater than
0. For solving this problem, define a function that computes the first digit if a number and use
that function.
SumRounded
Round a number to the next multiple of 10 if its ones digit is 5 or more, otherwise round it the
previous multiple of 10.So, 25 and 26 round to 30 where as 23 and 24 round to 20. 20 also
rounds to 20. You have been given 4 ints as input. Round each of the input values and return
their sum.

ComputeNthPrime
Given an input n, find out the nth prime

SuperDivide
A positive int is called super-divide if every digit in the number divides the number. So for
example 128 divides itself since 128 is divisible by 1, 2, and 8. Note that no number is divisible
by 0. Given a number as input, determine if it is a super-divide.

AllFactorsArePrime
Given a number n, return true is all the factors of n are prime numbers. Note that 1 and the
number itself are not considered as factors in this problem.

Count3Den
A number is defined as a 3Den if it is a multiple of 3 or has the digit 3 in it. Given a number num
as input, count the number of 3Den between 1 and num.

ReverseNumber
Given a number as input, reverse it. You can assume that the number is not negative.

---------------------------------------------------------------------------------------------
Module 2 :- STRINGS

CountCharInString
Given a string and a char as input, output the number of times, the char appears in the string.

-------------------------------------------------------------------------------
JoinChars
Given two strings s1 and s2 of equal length as input, the expected output is a string which the 1st
char from s1, then 1st char from s2, then 2nd char from s1, then 2nd char from s2 and so on.

-----------------------------------------------------------------------------------
GetFirstWord
Given a sentence as an input, return the first word of the sentence. Note that words in a sentence
have the char space or ' ' between them.

ConcatAsPattern
Given 2 strings str1 and str2 as input, return a string of the form (str1)str2(/str1)

-------------------------------------------------------------------------------------------
SecondHalf
Given a string as input, output the second half of the string. You can assume that the length of
the string is a even number.
-----------------------------------------------------------------------------------------
ReverseString
Given a string as input, reverse it. Reverse means return the string if it is read from right to left.

------------------------------------------------------------------------------------------------
DoubleString
Given a string, return a string where for every char in the original, there are two chars.

---------------------------------------------------------------------------------------
MoveUppercaseChars
Given a string as input, move all the alphabets in uppercase to the end of the string.

------------------------------------------------------------------------------------------
SameString
Given 3 strings as input, return true if any two of the strings are the same.
------------------------------------------------------------------------------------

JavaFile
A file name in java ends in .java. Given the name of the file, return true if its a java file, else
return false.
--------------------------------------------------------------------------------------
PatternInString
Given two strings str1 and str2 as input, determine whether str2 occurs with str1 or not.
-------------------------------------------------------------------------------------------
CountCommonChars
Given 2 strings, str1 and str2, as input, return the count of the chars which are in the same
position in str1 and str2.

------------------------------------------------------------------------------------------------
RemoveCharsFromString
Given two strings, str1 and str2 as input, remove all chars from str1 that appear in str2.
---------------------------------------------------------------------------------------------
SwapLastChars
Given a string as input, return the string with its last 2 chars swapped. If the string has less than 2
chars, do nothing and return the input string.

------------------------------------------------------------------------------------------
CountHello
Return the number of times that the string "hello" appears anywhere in the given string.

-----------------------------------------------------------------------------------------------
CombineStr
Given two strings s1 and s2 as input, create a string made of the first char of s1, the first char of
s2, the second char of s1, the second char of s2, and so on. Any leftover chars go at the end of the
result string.

------------------------------------------------------------------------------------------------
ChangeStringCase
Given a string as input, the expected output is a string where the case of all alphabets has been
changed.
--------------------------------------------------------------------------------------
BatBall
Given a string, return true if the string "bat" and "ball" appear the same number of times.
------------------------------------------------------------------------------------------------
NotPresentChars
Given two strings s1 and s2 as input, return a string where the characters of s1 which are not in
s2 have been replaced by #.
------------------------------------------------------------------------------------------
LetterPattern
A string str has been provided as input. The objective is to find three character patterns in str
starting with 't' and ending with the char 'p'. For all such patterns, the middle character is
removed.
---------------------------------------------------------------------------------------
CountCode
Given a string as input, count the number of times, the string "code" appears in the input string.
Note that while counting the occurrence of "code", we’ll accept any letter in place of 'd'. So
"core", "cope", "come" etc will also be added to the count.
------------------------------------------------------------------------------------
PalindromeString
Given a string as input, check whether it is a palindrome or not. A palindrome is a string which is
same if it is read from left to right or from right to left.

---------------------------------------------------------------------------------------
PermutationString
Given two strings str1 and str2 as input, check whether the strings are a permutation of each
other. str1 is a permutation of str2 if all the characters of str2 can be arranged in some way to
form str1.
-------------------------------------------------------------------------------------------
RemoveMultipleSpaces
Given a string as input, remove all the extra spaces that appear in it. Spaces wherever they
appear should be a single space. Multiple spaces should be replaced by a single space.
---------------------------------------------------------------------------------------
GetMiddleWord
Given 3 words w1,w2 and w3 as input, output the word that will come in between in a dictionary

---------------------------------------------------------------------------------
LargerNumber
Given 2 strings representing numbers as input, return the larger number. Note that both the
numbers are non negative.
----------------------------------------------------------------------------------------
StringToNumber
Given a string as input, convert it into the number it represents. You can assume that the string
consists of only numeric digits. It will not consist of negative numbers. Do not use
Integer.parseInt to solve this problem.

---------------------------------------------------------------------------------------
BinToInt
Given a binary number as input convert it into base 10 (decimal system). Note that to convert a
number 100111 from binary to decimal, the value is 1*2^5 + 0*2^4 + 0*2^3 + 1*2^2 + 1*2^1+
1*2^0. Also note that 5 here is the length of the binary number – 1.

----------------------------------------------------------------------------------------------
SolveExpression
Given a string representing a simple arithmetic expression, solve it and return its integer value.
The expression consists of two numbers with a + or – operator between the numbers, i.e., it will
of the form x+y or x-y where x and y are not negative.

-------------------------------------------------------------------------------------------------------------
RemoveDuplicateChars
Given a string as input, remove all chars from the string that appear again. That is, while reading a string
if a char has appeared previously it will be removed.
-----------------------------------------------------------------------------------------------------------
MostFrequentChar
Given a string as input, return the char which occurs the maximum number of times in the string. You can
assume that only 1 char will appear the maximum number of times.
------------------------------------------------------------------------------------------------------------------
IntToBin
Given a number in base 10 (decimal system) as input convert it into binary (base 2). Note that to convert a
number from base 10 to base 2, keep on dividing it by 2 and appending the remainder to start of the
binary number. For e.g. to convert 12 into binary, Step 1 : divide 12 by 2, quotient = 6, remainder = 0,
output = "0" Step 2 : divide 6 by 2, quotient = 3, remainder = 0, output = "00" Step 3 : divide 3 by 2,
quotient = 1, remainder = 1, output = "100" Step 4 : divide 1 by 2, quotient = 0, remainder = 1, output =
"1100" As quotient = 0 at step 4, we stop and the binary representation of 12 is 1100.
--------------------------------------------------------------------------------------------------------
LargeAddition
Given two numbers as input, return the sum of the numbers. Note that the numbers can be very large and
hence are provided as Strings. While adding them, do not convert them into int or long as they may not fit
into them. Also, do not use BigInteger class while solving this problem.
-------------------------------------------------------------------------------------------------------------------------------
Module 3 :- ARRAY
CountEvens
Given an array of ints as input, return the number of even ints in it.

MaxDifference
Given an array of ints as input, compute the difference between the largest and smallest numbers
in the array.

StringArrayOfNumbers

CountStrings
You have been given an array of strings and an int size as input. Return the number of strings in
the input array which have the length as size.

MatchingMarks
You have been given the scores of two students in different subjects. Count the number of times
the difference in their marks for the same subject is less than 10.

More6Than4
Given an array of ints as input, return true if the number of 6's (sixes) is greater than the number
of 4's (fours).

MCQScore
You have been given two char arrays as input, key and answersheet. The first input parameter is
the key array and contains the correct answers of an examination, like {'a','b','d','c','b','d','c'}. The
second input parameter is answersheet array and contains the answers that a student has given.
You can assume that the student has answered all the questions. While scoring the examination,
a correct answer gets +3 marks while an incorrect answer gets -1 marks. Calculate the score of
the student.

ShiftElements
Given a array of chars as input, return an array where the elements have been "left shifted" by
one, i.e. {'b','c','d','e'} becomes {'c','d','e','b'}. Note that you should not create a new array and
only modify the given input array.
JoinArray
Given two arrays, arr1 and arr2 as input, return an array which has the values of arr1 followed by
those of arr2.

ReverseArray
Given an array of integers as input, output an array which has the elements in reverse order.

AnyDuplicatesInArray

GenerateFizzBuzz
You have been two ints, n1 and n2 as input. Return a new String[] containing the numbers from
n1 to n2 as strings, except for multiples of 3, use "Fizz" instead of the number, for multiples of 5
use "Buzz", and for multiples of both 3 and 5 use "FizzBuzz".

CreateDomino
Given and int n as input where n>=0, create an array with the pattern {1,1,2,1,2,3,… 1,2,3..n}.

SplitSumArray
Given an array of ints as input, return true if it is possible to split the array into two so that the
sum of the numbers on the left is equal to the sum of the numbers on the right.

IsSortedArray
Given an array of integers as input, return true if the array is sorted. Note that the array can be sorted in either
ascending or descending order.

RemoveZeros
Given an array of integers return an array in the same order with all 0's removed.

ThirdLargestNumberInArray
Given an array of integers, find out the third largest value in the array.
Remove3s
Given an array on numbers as input, remove all elements from the array which are either
multiple of 3 or have the digit 3 in them. For e.g. 13 and 15 will be both removed from the array
if they are present.

LargestIn2D
Given a 2D array consisting of ints as input, return the largest int in it.

MatrixAdd
Given two matrices M1 and M2, the objective to add them. Each matrix is provided as an int[][],
a 2 dimensional integer array. The expected output is also 2 dimensional integer array.

WordTo2DChar
Given a para of words (separated by space), create a 2D array where each array in it represents
the word. Note that the words are of the same size.

JoinDescArray
Given two arrays, arr1 and arr2, that have been sorted in descending order, output an array which
appends the values from both arr1 and arr2 while being sorted in descending order.

AllPrimesBetween
Given two numbers n1 and n2 as input, return an array containing all the primes between n1 and
n2 (Note that both n1 and n2 can be included in the array if they are prime). Also, the primes in
the array need to be in ascending order.

RemoveDuplicates
Given an array of numbers as input, return an array with all the duplicate values removed.

MostFreqDigit
Given an array of numbers as input, return the digit which occurs the maximum number of times
in the input.
MostFreqNum
Given an array of numbers as input, return the number which occurs the maximum number of
times in the input.
_______________________________________________________
Module 4 a-b-c, 5 a,b,c,d:----JAVA :- program question
---------------------------------------------------------------------------------------
MODULE 4a
TwoDPoint
Create a class TwoDPoint that contains two fields x, y which are of type int. Define another class
TestTwoDPoint, where a main method is defined. The main method should create two
TwoDPoint objects, assign them values 2,2 and 3,3 and print them.
---------------------------------------------------------------------------------------------------------------------
TwoDPoint2
Adding to the previous problem, modify the class TestTwoDPoint and add a function to it. This
function takes two ints as input and returns a TwoDPoint.
---------------------------------------------------------------------------------------------------------------------

TwoDPoint3
Adding to the previous problem, modify the class TestTwoDPoint and add another function to it.
This function takes two TwoDPoints as input and returns the TwoDPoint that is farthest from the
point (0,0).
---------------------------------------------------------------------------------------------------------------------

TwoDPoint4
Adding to the previous problem, modify the class TestTwoDPoint and add another function to it.
This function takes two TwoDPoints as input and returns a new TwoDPoint whose x value is the
sum of x values of the input TwoDPoint's and whose y value is the sum of the y valaues of the
input TwoDPoint's.
---------------------------------------------------------------------------------------------------------------------

Create a class Student


Create a class Student that contains the following fields – name (of type string), marks(of type
int[]). Define another class TestStudent, where a main method is defined. The main method
should creates a Student object with name as "Bill" and marks as {88,92,76,81,83} and print it.
---------------------------------------------------------------------------------------------------------------------

Student2
Adding to the previous problem, modify the class TestStudent and add a function
totalMarks(Student st). This function takes a Student as input and returns the total marks of the
student.
---------------------------------------------------------------------------------------------------------------------
Student3
Adding to the previous problem, modify the class TestStudent and add a function
betterStudent(Student st1, Student st2). This function takes two Student's as input and returns the
Student with the higher total marks.
---------------------------------------------------------------------------------------------------------------------
Student4
Adding to the previous problem, modify the class TestStudent and add a function
createStudent(String nameStr, String marksStr). This function creates and return a new Student.
The name of the new Student is nameStr and the marks are determined from comma separated
string marksStr. For e.g. marksStr can be "68,72,76,81,73".
---------------------------------------------------------------------------------------------------------------------
Student5
Adding to the previous problem, modify the class TestStudent and add a function
display(Student st). This function takes a Student as input and prints it.
---------------------------------------------------------------------------------------------------------------------
Rectangle
Create a class Rectangle that contains the following fields – length(of type int), breadth(of type
int). Define another class TestRectangle, where a main method is defined. The main method
should creates a Rectangle object with length = 10 and breadth = 20 and print it.
---------------------------------------------------------------------------------------------------------------------
Rectangle2
Adding to the previous problem, modify the class TestRectangle and add a function
createStudent(int ln, in br). This function creates and return a new Rectangle.
---------------------------------------------------------------------------------------------------------------------
Rectangle3
problem, modify the class TestRectangle and add a function computeArea(Rectangle rect). This
function returns the area of the Rectangle rect. Also add another function
computePerimeter(Rectangle rect) which returns the perimeter of the Rectangle rect.
---------------------------------------------------------------------------------------------------------------------
Rectangle4
Adding to the previous problem, modify the class TestRectangle and add a function
createRectangles(int[] lengths, int[] breadths). This function returns an array of Rectangle
(Rectangle[]) which corresponds to the lengths and breadths being input. Note that the length of
both the input arrays is the same and you will create the same of the new Rectangle.
---------------------------------------------------------------------------------------------------------------------
Rectangle5
Adding to the previous problem, modify the class TestRectangle and add a function
largestPerimeter(Rectangle[] rects). This function returns the Rectangle with the largest
perimeter in the input rectangles.
---------------------------------------------------------------------------------------------------------------------
Rectangle6
Adding to the previous problem, modify the class TestRectangle and add a function
largestArea(Rectangle[] rects). This function returns the Rectangle with the largest area in the
input rectangles.
---------------------------------------------------------------------------------------------------------------------
Circle
Create a class Circle that contains the following field – radius(of type int). In the class Circle,
also define the following methods - area : which returns the area of the circle. Assume pi = 3.14 -
perimeter : which returns the perimeter of the circle. Define another class TestCircle, where a
main method is defined. The main method should create a Circle object with radius = 5 and
display the area and perimeter of the circle. Note that in calculating the area and perimeter use
the corresponding methods defined in Circle class.
---------------------------------------------------------------------------------------------------------------------
Circle2
Adding to the previous problem, Modify the class TestCircle. Add to it a function
largerCircle(Circle circle1, Circle circle2), which returns the Circle with the larger area. Note
that while calculating the area, you have to use the method defined in Circle class.
---------------------------------------------------------------------------------------------------------------------
Result
Create a class Result that contains the following fields – marks(of type int[]). The int[] marks
contains the marks obtained by a student in the various examinations that were conducted. In the
class Result also define the following functions - maxMarks : which returns the maximum marks
scored (it is the maximum value in the int[] marks). - avgMarks : which returns the average
marks scored in the exams. - totalMarks : which returns the total marks scored in the exams.
Also define the class TestResult in which there is function which created a new Result and
displays the values of max marks and average marks. Note that for calculating max marks and
average marks, you should use the methods defined in the class Result.
---------------------------------------------------------------------------------------------------------------------
Result2
Adding to the previous problem, Modify the class TestResult. Add to it a function
betterResult(Result res1, Result res2), which returns the better Result. Better result is defined as
the result the higher total marks. If total marks are the same, then it is the one with the higher
maximum marks. Note that while calculating total marks, you have to use the method defined in
the Result class.
---------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
Result3
Adding to the previous problem, Modify the class TestResult. Add to it a function
bestResult(Result[] results), which returns the best Result. The best result is defined as the result
with the highest average marks. Note that while calculating average marks, you have to use the
method defined in the Result class. Also, you can assume that no two results have the same
average marks.
---------------------------------------------------------------------------------------------------------------------
ShoppingCart
Create a class Item which refers to an item in the shopping cart of an online shopping site like
Amazon. The class Item has the fields name (of type String), productId (of type String), price (of
type double), quantity (of type int), amount (of type double). The field amount is calculated as
price * quantity. Also define a class ShoppingCart which refers to the shopping cart of a
customer at Amazon. The class ShoppingCart has the fields items (of type Item[]), totalAmount
(of type double). Also define a class TestCart which has a function makeCart(String[] itemData)
which takes the information about the shopping cart of a customer as input and returns an object
of type ShoppingCart.The input String[] items, consists of an array of String where each String
provides information on an item in the manner "name,id,price, quantity". For e.g. it can be
"Colgate,CP10023,54.50,3" where Colgate is the name, CP10023 is the product id, 54.50 is the
price and 3 is the quantity. Note that the ShoppingCart object returned should have the correct
totalAmount and each Item in it should the correct amount.
---------------------------------------------------------------------------------------------------------------------
ShoppingCart2
Modify the class ShoppingCart. Add to it the method addItem(Item item) which takes an Item as
input and adds it to the field items. The way we add it is that if the customer has already added
that product id to the cart earlier, only the quantity is modified and increased to reflect the new
purchase. If the item was not present, then the it id added to the field items. Remember that if the
field items can also be null. Also the field totalAmount should reflect the correct value. Also add
the method removeItem(String productId) which takes a productId as input removes the item
with that product id from the cart. Also the field totalAmount should reflect the correct value.
---------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
Student
Create a class Student which has the following fields name (of type String), marks (of type int[]),
overallGrade (of type char). All the marks are out of 100, and grades are assigned on the
following basis : >=85% (A grade), 70%-85% (B grade), 55%-70% (C grade), 40%-55% (D
grade), <40% (F grade). Also define a class Section which has the following fields students (of
type Student[]), numOfA (of type int), numOfF (of type int), highestTotal (of type int). numOfA
refers to the number of students in the section who got A grade. numOfF refers to the number of
students who got F grade. highestTotal refers to the highest total marks achieved by a student in
the section. Also define a class TestSection which has a function makeSection(String[]
studentsData) which takes the information on students as input and returns an object of type
Section. Each element of the input String[] studentsData consists of a String of the form
"Jack:88:92:76:90:66" where Jack is the name of the student and 88,92,76,90 and 66 are the
marks. Note that in the Section object that is returned by the function makeSection, all the fields
of Section should be correctly updated. Also, all the fields in each Student in the Section object
should be properly updated.
---------------------------------------------------------------------------------------------------------------------
Bowler
Define the following classes Class Bowler which has the fields name(String), overs (int),
maidens (int), runs (int), wickets (int). Class BowlerList which has the field bowlers(of type
Bowler[]). The class also has the following functions – totalOvers() – returns the total number of
overs bowled by all the bowlers. – totalRuns() – returns the total number of runs conceded by all
the bowlers. – totalWickets() – returns the total number of wickets taken by all the bowlers. –
economyRate() – returns a double calculated as total runs conceded divided by total overs
bowled – wickets(String bowlerName) – returns the number of wickets taken by the bowler
whose name is specified as parameter. If the name does not exist it is 0. Class TestBowler which
has a function makeBowlers(String[] bowlerData). The String[] is like
{"Zaheer-10-1-55-0","Ishant-8-0-72-0","Jadeja-10-2-34-2"}, where each String like
"Zaheer-10-1-55-0" means Name-Overs-Maidens-Runs-Wickets.
---------------------------------------------------------------------------------------------------------------------
TwoDPoint5
Modify the class TwoDPoint defined earlier and add a constructor that takes two parameters.
---------------------------------------------------------------------------------------------------------------------
Student6
Modify the class Student defined earlier and add a constructor that takes two parameters of type
String and int[]. Also define a constructor that takes no parameters.
---------------------------------------------------------------------------------------------------------------------
Rectangle7
Modify the class Rectangle defined earlier and add a constructor that takes two parameters –
length and breadth. Define a constructor that takes no parameters and initialize the rectangle
values to 0.
---------------------------------------------------------------------------------------------------------------------
ShoppingCart3
Modify the solution of problem Item and ShoppingCart to add constructors. In the class Item add
a constructor that takes the requisite parameters as input and also computes and sets the field
amount. In the class ShoppingCart add a constructor which takes a String[] itemData as input.
This input is similar to the parameter itemData provided to the function makeCart in the class
TestCart.
_____________________________________________________________________________

Module 4 – b
______________________________________________________________________________
ShapeColor
Create a class Shape that has member color indicating color of shape. Extend Shape to create
Square, Circle, Rectangle. Also, draw the class diagram.
---------------------------------------------------------------------------------------------------------------------
FourDimensionalShape
Create a class FourDimensionalShape that extends Shape and has four corners. Extend it to
create Square and Rectangle class. Put a print in every constructor of each class – what is the
result? Also, draw the class diagram.
---------------------------------------------------------------------------------------------------------------------
Vehicle
Create a class Vehicle with the fields type (String), color (String), tyres (int). Extend Vehicle to
create the class Car which always has 4 tyres and the type = “car”. Car has the additional fields
brand (String), fuel (String). Also, extend Vehicle to create the class Cycle which has always has
2 tyres and the type = “cycle”. Cycle has the additional fields, hasGears (boolean).
---------------------------------------------------------------------------------------------------------------------
ShapeCalcArea
Create a class Shape that has a method calculateArea which returns 0. Extend Shape to create
Square, Circle, Rectangle which have the corresponding calculateArea method. Also, draw the
class diagram.
---------------------------------------------------------------------------------------------------------------------
Point
Define a class Point which has a method distance() which returns the distance of the point from
origin. This method in the class Point always returns 0. Define a class 2DPoint which extends
Point and represents a point (x,y). The method distance() returns the distance from (0,0). Define
a class 3DPoint which extends Point and represents a point (x,y,z). The method distance() returns
the distance from (0,0,0). Note that the classes should have the correct implementation of
distance and all the required constructors
Module 4 C
______________________________________________________________________________
String1
Implement toString, equals, and hashCode for all classes in the class 2Dpoint which represents a
point (x,y). The function toString should represent a String representation of the 2DPoint. The
function equals should return true if two 2Dpoint’s represent the same point. In the main class,
create two 2DPoints. Pass them to a function that takes Objects as input and see if you can
invoke the toString and equals correctly.
---------------------------------------------------------------------------------------------------------------------
AbstractShape
Define the class Shape (as specified in the problem above) as an abstract class. Define the
sub-classes Square, Circle and Rectangle. See what changes are required to make the code work.
---------------------------------------------------------------------------------------------------------------------
Measurable
Create an interface Measurable that has 2 methods – calculateArea and calculatePerimeter.
Define classes Square, Rectangle and Circle that implement Measurable. Note that the classes
Square, Rectangle and Circle do not extend Shape. See how you can define Square, Rectangle
and Circle as of type Measurable and use it to calculate the area and perimeter.
---------------------------------------------------------------------------------------------------------------------
ShapePackage
Define the class Shape (as specified in the problem above) in a package in.trisect.shapes. Define
the sub-classes Square, Circle and Rectangle in a different package in.trisect.shapes.define. See
what changes are required to make the code work.
---------------------------------------------------------------------------------------------------------------------
PersonPackage
Define the class Person (as specified in the problem above) in a package in.trisect.person. Define
the sub-classes Student and Faculty in a different package in.trisect.college. See what changes
are required to make the code work.
---------------------------------------------------------------------------------------------------------------------
AbstractPersonPackage
Define the class Person (as specified in the problem above) as an abstract class. Define the
sub-classes Student and Faculty. See what changes are required to make the code work.
---------------------------------------------------------------------------------------------------------------------
PrivateShape
Define a class Shape with the member color and methods getPerimeter, getArea and display. The
method display prints the color, perimeter and area. For Shape, the methods getPerimeter and
getArea return 0. Extend Shape to Circle, Rectangle and Square. Make the data members of
Shape private. Modify your code to get it code working with private data members. Also, draw
the class diagram.
---------------------------------------------------------------------------------------------------------------------
PrivatePerson
Create a class Person with name, dateOfBirth and a method display which displays all the fields
in a single line. Make all the data members private. Extend Person to create Student and Faculty.
Student has an additional field collegeName and Faculty has an additional field subject. They
also override display method to display all the values in a single line. Modify you code to get it
code working with private data members. Also, draw the class diagram.
__________________________________________________________
Module 4d- 2 class

In a one day international, the bowling figures of all the bowlers have been provided. The
organizers have asked you to help them figure out who bowled the best. The approach is to
award points to each bowler and then choose the bowler with the highest points.
The points are given for maiden overs, economy and wickets. Each wicket carries 10 points.
Each maiden over bowled carries 2 points. A bowler who has conceded lesser runs than what the
overall run rate indicates, gets points equivalent to the runs he saved.
For e.g. if a bowler bowled 4 overs and conceded 21 runs while the overall runrate was 6.4 runs
per over, the bowler will get 4*6.4 – 21 = 4.6 economy points. However, if the bowler bowled 6
over for 45 runs while the overage average was 6.3 gets 6*6.3 – 45 = -7.2 economy points. Note
that the overall run rate can be computed by adding the runs and then dividing them by the total
number of overs bowled.
The input is provided as 2 arrays of the object Bowler. The Bowler object has fields
corresponding to name, overs, maidens, runs conceded and wickets. You can download the base
classes here. Also draw the class diagram for this problem.

PFA: the class required to solve the above problem

__________________________________________________________
Modue 4d- 4 (30-jan-2015)
Words in para
Given a paragraph, return a vector consisting of all the words in the para. The words in the
paragraph are separated by space. If para is “How are you today”, the output vector consists of
the words – How, are, you, today
---------------------------------------------------------------------------------------------------------------------
Distinct numbers in string
Given a string, return a vector of Integer consisting of all the distinct numbers in the para. The
numbers in the string are separated by space. If para is “88 99 22 33 44 55 88 22 55 100″, the
output vector consists of the numbers – 88,99,22,33,44,55,100
---------------------------------------------------------------------------------------------------------------------
Flight Tickets
Given the details of flights as input, create a vector of the object Ticket. Note that the tickets
should appear in the vector in the same order as the input.
The details have been provided as a String[]. Each item in the array corresponds to a ticket and
has the following space separated details: Origin, destination, departure, arrival, amount. For e.g.
a string in the String[] can be “Delhi Mumbai 0700 0920 5850″.
---------------------------------------------------------------------------------------------------------------------

Zoo Animals
Given a zoo, the objective is to compute the food requirements of the zoo as well create a count
of various animals. All these values are to be stored in the object ZooAnimals.
There is a function foodCalc(String[] animalDetails, String[] animalList) in the class
ZooFoodSystem which needs to be defined. Note that while returning the object ZooAnimals, all
the fields in the object should have the correct values. The inputs to the function foodCalc are
String[] animalDetails : Name, Food type (carnivore / herbivore) and amount of daily food
consumption.
String[] animalList : List of all animals found in the zoo. An animal will occur as many times in
the list as they are in the zoo.
The following Java files has been provided as download – Animal, AnimalCount and
ZooAnimals. Also draw the class diagrams. Download files for Zoo Animals
---------------------------------------------------------------------------------------------------------------------

Billing Counter
The problem here simulates the action of the billing counter of a department store.Two inputs
have been provided as String[], master and billscan. The String[] master, contains the following
details for each product : code, description, price and applicable discount. The String[] billscan
consists of the codes being scanned at the billing counter. Note that billscan can have the same
code appear multiple times.
The objective is to generate the itemized bill for the billscan provided. The itemized bill is an
object of the class ItemizedBill and consists of a Vector of BillItems and the total value of the
bill. Each BillItem corresponds to the different products being purchased at the counter. The
quantity purchased is reflected in the quantity field of the BillItem.
You have been provided the following Java files in the download, Product, ProductMaster,
BillItem, ItemizedBill and BillingCounter. Also draw the class diagram for this
problem. Download files for Billing Counter
Next download do…Class link for Monday 2nd February 5 pm:class link

Module 5a-1
Zoo Animals
Given a zoo, the objective is to compute the food requirements of the zoo as well create a count
of various animals. All these values are to be stored in the object ZooAnimals.
There is a function foodCalc(String[] animalDetails, String[] animalList) in the class
ZooFoodSystem which needs to be defined. Note that while returning the object ZooAnimals, all
the fields in the object should have the correct values. The inputs to the function foodCalc are
String[] animalDetails : Name, Food type (carnivore / herbivore) and amount of daily food
consumption.
String[] animalList : List of all animals found in the zoo. An animal will occur as many times in
the list as they are in the zoo.
The following Java files has been provided as download – Animal, AnimalCount and
ZooAnimals. Also draw the class diagrams. Download files for Zoo Animals
---------------------------------------------------------------------------------------------------------------------

Billing Counter
The problem here simulates the action of the billing counter of a department store.Two inputs
have been provided as String[], master and billscan. The String[] master, contains the following
details for each product : code, description, price and applicable discount. The String[] billscan
consists of the codes being scanned at the billing counter. Note that billscan can have the same
code appear multiple times.
The objective is to generate the itemized bill for the billscan provided. The itemized bill is an
object of the class ItemizedBill and consists of a Vector of BillItems and the total value of the
bill. Each BillItem corresponds to the different products being purchased at the counter. The
quantity purchased is reflected in the quantity field of the BillItem.
You have been provided the following Java files in the download, Product, ProductMaster,
BillItem, ItemizedBill and BillingCounter. Also draw the class diagram for this problem. Download
files for Billing Counter

______________________________________________________________________________
MODULE 5b-1

Bubble sort of numbers


Given an array of integers and a string which has the values “ascending” or “descending” as
input, sort them in ascending / descending order as specified by the input string
using bubble sort.
bubbleSort({1,4,2,3},”ascending”) = {1,2,3,4}
bubbleSort({11,4,8,12},”descending”) = {12,11,8,4}
---------------------------------------------------------------------------------------------------------------------
Bubble sort of fn of digits
Given an array of integers and a string which has the values “ascending” or “descending” as
input, sort them in ascending / descending order as specified by the input string
using bubble sort. Define for num1, a function prod(num1) which is the product of digits of
num1 and a function sum(num1) which is the sum of digits of num1.
num1 is greater than num2 if
- prod(num1) > prod(num2)
- prod(num1>=prod(num2) and sum(num1)>sum(num2)
- prod(num1)=prod(num2), sum(num1)=sum(num2), and num1>num2.
bubbleSort({18,24,44,8},”ascending”) = {24,8,18,44}
bubbleSort({33,19,91,9,133},”descending”) = {91,19,9,133,33}
---------------------------------------------------------------------------------------------------------------------
Bubble sort of strings
Given an array of strings as input, sort them in ascending order using bubble sort.
bubbleSort({“hello”,”how”,”are”,”you”,”little”,”angel”} =
{“angel”,”are”,”hello”,”how”,”little”,”you”}
---------------------------------------------------------------------------------------------------------------------

Bubble Sort – Large Numbers


An array of String, nums, has been provided as input. Each String represents a non negative
integer. The integers can be very large and hence have been stored as strings. The array has to
be sorted in ascending order of the integer value of the strings.
bubbleSort({“999″,”723534″,”99″,”18456543876″,”54253445340001″,”99″,”112343″,})={“99″,
”99″,”999″,”112343″,”723534″,”18456543876″,”54253445340001″}

---------------------------------------------------------------------------------------------------------------------
Ranking students in a section
Given the students of a section in a school, the objective is to order the students as per their total
marks in descending order.
The marks for each student are provided in the object Student, while the object Section
represents all the students in the class.
If two students have the same total marks, they will be ordered based on their marks in the
subjects.
The inputs provided are two String[]. The first String[] consists of name of student followed by
his/her marks in all the subjects. The second String[] is the list of all subjects. The order of
subjects in figuring out the rank in case total marks for two students are identical is the same as
the order of the subjects provided in this input.
The output is the object Section in which the students in Vector have been ordered on rank. You
can download the base classes here. Also draw the class diagram for this problem.
______________________________________________________________________________
Module 5b-2
Max cities
You have been given a Vector as input. Each element in the vector is of type “Country:City”.
Find out the country which has the maximum number of cities. You can assume that there is only
1 country with maximum number of cities in the input.
---------------------------------------------------------------------------------------------------------------------
Same Numbers , Same Count
Given two arrays of int, determine if they both contain the same numbers. Note that a number
can appear more than once in each array. Also note that if a number that is present n times in the
first input array, it should be present n in the second input array. And vice-versa, if a number is
present m times in the second input array should be present m times in the first input array. Do
not use sorting to solve this problem. Use HashMap to solve this problem.
---------------------------------------------------------------------------------------------------------------------

De-Duplicate
Given a String array of words as input, remove all duplicates and return a Vector of all the
unique strings. Use Hashtable to solve this problem. After solving it, solve the same problem
using HashSet instead of Hashtable.
---------------------------------------------------------------------------------------------------------------------
Same Strings (No duplicates)
Given two arrays of Strings, determine if they both contain the same strings. Note that no string
will appear more than once in each array. Do not use sorting to solve this problem. Also use
HashSet to solve this problem.
---------------------------------------------------------------------------------------------------------------------
Max cities
You have been given a Vector as input. Each element in the vector is of type “Country:City”.
Find out the country which has the maximum number of cities. You can assume that there is only
1 country with maximum number of cities in the input.

Moduel 5b-3
Same Strings (No duplicates)
Given two arrays of Strings, determine if they both contain the same strings. Note that no string
will appear more than once in each array. Do not use sorting to solve this problem. Also use
HashSet to solve this problem.

Max cities
You have been given a Vector as input. Each element in the vector is of type “Country:City”.
Find out the country which has the maximum number of cities. You can assume that there is only
1 country with maximum number of cities in the input.
Shopping System
This problem simulates the functioning of a department store.
Product represents all the different products in the department store
ProductMaster is the master of all the Product(s) in the department store
Scheme represents all the schemes and offers running in the store. They have two fields, quantity
and discount. Quantity represents the minimum quantity a shopper needs to purchase to qualify
for the discount.
ItemizedBill represents the bill of a shopper
BillItem represents each line item in the ItemizedBill of the shopper
BillingCounter represents all the bills that a billing counter has issued in a day
Given the list of products, schemes and the scan details at the billing counter, process the details
and return the object BillingCounter. In the scan details that have been provided as input, a bill
for a shopper starts with the string START:num where num represents the id of the bill. A bill
for a shopper ends with “STOP”.
The following Java filed has been provided as download – Product, ProductMaster, Scheme,
BillItem, ItemizedBill and BillingCounter. Also draw the class diagram for this problem.
__________________________________________________________
Module 5b- 4
Shopping System
This problem simulates the functioning of a department store.
Product represents all the different products in the department store
ProductMaster is the master of all the Product(s) in the department store
Scheme represents all the schemes and offers running in the store. They have two fields, quantity
and discount. Quantity represents the minimum quantity a shopper needs to purchase to qualify
for the discount.
ItemizedBill represents the bill of a shopper
BillItem represents each line item in the ItemizedBill of the shopper
BillingCounter represents all the bills that a billing counter has issued in a day
Given the list of products, schemes and the scan details at the billing counter, process the details
and return the object BillingCounter. In the scan details that have been provided as input, a bill
for a shopper starts with the string START:num where num represents the id of the bill. A bill
for a shopper ends with “STOP”.
The following Java filed has been provided as download – Product, ProductMaster, Scheme,
BillItem, ItemizedBill and BillingCounter. Also draw the class diagram for this problem.

READING LINKS:

Javadoc – Throwable
Javadoc – Exception
What is an Exception
The Catch or Specify Requirement
Catching and Handling Exceptions
The try Block
The catch Blocks
______________________________________________________________________________

Module 5b- 5

Basic Linked List functions


The objective of this exercise is to implement the class BasicList1 which implements the
interface ListInterface. The functions defined in ListInterface are insert, hasElement, elements
and length.
Note that the function getBasicList has been defined and should not be modified. Download files

---------------------------------------------------------------------------------------------------------------------
Basic Linked List functions – 2
The objective of this exercise is to implement the class BasicList2 which implements the
interface ListInterfaceAdvanced. The functions defined in ListInterface are insert, hasElement,
elements, length, delete and reverse. Note that the function getBasicList has been defined and
should not be modified. Download files
---------------------------------------------------------------------------------------------------------------------
Count prime nodes
You have been given the head of a linked list as input. Each node of the linked list stores 2 ints,
n1 and n2. Define a function that will count all those nodes from the linked list for which at least
one of n1 or n2 is a prime number.
---------------------------------------------------------------------------------------------------------------------
Sum of neighbours
You have been given the head of a linked list as input. Each node of the linked list has 2 values
of type int, myNum and sum3. The field myNum stores the value pertaining to that node. The
field sum3 stores the sum of myNum for that node as well as the previous and next node. If the
previous or next node is not present, it will only sum the relevant values. In the input linked list,
the value of sum3 has not been computed. Define a function that will compute and assign the
correct value of sum3 for each node in the linked list.

_____________________________________________________________________________________________
Module 5b- 6

Basic Linked List functions – 2


The objective of this exercise is to implement the class BasicList2 which implements the
interface ListInterfaceAdvanced. The functions defined in ListInterface are insert, hasElement,
elements, length, delete and reverse. Note that the function getBasicList has been defined and
should not be modified.
PFA:Files to solve basic linked list functions- 2
---------------------------------------------------------------------------------------------------------------------
Sum of neighbours
You have been given the head of a linked list as input. Each node of the linked list has 2 values
of type int, myNum and sum3. The field myNum stores the value pertaining to that node. The
field sum3 stores the sum of myNum for that node as well as the previous and next node. If the
previous or next node is not present, it will only sum the relevant values. In the input linked list,
the value of sum3 has not been computed. Define a function that will compute and assign the
correct value of sum3 for each node in the linked list.
---------------------------------------------------------------------------------------------------------------------
Remove nodes with duplicate chars
You have been given the head of a linked list as input. Each node of the linked list stores a string
data. If the field “data” has any char that is repeated in it, it has to removed from the list. Define
a function that will remove all those nodes from the linked list for which the field data has a char
that is present more than once in it.
---------------------------------------------------------------------------------------------------------------------
Find kth node
You have been given the head of a linked list and an integer k as input. Define a function which
returns the kth element from the end of the input linked list in one loop only. You cannot use any
collection / array. Also the input linked list should not be modified in any manner. If k is greater
than the length of the linked list return null.
---------------------------------------------------------------------------------------------------------------------
Loop in list – store node approach
You have been given the head of a linked list input. Find out whether the linked list has a loop in
it or not. The approach to be used is to save all the nodes and check if you find any node that you
have already saved. Solve it using vector and then solve it using HashSet.
---------------------------------------------------------------------------------------------------------------------
Loop in list – tortoise hare approach
You have been given the head of a linked list input. Find out whether the linked list has a loop in
it or not. The approach to be used is to traverse the list using two different speeds
simultaneously. In traverse1 (hare) move 2 nodes at an instance, while traverse2 (tortoise) is the
normal traversal. If you land on the same node in both the traversals, what does it tell you.
---------------------------------------------------------------------------------------------------------------------
Merge linked lists
You have been given the 2 linked lists as input. Both the linked list consist of a data of type int
and are sorted in ascending order. The objective is to return a merged Linked List which is also
sorted in ascending order. Note that should not create any extra node of the linked list nor use
collections or arrays.

You might also like