Merging intervals Merge lists/arrays Implement read() using read4k() 1 round of distributed system and large scale system design Compress string "aabcaaaaade" to "aabc5xade". Only compress if it shortens the string. 5xa means char a is repeated 5 times. Question on 2 lists and their union/ intersection/ remove elements present in L1 which are also present in L2
Anonymous
// helper method void append(StringBuilder sb, char cur, int count) { if (count > 3) { sb.append(count).append('x').append(cur); } else { for (int j = 0; j < count; j++) { sb.append(cur); } } } String compress(String s) { char cur = s.charAt(0); int count = 1; StringBuilder sb = new StringBuilder(); for (int i = 1; i < s.length(); i++) { char c = s.charAt(i); if (c == cur) { count++; } else { append(sb, cur, count); cur = c; count = 1; } } append(sb, cur, count); return sb.toString(); }
Check out your Company Bowl for anonymous work chats.