code: def encode_modified_utf8(u: str) -> bytearray:
      
      final_string = bytearray()
  
      for c in [ord(char) for char in u]:
          if c == 0x00 or (0x80 < c < 0x7FF):
              final_string.extend([
                  (0xC0 | (0x1F & (c >> 6))),
                  (0x80 | (0x3F & c))]
              )
          elif c < 0x7F:
              final_string.append(c)
          elif 0x800 < c < 0xFFFF:
              final_string.extend([
                  (0xE0 | (0x0F & (c >> 12))),
                  (0x80 | (0x3F & (c >> 6))),
                  (0x80 | (0x3F & c))]
              )
  
      return final_string
docs: Encodes a unicode string as modified UTF-8 as defined in section 4.4.7
      of the JVM specification.
  
      :param u: unicode string to be converted.
      :returns: A decoded bytearray.