Biggest gap between numbers comes out as -1
largest_gap(nums) returns the biggest jump between neighbouring numbers in a list that goes up. Example: largest_gap([1, 5, 6]) → 4.
Explore 184 Python challenges. Filter by bug pattern or difficulty.
update_matrix_value(rows, cols, r, c, val) creates a 2D zero-filled grid and updates only the cell at row r, column c. Example: update_matrix_value(2, 2, 0, 0, 99) → [[99, 0], [0, 0]].
Scope error
count_words(text) counts the total words in a string, ignoring irregular consecutive spaces. Example: count_words("hello world") → 2.
Logic error
strip_log_extension(filename) removes the trailing ".log" extension from a filename. Example: strip_log_extension("catalog.log") → "catalog".
Logic error
calculate_bonus(score, is_vip) adds a 50 bonus if is_vip is True, adding 0 otherwise. Example: calculate_bonus(100, False) → 100.
Scope error
count_active_users(users) returns the count of users where active is True. Example: count_active_users([{"active": True}, {"active": False}]) → 1.
Type error
track_two_user_carts(item1, item2) creates two independent carts and adds item1 to the first and item2 to the second. Example: track_two_user_carts("apple", "banana") → [["apple"], ["banana"]].
Scope error
divide_truncate_toward_zero(a, b) divides a by b, truncating the fractional part toward zero. Example: divide_truncate_toward_zero(-7, 2) → -3.
Logic error
summarize_stream(numbers) returns a dictionary with the count and sum of numbers. Example: summarize_stream([10, 20]) → {"count": 2, "sum": 30}.
Logic error
extract_first_digits(text) returns the first sequence of digits found anywhere in text. Example: extract_first_digits("order_123") → "123".
Logic error
remove_even_numbers(numbers) removes all even integers and returns a list containing only odd numbers. Example: remove_even_numbers([2, 4, 6]) → [].
Logic error
build_api_endpoint_path(base_path, sub_path) joins base_path and sub_path into a complete path string. Example: build_api_endpoint_path("/api/v1", "/users") → "/api/v1/users".
Logic error
is_matching_account_id(account_id, target_id) returns True if account_id matches target_id by value. Example: is_matching_account_id(1000, 1000) → True.
Logic error
increment_integer_only(val) increments val by 1 only if val is a mathematical integer, returning None for booleans and other types. Example: increment_integer_only(True) → None.
Type error
purge_inactive_sessions(sessions) removes all keys where active is False and returns the cleaned dictionary. Example: purge_inactive_sessions({"s1": True, "s2": False}) → {"s1": True}.
Logic error
count_unique_points(points) counts the different map pins. Each pin is [x, y]. Example: count_unique_points([[0, 0], [1, 2], [0, 0]]) → 2.
Type error
total_with_tip(bill, tip_percent) adds a tip to a bill. Example: total_with_tip(100, 10) → 110.
Scope error
first_pair(nums, target) returns the first pair, from the left, that adds up to target. Example: first_pair([1, 2, 3, 4], 5) → [1, 4].
Logic error
sum_evens(nums) adds up only the even numbers. Example: sum_evens([1, 2, 3, 4]) → 6.
Logic error
price_label(amount) shows a price with exactly two decimal places. Example: price_label(2.5) → "$2.50", price_label(3) → "$3.00".
Other
An AI assistant wrote this for a classic interview question. is_balanced(text) returns True when every ( is closed by a ) that comes after it. Example: is_balanced("(())") → True, is_balanced(")(") → False.
Logic error
rank(students) takes [name, score] pairs and returns the names from highest score to lowest. Example: rank([["asha", 72], ["ravi", 95], ["zoe", 60]]) → ["ravi", "asha", "zoe"].
Logic error
swap(pair) returns the two values in the opposite order. Example: swap([1, 2]) → [2, 1].
Logic error
count_clicks(n) clicks a Counter n times and returns the count. Example: count_clicks(3) → 3.
Scope error
greet(name) welcomes a user, and uses "guest" when no name was typed. Example: greet("") → "Hello, guest".
Null / Undefined
transpose(grid) swaps rows and columns. Example: transpose([[1, 2, 3], [4, 5, 6]]) → [[1, 4], [2, 5], [3, 6]].
Off-by-one
Showing 51–75 of 184 Python challenges