0% found this document useful (0 votes)
10 views1 page

Python DSA Practice Problems Guide

The document outlines a series of Python practice problems categorized into Easy, Medium, and Hard levels, focusing on foundational logic, strings, recursion, and object-oriented programming. Each problem includes a brief description of the task to be accomplished, such as FizzBuzz, sum of divisors, and anagram checking. It suggests a progression through the problems over two weeks to build confidence in Python and prepare for data structures and algorithms (DSA).
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)
10 views1 page

Python DSA Practice Problems Guide

The document outlines a series of Python practice problems categorized into Easy, Medium, and Hard levels, focusing on foundational logic, strings, recursion, and object-oriented programming. Each problem includes a brief description of the task to be accomplished, such as FizzBuzz, sum of divisors, and anagram checking. It suggests a progression through the problems over two weeks to build confidence in Python and prepare for data structures and algorithms (DSA).
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

Pre-DSA Python Practice Problems (Explanations

Only)
EASY (Foundational Logic & Lists)

1. FizzBuzz with Twist - Given an integer N, print numbers from 1 to N. For numbers divisible by 3,
print 'Fizz'; for numbers divisible by 5, print 'Buzz'; and for numbers divisible by both 3 and 5, print
'FizzBuzz'. Otherwise, print the number itself.

2. Sum of Divisors - Input a number and calculate the sum of all positive integers that divide it
exactly (divisors). For example, for 6 divisors are 1,2,3,6.

3. Max Consecutive Ones - Given a list containing only 0s and 1s, find the maximum number of
consecutive 1s in it. Example: [1,1,0,1,1,1] has a maximum of 3 consecutive 1s.

4. Rotate List - Input a list and a number K. Rotate the list to the right by K positions. Example:
[1,2,3,4,5] rotated by 2 -> [4,5,1,2,3].

5. Count Frequency of Elements - Input a list of numbers or strings. Count how many times each
distinct element appears and display the counts in order of their first appearance.

MEDIUM (Strings, Pairs, Recursion)

6. Pair Sum to Target - Given a list and a target sum, find all pairs of numbers whose sum equals
the target. Each pair should be listed once.

7. Anagram Checker - Given two strings, check if they are anagrams. Two strings are anagrams if
they contain the same characters in any order.

8. Longest Substring Without Repeating Characters - Input a string, find the longest substring
where all characters are unique (no character repeats). Return the length of that substring.

9. Compress String (Run-Length Encoding) - Input a string and compress it by replacing sequences
of the same character with the character followed by its count. Example: 'aaabb' -> 'a3b2'.

10. Recursive Sum of List - Write a recursive function that takes a list of numbers and returns the
sum of all elements without using built-in sum().

11. Recursive Palindrome Checker - Input a string and check recursively whether it reads the same
forwards and backwards (palindrome).

HARD (OOP & Advanced Logic)

12. Largest Prime Factor - Input a number and find its largest prime factor (a prime number that
divides the given number exactly).

13. Towers of Hanoi - Solve the classic puzzle where you move N disks from one rod to another
using a helper rod under the rules: only one disk at a time, larger disks cannot go on smaller ones.

14. Bank Account Class - Create a class for a bank account with attributes for balance and methods
to deposit money, withdraw money, and display the current balance.

15. Student Grades with Class - Create a class to store student names and their marks. Include
methods to calculate average marks, highest marks, and lowest marks.

SUGGESTED PROGRESSION: Start with Easy, then Medium, then Hard problems. Aim to
complete them over 2 weeks to build confidence in Python and get ready for DSA.

You might also like