Last Friday I received a message on my Google Gmail account. I just read the first line without opening the message. The message required me to select a date and time for this week. I decided that due to the amount of messages that I receive everyday and that it was Friday afternoon, I would answer it first thing Monday (today).
This morning I looked for the message and I could not find it. I looked in the trash and deleted folders with the same result. I did a Google search to see if there is a feature in Gmail to send a message and if the receiver does not reply within a specified time period, you would be able to automatically delete it. I was not able to find such feature. Hopefully the person that sent it will be kind enough to resend when they do not receive a reply from me.
OK, let’s look at this HackerRank challenge. Moving forward will try to pick up problems with higher difficulty level.
The idea is to check in a string containing a repeated three letter message “SOS” how many characters have changed. To get a better description please read the actual challenge.
I used Java and the Eclipse IDE to generate my solution. The code for the function of interest follows:
// Complete the marsExploration function below. static int marsExploration(String s) { int changed = 0; // **** loop once per SOS message **** for (int i = 0; i < s.length(); i += "SOS".length()) { // **** extract the current substring **** String subs = s.substring(i, i + 3); // **** count the changes **** if (subs.charAt(0) != 'S') changed++; if (subs.charAt(1) != 'O') changed++; if (subs.charAt(2) != 'S') changed++; } // **** **** return changed; }
If you are interested in checking out my solution, you may find it in GitHub.
If you have comments of questions regarding this or any other post in this blog please leave me a note below. If you are interested in a specific task, issue or problems you are welcome to leave me a message below.
Keep on learning and having fun developing software;
John
You can follow me on Twitter: @john_canessa