1. class Solution {
  2.  
  3. public String encode(List<String> strs) {
  4. // Time Complexity = O(N)
  5. StringBuilder sb = new StringBuilder();
  6.  
  7. char ch = '.'; // after each string from the list append a dot to segeregate
  8. for(String s : strs)
  9. {
  10. sb.append(s).append(ch);
  11. }
  12. return sb.toString();
  13. }
  14.  
  15. public List<String> decode(String str) {
  16. // Time Complexity = O(N)
  17. List<String> list = new ArrayList<>();
  18.  
  19. StringBuilder sb = new StringBuilder();
  20. for(char ch : str.toCharArray())
  21. {
  22. if(ch != '.')
  23. sb.append(ch);
  24.  
  25. else
  26. {
  27. // when dot is encountered, then add the current string to list
  28. list.add(sb.toString());
  29. // empty the current string
  30. sb = new StringBuilder();
  31. }
  32. }
  33. return list;
  34. }
  35. }