plduhoux
2/20/2018 - 1:12 AM

lookAndSaySequenceNextElement

String lookAndSaySequenceNextElement(String element) {
  String out = "";
  char[] arr = element.toCharArray();
  int index = 0;
  while (index < arr.length) {
      char elem = arr[index];
      int count = 1;
      while(index + count < arr.length && arr[index+count] == elem)
          count++;
      index += count;
      out += count;
      out += elem;
  }
  return out;
}