     "metadata": {},
     "source": [
      "## Clarifying Questions\n",
      "\n",
      "* Is the string ASCII (extended)?  Or Unicode?\n",
      "    * ASCII extended, which is 256 characters\n",
      "* Can you use additional data structures?  \n",
      "    * Yes\n",
      "* Is this case sensitive?\n",
      "    * Yes\n",
      "* Do you compress even if it doesn't save space?\n",
 
</s> remove     "* For each char in string\n",
    "    * If char == last_char\n",
    "        count++\n",
    "    * Else\n",
 </s> add     "    * For each char in string\n",
    "        * If char is the same as last_char, increment count\n",
    "        * Else\n",
    "            * Append last_char to compressed_string\n",
    "            * append count to compressed_string\n",
    "            * count = 1\n",
    "            * last_char = char\n", </s> remove     "        * append count to compressed_string\n",
    "        * count = 1\n",
    "        * last_char = char\n",
    "    * Append last_char to compressed_string\n",
    "    * append count to compressed_string\n",
    "* return compressed_string\n",
 </s> add     "        * Append count to compressed_string\n",
    "    * Return compressed_string\n", </s> remove     "* If string is empty return string\n",
    "* count = 0\n",
    "* size = 0\n",
    "* last_char = first char in string\n",
    "* For each char in string\n",
    "    * If char == last_char\n",
    "        count++\n",
    "    * Else\n",
    "        size += 2\n",
    "        count++\n",
    "        last_char = char\n",
    "* size += 2\n",
 </s> add     "* Calculate the size of the compressed string\n", </s> remove     "![alt text](https://raw.githubusercontent.com/donnemartin/algorithms-data-structures/master/images/compress_string.jpg)\n",
 </s> add     "Since Python strings are immutable, we'll use a list of characters instead to exercise in-place string manipulation as you would get with a C string (which is null terminated, as seen in the diagram below).  Python does not use a null-terminator.\n", </s> remove     "![alt text](https://raw.githubusercontent.com/donnemartin/algorithms-data-structures/master/images/compress_string.jpg)\n",
    "\n",
    "Since Python strings are immutable, we'll use a bytearray to exercise array manipulation.  As seen above, we could use a list of characters to create the compressed string then convert it to a string in the end, but this will result in additional space.\n",
    "\n",
    "The algorithm is the same, except we will need to work with the bytearray's character codes instead of the characters as we did above when we implemented this solution with a list.\n",
 </s> add     "The byte array algorithm similar when using a list, except we will need to work with the bytearray's character codes instead of the characters as we did above when we implemented this solution with a list.\n",
    "*Problem statements are sometimes intentionally ambiguous.  Asking clarifying questions, identifying constraints, and stating assumptions help to ensure you code the intended solution.*\n",
    "\n",
    "* Can I assume the string is ASCII?\n",
    "    * Yes\n",
    "    * Note: Unicode strings could require special handling depending on your language\n",
     "metadata": {},
     "source": [
      "## Clarifying Questions\n",
      "\n",
    "*Problem statements are sometimes intentionally ambiguous.  Asking clarifying questions, identifying constraints, and stating assumptions help to ensure you code the intended solution.*\n",
    "\n",
    "* Can I assume the string is ASCII?\n",
    "    * Yes\n",
    "    * Note: Unicode strings could require special handling depending on your language\n",
    "*Problem statements are sometimes intentionally ambiguous.  Asking clarifying questions, identifying constraints, and stating assumptions help to ensure you code the intended solution.*\n",
    "\n",
    "* Can I assume the string is ASCII?\n",
    "    * Yes\n",
    "    * Note: Unicode strings could require special handling depending on your language\n",
      "* Can you use additional data structures?  \n",
      "    * Yes\n",
      "* Is this case sensitive?\n",
      "    * Yes\n",
      "* Do you compress even if it doesn't save space?\n",
keep keep keep keep replace replace keep keep keep keep keep
 Reworked notebook: Added more detail to clarifying questions and test cases.  Reworked algorithm discussion, code, and unit test. 
arrays-strings/compress.ipynb