{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Coding Homework (DATS-6001)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Your Name: " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Implement the following questions in Python. While efficiency is not our primary concern, your code and solutions must be *correct*, *bug-free*, and *well-documented*." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Question 1 (2 + 2 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Given a positive integer $x$, return $x$ with its digits reversed.\n", "\n", "Eg: \n", "Input: $x = 123$ \n", "Output: $321$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "a. Describe the logic of your algorithm. In other words, justify why you think your alogirthm must return the desired output for a given input." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "b. Implement your algorithm in Python." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Question 2 (2 + 2 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Given a square matrix (list of lists), calculate the absolute difference between the sums of its diagonals.\n", "\n", "Eg:\n", "Input: \n", "mat = \n", "[[11,2,4], \n", "[4,5,6], \n", "[10,8,-12]]\n", "\n", "Output: 15 \n", "Explanation: \n", "Sum of primary diagonal $= 11 + 5 + (-12) = 4$. \n", "Sum of secondary diagonal $= 4 + 5 + 10 = 19$. \n", "Difference $= |19 - 4| = 15$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "a. Describe the logic of your algorithm. In other words, justify why you think your alogirthm must return the desired output for a given input." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "b. Implement your algorithm in Python." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Question 3 (2 + 2 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Given an unsorted integer array $nums$. return the smallest positive integer that is not present in $nums$. Note: 0 is not the positive integer.\n", "\n", "Input: arr[] = [2, -3, 4, 1, 1, 7] \n", "Output: 3 \n", "Explanation: 3 is the smallest positive number missing from the array. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "a. Describe the logic of your algorithm. In other words, justify why you think your alogirthm must return the desired output for a given input." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "b. Implement your algorithm in Python." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Question 4 (2 + 2 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Given an integer array, find the maximum product of any subarray.\n", "\n", "Input: arr[] = [-2, 6, -3, -10, 0, 2] \n", "Output: 180 \n", "Explanation: The subarray with maximum product is {6, -3, -10} with product = 6 * (-3) * (-10) = 180" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "a. Describe the logic of your algorithm. In other words, justify why you think your alogirthm must return the desired output for a given input." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "b. Implement your algorithm in Python." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Question 5 (2 + 2 points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Write a Python program to find the [median](https://en.wikipedia.org/wiki/Median) of two *sorted* arrays of different sizes. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "a. Describe the logic of your algorithm. In other words, justify why you think your alogirthm must return the desired output for a given input." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "b. Implement your algorithm in Python." ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "dats-6103", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 2 }