Kimberly Cook

...

Full Bio

300 days ago

### 5 Hardest Programming Language Code Challenges For Beginners

By Kimberly Cook |Email | Mar 5, 2019 | 28245 Views

On Coderbyte we offer over 70 easy difficulty programming language code challenges that are perfect for beginners who are learning to code and need some way to practice. We looked at the stats for our easy challenges (excluding the medium and hard questions) 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 - whereby easy we mean challenges that should be solvable somewhere between 15-25 minutes by a beginner coder.
Hardest Beginner Challenges
The 5 hardest "easy" challenges are listed below:

• 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 (you can even write down some steps in pseudocode, or better yet you can write a solution on Coderbyte).

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 #3 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!

Source: HOB