aboutsummaryrefslogtreecommitdiff
path: root/challenge-087/duncan-c-white/README
blob: 5fd57a503375ef43c120e1407c1cf7563633f13d (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Task 1: "Longest Consecutive Sequence

You are given an unsorted array of integers @N.

Write a script to find the longest consecutive sequence. Print 0 if no sequence found.

Example 1:

	Input: @N = (100, 4, 50, 3, 2)
	Output: (2, 3, 4)

Example 2:

	Input: @N = (20, 30, 10, 40, 50)
	Output: 0

Example 3:

	Input: @N = (20, 19, 9, 11, 10)
	Output: (9, 10, 11)
"

My notes: clearly defined, sort it first, then walk list looking for sequences


Task 2: "Largest Rectangle

You are given binary matrix m x n with all values being 0 or 1.

Write a script to find the largest rectangle containing only 1. Print 0 if none found.

Example 1:

Input:
    [ 0 0 0 1 0 0 ]
    [ 1 1 1 0 0 0 ]
    [ 0 0 1 0 0 1 ]
    [ 1 1 1 1 1 0 ]
    [ 1 1 1 1 1 0 ]

Output:
    [ 1 1 1 1 1 ]
    [ 1 1 1 1 1 ]

Example 2:

Input:
    [ 1 0 1 0 1 0 ]
    [ 0 1 0 1 0 1 ]
    [ 1 0 1 0 1 0 ]
    [ 0 1 0 1 0 1 ]

Output: 0

Example 3:

Input:
    [ 0 0 0 1 1 1 ]
    [ 1 1 1 1 1 1 ]
    [ 0 0 1 0 0 1 ]
    [ 0 0 1 1 1 1 ]
    [ 0 0 1 1 1 1 ]

Output:
    [ 1 1 1 1 ]
    [ 1 1 1 1 ]
"

My notes: clearly defined, I assume that a rectangle has min-width 2,
min-height 2, brute force: find all rectangles, pick max area