{"id":16561856,"url":"https://github.com/mzollin/dailycodingproblems","last_synced_at":"2026-02-02T00:01:42.158Z","repository":{"id":114786930,"uuid":"227175239","full_name":"mzollin/DailyCodingProblems","owner":"mzollin","description":null,"archived":false,"fork":false,"pushed_at":"2022-02-27T22:08:42.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-15T15:15:55.091Z","etag":null,"topics":["daily-coding-problem","dailycodingproblem"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mzollin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-10T17:14:17.000Z","updated_at":"2022-02-16T10:12:56.000Z","dependencies_parsed_at":"2023-03-30T08:54:38.537Z","dependency_job_id":null,"html_url":"https://github.com/mzollin/DailyCodingProblems","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mzollin/DailyCodingProblems","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzollin%2FDailyCodingProblems","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzollin%2FDailyCodingProblems/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzollin%2FDailyCodingProblems/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzollin%2FDailyCodingProblems/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mzollin","download_url":"https://codeload.github.com/mzollin/DailyCodingProblems/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzollin%2FDailyCodingProblems/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28996568,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T23:10:54.274Z","status":"ssl_error","status_checked_at":"2026-02-01T23:10:47.298Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["daily-coding-problem","dailycodingproblem"],"created_at":"2024-10-11T20:34:32.668Z","updated_at":"2026-02-02T00:01:42.119Z","avatar_url":"https://github.com/mzollin.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Daily Coding Problems\n\n## Day 1\n\u003eGiven a list of numbers and a number k, return whether any two numbers from the list add up to k.\nFor example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17.  \n\u003eBonus: Can you do this in one pass?\n```python\nfrom typing import List\n\nk: int = 17\nnumbers: List[int] = [10, 15, 3, 7]\n\ndef check_addup(k: int, numbers: List[int]) -\u003e bool:\n    for number in numbers:\n        if k - number in numbers:\n            return True\n    return False\n\nassert check_addup(k, numbers)\n```\n\n## Day 2\n\u003eGiven an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i. For example, if our input was [1, 2, 3, 4, 5], the expected output would be [120, 60, 40, 30, 24]. If our input was [3, 2, 1], the expected output would be [2, 3, 6].  \n\u003eFollow-up: what if you can't use division?\n```python\nimport math\nfrom typing import List\n\nnumbers1: List[int] = [1, 2, 3, 4, 5]\nnumbers2: List[int] = [3, 2, 1]\n\ndef array_product(numbers: List[int]) -\u003e List[int]:\n    prod = math.prod(numbers)\n    return [int(prod / i) for i in numbers]\n\ndef array_product_nodiv(numbers: List[int]) -\u003e List[int]:\n    products = list(numbers)\n    for i, _n in enumerate(numbers):\n        element = numbers.pop(i)\n        products[i] = math.prod(numbers)\n        numbers.insert(i, element)\n    return products\n\nassert array_product(numbers1) == [120, 60, 40, 30, 24]\nassert array_product(numbers2) == [2, 3, 6]\nassert array_product_nodiv(numbers1) == [120, 60, 40, 30, 24]\nassert array_product_nodiv(numbers2) == [2, 3, 6]\n```\n\n## Day 3\n\u003eGiven the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string back into the tree.  \n\nThe Node class and test were given.  \n```python\nimport jsonpickle\n# I admit to taking the easy way out on this one ;)\n\nclass Node:\n    def __init__(self, val, left=None, right=None):\n        self.val = val\n        self.left = left\n        self.right = right\n\ndef serialize(root: Node) -\u003e str:\n    return jsonpickle.encode(root)\n\ndef deserialize(s: str) -\u003e Node:\n    return jsonpickle.decode(s)\n\nnode = Node('root', Node('left', Node('left.left')), Node('right'))\nassert deserialize(serialize(node)).left.left.val == 'left.left'\n```\n\n## Day 4\n\u003eGiven an array of integers, find the first missing positive integer in linear time and constant space. In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well. For example, the input [3, 4, -1, 1] should give 2. The input [1, 2, 0] should give 3. You can modify the input array in-place.  \n```python\nfrom typing import List\n\nnumbers1: List[int] = [3, 4, -1, 1]\nnumbers2: List[int] = [1, 2, 0]\n\ndef lowest_missing_number(numbers: List[int]) -\u003e int:\n    numbers.sort()\n    lowest: int = 1\n    for i in numbers:\n        if i == lowest + 1:\n            lowest = i\n    return lowest + 1\n\nassert lowest_missing_number(numbers1) == 2\nassert lowest_missing_number(numbers2) == 3\n```\n\n## Day 5\n\u003econs(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that pair. For example, car(cons(3, 4)) returns 3, and cdr(cons(3, 4)) returns 4. Implement car and cdr.  \n\nThe implementation of cons was given and therefore not type annotated.\n```python\nfrom typing import Callable, Any, TypeVar\n\ndef cons(a, b):\n    def pair(f):\n        return f(a, b)\n    return pair\n\n# Big thanks to Florian Bruhin for helping with the type annotations on this one\nA = TypeVar('A')\nB = TypeVar('B')\n\ndef car(pair: Callable[[Callable[[A, B], A]], A]) -\u003e A:\n    return pair(lambda a, b: a)\n\ndef cdr(pair: Callable[[Callable[[A, B], B]], B]) -\u003e B:\n    return pair(lambda a, b: b)\n\nassert car(cons(3, 4)) == 3\nassert cdr(cons(3, 4)) == 4\n```\n\n## Day 775\n\u003eGiven an array of time intervals (start, end) for classroom lectures (possibly overlapping), find the minimum number of rooms required.  \n\u003eFor example, given [(30, 75), (0, 50), (60, 150)], you should return 2.\n```python\nschedule1 = [(30, 75), (0, 50), (60, 150)]\nschedule2 = [(10, 20), (20, 30)]\nschedule3 = [(25, 35), (25, 35)]\n\ndef find_rooms_required(schedule: list[tuple[int, int]]) -\u003e int:\n    timeline = []\n    used = 0\n    for start, end in schedule:\n        timeline += [(start, 1)] + [(end, -1)]\n    return max([used := used + v[1] for v in sorted(timeline)])\n\nassert find_rooms_required(schedule1) == 2\nassert find_rooms_required(schedule2) == 1\nassert find_rooms_required(schedule3) == 2\n```\n\n## Day 781\n\u003eYou are given a histogram consisting of rectangles of different heights. These heights are represented in an input list, such that [1, 3, 2, 5] corresponds to the following diagram:\n\u003e```\n\u003e       x\n\u003e       x\n\u003e   x   x\n\u003e   x x x\n\u003e x x x x\n\u003e```\n\u003eDetermine the area of the largest rectangle that can be formed only from the bars of the histogram. For the diagram above, for example, this would be six, representing the 2 x 3 area at the bottom right.\n```python\nfrom typing import List\n\nhistogram: List[int] = [1, 3, 2, 5]\n\ndef histogram_max_area(histogram: List[int]):\n    \"\"\"Calculate the largest rectangular area in a histogram.\"\"\"\n    histogram = [0] + histogram + [0]\n    stack: List[int] = [0]\n    maximum: int = 0\n\n    for i, val in enumerate(histogram):\n        while val \u003c histogram[stack[-1]]:\n            height = histogram[stack.pop()]\n            area = height * (i - stack[-1] - 1)\n            maximum = max(maximum, area)\n        stack.append(i)\n    return maximum\n\nassert histogram_max_area(histogram) == 6\n```\n\n## Day 785\n\u003eGiven a list of integers, return the largest product that can be made by multiplying any three integers.  \n\u003eFor example, if the list is [-10, -10, 5, 2], we should return 500, since that's -10 * -10 * 5.\n```python\nfrom itertools import combinations\nfrom math import prod\nfrom typing import List\n\nnumbers: List[int] = [-10, -10, 5, 2]\n\ndef largest_list_product(numbers: List[int], n: int = 3):\n    \"\"\"Calculate the largest product of any n integers in a list.\"\"\"\n    if n \u003e len(numbers):\n        raise ValueError(\"Not enough numbers in the list for this product!\")\n    return max([prod(c) for c in combinations(numbers, n)])\n\nassert largest_list_product(numbers) == 500\nassert largest_list_product(numbers, 2) == 100\nassert largest_list_product(numbers, 1) == 5\n```\n\n## Day 795\n\u003eAssume you have access to a function `toss_biased()` which returns 0 or 1 with a probability that's not 50-50 (but also not 0-100 or 100-0). You do not know the bias of the coin. Write a function to simulate an unbiased coin toss.\n```python\nimport random\n\ndef toss_biased():\n    \"\"\"Coin flip with unknown bias.\"\"\"\n    return int(random.random() \u003c 0.7)\n\ndef toss_unbiased_from_biased():\n    \"\"\"Get fair toss from biased coin using von Neumann method.\"\"\"\n    while True:\n        toss = toss_biased()\n        if toss != toss_biased():\n            return toss\n\nub = [toss_unbiased_from_biased() for n in range(1000)]\nassert 0.45 \u003c sum(ub) / len(ub) \u003c 0.55\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmzollin%2Fdailycodingproblems","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmzollin%2Fdailycodingproblems","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmzollin%2Fdailycodingproblems/lists"}