|
@@ -12,22 +12,83 @@
|
|
"metadata": {},
|
|
"metadata": {},
|
|
"source": [
|
|
"source": [
|
|
"### Problem 1:\n",
|
|
"### Problem 1:\n",
|
|
- "Given a N*N matrix, rotate the matrix by 90 degrees clockwise\n",
|
|
|
|
|
|
+ "Given a N*N matrix, mirror the matrix.\n",
|
|
"- Input: [[1, 2, 3],\n",
|
|
"- Input: [[1, 2, 3],\n",
|
|
" [4, 5, 6],\n",
|
|
" [4, 5, 6],\n",
|
|
" [7, 8, 9]]\n",
|
|
" [7, 8, 9]]\n",
|
|
" \n",
|
|
" \n",
|
|
- "- Output: [[7, 4, 1]\n",
|
|
|
|
- " [8, 5, 2] \n",
|
|
|
|
- " [9, 6, 3]]"
|
|
|
|
|
|
+ "- Output: [[3, 2, 1],\n",
|
|
|
|
+ " [6, 5, 4],\n",
|
|
|
|
+ " [9, 8, 7]]"
|
|
]
|
|
]
|
|
},
|
|
},
|
|
{
|
|
{
|
|
"cell_type": "code",
|
|
"cell_type": "code",
|
|
- "execution_count": null,
|
|
|
|
|
|
+ "execution_count": 9,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [
|
|
|
|
+ {
|
|
|
|
+ "data": {
|
|
|
|
+ "text/plain": [
|
|
|
|
+ "[[3, 2, 1], [6, 5, 4], [9, 8, 7]]"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ "execution_count": 9,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "output_type": "execute_result"
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "source": [
|
|
|
|
+ "def rotateMatrix(arr):\n",
|
|
|
|
+ " N = len(arr) - 1\n",
|
|
|
|
+ " for i in range(0, N):\n",
|
|
|
|
+ " x = 0\n",
|
|
|
|
+ " while x <= N:\n",
|
|
|
|
+ " arr[x][i], arr[x][N - i] = arr[x][N - i], arr[x][i]\n",
|
|
|
|
+ " x += 1\n",
|
|
|
|
+ " return arr\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "rotateMatrix([[1, 2, 3],\n",
|
|
|
|
+ " [4, 5, 6],\n",
|
|
|
|
+ " [7, 8, 9]])\n"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 10,
|
|
"metadata": {},
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"outputs": [],
|
|
- "source": []
|
|
|
|
|
|
+ "source": [
|
|
|
|
+ "arr = [[1, 2, 3],\n",
|
|
|
|
+ " [4, 5, 6],\n",
|
|
|
|
+ " [7, 8, 9]]"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 13,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [
|
|
|
|
+ {
|
|
|
|
+ "name": "stdout",
|
|
|
|
+ "output_type": "stream",
|
|
|
|
+ "text": [
|
|
|
|
+ "1 3\n",
|
|
|
|
+ "4 6\n",
|
|
|
|
+ "7 9\n",
|
|
|
|
+ "2 2\n",
|
|
|
|
+ "5 5\n",
|
|
|
|
+ "8 8\n"
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "source": [
|
|
|
|
+ "for i in range(0, len(arr) - 1):\n",
|
|
|
|
+ " x = 0\n",
|
|
|
|
+ " while x <= len(arr) - 1:\n",
|
|
|
|
+ " print(arr[x][i], arr[x][len(arr) - i - 1])\n",
|
|
|
|
+ " x += 1"
|
|
|
|
+ ]
|
|
}
|
|
}
|
|
],
|
|
],
|
|
"metadata": {
|
|
"metadata": {
|