Sunday 7 April 2019

Google Code Jam 2019 - Qualification Round

This weekend, I have participated at the Google Code Jam contest. You only needed to get 30 pts to attend the next round !

For the first question : Because each number always has a the number 4 in it, we can just :

create (initialise) string A and string B
for each digit in the number :
     if the digit is a 4 :
          put '1' in string B
          put '3' in string A
     else :
          put the digit in string A

For the second question : It is a pretty easy question. The idea is just to replace 'E' by 'S' and 'S' by 'E':

read the string s
for each character c in s :
     if c == 'E' :
         print 'S'
     else :
         print 'E'

For the third question : just use Euclid's gcd !

Have a look at the official editorial for question 3 and 4 :

https://codejam.withgoogle.com/2018/challenges/0000000000051705/analysis/000000000008830b
https://codejam.withgoogle.com/2018/challenges/0000000000051705/analysis/00000000000881de

Here is my youtube video (doing A and B) : https://youtu.be/0k4q1SMSYSo

std::next_permutation(arr.begin(),arr.end());

What is next_permutation(a.begin(),a.end()) ? Next permutation is like what its name says, finds the next permutation of a and assigns ...