export interface CodingQuestion { id: string; title: string; difficulty: 'Easy' | 'Medium' | 'Hard'; category: string; companies?: string[]; description: string; starterCode: { javascript: string; python: string; cpp: string; java: string; go: string; }; testCases: { input: string; output: string; params: any[]; expected: any; }[]; hiddenTestCases: { input: string; output: string; params: any[]; expected: any; }[]; solution: { javascript: string; python: string; cpp: string; java: string; go: string; explanation: string; }; } export const codingQuestions: CodingQuestion[] = [ { id: 'two-sum', title: 'Pair Sum Target', difficulty: 'Easy', category: 'Array', description: `Given a collection of integers \`nums\` and a specific \`target\` value, identify the indices of two numbers that combine to reach the \`target\`. Each input is guaranteed to have exactly one solution, and you cannot use the same element twice. The order of indices in the result does not matter.`, starterCode: { javascript: `/** * @param {number[]} nums * @param {number} target * @return {number[]} */ var twoSum = function(nums, target) { };`, python: `class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: pass`, cpp: `class Solution { public: vector twoSum(vector& nums, int target) { } };`, java: `class Solution { public int[] twoSum(int[] nums, int target) { } }`, go: `func twoSum(nums []int, target int) []int { }` }, testCases: [ { input: 'nums = [2,7,11,15], target = 9', output: '[0,1]', params: [[2,7,11,15], 9], expected: [0,1] }, { input: 'nums = [3,2,4], target = 6', output: '[1,2]', params: [[3,2,4], 6], expected: [1,2] } ], hiddenTestCases: [ { input: 'nums = [3,3], target = 6', output: '[0,1]', params: [[3,3], 6], expected: [0,1] }, { input: 'nums = [-1,-2,-3,-4,-5], target = -8', output: '[2,4]', params: [[-1,-2,-3,-4,-5], -8], expected: [2,4] } ], solution: { javascript: `var twoSum = function(nums, target) { const map = new Map(); for (let i = 0; i < nums.length; i++) { const complement = target - nums[i]; if (map.has(complement)) { return [map.get(complement), i]; } map.set(nums[i], i); } };`, python: `class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: prevMap = {} # val : index for i, n in enumerate(nums): diff = target - n if diff in prevMap: return [prevMap[diff], i] prevMap[n] = i`, cpp: `class Solution { public: vector twoSum(vector& nums, int target) { unordered_map prevMap; for (int i = 0; i < nums.size(); i++) { int diff = target - nums[i]; if (prevMap.find(diff) != prevMap.end()) { return {prevMap[diff], i}; } prevMap[nums[i]] = i; } return {}; } };`, java: `class Solution { public int[] twoSum(int[] nums, int target) { Map prevMap = new HashMap<>(); for (int i = 0; i < nums.length; i++) { int diff = target - nums[i]; if (prevMap.containsKey(diff)) { return new int[] { prevMap.get(diff), i }; } prevMap.put(nums[i], i); } return new int[] {}; } }`, go: `func twoSum(nums []int, target int) []int { prevMap := make(map[int]int) for i, n := range nums { diff := target - n if idx, ok := prevMap[diff]; ok { return []int{idx, i} } prevMap[n] = i } return nil }`, explanation: "Use a hash map to store the indices of numbers we've seen so far. For each number, check if its complement (target - current) exists in the map." } }, { id: 'stock-profit', title: 'Optimal Stock Trading', difficulty: 'Easy', category: 'Array', description: `You are given an array \`prices\` where \`prices[i]\` is the price of a given stock on the \`i-th\` day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.`, starterCode: { javascript: `/** * @param {number[]} prices * @return {number} */ var maxProfit = function(prices) { };`, python: `class Solution: def maxProfit(self, prices: List[int]) -> int: pass`, cpp: `class Solution { public: int maxProfit(vector& prices) { } };`, java: `class Solution { public int maxProfit(int[] prices) { } }`, go: `func maxProfit(prices []int) int { }` }, testCases: [ { input: 'prices = [7,1,5,3,6,4]', output: '5', params: [[7,1,5,3,6,4]], expected: 5 }, { input: 'prices = [7,6,4,3,1]', output: '0', params: [[7,6,4,3,1]], expected: 0 } ], hiddenTestCases: [ { input: 'prices = [1,2]', output: '1', params: [[1,2]], expected: 1 }, { input: 'prices = [2,4,1]', output: '2', params: [[2,4,1]], expected: 2 } ], solution: { javascript: `var maxProfit = function(prices) { let minPrice = Infinity; let maxProfit = 0; for (let price of prices) { if (price < minPrice) minPrice = price; else if (price - minPrice > maxProfit) maxProfit = price - minPrice; } return maxProfit; };`, python: `class Solution: def maxProfit(self, prices: List[int]) -> int: res = 0 lowest = prices[0] for price in prices: if price < lowest: lowest = price res = max(res, price - lowest) return res`, cpp: `class Solution { public: int maxProfit(vector& prices) { int l = 0, r = 1; int maxP = 0; while (r < prices.size()) { if (prices[l] < prices[r]) { int profit = prices[r] - prices[l]; maxP = max(maxP, profit); } else { l = r; } r++; } return maxP; } };`, java: `class Solution { public int maxProfit(int[] prices) { int minPrice = Integer.MAX_VALUE; int maxProfit = 0; for (int price : prices) { if (price < minPrice) minPrice = price; else if (price - minPrice > maxProfit) maxProfit = price - minPrice; } return maxProfit; } }`, go: `func maxProfit(prices []int) int { minPrice := 1000000000 maxProfit := 0 for _, price := range prices { if price < minPrice { minPrice = price } else if price - minPrice > maxProfit { maxProfit = price - minPrice } } return maxProfit }`, explanation: "Keep track of the minimum price seen so far and calculate the potential profit at each step. Update the maximum profit if the current profit is higher." } }, { id: 'contains-duplicate', title: 'Duplicate Finder', difficulty: 'Easy', category: 'Array', description: `Given an integer array \`nums\`, return \`true\` if any value appears at least twice in the array, and return \`false\` if every element is distinct.`, starterCode: { javascript: `/** * @param {number[]} nums * @return {boolean} */ var containsDuplicate = function(nums) { };`, python: `class Solution: def containsDuplicate(self, nums: List[int]) -> bool: pass`, cpp: `class Solution { public: bool containsDuplicate(vector& nums) { } };`, java: `class Solution { public boolean containsDuplicate(int[] nums) { } }`, go: `func containsDuplicate(nums []int) bool { }` }, testCases: [ { input: 'nums = [1,2,3,1]', output: 'true', params: [[1,2,3,1]], expected: true }, { input: 'nums = [1,2,3,4]', output: 'false', params: [[1,2,3,4]], expected: false } ], hiddenTestCases: [ { input: 'nums = [1,1,1,3,3,4,3,2,4,2]', output: 'true', params: [[1,1,1,3,3,4,3,2,4,2]], expected: true }, { input: 'nums = []', output: 'false', params: [[]], expected: false } ], solution: { javascript: `var containsDuplicate = function(nums) { const set = new Set(nums); return set.size !== nums.length; };`, python: `class Solution: def containsDuplicate(self, nums: List[int]) -> bool: hashset = set() for n in nums: if n in hashset: return True hashset.add(n) return False`, cpp: `class Solution { public: bool containsDuplicate(vector& nums) { unordered_set s; for (int n : nums) { if (s.count(n)) return true; s.insert(n); } return false; } };`, java: `class Solution { public boolean containsDuplicate(int[] nums) { Set set = new HashSet<>(); for (int n : nums) { if (set.contains(n)) return true; set.add(n); } return false; } }`, go: `func containsDuplicate(nums []int) bool { hashset := make(map[int]bool) for _, n := range nums { if hashset[n] { return true } hashset[n] = true } return false }`, explanation: "Use a hash set to keep track of elements already seen. If an element is already in the set, a duplicate exists." } }, { id: 'product-except-self', title: 'Array Product Exclusion', difficulty: 'Medium', category: 'Array', description: `Given an integer array \`nums\`, return an array \`answer\` such that \`answer[i]\` is equal to the product of all the elements of \`nums\` except \`nums[i]\`. The product of any prefix or suffix of \`nums\` is guaranteed to fit in a 32-bit integer. You must write an algorithm that runs in O(n) time and without using the division operation.`, starterCode: { javascript: `/** * @param {number[]} nums * @return {number[]} */ var productExceptSelf = function(nums) { };`, python: `class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: pass`, cpp: `class Solution { public: vector productExceptSelf(vector& nums) { } };`, java: `class Solution { public int[] productExceptSelf(int[] nums) { } }`, go: `func productExceptSelf(nums []int) []int { }` }, testCases: [ { input: 'nums = [1,2,3,4]', output: '[24,12,8,6]', params: [[1,2,3,4]], expected: [24,12,8,6] }, { input: 'nums = [-1,1,0,-3,3]', output: '[0,0,9,0,0]', params: [[-1,1,0,-3,3]], expected: [0,0,9,0,0] } ], hiddenTestCases: [ { input: 'nums = [0,0]', output: '[0,0]', params: [[0,0]], expected: [0,0] }, { input: 'nums = [1,0]', output: '[0,1]', params: [[1,0]], expected: [0,1] } ], solution: { javascript: `var productExceptSelf = function(nums) { const res = new Array(nums.length).fill(1); let prefix = 1; for (let i = 0; i < nums.length; i++) { res[i] = prefix; prefix *= nums[i]; } let postfix = 1; for (let i = nums.length - 1; i >= 0; i--) { res[i] *= postfix; postfix *= nums[i]; } return res; };`, python: `class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: res = [1] * (len(nums)) prefix = 1 for i in range(len(nums)): res[i] = prefix prefix *= nums[i] postfix = 1 for i in range(len(nums) - 1, -1, -1): res[i] *= postfix postfix *= nums[i] return res`, cpp: `class Solution { public: vector productExceptSelf(vector& nums) { int n = nums.size(); vector res(n, 1); int prefix = 1; for (int i = 0; i < n; i++) { res[i] = prefix; prefix *= nums[i]; } int postfix = 1; for (int i = n - 1; i >= 0; i--) { res[i] *= postfix; postfix *= nums[i]; } return res; } };`, java: `class Solution { public int[] productExceptSelf(int[] nums) { int n = nums.length; int[] res = new int[n]; res[0] = 1; for (int i = 1; i < n; i++) { res[i] = res[i - 1] * nums[i - 1]; } int right = 1; for (int i = n - 1; i >= 0; i--) { res[i] *= right; right *= nums[i]; } return res; } }`, go: `func productExceptSelf(nums []int) []int { n := len(nums) res := make([]int, n) res[0] = 1 for i := 1; i < n; i++ { res[i] = res[i-1] * nums[i-1] } right := 1 for i := n - 1; i >= 0; i-- { res[i] *= right right *= nums[i] } return res }`, explanation: "Calculate prefix products in one pass and suffix products in another pass. The result for each index is the product of its prefix and suffix." } }, { id: 'max-subarray', title: 'Maximum Sum Segment', difficulty: 'Medium', category: 'Array', description: `Given an integer array \`nums\`, find the subarray with the largest sum, and return its sum.`, starterCode: { javascript: `/** * @param {number[]} nums * @return {number} */ var maxSubArray = function(nums) { };`, python: `class Solution: def maxSubArray(self, nums: List[int]) -> int: pass`, cpp: `class Solution { public: int maxSubArray(vector& nums) { } };`, java: `class Solution { public int maxSubArray(int[] nums) { } }`, go: `func maxSubArray(nums []int) int { }` }, testCases: [ { input: 'nums = [-2,1,-3,4,-1,2,1,-5,4]', output: '6', params: [[-2,1,-3,4,-1,2,1,-5,4]], expected: 6 }, { input: 'nums = [1]', output: '1', params: [[1]], expected: 1 } ], hiddenTestCases: [ { input: 'nums = [5,4,-1,7,8]', output: '23', params: [[5,4,-1,7,8]], expected: 23 }, { input: 'nums = [-1]', output: '-1', params: [[-1]], expected: -1 } ], solution: { javascript: `var maxSubArray = function(nums) { let maxSub = nums[0]; let curSum = 0; for (let n of nums) { if (curSum < 0) curSum = 0; curSum += n; maxSub = Math.max(maxSub, curSum); } return maxSub; };`, python: `class Solution: def maxSubArray(self, nums: List[int]) -> int: maxSub = nums[0] curSum = 0 for n in nums: if curSum < 0: curSum = 0 curSum += n maxSub = max(maxSub, curSum) return maxSub`, cpp: `class Solution { public: int maxSubArray(vector& nums) { int maxSub = nums[0]; int curSum = 0; for (int n : nums) { if (curSum < 0) curSum = 0; curSum += n; maxSub = max(maxSub, curSum); } return maxSub; } };`, java: `class Solution { public int maxSubArray(int[] nums) { int maxSub = nums[0]; int curSum = 0; for (int n : nums) { if (curSum < 0) curSum = 0; curSum += n; maxSub = Math.max(maxSub, curSum); } return maxSub; } }`, go: `func maxSubArray(nums []int) int { maxSub := nums[0] curSum := 0 for _, n := range nums { if curSum < 0 { curSum = 0 } curSum += n if curSum > maxSub { maxSub = curSum } } return maxSub }`, explanation: "Use Kadane's Algorithm: Iterate through the array, keeping track of the current sum. If the current sum becomes negative, reset it to zero. The maximum sum encountered during the process is the result." } }, { id: 'three-sum', title: 'Triplet Sum Zero', difficulty: 'Medium', category: 'Array', description: `Given an integer array \`nums\`, return all the triplets \`[nums[i], nums[j], nums[k]]\` such that \`i != j\`, \`i != k\`, and \`j != k\`, and \`nums[i] + nums[j] + nums[k] == 0\`. Notice that the solution set must not contain duplicate triplets.`, starterCode: { javascript: `/** * @param {number[]} nums * @return {number[][]} */ var threeSum = function(nums) { };`, python: `class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: pass`, cpp: `class Solution { public: vector> threeSum(vector& nums) { } };`, java: `class Solution { public List> threeSum(int[] nums) { } }`, go: `func threeSum(nums []int) [][]int { }` }, testCases: [ { input: 'nums = [-1,0,1,2,-1,-4]', output: '[[-1,-1,2],[-1,0,1]]', params: [[-1,0,1,2,-1,-4]], expected: [[-1,-1,2],[-1,0,1]] }, { input: 'nums = [0,1,1]', output: '[]', params: [[0,1,1]], expected: [] }, { input: 'nums = [0,0,0]', output: '[[0,0,0]]', params: [[0,0,0]], expected: [[0,0,0]] } ], hiddenTestCases: [ { input: 'nums = [-2,0,0,2,2]', output: '[[-2,0,2]]', params: [[-2,0,0,2,2]], expected: [[-2,0,2]] }, { input: 'nums = []', output: '[]', params: [[]], expected: [] } ], solution: { javascript: `var threeSum = function(nums) { const res = []; nums.sort((a, b) => a - b); for (let i = 0; i < nums.length; i++) { if (i > 0 && nums[i] === nums[i - 1]) continue; let l = i + 1, r = nums.length - 1; while (l < r) { const sum = nums[i] + nums[l] + nums[r]; if (sum > 0) r--; else if (sum < 0) l++; else { res.push([nums[i], nums[l], nums[r]]); l++; while (nums[l] === nums[l - 1] && l < r) l++; } } } return res; };`, python: `class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: res = [] nums.sort() for i, a in enumerate(nums): if i > 0 and a == nums[i - 1]: continue l, r = i + 1, len(nums) - 1 while l < r: threeSum = a + nums[l] + nums[r] if threeSum > 0: r -= 1 elif threeSum < 0: l += 1 else: res.append([a, nums[l], nums[r]]) l += 1 while nums[l] == nums[l - 1] and l < r: l += 1 return res`, cpp: `class Solution { public: vector> threeSum(vector& nums) { vector> res; sort(nums.begin(), nums.end()); for (int i = 0; i < nums.size(); i++) { if (i > 0 && nums[i] == nums[i - 1]) continue; int l = i + 1, r = nums.size() - 1; while (l < r) { int sum = nums[i] + nums[l] + nums[r]; if (sum > 0) r--; else if (sum < 0) l++; else { res.push_back({nums[i], nums[l], nums[r]}); l++; while (nums[l] == nums[l - 1] && l < r) l++; } } } return res; } };`, java: `class Solution { public List> threeSum(int[] nums) { Arrays.sort(nums); List> res = new ArrayList<>(); for (int i = 0; i < nums.length && nums[i] <= 0; ++i) if (i == 0 || nums[i - 1] != nums[i]) { twoSumII(nums, i, res); } return res; } void twoSumII(int[] nums, int i, List> res) { int lo = i + 1, hi = nums.length - 1; while (lo < hi) { int sum = nums[i] + nums[lo] + nums[hi]; if (sum < 0) { ++lo; } else if (sum > 0) { --hi; } else { res.add(Arrays.asList(nums[i], nums[lo++], nums[hi--])); while (lo < hi && nums[lo] == nums[lo - 1]) ++lo; } } } }`, go: `func threeSum(nums []int) [][]int { sort.Ints(nums) res := [][]int{} for i := 0; i < len(nums)-2; i++ { if i > 0 && nums[i] == nums[i-1] { continue } l, r := i+1, len(nums)-1 for l < r { sum := nums[i] + nums[l] + nums[r] if sum < 0 { l++ } else if sum > 0 { r-- } else { res = append(res, []int{nums[i], nums[l], nums[r]}) l++ for l < r && nums[l] == nums[l-1] { l++ } } } } return res }`, explanation: "Sort the array first. Iterate through the array and for each element, use two pointers (left and right) to find pairs that sum to the negative of the current element. Skip duplicates to ensure unique triplets." } }, { id: 'max-product-subarray', title: 'Maximum Product Subarray', difficulty: 'Medium', category: 'Array', description: `Given an integer array \`nums\`, find a contiguous non-empty subarray within the array that has the largest product, and return the product.`, starterCode: { javascript: `var maxProduct = function(nums) {\n \n};`, python: `class Solution:\n def maxProduct(self, nums: List[int]) -> int:\n pass`, cpp: `class Solution {\npublic:\n int maxProduct(vector& nums) {\n \n }\n};`, java: `class Solution {\n public int maxProduct(int[] nums) {\n \n }\n}`, go: `func maxProduct(nums []int) int {\n \n}` }, testCases: [{ input: 'nums = [2,3,-2,4]', output: '6', params: [[2,3,-2,4]], expected: 6 }], hiddenTestCases: [{ input: 'nums = [-2,0,-1]', output: '0', params: [[-2,0,-1]], expected: 0 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use dynamic programming to keep track of both the maximum and minimum product ending at the current position.' } }, { id: 'min-rotated-sorted', title: 'Find Minimum in Rotated Sorted Array', difficulty: 'Medium', category: 'Array', description: `Suppose an array of length \`n\` sorted in ascending order is rotated between \`1\` and \`n\` times. Find the minimum element of this array.`, starterCode: { javascript: `var findMin = function(nums) {\n \n};`, python: `class Solution:\n def findMin(self, nums: List[int]) -> int:\n pass`, cpp: `class Solution {\npublic:\n int findMin(vector& nums) {\n \n }\n};`, java: `class Solution {\n public int findMin(int[] nums) {\n \n }\n}`, go: `func findMin(nums []int) int {\n \n}` }, testCases: [{ input: 'nums = [3,4,5,1,2]', output: '1', params: [[3,4,5,1,2]], expected: 1 }], hiddenTestCases: [{ input: 'nums = [4,5,6,7,0,1,2]', output: '0', params: [[4,5,6,7,0,1,2]], expected: 0 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use binary search to find the inflection point where the array is rotated.' } }, { id: 'search-rotated-sorted', title: 'Search in Rotated Sorted Array', difficulty: 'Medium', category: 'Array', description: `Given the array \`nums\` after the possible rotation and an integer \`target\`, return the index of \`target\` if it is in \`nums\`, or \`-1\` if it is not in \`nums\`.`, starterCode: { javascript: `var search = function(nums, target) {\n \n};`, python: `class Solution:\n def search(self, nums: List[int], target: int) -> int:\n pass`, cpp: `class Solution {\npublic:\n int search(vector& nums, int target) {\n \n }\n};`, java: `class Solution {\n public int search(int[] nums, int target) {\n \n }\n}`, go: `func search(nums []int, target int) int {\n \n}` }, testCases: [{ input: 'nums = [4,5,6,7,0,1,2], target = 0', output: '4', params: [[4,5,6,7,0,1,2], 0], expected: 4 }], hiddenTestCases: [{ input: 'nums = [4,5,6,7,0,1,2], target = 3', output: '-1', params: [[4,5,6,7,0,1,2], 3], expected: -1 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use a modified binary search that accounts for the rotation by identifying which half of the array is sorted.' } }, { id: 'sum-two-integers', title: 'Sum of Two Integers', difficulty: 'Medium', category: 'Binary', description: `Given two integers \`a\` and \`b\`, return the sum of the two integers without using the operators \`+\` and \`-\`.`, starterCode: { javascript: `var getSum = function(a, b) {\n \n};`, python: `class Solution:\n def getSum(self, a: int, b: int) -> int:\n pass`, cpp: `class Solution {\npublic:\n int getSum(int a, int b) {\n \n }\n};`, java: `class Solution {\n public int getSum(int a, int b) {\n \n }\n}`, go: `func getSum(a int, b int) int {\n \n}` }, testCases: [{ input: 'a = 1, b = 2', output: '3', params: [1, 2], expected: 3 }], hiddenTestCases: [{ input: 'a = 2, b = 3', output: '5', params: [2, 3], expected: 5 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use bitwise XOR for addition and bitwise AND followed by a left shift for the carry.' } }, { id: 'number-of-1-bits', title: 'Number of 1 Bits', difficulty: 'Easy', category: 'Binary', description: `Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).`, starterCode: { javascript: `var hammingWeight = function(n) {\n \n};`, python: `class Solution:\n def hammingWeight(self, n: int) -> int:\n pass`, cpp: `class Solution {\npublic:\n int hammingWeight(uint32_t n) {\n \n }\n};`, java: `class Solution {\n public int hammingWeight(int n) {\n \n }\n}`, go: `func hammingWeight(num uint32) int {\n \n}` }, testCases: [{ input: 'n = 11', output: '3', params: [11], expected: 3 }], hiddenTestCases: [{ input: 'n = 128', output: '1', params: [128], expected: 1 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use bitwise AND with (n-1) to repeatedly clear the least significant set bit until the number becomes zero.' } }, { id: 'counting-bits', title: 'Counting Bits', difficulty: 'Easy', category: 'Binary', description: `Given an integer \`n\`, return an array \`ans\` of length \`n + 1\` such that for each \`i\` (\`0 <= i <= n\`), \`ans[i]\` is the number of \`1\`'s in the binary representation of \`i\`.`, starterCode: { javascript: `var countBits = function(n) {\n \n};`, python: `class Solution:\n def countBits(self, n: int) -> List[int]:\n pass`, cpp: `class Solution {\npublic:\n vector countBits(int n) {\n \n }\n};`, java: `class Solution {\n public int[] countBits(int n) {\n \n }\n}`, go: `func countBits(n int) []int {\n \n}` }, testCases: [{ input: 'n = 2', output: '[0,1,1]', params: [2], expected: [0,1,1] }], hiddenTestCases: [{ input: 'n = 5', output: '[0,1,1,2,1,2]', params: [5], expected: [0,1,1,2,1,2] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use dynamic programming: the number of set bits in i is 1 + the number of set bits in (i & (i-1)).' } }, { id: 'missing-number', title: 'Missing Number', difficulty: 'Easy', category: 'Binary', description: `Given an array \`nums\` containing \`n\` distinct numbers in the range \`[0, n]\`, return the only number in the range that is missing from the array.`, starterCode: { javascript: `var missingNumber = function(nums) {\n \n};`, python: `class Solution:\n def missingNumber(self, nums: List[int]) -> int:\n pass`, cpp: `class Solution {\npublic:\n int missingNumber(vector& nums) {\n \n }\n};`, java: `class Solution {\n public int missingNumber(int[] nums) {\n \n }\n}`, go: `func missingNumber(nums []int) int {\n \n}` }, testCases: [{ input: 'nums = [3,0,1]', output: '2', params: [[3,0,1]], expected: 2 }], hiddenTestCases: [{ input: 'nums = [0,1]', output: '2', params: [[0,1]], expected: 2 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Calculate the expected sum of numbers from 0 to n and subtract the actual sum of the array elements.' } }, { id: 'reverse-bits', title: 'Reverse Bits', difficulty: 'Easy', category: 'Binary', description: `Reverse bits of a given 32 bits unsigned integer.`, starterCode: { javascript: `var reverseBits = function(n) {\n \n};`, python: `class Solution:\n def reverseBits(self, n: int) -> int:\n pass`, cpp: `class Solution {\npublic:\n uint32_t reverseBits(uint32_t n) {\n \n }\n};`, java: `class Solution {\n public int reverseBits(int n) {\n \n }\n}`, go: `func reverseBits(num uint32) uint32 {\n \n}` }, testCases: [{ input: 'n = 43261596', output: '964176192', params: [43261596], expected: 964176192 }], hiddenTestCases: [{ input: 'n = 1', output: '2147483648', params: [1], expected: 2147483648 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Iterate 32 times, shifting the result left and adding the last bit of n, then shifting n right.' } }, { id: 'climbing-stairs', title: 'Climbing Stairs', difficulty: 'Easy', category: 'DP', description: `You are climbing a staircase. It takes \`n\` steps to reach the top. Each time you can either climb \`1\` or \`2\` steps. In how many distinct ways can you climb to the top?`, starterCode: { javascript: 'var climbStairs = function(n) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'n = 2', output: '2', params: [2], expected: 2 }], hiddenTestCases: [{ input: 'n = 3', output: '3', params: [3], expected: 3 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'This is a classic Fibonacci sequence problem. The number of ways to reach step n is the sum of ways to reach step n-1 and n-2.' } }, { id: 'coin-change-ii', title: 'Coin Change II', difficulty: 'Medium', category: 'DP', description: `You are given an integer array \`coins\` representing coins of different denominations and an integer \`amount\` representing a total amount of money. Return the number of combinations that make up that amount.`, starterCode: { javascript: 'var change = function(amount, coins) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'amount = 5, coins = [1,2,5]', output: '4', params: [5, [1,2,5]], expected: 4 }], hiddenTestCases: [{ input: 'amount = 3, coins = [2]', output: '0', params: [3, [2]], expected: 0 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use dynamic programming where dp[i] represents the number of ways to make amount i. Iterate through each coin and update the dp array.' } }, { id: 'longest-increasing-subsequence', title: 'Longest Increasing Subsequence', difficulty: 'Medium', category: 'DP', description: `Given an integer array \`nums\`, return the length of the longest strictly increasing subsequence.`, starterCode: { javascript: 'var lengthOfLIS = function(nums) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'nums = [10,9,2,5,3,7,101,18]', output: '4', params: [[10,9,2,5,3,7,101,18]], expected: 4 }], hiddenTestCases: [{ input: 'nums = [0,1,0,3,2,3]', output: '4', params: [[0,1,0,3,2,3]], expected: 4 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use dynamic programming where dp[i] is the length of the LIS ending at index i, or use binary search with a tails array for O(n log n) complexity.' } }, { id: 'longest-common-subsequence', title: 'Longest Common Subsequence', difficulty: 'Medium', category: 'DP', description: `Given two strings \`text1\` and \`text2\`, return the length of their longest common subsequence.`, starterCode: { javascript: 'var longestCommonSubsequence = function(text1, text2) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'text1 = "abcde", text2 = "ace"', output: '3', params: ["abcde", "ace"], expected: 3 }], hiddenTestCases: [{ input: 'text1 = "abc", text2 = "abc"', output: '3', params: ["abc", "abc"], expected: 3 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use a 2D DP table where dp[i][j] represents the LCS of text1[0...i] and text2[0...j].' } }, { id: 'word-break', title: 'Word Break', difficulty: 'Medium', category: 'DP', description: `Given a string \`s\` and a dictionary of strings \`wordDict\`, return \`true\` if \`s\` can be segmented into a space-separated sequence of one or more dictionary words.`, starterCode: { javascript: 'var wordBreak = function(s, wordDict) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 's = "leetcode", wordDict = ["leet","code"]', output: 'true', params: ["leetcode", ["leet","code"]], expected: true }], hiddenTestCases: [{ input: 's = "applepenapple", wordDict = ["apple","pen"]', output: 'true', params: ["applepenapple", ["apple","pen"]], expected: true }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use dynamic programming where dp[i] is true if s[0...i] can be segmented. For each i, check all possible prefixes s[j...i].' } }, { id: 'combination-sum', title: 'Combination Sum', difficulty: 'Medium', category: 'DP', description: `Given 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\`.`, starterCode: { javascript: 'var combinationSum = function(candidates, target) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'candidates = [2,3,6,7], target = 7', output: '[[2,2,3],[7]]', params: [[2,3,6,7], 7], expected: [[2,2,3],[7]] }], hiddenTestCases: [{ input: 'candidates = [2,3,5], target = 8', output: '[[2,2,2,2],[2,3,3],[3,5]]', params: [[2,3,5], 8], expected: [[2,2,2,2],[2,3,3],[3,5]] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use backtracking to explore all possible combinations. Since we can reuse elements, the recursive call should start from the same index.' } }, { id: 'max-sum-non-adjacent', title: 'Maximum Sum of Non-Adjacent Elements', difficulty: 'Medium', category: 'DP', description: `Given an array of positive integers, find the maximum sum of a subsequence such that no two elements in the subsequence are adjacent in the array.`, starterCode: { javascript: 'var maxSumNonAdjacent = function(nums) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'nums = [3, 2, 7, 10]', output: '13', params: [[3, 2, 7, 10]], expected: 13 }], hiddenTestCases: [{ input: 'nums = [3, 2, 5, 10, 7]', output: '15', params: [[3, 2, 5, 10, 7]], expected: 15 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'This is similar to the House Robber problem. For each element, you can either include it (and add it to the max sum excluding the previous element) or exclude it.' } }, { id: 'house-robber', title: 'House Robber', difficulty: 'Medium', category: 'DP', description: `You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. The only constraint stopping you from robbing each of them is that adjacent houses have security systems connected.`, starterCode: { javascript: 'var rob = function(nums) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'nums = [1,2,3,1]', output: '4', params: [[1,2,3,1]], expected: 4 }], hiddenTestCases: [{ input: 'nums = [2,7,9,3,1]', output: '12', params: [[2,7,9,3,1]], expected: 12 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use dynamic programming: dp[i] = max(dp[i-1], dp[i-2] + nums[i]).' } }, { id: 'decode-ways', title: 'Decode Ways', difficulty: 'Medium', category: 'DP', description: `A message containing letters from A-Z can be encoded into numbers using the following mapping: 'A' -> "1", 'B' -> "2", ..., 'Z' -> "26". Given a string \`s\` containing only digits, return the number of ways to decode it.`, starterCode: { javascript: 'var numDecodings = function(s) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 's = "12"', output: '2', params: ["12"], expected: 2 }], hiddenTestCases: [{ input: 's = "226"', output: '3', params: ["226"], expected: 3 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use dynamic programming where dp[i] is the number of ways to decode s[0...i]. Check if s[i] and s[i-1...i] form valid decodings.' } }, { id: 'insert-interval', title: 'Insert Interval', difficulty: 'Medium', category: 'Interval', description: `You are given an array of non-overlapping intervals \`intervals\` where \`intervals[i] = [starti, endi]\` sorted in ascending order by \`starti\`. You are also given an interval \`newInterval = [start, end]\`.`, starterCode: { javascript: 'var insert = function(intervals, newInterval) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'intervals = [[1,3],[6,9]], newInterval = [2,5]', output: '[[1,5],[6,9]]', params: [[[1,3],[6,9]], [2,5]], expected: [[1,5],[6,9]] }], hiddenTestCases: [{ input: 'intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]', output: '[[1,2],[3,10],[12,16]]', params: [[[1,2],[3,5],[6,7],[8,10],[12,16]], [4,8]], expected: [[1,2],[3,10],[12,16]] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Iterate through intervals, adding those that end before the new interval starts. Then merge the new interval with overlapping ones, and finally add the remaining intervals.' } }, { id: 'merge-intervals', title: 'Merge Intervals', difficulty: 'Medium', category: 'Interval', description: `Given an array of \`intervals\` where \`intervals[i] = [starti, endi]\`, merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.`, starterCode: { javascript: 'var merge = function(intervals) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'intervals = [[1,3],[2,6],[8,10],[15,18]]', output: '[[1,6],[8,10],[15,18]]', params: [[[1,3],[2,6],[8,10],[15,18]]], expected: [[1,6],[8,10],[15,18]] }], hiddenTestCases: [{ input: 'intervals = [[1,4],[4,5]]', output: '[[1,5]]', params: [[[1,4],[4,5]]], expected: [[1,5]] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Sort intervals by start time. Iterate and merge an interval with the previous one if they overlap.' } }, { id: 'non-overlapping-intervals', title: 'Non-overlapping Intervals', difficulty: 'Medium', category: 'Interval', description: `Given an array of intervals \`intervals\` where \`intervals[i] = [starti, endi]\`, return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.`, starterCode: { javascript: 'var eraseOverlapIntervals = function(intervals) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'intervals = [[1,2],[2,3],[3,4],[1,3]]', output: '1', params: [[[1,2],[2,3],[3,4],[1,3]]], expected: 1 }], hiddenTestCases: [{ input: 'intervals = [[1,2],[1,2],[1,2]]', output: '2', params: [[[1,2],[1,2],[1,2]]], expected: 2 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Sort intervals by end time. Use a greedy approach to keep the interval that ends earliest to leave more room for others.' } }, { id: 'repeating-missing-number', title: 'Find the Repeating and Missing Number', difficulty: 'Medium', category: 'Interval', description: `Given an unsorted array of size \`n\`. Array elements are in the range from \`1\` to \`n\`. One number from set \`{1, 2, ..., n}\` is missing and one number occurs twice in the array. Find these two numbers.`, starterCode: { javascript: 'var findTwoElement = function(arr) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'arr = [3, 1, 3]', output: '[3, 2]', params: [[3, 1, 3]], expected: [3, 2] }], hiddenTestCases: [{ input: 'arr = [4, 3, 6, 2, 1, 1]', output: '[1, 5]', params: [[4, 3, 6, 2, 1, 1]], expected: [1, 5] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use mathematical equations (sum of n numbers and sum of squares) or bitwise XOR to find the two numbers.' } }, { id: 'clone-graph', title: 'Clone Graph', difficulty: 'Medium', category: 'Graph', description: `Given a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph.`, starterCode: { javascript: 'var cloneGraph = function(node) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'adjList = [[2,4],[1,3],[2,4],[1,3]]', output: '[[2,4],[1,3],[2,4],[1,3]]', params: [[[2,4],[1,3],[2,4],[1,3]]], expected: [[2,4],[1,3],[2,4],[1,3]] }], hiddenTestCases: [{ input: 'adjList = [[]]', output: '[[]]', params: [[[]]], expected: [[]] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use a hash map to store the mapping from original nodes to their clones. Perform a BFS or DFS traversal to clone the graph.' } }, { id: 'course-schedule-i', title: 'Course Schedule I', difficulty: 'Medium', category: 'Graph', description: `There are a total of \`numCourses\` courses you have to take, labeled from \`0\` to \`numCourses - 1\`. Some courses may have prerequisites. Return \`true\` if you can finish all courses.`, starterCode: { javascript: 'var canFinish = function(numCourses, prerequisites) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'numCourses = 2, prerequisites = [[1,0]]', output: 'true', params: [2, [[1,0]]], expected: true }], hiddenTestCases: [{ input: 'numCourses = 2, prerequisites = [[1,0],[0,1]]', output: 'false', params: [2, [[1,0],[0,1]]], expected: false }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'This is a cycle detection problem in a directed graph. Use Kahn\'s algorithm (BFS) or DFS to detect if a cycle exists.' } }, { id: 'pacific-atlantic-water-flow', title: 'Pacific Atlantic Water Flow', difficulty: 'Medium', category: 'Graph', description: `There is an \`m x n\` rectangular island that borders both the Pacific Ocean and the Atlantic Ocean. Find all grid coordinates where water can flow to both oceans.`, starterCode: { javascript: 'var pacificAtlantic = function(heights) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'heights = [[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]]', output: '[[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]]', params: [[[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]]], expected: [[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]] }], hiddenTestCases: [{ input: 'heights = [[2,1],[1,2]]', output: '[[0,0],[0,1],[1,0],[1,1]]', params: [[[2,1],[1,2]]], expected: [[0,0],[0,1],[1,0],[1,1]] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Perform DFS/BFS starting from the edges of the Pacific and Atlantic oceans. The intersection of cells reachable from both oceans is the answer.' } }, { id: 'number-of-islands', title: 'Number of Islands', difficulty: 'Medium', category: 'Graph', description: `Given 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.`, starterCode: { javascript: 'var numIslands = function(grid) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'grid = [["1","1","1","1","0"],["1","1","0","1","0"],["1","1","0","0","0"],["0","0","0","0","0"]]', output: '1', params: [[["1","1","1","1","0"],["1","1","0","1","0"],["1","1","0","0","0"],["0","0","0","0","0"]]], expected: 1 }], hiddenTestCases: [{ input: 'grid = [["1","1","0","0","0"],["1","1","0","0","0"],["0","0","1","0","0"],["0","0","0","1","1"]]', output: '3', params: [[["1","1","0","0","0"],["1","1","0","0","0"],["0","0","1","0","0"],["0","0","0","1","1"]]], expected: 3 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Iterate through each cell. When you find a "1", increment the count and perform DFS/BFS to mark all connected "1"s as visited.' } }, { id: 'longest-consecutive-sequence', title: 'Longest Consecutive Sequence', difficulty: 'Medium', category: 'Graph', description: `Given an unsorted array of integers \`nums\`, return the length of the longest consecutive elements sequence.`, starterCode: { javascript: 'var longestConsecutive = function(nums) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'nums = [100,4,200,1,3,2]', output: '4', params: [[100,4,200,1,3,2]], expected: 4 }], hiddenTestCases: [{ input: 'nums = [0,3,7,2,5,8,4,6,0,1]', output: '9', params: [[0,3,7,2,5,8,4,6,0,1]], expected: 9 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use a hash set for O(1) lookups. For each number, if it\'s the start of a sequence (i.e., num-1 is not in the set), count the length of the sequence.' } }, { id: 'alien-dictionary', title: 'Alien Dictionary', difficulty: 'Hard', category: 'Graph', description: `There is a new alien language that uses the English alphabet. However, the order among the letters is unknown to you. You are given a list of strings \`words\` from the alien language's dictionary, where the strings in \`words\` are sorted lexicographically by the rules of this new language.`, starterCode: { javascript: 'var alienOrder = function(words) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'words = ["wrt","wrf","er","ett","rftt"]', output: '"wertf"', params: [["wrt","wrf","er","ett","rftt"]], expected: "wertf" }], hiddenTestCases: [{ input: 'words = ["z","x"]', output: '"zx"', params: [["z","x"]], expected: "zx" }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Build a directed graph where an edge exists from char A to char B if A comes before B. Perform a topological sort on the graph.' } }, { id: 'graph-valid-tree', title: 'Graph Valid Tree', difficulty: 'Medium', category: 'Graph', description: `Given \`n\` nodes labeled from \`0\` to \`n-1\` and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.`, starterCode: { javascript: 'var validTree = function(n, edges) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'n = 5, edges = [[0,1],[0,2],[0,3],[1,4]]', output: 'true', params: [5, [[0,1],[0,2],[0,3],[1,4]]], expected: true }], hiddenTestCases: [{ input: 'n = 5, edges = [[0,1],[1,2],[2,3],[1,3],[1,4]]', output: 'false', params: [5, [[0,1],[1,2],[2,3],[1,3],[1,4]]], expected: false }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'A graph is a tree if it is connected and has no cycles. Use DFS/BFS or Union-Find to check these conditions.' } }, { id: 'reverse-linked-list', title: 'Reverse a Linked List', difficulty: 'Easy', category: 'Linked List', description: `Given the head of a singly linked list, reverse the list, and return the reversed list.`, starterCode: { javascript: 'var reverseList = function(head) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'head = [1,2,3,4,5]', output: '[5,4,3,2,1]', params: [[1,2,3,4,5]], expected: [5,4,3,2,1] }], hiddenTestCases: [{ input: 'head = [1,2]', output: '[2,1]', params: [[1,2]], expected: [2,1] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use three pointers: prev, curr, and next. Iterate through the list and reverse the pointers.' } }, { id: 'detect-loop-linked-list', title: 'Detect a Loop in Linked List', difficulty: 'Easy', category: 'Linked List', description: `Given head, the head of a linked list, determine if the linked list has a cycle in it.`, starterCode: { javascript: 'var hasCycle = function(head) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'head = [3,2,0,-4], pos = 1', output: 'true', params: [[3,2,0,-4], 1], expected: true }], hiddenTestCases: [{ input: 'head = [1], pos = -1', output: 'false', params: [[1], -1], expected: false }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use Floyd\'s Cycle-Finding Algorithm (tortoise and hare). If the fast pointer catches up to the slow pointer, a cycle exists.' } }, { id: 'merge-two-sorted-lists', title: 'Merge Two Sorted Lists', difficulty: 'Easy', category: 'Linked List', description: `Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists.`, starterCode: { javascript: 'var mergeTwoLists = function(list1, list2) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'list1 = [1,2,4], list2 = [1,3,4]', output: '[1,1,2,3,4,4]', params: [[1,2,4], [1,3,4]], expected: [1,1,2,3,4,4] }], hiddenTestCases: [{ input: 'list1 = [], list2 = [0]', output: '[0]', params: [[], [0]], expected: [0] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use a dummy head node and a current pointer. Compare the heads of the two lists and append the smaller one to the merged list.' } }, { id: 'merge-k-sorted-lists', title: 'Merge K Sorted Lists', difficulty: 'Hard', category: 'Linked List', description: `You are given an array of \`k\` linked-lists \`lists\`, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it.`, starterCode: { javascript: 'var mergeKLists = function(lists) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'lists = [[1,4,5],[1,3,4],[2,6]]', output: '[1,1,2,3,4,4,5,6]', params: [[[1,4,5],[1,3,4],[2,6]]], expected: [1,1,2,3,4,4,5,6] }], hiddenTestCases: [{ input: 'lists = []', output: '[]', params: [[]], expected: [] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use a min-priority queue to keep track of the heads of all lists. Alternatively, use a divide and conquer approach to merge lists in pairs.' } }, { id: 'remove-nth-node-from-back', title: 'Remove Nth Node From End of List', difficulty: 'Medium', category: 'Linked List', description: `Given the head of a linked list, remove the nth node from the end of the list and return its head.`, starterCode: { javascript: 'var removeNthFromEnd = function(head, n) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'head = [1,2,3,4,5], n = 2', output: '[1,2,3,5]', params: [[1,2,3,4,5], 2], expected: [1,2,3,5] }], hiddenTestCases: [{ input: 'head = [1], n = 1', output: '[]', params: [[1], 1], expected: [] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use two pointers: fast and slow. Move the fast pointer n steps ahead, then move both until fast reaches the end. The slow pointer will be at the node before the one to be removed.' } }, { id: 'set-matrix-zeroes', title: 'Set Matrix Zeroes', difficulty: 'Medium', category: 'Matrix', description: `Given an \`m x n\` integer matrix \`matrix\`, if an element is \`0\`, set its entire row and column to \`0\`'s. You must do it in place.`, starterCode: { javascript: 'var setZeroes = function(matrix) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'matrix = [[1,1,1],[1,0,1],[1,1,1]]', output: '[[1,0,1],[0,0,0],[1,0,1]]', params: [[[1,1,1],[1,0,1],[1,1,1]]], expected: [[1,0,1],[0,0,0],[1,0,1]] }], hiddenTestCases: [{ input: 'matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]', output: '[[0,0,0,0],[0,4,5,0],[0,3,1,0]]', params: [[[0,1,2,0],[3,4,5,2],[1,3,1,5]]], expected: [[0,0,0,0],[0,4,5,0],[0,3,1,0]] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use the first row and first column of the matrix as markers to indicate if that row or column should be zeroed.' } }, { id: 'spiral-matrix', title: 'Spiral Matrix', difficulty: 'Medium', category: 'Matrix', description: `Given an \`m x n\` matrix, return all elements of the matrix in spiral order.`, starterCode: { javascript: 'var spiralOrder = function(matrix) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'matrix = [[1,2,3],[4,5,6],[7,8,9]]', output: '[1,2,3,6,9,8,7,4,5]', params: [[[1,2,3],[4,5,6],[7,8,9]]], expected: [1,2,3,6,9,8,7,4,5] }], hiddenTestCases: [{ input: 'matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]', output: '[1,2,3,4,8,12,11,10,9,5,6,7]', params: [[[1,2,3,4],[5,6,7,8],[9,10,11,12]]], expected: [1,2,3,4,8,12,11,10,9,5,6,7] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Maintain four boundaries (top, bottom, left, right) and iterate in a spiral pattern, updating the boundaries as you go.' } }, { id: 'rotate-matrix', title: 'Rotate Image', difficulty: 'Medium', category: 'Matrix', description: `You are given an \`n x n\` 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place.`, starterCode: { javascript: 'var rotate = function(matrix) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'matrix = [[1,2,3],[4,5,6],[7,8,9]]', output: '[[7,4,1],[8,5,2],[9,6,3]]', params: [[[1,2,3],[4,5,6],[7,8,9]]], expected: [[7,4,1],[8,5,2],[9,6,3]] }], hiddenTestCases: [{ input: 'matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]', output: '[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]', params: [[[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]], expected: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Transpose the matrix (swap matrix[i][j] with matrix[j][i]) and then reverse each row.' } }, { id: 'max-depth-bt', title: 'Maximum Depth of Binary Tree', difficulty: 'Easy', category: 'Tree', description: `Given the root of a binary tree, return its maximum depth.`, starterCode: { javascript: 'var maxDepth = function(root) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'root = [3,9,20,null,null,15,7]', output: '3', params: [[3,9,20,null,null,15,7]], expected: 3 }], hiddenTestCases: [{ input: 'root = [1,null,2]', output: '2', params: [[1,null,2]], expected: 2 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use recursion: the depth of a tree is 1 + the maximum depth of its left and right subtrees.' } }, { id: 'identical-trees', title: 'Check if Two Trees are Identical', difficulty: 'Easy', category: 'Tree', description: `Given the roots of two binary trees \`p\` and \`q\`, write a function to check if they are the same or not.`, starterCode: { javascript: 'var isSameTree = function(p, q) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'p = [1,2,3], q = [1,2,3]', output: 'true', params: [[1,2,3], [1,2,3]], expected: true }], hiddenTestCases: [{ input: 'p = [1,2], q = [1,null,2]', output: 'false', params: [[1,2], [1,null,2]], expected: false }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Two trees are identical if their roots have the same value and their left and right subtrees are also identical.' } }, { id: 'invert-bt', title: 'Invert/Flip Binary Tree', difficulty: 'Easy', category: 'Tree', description: `Given the root of a binary tree, invert the tree, and return its root.`, starterCode: { javascript: 'var invertTree = function(root) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'root = [4,2,7,1,3,6,9]', output: '[4,7,2,9,6,3,1]', params: [[4,2,7,1,3,6,9]], expected: [4,7,2,9,6,3,1] }], hiddenTestCases: [{ input: 'root = [2,1,3]', output: '[2,3,1]', params: [[2,1,3]], expected: [2,3,1] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Swap the left and right children of each node recursively.' } }, { id: 'max-path-sum', title: 'Maximum Path Sum', difficulty: 'Hard', category: 'Tree', description: `A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. Find the maximum path sum of any non-empty path.`, starterCode: { javascript: 'var maxPathSum = function(root) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'root = [1,2,3]', output: '6', params: [[1,2,3]], expected: 6 }], hiddenTestCases: [{ input: 'root = [-10,9,20,null,null,15,7]', output: '42', params: [[-10,9,20,null,null,15,7]], expected: 42 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'For each node, calculate the maximum path sum passing through it (left gain + node value + right gain) and update a global maximum.' } }, { id: 'level-order-traversal', title: 'Level Order Traversal', difficulty: 'Medium', category: 'Tree', description: `Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).`, starterCode: { javascript: 'var levelOrder = function(root) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'root = [3,9,20,null,null,15,7]', output: '[[3],[9,20],[15,7]]', params: [[3,9,20,null,null,15,7]], expected: [[3],[9,20],[15,7]] }], hiddenTestCases: [{ input: 'root = [1]', output: '[[1]]', params: [[1]], expected: [[1]] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use a queue to perform a Breadth-First Search (BFS). For each level, process all nodes currently in the queue.' } }, { id: 'serialize-deserialize-bt', title: 'Serialize and De-serialize BT', difficulty: 'Hard', category: 'Tree', description: `Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer. Design an algorithm to serialize and deserialize a binary tree.`, starterCode: { javascript: 'var serialize = function(root) {\n \n};\nvar deserialize = function(data) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'root = [1,2,3,null,null,4,5]', output: '[1,2,3,null,null,4,5]', params: [[1,2,3,null,null,4,5]], expected: [1,2,3,null,null,4,5] }], hiddenTestCases: [{ input: 'root = []', output: '[]', params: [[]], expected: [] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use a pre-order traversal for serialization, marking null nodes with a special character. Use a queue for deserialization to reconstruct the tree.' } }, { id: 'longest-substring-without-repeating', title: 'Longest Substring Without Repeating Characters', difficulty: 'Medium', category: 'String', description: `Given a string \`s\`, find the length of the longest substring without repeating characters.`, starterCode: { javascript: 'var lengthOfLongestSubstring = function(s) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 's = "abcabcbb"', output: '3', params: ["abcabcbb"], expected: 3 }], hiddenTestCases: [{ input: 's = "bbbbb"', output: '1', params: ["bbbbb"], expected: 1 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use a sliding window with two pointers and a hash set or map to keep track of characters in the current window.' } }, { id: 'longest-repeating-character-replacement', title: 'Longest Repeating Character Replacement', difficulty: 'Medium', category: 'String', description: `You are given a string \`s\` and an integer \`k\`. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most \`k\` times.`, starterCode: { javascript: 'var characterReplacement = function(s, k) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 's = "ABAB", k = 2', output: '4', params: ["ABAB", 2], expected: 4 }], hiddenTestCases: [{ input: 's = "AABABBA", k = 1', output: '4', params: ["AABABBA", 1], expected: 4 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use a sliding window. The condition for a valid window is (window length - frequency of most frequent character <= k).' } }, { id: 'minimum-window-substring', title: 'Minimum Window Substring', difficulty: 'Hard', category: 'String', description: `Given two strings \`s\` and \`t\` of lengths \`m\` and \`n\` respectively, return the minimum window substring of \`s\` such that every character in \`t\` (including duplicates) is included in the window.`, starterCode: { javascript: 'var minWindow = function(s, t) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 's = "ADOBECODEBANC", t = "ABC"', output: '"BANC"', params: ["ADOBECODEBANC", "ABC"], expected: "BANC" }], hiddenTestCases: [{ input: 's = "a", t = "a"', output: '"a"', params: ["a", "a"], expected: "a" }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use a sliding window and two frequency maps. Expand the window until all characters of t are included, then contract it as much as possible.' } }, { id: 'valid-anagram', title: 'Valid Anagram', difficulty: 'Easy', category: 'String', description: `Given two strings \`s\` and \`t\`, return \`true\` if \`t\` is an anagram of \`s\`, and \`false\` otherwise.`, starterCode: { javascript: 'var isAnagram = function(s, t) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 's = "anagram", t = "nagaram"', output: 'true', params: ["anagram", "nagaram"], expected: true }], hiddenTestCases: [{ input: 's = "rat", t = "car"', output: 'false', params: ["rat", "car"], expected: false }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Two strings are anagrams if they have the same characters with the same frequencies. Use a frequency map or sort both strings.' } }, { id: 'group-anagrams', title: 'Group Words by Anagrams', difficulty: 'Medium', category: 'String', description: `Given an array of strings \`strs\`, group the anagrams together. You can return the answer in any order.`, starterCode: { javascript: 'var groupAnagrams = function(strs) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'strs = ["eat","tea","tan","ate","nat","bat"]', output: '[["bat"],["nat","tan"],["ate","eat","tea"]]', params: [["eat","tea","tan","ate","nat","bat"]], expected: [["bat"],["nat","tan"],["ate","eat","tea"]] }], hiddenTestCases: [{ input: 'strs = [""]', output: '[[""]]', params: [[""]], expected: [[""]] }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use a hash map where the key is the sorted version of the string (or a frequency count) and the value is a list of anagrams.' } }, { id: 'balanced-parenthesis', title: 'Balanced Paranthesis', difficulty: 'Easy', category: 'String', description: `Given a string \`s\` containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.`, starterCode: { javascript: 'var isValid = function(s) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 's = "()"', output: 'true', params: ["()"], expected: true }], hiddenTestCases: [{ input: 's = "()[]{}"', output: 'true', params: ["()[]{}"], expected: true }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Use a stack. For each opening bracket, push it onto the stack. For each closing bracket, check if it matches the top of the stack.' } }, { id: 'palindrome-number', title: 'Palindrome Number', difficulty: 'Easy', category: 'String', description: `Given an integer \`x\`, return \`true\` if \`x\` is a palindrome, and \`false\` otherwise.`, starterCode: { javascript: 'var isPalindrome = function(x) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 'x = 121', output: 'true', params: [121], expected: true }], hiddenTestCases: [{ input: 'x = -121', output: 'false', params: [-121], expected: false }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Reverse the second half of the number and compare it with the first half, or convert the number to a string and use two pointers.' } }, { id: 'longest-palindromic-substring', title: 'Longest Palindromic Substring', difficulty: 'Medium', category: 'String', description: `Given a string \`s\`, return the longest palindromic substring in \`s\`.`, starterCode: { javascript: 'var longestPalindrome = function(s) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 's = "babad"', output: '"bab"', params: ["babad"], expected: "bab" }], hiddenTestCases: [{ input: 's = "cbbd"', output: '"bb"', params: ["cbbd"], expected: "bb" }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Expand around each character (and each pair of adjacent characters) to find the longest palindrome centered at that position.' } }, { id: 'palindromic-substrings', title: 'Palindromic Substrings', difficulty: 'Medium', category: 'String', description: `Given a string \`s\`, return the number of palindromic substrings in it.`, starterCode: { javascript: 'var countSubstrings = function(s) {\n \n};', python: '', cpp: '', java: '', go: '' }, testCases: [{ input: 's = "abc"', output: '3', params: ["abc"], expected: 3 }], hiddenTestCases: [{ input: 's = "aaa"', output: '6', params: ["aaa"], expected: 6 }], solution: { javascript: '', python: '', cpp: '', java: '', go: '', explanation: 'Similar to finding the longest palindromic substring, expand around each center and count all palindromes found.' } } ];