Step 01 Beginner Problems — Language Basics
Learn Python
Python is the fastest language to learn and to write: no boilerplate, no types to declare, and data structures like lists and dicts built into the syntax itself. For DSA it lets you think about the algorithm instead of the spelling. This lesson is an orientation — how a Python program looks, input done right, the core constructs for this sheet, and the road map through the library lessons.
A program with no ceremony
A Python file is just statements, executed top to bottom. Indentation is not style — it is the syntax that defines blocks, so keep it consistent (4 spaces). print() outputs, input() reads a line as a string, and int() converts. The whole 'sum of N numbers' program fits in a few lines:
def solve():
n = int(input())
total = 0
for _ in range(n):
total += int(input())
print(total)
solve()Input done right
input() always returns a string, so convert explicitly. For a line of space-separated numbers, the idiom is nums = list(map(int, input().split())) — split() breaks the line into words, map applies int to each, list collects them. Reading input one line at a time is fine for this sheet; when inputs grow huge, sys.stdin.readline or reading all of sys.stdin at once is the standard speed fix.
Two arithmetic traps to burn in now: / is true division (7 / 2 is 3.5) while // is floor division (7 // 2 is 3) — digit problems want //. And % is the remainder, your digit-extraction tool.
The core constructs tour
Numbers (int has unlimited size — overflow simply does not exist in Python), strings (immutable, sliceable: s[::-1] reverses), lists (dynamic arrays: append, pop, sort), dicts (hash maps: counting frequencies is a two-liner), and sets (uniqueness and O(1) membership). Loops: for x in range(n) for counting, for item in list for traversal, while cond for condition-driven work. Functions use def, and multiple return values come back as tuples.
One habit matters more than any other in Python: build strings with ''.join(list_of_pieces) instead of += in a loop, and prefer built-in functions (sum, max, sorted) over hand-written loops — they run at C speed.
Your Python road map for this sheet
In order: (1) this syntax core until patterns and digit problems feel mechanical; (2) recursion; (3) the two Python Libraries lessons in this module — built-ins and math first, then the DSA power tools: collections.Counter, deque, heapq, bisect and itertools. Python's weakness is raw speed, so you will lean on complexity analysis (the Time Complexity lesson) a little more than C++ users do — a fair trade for writing solutions in half the lines.
Key points
- Python has no skeleton and no overflow: indentation is syntax, ints are unbounded, input() always returns a string.
- The input idiom: list(map(int, input().split())); digit problems need // (floor division) and % (remainder), not /.
- Lists, dicts and sets are built into the syntax — frequencies via dict/Set are everyday tools, not library extras.
- Build strings with ''.join(...) and prefer built-ins like sum/max/sorted — they run at C speed.
- Road map: syntax core → recursion → Python Libraries Parts 1 and 2.