Showing 1125 questions
Given a string with parentheses, determine the minimum number of parentheses you must remove to make the string valid. A valid string has balanced and properly nested parentheses.
#1. Minimum Remove to Make Valid Parentheses
Determine if a given abbreviation is valid for a given word. An abbreviation can contain digits representing the number of skipped characters.
#2. Valid Word Abbreviation
Traverse a binary tree and return a list of node values for each vertical line, ordered from left to right. Nodes on the same vertical line should be ordered from top to bottom.
#3. Binary Tree Vertical Order Traversal
Determine if a string is a palindrome after removing at most one character. Consider both left and right removals when checking for palindrome validity.
#4. Valid Palindrome II
Find the lowest common ancestor of two nodes in a binary tree where each node has a parent pointer. You're given the two nodes directly, not the root of the tree.
#5. Lowest Common Ancestor of a Binary Tree III
Find the kth largest element in an unsorted array. Note that it is the kth largest element in sorted order, not the kth distinct element.
#6. Kth Largest Element in an Array
Find the lowest common ancestor of two nodes in a given binary tree. The lowest common ancestor is defined as the farthest node from the root that is an ancestor of both nodes.
#7. Lowest Common Ancestor of a Binary Tree
Given a binary tree, imagine you are standing on the right side of it. Return the values of the nodes you can see, ordered from top to bottom.
#8. Binary Tree Right Side View
Implement a basic calculator to evaluate a simple expression string. The expression can contain non-negative integers, '+', '-', '*', '/' operators, and spaces; integer division should truncate toward zero.
#9. Basic Calculator II
You're given an array representing weights. Implement a function to randomly pick an index from the array, where the probability of picking each index is proportional to its weight.
#10. Random Pick with Weight
You are given a nested list of integers where each integer has a depth. Calculate the weighted sum of all integers in the list, where the weight of an integer is its depth within the nested structure.
#11. Nested List Weight Sum
Find a peak element in an array, where a peak is greater than its neighbors. You only need to return the index of any one peak element if multiple exist.
#12. Find Peak Element
Imagine a binary tree where each path from the root to a leaf represents a number. Calculate the sum of all these root-to-leaf numbers.
#13. Sum Root to Leaf Numbers
Find the longest path between any two nodes in a binary tree. The path may or may not pass through the root.
#14. Diameter of Binary Tree
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#15. Merge Intervals
Find the k most frequent elements in a given array of numbers. Return the top k elements based on their frequency.
#16. Top K Frequent Elements
Rearrange the characters of a given string according to a custom order defined by another string. If a character isn't in the custom order, place it at the end in any order.
#17. Custom Sort String
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.
#18. Two Sum
Calculate x raised to the power of n. Be mindful of potential edge cases and optimize for efficiency, as a naive approach might not be sufficient.
#19. Pow(x, n)
You are given k sorted lists. Combine all of their elements into a single sorted list and return it.
#20. Merge k Sorted Lists