Showing 134 questions
Find the longest sequence of consecutive 1s in a binary array. Return the maximum number of consecutive 1s.
#1. Max Consecutive Ones
Find two numbers in a given array that add up to a specific target value, and return their indices. Essentially, you need to efficiently locate the pair that satisfies the sum requirement.
#2. Two Sum
You're given daily stock prices. Find the maximum profit you can make by buying and selling the stock once. You must buy before you sell.
#3. Best Time to Buy and Sell Stock
Find the contiguous subarray within a given array of numbers which has the largest sum. Return the sum of this subarray.
#4. Maximum Subarray
Determine whether an integer is a palindrome. That is, it reads the same forwards and backward.
#5. Palindrome Number
You are climbing a staircase with n steps. Find how many distinct ways you can climb to the top, given that you can climb one or two steps at a time.
#6. Climbing Stairs
Determine the minimum number of character swaps required to make two strings permutations of each other. You're essentially figuring out how much the character frequencies differ between the strings.
#7. Permutation Difference between Two Strings
Given an array, rotate the elements to the right by a specified number of steps. The goal is to modify the original array in-place with the rotated elements.
#8. Rotate Array
You're given a list of rectangles. Find the rectangle with the longest diagonal, and return its area. If there's a tie for longest diagonal, return the maximum area among those rectangles.
#9. Maximum Area of Longest Diagonal Rectangle
Find the smallest number whose digits' product equals a given target number, and all its digits are divisible by a given divisor.
#10. Smallest Divisible Digit Product II
You're given a list of numbers. By deleting a number, you earn its value, but you must also delete all numbers one less and one greater than it. Maximize the total earned value.
#11. Delete and Earn
Find the element that appears more than n/2 times in a given array of size n. Essentially, you need to identify the majority element.
#12. Majority Element
Given an integer n, find the smallest positive integer whose digits, when multiplied together, equal n. If no such integer exists, return -1.
#13. Smallest Divisible Digit Product I
You're given an array of numbers. Calculate the sum of the array elements whose index, when converted to binary, has exactly 'k' set bits (1s).
#14. Sum of Values at Indices With K Set Bits
Determine if a number is a 'happy number'. A happy number eventually reaches 1 when replaced by the sum of the squares of its digits, repeating the process until it does.
#15. Happy Number
Given a list of non-negative integers, arrange them such that they form the largest possible number. Return the largest number as a string.
#16. Largest Number
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#17. Longest Substring Without Repeating Characters
Given an array of numbers, find a subsequence of a specific length that has the largest possible sum. Return the indices of the elements in that subsequence.
#18. Find Subsequence of Length K With the Largest Sum
Determine the minimum number of right shift operations needed to sort a given array in non-decreasing order. If the array cannot be sorted by right shifts, return -1.
#19. Minimum Right Shifts to Sort the Array
Imagine an ant moving on a number line. Given a series of movements, determine how many times the ant returns to its starting position (the boundary).
#20. Ant on the Boundary