319 challenges in the catalogue. Browse freely; sign in to open the editor and submit.
Implement a minimal Observable class (inspired by RxJS) and a fromPromise factory function. The Observable should support subscribing with next/error/complete callbacks, and basic operators like map and filter. constructor(subscribeFn) —…
Sign in to solveFive philosophers sit at a round table with a fork between each pair. To eat, a philosopher needs both the left and right fork. Design a solution that prevents deadlock and allows all philosophers to eat. Implement a deadlock-free solution…
Sign in to solveA system logs failed and succeeded tasks in two separate tables. Write a solution to report the period of time in 2019 where tasks had the same status ('failed' or 'succeeded') continuously. The result table should contain period_state,…
Sign in to solveImplement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (push, top, pop, and empty). Implement the MyStack class: void push(int x) Pushes element x to the…
Sign in to solveGiven an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume…
Sign in to solveGiven an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1: Example 2: 1 <= nums.length <= 10^5 -10^4 <= nums[i] <= 10^4 k is in the range [1, the number of unique…
Sign in to solveGiven an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order. The same number may be…
Sign in to solveImplement a transaction manager that supports ACID properties with optimistic concurrency control. The system should handle concurrent transactions, detect conflicts using version numbers, support automatic retries, and ensure data…
Sign in to solveGiven an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You must write an algorithm with O(log n)…
Sign in to solveGiven an integer array nums of unique elements, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. Example 1: Example 2: 1 <= nums.length <= 10 -10 <= nums[i]…
Sign in to solveGiven an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue. We will use the integers 0, 1, and 2 to represent the…
Sign in to solveGiven head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally,…
Sign in to solve