Platforma Universality

0

Cześć. Miał ktoś styczność z tą platformą i wie co trzeba zrobić aby algorytm zaakceptował zadanie ? Mam np takie zadanie z JS-a

Ram had to send large amount of data to his friend Vishnu. Since he was concerned about the time and the amount of data transfer it will take, he wanted to compress the data before he sent it. So he turns to you for help.

You need to perform run length encoding on a given string. The encoding is as follows : 'consecutive character count' followed by '!' followed by the 'character'. Do not encode the characters unless they lead to compression !

Input
Input consists of multiple lines of strings s, one string per line, with |s| <= 100000 (read the input till EOF)

Output
For each input string, output a single line printing the run length encoding of the input string

Example
Input:
aabbbbbccccc
aaaabbbbbbbbbbbbbbbccccc

Output:
aa5!b5!c
4!a15!b5!c

I napisałem funkcję, która wywołana z parametrem input, zwraca zadany output, ale nie zalicza mi tego zadania :/
Moje rozwiązanie :

compressString = (string) => {
	let arr = string.split('')
	let counts = {};
	arr.forEach(function(x) { counts[x] = (counts[x] || 0) +1; });
  let compressedString = '';
	for (let [key, value] of Object.entries(counts)) {
  	if(value <= 2) {
    	for(let i=0; i<value; i++) {
      	 compressedString += key
      }
    }else {
    	compressedString += key + '!' + value
    }
 }
  return compressedString
}
0

Robiłem to samo zadanie i tez mam ten sam problem co ty :(

1 użytkowników online, w tym zalogowanych: 0, gości: 1