This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
def max_the_stock(prices: List[int]) -> int: | |
""" | |
Determine the maximum profit achievable by buying and selling a stock once. | |
Args: | |
prices (List[int]): A list of integers representing stock prices in chronological order. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
def see_buildings_left(buildings: List[int]) -> int: | |
""" | |
Calculate the number of buildings visible from the left. | |
A building is visible if it is taller than all the buildings to its left. | |
Args: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
from typing import List | |
def group_anagrams(words: List[str]) -> List[List[str]]: | |
"""Groups an array of strings into lists of anagrams. | |
Args: | |
words (List[str]): List of words to group by anagrams. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from collections import Counter | |
from typing import List, Dict | |
def roll_dice(num_dice: int = 5) -> List[int]: | |
""" | |
Rolls a specified number of dice and returns their values as a list. | |
Args: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
from urllib.request import urlopen, Request | |
from urllib.error import URLError | |
from typing import Optional | |
# Attempt to import feedparser; set flag based on availability | |
try: | |
import feedparser | |
USE_FEEDPARSER = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xml.sax.saxutils import escape | |
def generate_circle(radius: int, center: tuple[int, int], color: str) -> str: | |
""" | |
Generates a valid SVG string for a circle. | |
Args: | |
radius (int): The radius of the circle (must be positive). | |
center (tuple[int, int]): The (x, y) center position of the circle. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
from dataclasses import dataclass | |
from datetime import datetime, timedelta | |
from typing import List | |
@dataclass | |
class Ingredient: | |
""" | |
Class to represent an ingredient and its expiration date. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List, Optional | |
class StringSplitter: | |
@staticmethod | |
def split(string: str, delimiter: Optional[str] = None) -> List[str]: | |
""" | |
Splits the input string by the specified delimiter. | |
Args: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
from typing import List, Tuple | |
# Define the type alias for better readability (colour and fabric tuple) | |
ClothingItem = Tuple[str, str] | |
def min_laundry_loads(items: List[ClothingItem]) -> int: | |
""" | |
This function takes a list of clothing items, each represented by a tuple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ways_to_score(total_points: int) -> int: | |
""" | |
Calculate the number of unique ways in American Football 🏈 to score exactly total_points | |
using combinations of touchdowns (6 points), field goals (3 points), and safeties (2 points). | |
:param total_points: An integer representing the total points to score. | |
:return: The number of unique ways to score exactly total_points. | |
""" | |
# ways[i] will hold the number of ways to score exactly i points. |
NewerOlder