messages listlengths 2 4 |
|---|
[
{
"role": "user",
"content": "Write a Python function `two_sum(nums, target)` that returns the indices [i, j] (i < j) of the two numbers in `nums` that add up to `target`. Assume exactly one solution exists. Stdlib only."
},
{
"role": "assistant",
"content": "<think>\nI need two_sum(nums, target... |
[
{
"role": "user",
"content": "Write a Python function `is_valid_parentheses(s)` that returns True if the brackets in `s` (only `()`, `[]`, `{}`) are correctly opened and closed in order."
},
{
"role": "assistant",
"content": "<think>\nI need is_valid_parentheses(s) that returns True only when ev... |
[
{
"role": "user",
"content": "Given a list of [start, end] intervals, merge all overlapping or touching intervals and return the merged list sorted by start. Python stdlib only."
},
{
"role": "assistant",
"content": "<think>\nI need merge_intervals(intervals) returning merged, sorted-by-start in... |
[
{
"role": "user",
"content": "Implement `binary_search(arr, target)` returning the index of `target` in the sorted list `arr`, or -1 if absent. Iterative, stdlib only."
},
{
"role": "assistant",
"content": "<think>\nI need binary_search(arr, target) returning the index of target in a sorted list... |
[
{
"role": "user",
"content": "Given a 2D grid of 0 (open) and 1 (wall), write `shortest_path(grid)` using BFS from the top-left cell to the bottom-right cell. Return the number of cells in the shortest path, or -1 if unreachable."
},
{
"role": "assistant",
"content": "<think>\nI need shortest_pa... |
[
{
"role": "user",
"content": "Implement `top_k_frequent(nums, k)` returning the k most frequent elements in `nums`. Python stdlib only."
},
{
"role": "assistant",
"content": "<think>\nI need top_k_frequent(nums, k) returning the k most common elements. Plan the state: a Counter maps value -> fre... |
[
{
"role": "user",
"content": "Implement `length_of_longest_substring(s)` returning the length of the longest substring without repeating characters. Sliding window, stdlib only."
},
{
"role": "assistant",
"content": "<think>\nI need length_of_longest_substring(s). The sliding window state is: la... |
[
{
"role": "user",
"content": "Write `group_anagrams(words)` that groups strings that are anagrams of each other. Return a list of groups. Python stdlib only."
},
{
"role": "assistant",
"content": "<think>\nI need group_anagrams(words) that groups anagrams. The whole idea lives in one key decisio... |
[
{
"role": "user",
"content": "Implement `rotate(nums, k)` that rotates the list `nums` to the right by `k` steps, in place. Python stdlib only."
},
{
"role": "assistant",
"content": "<think>\nI need rotate(nums, k) to rotate a list right by k steps in place. First normalize k: k %= n so k > n an... |
[
{
"role": "user",
"content": "Given an integer list `nums`, return `answer` where `answer[i]` is the product of all elements except `nums[i]`, without using division. O(n) time."
},
{
"role": "assistant",
"content": "<think>\nI need product_except_self(nums), every element replaced by the produc... |
[
{
"role": "user",
"content": "Write `max_subarray(nums)` returning the largest sum of any contiguous non-empty subarray (Kadane's algorithm)."
},
{
"role": "assistant",
"content": "<think>\nI need max_subarray(nums), the largest sum of any contiguous non-empty subarray. The state is two scalars:... |
[
{
"role": "user",
"content": "Design an `LRUCache` class with `get(key)` and `put(key, value)`, capacity-bounded, evicting the least recently used entry on overflow. Use collections.OrderedDict."
},
{
"role": "assistant",
"content": "<think>\nI need an LRUCache class with get and put, capacity-b... |
[
{
"role": "user",
"content": "Implement `flood_fill(image, sr, sc, new_color)`: recolor the connected component of the starting cell (4-directionally) to new_color. In place, iterative."
},
{
"role": "assistant",
"content": "<think>\nI need flood_fill(image, sr, sc, new_color), recoloring the 4-... |
[
{
"role": "user",
"content": "Given a 2D grid of '1' (land) and '0' (water) strings, write `num_islands(grid)` that counts connected components of land (4-directionally). Python stdlib only."
},
{
"role": "assistant",
"content": "<think>\nI need num_islands(grid) counting connected land componen... |
[
{
"role": "user",
"content": "Given coin denominations and an amount, return the fewest coins needed to make the amount, or -1 if impossible. `coin_change(coins, amount)`, bottom-up DP."
},
{
"role": "assistant",
"content": "<think>\nI need coin_change(coins, amount) returning the fewest coins f... |
[
{
"role": "user",
"content": "Implement `edit_distance(a, b)` returning the Levenshtein distance between strings a and b (insert, delete, substitute, unit cost). Bottom-up DP."
},
{
"role": "assistant",
"content": "<think>\nI need edit_distance(a, b), the Levenshtein distance with unit-cost inse... |
[
{
"role": "user",
"content": "Implement `length_of_lis(nums)` returning the length of the longest strictly increasing subsequence, O(n log n)."
},
{
"role": "assistant",
"content": "<think>\nI need length_of_lis(nums), the length of the longest strictly increasing subsequence, O(n log n). The st... |
[
{
"role": "user",
"content": "Given a string s and a list of words, write `word_break(s, words)` returning True iff s can be segmented entirely into words from the list. Bottom-up DP."
},
{
"role": "assistant",
"content": "<think>\nI need word_break(s, words), True iff s segments entirely into w... |
[
{
"role": "user",
"content": "Given an integer array and k, count the number of contiguous subarrays whose sum equals k. Handle negatives. `subarray_sum(nums, k)`."
},
{
"role": "assistant",
"content": "<think>\nI need subarray_sum(nums, k), count of contiguous subarrays summing to k, negatives ... |
[
{
"role": "user",
"content": "Return the elements of a 2D matrix in spiral order (left-to-right top, down right side, right-to-left bottom, up left side, shrinking inward). `spiral_order(matrix)`."
},
{
"role": "assistant",
"content": "<think>\nI need spiral_order(matrix), all cells in spiral or... |
[
{
"role": "user",
"content": "Given an m x n integer matrix, if an element is 0, set its entire row and column to 0. Do it in place, ideally O(1) extra space. `set_zeroes(matrix)`."
},
{
"role": "assistant",
"content": "<think>\nI need set_zeroes(matrix): any 0 cell takes its whole row and colum... |
[
{
"role": "user",
"content": "Write `is_valid_sudoku(board)` for a 9x9 board with digits '1'-'9' and '.' for empty cells; return True iff no row, column, or 3x3 box contains a duplicate digit."
},
{
"role": "assistant",
"content": "<think>\nI need is_valid_sudoku(board), a 9x9 with digits '1'-'9... |
[
{
"role": "user",
"content": "Given elevation heights, compute how much rain water is trapped after raining. `trap(height)`, O(n) time."
},
{
"role": "assistant",
"content": "<think>\nI need trap(height), water trapped by an elevation map, O(n) time O(1) space. State: two pointers left and right... |
[
{
"role": "user",
"content": "Given k sorted integer lists, merge them into one sorted list. `merge_k_lists(lists)`, heap-based."
},
{
"role": "assistant",
"content": "<think>\nI need merge_k_lists(lists), k sorted integer lists merged into one sorted list, heap-based. State: a heap of triples (... |
[
{
"role": "user",
"content": "Implement a `TokenBucket` rate limiter with capacity and refill rate (tokens/second). Method `allow(now, cost=1.0)` returns True if `cost` tokens are available at time `now` (seconds, float), consuming them if so."
},
{
"role": "assistant",
"content": "<think>\nI ne... |
[
{
"role": "user",
"content": "Write a Python expression evaluator using Pratt parsing (precedence climbing). It must support +, -, *, /, parentheses, unary minus, and integer or float literals, with correct precedence and left associativity. Stdlib only. Provide `evaluate(expr: str) -> float` and a runnable... |
[
{
"role": "user",
"content": "Write a JSON parser in Python by hand (recursive descent), no json module and no third-party libraries. Support objects, arrays, strings with escapes including \\uXXXX (and surrogate pairs), numbers, true/false/null. Raise a clear ValueError on malformed input. Include a demo u... |
[
{
"role": "user",
"content": "Build a tiny template engine in Python (stdlib only). Support `{{ dotted.path }}` variable interpolation (HTML-escaped) and `{% for item in items %} ... {% endfor %}` loops, including nesting. Unclosed tags and undefined variables must raise ValueError. Include a demo under `if... |
[
{
"role": "user",
"content": "Write a CSV parser in Python by hand (do not use the csv module). Handle quoted fields, doubled quotes inside quoted fields (\"\"), commas and newlines inside quotes, and CRLF line endings. An unterminated quote must raise ValueError. Include a demo under `if __name__ == \"__ma... |
[
{
"role": "user",
"content": "Write `roman_to_int(s: str) -> int` in Python, hand-rolled (no libraries). It must handle subtractive notation (IV = 4, CM = 900), reject malformed numerals (e.g. 'IIII', 'IC') with ValueError, and include a demo under `if __name__ == \"__main__\":`."
},
{
"role": "assi... |
[
{
"role": "user",
"content": "Write `int_to_roman(num: int) -> str` in Python using the greedy subtractive-pair table (no libraries). Reject out-of-range input (outside 1..3999) with ValueError. Include a demo under `if __name__ == \"__main__\":`."
},
{
"role": "assistant",
"content": "<think>\n... |
[
{
"role": "user",
"content": "Write a hand-rolled URL query-string parser in Python (do not use urllib.parse). Support `?a=1&b=2`, percent-decoding (UTF-8 aware), `+` as space, keys without `=` (value ''), and repeated keys collected into lists. Malformed percent-encoding must raise ValueError. Include a de... |
[
{
"role": "user",
"content": "Write `slugify(text: str) -> str` in Python: lowercase, strip accents, replace runs of non-alphanumeric characters with a single dash, strip leading/trailing dashes. Stdlib only (unicodedata, re). Include a demo under `if __name__ == \"__main__\":`."
},
{
"role": "assis... |
[
{
"role": "user",
"content": "Implement a Trie in Python (stdlib only) with `insert(word)`, `starts_with(prefix)`, and `autocomplete(prefix)` returning all stored words with that prefix in sorted order. Iterative traversal (no deep recursion). Include a demo under `if __name__ == \"__main__\":`."
},
{
... |
[
{
"role": "user",
"content": "Write `levenshtein(a: str, b: str) -> int` in Python using dynamic programming with O(min(m, n)) memory (two rows). Stdlib only. Include a demo under `if __name__ == \"__main__\":`."
},
{
"role": "assistant",
"content": "<think>\nWe need the edit distance between tw... |
[
{
"role": "user",
"content": "Write `eval_postfix(expr: str) -> float` in Python that evaluates reverse Polish notation with tokens separated by whitespace: +, -, *, /, parentheses-free. Underflow, unknown tokens, division by zero, and leftover operands must raise ValueError. Include a demo under `if __name... |
[
{
"role": "user",
"content": "Write `parse_ini(text: str) -> dict` in Python, hand-rolled: sections in [brackets], `key = value` pairs, `;` and `#` full-line comments, blank lines, optional quoted values. Duplicate sections and lines without '=' must raise ValueError. Include a demo under `if __name__ == \"... |
[
{
"role": "user",
"content": "Write a simple Markdown-to-HTML converter in Python (stdlib only: html, re). Support #/##/### headings, unordered lists with '-', paragraphs, and inline `code`, **bold**, *italic*. Escape raw HTML in the source. Include a demo under `if __name__ == \"__main__\":`."
},
{
... |
[
{
"role": "user",
"content": "Write an LCS-based line diff in Python (stdlib only). `diff_lines(a: str, b: str) -> list[tuple[str, str]]` returns (' '| '-' | '+', line) tuples aligning the two texts. Include a demo under `if __name__ == \"__main__\":`."
},
{
"role": "assistant",
"content": "<thi... |
[
{
"role": "user",
"content": "Write `topological_sort(nodes, edges)` in Python using Kahn's algorithm with a min-heap for deterministic output. `edges` are (before, after) pairs; unknown endpoints and cycles must raise ValueError. Include a demo under `if __name__ == \"__main__\":`."
},
{
"role": "a... |
[
{
"role": "user",
"content": "Write Dijkstra's shortest path in Python (stdlib only): `dijkstra(graph, source)` returning (dist, prev) and `path_to(prev, source, target)` reconstructing the path. Use heapq; reject negative weights; handle unreachable targets. Include a demo under `if __name__ == \"__main__\... |
[
{
"role": "user",
"content": "Implement a binary min-heap in Python from scratch (no heapq): `MinHeap` with `push`, `pop`, `peek`, `__len__`, and O(n) heapify construction from an iterable. Include a demo under `if __name__ == \"__main__\":`."
},
{
"role": "assistant",
"content": "<think>\nWe ne... |
[
{
"role": "user",
"content": "Write `min_meeting_rooms(intervals)` in Python: given a list of [start, end) meeting intervals, return the minimum number of rooms required. Stdlib only; reject end < start. Include a demo under `if __name__ == \"__main__\":`."
},
{
"role": "assistant",
"content": "... |
[
{
"role": "user",
"content": "Write `sliding_window_maximum(nums, k)` in Python using a deque in O(n). Stdlib only (collections.deque). Reject k <= 0 with ValueError; return [] when k > len(nums). Include a demo under `if __name__ == \"__main__\":`."
},
{
"role": "assistant",
"content": "<think>... |
[
{
"role": "user",
"content": "Write `max_profit(prices)` in Python: given daily stock prices, return the maximum profit from one buy and one sell (sell after buy), or 0 if none is profitable. One pass, O(1) space. Stdlib only. Include a demo under `if __name__ == \"__main__\":`."
},
{
"role": "assis... |
[
{
"role": "user",
"content": "Write `can_jump(nums)` in Python `True` if you can reach the last index of `nums` (each element is the max jump length from that position). Greedy O(n), O(1) space. Stdlib only. Include a demo under `if __name__ == \"__main__\":`."
},
{
"role": "assistant",
"content... |
[
{
"role": "user",
"content": "Write `rob(nums)` in Python: maximum money robbing non-adjacent houses from a list of house values, without robbing adjacent houses. One pass, O(1) space. Stdlib only. Include a demo under `if __name__ == \"__main__\":`."
},
{
"role": "assistant",
"content": "<think... |
[
{
"role": "user",
"content": "Write `num_decodings(s)` in Python counting decodings of a digit string (1=A..26=Z). Strings with invalid characters or a leading zero like '06' must yield 0 (and letters must raise ValueError). O(n) time, O(1) space. Stdlib only. Include a demo under `if __name__ == \"__main__... |
[
{
"role": "user",
"content": "Write `combination_sum(candidates, target)` in Python: all unique combinations from distinct `candidates` summing to `target`, unlimited reuse, each combination non-decreasing. Backtracking; sorted input gives canonical order. Include a demo under `if __name__ == \"__main__\":`... |
[
{
"role": "user",
"content": "Write `count_n_queens(n)` in Python counting placements of n non-attacking queens on an n×n board using backtracking with column and diagonal sets. O(n!) worst case but fast with pruning. Include a demo under `if __name__ == \"__main__\":`."
},
{
"role": "assistant",
... |
[
{
"role": "user",
"content": "Build a complete 2048 game as a single HTML file (inline CSS and JS, no libraries or external assets). 4x4 grid, arrow/WASD moves, correct merge-once-per-move rules, score, new tile spawn (2 or 4), game over detection when no moves remain, and a win overlay at 2048. Keep the de... |
[
{
"role": "user",
"content": "Build a complete Asteroids game as a single HTML file (inline CSS and JS, no libraries or external assets). Ship with rotate/thrust, bullets, three sizes of asteroids that split, lives, score, waves, and game over. Keep the design dark and polished, and expose a small window.__... |
[
{
"role": "user",
"content": "Build a complete single-player blackjack game as a single HTML file (inline CSS and JS, no libraries or external assets). Six-deck shoe reshuffled when low, deal/hit/stand, dealer draws to 17, blackjack pays 3:2, chips with a 10 bet, win/lose/push messaging, and a bankroll rese... |
[
{
"role": "user",
"content": "Build a complete Bomberman-style arena game as a single HTML file (inline CSS and JS, no libraries or external assets). 13x11 grid, destructible blocks, a player with bombs (2-second fuse, cross blast), two wandering enemies, three lives, score, win by clearing the enemies. Kee... |
[
{
"role": "user",
"content": "Build a complete Breakout game as a single HTML file (inline CSS and JS, no libraries or external assets). Canvas, paddle controlled by mouse or arrow keys, a launchable ball, 8x5 brick field, 3 lives, score, win when the board is cleared, lose when lives hit 0. Keep the design... |
[
{
"role": "user",
"content": "Build a complete two-player checkers game as a single HTML file (inline CSS and JS, no libraries or external assets). 8x8 board, red vs black, diagonal moves, captures by jumping, kings on the last rank, and win when the opponent has no pieces or no legal moves. Keep the design... |
[
{
"role": "user",
"content": "Build a complete two-player chess game as a single HTML file (inline CSS and JS, no libraries or external assets). 8x8 board with unicode pieces, click to select and move, full legal move generation (no castling/en passant/promotion yet), check detection, checkmate and stalemat... |
[
{
"role": "user",
"content": "Build a complete Connect Four game as a single HTML file (inline CSS and JS, no libraries or external assets). You play red against a CPU playing amber. Click a column to drop your disc. The CPU should use a minimax strategy with alpha-beta pruning, the board should highlight n... |
[
{
"role": "user",
"content": "Build a complete Doodle Jump game as a single HTML file (inline CSS and JS, no libraries or external assets). 360x600 canvas, auto-bounce on platforms, camera scrolls up, score is the altitude reached, game over when you fall below the view, best score in localStorage, left/rig... |
[
{
"role": "user",
"content": "Build a complete Flappy Bird game as a single HTML file (inline CSS and JS, no libraries or external assets). 400x600 canvas, gravity and flap physics, scrolling pipes with a gap, score, best score in localStorage, game over and restart. Keep the design dark and polished, and e... |
[
{
"role": "user",
"content": "Build a complete Frogger game as a single HTML file (inline CSS and JS, no libraries or external assets). 13x9 grid, road lanes with cars, river lanes with logs, five goal homes at the top, three lives, score for progress and homes, lose on traffic or water, and win when all ho... |
[
{
"role": "user",
"content": "Build a complete Lights Out puzzle as a single HTML file (inline CSS and JS, no libraries or external assets). 5x5 grid of light tiles; pressing a tile toggles it and its orthogonal neighbours. Show a moves counter and how many lights are lit. The board must always be solvable.... |
[
{
"role": "user",
"content": "Build a complete 3D maze game as a single HTML file (inline CSS and JS, no libraries or external assets). First-person view rendered by ray casting with no dependencies, an archipelago-style maze with six coins to collect, arrow keys and WASD to move and turn, coin counter HUD,... |
[
{
"role": "user",
"content": "Build a complete memory-match game as a single HTML file (inline CSS and JS, no libraries or external assets). 4x4 grid, eight pairs of colored glyph tiles, click to flip, matched pairs stay open, mismatched pairs flip back after a short delay, and a moves counter in the HUD. A... |
[
{
"role": "user",
"content": "Build a complete Minesweeper game as a single HTML file (inline CSS and JS, no libraries or external assets). 9x9 grid with 10 mines, left-click reveals, right-click flags, flood fill for empty regions, a timer that starts on first reveal, and a win when all non-mine cells are ... |
[
{
"role": "user",
"content": "Build a complete Pac-Man-style maze chase as a single HTML file (inline CSS and JS, no libraries or external assets). Fixed 19x15 maze, pellets, one shared draw canvas, 3 ghosts with chase/scatter phases, lives, score, win when every pellet is cleared. Keep the design dark and ... |
[
{
"role": "user",
"content": "Build a complete Pong game as a single HTML file (inline CSS and JS, no libraries or external assets). Canvas 640x400, player paddle on the left with W/S and arrow keys, CPU paddle on the right, first to 7, ball angle depends on where it hits the paddle. Show the score and targ... |
[
{
"role": "user",
"content": "Build a complete Simon memory game as a single HTML file (inline CSS and JS, no libraries or external assets). Four glowing pads, a sequence that grows each round, playback then your turn to repeat it, a wrong pad ends the run, best round in localStorage, and a mute toggle. Kee... |
[
{
"role": "user",
"content": "Build a complete Snake game as a single HTML file (inline CSS and JS, no libraries or external assets). Use a 20x20 grid on a canvas with 24px cells. Arrow keys and WASD steer, food makes the snake grow, and hitting a wall or yourself ends the run. Show score, best score (persi... |
[
{
"role": "user",
"content": "Build a complete Sokoban game as a single HTML file (inline CSS and JS, no libraries or external assets). One hand-authored level with a player, one box and one goal. Arrow keys or WASD push the box. Show a moves counter and boxes-on-goals counter. Add an end-of-game overlay wi... |
[
{
"role": "user",
"content": "Build a real-time solar system simulation as a single HTML file (inline CSS and JS, no libraries or external assets). Software-projected planets in a tilted orbit view with a glowing sun and starfield, five planets on Keplerian orbits, pause/resume, speed presets (1x to 240x), ... |
[
{
"role": "user",
"content": "Build a complete Space Invaders game as a single HTML file (inline CSS and JS, no libraries or external assets). A 5x8 fleet marches side to side and steps down, the player shoots with Space, enemy fire ramps up, reaching the bottom loses, clearing the fleet wins, three lives. ... |
[
{
"role": "user",
"content": "Build a complete 3D cube stacking game as a single HTML file (inline CSS and JS, no libraries or external assets). Software 3D projection on a canvas, a cube swaying above the tower, Space to drop, accept landings within half a cube of center, three misses and the run ends, bes... |
[
{
"role": "user",
"content": "Build a complete Sudoku game as a single HTML file (inline CSS and JS, no libraries or external assets). 9x9 grid, generate a fresh solvable puzzle, typing digits into cells, conflict highlighting when a row, column or box contains a duplicate, and a win overlay when the board ... |
[
{
"role": "user",
"content": "Build a complete Tetris game as a single HTML file (inline CSS and JS, no libraries or external assets). 10x20 board, all seven tetrominoes with rotation and basic wall kicks, gravity that speeds up per level, line clears with the standard 100/300/500/800 scoring, next-piece pr... |
[
{
"role": "user",
"content": "Build a complete tic-tac-toe game as a single HTML file (inline CSS and JS, no libraries or external assets). You are X against a CPU playing O. The CPU should use an unbeatable strategy, the board should be nine large clickable cells, and the HUD should track wins, losses and ... |
[
{
"role": "user",
"content": "Build a complete tower defense game as a single HTML file (inline CSS and JS, no libraries or external assets). Fixed path on a canvas grid, waves of enemies, one tower type (gun, cost 50, range, fire rate, damage), click a cell to build, money from kills, 20 lives, win after f... |
[
{
"role": "user",
"content": "Build a complete Whack-a-Mole game as a single HTML file (inline CSS and JS, no libraries or external assets). 3x3 holes on a canvas, 30-second rounds, a mole pops up in a random hole for a window that shrinks as you score, clicking the mole scores, best in localStorage, pause ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.