Skip to content

Commit fe4d210

Browse files
committed
solved #1329 with solution help
1 parent 5c0e83d commit fe4d210

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

leetcode_kuro_RnD.ipynb

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9170,28 +9170,51 @@
91709170
},
91719171
{
91729172
"cell_type": "code",
9173-
"execution_count": 50,
9173+
"execution_count": 56,
91749174
"metadata": {},
91759175
"outputs": [
91769176
{
91779177
"name": "stdout",
91789178
"output_type": "stream",
91799179
"text": [
9180-
"[11, 25, 66, 1, 69, 7]\n",
9181-
"[23, 55, 17, 45, 15, 52]\n",
9182-
"[75, 31, 36, 44, 58, 8]\n",
9183-
"[22, 27, 33, 25, 68, 4]\n",
9184-
"[84, 28, 14, 11, 5, 50]\n"
9180+
"6 5\n",
9181+
"10\n",
9182+
"[[11, 25, 66, 1, 69, 7], [23, 55, 17, 45, 15, 52], [75, 31, 36, 44, 58, 8], [22, 27, 33, 25, 68, 4], [84, 28, 14, 11, 5, 50]]\n"
91859183
]
91869184
}
91879185
],
91889186
"source": [
91899187
"# 1329 : https://leetcode.com/problems/sort-the-matrix-diagonally/\n",
91909188
"\n",
9189+
"## ggot help from solution in comments : https://leetcode.com/problems/sort-the-matrix-diagonally/discuss/2659828/Easy-Solution-with\n",
9190+
"from collections import defaultdict\n",
9191+
"\n",
91919192
"mat = [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]]\n",
9193+
"col_mat = len(mat[0])\n",
9194+
"row_mat = len(mat)\n",
9195+
"\n",
9196+
"print(col_mat, row_mat)\n",
9197+
"\n",
9198+
"total_arrangements = (col_mat + row_mat) - 1\n",
9199+
"print(total_arrangements)\n",
9200+
"\n",
9201+
"diagonal_map = defaultdict(list)\n",
9202+
"for i in range(row_mat):\n",
9203+
" for j in range(col_mat):\n",
9204+
" diagonal_index = i - j\n",
9205+
" element = mat[i][j]\n",
9206+
" diagonal_map[diagonal_index].append(element)\n",
9207+
" # print(diagonal_map)\n",
9208+
"\n",
9209+
" for key in diagonal_map:\n",
9210+
" diagonal_map[key].sort(reverse=True)\n",
9211+
"\n",
9212+
" for j in range(row_mat):\n",
9213+
" diagonal_index = i - j\n",
9214+
" element = diagonal_map[diagonal_index].pop()\n",
9215+
" mat[i][j] = element\n",
91929216
"\n",
9193-
"for val in mat: \n",
9194-
" print(val)"
9217+
"print(mat)\n"
91959218
]
91969219
},
91979220
{

0 commit comments

Comments
 (0)