Zoho 2nd and 3rd Round Coding Questions PDF Free
Zoho 2nd and 3rd Round Coding Questions PDF Free
Input:i l
i k e Output
:Yes
Thestringcanbesegmentedas"ilike".
Input:ilikesamsun
3. Print the following pattern
gOutput:Yes
1
Thestringcanbesegmentedas"ilikesamsung"or"
32
654
10987
10987
654
32
1
Output:421280000 0.
class GFG {
int j = len - 1 - i;
if (k == i || k == j)
System.out.print(str.charAt(k));
else
System.out.print(" ");
System.out.println("");
pattern(str, len);
9. From the input sentence given, find the strings which are not
palindrome and print it. Input: he knows malayalam
Output: he knows
10. Given two Strings s1 and s2, remove all the characters from s1 which is present in s2.
Input: s1=”expErIence”,
s2=”En” output: s1=”exprIece”
https://www.geeksforgeeks.org/given-a-number-find-next-smallest-palindrome-
larger-than- this-number
https://code.sololearn.com/cIwVvehBp5p3/?ref=app
14. Given an array with repeated numbers, Find the top three repeated
numbers. input: array[]={3, 4, 2, 3, 16, 3, 15, 16, 15, 15, 16, 2, 3}
output: 3, 16, 15
https://code.sololearn.com/cwpdMh2NU17G/?ref=app
15. 1.Given two dimensional matrix of integer and print the rectangle can be
formed using given indices and also find the sum of the elements in the
rectangle
Input: mat[M][N] = {{1, 2, 3, 4, 6}, {5, 3, 8, 1, 2}, {4, 6, 7, 5, 5}, {2, 4, 8, 9, 4} };
index = (2, 0) and
(3, 4) Output:
Rectangl
e4675
5
24894
sum 54
16. Find the result subtraction, multiplication, division of two integers using +
operator.
Input: 6 a 4
n
d
output:
addition 6+4 = subtraction 6+(-4) multiplication = 24,
10, = 2, division = 1
Input : -8 and -
4 Output:
addition -8+(-4) = -12, subtraction (-8)+(-(-4)) = -4,
multiplication = 32, division = 2
17. Given a sentence of string, in that remove the palindrome words and
print the remaining.
Input:
He did a good
deed Output:
He good
Input:
Hari speaks
malayalam Output:
Hari speaks
18. Given two dates, find total number of days between them.
Input: dt1 = {10, 2, 2014} dt2 = {10, 3, 2015}
Output: 393
dt1 represents “10-Feb-2014” and dt2 represents “10-Mar-2015” The
difference is 365 + 28
Input: dt1 = {10, 2, 2000} dt2 = {10, 3, 2000}
Output: 29
Note that 2000 is a leap year
Input: dt1 = {10, 2, 2000} dt2 = {10, 2, 2000}
Output: 0
Both dates are same
Input: dt1 = {1, 2, 2000}; dt2 = {1, 2, 2004};
Output: 1461
Number of days is 365*4 + 1
19. Let 1 represent ‘A’, 2 represents ‘B’, etc. Given a digit sequence, count
the number of possible decodings of the given digit sequence.
Examples:
Input: digits[] =
“121” Output: 3 // The possible decodings are
“ABA”, “AU”, “LA”
Input: digits[] = “1234” Output: 3
// The possible decodings are “ABCD”, “LCD”, “AWD”
https://code.sololearn.com/ckvAG662AhVA/?ref=app
https://www.geeksforgeeks.org/convert-sentence-equivalent-mobile-numeric-
keypad- sequence/
Ex I/p
abcccccbba O/p
8 (from a to a)
I/p aaaaaaaa
O/p 6
Solution - https://code.sololearn.com/cladNMMuENGD/?ref=app
https://code.sololearn.com/czDUJv0giQYz/?ref=app
21. sort the array odd numbers in ascending and even numbers in
descending. I/p 5 8 11 6 2 1 7
O/p 1 5 7 11 8 6 2
https://code.sololearn.com/cGWZ8TOePPow/?ref=app
22. It’s about anagram.i/p was array of strings .and a word was given to find
whether it has anagram in given array.
I/p catch, got, tiger, mat, eat, Pat,
tap, tea Word: ate
O/p eat, tea
https://code.sololearn.com/cMwfOglVKBgn/?ref=app
23. array of numbers were given to find a number which has same sum of
numbers in it’s either side.
I/p 1, 2, 3, 7, 6
O/p 7(has 1+ 2+3 in left 6 in right)
https://code.sololearn.com/cw2ow36miDEF/?ref=app
https://code.sololearn.com/cgVY6y197qYy/?ref=app
https://code.sololearn.com/c3A7Hnl22FId/?ref=app
https://www.geeksforgeeks.org/program-to-print-first-n-prime-numbers/
28. prime factor – sort the array based on the minimum factor they have.
https://code.sololearn.com/cx4ZdN5fFkJR/?ref=app
29. adding a digit to all the digits of a number eg digit=4, number = 2875, o/p= 612119
https://code.sololearn.com/cPx7SZGkCMGL/?ref=app
https://code.sololearn.com/ceREaQ9hsQ00/?ref=app
31. given a set of numbers, and a digit in each iteration, if the digit exists in any of the
numbers, remove its occurrences and ask for the next digit till the list becomes empty.
Input:[ 20, 7]
35.[ Sort
11, the array
5] elements in descending order according to their frequency of
Input :[-1, 0,3,2]
occurrence
Output:[ 1, 3] 2]
[ 3,4,0,-1,
Output :3 333222121245
Explanation : 3 occurred 4 times, 2 occurred 3 times, 12 occurred 2 times, 4
occurred 1
time, 5 occurred 1 time
Input :[0-121 0]
sort single
Output occurrence
:00-112 elements in ascending order
36. Print true if second string is a substring of first string, else print false.
Output:28
39. Print pattern like this
Input: 1106813 21
Exampl
Output:1 81321
e:Input
:1
Output:0
Input
:2Outpu
t:00
01
10
11
Input
:3Outpu
t:000
001
010
011
100
101
110
111
Input:
N
=
4
1 0
1 0
1 0
0 1
1 1
1 1
Output:
_ 1 00 0
0
0 1
_ 0 0 1
_ _ _ _
000_
Numberofbits:12
42. Evaluate given expression which has factorials and exponential terms.
Bits: 101101 101111
ConsecutiveK:2
43. To implement snake and ladder game for given two-dimensional array
having position of snakes and ladders
Output:
1011001100110110
44.To calculate strength of the password string using some predefined rules
given in the question
45.Given four points, We have to say whether it is square or rectangle or any other
shape
53. Print the total number of odd and even digits in the given number.
Ex.I N P U T :
Output:ODD
SizeofArray :8
Ex.I N P U T :
SizeofArray :4
Enter the elements: 4 1 22
OUTPUT:
Ex.I N P U T :
SizeofArray :1En
terthe elements: 1
OUTPUT:
11
121
1331
14641
Ex.I N P U T : 7
OUTPUT:
11
121
1331
14641
56. Given a two dimensional array which consists of only 0’s and 1’s. Print the
matrix without duplication.
Ex. INPUT :
1 0
1
1 1
0
1 1
1
1 0
1
OUTPUT :
Unique Matrix :
1 0 1
1 1 0
111
57. Given an array of positive numbers. Print the numbers which have longest
continuous range.
Ex.I N P U T :
Enter sizeoffirst
OUTPUT:
array :6 Entertheelements :
1 2 3 4 5 3Enter size of second
array: 4 Entertheelements :
1234
1 275
Ex.I N P U T :
Enter arraysize: 8
OUTPUT:
59. Given an array of numbers. Print the numbers without duplication.
60. Given an array of numbers and a number k. Print the maximum possible k
INPUT:
digit number which can be formed using given numbers.
INPUT:
Enter the array
size: 4 Entertheelements:
Enterthearray
1124 size: 4
OUTPUT:
974
INPUT:
Enterthearray size: 6
Enter the elements:1 4 89 73 9
7Enternumber ofdigits: 5
61. Given an array of numbers and a window of size k. Print the maximum of
numbers inside the window for each step as the window moves from the
beginning of the array.
INPUT:
62. Find the minimum number of times required to represent a number as sum
of squares.
Enterthearray size: 8
12=1^2+1^2+1^2+1^2+1^2+1^2+
Enter the
1^2+1^2+1^2+1^2+1^2+1^2
elements:1,3,5,2,1,8,6,9Enterthew
63. Search a string in a given 2D matrix. And print its
12=2^2+2^2
possible +2^2 allowed movements are right left up and
path.
indow size:3
down.
12=3^2+1^2 +1^2
OUTPUT:
64.
Input:12 In a given pascal triangle find the possible triangles.
Output:min:3
65. in a matrix find the number of rectangles filled with 1s.
Input: 1 0
1
0
1 1 0
1
0 0 1
1
0 0 1
1
Output: 2.
66. There are n items each with a value and weight. A sack is filled with the
weights. In other words there is an array with of length n having the values of
the items arr[0…n-1] and another array with weight arr[0…n-1].
if a sack is to be filled with weight W find the minimum possible value subset.
68. Take a 2 or 3 digit input number, reverse it and add it to the original
number until the obtained number is a palindrome or 5 iterations are
completed.
Input : n = 32
Output : 55
23 + 32 = 55 which is a
palindrome.
Input : 39
Output :
363
69. Given a string, reverse only vowels in it; leaving rest of the string as it is.
Input :
abcdef Output : ebcdaf
70. Write a program to check if the given words are present in matrix given
below. The words can be left to right, top to bottom and the diagonals (in top
to bottom direction)
71. Write a program to form lines using given set of words. The line formation
should follow below rules.
i) Total characters in a single line excluding the space between the words and
the favorite character should not exceed the given number.
ii) Favorite character is case insensitive.
iii) Words should not be broken up. Complete words alone should be used in
a single line. A word should be used in one line only.
Input : Max char per line =
10Favoritecharacter=
'o'
Words : Zoho, Eating, Watching,
PogoLoving,Mango
Output:WatchingZoho
Eating
MangoLoving
72. Adding 2 numbers
GIven 2 huge numbers as seperate digits, store them in
array and process them and calculate the sum of 2 numbers
and store the result in an array and print the sum.
Input:
Number of
digits:12 9 2 8 1 3 5 6 7 3 1
1 6
Number of
digits:9 7 8 4 6 2 1 9 9
7
Output :
928920295113
1
0
output =
0.5
Hint : The equation sin(x) = x – x^3 / 3! + x^5 / 5! – ….
78. Given an odd length word which should be printed from the middle of
the word. The output should be in the
following pattern. Example:
Input:PROGRA
MOutput:
79. It is a program to implement Least Recently Used (LRU) concept. Given a
key, if it is Galready existed then it should be marked as recently used otherwise
a value should
G be stored which is given as input and marked as recently used.
The capacity is to store only 10 key, value pairs. If the table is full and given a
RG
new key; the key, value pair which is not recently used should be deleted which
gives feasibility
RA to store the new key, value pair.
GR
AMGR
80. Given a few pairs of names in the order child, father. The input is a person
nameAMP and level number. The output should be the number of children in that
particular level for the person
given.
Example:
Input:
[
{Ram, Syam},
{Akil, Syam},
{Nikil, Ram},
{Subhash, Ram},
{Karthik, Akil}
];
Syam 2
Output: 3 (Syam has Ram and Akil in level 1 and in level 2 he have Nikil,
Subhash, Karthik. So the answer is 3).
81. Given an array of positive integers. The output should be the number of
occurrences of each
number.
Example:
Input: {2, 3, 2, 6, 1, 6, 2}
Output:
1–1
2–3
3–1
6–2
82. sort numbers based on digits starting from most significant numbers. Eg:
input-100 1 11 21 2 3. Output-1 100 11 2 21 3
83. Given an array, find the minimum of all the greater numbers for each
element in the array.
84. Find the largest sum contiguous subarray which should not have negative
Sample:
numbers. We have to print the sum and the corresponding array elements which
brought up the sum.
Array:{2,3,7,1,8,5,11}
Output:
Sample:
Array:{2,7, 5,1,3,2,9,7}
Output:
Sum:14
85. Given a string, we have to reverse the string without changing the
position of punctuations and spaces.
86. Given
Sample: a 2D
house no grid of
characters, you have to search for all the words in a
: 123@
dictionary by moving only along two directions, either right or down. Print
cbeOutput:
the word if it occurs.
87. Given a string, change the order of words in the string (last string should
Sample:
come first). Should use RECURSION
a zo l
n xh o
v Given
88. y i a number,
v convert it into corresponding alphabet.
Sample:
o r se
Dictionary={van,zoho,love,are,is}
Output:
zo
ho
lo
InputOutput
1 A
1. Z
2. AA
676 ZZZ
90. Write a program to print all permutations of a given string. Note here you
need to take all combinations as well, say for the input ABC the output
should be as follows:
Input:ABC
Output:
A91. Write a program to rotate an n*n matrix 90,180,270,360 degree.
Bhttps://www.geeksforgeeks.org/inplace-rotate-square-matrix-by-90-degrees/ is
Cthe solution for rotating a matrix 90 degree. For rotating the matrix
ABAC BABCCA CB
180,270,360 degree, u need to call the same method 2,3,4 times based on the
ABCACBBCABACCBACAB
input.
92. https://www.geeksforgeeks.org/reverse-words-in-a-given-string/
Input Output
72581 7(2+5)81
77(8-1)
777
cannot create a mono digit number
3962
94. You’re given an array. Print the elements of the array which are greater than its previous
elements in the
array.
Input : 2, -3, -4, 5, 9, 7, 8 Output: 2 5 9 You should solve this question in O(n) time.
95.
You’re given an even number n. If n=4, you have to print the following
pattern : 4444
4334
4334
4444
96. You’re given a number n. If write all the numbers from 1 to n in a paper, we have to find
the number of characters written on the paper.For example if n=13, the output should be 18
if n = 101, the output should be 195
97.A number is called as binary-decimal if all the digits in the number should be
either ‘1’ or ‘0’. Any number can be written as a sum of binary-decimals. Our
task is to find the minimum number of binary-decimals to represent a
number.Input : 32Output : 10 11 11
Input : 120
Output : 10 110
98. You’re given a string as an input. You have to reverse the string by keeping
the punctuation and spaces. You have to modify the source string itself with
creating an another string.
Input :A man, in the boat says : I see 1-2-3 in the sky
Output :
y kse, ht ni3 21ee slsy : a sta o-b-e ht nin amA
99. Given two numbers a and b both < 200 we have to find the square
numbers which lie between a and b(inclusive)
eg)i/pa =20;b=sort
Alternately 100;an unsorted array..
o/p25,36,49,64,81,100
eg)i/p{5,2,8,7,4,3,9}
o/p{9,2,8,3,7,4,5}
100.Given an array and a threshold value find the o/p
5 o/p1 0 0 0 1 1 {3,2} 2
8b.The two numbers were
{3,3,2}
given in 3
10 {3,3,3,1}
base neg)a=123b =13n =4 4
13 o/p2 0 2{3,3,3,3,1} 5
6 {3,3} 2
2 {2} 1
102. Write a program to print the below pattern
for n = 6
103. Given
1 bigger7 NxN matrix
12 and
16a smaller
19 MxM21 matrix print TRUE if the smaller
matrix can
2 be found
8 in the
13 bigger
17 matrix
20else print FALSE
3 9 14 18
4 10 15
104. Given two matrices a and b both of size NxN find if matrix a can
5 11
be transformed to matrix b by rotating it 90deg , 180deg , 270deg if so print
TRUE else print FALSE
6
105. In addition to the above question you have to check if matrix a can
be transformed by mirroring vertically or horizontally to matrix b.
106. Given an array of integers, rearrange the array in such a way that the
first element is first maximum and second element is first minimum.
Eg.)Input: {1,2, 3,4, 5, 6,7}
Input:
108. Form a number system with only 3 and 4. Find the nth number of the
number system. Eg.) The numbers are: 3, 4, 33, 34, 43, 44, 333, 334, 343,
344, 433, 434, 443, 444, 3333, 3334, 3343, 3344, 3433, 3434, 3443, 3444 ….
Array2:2,3,4,5,6,7,8,9,11,15
Output:
Mergedarray:2,3,4,5,6,7,8,9,10,11,13,15
112. Find if a String2 is substring of String1. If it is, return the index of the first
occurrence. else return -1.
113. Write
Eg1:Input:a program to print the following output for the given input. You can
assume the string is of odd length
String1:test123string
String2:123
Output:4
Eg2:Input:
1 5
String1:testing12
2 4
String2:1234
3
Output:-1
2 4
1 5
Eg Input:
2: geeksforgeeks
Eg 1: Input: 12345
Output:
Output:
g s
e k
e e
k e
s g
f r
f r
s g
k e
e e
e k
g s
114. Write a program to sort the elements in odd positions in descending
order and elements in ascending order
Eg1:Input:13,24,15,12,10,5
Output:13,2,12,10,5,15,4
115. Write a program to give the following output for the given input
Eg2:Input:1,2,3,4,5,6,7,8,9
Eg1:Input:a1b10
Output:9,2,7,4,5,6,3,8,1
Output:
abbbbbbbbbbEg:2: Input:
b3c6d15
Output:
bbbccccccdddddddddddddddThenumber
ADVANCED CODING
1.
6. This time all the questions were based on matrix. I got 6 programs, again
you get the next program after you complete the current program. All the
programs were just an addition to the previous one. Here the concepts to
be strong about were logic for diagonals ( all the four, top-left, top-right,
bottom-left, bottom-right), finding the path in a matrix from source to
destination.
7. Lift system
There were 8 modules
1. Display the position of Lift
Lift :L1L2L3 L4L5
2. Assign Lift to the users
Input :25
Floor:0 0 0 0 0
Output:L1isassigned
Lift :L1L2L3 L4L5
Floor:5 0 0 0 0
10. Given a MxN matrix filled with ‘-‘ and you need to drop the balloons in
the desired columns starting from the bottom. You need to print the
matrix when a new balloon is
dropped.
You need to continue getting inputs until the box is full or until the user
chooses to stop.
TESTCASE:
---
- - -
- R -
- - -
- B -
- R -
R R -
Do you wish to continue(Y/N) :
Y Enter the column number :
2
Enter the color of the balloon : R
Contents of the matrix :
- R -
- B -
R R -
Program Stopped
Extended version of the previous problem. Now you need to quit when a row become filled
completely.
TEST CASE :
- B -
- R -
Do you wish to continue(Y/N) : Y
- B -
- R -
Extended version of the previous problem. Now you need to drop balloon in the first free cell
from left if the specified column is filled in every row.
TEST CASE :
- - -
B R -
B R R
Do you wish to continue(Y/N) : Y
Enter the column number : 2
Enter the color of the balloon :
R
Contents of the matrix :
- - -
- R -
B R R
Do you wish to continue(Y/N) :
Y Enter the column number :
2
Enter the color of the balloon :
B Contents of the matrix :
- - -
B R -
B R R
Do you wish to continue(Y/N) : N
Program terminated.
Extended version of the previous problem. If any column has three continuous balloons of
same colors then we need to burst them.
TEST CASE :
- - -
R R R
R R R
Do you wish to continue(Y/N) :
Y Enter the column number :
2
Enter the color of the balloon :
B Contents of the matrix :
- - -
R R -
R R R
Do you wish to continue(Y/N) :
Y Enter the column number :
2
Enter the color of the balloon :
R Contents of the matrix :
- - -
R R R
R R R
Do you wish to continue(Y/N) : Y
R-R
Do you wish to
continue(Y/N):NProgram
Terminated.
Extended version of the previous problem. Now you need to burst the three continuous
They insisted us to do it in a object oriented language. First they asked the design( what are all
the classes and objects & what data structure do you use).
Application description:
▪
▪ There are ‘n’ number of points in a highway out of which some points collect toll.
▪ Each toll has its own charging scheme according to the vehicles and whether
or not they are a VIP user.
▪ If they are VIP user, 20% discount apply.
▪ If the vehicle passes 3 toll gates, it has to pay in all the 3 toll gates
according to the scheme of respective tolls.
There were 4 modules.
1. Given the details of vehicle type, start and destination……display the total toll paid
during the journey and print the amount after applying the discount.
2. Display the details of all the tolls…..like what are all the vehicles(vehicle number) passed
that respective toll and the amount each vehicle paid……and the total amount
charged in that toll.
3. Display the details of all the vehicles …….like what are all the journeys did it
take….the start and destination of the same……tolls it passed during that
journey….amount paid in that journey…..and the total amount paid by that vehicle.
4. Assume the highway as a circular path……we have to find the short route and
identify the tolls between that route and calculate the amount.
14. We were asked to design an application program for n*n tic-tac-toe game.
Here, you are expected to code with proper standards and in a most
optimized way. And, in this round you need to find all the edge cases and
corner cases yourself. The interviewers won’t help you if you miss anything.
So, make sure you covered all the cases before showing output to the
interviewers.
https://www.geeksforgeeks.org/implementation-of-tic-tac-toe-game/
17 . text editor
Only 40 characters per line and words should be wrapped if
they brake Also perform insert delete operations
char
productname[20];in
tproduct_price;
intproduct_id;
Get the product name, price and id and display the product name and price in
descending of the price.
For the same above structure, now add another structure which is the category.
That category will have products in it.
Structcategory
According the category get the product name, product price and id, then
{display all the products category wise in descending order.
For
charthe same structure which as category and product, get the category id
from the user in the product structure and save to the category list. Then
category_name[20];in
display
t cat_id;
them all in category wise.
A sheet full of data will be given with inventory stock list, which as different
categories and different products as input with category capacity and
product availability in the structure. Now we need to add a new category or
new product with capacity and availability. Need to check whether the
product availability is exceeding the category capacity, if yes the output rack
is full or else tell how much free space is available and add the product to
list.
Constraints in the above in question will be given, need to solve all the
constraints
19. Design a Call taxi booking application
-There are n number of taxi’s. For simplicity, assume 4. But it should work for
any number of
taxi’s.
-The are 6 points(A,B,C,D,E,F)
-All the points are in a straight line, and each point is 15kms away from the
adjacent points.
-It takes 60 mins to travel from one point to another
-Each taxi charges Rs.100 minimum for the first 5 kilometers and Rs.10 for
the subsequent
kilometers.
-For simplicity, time can be entered as absolute time. Eg: 9hrs, 15hrs etc.
-All taxi’s are initially stationed at A.
-When a customer books a Taxi, a free taxi at that point is allocated
-If no free taxi is available at that point, a free taxi at the nearest point is
allocated.
-If two taxi’s are free at the same point, one with lower earning is allocated
-Note that the taxi only charges the customer from the pickup point to the
drop point. Not the distance it travels from an adjacent
point to pickup the customer.
-If no taxi is free at that time, booking is
rejected Design modules for
1)
CalltaxibookingInput
1:
Customer ID:
1Pickup
Point: ADrop
Point:
BPickupTime:
9
Output1:
Taxicanbeallotted.
Taxi-1isallotted
Input2:
Customer ID:
2Pickup
Point: BDrop
Point:
DPickupTime:
(Note: Since Taxi-1 would have completed its journey when second booking
is done, so Taxi-2 from nearest point A which is free is allocated)
These
Input3: were just sample inputs. It should work for any input that they give.
Those
Customer
who
ID:
finished both the modules within 3 hours and if it worked for all
Taxi No:Total Earnings:
the inputs they give, those candidates were given extra modules to work
BookingIDCustomerIDFromToPickupTimeDropTimeAmount
3Pickup
with.
Point: BDrop
Point:
Output:
Taxi-1Total Earnings: Rs. 400
CPickupTime:
12
1 1 AB910200
33BC1213200
Each of the 9 cells can either be empty or filled with an atom. R3, R2, R1 are
the rays that originate from the left. C1, C2, C3 are the rays that originate
from
R3|- the- bottom
-| of the box.
R2|- : Position
Input - -| of the atoms and the rays that gets originated from the outside
of the box.
R1|- - -|
Eg.)3
Rule 1:
A ray31that has an atom in its path should print ‘H’ (Hit) If it does not have any
atoms 22
in its path, the ray should pass to the other side.
Rule 13
C1 C3 2 & 3:
A ray3that has an atom in its diagonal adjacent position should refract.
R3 | --- | R3
H | -X- |
H| - R3 C1C3
- -|
R1 | --- | R1 C1 HC3
Output: Printthebox.
H | X-- |
R | -X- |
RHR
H | -X- |
R2 | --- | C3
| --- |
R2 C3
Rule 4:
A ray that has atoms in both of the diagonal adjacent positions should reflect
back.
Rule 5:
The deflection of rays should happen in the order of the input rays.
Inputray:C2
The
Inputfinal
|- Rays:
-
task was to implement
-|R3, R2, C1, C3
these rules for dynamic matrix size.
H | -X- |
|X - | X|
R2 --- | C3
| --- |
|- - -
|R
R2 C3
Inputray:R2
|- X
-|
R| - - -
Input : no of rows, no of
columnsEg.) 44 (row& column)
2(Noofatoms)
44(Positionofatom)
22(Positionofatom)
2(Noofrays)
R4C2(Raynumber)
H| - - - X|
|- - - -|
|- X - -|
|- - - -|
H
The final task was very confusing and it had to handle all the cases. There
are chances for a ray to end at the starting position if the number of rows
and columns are more than 5.