Python Practice Challenges
Solve Python programming challenges. Test your understanding and improve your coding skills.
Difficulty:
Area of a Circle
Easy
Calculate the area of a circle given its radius (`r`). Use $\pi \approx 3.14159$. Round the result to two decimal places.
basics
math
Celsius to Fahrenheit
Easy
Convert a temperature from Celsius (`C`) to Fahrenheit (`F`). Formula: $F = C \times 9/5 + 32$. Return the result as an integer.
basics
math
Count Word Frequency
Medium
Given a string of text, return an object/map where keys are words and values are the frequency (count) of those words. Words should be lowercased and cleaned of punctuation.
objects_maps
strings
Linked List Reversal
Expert
Reverse a singly linked list in place and return the new head of the list. You will be given the head of the list.
data_structures
linked_lists
algorithms
Reverse a String
Medium
Given an input string, return the string with its characters in reverse order.
strings
Two Sum
Hard
Given an array of integers (`nums`) and a target sum, return the indices of the two numbers that add up to the target. Assume exactly one solution exists.
arrays
objects_maps
algorithms
Array Sum and Average
Easy
Calculate the sum and average of all numbers in a given list of integers. Return the result as an object (dictionary) with keys 'sum' and 'average'.
arrays
math
Check Palindrome
Medium
Determine if a given string is a palindrome (reads the same forwards and backwards, ignoring case and non-alphanumeric characters).
strings
Factorial (Recursive)
Medium
Calculate the factorial of a non-negative integer `n` using recursion. The factorial of a number is the product of all integers from 1 to that number.
recursion
math
Longest Word in Sentence
Hard
Find and return the longest word in a sentence. If there are ties in length, return the first longest word found. The result should be a cleaned word (no punctuation).
strings
arrays
Rotate Array Left
Hard
Rotate the elements of an array to the left by `k` steps. The rotation should be done in-place or return a new rotated array.
arrays
algorithms
Valid Parentheses
Hard
Determine if an input string of parentheses `(`, `)`, `{`, `}`, `[`, `]` is valid. A string is valid if open brackets must be closed by the same type of brackets, and open brackets must be closed in the correct order. Must use a stack data structure.
data_structures
algorithms
strings
stack
Binary Search
Medium
Implement the binary search algorithm to efficiently find a target value in a sorted array. Return the index of the target, or -1 if the target is not found.
arrays
algorithms
Count Vowels
Easy
Write a function that counts and returns the number of vowels (a, e, i, o, u) in a given string. Case should not matter.
strings
Fibonacci Sequence (Nth Term)
Hard
Find the nth term of the Fibonacci sequence, where F(0)=0 and F(1)=1. Optimize for performance using iteration or memoization to avoid redundant calculations.
recursion
algorithms
dynamic_programming
Remove Duplicates
Medium
Given a list of items, return a new list containing only the unique elements in their original order.
arrays
Sum of Two Integers (Bitwise)
Easy
Write a function that takes two integer inputs, `a` and `b`, and returns their sum without using the standard '+' or '-' operators. The solution must use bitwise operations.
basics
math
bitwise
