Interview Programming Challenge

Ray Alva
Ray Alva
Mar 1 · 3 min read

A week ago I had my very first technical interview with a company I was very excited about. I had only participated in mock interviews before so to have a real interview coming up was both exciting and stressing. When the day came I realized that it was actually a very fun experience. I learned a lot about how the hiring process might go for other companies. Best of all, I was given a new programming challenge to have fun with! In this post I will show you what the challenge was and the solution I came up with.

The challenge was to create a function that auto corrected a string. The rules were simple.

  • Only the first letter of the first word was required to be capitalized.
  • The first letter of the second word could be capitalized or lower cased.
  • All letters after the first letter of the word had to be lower cased.

I decided to use the Ruby programming language to solve this problem. My thought process was to first split the input sentence into an array of words and create an empty array where the final product would be stored.

def auto_correct(str)
arr = str.split(' ')
nu_arr = []
end

Ok, so now that I knew how I was going to process the original string I thought that I would need to iterate through each word. I needed a way to recognize the first word so that it was always capitalized. In order to do that I used .each_with_index. If the index was 0 then I can have that word’s first letter capitalized. Inside this block I also needed to split the word into individual letters and set a variable for the processed word. This is what my code looked like so far.

def auto_correct(str)
arr = str.split(' ')
nu_arr = []

Now I need to go through every letter and figure out whether it needs to be a capital letter or lower case letter. I decided to do another .each_with_index block to go through every letter, change the casing, and concatenate it to the nu_word. If the index for the word was 0 and the index for the letter was 0 then that letter had to be capitalized. Else, if the index of the letter was zero but not the first word then that letter could be left as is and then concatenated to the nu_word. Else the letter is lower case. I wrote and if statement that would do just that. After the if statement I would shovel the nu_word to the nu_arr. This is what that looked like.

def auto_correct(str)
arr = str.split(' ')
nu_arr = []

Great so now our nu_arr should contain all the words processed correctly according to the rules. Now the only thing left to do is to join the words into a string and ouput the result to the console. Let’s call the method and see our result

def auto_correct(str)
arr = str.split(' ')
nu_arr = []

After we run it our code the result looks like this “Hello World!”. The code is working perfectly!

The problem was fun and it was the very first time I had interviewed so it was great experience. Maybe this wasn’t the best or most efficient answer but I was proud that I was able to solve the problem. In reality trying to solve this problem wasn’t so straightforward. I went through periods of trial and error and it took me some time to get it working. Either way I feel like the interview went well and I really enjoyed getting some interviewing experience. Let me know what your solution looks like. I would love to see what other people come up with. Thanks for reading and happy coding! 😎

Geek Culture

Proud to geek out.

Sign up for Geek Culture Hits

By Geek Culture

Subscribe to receive top 10 most read stories of Geek Culture — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Ray Alva

Written by

Ray Alva

Flatiron School Graduate

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Ray Alva

Written by

Ray Alva

Flatiron School Graduate

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store