We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Checking changes between each "SOS".
Lets take message = "SOSTRSSOO" and sos = "SOS"
for i = 0; i< 9; i++, we will have:
message.charAt(i) != sos.charAt(i % 3) is false upto i = 2.
Now when i = 3, message[3] != sos[3 % 3 i.e. 0] is true.
So count will increase. Again at i =4:
message[4] != sos[4 % 3 i.e. 1] is true.
Briefly, the whole message is broken into set of 3 characters and compared to sos
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Mars Exploration
You are viewing a single comment's thread. Return to all comments →
Checking changes between each "SOS". Lets take message = "SOSTRSSOO" and sos = "SOS" for i = 0; i< 9; i++, we will have: message.charAt(i) != sos.charAt(i % 3) is false upto i = 2. Now when i = 3, message[3] != sos[3 % 3 i.e. 0] is true. So count will increase. Again at i =4: message[4] != sos[4 % 3 i.e. 1] is true.
Briefly, the whole message is broken into set of 3 characters and compared to sos