You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+4-2
Original file line number
Diff line number
Diff line change
@@ -19,9 +19,11 @@ Keep updating.
19
19
## Hard
20
20
- Kaprekars Constant
21
21
- Chessboard Traveling
22
-
-MaximalSquare
22
+
-Maximal Square
23
23
- I think this one is very hard when it comes to matrix and filter, and how to handle filter movement within a matrix by pure code without using some matrix handling library.
24
24
- Since coderbyte uses python2, and my own laptop uses python3, I have 2 version of the code.
25
25
- For python2 version, you can just copy and paste the code on to the [coderbyte online editor](https://www.coderbyte.com/information/Maximal%20Square) and test the code.
26
26
- For python3, you can run it on your own computer. You need to copy and paste the test case on strArr, for example: `strArr = ["0111", "1111", "1111", "1111"]`
27
-
- Have fun!
27
+
- You can uncomment the `print()` to have a close monitor on how it works. Have fun!
28
+
- Pentagonal Number
29
+
- Although it is a hard challenge, it is not hard at all. All you need to do is to find the regular pattern of how the pentagon grows.
Have the function PentagonalNumber(num) read num which will be a positive integer and determine how many dots exist in a pentagonal shape around a center dot on the Nth iteration. For example, in the image below you can see that on the first iteration there is only a single dot, on the second iteration there are 6 dots, on the third there are 16 dots, and on the fourth there are 31 dots.
3
+
4
+

5
+
6
+
Your program should return the number of dots that exist in the whole pentagon on the Nth iteration.
7
+
8
+
Hard challenges are worth 15 points and you are not timed for them. Use the Parameter Testing feature in the box below to test your code with different arguments.
Have the function MaximalSquare(strArr) take the strArr parameter being passed which will be a 2D matrix of 0 and 1's, and determine the area of the largest square submatrix that contains all 1's. A square submatrix is one of equal width and height, and your program should return the area of the largest submatrix that contains only 1's. For example: if strArr is ["10100", "10111", "11111", "10010"] then this looks like the following matrix:
5
+
6
+
1 0 1 0 0
7
+
1 0 1 1 1
8
+
1 1 1 1 1
9
+
1 0 0 1 0
10
+
11
+
For the input above, you can see the bolded 1's create the largest square submatrix of size 2x2, so your program should return the area which is 4. You can assume the input will not be empty.
12
+
13
+
Hard challenges are worth 15 points and you are not timed for them.
14
+
15
+
Sample Test Cases
16
+
17
+
Input:["0111", "1111", "1111", "1111"]
18
+
19
+
Output:9
20
+
21
+
Input:["0111", "1101", "0111"]
22
+
23
+
Output:1
24
+
'''
25
+
defMaximalSquare(strArr):
26
+
l=list([[int(x) forxins] forsinstrArr])
27
+
row=len(strArr)
28
+
col=len(strArr[0])
29
+
F=min(row, col)
30
+
31
+
forfinrange(F, 0, -1): # descending searching
32
+
foriinrange(0, row-f+1): # from row to row (filter goes from upper to bottom)
33
+
# if f == row, do this for loop only once
34
+
# i is the row index of the matrix
35
+
forjinrange(0, col-f+1): # from column to column (filter goes from left to right)
36
+
# if f == col, do this loop only once
37
+
# j is the column index of the matrix
38
+
# strArr[i][j] is the upper left corner of the submatrix
0 commit comments