0% found this document useful (0 votes)
3 views3 pages

Competitive Coding Question Bank

Uploaded by

Khushboo Garg
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Competitive Coding Question Bank

Uploaded by

Khushboo Garg
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT 4 Question Bank - Competitive Coding (Beginner Level)

Total: 25 Problems

A. Prime Numbers - Sieve of Eratosthenes (5 questions)

1. Generate All Primes <= N

Implement Sieve of Eratosthenes to list all primes less than or equal to N.

2. Count Primes in Range [L, R]

Use Sieve to count how many prime numbers exist between L and R.

3. Is It a Prime?

For T test cases, check if each given number is prime using a sieve-preprocessed list.

4. Twin Primes <= N

Count pairs of primes (p, p+2) where both are <= N.

5. Prime Gaps <= N

Return the maximum difference between consecutive primes <= N.

B. File I/O in Python (4 questions)

6. Write and Read a List of Integers

Write integers to a file, then read and return them in reverse order.

7. Count Words in a Text File

Read a file and count the total number of words.

8. Copy File Content

Copy content from one file to another with line numbers prefixed.

9. Frequency of Characters

Read a file and return frequency count of each alphabet letter.

C. Exceptions and Assertions (4 questions)

10. Safe Division

Implement a function that divides two numbers and handles ZeroDivisionError.

11. Age Validator

Input age, raise ValueError if age < 0 or > 120.


12. Assertion Test

Assert that a number is a perfect square, else raise error.

13. Nested Try-Except

Catch multiple exceptions: IndexError, ValueError, and general Exception.

D. Modules (3 questions)

14. Create and Use Custom Module

Create a module math_utils with functions like factorial and GCD. Import and use them.

15. Built-in Module Use - Math

Use math module to compute trigonometric values, square roots, and factorials.

16. Random Password Generator

Use random and string to generate a password of length N.

E. Abstract Data Types - ADTs (4 questions)

17. Stack Implementation

Implement stack using list with push, pop, and peek.

18. Queue Implementation

Implement queue using list with enqueue, dequeue, and size.

19. Frequency Dictionary

Given a string, return a frequency dictionary of characters.

20. Student Marks Dictionary

Input N student names and marks, and return student with highest marks.

F. Classes, Special Methods, and Inheritance (5 questions)

21. Student Class with __str__

Define a Student class with name, age, and implement __str__.

22. Comparison Using __lt__

Compare two student objects based on marks using __lt__.

23. Bank Account with Balance

Class with methods deposit, withdraw, and balance check.


24. Inheritance - Animal and Dog

Use base class Animal, and override method speak in subclass Dog.

25. Operator Overloading - Complex Numbers

Define a Complex class that supports + and - operators.

You might also like