Explore
Written by Neo Matrix · Quant Dev at HighLatency Traders Neo is a high-frequency trader. He needs to find the median price from two massive sorted logs of stock prices. Merging them first is too slow for his sub-millisecond requirements. **Neo's Code:** Find the median of two sorted arrays in O(log(min(m, n))) time. __EXAMPLES__:[{"title":"Example 1","input":"nums1 = [1, 3], nums2 = [2]","output":"2.0","explanation":"Merged array is [1, 2, 3], median is 2."}]
Written by Cora Check · Game Designer at PuzzleByte Cora is building a chess-based puzzle game. She needs to generate all valid placements of N queens on an NxN board such that no two queens attack each other. Her current code is placing queens randomly. **Cora's Code:** Find all distinct solutions to the N-Queens puzzle. __EXAMPLES__:[{"title":"Example 1","input":"4","output":"[['.Q..','...Q','Q...','..Q.'],['..Q.','Q...','...Q','.Q..']]","explanation":"The two valid configurations for a 4x4 board."}]
Written by Sage Mode · Freelance Consultant at SoloPM Sage is a freelance project manager. She has multiple jobs offered with different start times, end times, and profits. She needs to pick the best non-overlapping jobs to maximize her income. **Sage's Code:** Find the maximum profit you can take such that no two jobs in the subset overlap. __EXAMPLES__:[{"title":"Example 1","input":"start = [1,2,3,3], end = [3,4,5,6], profit = [50,10,40,70]","output":"120","explanation":"Pick job 1 and 4: profit = 50 + 70 = 120."}]
Written by Odin Nord · Lead Engine Dev at Bifrost Games Odin is building a distributed game engine. He needs to transmit game state trees over the network. His current serialization is bulky and loses the tree structure after a certain depth. **Odin's Code:** Design an algorithm to serialize and deserialize a binary tree. __EXAMPLES__:[{"title":"Example 1","input":"[1, 2, 3, null, null, 4, 5]","output":"[1, 2, 3, null, null, 4, 5]","explanation":"The tree is serialized and then perfectly reconstructed."}]
Written by Rumi Gene · Bioinformatician at BioSequel Rumi is building a high-speed DNA sequencer. She needs to find the smallest segment of a genetic sequence that contains all required markers. Her current code is quadratic and failing on long sequences. **Rumi's Code:** Find the minimum window in string S which contains all characters of string T. __EXAMPLES__:[{"title":"Example 1","input":"s = 'ADOBECODEBANC', t = 'ABC'","output":"'BANC'","explanation":"BANC contains A, B, and C and is the smallest."}]
Written by Kael Voxel · Graphics Dev at RenderLabs Kael is a graphics engineer working on a voxel engine. He needs to find the largest rectangular area in a 2D histogram of building heights. His brute force code is too slow for real-time rendering. **Kael's Code:** Find the area of the largest rectangle in a histogram. __EXAMPLES__:[{"title":"Example 1","input":"[2, 1, 5, 6, 2, 3]","output":"10","explanation":"The largest rectangle is 5 and 6, area = 5 * 2 = 10."}]
Written by Aria Spark · SRE at CloudMerge Aria is merging log streams from K different microservices. Her current approach of joining all streams and then sorting the giant result is causing memory exhaustion and high latency. **Aria's Code:** Merge K sorted linked lists into one sorted linked list efficiently. __EXAMPLES__:[{"title":"Example 1","input":"[[1,4,5],[1,3,4],[2,6]]","output":"[1,1,2,3,4,4,5,6]","explanation":"All lists are merged in sorted order."}]
Written by Pippin Took · Linguist at ShireSpeak Pippin is a linguist who needs to check if a sentence can be segmented into words from a given dictionary. His recursive solution is timing out on long sentences with ambiguous overlaps. **Pippin's Code:** Determine if a string can be segmented into a space-separated sequence of one or more dictionary words. __EXAMPLES__:[{"title":"Example 1","input":"s = 'leetcode', wordDict = ['leet', 'code']","output":"true","explanation":"Returns true because 'leetcode' can be segmented as 'leet code'."}]
Written by Sky Type · UX Engineer at SpellBound Sky is building an autocorrect feature. The current version only handles one-character mistakes and is failing for complex word transformations like 'intention' to 'execution'. **Sky's Code:** Find the minimum number of operations (insert, delete, replace) required to convert one string to another. __EXAMPLES__:[{"title":"Example 1","input":"word1 = 'horse', word2 = 'ros'","output":"3","explanation":"horse -> rorse -> rose -> ros."}]
Written by Zane Fluid · Architecture Visualizer at AquaDesign Zane is designing a high-end fountain. He needs to calculate how much water is trapped between decorative pillars of varying heights. His current logic double-counts water and is generally a mess. **Zane's Code:** Calculate how much water can be trapped between pillars represented by an array of heights. __EXAMPLES__:[{"title":"Example 1","input":"[0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]","output":"6","explanation":"6 units of rain water are being trapped."}]
Written by Tate Flow · Data Scientist at SenseIt Tate is analyzing sensor data to find the longest period of strictly increasing values. His code is extremely slow because it checks every possible subsequence. **Tate's Code:** Find the length of the longest strictly increasing subsequence in O(n^2) or O(n log n) time. __EXAMPLES__:[{"title":"Example 1","input":"[10, 9, 2, 5, 3, 7, 101, 18]","output":"4","explanation":"The sequence is [2, 3, 7, 101]."}]
Written by Micah Bolt · Firmware Engineer at VendoMatic Micah is writing code for a vending machine. His greedy algorithm for giving change is failing for denominations like [1, 3, 4] for a target of 6 (it gives 4+1+1 instead of 3+3). **Micah's Code:** Find the minimum number of coins needed to make up a given amount using Dynamic Programming. __EXAMPLES__:[{"title":"Example 1","input":"coins = [1, 2, 5], amount = 11","output":"3","explanation":"5 + 5 + 1 = 11."}]
Written by Avery Seas · Lead Mapper at DeepBlue Games Avery is a cartographer for a nautical adventure game. Her code for counting islands in a grid is causing 'infinite ocean' bugs because it doesn't correctly track visited land tiles. **Avery's Code:** Count the number of islands in a 2D binary grid using Depth First Search (DFS) or Breadth First Search (BFS). __EXAMPLES__:[{"title":"Example 1","input":"grid = [['1','1','0'],['1','1','0'],['0','0','1']]","output":"2","explanation":"Top left cluster is one island, bottom right '1' is another."}]
Written by Kit Cloud · Systems Architect at DataTree Kit is building a file system explorer. He needs to validate if the metadata tree is a valid Binary Search Tree. His current recursive check is missing edge cases where sub-tree nodes exceed ancestor limits. **Kit's Code:** Write a function to determine if a binary tree is a valid Binary Search Tree (BST). __EXAMPLES__:[{"title":"Example 1","input":"[2, 1, 3]","output":"true","explanation":"1 < 2 and 3 > 2, so it's valid."}]
Written by Bryn Hope · Scheduler at HealthFirst Bryn is scheduling appointments for a busy clinic. His code for merging overlapping time slots is broken, leading to double-booked rooms and angry patients. **Bryn's Code:** Merge all overlapping intervals in an array and return the non-overlapping results in O(n log n) time. __EXAMPLES__:[{"title":"Example 1","input":"[[1,3],[2,6],[8,10],[15,18]]","output":"[[1,6],[8,10],[15,18]]","explanation":"[1,3] and [2,6] overlap, so they merge into [1,6]."}]
Written by Noa Time · Senior Developer at ChronoTech Noa is a developer for a watch manufacturer. The timestamp logs are sorted but rotated due to a time-zone bug. Noa is using a linear search that is too slow for high-frequency logs. **Noa's Code:** Find a target in a sorted but rotated array in O(log n) time. __EXAMPLES__:[{"title":"Example 1","input":"nums = [4, 5, 6, 7, 0, 1, 2], target = 0","output":"4","explanation":"0 is at index 4."}]
Written by Quinn Parks · Head Librarian at CityArchives Quinn is a librarian who needs to find the first and last occurrence of a book ID in a sorted index. Quinn's linear scan is taking too long for the million-book database. **Quinn's Code:** Use binary search twice to find the starting and ending position of a target value in O(log n) time. __EXAMPLES__:[{"title":"Example 1","input":"nums = [5, 7, 7, 8, 8, 10], target = 8","output":"[3, 4]","explanation":"8 appears from index 3 to 4."}]
Written by Harlow West · Civil Engineer at WaterGrid Harlow is designing a reservoir management system. Her code for finding the maximum water capacity between two walls uses a quadratic search, making it too slow for real-time simulations. **Harlow's Code:** Optimize Harlow's calculation to find the maximum water volume in O(n) time. __EXAMPLES__:[{"title":"Example 1","input":"[1, 8, 6, 2, 5, 4, 8, 3, 7]","output":"49","explanation":"The max area is between wall at index 1 and 8."}]
Written by Eli Watts · DSP Engineer at SignalCore Eli is parsing stream data to find the longest burst of unique signals. His current code uses a nested loop to check every single possible substring, which is crashing the buffer. **Eli's Code:** Optimize Eli's substring search to find the length of the longest substring without repeating characters in O(n) time. __EXAMPLES__:[{"title":"Example 1","input":"'abcabcbb'","output":"3","explanation":"The longest substring is 'abc' with length 3."}]
Written by Jesse Snow · Weather Analyst at MeteoScale Jesse is working with a sorted list of daily temperatures. He needs to find two days whose temperatures sum to a target, but he's using a hash map that wastes O(n) extra space. **Jesse's Code:** Find two numbers in a sorted array that sum to a target using O(1) extra space. __EXAMPLES__:[{"title":"Example 1","input":"numbers = [2, 7, 11, 15], target = 9","output":"[1, 2]","explanation":"2 + 7 = 9. Return 1-based indices."}]
Written by Val Knight · QA Lead at GameHouse Val is a game tester checking for missing levels in a level sequence. She sorts the entire array just to find one missing number, making her tests sluggish. **Val's Code:** Find the missing number in an array containing n distinct numbers in the range [0, n] in O(n) time. __EXAMPLES__:[{"title":"Example 1","input":"[3, 0, 1]","output":"2","explanation":"n=3, range [0,3], missing is 2."}]
Written by Robin Hood · Security Engineer at SecureSync Robin is syncing two user lists. He wrote an O(n*m) double loop to find common IDs, which is causing timeouts on the admin dashboard during sync. **Robin's Code:** Optimize the intersection check to find common elements between two arrays in O(n + m) time. __EXAMPLES__:[{"title":"Example 1","input":"nums1 = [1, 2, 2, 1], nums2 = [2, 2]","output":"[2]","explanation":"Only 2 is common."}]
Written by Toby Fox · Search Specialist at FindIt Toby is building a search engine snippet generator. His code for finding the length of the last word in a sentence is filled with complex regex that keeps breaking on trailing spaces. **Toby's Code:** Clean up Toby's logic to find the length of the last word in a string of space-separated words. __EXAMPLES__:[{"title":"Example 1","input":"'Hello World'","output":"5","explanation":"The last word is 'World'."}]
Written by Remi Silva · Database Admin at ShopStop Remi is cleaning up a database of product prices. He wrote a function to move all zeros to the end of the array, but it creates multiple copies of the array, which is memory-intensive. **Remi's Code:** Refactor Remi's code to move all 0's to the end in-place without making a copy of the array. __EXAMPLES__:[{"title":"Example 1","input":"[0, 1, 0, 3, 12]","output":"[1, 3, 12, 0, 0]","explanation":"All zeros moved to the end, preserving relative order of non-zeros."}]
Written by Skyler Blue · Junior Systems dev at BitWise Skyler is trying to determine if a number is a power of two. He's using a very strange recursive division method that crashes for large numbers. **Skyler's Code:** Optimise Skyler's check to determine if an integer is a power of two. __EXAMPLES__:[{"title":"Example 1","input":"16","output":"true","explanation":"16 is 2^4."}]
Written by Pat Green · Junior Linguist at Wordly Pat is building a text analysis tool. He wrote a giant switch statement to count vowels in strings, which is hard to read and even harder to extend. **Pat's Code:** Refactor Pat's code to count the number of vowels in a string more cleanly. __EXAMPLES__:[{"title":"Example 1","input":"'hello world'","output":"3","explanation":"vowels are e, o, o."}]
Written by Dana White · DevOps Analyst at LogMaster Dana is building a system to flag duplicate entries in a log file. She wrote a triple-nested loop to be 'extra sure' she doesn't miss anything, but it's taking ages on large logs. **Dana's Code:** Optimize Dana's check to detect if an array contains any duplicate values in O(n) time. __EXAMPLES__:[{"title":"Example 1","input":"[1, 2, 3, 1]","output":"true","explanation":"1 appears twice."}]
Written by Finley Miller · Associate Dev at LegacySystems Finley is a bootcamp grad who was asked to implement FizzBuzz for a legacy system. He used a very confusing chain of ternary operators that is making his team's head spin. **Finley's Code:** Clean up Finley's FizzBuzz logic into a more readable format. __EXAMPLES__:[{"title":"Example 1","input":"3","output":"['1', '2', 'Fizz']","explanation":"3 is divisible by 3, so it becomes 'Fizz'."}]
Written by Sasha Reed · Cryptography Intern at SafeMsg Sasha is trying to reverse strings for a secret code generator. She decided to use recursion, but didn't consider that long strings will cause a stack overflow in the production environment. **Sasha's Code:** Refactor Sasha's recursive string reversal into an iterative version or a built-in method call for efficiency. __EXAMPLES__:[{"title":"Example 1","input":"'hello'","output":"'olleh'","explanation":"The string is reversed correctly."}]
Written by Charlie Brown · Enthusiastic Hobbyist at ChessClub Charlie is building a leaderboard for a local chess tournament. He's using a nested loop to find the highest score, causing the browser to freeze when more than 1,000 players join. **Charlie's Code:** Refactor Charlie's function to find the maximum integer in an array in O(n) time. __EXAMPLES__:[{"title":"Example 1","input":"[10, 5, 20, 15]","output":"20","explanation":"20 is the largest number in the list."}]
Written by Jamie Clarke · Release Engineer at RepoMasters Jamie is a release manager who needs to find the first 'bad' version in a series of commits. Jamie's linear search is too slow for repositories with thousands of releases. **Jamie's Code:** Use binary search to find the first bad version in O(log n) time. __EXAMPLES__:[{"title":"Example 1","input":"n = 5, bad = 4","output":"4","explanation":"4 is the first version that is bad."}]
Written by Drew Banks · Game Developer at IndieQuest Drew is modeling stairs for a game engine. To calculate the number of ways to climb 'n' steps, Drew used simple recursion, which is now causing exponential lag as levels get harder. **Drew's Code:** Help Drew implement a dynamic programming solution to calculate stairs combinations in O(n) time. __EXAMPLES__:[{"title":"Example 1","input":"n = 3","output":"3","explanation":"1+1+1, 1+2, 2+1."}]
Written by Riley Smith · Algorithmic Trader at Quantify Riley is building a trading bot. The bot needs to find the best day to buy and sell a stock for maximum profit. Riley's O(n^2) code is too slow to catch live market opportunities. **Riley's Code:** Refactor Riley's stock trading logic to run in O(n) time. __EXAMPLES__:[{"title":"Example 1","input":"[7, 1, 5, 3, 6, 4]","output":"5","explanation":"Buy on day 2 (price=1) and sell on day 5 (price=6), profit = 5."}]
Written by Casey Jones · Systems Architect at Legacy Solutions Casey is working on a legacy system where data is stored in a linked list. For a new feature, they need to reverse the list. Casey tried a recursive approach but it's hitting the stack limit on long lists. **Casey's Code:** Implement an iterative linked list reversal to avoid stack overflow errors. __EXAMPLES__:[{"title":"Example 1","input":"[1, 2, 3, 4, 5]","output":"[5, 4, 3, 2, 1]","explanation":"The linked list pointers are reversed."}]
Written by Morgan Lee · Software Engineer at WordSearch Co. Morgan is building a search tool that identifies anagrams in a massive word list. The current approach involves sorting every single word pair, which is extremely inefficient during high-traffic periods. **Morgan's Code:** Help Morgan optimize the anagram check using a frequency counter instead of sorting. __EXAMPLES__:[{"title":"Example 1","input":"s = 'anagram', t = 'nagaram'","output":"true","explanation":"Both strings have the same characters with the same frequencies."}]
Written by Taylor Reed · DevOps Engineer at CloudScale Taylor is writing a parser for a new configuration language. The bracket validation logic is buggy and doesn't handle nested structures correctly, leading to random syntax errors in production. **Taylor's Code:** Write a function using a stack to validate that all opening brackets are correctly closed in the right order. __EXAMPLES__:[{"title":"Example 1","input":"'()[]{}'","output":"true","explanation":"All brackets are closed in the correct order."}]
Written by Sam Wilson · Data Analyst at TradeFlow Sam is analyzing stock price trends to find the most profitable consecutive trading days. The current code checks every possible sub-array, which is painfully slow for historical data. **Sam's Code:** Implement Kadane's algorithm to find the maximum subarray sum in O(n) time. __EXAMPLES__:[{"title":"Example 1","input":"[-2, 1, -3, 4, -1, 2, 1, -5, 4]","output":"6","explanation":"[4, -1, 2, 1] has the largest sum = 6."}]
Written by Jordan Lee · Backend Developer at FinTrack Jordan is building a financial reconciliation tool that finds two transactions that sum up to a specific target value. The current version uses two nested loops, and with millions of transactions, it's taking minutes to run. **Jordan's Code:** Optimize Jordan's 'two sum' implementation to run in O(n) time. __EXAMPLES__:[{"title":"Example 1","input":"nums = [2, 7, 11, 15], target = 9","output":"[0, 1]","explanation":"nums[0] + nums[1] = 2 + 7 = 9."}]
Written by Maya Patel · Full Stack Engineer at Socially Maya was building a feature to detect palindromic usernames for a social media platform. Under immense pressure, she wrote a solution that handles special characters inconsistently and is O(n^2) due to constant string slicing. **Maya's Code:** Help Maya optimize the palindrome check to be O(n) and case-insensitive, ignoring non-alphanumeric characters. __EXAMPLES__:[{"title":"Example 1","input":"'A man, a plan, a canal: Panama'","output":"true","explanation":"After removing spaces and punctuation, the string becomes 'amanaplanacanalpanama', which is a palindrome."}]
Written by Alex Chen · Junior Frontend Dev at ShopFast Alex, a junior developer at a fast-growing e-commerce startup, was tasked with deduplicating a list of customer IDs. In a rush to meet a deadline, Alex wrote a nested loop solution that is O(n^2). Now, the production database is timing out on large datasets. **Alex's Code:** Refactor Alex's function to remove duplicates from an array of integers in O(n) time and O(n) space. __EXAMPLES__:[{"title":"Example 1","input":"[1, 2, 2, 3, 4, 4, 5]","output":"[1, 2, 3, 4, 5]","explanation":"All duplicates are removed while preserving the original order."}]
Written by Jamie Dawson · Frontend Developer at FlagFrenzy, known for "creative" solutions under pressure At the trendy startup "FlagFrenzy", junior dev Jamie was tasked with implementing a new feature flag system that dynamically toggles UI components based on backend logic. Under pressure from the CEO to ship by EOD, Jamie hacked together a monstrosity that somehow worked... until it didn't. Now, users are seeing random components appear and disappear, and the CEO is livid. Your mission: fix Jamie's code before the next investor demo in 2 hours. **Jamie "Flag-It" Dawson's Code:** Refactor Jamie's `renderComponent` function to correctly handle dynamic feature flags and component rendering. The function should take a component name, user permissions, and feature flags, then return the appropriate React-like component configuration or null if the component should not render. __EXAMPLES__:[{"title":"Admin accessing Analytics","input":"componentName: \"Analytics\", userPermissions: [\"admin\"], featureFlags: { analyticsData: [1, 2, 3] }","output":"{ \"component\": \"Analytics\", \"props\": { \"data\": [1, 2, 3] } }","explanation":"The admin should see the Analytics component with the provided data since they have the correct permissions."},{"title":"Regular user trying to access AdminPanel","input":"componentName: \"AdminPanel\", userPermissions: [\"user\"], featureFlags: {}","output":"null","explanation":"The AdminPanel should not render for users without admin permissions, regardless of feature flags."}]
Written by Jamie Chen · Frontend Developer at SnackOverflow (self-proclaimed "Full-Stack in 30 Days") At the trendy startup "SnackOverflow," junior dev Jamie was tasked with implementing a new feature flag system to toggle between frontend themes and backend API endpoints. Under pressure from the CEO to "ship it by lunch," Jamie hacked together a monolithic function that mixed DOM manipulation with API calls. Now, users are seeing the wrong theme and the wrong data, and the CEO is livid. Can you fix Jamie's mess before the board meeting in 30 minutes? **Jamie "Copy-Paste" Chen's Code:** Refactor Jamie's messy function to correctly separate frontend theme toggling from backend API endpoint selection. The function should return an object with two properties: `theme` (string) and `apiEndpoint` (string), based on the input feature flag. __EXAMPLES__:[{"title":"Dark Mode Flag","input":"The feature flag is set to \"dark_mode\".","output":"The function returns `{ theme: \"dark\", apiEndpoint: \"https://api.snackoverflow.com/v1\" }`.","explanation":"The \"dark_mode\" flag should only affect the theme, not the API endpoint. The DOM manipulation is unnecessary and should be removed."},{"title":"Legacy Flag","input":"The feature flag is set to \"legacy\".","output":"The function returns `{ theme: \"light\", apiEndpoint: \"https://api.snackoverflow.com/legacy\" }`.","explanation":"The \"legacy\" flag should only affect the API endpoint. The theme should default to \"light\" since it wasn't explicitly set."}]
Meet Jamie, a frontend developer at StartupX who was tasked with implementing a new feature flag system to toggle between two API endpoints. Under pressure from the CEO to ship by EOD, Jamie hacked together a solution that somehow mixed frontend state with backend logic in a single function. Now, the feature flags are flipping randomly, and the CEO is seeing the wrong dashboard data. The team has 30 minutes to fix it before the investor demo. **Jamie's Code:** Refactor Jamie's messy feature flag logic to correctly determine which API endpoint to call based on the user's role and the feature flag state. The function should return the appropriate endpoint URL. __EXAMPLES__:[{"title":"Admin with Feature Enabled","input":"userRole is \"admin\" and isFeatureEnabled is true","output":"The endpoint should be \"https://api.startupx.com/admin/new-dashboard\"","explanation":"Admins with the feature enabled should get the new admin dashboard endpoint."},{"title":"User with Feature Disabled","input":"userRole is \"user\" and isFeatureEnabled is false","output":"The endpoint should be \"https://api.startupx.com/v1\"","explanation":"Regular users with the feature disabled should get the old endpoint."}]
Meet Jamie, a frontend developer at StartupX who was tasked with implementing a new feature flag system to toggle between two API endpoints. Under pressure from the CEO to ship by EOD, Jamie hacked together a solution that mixed frontend state with backend logic in a single function. Now, the feature flags are causing inconsistent behavior, and the CEO is seeing different results on every refresh! **Jamie's Code:** Refactor Jamie's messy code to properly separate frontend and backend logic. The function should dynamically switch between two API endpoints based on a feature flag, but currently, it's mixing concerns and has a logical bug that causes incorrect endpoint selection. __EXAMPLES__:[{"title":"Admin with New Dashboard Flag","input":"featureFlag = \"new_dashboard\", userData = { id: 123, role: \"admin\" }","output":"An object with adminData, userData, and debugUrl pointing to \"https://api.startupx.com/v2\"","explanation":"The feature flag is set to \"new_dashboard\", so the v2 endpoint should be used. The user is an admin, so both adminData and userData should be fetched from the v2 endpoint."},{"title":"Non-Admin with Old Dashboard Flag","input":"featureFlag = \"old_dashboard\", userData = { id: 456, role: \"user\" }","output":"An object with userData and debugUrl pointing to \"https://api.startupx.com/v1\", but no adminData","explanation":"The feature flag is not set to \"new_dashboard\", so the v1 endpoint should be used. The user is not an admin, so only userData should be fetched."}]
At the trendy startup "CodeBrew", junior developer Jamie was tasked with implementing a new feature flag system that would toggle UI elements based on backend logic. Under pressure from the CEO to ship by EOD, Jamie hacked together a solution that somehow worked... until the QA team noticed the frontend was making 50+ API calls per second for a single toggle. The backend team is now threatening to revoke Jamie's coffee privileges. **Jamie's Code:** Refactor Jamie's messy feature flag function to properly cache backend responses and avoid redundant API calls while maintaining the same functionality. __EXAMPLES__:[{"title":"Basic Feature Flag Check","input":"Check if the 'newDashboard' feature is enabled with a default value of false","output":"Returns true (since the mock backend has this flag set to true)","explanation":"The function should return the value from the backend for existing flags, ignoring the default value."},{"title":"Non-existent Feature Flag","input":"Check if the 'nonexistentFeature' is enabled with a default value of true","output":"Returns true (the default value)","explanation":"When the backend doesn't have the requested flag, the function should return the provided default value."}]
Meet Jamie, a frontend developer at StartupX who was tasked with implementing a new feature flag system to toggle between two API endpoints. Under pressure from the CEO to ship by EOD, Jamie hacked together a solution that mixed frontend state with backend logic in a single function. Now, the feature flags are acting erratically, and the CEO is seeing the wrong data in the dashboard. The team has 30 minutes to fix it before the investor demo! **Jamie's Code:** Refactor Jamie's messy feature flag function to correctly determine which API endpoint to call based on the feature flag state and user role. The function should return the appropriate endpoint URL and ensure the logic is clean and maintainable.
It's 3 AM, and startup developer "Zack Attack" is frantically trying to launch the company's new feature: a real-time user activity dashboard. Under pressure from the CEO to "just make it work," Zack hacked together a frontend-backend hybrid function that fetches user data, processes it, and renders it—all in one messy blob. The dashboard is live, but users are complaining about slow load times and incorrect data. The CEO just texted: "FIX IT OR WE'RE DOOMED." **Zack Attack's Code:** Refactor Zack's monolithic function to separate frontend rendering logic from backend data processing. Fix the logical bug causing incorrect user activity counts and improve performance by avoiding unnecessary computations.
At the trendy startup "CodeBrew", junior developer Jamie was tasked with building a "simple" user dashboard that displays a user's profile and their recent orders. Under pressure from the CEO to "ship it by yesterday," Jamie hacked together a monstrosity that fetches user data and order history in a single function, mixes frontend rendering with backend logic, and somehow manages to call the database in a loop. Now, the dashboard is painfully slow, and users are complaining. The team has 1 hour to fix it before the CEO notices. **Jamie's Code:** Refactor Jamie's messy function to separate frontend rendering from backend logic, fix the performance issue, and ensure the function returns the correct dashboard data structure. The function should efficiently fetch and combine user data and order history without redundant database calls.
Alex, a junior developer at DataFlow Inc., was given just one hour to fix the company's analytics dashboard before a big client demo. Under pressure, Alex hacked together a function to filter and display user data, but now the dashboard is slow and sometimes shows incorrect results. The client is waiting, and Alex needs your help to clean up the mess! **Alex's Code:** Refactor the `solution` function to correctly filter an array of user objects based on a search term and a minimum activity score. The function should return an array of usernames that match both criteria. The search term should be case-insensitive and match any part of the username. The activity score must be greater than or equal to the provided minimum.
Meet Jamie, a frontend developer who was just told at 4:55 PM on a Friday that the backend API for the new user dashboard is "mostly done" but needs a quick frontend integration. Under pressure from the PM to "just make it work before the weekend," Jamie hacked together a function that fetches user data, processes it, and even handles the UI updates—all in one messy blob. Now, the dashboard is slow, buggy, and the team is questioning why the "loading" spinner never stops spinning. **Jamie's Code:** Refactor Jamie's chaotic function to separate frontend and backend concerns. The function should fetch user data from a mock API, process it, and return a clean object for the frontend to render. Ensure the function is efficient, readable, and doesn't mix responsibilities.
At 'SliceHub', a trendy pizza delivery startup, the lead developer, Gary, was up all night coding the pizza order system. In a caffeine-fueled haze, he mixed frontend UI logic with backend order validation, creating a monstrosity that crashes when customers order more than 3 pizzas. The CEO is livid—orders are pouring in, but the system can't handle them! **Gary's Code:** Fix Gary's `processOrder` function so it correctly validates and processes pizza orders without crashing or mixing UI and backend logic.