Campusmonk DSA BlackBook Series – Part 1 (Exam Pattern)

Posted on: Mon Jul 21 2025

 

✅ Q1. Count All Digits of a Number

Problem Statement:
Given an integer n, write a program to count the total number of digits in n.

Input Format:

  • A single integer n (0 ≤ n ≤ 10⁹)

Output Format:

  • An integer representing the number of digits in n

Examples:

Input: 4  

Output: 1

 

Input: 14  

Output: 2

 

📎 Practice Link (GFG)

 


 

✅ Q2. Count Number of Odd Digits

Problem Statement:
Given an integer n, return the number of odd digits present in n.

Input Format:

  • A single integer n

Output Format:

  • An integer representing the number of odd digits

Examples:

Input: 5  

Output: 1

 

Input: 25  

Output: 1

 

 


 

✅ Q3. Reverse a Number

Problem Statement:
Given an integer n, return the number formed by reversing its digits.
Ignore any leading zeros in the reversed number.

Input Format:

  • A single integer n

Output Format:

  • Reversed integer

Examples:

Input: 1234  

Output: 4321

 

Input: 120  

Output: 21

 

📎 Practice Link (LeetCode)

 


 

✅ Q4. Check if a Number is Palindrome

Problem Statement:
Write a program to check whether a given number n is a palindrome.
A number is a palindrome if it reads the same forwards and backwards.

Input Format:

  • A single integer n

Output Format:

  • true if it is a palindrome, otherwise false

Examples:

Input: 121  

Output: true

 

Input: 123  

Output: false

 

📎 Practice Link (LeetCode)

 


 

✅ Q5. Find the Largest Digit in a Number

Problem Statement:
Given a positive integer n, write a program to find the largest digit in the number.

Input Format:

  • A single integer n

Output Format:

  • An integer representing the largest digit

Examples:

Input: 5492  

Output: 9

 

Input: 103  

Output: 3

 

 


 

✅ Q6. Print All Divisors of a Number

Problem Statement:
Given a number n, write a program to print all the divisors of n in ascending order.

Input Format:

  • A single integer n (1 ≤ n ≤ 10⁶)

Output Format:

  • Space-separated integers representing all divisors of n

Examples:

Input: 12  

Output: 1 2 3 4 6 12

 

Input: 7  

Output: 1 7

 

📎 Practice Link (GFG)

 


 

✅ Q7. Factorial of a Number

Problem Statement:
Write a program to find the factorial of a given number n.

Input Format:

  • A single integer n (1 ≤ n ≤ 20)

Output Format:

  • A single long integer representing n!

Examples:

Input: 5  

Output: 120

 

Input: 1  

Output: 1

 

📎 Practice Link (HackerEarth)

 


 

✅ Q8. Check if a Number is Armstrong

Problem Statement:
A number is called an Armstrong number if the sum of its digits raised to the power of the number of digits is equal to the number itself.
Write a program to check if the given number is Armstrong.

Input Format:

  • A single integer n

Output Format:

  • true if it is Armstrong, otherwise false

Examples:

Input: 153  

Output: true

 

Input: 123  

Output: false

 

📎 Practice Link (GFG)

 


 

✅ Q9. Check for Perfect Number

Problem Statement:
A number is said to be perfect if it is equal to the sum of its proper divisors (excluding itself).
Write a program to check whether a number is perfect.

Input Format:

  • A single integer n

Output Format:

  • true if the number is perfect, otherwise false

Examples:

Input: 28  

Output: true  

Explanation: 1 + 2 + 4 + 7 + 14 = 28

 

Input: 15  

Output: false

 

📎 Practice Link (LeetCode)

 


 

✅ Q10. Check if a Number is Prime

Problem Statement:
Write a program to check whether the given number n is a prime number or not.

Input Format:

  • A single integer n

Output Format:

  • true if the number is prime, otherwise false

Examples:

Input: 7  

Output: true

 

Input: 9  

Output: false

 

📎 Practice Link (GFG)