We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defmoduleSolutiondodefsplit_list([]),do:[]defsplit_list([h|t])do{grouped,rest}=Enum.split_while([h]++t,fn(x)->x==hend)caserestdo[]->[grouped]_->[grouped]++split_list(rest)endenddefcompress_string(string)dostring|>String.codepoints|>split_list|>Enum.map(fn(char)->"#{List.first(char)}#{ if length(char) > 1,do:length(char),else:''}"end)|>Enum.joinenddefmaindoIO.gets("")|>compress_string|>IO.putsendendSolution.main
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
String Compression
You are viewing a single comment's thread. Return to all comments →
Elixir solution of the "String Compression"