is_palindrome(n) — a number is a palindrome if it reads the same forwards and backwards
Think about strings — Python has a clean one-liner for thisis_armstrong(n) — for each digit, raise it to the power of total digit count, then sum all
You'll need: how many digits does n have? How do you extract each digit?is_prime(n) — handle edge cases (n < 2), then check divisors
You only need to check up to √n — think about why that isclassify() on the test numbers and verify the output matchesprice × qty > 1000 for each item. When that's true, only the price changes — reduce it by 10%. Think: what is 90% of the original price? You'll need to decide whether to change the original dict or build a new one.
Employee class but calculate pay differently. This is the classic use case for method overriding — same method name, different logic per subclass.
__init__ methods — call super() then store the extra attributesget_pay() in each subclass with the correct calculationdisplay() method in the base class calls self.get_pay() — it will automatically use the right version. Run and verify output.display() calls self.get_pay(), and Python automatically picks the right version based on what type the object actually is. You don't need any if/else in display(). Focus on making sure each subclass stores what it needs and returns the right thing from get_pay().
[ERROR] Database timeout or [INFO] User logged in. You'll build a parser that counts log levels, finds all error lines, and writes a cleaned summary. This is exactly what tools like Splunk and Datadog do at massive scale.
parse_log() should read the file and return a dict: {"INFO": 4, "ERROR": 3, "WARNING": 1}save_errors() should write each error line to errors.log, one per lineis_prime[p*p], is_prime[p*p+p], ... as False
You need to step through multiples of p, starting at p*p, up to nsieve(50) — verify you get 15 primesnew StringBuilder(s).reverse().toString()String.valueOf(n).length()Math.pow(base, exp) returns double — cast to int if neededMath.sqrt(n)
isPalindrome — convert n to String, compare with its StringBuilder reverseisArmstrong — extract digits via String.valueOf, raise each to power of digit count using Math.powisPrime — loop from 2 to (int)Math.sqrt(n), return false if any divide evenlys.charAt(i) - '0'. For the power, Math.pow returns a double so you need to cast: (int) Math.pow(digit, numDigits).
CartItem class and ArrayList. In Java, you use a class to bundle related data instead of a dict. The logic is identical — only the way you access data changes.
item.price * item.qtyprice * qty > 1000 — update price directly on CartItemqty > 1 into an ArrayList<String>item.price directly inside the loop — Java passes object references, so changes to item fields inside a for-each loop are permanent.
.mapToInt().sum() to find the sum of all numbers.mapToInt(x -> x).sum() converts to an IntStream that has a built-in sum() method — this is different from using .reduce(). For chaining two filters, you can either write two separate .filter() calls or combine them into one with &&.
Employee class and override getPay(). The base class display() calls getPay() — Java picks the right version automatically at runtime.
FullTime constructor and return it from getPay()PartTime constructor and return rate * hours from getPay()abstract double getPay() — this forces every subclass to implement it, otherwise the code won't compile. The display() method can safely call getPay() without knowing which subclass it's dealing with. This is Java's polymorphism — the right version is selected at runtime, not compile time.
logScore() — throw InvalidScoreException("Score X is out of range 0-100") if score < 0 or score > 100name + ": " + score + "\n" to the file using FileWriter in append modenew FileWriter(filename, true) adds to the file without overwriting; false or no second argument would erase it each time. The custom exception just needs to pass the message to super() — the try/catch in main handles the rest.
isPalindrome — in JS, strings can be reversed with .split("").reverse().join("")isArmstrong — digits is already an array of character strings; use Number(d) to convert each to a number, and ** for exponentiationdigits.reduce((sum, d) => sum + Number(d) ** power, 0). For the color, set result.style.color after determining the label.
.reduce() to calculate the total bill (price × qty for each item).reduce() or .sort() to find the most expensive item by unit price.map() to apply 10% discount on items where price × qty > 1000 — return new array.filter() to get names of items where qty > 1, then .map() to extract just the namesitem.price * item.qty each iteration. For the discounted cart, return a new object in .map() — spread the original first (...item) then override the price property. This avoids mutating the original cart.
makeCounter — each method should read/write the closed-over count variablecountdown(from) — use a loop with setTimeout(fn, i * 500) to print each number 500ms apart
Each iteration of the loop schedules a callback at a different delaycountdown(5) and observe the output spaced 500ms apart in the consolecount variable from makeCounter's scope. For countdown, setTimeout(() => console.log(from - i), i * 500) inside a for loop schedules each print at a different time. But beware — with var, all iterations share the same variable. Use let in the loop.
async/await makes this readable. You'll fetch from a free public API, parse the JSON response, and display it in HTML. This is the foundation of every modern web app.
async, then use await before anything that takes time.user.name.first and user.name.lastuser.email) and city (user.location.city)data.results[0] gives you the user object. From there, name, email, and location are all top-level keys. Use out.innerHTML = `<b>Name:</b> ${...}<br>...` to format it nicely. The loading state is just setting textContent before the await, then replacing it after.
addTask — get the input value, push to array, clear input, call render()render — loop through tasks, create <li> for each. Done tasks should have a strikethrough styletoggleDone(i), a "×" button calls deleteTask(i)taskList.innerHTML = "" first, then loop and append. Use inline onclick attributes with the index: onclick="toggleDone(${i})".
if inside a loop.WHERE city = 'Delhi'
| id | name | city | marks | grade |
|---|---|---|---|---|
| 1 | 'Rahul' | 'Delhi' | 72 | 'B' |
| 2 | 'Priya' | 'Mumbai' | 91 | 'A' |
| 3 | 'Arjun' | 'Delhi' | 38 | 'F' |
| 4 | 'Sneha' | 'Pune' | 85 | 'A' |
| 5 | 'Vikram' | 'Mumbai' | 55 | 'C' |
| 6 | 'Anita' | 'Delhi' | 94 | 'A' |
| 7 | 'Rohan' | 'Pune' | 43 | 'F' |
| id | name | city | marks | grade |
|---|---|---|---|---|
| 6 | Anita | Delhi | 94 | A |
| 1 | Rahul | Delhi | 72 | B |
| 3 | Arjun | Delhi | 38 | F |
| name | marks |
|---|---|
| Priya | 91 |
| Sneha | 85 |
| Anita | 94 |
| name | marks |
|---|---|
| Anita | 94 |
| Priya | 91 |
| Sneha | 85 |
| name | city | marks |
|---|---|---|
| Priya | Mumbai | 91 |
| Sneha | Pune | 85 |
| Vikram | Mumbai | 55 |
WHERE city IN ('Mumbai', 'Pune').
| id | name | city | marks | grade |
|---|---|---|---|---|
| 1 | 'Rahul' | 'Delhi' | 72 | 'B' |
| 2 | 'Priya' | 'Mumbai' | 91 | 'A' |
| 3 | 'Arjun' | 'Delhi' | 38 | 'F' |
| 4 | 'Sneha' | 'Pune' | 85 | 'A' |
| 5 | 'Vikram' | 'Mumbai' | 55 | 'C' |
| 6 | 'Anita' | 'Delhi' | 94 | 'A' |
| 7 | 'Rohan' | 'Pune' | 43 | 'F' |
| city | COUNT(*) |
|---|---|
| Delhi | 3 |
| Mumbai | 2 |
| Pune | 2 |
| grade | AVG(marks) |
|---|---|
| A | 90.0 |
| B | 72.0 |
| C | 55.0 |
| F | 40.5 |
| city | COUNT(*) |
|---|---|
| Delhi | 3 |
| city | MAX(marks) |
|---|---|
| Delhi | 94 |
| Mumbai | 91 |
| Pune | 85 |
FROM tableA INNER JOIN tableB ON tableA.id = tableB.student_idstudents.id
| id | name | city |
|---|---|---|
| 1 | 'Rahul' | 'Delhi' |
| 2 | 'Priya' | 'Mumbai' |
| 3 | 'Arjun' | 'Delhi' |
| 4 | 'Sneha' | 'Pune' |
| id | student_id | course | score |
|---|---|---|---|
| 1 | 1 | 'Python' | 88 |
| 2 | 1 | 'SQL' | 76 |
| 3 | 2 | 'Python' | 95 |
| 4 | 3 | 'Java' | 62 |
| 5 | 4 | 'SQL' | 81 |
| 6 | 2 | 'Java' | 70 |
| name | course |
|---|---|
| Rahul | Python |
| Rahul | SQL |
| Priya | Python |
| Arjun | Java |
| Sneha | SQL |
| Priya | Java |
| name | course | score |
|---|---|---|
| Rahul | Python | 88 |
| Priya | Python | 95 |
| Sneha | SQL | 81 |
| name | course_count |
|---|---|
| Rahul | 2 |
| Priya | 2 |
| Arjun | 1 |
| Sneha | 1 |
| name | score |
|---|---|
| Priya | 95 |
| Rahul | 88 |
WHERE right_table.id IS NULL. This finds rows in the left table with no matching row in the right.
| id | name |
|---|---|
| 1 | 'Rahul' |
| 2 | 'Priya' |
| 3 | 'Arjun' |
| 4 | 'Sneha' |
| 5 | 'Vikram' |
| id | student_id | course |
|---|---|---|
| 1 | 1 | 'Python' |
| 2 | 1 | 'SQL' |
| 3 | 2 | 'Python' |
| 4 | 3 | 'Java' |
| 5 | 4 | 'SQL' |
| name | course |
|---|---|
| Rahul | Python |
| Rahul | SQL |
| Priya | Python |
| Arjun | Java |
| Sneha | SQL |
| Vikram | NULL |
| name |
|---|
| Vikram |
| name | course_count |
|---|---|
| Rahul | 2 |
| Priya | 1 |
| Arjun | 1 |
| Sneha | 1 |
| Vikram | 0 |
| id | name | city | marks | grade |
|---|---|---|---|---|
| 1 | 'Rahul' | 'Delhi' | 72 | 'B' |
| 2 | 'Priya' | 'Mumbai' | 91 | 'A' |
| 3 | 'Arjun' | 'Delhi' | 38 | 'F' |
| 4 | 'Sneha' | 'Pune' | 85 | 'A' |
| 5 | 'Vikram' | 'Mumbai' | 55 | 'C' |
| 6 | 'Anita' | 'Delhi' | 94 | 'A' |
| 7 | 'Rohan' | 'Pune' | 43 | 'F' |
| id | name | city | marks | grade |
|---|---|---|---|---|
| 1 | Rahul | Delhi | 72 | B |
| 2 | Priya | Mumbai | 91 | A |
| 3 | Arjun | Delhi | 65 | C |
| 4 | Sneha | Pune | 85 | A |
| 5 | Vikram | Mumbai | 55 | C |
| 6 | Anita | Delhi | 94 | A |
| 8 | Karan | Bangalore | 78 | B |