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
|
Task 1: "Search Matrix
You are given 5x5 matrix filled with integers such that each row is
sorted from left to right and the first integer of each row is greater
than the last integer of the previous row.
Write a script to find a given integer in the matrix using an efficient search algorithm.
Example
Matrix: [ 1, 2, 3, 5, 7 ]
[ 9, 11, 15, 19, 20 ]
[ 23, 24, 25, 29, 31 ]
[ 32, 33, 39, 40, 42 ]
[ 45, 47, 48, 49, 50 ]
Input: 35
Output: 0 since it is missing in the matrix
Input: 39
Output: 1 as it exists in the matrix
"
My notes: could flatten onto a 1D array and binary search. Other
methods? Find which row it's in (if any) and then grep? Did that.
Not a very nice method (not even sure it works:-))
Task 2: "Ordered Letters
Given a word, you can sort its letters alphabetically (case
insensitive). For example, "beekeeper" becomes "beeeeekpr" and
"dictionary" becomes "acdiinorty".
Write a script to find the longest English words that don't change when
their letters are sorted.
"
My notes: nice!
|