class Solution { public String encode(List strs) { // Time Complexity = O(N) StringBuilder sb = new StringBuilder(); char ch = '.'; // after each string from the list append a dot to segeregate for(String s : strs) { sb.append(s).append(ch); } return sb.toString(); } public List decode(String str) { // Time Complexity = O(N) List list = new ArrayList<>(); StringBuilder sb = new StringBuilder(); for(char ch : str.toCharArray()) { if(ch != '.') sb.append(ch); else { // when dot is encountered, then add the current string to list list.add(sb.toString()); // empty the current string sb = new StringBuilder(); } } return list; } }