Tag Archives: easy

Move All Zeroes to End of Array : GeeksforGeeks

Problem link: http://www.geeksforgeeks.org/move-zeroes-end-array/

Problem Statement:
Given an array of random numbers, Push all the zero’s of a given array to the end of the array. For example, if the given arrays is {1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0}, it should be changed to {1, 9, 8, 4, 2, 7, 6, 0, 0, 0, 0}. The order of all other elements should be same. Expected time complexity is O(n) and extra space is O(1).
Continue reading


FoxAndClassroom: TopCoder Problem 12811

[The problem appeared in TopCoder SRM 594 (Div-2, Level-1)]
Problem link: http://community.topcoder.com/stat?c=problem_statement&pm=12811

Problem Statement:
Fox Ciel is now in high school. The seats in her classroom are arranged into an n by m matrix. The rows are numbered from 0 to n-1 (front to back) and the columns from 0 to m-1 (left to right).
At the beginning, Ciel can choose any of the seats. Then, at the end of each week Ciel will shift one row to the back and one column to the right, wrapping around whenever necessary. Formally, if her current seat is in row r and column c, then her seat next week will be the one in row ((r+1) modulo n) and column ((c+1) modulo m).
Fox Ciel now wonders whether she can sit in all the seats in the classroom if she follows the above procedure. As we already mentioned, she can start in any of the seats. Also, she can attend the school for as many weeks as she wants to. Return “Possible” if she can sit in all the seats and “Impossible” otherwise.
Continue reading

Hello Hello : CodeChef Problem HELLO

Problem link: http://www.codechef.com/AUG13/problems/HELLO/

Problem Statement:
Chef talks a lot on his mobile phone. As a result he exhausts his talk-value (in Rokdas) very quickly. One day at a mobile recharge shop, he noticed that his service provider gives add-on plans which can lower his calling rates (Rokdas/minute). One of the plans said “Recharge for 28 Rokdas and enjoy call rates of 0.50 Rokdas/min for one month”. Chef was very pleased. His normal calling rate is 1 Rokda/min. And he talked for 200 minutes in last month, which costed him 200 Rokdas. If he had this plan activated, it would have costed him: 28 + 0.5*200 = 128 Rokdas only! Chef could have saved 72 Rokdas. But if he pays for this add-on and talks for very little in the coming month, he may end up saving nothing or even wasting money. Now, Chef is a simple guy and he doesn’t worry much about future. He decides to choose the plan based upon his last month’s usage.

There are numerous plans. Some for 1 month, some for 15 months. Some reduce call rate to 0.75 Rokdas/min, some reduce it to 0.60 Rokdas/min. And of course each of them differ in their activation costs. Note – If a plan is valid for M months, then we must pay for (re)activation after every M months (once in M months). Naturally, Chef is confused, and you (as always) are given the task to help him choose the best plan.
Continue reading

Splitting Candies : CodeChef Problem SPCANDY

Problem link: http://www.codechef.com/AUG13/problems/SPCANDY/

Problem Statement:
Cyael is a teacher at a very famous school in Byteland and she is known by her students for being very polite to them and also to encourage them to get good marks on their tests.

Then, if they get good marks she will reward them with candies 🙂 However, she knows they are all very good at Mathematics, so she decided to split the candies evenly to all the students she considers worth of receiving them, so they don’t fight with each other.

She has a bag which initially contains N candies and she intends to split the candies evenly to K students. To do this she will proceed as follows: while she has more than K candies she will give exactly 1 candy to each student until she has less than K candies. On this situation, as she can’t split candies equally among all students she will keep the remaining candies to herself.

Your job is to tell how many candies will each student and the teacher
receive after the splitting is performed.
Continue reading

Special Pythagorean triplet: Project Euler Problem 9

Problem link: http://projecteuler.net/problem=9

Problem Statement:
A Pythagorean triplet is a set of three natural numbers, a<b<c, for which,

For example, 3^2+4^2=9+16=25=5^2.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.

Continue reading

Summation of primes: Project Euler Problem 10

Problem link: http://projecteuler.net/problem=10

Problem Statement:
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.

Continue reading

Largest product in a series: Project Euler Problem 8

Problem link: http://projecteuler.net/problem=8

Problem Statement:
Find the greatest product of five consecutive digits in the 1000-digit number.


Continue reading