A friend of mine is starting to learn how to code, and I thought it could be a good idea for her to practice algorithms by doing some code challenges. When I looked for some code challenge sites to suggest to her, I saw that the “easy” level was not that easy. So I’ve made her a list of really easy code challenges for total beginners:
Length of Last Word - LeetCode
Given a string s consists of some words separated by spaces, return the length of the last word in the string. If the…
This one was super easy, my friend didn’t need any help.
Plus One - LeetCode
Given a non-empty array of decimal digits representing a non-negative integer, increment one to the integer. The digits…
Here my friend started having some difficulties to solve it. I tried suggesting her to do a sum in a paper, and to try to see which process she was doing and how she can replicate that in an algorithm.
Contains Duplicate - LeetCode
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value…
Same here, she was having difficulties so I tried helping her with a real world example. I wanted her to realise that in real life, where someone would have told her to check if there were any duplicates in a room full of numbered boxes giving her a pen and paper, she would have an easy way of doing that. So the thing was just trying to really think in that process and translate it to an algorithm.
Max Consecutive Ones - LeetCode
Given a binary array, find the maximum number of consecutive 1s in this array. Input: [1,1,0,1,1,1]Output…
With this one she was already capable of working on it on her own, write the algorithm and improve it after checking it with some test cases.
Remove Element - LeetCode
Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not…
This last one is a fun one. I had to do it for some job interview a few years ago, and I must admit, I couldn’t see the answer. In my defence, I was really nervous and it was my first interview in another country, in a third language. Even if for a beginner it may be a little hard, it’s interesting because it’s not really complicated but you just need think about it.
Hopefully this code challenges will put a beginner on the right track.