Last Updated:
HackerRank's Camel Case 4 - Python Coding Practice
HackerRank

HackerRank's Camel Case 4 - Python Coding Practice

HackerRank's camelCase 4

Python Solution

#!/usr/bin/env python3
#####################################
# HackerRank camelCase 4 challenge ##
# YOU ARE MISSING A LINE BREAK AT  ##
# THE END OF ONE OF THE TEST CASES ##
# .rstrip IS WHAT YOU WANT         ##
#####################################
import re
while True:
    try:
        # DO NOT MISS THIS COMMENT
        # THIS IS THE SOLUTION .rstrip
        # one of the test cases has a LINE
        # BREAK at the end ^_^ see?
        # YOU WANT TO USE .rstrip
        s = input().rstrip()
        #            _        _
        #   _ __ ___| |_ _ __(_)_ __
        #  | '__/ __| __| '__| | '_ \
        # _| |  \__ \ |_| |  | | |_) |
        #(_)_|  |___/\__|_|  |_| .__/
        #                      |_|  
        combinesplit, mvc, parenth = s.split(";")
        if combinesplit == "S":
            if mvc == "M":
                capitalize = parenth[:-2]                                   
                
            if mvc == "V" or mvc == "C":
                capitalize = parenth
            
            s = re.sub ("(\w)([A-Z])", r"\1 \2", capitalize)
            print (s.lower())
                
        if combinesplit == "C":
            capitalize = parenth.title ()
            s = re.sub (r" ", r"", capitalize)
            q = s[:1].lower() + s[1:]                
            
            if mvc == "M":                                
                print (q+"()")
                
            if mvc == "V":
                print (s)
              
            if mvc == "C":
                print (q)
            
    except EOFError:
      break

A Minor Annoying Problem

So, personally, I don't use these coding challenge websites to push myself, job hunt, test my skills or anything like that. I strictly use them as a platform for ideas for project-based learning. Which, half of them are just that. Their existence is to help you learn how to use one a language or another, usually in a practical way. Some times even in a fun way.

Not only being a fairly decent platform for learning, HackerRank's certifications are widely recognized in the industry. I just took issue with this challenge. Since, I strictly use these things for personal development and mostly to "stay sharp" on skills I'm not currently using as frequently as I'd like to, I almost never pay for the premium.

If you use the free version of HackerRank you can still access everything (that I'm aware of), it simply limits the processing power of your development area and only shows you 2 out of the 6+ unit tests it's going to put your script through. You can probably see where I'm going with this.

Camel Case 4 - Python

This camelCase challenge is available for a wide variety of languages and it's pretty genius in it's simplicity. It pretty much covers text manipulation in one shot. Well, unfortunately for me, there's a unit test that's only visible to premium only (and even then, it'd be hard to spot) where one of the strings you're manipulating has a line
break at the very end of it.

So, it kept telling me that I was fine and passing all the tests, except this one asshole and I just left it there in frustration. I finally was given a hint (by hint, I mean told DIRECTLY) by a paying member, what that unit test was hiding from me (he also explained that even he didn't see the line break right away, since it was at the end of the string). I assume he probably thought the empty line was a typo.

Anyway, the solution is up there and the tip is in the comments. I don't expect this will make anyone a better developer to be stuck on for any length of time, especially when the issue is hidden from you. So, I hope you know that cheating these things is quite literally only cheating yourself. The whole point is to complete the challenge and be sure you're comfortable with all of the programming caveats the script requires.

Be well. And, fuck you HackerRank, I'm not taking it down. Again, I do not feel that this harms or takes away from your platform and I feel that this tricky bit being hidden behind a paywall is nefarious and malicious. I would've been IRATE if I had paid for a membership only to discover that line break. IRATE!

Stuart Gray

Stuart Gray

Stuart Gray is a network and systems engineer with over 18 years of experience, as a professional, in the network security industry. Getting his start early, at only 19, Stuart went to work for IBM Internet Security System's X-Force Advanced Research and Development team. Since leaving IBM, around 25 years old, Stuart has worn many hats across the industry and even ran his own business, Gray Hat Freelancing. Currently, Stuart focuses on strengthening his career, keeping his skill sets sharp and growing his knowledge base in regards to emerging technologies. One thing Stuart loves about network security is that it never stagnates and there's always more to learn.

Comments