 Coderbyte

# The 5 hardest code challenges for beginners Daniel Borowski Updated on ・3 min read

On Coderbyte we offer around 100 easy code challenges that are perfect for beginners who are learning to code and need some way to practice. We looked at the stats for these challenges and found the ones where users struggled with the most to achieve a perfect score. We ended up narrowing down all the easy challenges to find the 5 hardest ones listed in the easy section — where by easy we mean challenges that should be solvable somewhere between 15–25 minutes by a beginner coder.

# Hardest Beginner Challenges

• Question Marks: Requires looping through a string and checking if certain conditions are met.

• Vowel Square: Requires finding a 2x2 square of vowels in a larger matrix.

• Scale Balancing: Requires looping through an array of weights to determine if a scale can be perfectly balanced.

• Correct Path: Requires traversing through a partially finished path in an NxN matrix and finishing the path.

• Closest Enemy II: Requires checking the distance between certain points in a NxM matrix.

Out of these, the challenge where users struggled most to get a perfect score and spent the longest time solving is Question Marks.

# Challenge Description

Take an input string parameter and determine if exactly 3 question marks exist between every pair of numbers that add up to 10. If so, return true, otherwise return false. Some examples test cases are below:

``````"arrb6???4xxbl5???eee5" => true
"acc?7??sss?3rr1??????5" => true
"5??aaaaaaaaaaaaaaaaaaa?5?5" => false
"9???1???9???1???9" => true
"aa6?9" => false
``````

Before reading further, try and think of how you would solve this challenge.

# Analysis

This challenge requires several layers of logic to get right, which is why it can be difficult to come up with a solution at first. It requires looping through the string and maintaining the position of every pair of numbers that add up to 10. If you do find two numbers that add up to 10, then you will need to determine if exactly 3 specific characters exist somewhere between these two indices.

• 68% of users who submitted a solution in JavaScript didn’t get a perfect score.

• 35% of users who submitted a solution in Ruby didn’t get a perfect score.

• The average number of lines for a solution is 15–29.

# Sample Solutions

Below is a very concise and elegant solution written in Python by the #13th ranked user on Coderbyte, Qlogin.

``````def QuestionsMarks(s):
qnum = 0
dig = 0
has_10 = False
for ch in s:
if ch.isdigit():
if int(ch) + dig == 10:
if qnum != 3:
return 'false'
has_10 = True
dig = int(ch)
qnum = 0
elif ch == '?':
qnum += 1
return 'true' if has_10 else 'false'
``````

There is also a clever regex solution that a user on Coderbyte implemented in Java to solve the challenge:

``````public static String QuestionsMarks(String str) {

str = str.replaceAll("[a-z]+","");
Pattern pattern = Pattern.compile("([0-9])([?])([?])([?])([0-9])");
Pattern pattern01 = Pattern.compile("([0-9])([?])([?])([0-9])");
Matcher matcher01 = pattern01.matcher(str);
Pattern pattern02 = Pattern.compile("([0-9])([?])([0-9])");
Matcher matcher02 = pattern02.matcher(str);
Matcher matcher = pattern.matcher(str);

if (matcher01.find() || matcher02.find()) {
return "false";
} else if (matcher.find()) {
return "true";
}

return "false";

}
``````

Try out the challenges for yourself on Coderbyte and comment below on what you think about the sample solutions!   