CODELABS3277 Challenge #1 Solution and Discussion

Problems are available at Hackerearth you can visit the link and try to solve these problem without going through the solutions and if already done then checkout the solutions.

All the solution are in C++. Solution in C will be added soon.

Problem : Easy Counting

Just you are asked to calculate the number os ones and number of zeroes in binary representation of the given number. The below is the basic implementation of logic of converting Decimal number to binary. To make it more efficient we can count number of bit's required for it's representation and use __builtin_popcount(n) to count number of one's then subtract this with number of bits you will get the number of zeroes.

Problem : Saturn Planet

Simple problem for calculating distance your coordinate geometry concept can be used here.

Problem : Problem with Monk

The challenge here was to take infine inputs which can be implemented by using cin/scanf inside while loop.

Problem : Is array is Palindrome?

Simply concatnate the array number to a string and check whether the string formed is palindrome or not.

Problem : An odd alphabet with monk

This problem can be solved most efficiently using the property of XOR i.e. 1^1 = 0 , 1^1^1^1 = 0, 1^1^1 = 1 which implies if frequency of numbers are even then XOR = 0. So convert the char to integer and use this property.

Thank You.
Happy Coding!!!