Implements some simple string manipulation and string search problem solutions using stack:
- Golang API (Gin)
- Elasticsearch v7
A string is said to be a special string if either of two conditions is met:
- All of the characters are the same, e.g. aaa.
- All characters except the middle one are the same, e.g. aadaa.
A special substring is any substring of a string which meets one of those criteria. Given a string, determine how many special substrings can be formed from it.
Expose API endpoint:
POST /special/count
which consumes data like:
{
"data": {
"attributes": {
"text": "aaaaaabbaaa"
}
}
}and responds with the count of special substrings as defined above.
- Clone repo
- From project root run
docker-compose up(Note that the Go API will take a minute or two to finish building) - Run tests
docker exec -it app go test ./... - Make special strings request count:
curl -X POST \
http://localhost:8080/special/count \
-H 'Content-Type: application/json' \
-d '{
"data": {
"attributes": {
"text": "alskdfjalsiddjfoirjkdddddddddddddddddddjijiiirrrrrrrrrrrrrrrrrrrrlllllllllllllllllllldkaldjifaddjddddddddddddddddddddjddddddddddddddddkkkkalsdlsksjlsajdlkfjaldskjfalsdkiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnssssssssssssssss"
}
}
}'
Should return the count of special substrings 6,033.