“Duplicate Encoder” is a coding puzzle that people can be attempted in the following languages: java, javascript, python, ruby, csharp, php, rust, r, scala, nim, c, elm, haskell, typescript, cpp, coffeescript, crystal, swift, julia, and go.
- Difficulty: 6 kyu
- Stars: 1740
- Votes: 8114
- Category: reference
- Tags: Fundamentals, Strings, Data Types, Arrays
- Source: codewars
Description
The goal of this exercise is to convert a string to a new string where each character in the new string is "("
if that character appears only once in the original string, or ")"
if that character appears more than once in the original string. Ignore capitalization when determining if a character is a duplicate.
Examples
"din" => "((("
"recede" => "()()()"
"Success" => ")())())"
"(( @" => "))(("
Notes
Assertion messages may be unclear about what they display in some languages. If you read "...It Should encode XXX"
, the "XXX"
is the expected result, not the input!
Solve It Here
Click the link below to solve it on Codewars:
Notes
This puzzle was posted by a Slackbot via a slash command. If you want to help work on the app, send a message to @Josh.
If you don’t want to see the coding puzzles when you visit the forum, you can go into your settings and mute the puzzles category.