Showing 12 questions
Compress a given string by replacing consecutive repeating characters with the character followed by the count of repetitions. If the compressed string isn't shorter, return the original.
#1. String Compression
Design an algorithm to encode a list of strings into a single string and then decode the single string back to the original list of strings.
#2. Encode and Decode Strings
Design a key-value store that supports storing values associated with timestamps. You should be able to retrieve the value for a given key at the latest timestamp less than or equal to a given time.
#3. Time Based Key-Value Store
Given an array representing the height of bars, calculate how much water can be trapped between them after rain. Think about finding the maximum height to the left and right of each bar.
#4. Trapping Rain Water
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#5. Merge Intervals
Given an array, rearrange it so that all zeros are moved to the end while maintaining the relative order of the non-zero elements.
#6. Move Zeroes
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#7. Valid Parentheses
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#8. Number of Islands
Determine if it is possible to finish all courses given prerequisites. Some courses must be taken before others; can you find a valid order?
#9. Course Schedule
You're given a sorted array of integers. Return a new array containing the squares of each number, also sorted in non-decreasing order.
#10. Squares of a Sorted Array
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.
#11. Best Time to Buy and Sell Stock
Traverse a given matrix in a spiral pattern, returning all elements in the order you visit them. Essentially, walk around the matrix layer by layer, adding elements to a list.
#12. Spiral Matrix