You are on page 1of 5

Questions for Coding Competition

“Binary Battleground”
Date: 29.02.24

Stage 1: Simple Mathematical Programs with a Twist

1. Factorial with a Twist:


Description: Calculate the factorial of a number and count the number of trailing zeros.
2. Mystery Number:
Description: The user guesses a number within a range, but the program only gives clues like
"higher" or "lower" without revealing the actual number.
3. Prime Number with a Twist:
Description: Check if a number is prime and find the next prime number if it's not.

4. Palindrome Number with a Twist:

Description: Check if a number is a palindrome and find the sum of its digits.

5. Fibonacci Sequence with a Twist:

Description: Generate the Fibonacci sequence till first N terms and find the sum of even numbers
in the sequence generated till N terms.

6. Is it a Power of 2? with a Twist:

Description: Check if a given number is a Power of the number 2. Also find which exact Power of 2
the number is. The code should have O(1) time complexity.

7. Perfect Number with a Twist:

Description: Check if a number is a perfect number and print its divisors.


2

8. Decimal to Binary Converter:


Description: Convert a decimal number to binary and count the number of unset bits (0s).
9. Reverse Factorial:
Description: Given a number, find its reverse factorial, that is Instead of finding the factorial of a
number, find which factorial it is.
10. Write the program to find the sum of the following infinite series:
𝑆 = − 1 + 4 − 9 + 16 + ... 𝑡𝑖𝑙𝑙 𝑛 𝑡𝑒𝑟𝑚𝑠
11. Write the program to find the sum of the following infinite series:
𝑆 = 2 − 4 + 6 − 8 + ... 𝑡𝑖𝑙𝑙 𝑛 𝑡𝑒𝑟𝑚𝑠
12. Write the program to find the sum of the following infinite series:
2 3 𝑛
𝑥 𝑥 𝑥
𝑆 = 1 + 𝑥 + 2!
+ 3!
+...... + 𝑛!
13. Find the kth Odd integer in sequence
Description: Write a program to find the Kth occurrence of an odd integer in a sequence of non-
negative integers terminated with -1. Do not use an array or a list.

Sample Input:
2
1 4 8 3 6 5 2 3 4 1 -1
Sample Output:
3
14. Is it a triangle ?
Description: Check whether 3 given sides form a triangle and calculate the area of the triangle if
the sides are valid.

15. Check the Parity.


Description: Write a program to calculate the parity bit to be attached to a binary sequence
terminated with -1. If it is an odd parity set the parity bit to 1. If it is an even parity set the parity bit
to 0. Do not use an array or a list.
Sample Input:
1 0 1 1 0 0 0 1 0 1 -1
Sample Output:
1
3

Stage 2: Advanced Pattern Printing

Pattern - 1 Pattern - 6

Pattern - 2 Pattern - 7

Pattern - 3 Pattern - 8

Pattern - 4 Pattern - 9

Pattern - 10
Pattern - 5
4

Stage 3 : String and Array-Based Programs

Simple Path Finding

Given an
n×n
binary Matrix A , where each entry is 0 or 1.
A has a unique path of 1's from A[0][0] to A[n-1][n-1].
The path always goes Right (R) or Down (D).

Write a Program.to print the directions of this path.

Note: You can assume that there is exactly one correct path.
All 1's in A are in this unique path, there are no dead ends.

Input
The first line contains the dimension of the matrix n. Assume n < 100.
The second line contains the contents of the matrix A, each row per line.

Output
The path of 1's in the Matrix.

Example

Input

4
1110
0011
0001
0001

Output

RRDRDD

Explanation

The path of 1's from A[0][0] to A[3][3] is

A[0][0] Right --> A[0][1] Right --> A[0][2] Down --> A[1][2] Right --> A[1][3] Down --> A[2][3] Down --> A[3][3].
5

Solution to the triangular number pattern may be a little hard for some (specially the second half of the pattern),
therefore it has been provided below:
rows = 9
curr = 1
upper = rows//2 + 1
elements_last = 0
elsements_secondlast = 0
for i in range(1, upper + 1):
elements_secondlast = elements_last
for k in range(1, upper + 1 - i):
print(" ", end = "\t")
for j in range(1, 2*i):
val = (curr*(curr + 1))//2
print(val,end = "\t")
curr+= 1
elements_last = 2*i - 1
print()
curr -= elements_last + elements_secondlast
lower = rows - upper
curr_last = curr
for i in range(lower, -1, -1):
for k in range(1, upper + 1 - i):
print(" ", end = "\t")
for j in range(1, 2*i):
val = (curr*(curr + 1))//2
print(val,end = "\t")
curr+= 1
elements_last = 2*i - 1
curr = curr - elements_last - 2*(i-1) + 1
print()

You might also like