Hackerrank - Halloween party Solution
1 min read

Hackerrank - Halloween party Solution

Hackerrank - Halloween party Solution

Alex is attending a Halloween party with his girlfriend, Silvia. At the party, Silvia spots the corner of an infinite chocolate bar (two dimensional, infinitely long in width and length).

If the chocolate can be served only as 1 x 1 sized pieces and Alex can cut the chocolate bar exactly  times, what is the maximum number of chocolate pieces Alex can cut and give Silvia?

Input Format
The first line contains an integer , the number of test cases.  lines follow.
Each line contains an integer .

Output Format
lines; each line should contain an integer that denotes the maximum number of pieces that can be obtained for each test case.


Note: Chocolate must be served in 1 x 1 sized pieces. Alex can't relocate any of the pieces, nor can he place any piece on top of another.

Sample Input #00


Sample Output #00


The explanation below is for the first two test cases. The rest of them follow a similar logic.

For the first test-case where , you need  horizontal and  vertical cuts.


For the second test case, where , you need  horizontal and  vertical cuts.

Solution in python

Solution 1

def halloweenParty(k):
    return (k//2)*(k-k//2)

for _ in range(int(input())):

Solution 2

from math import ceil,floor
def halloweenParty(k):
    return ceil(k/2)*floor(k/2)

for _ in range(int(input())):

Enjoying these posts? Subscribe for more

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

That's okay. But without advertising-income, we can't keep making this site awesome.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add thepoorcoder.com to your ad blocking whitelist or disable your adblocking software.