1747154914

Programming Challenges for Skill Improvement


If you're looking to **sharpen your programming skills**, tackling a variety of challenges is one of the best ways to grow. Here are **10 engaging problems** that span different concepts—from **algorithms** to **data structures** and **problem-solving**—that will push you to think creatively and write efficient code. ### 1. **Reverse a String Without Built-in Functions** A classic warm-up! Instead of using `[::-1]` or `.reverse()`, try reversing a string manually. This helps you understand **loops** and **array indexing**. ```python def reverse_string(s): reversed_str = "" for char in s: reversed_str = char + reversed_str return reversed_str print(reverse_string("hello")) # Output: "olleh" ``` ### 2. **Find the Missing Number in an Array** Given an array of numbers from `1 to n` with one missing, find the gap. This tests your **logical reasoning** and **math skills**. ```python def find_missing(nums): n = len(nums) + 1 expected_sum = n * (n + 1) // 2 actual_sum = sum(nums) return expected_sum - actual_sum print(find_missing([3, 1, 4, 5])) # Output: 2 ``` ### 3. **Check for a Palindrome** Determine if a word or phrase reads the same backward (ignoring spaces and punctuation). Great for practicing **string manipulation**. ```python import re def is_palindrome(s): cleaned = re.sub(r'[^a-zA-Z0-9]', '', s.lower()) return cleaned == cleaned[::-1] print(is_palindrome("A man, a plan, a canal: Panama")) # Output: True ``` ### 4. **Implement a Basic Hash Table** Build a simple **hash table** from scratch to understand how key-value storage works under the hood. ```python class HashTable: def __init__(self): self.size = 10 self.table = [[] for _ in range(self.size)] def _hash(self, key): return hash(key) % self.size def set(self, key, value): hash_key = self._hash(key) for i, (k, v) in enumerate(self.table[hash_key]): if k == key: self.table[hash_key][i] = (key, value) return self.table[hash_key].append((key, value)) def get(self, key): hash_key = self._hash(key) for k, v in self.table[hash_key]: if k == key: return v raise KeyError(key) ``` ### 5. **Flatten a Nested List** Turn a multi-dimensional list (e.g., `[1, [2, [3]]]`) into a flat one (`[1, 2, 3]`). This is great for **recursion** practice. ```python def flatten(lst): result = [] for item in lst: if isinstance(item, list): result.extend(flatten(item)) else: result.append(item) return result print(flatten([1, [2, [3]])) # Output: [1, 2, 3] ``` ### 6. **Detect a Cycle in a Linked List** A common **data structures** problem—determine if a linked list loops back on itself. ```python class ListNode: def __init__(self, val=0): self.val = val self.next = None def has_cycle(head): slow = fast = head while fast and fast.next: slow = slow.next fast = fast.next.next if slow == fast: return True return False ``` ### 7. **Merge Two Sorted Arrays** Combine two sorted arrays into one sorted array **without** using built-in sort functions. Tests your **two-pointer technique**. ```python def merge_sorted(arr1, arr2): merged = [] i = j = 0 while i < len(arr1) and j < len(arr2): if arr1[i] < arr2[j]: merged.append(arr1[i]) i += 1 else: merged.append(arr2[j]) j += 1 merged.extend(arr1[i:]) merged.extend(arr2[j:]) return merged print(merge_sorted([1, 3, 5], [2, 4, 6])) # Output: [1, 2, 3, 4, 5, 6] ``` ### 8. **Find the Longest Substring Without Repeating Characters** A **sliding window** challenge to improve your **string and hash map** skills. ```python def longest_unique_substring(s): seen = {} start = max_len = 0 for i, char in enumerate(s): if char in seen and seen[char] >= start: start = seen[char] + 1 seen[char] = i max_len = max(max_len, i - start + 1) return max_len print(longest_unique_substring("abcabcbb")) # Output: 3 ("abc") ``` ### 9. **Implement a Binary Search Algorithm** A must-know **divide-and-conquer** method for efficient searching in **sorted arrays**. ```python def binary_search(arr, target): left, right = 0, len(arr) - 1 while left <= right: mid = (left + right) // 2 if arr[mid] == target: return mid elif arr[mid] < target: left = mid + 1 else: right = mid - 1 return -1 print(binary_search([1, 2, 3, 4, 5], 3)) # Output: 2 ``` ### 10. **Build a Simple Web Scraper** Use libraries like `requests` and `BeautifulSoup` to extract data from a webpage—great for **real-world automation**. ```python import requests from bs4 import BeautifulSoup def scrape_titles(url): response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') titles = [h.text for h in soup.find_all('h2')] return titles print(scrape_titles("https://example.com")) ``` Each of these challenges helps reinforce **core programming concepts** while keeping things practical.

(2) Comments
thecow
thecow
1747155132

i'm used to programmers saying study more lists and arrays =D


amargo85
amargo85
1747155054

excellent content! but I just think it should be represented in more than one language


Welcome to Chat-to.dev, a space for both novice and experienced programmers to chat about programming and share code in their posts.

About | Privacy | Donate
[2025 © Chat-to.dev]