Question 1: Hollow Diamond Pattern
Explanation: Print a hollow diamond pattern using * for a given odd number of rows. The diamond
has a hollow center.
Sample Input: n = 5
Sample Output:
*
Question 2: Binary Number Pyramid
Explanation: Print a pyramid where each row is a palindrome of binary digits (0s and 1s). The first
row has 1, the second row has 0 1 0, and so on.
Sample Input: n = 3
Sample Output:
1
010
10101
Question 3: Spiral Matrix Generation
Explanation: Generate an n x n matrix filled with numbers from 1 to n² in a clockwise spiral order.
Sample Input: n = 3
Sample Output: 1 2 3
894
765
Question 4: Array Rotation with Constraint
Explanation: Rotate an array to the left by k positions without using a temporary array (in-place).
Sample Input: arr = [1, 2, 3, 4, 5], k = 2
Sample Output: [3, 4, 5, 1, 2]
Question 5: Frequency Count In-Place
Explanation: Count the frequency of each element in an array without using additional data
structures. Assume the array elements are positive integers and use the array indices for counting
(if possible).
Sample Input: arr = [1, 2, 2, 3, 3, 3]
Sample Output:
1 occurs 1 time
2 occurs 2 times
3 occurs 3 times
Question 6: Merge Sorted Arrays In-Place
Explanation: Merge two sorted arrays into the first array, which has enough space to hold both.
Merge from the end to avoid overwriting.
Sample Input: arr1 = [1, 3, 5, 0, 0, 0] (with space for 3 more), arr2 = [2, 4, 6]
Sample Output: [1, 2, 3, 4, 5, 6]
Question 7: Pascal's Triangle with a twist
Explanation: Print the first n rows of Pascal's Triangle, but replace each value with 1 if it is odd or 0
if it is even.
Sample Input: n = 4
Sample Output:
1
101
1111
10001
Question 8: Zig-Zag String with Rows
Explanation: Given a string and number of rows, print the string in a zig-zag pattern across the rows
with spaces for alignment.
Sample Input: str = "PROGRAMMING", rows = 3
Sample Output:
PGMN
RRMG
OAI
Question 9: Decimal to Binary (Bit Manipulation)
Explanation: Convert a decimal number to binary .
Sample Input: decimal = 10
Sample Output: 1010
Question 10: Binary to Decimal (Manual Calculation)
Explanation: Convert a binary string to its decimal equivalent by multiplying each bit by 2 raised to
its position and summing the results.
Sample Input: binary = "1010"
Sample Output: 10
Question 11: Decimal to Octal (Loop Method)
Explanation: Convert a decimal number to octal by repeatedly dividing by 8 and collecting the
remainders.
Sample Input: decimal = 100
Sample Output: 144
Question 12: Find Missing Number in Array
Explanation: Given an array of size n-1 containing distinct integers from 1 to n, find the missing
number using the sum formula.
Sample Input: arr = [1, 2, 4, 5] (n=5)
Sample Output: 3
Question 13: Leader Elements with Condition
Explanation: Print all elements that are greater than all elements to their right, but exclude the last
element if it is not the largest value in the array.
Sample Input: arr = [5, 3, 20, 15, 8]
Sample Output: 20, 15
Question 14: Floyd's Triangle with Prime Highlight
Explanation: Print Floyd's Triangle (consecutive natural numbers in a right-angled triangle) but
enclose prime numbers in brackets.
Sample Input: n = 4
Sample Output: 1 [2] [3] 4 [5] 6 [7] 8 9 10
Question 15: Heart Pattern with Message
Explanation: Print a heart pattern using * and incorporate a short message in the center below the
heart.
Sample Input: message = "JAVA"
Sample Output:
JAVA
Question 16: Sort 0s, 1s, and 2s (Dutch Flag)
Explanation: Sort an array containing only 0s, 1s, and 2s in a single pass using the Dutch National
Flag algorithm.
Sample Input: arr = [2, 0, 1, 2, 1, 0]
Sample Output: [0, 0, 1, 1, 2, 2]
Question 17: Maximum Subarray Sum (Kadane's)
Explanation: Find the contiguous subarray with the largest sum using Kadane's algorithm and print
the sum and the subarray indices.
Sample Input: arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Sample Output: Sum = 6, Subarray from index 3 to 6
Question 18: Binary to Octal via Grouping
Explanation: Convert a binary string to octal by grouping bits into sets of three from the right,
padding with leading zeros if necessary, and converting each group to an octal digit.
Sample Input: binary = "1101010"
Sample Output: 152
Question 19: Anagram Check for Arrays
Explanation: Check if two arrays are anagrams (contain the same elements with the same
frequencies) without sorting. Use frequency counting with an array if values are within a range.
Sample Input: arr1 = [1, 2, 3, 4], arr2 = [4, 3, 2, 1]
Sample Output: true
Question 20: Wave Array Formation
Explanation: Rearrange an array into a wave pattern where arr[0] >= arr[1] <= arr[2] >= arr[3] ...
without sorting.
Sample Input: arr = [10, 5, 6, 3, 2, 20]
Sample Output: [10, 5, 6, 3, 20, 2]
Question 21: Pattern with Mirror Reflection
Explanation: Print a pattern that is mirror-reflected horizontally and vertically, such as a butterfly
pattern.
Sample Input: n = 4
Sample Output:
Question 22: Matrix Multiplication with Validation
Explanation: Multiply two matrices after validating that the number of columns in the first matrix
matches the number of rows in the second matrix. If not, print an error.
Sample Input: matrix1 = [[1, 2], [3, 4]], matrix2 = [[5, 6], [7, 8]]
Sample Output: [[19, 22], [43, 50]]
Question 23: Binary to Hexadecimal Conversion
Explanation: Convert a binary string to hexadecimal by grouping bits into sets of four from the right,
padding with leading zeros, and converting each group to a hex digit.
Sample Input: binary = "110101101"
Sample Output: 1AD
Question 24: Decimal to Hexadecimal
Explanation: Convert a decimal number to hexadecimal by repeatedly dividing by 16 and using a
mapping array for digits beyond 9 (A-F).
Sample Input: decimal = 255
Sample Output: FF
Question 25: Find All Triplets with Zero Sum
Explanation: Find all unique triplets in an array that add up to zero. Use sorting and two pointers to
avoid duplicates.
Sample Input: arr = [-1, 0, 1, 2, -1, -4]
Sample Output: Triplets: [-1, -1, 2], [-1, 0, 1]
Question 26: Maximum Product Subarray
Explanation: Find the contiguous subarray that has the largest product using dynamic programming
to track max and min products.
Sample Input: arr = [2, 3, -2, 4]
Sample Output: 6 (from subarray [2, 3])
Question 27: Rotate Matrix by 90 Degrees
Explanation: Rotate an n x n matrix by 90 degrees clockwise in-place by transposing the matrix and
then reversing each row.
Sample Input: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Sample Output: [[7, 4, 1], [8, 5, 2], [9, 6, 3]]
Question 28: Add Two Binary Strings
Explanation: Add two binary strings and return the sum as a binary string by simulating binary
addition from right to left with carry.
Sample Input: binary1 = "1010", binary2 = "1011"
Sample Output: 10101
Question 29: Longest Palindromic Substring in Array
Explanation: Given an array of strings, find the longest string that is a palindrome. If multiple have
the same length, print the first one encountered.
Sample Input: arr = ["abc", "madam", "racecar", "apple", "level"]
Sample Output: "racecar”