DevTalk
August 30, 2023
10
min read

CODE100 - Could you have solved our coding challenges?

Benedikt Bischof

​During the WeAreDevelopers World Congress 2023 in Berlin we ran the first edition of CODE100, a new "game-show-meets-coding" format, created by WeAreDevelopers. ​ The game consisted of 6 rounds, 3 of which were coding challenges. For each of these coding rounds, the challengers (contestants) had to request a JWT token from the CODE100 API. This token was then used to authenticate the challengers against the API to retrieve the puzzles and submit their solutions. Turns out that this was a bit of a hurdle, so we may change that in the future.

But let's talk quickly about the challenges. How would you have solved them? You can find solutions in various languages in our Code 100 GitHub repository. ​

Challenge 1 - Sum numbers in a string

The puzzle for this challenge was a string and the challengers needed to code up a solution to sum up all the numbers contained in the string: ​

The puzzle is a string containing any amount of characters which can be either a letter or a digit. If there is a number with more than 1 digit, this should be counted as a whole number - not as separate digits. ​

Example puzzle

world20congresss23

Example result

43 (not 7) ​ Check out the solutions in various languages and the original puzzle and expected result on GitHub:

Puzzle 1 used in CODE100 2023 Berlin

Expected result 1 used in CODE100 2023 Berlin

Challenge 1 solutions

Possible solutions

As with any of these challenges, there is more than one solution - but here are two: ​

Solution 1

• Set a sum variable to 0

• Set a currentnumber variable to an empty string

• Split the string into an array of characters (e.g. in JavaScript with .split(''))

• Iterate over the array of characters

• If the current character is a valid digit, append it to the currentnumber variable

• If the current character is not a valid digit, add the (parsed) currentnumber variable to the sum variable and reset the currentnumber variable to an empty string ​ This is a more "imperative" solution, which is easier to understand for beginners and a very valid way to do it. ​

Solution 2

This second solution requires some more knowledge about regular expressions, but is a lot shorter and faster to write:

• Split the string into numbers using a regular expression (e.g. in JavaScript with .split(/D/))

• Add up the numbers in the resulting array ​

Challenge 2 - Identify anagrams

The puzzle for this challenge was to identify anagrams: ​

You will receive an array of strings.

Submit that array of strings, sorted from A-Z, but only supply the words that are an anagram of another word in that array.

Example puzzle

[ "kiwi", "melon", "apple", "lemon" ]

Example result

[ "lemon", "melon" ]

Check out the solutions in various languages and the original puzzle and expected result on GitHub:​

Puzzle 2 used in CODE100 2023 Berlin

Expected result 2 used in CODE100 2023 Berlin

Challenge 2 solutions

Possible solution

• Write a function that identifies if two words are anagrams

– Sort the letters of both words alphabetically

– Iterate word 1, and create an object map for each character, counting the occurance of each

– Iterate word 2, and check if the character count matches

• Iterate over the array of words

• For each word, iterate over the remaining words in the array

• If the current word is an anagram of the other word, add it to the result array ​

Challenge 3 - Linked list

This third challenge, the challengers had to iterate through a linked list: ​

You will receive an array with nodes of a linked list and the ID of the top node as illustrated in the example below.

- The property next points to the ID of the next node
- The last node has the value null for next
- The property top points to the ID of the first node

Submit as solution an array of the values in the order that they appear in the linked list.

Example puzzle

{
   "linkedList": [
       { "id": "b", "value": 2, "next": "c" },
       { "id": "c", "value": 3, "next": null },
       { "id": "a", "value": 1, "next": "b" }
   ],
   "top": "a"
}

Example result

[ 1, 2, 3 ]

Puzzle 3 used in CODE100 2023 Berlin

Expected result 3used in CODE100 2023 Berlin

Challenge 3 solutions

Possible solution

• Write a recursive function that takes a node ID as an argument

• If the node is null, abort the function (this means that it's the last node in the list)

• Push the value of the current node to the result array

• Call the recursive function again with the ID of the next node ​

Summary

These challenges look easy at the first glance, but can be hard to execute when time is your enemy and you have are facing a live audience. The challengers did a great job and we are looking forward to the next CODE100 event!

Speaking of which, what would you like the next iterations of CODE100 to be? We're still in early days and we're planning to do a lot more with this idea.

CODE100 - Could you have solved our coding challenges?

August 30, 2023
10
min read

Subscribe to DevDigest

Get a weekly, curated and easy to digest email with everything that matters in the developer world.

Learn more

From developers. For developers.