-
Notifications
You must be signed in to change notification settings - Fork 3
/
problem_instructions.txt
1281 lines (862 loc) · 32.2 KB
/
problem_instructions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
=========================
Day 0: Print Hello World!
=========================
For this challenge, all you have to do is print the following two lines:
Hello World.
Welcome to 30 Days of Code.
==================
Day 1: Data Types!
==================
For this challenge, consider the following inputs (you don't need to read any input):
5.35
'a'
false
100
"I am a code monkey"
true
17.3
'c'
"derp"
For each line above, print out if it is an instance of a primitive or referenced type
as well as which data type it is (using the typical examples above).
Note: This challenge is focused only on Java data types, but you can submit the answer
in other languages as well. Hint: In Java, String is a referenced type. Most challenges
in upcoming days are language-agnostic.
> Output Format
Output 9 lines. Print one line for each of the input given above in the following format:
MainDataTypeOfInstance : SpecificDataTypeOfInstance
For example, if the input is:
123
Your output should be:
Primitive : int
Make sure you spell everything correctly and capitalize your entries. Also, don't forget
spaces and colon in between the main and specific data types!
==================
Day 2: Arithmetic!
==================
Practice how to do arithmetic with code in this challenge! If given the meal price,
tip percentage, and tax percentage, we can find the final price of a meal.
> Input Format
Three numbers, (M, T, and X), each on separate lines:
- M will be a double representing the original price of the meal.
- T will be a integer representing the percentage that the customer wants to tip based
off of the original price of the meal.
- X will be an integer representing the tax percentage that the customer has to pay
based off of the original price of the meal.
> Output Format
A string stating... "The final price of the meal is $-."
where the final price of the meal is substituted for the dash. The price should be
rounded to the nearest integer (dollar) - the code for rounding has already been added
in the editor if you are coding in Java.
> Sample Input
12.00
20
8
> Sample Output
The final price of the meal is $15.
> Explanation
M = 12, T = 20, X = 8
tip = (20 * 12) / 100 = 2.4
tax = (8 * 12) / 100 = 0.96
final price = 12 + 2.4 + 0.96 = 15.36
Officially, the price of the meal is $15.36, but rounded to the nearest dollar (integer),
the meal is $15.
==========================
Day 3: If-Else Statements!
==========================
This problem will test your knowledge on "if-else" statements.
Given an integer N as input, check the following:
If N is odd, print "Weird".
If N is even and, in between the range of 2 and 5(inclusive), print "Not Weird".
If N is even and, in between the range of 6 and 20(inclusive), print "Weird".
If N is even and N>20, print "Not Weird".
We have given you partially completed code in the editor, complete it to solve the problem.
> Input Format
There is a single line of input: integer N.
> Constraints
1 <= N <= 100
> Output Format
Print "Weird" if the number is weird. Otherwise, print "Not Weird".
Do not print the quotation marks.
> Sample Input 1
3
> Sample Output 1
Weird
==============================================
Day 4: Logical Operators + Class vs. Instance!
==============================================
You will create a class Person and write a constructor that takes an integer, initial_Age.
In this constructor, you should check that the initial_Age is not negative because we
can't have people with negative ages.
If the initial_Age is negative, set the instance's age equal to zero then print:
"This person is not valid, setting age to 0."
without the quotations..
Inside of this class, you will also create an instance variable called age and if
initial_Age is not negative, then you will set age to equal the value of initial_Age.
In addition, you will write an instance method, amIOld(), that prints whether people
are old or not to the console.
In amIOld(), do the following things:
If the age of the Person instance is less than 13, then print "You are young."
If the age of the Person instance is equal or greater than 13, but less 18, print "You are a teenager."
Otherwise, print "You are old."
In addition, create an instance function called yearPasses() that increases the age of
the person instance by one.
Much of the structure of the code is given to you below, but in the future, you will
write this. The code that will create instances of your Person class is in the main
function. You may not understand it all yet, but take a look just to see what's going on.
Do not change any of the variable names or remove any of the code given.
> Input Format
First line contains T, number of test cases. Each test case contains an integer age,
representing age of the person.
> Constraints
1 <= T <=4
-5 <= age <= 30
> Output Format
The code that will test your methods is already in the editor. All you have to do is
edit the methods given to you in the editor so that they perform correctly as stated
above. If your methods are implemented correctly, each testcase will print out either
two or three lines.
If the age is less than zero, then your program should print out:
This person is not valid, setting age to 0.
You are young.
You are young.
If the age is equal or greater than 0, then your program should print out two lines.
The first line that the program prints out should be the output of amIOld() on the
current age. Then, three years pass via yearPasses() and the second line the program
prints should be the output of amIOld() after the time has passed.
> Sample Input
4
-1
10
16
18
> Sample Output
This person is not valid, setting age to 0.
You are young.
You are young.
You are young.
You are a teenager.
You are a teenager.
You are old.
You are old.
You are old.
=============
Day 5: Loops!
=============
In this problem you will test your knowledge of loops.
Given three integers a, b, and N, output the following series:
a+2^0*b, a + 2^0*b + 2^1*b, ......, a + 2^0*b + 2^1*b + ... + 2^(N-1)*b
> Input Format
The first line will contain the number of testcases T.
Each of the next T lines will have three integers, a, b, and N.
> Constraints
0 <= T <= 500
0 <=a, b <= 50
1 <= N <= 15
> Output Format
Print the answer to each test case in a separate line.
> Sample Input
2
5 3 5
0 2 10
> Sample Output
8 14 26 50 98
2 6 14 30 62 126 254 510 1022 2046
====================
Day 6: Let's Review!
====================
Your teacher has given you the task of drawing a staircase structure. Being an expert
programmer, you decided to make a program to draw it for you instead. Given the required
height, can you print a staircase as shown in the example?
Note: The last line has zero spaces before it.
> Constraints
1 <= N <= 100
> Input Format
You are given an integer N depicting the height of the staircase.
> Output Format
Print a staircase of height N that consists of # symbols and spaces as given in > Sample Output.
> Sample Input
6
> Sample Output
#
##
###
####
#####
######
==============
Day 7: Arrays!
==============
An array is a series of elements of the same type placed in contiguous memory locations
that can be individually referenced by adding an index to a unique identifier.
You'll be given an array of N integers, and you have to print the integers in reverse order.
> Input Format
The first line of input contains N, the number of integers. The next line contains
N integers separated by a space.
> Constraints
1 <= N <= 1000
1 <= A[i] <= 10000, where A[i] is the ith integer in the array.
> Output Format
Print the N integers of the array in the reverse order on a single line separated by a space.
> Sample Input
4
1 4 3 2
> Sample Output
2 3 4 1
=============================
Day 8: Dictionaries and Maps!
=============================
You are given a phone book that consists of your friend's names and their phone number.
After that you will be given your friend's name as query. For each query, print the
phone number of your friend.
> Input Format
The first line will have an integer N denoting the number of entries in the phone book.
Each entry consists of two lines: a name and the corresponding phone number.
After these, there will be some queries. Each query will contain name of a friend.
Read the queries until end-of-file.
> Constraints
A name consists of only lower-case English letters and it may be in the format
'first-name last-name' or in the format 'first-name'. Each phone number has exactly
8 digits without any leading zeros.
1 <= N <= 10^4
1 <= queries <= 10^4
> Output Format
For each case, print "Not found" without quotes, if the friend has no entry in the phone book.
Otherwise, print the friend's name and phone number. See sample output for the exact format.
To make the problem easier, we provided a portion of the code in the editor. You can
either complete that code or write completely on your own.
> Sample Input
3
sam
99912222
tom
11122222
harry
12299933
sam
edward
harry
> Sample Output
sam=99912222
Not found
harry=12299933
=================
Day 9: Recursion!
=================
Euclid's Algorithm for Computing the GCD of two integers
Given two integers, x and y, their GCD (greatest common divisor) can be calculated
recursively using Euclid's Algorithm, which essentially says that if x equals y, then
GCD(x,y)=x; otherwise, GCD(x,y)=GCD(x-y,y) if x>y. Note that this logic can be further
optimized for a more efficient implementation.
Given the starter code in your editor, complete the function body so it returns the GCD
of two input integers, x and y.
> Input Format
Two space-separated integers, x and y.
> Constraints
1 <= x, y <= 10^6
> Output Format
Print the GCD of x and y as an integer.
> Sample Input
1 5
> Sample Output
1
=======================
Day 10: Binary Numbers!
=======================
For this challenge, convert a given number, n, from decimal (base 10) to binary
(base 2).
> Input Format
The first line contains a single integer, T, the number of test cases. The T
subsequent lines of test cases each contain a single value, n, the base 10
positive integer to be converted.
> Constraints
1 <= T <= 1000
1 <= n <= 2^31
> Output Format
For each test case, print the value of n in binary on a new line.
> Sample Input
2
4
5
> Sample Output
100
101
================================
Day 11: 2D-Arrays + More Review!
================================
Given a 6x6 2D Array, A:
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
We can find 16 hourglasses in A; we define an hourglass in A to be a subset of values
with indexes falling in this pattern in A's graphical representation:
a b c
d
e f g
The sum of an hourglass is the sum of the values within it.
Your task is to calculate the sum of every hourglass in some 2D Array, A, and print the
largest value (maximum of the sums) as your answer.
> Input Format
There are 6 lines of input, where each line contains 6 space-separated integers describing
2D Array A; every value in A will be in the inclusive range of -9 to 9.
> Constraints
-9 <= A[i][j] <= 9
0 <= i, j <= 5
> Output Format
Print the largest (maximum) hourglass sum found in A.
> Sample Input
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 2 4 4 0
0 0 0 2 0 0
0 0 1 2 4 0
> Sample Output
19
===================
Day 12: Inheritance
===================
You are given two classes, Student and Grade, where Student is the base class
and Grade is the derived class. Completed code for Student and stub code for
Grade are provided for you in the editor. Note that Grade inherits all the
properties of Student.
Complete the Grade class by writing a class constructor (Grade(String,String,int,int))
and a char calculate() method. The calculate method should return the character
representative of a Student's *Grade. Score as defined in this chart:
Score Grade
score < 40 D
40 <= score < 60 B
60 <= score < 75 A
75 <= score < 90 E
90 <= score <= 100 O
> Input Format
Input is already handled for you by the code pre-filled in the editor. There are
4 lines of input containing first name, last name, phone, and score, respectively.
> Constraints
4 <= |first name|, |last name| <= 10
phone contains exactly 7 digits
1 <= score <= 100
> Output Format
Output is already handled for you by the code pre-filled in the editor. Your output will
be correct if your Grade class constructor and calculate method are properly written.
> Sample Input
Heraldo
Memelli
8135627
90
> Sample Output
First Name: Heraldo
Last Name: Memelli
Phone: 8135627
Grade: O
=========================
Day 13: Abstract Classes!
=========================
In the editor we have provided the abstract Book class and a Solution class.
In the Solution class we created instance of a class called MyBook. Your task
is to write just the MyBook class. The class MyBook mustn't be public.
> Input Format
Input from STDIN is already handled in the code given in the editor.
MyBook's constructor must have the following parameters: String title,
String author, and int price.
> Output Format
The void display() method should print and label the respective title, author, and
price of the book's instance (with each value on its own line) like so:
Title: $title
Author: $author
Price: $price
> Sample Input
The Alchemist
Paulo Coelho
248
> Sample Output
Title: The Alchemist
Author: Paulo Coelho
Price: 248
========================
Day 14: All about Scope!
========================
The absolute difference between two integers, a and b, is |a-b|. The maximum
absolute difference of two integers in a set of positive integers, elements,
is the largest absolute difference of any two integers in elements. The class
Difference is started for you in the editor. It has a private instance array
(elements) for storing N non-negative integers, and a public integer
(maxDifference) for storing the maximum absolute difference.
Your task is to write the class constructor for Difference and the
computeDifference method so that it finds the maximum absolute difference
between any two numbers in N and stores it in maxDifference.
> Input Format
The first line contains a positive integer, N, denoting the size of array elements.
The second line contains N space-separated positive integers describing elements.
> Constraints
1 <= N <= 10
1 <= elements[i] <= 100, where 0 <= i <= N-1
> Output Format
Print the maximum absolute difference between any two integers in elements.
> Sample Input
3
1 2 5
> Sample Output
4
> Explanation
|1-2| = 1
|1-5| = 4
|2-5| = 3
We print the maximum of these absolute differences, which is 4.
====================
Day 15: Linked List!
====================
You are given a class Node in the editor which has one instance pointer 'next'
pointing to next node and an integer data to store the data in Node. You are
also given a pointer 'head' pointing to the head node of a linked list and an
integer data to add to the list. Create a new node with the given integer.
Insert this node at the tail of the linked list and return the head node. The
given head pointer may be null, meaning that the initial list is empty.
Code for input/output is already handled in the editor. You have to complete
the function insert given in the editor. It takes two arguments: the head node
of the linked list and an integer data to be inserted.
> Input Format
First line contains T, the number of testcases. Each test case contains an
integer to be inserted at tail of linked list.
> Output Format
Output the data in each node separated by space.
> Sample Input
4
2
3
4
1
> Sample Output
2 3 4 1
> Explanation
T=4
Initially head is null and 2 is inserted. 3,4,1 are inserted at the tail of linked list
hence the linked list becomes 2 3 4 1
================
Day 16: Sorting!
================
The absolute difference between two integers, a and b, is |a-b|. The minimum
absolute difference between two integers in a list A of positive integers, is
the smallest absolute difference between any two integers in A.
Given a list A = {a0, a1, ..., aN-1} of unsorted integers, find and print the
pair (or pairs) of elements having the minimum absolute difference.
Note: More than one pair of elements may have the same absolute difference.
> Input Format
The first line contains a single integer N, denoting the length of list A.
The second line contains N space-separated integers, a0, a1, ..., aN-1,
representing the elements in A.
> Constraints
2 <= N <= 2*10^5
-10^7 <= A[i] <= 10^7
A[i] != A[j], where 0 <= i < j <= N-1
> Output Format
Print the space-separated pair of elements having the minimum absolute
difference in ascending order. If more than one pair meets this criterion,
print them consecutively, separated by a space, in ascending order on a single
line. Because we are printing space-separated pairs, some elements may appear
more than once in your output.
> Sample Input 2
12
-20 -3916237 -357920 -3620601 7374819 -7330761 30 6246457 -6461594 266854 -520 -470
> Sample Output 2
-520 -470 -20 30
> Explanation
Our minimum absolute difference is 50. The pairs (-470, -520) and (-20, 30) both have
this difference.
===================
Day 17: Exceptions!
===================
Create a class Calculator which consists of a single method power(int,int).
This method takes two integers, n and p, as parameters and finds np. If either
n or p is negative, then the method must throw an exception which says
"n and p should be non-negative".
Code for handling Input/Output is already provided in the editor. Please read
the partially completed code in the editor and complete it.
Note: The class Calculator mustn't be public.
No need to worry about constraints, there won't be any overflow if your code
is correct.
> Input Format
First line contains T, the number of test cases. Next T lines contain two
integers n and p separated by a space.
> Output Format
Output T lines. For each test case if n and p are positive then print np else
print "n and p should be non-negative" without quotes.
========================
Day 18: Queues & Stacks!
========================
A palindrome is a "word, phrase, number, or other sequence of characters which reads the
same backwards and forwards." Can you determine if a given string, s, is a palindrome?
To solve this challenge, we must first take each character in s, enqueue it in a queue,
and also push it onto a stack. Once that's done, we must dequeue the first character
from the queue and pop the top character off the stack, then compare the two characters
to see if they are the same; as long as the characters match, we continue dequeueing,
popping, and comparing each character until our containers are empty (a non-match means
s isn't a palindrome).
Write the following four functions/methods in class Palindrome:
void pushCharacter(char ch): Pushes a character onto a stack.
void enqueueCharacter(char ch): Enqueues a character in a queue.
char popCharacter(): Pops and returns the top character.
char dequeueCharacter(): Dequeues and returns the first character.
Code handling Input/Output and determining if s is palindrome is provided in the editor.
> Input Format
A single line containing string s.
Note: s will always be lowercase.
> Output Format
If s is a palindrome, print "The word, s, is a palindrome."
Otherwise, print "The word, s, is not a palindrome." without quotes
> Sample Input
racecar
> Sample Output
The word, racecar, is a palindrome.
===================
Day 19: Interfaces!
===================
Interfaces are an important concept in Java and in a few other languages like C#.
Here you are given an interface AdvancedArithmetic which contains a method signature
int divisorSum(int n). (The divisorSum function just takes an integer as input and
return the sum of all its divisors.) Your only task is to write a class Calculator
which implements the interface.
Note : The class Calculator shouldn't be public.
> Input Format
Only one line containing integer n
> Constraints
1 <= n <= 1000
> Output Format
In the first line print "I implemented: AdvancedArithmetic" without quotes. In the next
line print the sum of divisors of n as given in problem statement.
> Sample Input
6
> Sample Output
I implemented: AdvancedArithmetic
12
> Explanation
Divisors of 6 are 1, 2, 3, and 6. (1 + 2 + 3 + 6 = 12.)
=====================================
Day 20: Review + More String Methods!
=====================================
Given a string S, find number of words in that string. For this problem a word is
defined by a string of one or more English letters.
Note: Space or any of the special characters like ![,?.\_'@+] will act as a delimiter.
> Input Format
The string will only contain lower case english alphabets, upper case english alphabets,
blank spaces and this special characters: ![,?.\_'@+].
> Constraints
1 <= |S| <= 400000
> Output Format
In the first line, print number of words in the string. The words don't need to be
unique. Also print each word in a separate line.
> Sample Input
He is a very very good boy, isn't he?
> Sample Output
10
He
is
a
very
very
good
boy
isn
t
he
================
Day 21: Generics
================
Generic methods are a very efficient way to handle multiple datatypes using a single method.
Note: Fewer languages are enabled for this challenge because the concept of Generics is not
common in many languages.
Let's say you have an integer array and a string array. You have to write a single
method printArray that can print all the elements of both arrays. The method should
be able to accept both integer arrays or string arrays.
You are given code in the editor. Complete the code so that it prints the following lines:
1
2
3
Hello
World
Do not use method overloading because your answer will not be accepted.
===========================
Day 22: Binary Search Trees
===========================
The height of a binary tree is the number of nodes on the largest path from root to
any leaf. You are given a pointer root pointing to the root of a binary search tree.
Return the height of the tree.
You only have to complete the function getHeight given in the editor.
> Input Format
First line contains T, the number of test cases. Next T lines contain an integer data
to be added to the binary search tree.
> Output Format
Output the height of the binary search tree.
> Sample Input
7
3
5
2
1
4
6
7
> Sample Output
4
> Explanation
The Binary Search tree formed with the given values is
3
/ \
2 5
/ / \
1 4 6
\
7
The maximum length root to leaf path is 3->5->6->7. There are 4 nodes in this path.
Therefore the height of the binary tree = 4.
=============================
Day 23: Review + Binary Trees
=============================
You are given a pointer root pointing to the root of a binary tree. You need to print
the level order traversal of this tree. In level order traversal, we visit the nodes
level by level from left to right. For example:
3
/ \
5 2
/ \ /
1 4 6
For the above tree, the level order traversal is 3 -> 5 -> 2 -> 1 -> 4 -> 6.
HINT: A queue could be helpful.
The code for input/output is already handled in the editor. You only have to complete
the function levelOrder given in the editor.
> Input Format
First line contains T, the number of test cases. Next T lines contain an integer data
to be added to the binary search tree.
> Output Format
Print the values of the level order traversal separated by spaces.
> Sample Input
6
3
5
4
7
2
1
> Sample Output
3 2 5 1 4 7
> Explanation
Level 1: 3
/ \
Level 2: 2 5
/ / \
Level 3: 1 4 7
We need to print the nodes level by level. We process each level from left to right.
Level Order Traversal: 3 -> 2 -> 5 -> 1 -> 4 -> 7
========================================
Day 24: More Review + More Linked Lists!
========================================
You're given the pointer head pointing to the head node of a linked list, where the
data in the nodes is in non decreasing order. Delete as few nodes as possible so that
the list does not contain any value more than once. The given head pointer may be null
indicating that the list is empty. Adjust the next pointers to ensure that the
remaining nodes form a single sorted linked list.
The code for handling input/output is already given in the editor. You have to complete
the function removeDuplicates given in the editor which takes one argument - the head
of the linked list.
> Input Format
First line contains T, the number of testcases. Each test case contains an integer
data to be inserted at tail of linked list. Note: The input data for each test case
is always given in non-decreasing order.
> Output Format
Print the data in each node of linked list separated by a space after the deletion
of duplicates as given in problem statement.
> Sample Input
6
1