Professional Documents
Culture Documents
Coding Competition "Binary Battleground"-QUESTIONS
Coding Competition "Binary Battleground"-QUESTIONS
“Binary Battleground”
Date: 29.02.24
Description: Check if a number is a palindrome and find the sum of its digits.
Description: Generate the Fibonacci sequence till first N terms and find the sum of even numbers
in the sequence generated till N terms.
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.
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.
Pattern - 1 Pattern - 6
Pattern - 2 Pattern - 7
Pattern - 3 Pattern - 8
Pattern - 4 Pattern - 9
Pattern - 10
Pattern - 5
4
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).
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
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()