0% found this document useful (0 votes)
29 views

Practice Ques

practice questions for improving coding skills from beginner to advance.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Practice Ques

practice questions for improving coding skills from beginner to advance.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 29

Determining Even/Odd Numbers

Difficulty: Easy
Topics: Basic Programming
Description: Write a program to check whether a number is even or odd.
Example:
Input: number = 4
Output: Even
Explanation: Since 4 is divisible by 2, it is an even number.

Checking for Prime Numbers


Difficulty: Easy
Topics: Basic Programming, Number Theory
Description: Write a program to determine if a number is prime.
Example:
Input: number = 7
Output: Prime
Explanation: 7 has no divisors other than 1 and itself, so it is a prime number.

Validating Leap Years


Difficulty: Easy
Topics: Basic Programming, Date Handling
Description: Write a program to check if a given year is a leap year.
Example:
Input: year = 2020
Output: Leap Year
Explanation: 2020 is divisible by 4 but not by 100, or it is divisible by 400, so
it is a leap year.

Calculating Armstrong Numbers


Difficulty: Easy
Topics: Basic Programming, Number Theory
Description: Write a program to check if a number is an Armstrong number.
Example:
Input: number = 153
Output: Armstrong Number
Explanation: 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153.

Generating the Fibonacci Series


Difficulty: Easy
Topics: Basic Programming, Sequences
Description: Write a program to generate the Fibonacci series up to a given number.
Example:
Input: limit = 10
Output: [0, 1, 1, 2, 3, 5, 8]
Explanation: The Fibonacci series up to 10 is generated as [0, 1, 1, 2, 3, 5, 8].

Identifying Palindromes
Difficulty: Easy
Topics: Basic Programming, String Manipulation
Description: Write a program to check if a string or number is a palindrome.
Example:
Input: string = "radar"
Output: Palindrome
Explanation: "radar" reads the same backward as forward.

Crafting Star Patterns


Difficulty: Easy
Topics: Basic Programming, Patterns
Description: Write a program to create different star patterns (e.g., pyramid,
diamond).
Example:
Input: patternType = "pyramid", height = 5
Output:

*
***
*****
*******
*********
Explanation: A pyramid pattern with a height of 5 is generated.

Finding the Factorial of a Number


Difficulty: Easy
Topics: Basic Programming, Mathematical Computations
Description: Write a program to compute the factorial of a given number.
Example:
Input: number = 5
Output: 120
Explanation: 5! (factorial) is 5 × 4 × 3 × 2 × 1 = 120.

Summing Digits of a Number


Difficulty: Easy
Topics: Basic Programming, Mathematical Computations
Description: Write a program to calculate the sum of digits of a number.
Example:
Input: number = 1234
Output: 10
Explanation: The sum of the digits 1 + 2 + 3 + 4 = 10.

Finding the Greatest Common Divisor (GCD)


Difficulty: Easy
Topics: Basic Programming, Number Theory
Description: Write a program to find the GCD of two numbers.
Example:
Input: a = 48, b = 18
Output: 6
Explanation: The GCD of 48 and 18 is 6.

Finding the Least Common Multiple (LCM)


Difficulty: Easy
Topics: Basic Programming, Number Theory
Description: Write a program to find the LCM of two numbers.
Example:
Input: a = 12, b = 15
Output: 60
Explanation: The LCM of 12 and 15 is 60.

Counting Vowels and Consonants in a String


Difficulty: Easy
Topics: Basic Programming, String Manipulation
Description: Write a program to count vowels and consonants in a given string.
Example:
Input: string = "hello world"
Output: Vowels: 3, Consonants: 7
Explanation: "hello world" contains 3 vowels (e, o, o) and 7 consonants (h, l, l,
w, r, l, d).

Reversing a String
Difficulty: Easy
Topics: Basic Programming, String Manipulation
Description: Write a program to reverse a given string.
Example:
Input: string = "programming"
Output: "gnimmargorp"
Explanation: The reversed string of "programming" is "gnimmargorp".

Finding the Largest and Smallest Numbers in an Array


Difficulty: Easy
Topics: Basic Programming, Arrays
Description: Write a program to find the largest and smallest numbers in an array.
Example:
Input: array = [4, 7, 1, 8, 5]
Output: Largest: 8, Smallest: 1
Explanation: The largest number in the array is 8 and the smallest is 1.

Sorting an Array
Difficulty: Easy
Topics: Basic Programming, Sorting Algorithms
Description: Write a program to sort an array of numbers in ascending order.
Example:
Input: array = [3, 1, 4, 1, 5, 9]
Output: [1, 1, 3, 4, 5, 9]
Explanation: The array sorted in ascending order is [1, 1, 3, 4, 5, 9].

Finding the Sum of Elements in an Array


Difficulty: Easy
Topics: Basic Programming, Arrays
Description: Write a program to find the sum of elements in an array.
Example:
Input: array = [1, 2, 3, 4, 5]
Output: 15
Explanation: The sum of the elements in the array is 15.

Checking for Armstrong Numbers in a Range


Difficulty: Easy
Topics: Basic Programming, Number Theory
Description: Write a program to find all Armstrong numbers within a given range.
Example:
Input: range = [1, 500]
Output: [1, 153, 370, 371, 407]
Explanation: Armstrong numbers between 1 and 500 are 1, 153, 370, 371, and 407.

Generating Multiplication Tables


Difficulty: Easy
Topics: Basic Programming, Mathematical Computations
Description: Write a program to generate multiplication tables for a given number.
Example:
Input: number = 4
Output:

4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
Explanation: The multiplication table for 4 up to 5 is generated.
Finding Prime Numbers in a Range
Difficulty: Easy
Topics: Basic Programming, Number Theory
Description: Write a program to find all prime numbers within a given range.
Example:
Input: range = [10, 30]
Output: [11, 13, 17, 19, 23, 29]
Explanation: Prime numbers between 10 and 30 are 11, 13, 17, 19, 23, and 29.

Checking for Perfect Numbers


Difficulty: Easy
Topics: Basic Programming, Number Theory
Description: Write a program to determine if a number is a perfect number.
Example:
Input: number = 28
Output: Perfect Number
Explanation: 28 is a perfect number because its divisors (1, 2, 4, 7, 14) sum up to
28.

Calculating the Sum of Even Numbers in a Range


Difficulty: Easy
Topics: Basic Programming, Mathematical Computations
Description: Write a program to find the sum of all even numbers within a given
range.
Example:
Input: range = [1, 10]
Output: 30
Explanation: The sum of even numbers between 1 and 10 is 2 + 4 + 6 + 8 + 10 = 30.

Calculating the Sum of Odd Numbers in a Range


Difficulty: Easy
Topics: Basic Programming, Mathematical Computations
Description: Write a program to find the sum of all odd numbers within a given
range.
Example:
Input: range = [1, 10]
Output: 25
Explanation: The sum of odd numbers between 1 and 10 is 1 + 3 + 5 + 7 + 9 = 25.

Finding the Fibonacci Number at a Specific Position


Difficulty: Easy
Topics: Basic Programming, Sequences
Description: Write a program to find the Fibonacci number at a specific position.
Example:
Input: position = 5
Output: 5
Explanation: The Fibonacci number at position 5 is 5 (sequence: 0, 1, 1, 2, 3, 5).

Printing Prime Numbers Less Than a Given Number


Difficulty: Easy
Topics: Basic Programming, Number Theory
Description: Write a program to print all prime numbers less than a given number.
Example:
Input: number = 20
Output: 2, 3, 5, 7, 11, 13, 17, 19
Explanation: The prime numbers less than 20 are 2, 3, 5, 7, 11, 13, 17, and 19.

Finding the Number of Digits in a Number


Difficulty: Easy
Topics: Basic Programming, Mathematical Computations
Description: Write a program to count the number of digits in a given number.
Example:
Input: number = 12345
Output: 5
Explanation: The number 12345 has 5 digits.

Checking if a Number is a Narcissistic Number


Difficulty: Easy
Topics: Basic Programming, Number Theory
Description: Write a program to check if a number is a narcissistic number (where
the sum of its digits raised to the power of the number of digits equals the number
itself).
Example:
Input: number = 153
Output: Narcissistic Number
Explanation: 153 is a narcissistic number because 1^3 + 5^3 + 3^3 = 153.

Generating a Pattern of Numbers


Difficulty: Easy
Topics: Basic Programming, Patterns
Description: Write a program to generate number patterns (e.g., sequential numbers
in a matrix).
Example:
Input: rows = 3
Output:

1
2 3
4 5 6
Explanation: A number pattern with 3 rows is generated.

Finding the Sum of the Digits of the Factorial of a Number


Difficulty: Easy
Topics: Basic Programming, Mathematical Computations
Description: Write a program to find the sum of the digits of the factorial of a
given number.
Example:
Input: number = 4
Output: 9
Explanation: The factorial of 4 is 24, and the sum of the digits (2 + 4) is 6.

Finding the Largest Palindrome in a String


Difficulty: Easy
Topics: Basic Programming, String Manipulation
Description: Write a program to find the largest palindrome in a given string.
Example:
Input: string = "babad"
Output: "bab" or "aba"
Explanation: Both "bab" and "aba" are valid palindromes in the string.

Finding Missing Numbers in a Sequence


Difficulty: Easy
Topics: Basic Programming, Arrays
Description: Write a program to find missing numbers in a sequence from 1 to n.
Example:
Input: sequence = [1, 2, 4, 5]
Output: [3]
Explanation: The missing number in the sequence from 1 to 5 is 3.
Generating a Pascal’s Triangle
Difficulty: Medium
Topics: Arrays, Mathematical Computations
Description: Write a program to generate Pascal's Triangle up to a given number of
rows.
Example:
Input: rows = 4
Output:

1
1 1
1 2 1
1 3 3 1
Explanation: Pascal's Triangle with 4 rows is generated.

Finding the Median of an Array


Difficulty: Medium
Topics: Arrays, Sorting
Description: Write a program to find the median of an array of numbers.
Example:
Input: array = [3, 1, 2, 4, 5]
Output: 3
Explanation: The median of the sorted array [1, 2, 3, 4, 5] is 3.

Calculating the Power of a Number


Difficulty: Easy
Topics: Basic Programming, Mathematical Computations
Description: Write a program to calculate the power of a number.
Example:
Input: base = 2, exponent = 3
Output: 8
Explanation: 2 raised to the power of 3 is 8.

Checking for an Anagram


Difficulty: Easy
Topics: String Manipulation
Description: Write a program to check if two strings are anagrams.
Example:
Input: string1 = "listen", string2 = "silent"
Output: True
Explanation: "listen" and "silent" are anagrams of each other.

Finding the Sum of Prime Numbers in a Range


Difficulty: Medium
Topics: Number Theory, Mathematical Computations
Description: Write a program to calculate the sum of all prime numbers within a
given range.
Example:
Input: range = [1, 10]
Output: 17
Explanation: The sum of prime numbers between 1 and 10 is 2 + 3 + 5 + 7 = 17.

Finding the N-th Triangular Number


Difficulty: Easy
Topics: Basic Programming, Mathematical Computations
Description: Write a program to find the N-th triangular number.
Example:
Input: N = 4
Output: 10
Explanation: The 4th triangular number is 10 (sum of the first 4 natural numbers).

Checking for Perfect Squares


Difficulty: Easy
Topics: Mathematical Computations
Description: Write a program to determine if a number is a perfect square.
Example:
Input: number = 16
Output: True
Explanation: 16 is a perfect square (4^2 = 16).

Finding the Sum of Squares of Digits


Difficulty: Easy
Topics: Basic Programming, Mathematical Computations
Description: Write a program to find the sum of the squares of the digits of a
number.
Example:
Input: number = 123
Output: 14
Explanation: The sum of the squares of digits is 1^2 + 2^2 + 3^2 = 14.

Generating a Square Matrix of a Given Size


Difficulty: Medium
Topics: Arrays, Matrix Operations
Description: Write a program to generate a square matrix of a given size and fill
it with sequential numbers.
Example:
Input: size = 3
Output:

1 2 3
4 5 6
7 8 9
Explanation: A 3x3 matrix is generated with sequential numbers.

Calculating the Sum of Digits of a Number Until Single Digit


Difficulty: Medium
Topics: Mathematical Computations
Description: Write a program to keep summing the digits of a number until a single
digit is obtained.
Example:
Input: number = 9875
Output: 2
Explanation: The sum of digits is 9 + 8 + 7 + 5 = 29, and then 2 + 9 = 11, and
finally 1 + 1 = 2.

Finding the Count of Specific Digits in a Number


Difficulty: Easy
Topics: Basic Programming, String Manipulation
Description: Write a program to count the occurrences of a specific digit in a
number.
Example:
Input: number = 122333, digit = 3
Output: 3
Explanation: The digit 3 occurs 3 times in the number 122333.

Generating a Fibonacci Sequence Using Recursion


Difficulty: Medium
Topics: Recursion, Sequences
Description: Write a recursive program to generate the Fibonacci sequence up to a
given number.
Example:
Input: number = 5
Output: 0, 1, 1, 2, 3
Explanation: The Fibonacci sequence up to 5 is generated.

Finding All Divisors of a Number


Difficulty: Easy
Topics: Basic Programming, Mathematical Computations
Description: Write a program to find all divisors of a given number.
Example:
Input: number = 12
Output: 1, 2, 3, 4, 6, 12
Explanation: The divisors of 12 are 1, 2, 3, 4, 6, and 12.

Finding the Average of Numbers in an Array


Difficulty: Easy
Topics: Arrays, Mathematical Computations
Description: Write a program to calculate the average of numbers in an array.
Example:
Input: array = [1, 2, 3, 4, 5]
Output: 3
Explanation: The average of the numbers is (1 + 2 + 3 + 4 + 5) / 5 = 3.

Finding the Mode of Numbers in an Array


Difficulty: Medium
Topics: Arrays, Statistical Analysis
Description: Write a program to find the mode (most frequent number) in an array.
Example:
Input: array = [1, 2, 2, 3, 4, 4, 4]
Output: 4
Explanation: The most frequent number in the array is 4.

Determining the Length of a String Without Using Built-In Functions


Difficulty: Medium
Topics: String Manipulation
Description: Write a program to determine the length of a string without using
built-in functions.
Example:
Input: string = "hello"
Output: 5
Explanation: The length of the string "hello" is determined without using built-in
functions.

Generating a Number Pyramid


Difficulty: Medium
Topics: Patterns, Basic Programming
Description: Write a program to generate a pyramid of numbers (e.g., 1, 12, 123,
etc.).
Example:
Input: rows = 4
Output:

1
12
123
1234
Explanation: A number pyramid with 4 rows is generated.

Finding the Sum of Prime Factors of a Number


Difficulty: Medium
Topics: Number Theory, Mathematical Computations
Description: Write a program to find the sum of the prime factors of a given
number.
Example:
Input: number = 12
Output: 5
Explanation: The prime factors of 12 are 2 and 3, and their sum is 2 + 3 = 5.

Finding the Second Largest Number in an Array


Difficulty: Medium
Topics: Arrays, Sorting
Description: Write a program to find the second largest number in an array.
Example:
Input: array = [10, 20, 4, 45, 99]
Output: 45
Explanation: The second largest number in the array is 45.

Finding the Longest Substring Without Repeating Characters


Difficulty: Medium
Topics: String Manipulation, Sliding Window
Description: Write a program to find the longest substring without repeating
characters in a given string.
Example:
Input: string = "abcabcbb"
Output: "abc"
Explanation: The longest substring without repeating characters is "abc".

s2

Finding the Sum of Digits of a Number Until Zero


Difficulty: Easy
Topics: Basic Programming, Mathematical Computations
Description: Write a program to repeatedly sum the digits of a number until the
result is zero.
Example:
Input: number = 123
Output: 6
Explanation: Sum of digits is 1 + 2 + 3 = 6; sum of digits of 6 is 6 (which is a
single digit).

Generating a Multiplication Table for a Range


Difficulty: Easy
Topics: Arrays, Basic Programming
Description: Write a program to generate multiplication tables for numbers within a
specified range.
Example:
Input: start = 2, end = 4
Output:

2 x 1 = 2 3 x 1 = 3 4 x 1 = 4
2 x 2 = 4 3 x 2 = 6 4 x 2 = 8
2 x 3 = 6 3 x 3 = 9 4 x 3 = 12
2 x 4 = 8 3 x 4 = 12 4 x 4 = 16
Calculating the Sum of a Series (1 + 1/2 + 1/3 + ... + 1/n)
Difficulty: Medium
Topics: Mathematical Computations
Description: Write a program to calculate the sum of the series 1 + 1/2 + 1/3 + ...
+ 1/n up to the nth term.
Example:
Input: n = 4
Output: 2.083333
Explanation: Sum of the series is 1 + 1/2 + 1/3 + 1/4 ≈ 2.083333.

Finding All Pairs of Elements in an Array that Add Up to a Given Sum


Difficulty: Medium
Topics: Arrays, Hashing
Description: Write a program to find all pairs of elements in an array whose sum
equals a specified target.
Example:
Input: array = [1, 2, 3, 4, 5], target = 5
Output: [(1, 4), (2, 3)]
Explanation: Pairs that sum up to 5 are (1, 4) and (2, 3).

Generating a Diamond Pattern of Stars


Difficulty: Medium
Topics: Patterns, Basic Programming
Description: Write a program to create a diamond pattern with stars of a given
size.
Example:
Input: size = 5
Output:

*
***
*****
***
*
Counting the Number of Palindromic Substrings in a String
Difficulty: Medium
Topics: String Manipulation
Description: Write a program to count how many palindromic substrings exist in a
given string.
Example:
Input: string = "aaa"
Output: 6
Explanation: Palindromic substrings are "a", "a", "a", "aa", "aa", "aaa".

Generating a Matrix with Multiplication Table


Difficulty: Easy
Topics: Arrays, Matrix Operations
Description: Write a program to generate a matrix where each element at position
(i, j) is the product of i and j.
Example:
Input: size = 3
Output:

1 2 3
2 4 6
3 6 9
Finding the GCD of Multiple Numbers
Difficulty: Medium
Topics: Mathematical Computations
Description: Write a program to find the GCD (Greatest Common Divisor) of an array
of numbers.
Example:
Input: array = [12, 24, 36]
Output: 12
Explanation: The GCD of 12, 24, and 36 is 12.

Finding the Sum of the First N Odd Numbers


Difficulty: Easy
Topics: Mathematical Computations
Description: Write a program to calculate the sum of the first N odd numbers.
Example:
Input: N = 5
Output: 25
Explanation: Sum of the first 5 odd numbers (1 + 3 + 5 + 7 + 9) is 25.

Finding the Number of Perfect Numbers Up to a Given Limit


Difficulty: Medium
Topics: Number Theory
Description: Write a program to find how many perfect numbers exist up to a given
limit.
Example:
Input: limit = 30
Output: 1
Explanation: There is only one perfect number (6) up to 30.

Finding the Largest Prime Factor of a Number


Difficulty: Medium
Topics: Number Theory
Description: Write a program to find the largest prime factor of a given number.
Example:
Input: number = 28
Output: 7
Explanation: The prime factors of 28 are 2 and 7, with the largest being 7.

Generating a Matrix of Fibonacci Numbers


Difficulty: Medium
Topics: Arrays, Matrix Operations
Description: Write a program to generate a matrix where each element is a Fibonacci
number.
Example:
Input: size = 3
Output:

1 1 2
3 5 8
13 21 34
Finding the Sum of the First N Prime Numbers
Difficulty: Medium
Topics: Prime Numbers, Mathematical Computations
Description: Write a program to calculate the sum of the first N prime numbers.
Example:
Input: N = 4
Output: 17
Explanation: The sum of the first 4 prime numbers (2 + 3 + 5 + 7) is 17.

Checking for a Balanced Bracket Sequence


Difficulty: Medium
Topics: String Manipulation, Stack
Description: Write a program to check if a given string with brackets is balanced.
Example:
Input: string = "{[()]}"
Output: True
Explanation: The brackets are balanced.

Finding the Sum of Numbers in a String


Difficulty: Easy
Topics: String Manipulation
Description: Write a program to extract and sum all numbers present in a given
string.
Example:
Input: string = "The numbers are 12 and 34"
Output: 46
Explanation: The sum of numbers 12 and 34 is 46.

Finding the Longest Consecutive Sequence in an Array


Difficulty: Medium
Topics: Arrays, Hashing
Description: Write a program to find the longest sequence of consecutive numbers in
an array.
Example:
Input: array = [100, 4, 200, 1, 3, 2]
Output: 4
Explanation: The longest consecutive sequence is [1, 2, 3, 4].

Generating a Matrix with a Spiral Pattern


Difficulty: Medium
Topics: Arrays, Matrix Operations
Description: Write a program to generate a matrix filled with numbers in a spiral
pattern.
Example:
Input: size = 3
Output:

1 2 3
8 9 4
7 6 5
Finding All Subsets of a Set
Difficulty: Medium
Topics: Combinatorics
Description: Write a program to generate all possible subsets of a given set of
numbers.
Example:
Input: set = [1, 2]
Output: [[], [1], [2], [1, 2]]
Explanation: The subsets of [1, 2] are the empty set, [1], [2], and [1, 2].

Checking for Perfect Squares in a Range


Difficulty: Easy
Topics: Mathematical Comput

ations
Description: Write a program to check which numbers in a given range are perfect
squares.
Example:
Input: start = 1, end = 10
Output: [1, 4, 9]
Explanation: Perfect squares between 1 and 10 are 1, 4, and 9.
Finding the Sum of Diagonal Elements in a Matrix
Difficulty: Easy
Topics: Matrix Operations
Description: Write a program to calculate the sum of the diagonal elements in a
square matrix.
Example:
Input: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Output: 15
Explanation: The sum of the diagonal elements (1 + 5 + 9) is 15.

Finding the Second Smallest Number in an Array


Difficulty: Easy
Topics: Arrays
Description: Write a program to find the second smallest number in an array.
Example:
Input: array = [12, 13, 1, 10, 34, 1]
Output: 10
Explanation: The second smallest number in the array is 10.

Generating Pascal’s Triangle Up to N Rows


Difficulty: Medium
Topics: Combinatorics
Description: Write a program to generate Pascal’s Triangle up to N rows.
Example:
Input: N = 3
Output:

1
1 1
1 2 1
Finding the Sum of Digits of the Product of Two Numbers
Difficulty: Easy
Topics: Mathematical Computations
Description: Write a program to find the sum of the digits of the product of two
given numbers.
Example:
Input: number1 = 12, number2 = 34
Output: 9
Explanation: The product of 12 and 34 is 408, and the sum of its digits is 4 + 0 +
8 = 12.

Checking for Palindromic Numbers in a Range


Difficulty: Medium
Topics: Mathematical Computations
Description: Write a program to check for palindromic numbers within a given range.
Example:
Input: start = 1, end = 100
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99]
Explanation: Palindromic numbers between 1 and 100 are the numbers listed.

Generating a Matrix with Alternating 0s and 1s


Difficulty: Easy
Topics: Arrays, Matrix Operations
Description: Write a program to generate a matrix where the elements alternate
between 0 and 1.
Example:
Input: size = 3
Output:
0 1 0
1 0 1
0 1 0
Finding the Count of a Specific Word in a String
Difficulty: Easy
Topics: String Manipulation
Description: Write a program to count how many times a specific word appears in a
given string.
Example:
Input: string = "hello world hello"
Output: 2
Explanation: The word "hello" appears 2 times in the string.

Finding the Largest Sum of a Subarray


Difficulty: Medium
Topics: Arrays, Dynamic Programming
Description: Write a program to find the largest sum of any contiguous subarray.
Example:
Input: array = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Output: 6
Explanation: The largest sum is 6, from the subarray [4, -1, 2, 1].

Generating a Right-Angle Triangle Pattern of Numbers


Difficulty: Easy
Topics: Patterns
Description: Write a program to create a right-angle triangle pattern with numbers.
Example:
Input: height = 4
Output:

1
12
123
1234
Finding All Divisors of the Product of Two Numbers
Difficulty: Medium
Topics: Number Theory
Description: Write a program to find all divisors of the product of two given
numbers.
Example:
Input: number1 = 6, number2 = 10
Output: [1, 2, 3, 5, 6, 10, 15, 30]
Explanation: The product of 6 and 10 is 60, and its divisors are listed.

Finding the Longest Sequence of Consecutive 1s in a Binary Array


Difficulty: Medium
Topics: Arrays, Binary Operations
Description: Write a program to find the longest sequence of consecutive 1s in a
binary array.
Example:
Input: array = [1, 1, 0, 1, 1, 1]
Output: 3
Explanation: The longest sequence of 1s is [1, 1, 1] with length 3.

Calculating the Sum of the First N Fibonacci Numbers


Difficulty: Medium
Topics: Fibonacci Sequence, Mathematical Computations
Description: Write a program to calculate the sum of the first N Fibonacci numbers.
Example:
Input: N = 5
Output: 12
Explanation: The first 5 Fibonacci numbers are 1, 1, 2, 3, 5, and their sum is 12.

Checking for a Repeated Substring in a String


Difficulty: Medium
Topics: String Manipulation
Description: Write a program to check if a substring is repeated within a given
string.
Example:
Input: string = "abab"
Output: True
Explanation: The substring "ab" is repeated.

Finding the Median of a List of Numbers


Difficulty: Medium
Topics: Sorting, Mathematical Computations
Description: Write a program to find the median value of a list of numbers.
Example:
Input: list = [3, 1, 4, 1, 5]
Output: 3
Explanation: After sorting the list to [1, 1, 3, 4, 5], the median is 3.

Finding the Number of Words in a String


Difficulty: Easy
Topics: String Manipulation
Description: Write a program to count the number of words in a given string.
Example:
Input: string = "Hello world"
Output: 2
Explanation: There are 2 words in the string.

Generating a Matrix with a Diagonal Pattern


Difficulty: Medium
Topics: Matrix Operations
Description: Write a program to create a matrix where elements form diagonal lines
of a given pattern.
Example:
Input: size = 4
Output:

1 0 0 0
1 1 0 0
1 1 1 0
1 1 1 1
Finding the Sum of the First N Even Numbers
Difficulty: Easy
Topics: Mathematical Computations
Description: Write a program to calculate the sum of the first N even numbers.
Example:
Input: N = 4
Output: 20
Explanation: The first 4 even numbers are 2, 4, 6, 8, and their sum is 20.

Finding the Count of Digits Greater Than a Specific Value


Difficulty: Easy
Topics: Mathematical Computations
Description: Write a program to count how many digits in a number are greater than
a specific value.
Example:
Input: number = 54321, value = 3
Output: 2
Explanation: The digits

greater than 3 in 54321 are 5, 4, and 4, so the count is 2.

Generating a Pattern of Prime Numbers


Difficulty: Medium
Topics: Prime Numbers, Patterns
Description: Write a program to generate a pattern where each row contains the
first few prime numbers.
Example:
Input: rows = 3
Output:

2
2 3
2 3 5
Finding the Common Elements in Two Arrays
Difficulty: Medium
Topics: Arrays
Description: Write a program to find common elements between two arrays.
Example:
Input: array1 = [1, 2, 3, 4], array2 = [3, 4, 5, 6]
Output: [3, 4]
Explanation: The common elements between the two arrays are 3 and 4.

Finding the Sum of the Squares of All Even Numbers Up to N


Difficulty: Medium
Topics: Mathematical Computations
Description: Write a program to calculate the sum of squares of all even numbers up
to a given N.
Example:
Input: N = 4
Output: 20
Explanation: The even numbers up to 4 are 2 and 4, and their squares are 4 and 16.
The sum is 20.

Generating a Pattern of Increasing Numbers


Difficulty: Easy
Topics: Patterns
Description: Write a program to create a pattern where numbers increase with each
row.
Example:
Input: rows = 3
Output:

1
12
123
Finding the Largest Element in Each Row of a Matrix
Difficulty: Easy
Topics: Matrix Operations
Description: Write a program to find the largest element in each row of a matrix.
Example:
Input: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Output: [3, 6, 9]
Explanation: The largest elements in each row are 3, 6, and 9.

Checking for Anagram Pairs in a List of Strings


Difficulty: Medium
Topics: String Manipulation
Description: Write a program to find pairs of strings in a list that are anagrams
of each other.
Example:
Input: strings = ["listen", "silent", "hello", "world"]
Output: [("listen", "silent")]
Explanation: "listen" and "silent" are anagrams.

Finding the Frequency of Each Character in a String


Difficulty: Easy
Topics: String Manipulation
Description: Write a program to count the frequency of each character in a given
string.
Example:
Input: string = "hello"
Output: {'h': 1, 'e': 1, 'l': 2, 'o': 1}
Explanation: The frequency of each character in the string "hello" is shown.

Generating a Matrix with Random Numbers


Difficulty: Easy
Topics: Random Number Generation, Matrix Operations
Description: Write a program to generate a matrix filled with random numbers.
Example:
Input: rows = 2, columns = 3
Output:

3 8 1
7 4 6
Finding the Length of the Longest Word in a String
Difficulty: Easy
Topics: String Manipulation
Description: Write a program to find the length of the longest word in a given
string.
Example:
Input: string = "Find the longest word"
Output: 8
Explanation: The longest word is "longest" with length 8.

Finding All Triplets in an Array That Sum to Zero


Difficulty: Medium
Topics: Arrays, Sorting
Description: Write a program to find all unique triplets in an array that sum to
zero.
Example:
Input: array = [-1, 0, 1, 2, -1, -4]
Output: [[-1, -1, 2], [-1, 0, 1]]
Explanation: The unique triplets that sum to zero are listed.

Generating a Square Matrix with Random Values


Difficulty: Easy
Topics: Random Number Generation, Matrix Operations
Description: Write a program to generate a square matrix where each element is a
random value.
Example:
Input: size = 3
Output:

7 3 5
2 6 9
1 8 4
Finding the Difference Between the Sum of Even and Odd Numbers in an Array
Difficulty: Easy
Topics: Arrays, Mathematical Computations
Description: Write a program to calculate the difference between the sum of even
and odd numbers in an array.
Example:
Input: array = [1, 2, 3, 4, 5, 6]
Output: 4
Explanation: The sum of even numbers is 12, and the sum of odd numbers is 8. The
difference is 4.

Generating a Triangle Pattern of Stars with a Given Height


Difficulty: Easy
Topics: Patterns
Description: Write a program to create a triangle pattern of stars with a specified
height.
Example:
Input: height = 4
Output:

*
**
***
****

s3

Problem 1: Print a Right-Angle Triangle of Stars


Difficulty: Easy
Topics: Pattern Printing
Hint: Print a right-angle triangle pattern of stars (*). Each row should contain an
increasing number of stars, starting from 1 star in the first row.

Example 1: Input: n = 4
Output:

*
**
***
****
Problem 2: Print a Square of Stars
Difficulty: Easy
Topics: Pattern Printing
Hint: Print a square pattern of stars (*). Each row and column should have the same
number of stars.

Example 1: Input: n = 5
Output:

*****
*****
*****
*****
*****
Problem 3: Print a Pyramid Pattern
Difficulty: Easy
Topics: Pattern Printing
Hint: Print a pyramid pattern with stars (*). The pyramid should have a single peak
and each row should have an increasing number of stars, centered horizontally.

Example 1: Input: n = 3
Output:

*
***
*****
Problem 4: Print a Diamond Pattern
Difficulty: Easy
Topics: Pattern Printing
Hint: Print a diamond pattern with stars (*). The pattern should include a single
peak in the middle with symmetric rows above and below it.

Example 1: Input: n = 3
Output:

*
***
*****
***
*
Problem 5: Print a Hollow Square of Stars
Difficulty: Easy
Topics: Pattern Printing
Hint: Print a hollow square pattern with stars (*). The border of the square should
be filled with stars while the inner part should be empty.

Example 1: Input: n = 5
Output:

*****
* *
* *
* *
*****
Problem 6: Print a Number Triangle
Difficulty: Easy
Topics: Pattern Printing
Hint: Print a right-angle triangle pattern with numbers. Each row should contain an
increasing sequence of numbers starting from 1.

Example 1: Input: n = 4
Output:

1
12
123
1234
Problem 7: Print an Inverted Triangle Pattern
Difficulty: Easy
Topics: Pattern Printing
Hint: Print an inverted triangle pattern with stars (*). Each row should contain
decreasing numbers of stars from the top row.
Example 1: Input: n = 5
Output:

*****
****
***
**
*
Problem 8: Print a Diamond Pattern with Numbers
Difficulty: Easy
Topics: Pattern Printing
Hint: Print a diamond pattern with numbers. The pattern should have a peak in the
middle with symmetric rows above and below it.

Example 1: Input: n = 3
Output:

1
121
12321
121
1
Problem 9: Print a Right-Angle Triangle of Numbers
Difficulty: Easy
Topics: Pattern Printing
Hint: Print a right-angle triangle pattern with increasing numbers. Each row should
contain a continuous sequence of increasing numbers.

Example 1: Input: n = 4
Output:

1
23
456
78910
Problem 10: Print a Pyramid Pattern with Numbers
Difficulty: Easy
Topics: Pattern Printing
Hint: Print a pyramid pattern with increasing numbers. Each row should have an
increasing sequence of numbers, centered horizontally.

Example 1: Input: n = 3
Output:

1
232
34543
Problem 11: Print a Pattern of Alternating 0s and 1s
Difficulty: Medium
Topics: Matrix Pattern
Hint: Print a matrix where elements alternate between 0 and 1. The pattern should
alternate both row-wise and column-wise.

Example 1: Input: n = 4
Output:

0101
1010
0101
1010
Problem 12: Print a Pascal’s Triangle
Difficulty: Medium
Topics: Matrix Pattern
Hint: Print Pascal’s Triangle up to N rows. Each row should be constructed based on
the sum of the elements directly above it in the previous row.

Example 1: Input: n = 4
Output:

1
1 1
1 2 1
1 3 3 1
Problem 13: Print a Pattern of Consecutive Numbers
Difficulty: Medium
Topics: Matrix Pattern
Hint: Print a matrix of consecutive numbers starting from 1, filling rows
sequentially.

Example 1: Input: n = 3
Output:

1 2 3
4 5 6
7 8 9
Problem 14: Print a Star Pattern with Increasing Width
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a pattern where each row has an increasing width of stars.

Example 1: Input: n = 3
Output:

*
***
*****
Problem 15: Print a Right-Angle Triangle Pattern with Characters
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a right-angle triangle pattern using characters. Each row should
contain the same character repeated according to the row number.

Example 1: Input: n = 3
Output:

A
BB
CCC
Problem 16: Print a Checkerboard Pattern
Difficulty: Medium
Topics: Matrix Pattern
Hint: Print a checkerboard pattern with two different characters alternating.

Example 1: Input: n = 4
Output:

XOXOXO
OXOXOX
XOXOXO
OXOXOX
Problem 17: Print a Pyramid Pattern of Increasing Stars
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a pyramid pattern where each row increases in the number of stars.

Example 1: Input: n = 3
Output:

*
***
*****
Problem 18: Print a Border Pattern with Numbers
Difficulty: Medium
Topics: Matrix Pattern
Hint: Print a border pattern using numbers. The border should be filled with
numbers, and the inner part should be empty.

Example 1: Input: n = 4
Output:

1234
1 1
1 1
1234
Problem 19: Print an Inverted Pyramid Pattern with Characters
Difficulty: Medium
Topics: Pattern Printing
Hint: Print an inverted pyramid pattern using characters. Each row should have
decreasing characters from the top row.

Example 1: Input: n = 3
Output:

CCC
BB
A
Problem 20: Print a Cross Pattern with Stars
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a cross pattern using stars. The cross should be centered within a
matrix.

Example 1: Input: n = 5
Output:

***
*
*
*
***
Problem 21: Print a Spiral Matrix
Difficulty: Hard
Topics: Matrix Pattern
Hint: Print a matrix filled with numbers in a spiral pattern. The numbers should
start from 1 and increment as you move around the spiral.
Example 1: Input: n = 3
Output:

1 2 3
8 9 4
7 6 5
Problem 22: Print a Diamond Pattern with Increasing Width
Difficulty: Hard
Topics: Pattern Printing
Hint: Print a diamond pattern where each line has increasing width of stars.

Example 1: Input: n = 3
Output:

*
***
*****
***
*
Problem 23: Print a Diamond Pattern with Numbers Increasing
Difficulty: Hard
Topics: Pattern Printing
Hint: Print a diamond pattern where numbers increase. Each row should show a
symmetrical pattern with numbers increasing towards the center.

Example 1: Input: n = 3
Output:

1
121
12321
121
1
Problem 24: Print a Pattern of Increasing and Decreasing Stars
Difficulty: Hard
Topics: Pattern Printing
Hint: Print a pattern where stars increase to a midpoint and then decrease.

Example 1: Input: n = 3
Output:

*
***
*****
***
*
Problem 25: Print a Matrix with Zigzag Pattern
Difficulty: Hard
Topics: Matrix Pattern
Hint: Print a matrix with a zigzag pattern of numbers. The numbers should alternate
direction row-wise.

Example 1: Input: n = 3
Output:

1 2 3 4
8 7 6 5
9 10 11 12
Problem 26: Print a Pattern of Alternating Characters in Rows
Difficulty: Hard
Topics: Pattern Printing
Hint: Print a pattern where rows alternate between two characters.

Example 1: Input: n = 4
Output:

ABAB
BABA
ABAB
BABA
Problem 27: Print a Number Pyramid Pattern with Characters
Difficulty: Hard
Topics: Pattern Printing
Hint: Print a pyramid pattern using increasing characters, where each row increases
in width and character range.

Example 1: Input: n = 3
Output:

A
BCD
EFGHI
Problem 28: Print a Pattern with Diagonal Lines
Difficulty: Hard
Topics: Pattern Printing
Hint: Print a pattern with diagonal lines using characters. Each diagonal line
should be aligned properly.

Example 1: Input: n = 4
Output:

A
B B
C C
D D
Problem 29: Print a Matrix with Diamond Pattern of Numbers
Difficulty: Hard
Topics: Matrix Pattern
Hint: Print a matrix where elements follow a diamond pattern with numbers.

Example 1: Input: n = 3
Output:

1
121
12321
121
1
Problem 30: Print a Cross Pattern of Stars with Diagonals
Difficulty: Hard
Topics: Pattern Printing
Hint: Print a cross pattern using stars with intersecting diagonals.

Example 1: Input: n = 5
Output:

* * * * *
* * * *
* * *
* *
*
* *
* * *
* * * *
* * * * *
Problem 31: Print a Triangular Matrix with Numbers
Difficulty: Easy
Topics: Pattern Printing
Hint: Print a triangular matrix where each row contains increasing numbers. Each
subsequent row should start from the next number.

Example 1: Input: n = 3
Output:

1
2 3
4 5 6
Problem 32: Print a Star Pattern with Increasing and Decreasing Width
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a pattern with stars that increase to a midpoint and then decrease. The
stars should be centered horizontally.

Example 1: Input: n = 3
Output:

*
***
*****
***
*
Problem 33: Print a Pattern of Nested Squares
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a pattern with nested squares using stars. The outermost square should
be filled with stars, and each subsequent square should be smaller and centered
inside the previous one.

Example 1: Input: n = 5
Output:

*****
* *
* *
* *
*****
Problem 34: Print a Pattern with Increasing Characters in Columns
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a pattern where each column contains increasing characters from A.

Example 1: Input: n = 3
Output:

A
B C
D E F
Problem 35: Print a Matrix with Spiral Diagonals
Difficulty: Hard
Topics: Matrix Pattern
Hint: Print a matrix with numbers arranged in diagonal spirals. The numbers should
fill the matrix in a diagonal spiral fashion.

Example 1: Input: n = 3
Output:

1 2 3
4 5 6
7 8 9
Problem 36: Print a Checkerboard Pattern with Increasing Size
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a checkerboard pattern where the size of each square increases as you
move along the matrix.

Example 1: Input: n = 3
Output:

XOX
OXO
XOX
Problem 37: Print a Cross Pattern with Increasing Size
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a cross pattern where the size of the cross increases with each row.
The pattern should be centered.

Example 1: Input: n = 3
Output:

*
***
*****
***
*
Problem 38: Print a Pattern of Alternating Triangles
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a pattern with alternating triangles of stars. The triangles should
alternate direction.

Example 1: Input: n = 3
Output:

*
***
*****
***
*
Problem 39: Print a Matrix with Diamond Pattern of Numbers
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a matrix where numbers form a diamond pattern. The numbers should
increase and decrease symmetrically around the center.

Example 1: Input: n = 3
Output:

1
121
12321
121
1
Problem 40: Print a Star Pattern with Increasing Width and Centered
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a pattern where the width of stars increases, and the stars are
centered horizontally.

Example 1: Input: n = 3
Output:

*
***
*****
Problem 41: Print a Pattern with Spiral and Zigzag
Difficulty: Hard
Topics: Matrix Pattern
Hint: Print a matrix with both spiral and zigzag patterns. The matrix should first
fill in a spiral pattern and then in a zigzag fashion.

Example 1: Input: n = 3
Output:

1 2 3
6 5 4
7 8 9
Problem 42: Print a Pattern of Alternating Characters in Matrix
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a matrix where characters alternate in each cell to form a pattern.

Example 1: Input: n = 3
Output:

ABAB
BABA
ABAB
Problem 43: Print a Pattern with Nested Triangles
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a pattern with nested triangles of stars. Each triangle should be
centered and decrease in size.

Example 1: Input: n = 3
Output:

*
***
*****
***
*
Problem 44: Print a Matrix with Increasing Rows and Columns
Difficulty: Easy
Topics: Matrix Pattern
Hint: Print a matrix where each row and column contains increasing numbers.

Example 1: Input: n = 3
Output:

1 2 3
4 5 6
7 8 9
Problem 45: Print a Pattern with Rows of Increasing Characters
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a pattern where each row contains an increasing sequence of characters.

Example 1: Input: n = 3
Output:

A
BC
DEF
Problem 46: Print a Star Pattern with Diamond Shape and Numbers
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a pattern with a diamond shape of stars, with numbers inside the
diamond.

Example 1: Input: n = 3
Output:

1
121
12321
121
1
Problem 47: Print a Matrix with Cross Pattern of Numbers
Difficulty: Hard
Topics: Matrix Pattern
Hint: Print a matrix where the center forms a cross pattern with numbers.

Example 1: Input: n = 5
Output:

12321
01210
01210
01210
12321
Problem 48: Print a Pattern with Concentric Squares
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a pattern with concentric squares using stars. The outer square should
be larger and each subsequent square should be centered inside.

Example 1: Input: n = 5
Output:

*****
* *
* *
* *
*****
Problem 49: Print a Pattern of Alternating Rows and Columns of Numbers
Difficulty: Easy
Topics: Pattern Printing
Hint: Print a pattern with alternating rows and columns of numbers, where each row
and column increases sequentially.

Example 1: Input: n = 3
Output:

123
456
789
Problem 50: Print a Matrix with Zigzag Pattern of Stars
Difficulty: Medium
Topics: Pattern Printing
Hint: Print a matrix where stars form a zigzag pattern, alternating rows in their
positioning.

Example 1: Input: n = 3
Output:

* * *
* *
* * *

You might also like