Problem Solving — fix the bug — 260 questions
Play ▸- #1 · Which fix removes the bug? function add(a, b) { a + b; }
- #2 · What is the correct fix? def greet(name): print("Hi " + name)
- #3 · Which fix removes the bug? const nums = [1, 2, 3]; console.log(nums.length())
- #4 · What is the correct fix? nums = [10, 20, 30] print(nums[3])
- #5 · Which fix removes the bug? let x = 5 if (x = 10) { console.log("ten"); }
- #6 · What is the correct fix? total = 0 for i in range(5) total += i
- #7 · Which fix removes the bug? const name = "Ada"; console.log("Hello, " + Name);
- #8 · What is the correct fix? def square(n): return n ** 2 print(squere(4))
- #9 · Which fix removes the bug? const arr = [1, 2, 3]; arr.push;
- #10 · What is the correct fix? age = "20" next_year = age + 1
- #11 · Which fix removes the bug? function isEven(n) { return n % 2 = 0; }
- #12 · What is the correct fix? fruits = ["apple", "pear"] print(len(fruits)
- #13 · Which fix removes the bug? let count = 0; while (count < 3) { console.log(cou
- #14 · Which fix removes the off-by-one bug? const arr = [1, 2, 3]; for (let i = 0; i <= arr.le
- #15 · What is the correct fix? def average(nums): total = sum(nums) return total
- #16 · Which fix removes the bug? function double(arr) { return arr.map(x => x * 2)
- #17 · What is the correct fix? def first_upper(words): for w in words: if w[0].is
- #18 · Which fix removes the bug? function getLen(s: string): number { return s.leng
- #19 · What is the correct fix? const obj = { a: 1, b: 2 }; for (const key in obj)
- #20 · Which fix removes the bug? def count_evens(nums): c = 0 for n in nums: if n %
- #21 · What is the correct fix? function greet(name) { return "Hi " + name; } gree
- #22 · Which fix removes the bug? def repeat(text, times): return text * time
- #23 · What is the correct fix? const ids: number[] = []; ids.push("3");
- #24 · Which fix removes the bug? const max = Math.max([4, 9, 1]);
- #25 · What is the correct fix? def safe_div(a, b): if b == 0: return None return
- #26 · Which fix removes the bug? const s = "racecar"; const rev = s.split("").rever
- #27 · Which fix removes the bug? const nums = [1, 2, 3, 4]; nums.forEach((n, i) =>
- #28 · What is the correct fix? def add_item(item, bag=[]): bag.append(item) retur
- #29 · Which fix removes the bug? async function getData() { const res = fetch("/api
- #30 · What is the correct fix? var fns = []; for (var i = 0; i < 3; i++) { fns.pu
- #31 · Which fix removes the bug? def dedupe(items): seen = [] for x in items: if x
- #32 · What is the correct fix? function findUser(id: number, users: {id: number}[
- #33 · Which fix removes the bug? function sum(arr) { let total; for (const n of arr
- #34 · What is the correct fix? nums = [3, 1, 2] sorted_nums = nums.sort() print(s
- #35 · Which fix removes the bug? const counts = {}; for (const c of "hello") { coun
- #36 · What is the correct fix? def factorial(n): if n == 0: return 1 return n * f
- #37 · Which fix removes the bug? function parseFlag(v?: string): boolean { return v
- #38 · What is the correct fix? function clone(obj) { const copy = obj; copy.x = 9
- #39 · Which fix removes the subtle bug? function binarySearch(a, t) { let lo = 0, hi = a.l
- #40 · What is the correct fix? def chunk(lst, n): result = [] for i in range(0, l
- #41 · Which fix removes the bug? function debounce(fn, ms) { let t; return function
- #42 · What is the correct fix? async function loadAll(urls: string[]) { const out
- #43 · Which fix removes the bug? def merge(d1, d2): merged = d1 for k, v in d2.item
- #44 · What is the correct fix? const obj = { value: 10, getValue: () => { return
- #45 · Which fix removes the bug? def fib(n, memo={}): if n <= 1: return n if n in m
- #46 · What is the correct fix? function flatten(arr) { return arr.reduce((acc, x)
- #47 · Which fix removes the bug? function uniq<T>(items: T[]): T[] { const seen = n
- #48 · What is the correct fix? def remove_evens(nums): for n in nums: if n % 2 ==
- #49 · Which fix removes the bug? function range(start, end) { const out = []; for (
- #50 · What is the correct fix? function groupBy<T>(arr: T[], key: keyof T) { cons
- #51 · Which fix removes the bug? const nums = [10, 20, 30]; for (const i in nums) {
- #52 · What is the correct fix? function half(s) { return parseInt(s) / 2; } half(
- #53 · Which fix removes the bug? def greet(self, name): return "Hi " + name class G
- #54 · What is the correct fix? switch (kind) { case 'a': total += 1; case 'b': to
- #55 · Which fix removes the bug? s = "hello" s[0] = "H" print(s)
- #56 · Which fix removes the subtle bug? const items = [3, 1, 2]; const sorted = items.sort
- #57 · What is the correct fix? a = [1, 2, 3] b = a b.append(4) print(len(a))
- #58 · Which fix removes the bug? const found = [1, 2, 3].forEach((n) => { if (n ===
- #59 · What is the correct fix? counts = {"a": 1, "b": 0} for k in counts: if coun
- #60 · Which fix removes the bug? async function total(): Promise<number> { const re
- #61 · What is the correct fix? const obj = { count: 0, start() { setTimeout(funct
- #62 · Which fix removes the bug? def rate(a, b): if b is 0: return 0 return a / b
- #63 · What is the correct fix? function tag(name) { this.name = name; } const t =
- #64 · Which fix removes the subtle bug? try: value = int(raw) except: value = 0
- #65 · What is the correct fix? const a = [1, 2]; const b = [1, 2]; if (a === b) {
- #66 · Which fix removes the bug? def top(words): return sorted(words, key=len(words
- #67 · What is the correct fix? let total = 0; [1, 2, 3].forEach((n) => { total =
- #68 · Which fix removes the bug? const seen: Map<string, number> = new Map(); seen[
- #69 · What is the correct fix? total = 0 for row in rows: total += row print("tot
- #70 · Which fix removes the subtle bug? const cfg = { retries: 0 }; const retries = cfg.re
- #71 · What is the correct fix? grid = [[0] * 3] * 3 grid[0][0] = 5 print(grid[1][
- #72 · Which fix removes the bug? async function all(ids) { const out = []; ids.forE
- #73 · What is the correct fix? fns = [] for i in range(3): fns.append(lambda: i)
- #74 · Which fix removes the subtle bug? const clone = { ...user }; clone.address.city = 'R
- #75 · What is the correct fix? function pick<T>(list: T[], i: number): T { return
- #76 · Which fix removes the bug? def add_tag(tag, tags=[]): tags.append(tag) return
- #77 · Which fix removes the subtle bug? const ids = rows.map((r) => r.id); const uniq = id
- #78 · What is the correct fix? with open(path) as f: data = f.read() print(f.clos
- #79 · Which fix removes the bug? let timer; function poll() { timer = setInterval(f
- #80 · What is the correct fix? enum Role { User, Admin } function isAdmin(r: Role
- #81 · Which fix removes the bug? const rows = Array(3).fill([]); rows[0].push('a');
- #82 · What is the correct fix? const nums = [5, 1, 10]; nums.sort((a, b) => a > b
- #83 · Which fix removes the bug? const price = 19.99; const label = price.toFixed(2
- #84 · What is the correct fix? const list = ['a', 'b']; if ('a' in list) { consol
- #85 · Which fix removes the bug? def total(items): sum = 0 for i in items: sum += i
- #86 · What is the correct fix? count = 0 def bump(): count += 1 bump()
- #87 · Which fix removes the bug? cfg = {'host': 'x'} port = cfg['port']
- #88 · What is the correct fix? const raw = '{bad json}'; const cfg = JSON.parse(r
- #89 · Which fix removes the bug? const name = ' Sara '; if (name === 'Sara') { gree
- #90 · What is the correct fix? names = ['ana', 'bob'] for i in range(1, len(names
- #91 · Which fix removes the bug? class Counter { n = 0; inc() { this.n++; } } btn.a
- #92 · What is the correct fix? const users = {}; if (users.hasOwnProperty('toStri
- #93 · Which fix removes the subtle bug? const merged = Object.assign({}, base); merged.opt
- #94 · What is the correct fix? try: run() except Exception: log('general') except
- #95 · Which fix removes the bug? import copy a = {'x': [1, 2]} b = copy.copy(a) b['
- #96 · What is the correct fix? const ok = [1, 2, 3].reduce((a, b) => a + b); cons
- #97 · Which fix removes the inefficiency? async function loadAll(ids) { const out = []; for
- #98 · What is the correct fix? fetchUser().then((u) => render(u));
- #99 · Which fix removes the bug? def price(v): assert v > 0, 'must be positive' ret
- #100 · Which fix removes the inefficiency? out = '' for row in rows: out += row + ','
- #101 · What is the correct fix? function len(v: any) { return v.length; } len(42);
- #102 · Which fix removes the bug? const el = document.querySelector('.box')!; el.cla
- #103 · Which fix removes the off-by-one bug? const page = 2, size = 10; const rows = all.slice(
- #104 · What is the correct fix? const versions = ['1.10.0', '1.9.0']; versions.sor
- #105 · Which fix removes the bug? if user.get('role') is 'admin': grant()
- #106 · What is the correct fix? for i in range(0, 1, 0.1): print(i)
- #107 · Which fix removes the bug? const emails = rows.map((r) => r.email.toLowerCase
- #108 · Which fix removes the subtle bug? const cache = {}; function get(key) { if (cache[ke
- #109 · Which fix removes the race? let seq = 0; async function next() { const v = seq
- #110 · Which fix removes the bug? class Node: children = [] def add(self, c): self.c
- #111 · Which fix removes the bug? def walk(node, seen=set()): seen.add(node.id) for
- #112 · What is the correct fix? el.addEventListener('scroll', () => heavy()); // l
- #113 · Which fix removes the subtle bug? const total = items.reduce((sum, i) => sum + i.pri
- #114 · What is the correct fix? rows = [r for r in rows if r.ok] for i, r in enume
- #115 · Which fix removes the subtle bug? const idx = {}; for (const r of rows) idx[r.id] =
- #116 · Which fix removes the bug? interface Opts { retries?: number } function run(o
- #117 · Which fix removes the bug? import re if re.match(r'\d+', value): accept(value
- #118 · Which fix handles the text correctly? const first = 'e\u0301'.charAt(0); console.log('🙂
- #119 · What is the correct fix? with open(path) as f: for line in f: rows.append(l
- #120 · Which fix removes the bug? function debounce(fn, ms) { let t; return (...a) =
- #121 · Which fix removes the crash? def parse(rows): return [int(r) for r in rows] par
- #122 · Which fix removes the bug? const out = rows .filter((r) => r.ok) .map((r) =>
- #123 · What is the correct fix? type Cfg = { a: number } | { b: number }; function
- #124 · Which fix removes the bug? const set = new Set([1, 2, 3]); console.log(set.le
- #125 · What is the correct fix? items = ['b', 'a'] sorted(items) print(items[0])
- #126 · Which fix removes the bug? for (var i = 0; i < 3; i++) { setTimeout(() => con
- #127 · What is the correct fix? nums = [1, 2, 3] print(nums.index(9))
- #128 · Which fix removes the bug? const n = '7'; if (n === 7) { run(); }
- #129 · What is the correct fix? def scale(v, factor): return v * factor print(scal
- #130 · Which fix removes the bug? const copy = rows; copy.length = 0; console.log(ro
- #131 · Which fix removes the bug? for (let i = 0; i <= nums.length; i++) { console.l
- #132 · Which fix removes the bug? if (status = 'ready') { start(); }
- #133 · Which fix removes the bug? const total = items.map((i) => i.price); console.l
- #134 · Which fix removes the bug? setTimeout(refresh(), 1000);
- #135 · Which fix removes the bug? const sorted = [10, 9, 100].sort(); console.log(so
- #136 · Which fix removes the bug? if (names.indexOf(target)) { console.log('found');
- #137 · Which fix removes the bug? items.forEach(async (item) => { await save(item);
- #138 · Which fix removes the bug? class Counter { constructor() { this.n = 0; } tick
- #139 · Which fix removes the bug? const copy = { ...settings }; copy.theme.color = '
- #140 · Which fix removes the bug? async function load() { const rows = await db.quer
- #141 · What is the correct fix? if value == None: return
- #142 · What is the correct fix? print("total: " + count)
- #143 · What is the correct fix? settings = {} print(settings['theme'])
- #144 · What is the correct fix? def add(item, bucket=[]): bucket.append(item) retu
- #145 · What is the correct fix? for item in items: if item.stale: items.remove(ite
- #146 · What is the correct fix? try: run() except: pass
- #147 · What is the correct fix? class Cart: items = [] def add(self, x): self.item
- #148 · What is the correct fix? callbacks = [lambda: i for i in range(3)] print(ca
- #149 · What is the correct fix? total = 0 for row in rows: total += row.amount ave
- #150 · Which fix removes the bug? const el = document.getElementById('name'); el.val
- #151 · Which fix removes the bug? const age: number = parseInt(input); if (age > 18)
- #152 · Which fix removes the bug? function shout(text: any): string { return text.to
- #153 · Which fix removes the bug? interface User { id: number; name: string } const
- #154 · Which fix removes the bug? const nums = [1, 2, 3]; const doubled = nums.forEa
- #155 · Which fix removes the bug? const total = '5' + 3; console.log(total === 8);
- #156 · Which fix removes the bug? const items = ['a', 'b', 'c']; for (let i = 0; i <
- #157 · Which fix removes the bug? def add_item(item, bucket=[]): bucket.append(item)
- #158 · Which fix removes the bug? counts = {} for word in words: counts[word] += 1
- #159 · Which fix removes the bug? for item in items: if item.expired: items.remove(i
- #160 · Which fix removes the bug? async function load() { const res = fetch('/api/da
- #161 · Which fix removes the bug? class Timer { constructor() { this.ticks = 0; } st
- #162 · Which fix removes the bug? const sorted = [10, 9, 1].sort(); console.log(sort
- #163 · Which fix removes the bug? const copy = { ...original }; copy.address.city =
- #164 · Which fix removes the bug? if (user.age = 18) { grantAccess(); }
- #165 · Which fix removes the bug? handlers = [] for i in range(3): handlers.append(l
- #166 · Which fix removes the bug? total = 0 for price in prices: total =+ price
- #167 · Which fix removes the bug? with open(path) as f: pass data = f.read()
- #168 · Which fix removes the bug? total = 0 def add(n): total += n
- #169 · Which fix removes the bug? function parse(input: string): number { return JSO
- #170 · Which fix removes the bug? const ids: number[] = []; ids.push('7' as unknown
- #171 · Which fix removes the bug? const results = []; items.forEach(async (i) => { r
- #172 · Which fix removes the bug? try { await work(); } catch (e) { retry(); } final
- #173 · Which fix removes the bug? class Cache: store = {} def put(self, k, v): self.
- #174 · Which fix removes the bug? const el = document.getElementById('save'); el.add
- #175 · Which fix removes the bug? function greet(name) { return 'Hi ' + name; } cons
- #176 · Which fix removes the bug? const age = input.value; if (age > 18) allow();
- #177 · Which fix removes the bug? nums = [1, 2, 3] print(nums[len(nums)])
- #178 · Which fix removes the bug? s = 'hello' s[0] = 'H'
- #179 · Which fix removes the bug? def divide(a, b): return a / b print(divide(4, 0))
- #180 · Which fix removes the bug? let count: number; console.log(count + 1);
- #181 · Which fix removes the bug? const map = {}; map[{ id: 1 }] = 'a'; console.log(
- #182 · Which fix removes the bug? const btn = document.querySelector('#go'); btn.dis
- #183 · Which fix removes the bug? const total = items.reduce((sum, i) => sum + i.pri
- #184 · Which fix removes the bug? if (config.retry.count) { schedule(config.retry);
- #185 · Which fix removes the bug? import json data = json.load(open(path))
- #186 · Which fix removes the bug? class Node: def __eq__(self, other): return self.i
- #187 · Which fix removes the bug? import os path = os.path.join('/data', '/logs') pr
- #188 · Which fix removes the bug? for i in range(len(items)): if items[i] is None: d
- #189 · Which fix removes the bug? interface User { name: string } const u = {} as Us
- #190 · Which fix removes the bug? window.addEventListener('scroll', () => recalcLayo
- #191 · Which fix removes the bug? const cache = new Map(); function remember(node, v
- #192 · Which fix removes the bug? const [a, b] = await Promise.all([one(), two()]);
- #193 · Which fix removes the bug? import threading count = 0 def bump(): global coun
- #194 · Which fix removes the bug? def gen(): yield from range(3) g = gen() list(g) p
- #195 · Which fix removes the bug? const handlers: Record<string, () => void> = {}; h
- #196 · Which fix removes the bug? const items = document.querySelectorAll('li'); con
- #197 · Which fix removes the bug? age = input('Age: ') print(age + 1)
- #198 · Which fix removes the bug? const copy = JSON.parse(JSON.stringify(event)); co
- #199 · Which fix removes the bug? import math def area(r): return math.pi * r ^ 2
- #200 · Which fix removes the bug? type Shape = { kind: 'circle'; r: number } | { kin
- #201 · Which fix removes the bug? x = 7 if x > 0 and < 10: print('digit')
- #202 · Which fix removes the bug? const total = 0; for (const n of [1, 2, 3]) { tota
- #203 · Which fix removes the bug? def greet(): return 'hi' print(greet)
- #204 · Which fix removes the bug? const words = 'red green blue'.split(); console.lo
- #205 · Which fix removes the bug? nums = [1, 2, 3] nums.add(4)
- #206 · Which fix removes the bug? name = 'Ada' print('Hello, {name}')
- #207 · Which fix removes the bug? scores = ['9', '10', '100'] print(max(scores)) # e
- #208 · Which fix removes the bug? const d = new Date(2026, 2, 5); console.log(d.getD
- #209 · Which fix removes the bug? function sum(...nums: number[]): number { return n
- #210 · Which fix removes the bug? function walk(value) { if (typeof value === 'array
- #211 · Which fix removes the bug? from datetime import datetime d = datetime.strptim
- #212 · Which fix removes the bug? const prices = ['1', '2', '3']; const total = pric
- #213 · Which fix removes the bug? with open('out.txt') as f: f.write('hi')
- #214 · Which fix removes the bug? try: run() except ValueError, TypeError: log('bad
- #215 · Which fix removes the bug? const users = [{ id: 1 }, { id: 1 }]; const unique
- #216 · Which fix removes the bug? def counter(): total = 0 def add(n): total += n re
- #217 · Which fix removes the bug? function shuffle(arr) { return arr.sort(() => Math
- #218 · Which fix removes the bug? keys = ['a', 'b'] groups = dict.fromkeys(keys, [])
- #219 · Which fix removes the bug? const orderId = 9007199254740993; save(orderId); /
- #220 · Which fix removes the bug? function isText(x: unknown): boolean { return type
- #221 · Which fix removes the bug? var counts map[string]int counts["go"] = 1
- #222 · Which fix removes the bug? SELECT name FROM users WHERE email = NULL; -- expe
- #223 · Which fix removes the bug? for n in [1, 2, 3]: total = 0 total += n print(tot
- #224 · Which fix removes the bug? # print 1 through 10 for i in range(1, 10): print(
- #225 · Which fix removes the bug? const price = 2.567; const shown = Math.round(pric
- #226 · Which fix removes the bug? const ids = [4, 8, 15]; if (ids.contains(8)) { con
- #227 · Which fix removes the bug? for _, p := range people { p.Age++ } fmt.Println(p
- #228 · Which fix removes the bug? String answer = scanner.nextLine(); if (answer ==
- #229 · Which fix removes the bug? String role = user.getRole(); // may be null if (r
- #230 · Which fix removes the bug? SELECT dept, COUNT(*) FROM emp WHERE COUNT(*) > 5
- #231 · Which fix removes the bug? if 'admin' or 'root' in roles: grant()
- #232 · Which fix removes the bug? prices = {'tea': 2, 'jam': 5} for name, cost in pr
- #233 · Which fix removes the bug? colors = ('red') for c in colors: print(c) # expec
- #234 · Which fix removes the bug? const queue = [1, 2, 3, 4]; const preview = queue.
- #235 · Which fix removes the bug? var n int var err error if s != "" { n, err := str
- #236 · Which fix removes the bug? int days = 30; long ms = days * 24 * 60 * 60 * 100
- #237 · Which fix removes the bug? SELECT u.name, o.id FROM users u LEFT JOIN orders
- #238 · Which fix removes the bug? name = 'report.txt'.strip('.txt') print(name) # ex
- #239 · Which fix removes the bug? const scores = new Map([['ana', 3]]); const body =
- #240 · Which fix removes the bug? const ids = new Array(3).map((_, i) => i); console
- #241 · Which fix removes the bug? String name = "Ada"; System.out.println(name.lengt
- #242 · Which fix removes the bug? sum := 7 avg := sum / 2 fmt.Println(avg) // expect
- #243 · Which fix removes the bug? SELECT name FROM users WHERE age > 18 AND < 30; --
- #244 · Which fix removes the bug? const prices: Record<string, number> = { tea: 2, j
- #245 · Which fix removes the bug? const n = Number(input); if (n === NaN) { showErro
- #246 · Which fix removes the bug? score = 95 if score >= 50: grade = 'pass' elif sco
- #247 · Which fix removes the bug? line = 'red green blue' words = line.split(' ') pr
- #248 · Which fix removes the bug? from collections import defaultdict counts = defau
- #249 · Which fix removes the bug? const cfg = Object.freeze({ db: { host: 'x' } });
- #250 · Which fix removes the bug? function keysOf(v) { if (typeof v === 'object') re
- #251 · Which fix removes the bug? src := []int{1, 2, 3} dst := make([]int, 0, len(sr
- #252 · Which fix removes the bug? List<Integer> ids = Arrays.asList(1, 2); ids.add(3
- #253 · Which fix removes the bug? SELECT AVG(score) FROM results; -- scores: 10, NUL
- #254 · Which fix removes the bug? type User = { name?: string }; function nameLen(us
- #255 · Which fix removes the bug? from functools import lru_cache @lru_cache(maxsize
- #256 · Which fix removes the bug? from dataclasses import dataclass @dataclass class
- #257 · Which fix removes the bug? const qty = 0.0000005; const whole = parseInt(qty)
- #258 · Which fix removes the bug? func process(items []string) { n := 0 defer fmt.Pr
- #259 · Which fix removes the bug? for (String n : names) { if (n.isEmpty()) names.re
- #260 · Which fix removes the bug? SELECT u.name, COUNT(*) AS orders FROM users u LEF