blob: b4f84102f404666660c9ff20003b82b711eb1a4f (
plain)
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
|
Task 1: "Palindrome Number
You are given a number $N.
Write a script to figure out if the given number is Palindrome.
Print 1 if true otherwise 0.
Example 1:
Input: 1221
Output: 1
Example 2:
Input: -101
Output: 0, since -101 and 101- are not the same.
Example 3:
Input: 90
Output: 0
"
My notes: sounds trivial. N == join(reverse(split(N)))
Task 2: "Demo Stack
Write a script to demonstrate Stack operations like below:
push($n) - add $n to the stack
pop() - remove the top element
top() - get the top element
min() - return the minimum element
Example:
my $stack = Stack->new;
$stack->push(2);
$stack->push(-1);
$stack->push(0);
$stack->pop; # removes 0
print $stack->top; # prints -1
$stack->push(0);
print $stack->min; # prints -1
"
My notes: ok so by "script" we mean "Perl class". Very easy to do,
but I wonder what ch-2.pl does - contains the above example I guess.
On second thought, let's inline the Stack module into ch-2.pl..
|