Sharpen your coding skills with real-world challenges. Earn points, climb the leaderboard, and become a top coder.
Total Challenges
Total Points Available
Active Competitors
Showing 18 challenges
Write a function to find all pairs of elements in an array such that their sum equals a target value. The function should return all pairs in a 2D array, where each pair is sorted in ascending order. If no such pair exists, return an empty array. For example, if the input array is [1, 2, 3, 4, 5] and the target value is 7, the function should return [[2, 5], [3, 4]] because 2 + 5 = 7 and 3 + 4 = 7.
Given an array of integers, find the smallest window that contains all elements in the array. The window is defined by its start and end indices. If there are multiple windows that contain all elements, return the one with the smallest end index. If no such window exists, return null. For example, if the input array is [1, 2, 3, 4, 5, 6] and the given array is [1, 4, 5], the smallest window is [4, 5]. Constraints: - The input array has a length between 1 and 1000. - The given array has a length between 1 and 10. - All elements in the input array are between 1 and 1000. - All elements in the given array are distinct and between 1 and 1000. Example: Input: [1, 2, 3, 4, 5, 6], [1, 4, 5] Output: [4, 5]
Write a function that finds the maximum sum of a subarray of a given array of integers. The function should return the maximum sum of a subarray. For example, given the array [-2, -3, 4, -1, -2, 1, 5, -3], the function should return 7, which is the maximum sum of the subarray [4, -1, -2, 1, 5].
Given an array of integers, determine the missing element in the sequence from 1 to n where n is the length of the array. If the array is not in ascending order or does not contain all integers from 1 to n, return -1. If the array contains all integers from 1 to n, return the length of the array. Example: Input: [4, 2, 3], Expected Output: 1.
Write a function that takes an array of integers as input and rotates it clockwise by one position. For example, if the input array is [1, 2, 3, 4, 5], the function should return [5, 1, 2, 3, 4]. The array can be of any size and may contain duplicate elements. You can assume that the input array is not empty. Provide examples of how your function works with different input arrays.
Given a 2D array of integers, write a function to flatten it into a single array. The function should not modify the original array. Examples: Input: [[1, 2], [3, 4], [5, 6]] Output: [1, 2, 3, 4, 5, 6] Constraints: The input array may be empty, and the sub-arrays may also be empty. The input will always be a 2D array.
Given an integer array, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. This is the classic Kadane's Algorithm problem.
Implement a binary search algorithm that takes a sorted array and a target value, and returns the index of the target if found, or -1 if not found.
Merge two sorted linked lists and return the merged list as a new sorted list. The new list should be made by splicing together the nodes of the first two lists.
Implement a binary search algorithm that takes a sorted array and a target value, and returns the index of the target if found, or -1 if not found.
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) as an array of arrays.
Given an m x n grid of characters and a string word, return true if the word exists in the grid. The word can be constructed from sequentially adjacent cells (horizontally or vertically), and each cell may only be used once.
Given an array of coin denominations and a total amount, return the fewest number of coins needed to make up that amount. Return -1 if it cannot be done.
Given a string s and a pattern p, implement regular expression matching with support for '.' and '*' where '.' matches any single character and '*' matches zero or more of the preceding element.
Given a string, return the string reversed.
Given a string, return the longest substring that is a palindrome.
You are given an array of k sorted linked lists. Merge them into one sorted linked list and return it.
Given an array of integers and a target sum, return the indices of the two numbers such that they add up to the target.