1039 data structures and algorithms questions1039 Interview Questions
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.
#1. Two Sum
Given a set of distinct integers, your task is to generate all possible subsets (the power set). The solution should not contain duplicate subsets.
#2. Subsets
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#3. Longest Substring Without Repeating Characters
Find all unique triplets in an array that sum to zero. You'll need to consider the potential for duplicate numbers and avoid duplicate triplets in your solution.
#4. 3Sum
Reverse the digits of a given 32-bit signed integer. Handle potential overflow by returning 0 if the reversed value is outside the valid range.
#5. Reverse Integer
Convert a given integer into its Roman numeral representation. You need to understand the mapping between integer values and Roman symbols to perform the conversion accurately.
#6. Integer to Roman
You're given a non-negative integer represented as an array of digits. Add one to the integer and return the updated array.
#7. Plus One
Determine whether an integer is a palindrome. That is, it reads the same forwards and backward.
#8. Palindrome Number
Determine if a target value exists within a sorted 2D matrix. The matrix is sorted row-wise and column-wise, offering opportunities for efficient searching.
#9. Search a 2D Matrix
Given a non-negative integer, you can swap two of its digits at most once. Find the largest possible resulting number after performing this swap.
#10. Maximum Swap
You are given an array of fruits represented by characters. Find the longest subarray that contains at most two types of fruits.
#11. Fruit Into Baskets
Calculate the span of a stock's price for each day, defined as the maximum consecutive days (including the current day) the price was less than or equal to today's price. Implement a data structure to efficiently compute these spans as new stock prices arrive online.
#12. Online Stock Span
Find the median of two sorted arrays. The arrays can be of different sizes, and you should aim for an efficient solution.
#13. Median of Two Sorted Arrays
You're given a sorted array that has been rotated, and a target value. Find the index of the target value in the rotated array, or return -1 if it's not present.
#14. Search in Rotated Sorted Array
Given a sorted array, remove the duplicate elements in-place such that each unique element appears only once. Return the new length of the array.
#15. Remove Duplicates from Sorted Array
You are given a list of events with start times, end times, and values. Determine the maximum total value you can obtain by attending at most 'k' events, without any overlapping events.
#16. Maximum Number of Events That Can Be Attended II
You are given a circular route with gas stations. Determine if you can complete the circuit, starting from a particular station, given the gas available and cost to travel between stations.
#17. Gas Station
You are given a square matrix representing an image. Rotate the image by 90 degrees clockwise in-place.
#18. Rotate Image
Find the longest palindromic substring within a given string. A palindromic substring reads the same forwards and backward.
#19. Longest Palindromic Substring
Write a function that returns the string 'Hello, World!'. This is a classic first coding challenge.
#20. Create Hello World Function