      "![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 list of characters to exercise string manipulation.  Note using a list vs a bytearray will will result in additional space to create the list and to convert the list to a string.\n",
      "\n",
      "* 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",
      "* If the compressed string size is >= string size, return string\n",
      "* Create compressed_string\n",
      "* For each char in string\n",
      "    * If char == last_char\n",
      "        count++\n",
 
</s> remove     "Since Python strings are immutable, we'll use a list of characters to exercise string manipulation.  Note using a list vs a bytearray will will result in additional space to create the list and to convert the list to a string.\n",
 </s> add     "![alt text](https://raw.githubusercontent.com/donnemartin/algorithms-data-structures/master/images/compress_string.jpg)\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     "![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     "        * 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     "![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",
    "* Calculate the size of the compressed string\n",
      "![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 list of characters to exercise string manipulation.  Note using a list vs a bytearray will will result in additional space to create the list and to convert the list to a string.\n",
      "\n",
    "* Calculate the size of the compressed string\n",
    "* Calculate the size of the compressed string\n",
    "* Calculate the size of the compressed string\n",
    "* Calculate the size of the compressed string\n",
    "* Calculate the size of the compressed string\n",
    "* Calculate the size of the compressed string\n",
    "* Calculate the size of the compressed string\n",
    "* Calculate the size of the compressed string\n",
    "* Calculate the size of the compressed string\n",
    "* Calculate the size of the compressed string\n",
    "* Calculate the size of the compressed string\n",
    "* Calculate the size of the compressed string\n",
      "* If the compressed string size is >= string size, return string\n",
      "* Create compressed_string\n",
      "* For each char in string\n",
      "    * If char == last_char\n",
      "        count++\n",
keep keep keep keep replace replace replace replace replace replace replace replace replace replace 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