Showing 12 questions
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.
#1. Happy Number
Find the length of the longest valid (well-formed) parentheses substring within a string containing only '(' and ')' characters. A valid substring has correctly matched opening and closing parentheses.
#2. Longest Valid Parentheses
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. You need to implement a stack with an additional function to efficiently get the minimum value.
#3. Min Stack
Traverse a matrix diagonally, returning the elements in a specific zig-zag order. You'll need to manage the direction and boundaries to output the elements correctly.
#4. Diagonal Traverse
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#5. Valid Parentheses
You're given a flowerbed represented by an array of 0s and 1s, where 0 means empty and 1 means planted. Determine if you can plant a given number of new flowers without violating the rule that adjacent plots cannot be planted.
#6. Can Place Flowers
Find the contiguous subarray within a given array of numbers which has the largest sum. Return the sum of this subarray.
#7. Maximum Subarray
Given a sequence of numbers, find the next lexicographically greater permutation of the numbers. If no greater permutation exists, rearrange the numbers into the smallest possible permutation (ascending order).
#8. Next Permutation
You are given an array where each element represents your maximum jump length at that position. Determine if you can reach the last index starting from the first index.
#9. Jump Game
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#10. Longest Substring Without Repeating Characters
Maximize your profit by buying and selling a stock multiple times. You're given an array representing stock prices, and can make as many transactions as you want.
#11. Best Time to Buy and Sell Stock II
Design a graph data structure that allows you to add edges and calculate the shortest path between any two nodes. Implement a shortest path algorithm to efficiently find the minimum distance.
#12. Design Graph With Shortest Path Calculator