I saw this problem on HackerNews:
Most candidates cannot solve this interview problem:
* Input: "aaaabbbcca"
* Output: [("a", 4), ("b", 3), ("c", 2), ("a", 1)]
Write a function that converts the input to the output
I ask it in the screening interview and give it 25 minutes
How would you solve it?
Here's my solution(s) written in #Haskell: https://gist.github.com/hyperrealgopher/19730725804ba8825d50d96f75b88a96
@hyperrealgopher
This is probably wrong I found a way to count characters in a string on stackoverrflow then adapted it for this
#https://gist.github.com/hyperrealgopher/19730725804ba8825d50d96f75b88a96
string="aaaabbbccd"
char="a"
echo "character count for a"
awk -F"${char}" '{print NF-1}' <<< "${string}"
char="b"
echo "charcter count for b"
awk -F"${char}" '{print NF-1}' <<< "${string}"
char="c"
echo "character count for c"
awk -F"${char}" '{print NF-1}' <<< "${string}"
char="d"
echo "character count for d"
awk -F"${char}" '{print NF-1}' <<< "${string}"
Good point and you want me to separate the count for the first set of a's and the last one not give a total.