Write a function that takes a string and returns it reversed. Examples: reverseStr("hello") => "olleh" reverseStr("world") => "dlrow" Constraints: - 0 <= s.length <= 10000
Return the number of vowels (a, e, i, o, u) in a string. Case-insensitive. Examples: countVowels("hello") => 2 countVowels("AEIOU") => 5 Constraints: - 0 <= s.length <= 10000
Write a function that capitalizes the first letter of a string and lowercases the rest. Examples: capitalizeFirst("hello") => "Hello" capitalizeFirst("WORLD") => "World" Constraints: - 0 <= s.length <= 10000
Check if a string is a palindrome (reads the same forwards and backwards). Consider only alphanumeric characters and ignore case. Examples: isPalindrome("racecar") => true isPalindrome("hello") => false Constraints: - 0 <= s.length <= 10000
Implement a stack data structure with push, pop, peek, and isEmpty methods. push(val) adds to top, pop() removes and returns top (return null if empty), peek() returns top without removing (return null if empty), isEmpty() returns boolean.
Implement a queue with enqueue, dequeue, front, and isEmpty methods. enqueue(val) adds to back, dequeue() removes and returns front (null if empty), front() returns front without removing (null if empty), isEmpty() returns boolean.
You start at the main folder. Given an array of operations: '../' moves to parent (stays if at main), './' stays in current, 'x/' moves to child folder named x. Return the minimum number of operations to go back to the main folder.
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. Use a hash map for O(n) time. Each input has exactly one solution, and you may not use the same element twice.
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Use a hash set for optimal performance.
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one using a hash set.
Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique. Result can be in any order.
Write a recursive function that computes the factorial of a non-negative integer n. n! = n * (n-1) * ... * 1, and 0! = 1.
Write a recursive function that returns the sum of the digits of a non-negative integer.
Write a recursive function that counts the number of digits in a non-negative integer.
Write a recursive function that returns the sum of all elements in an array. Do not use loops.
You are a parent and want to give cookies to children. Each child i has a greed factor g[i], and each cookie j has a size s[j]. A child is content if s[j] >= g[i]. Maximize the number of content children. Each child gets at most one cookie.
You are given boxTypes where boxTypes[i] = [numberOfBoxes_i, numberOfUnitsPerBox_i] and truckSize (max number of boxes). Choose boxes to maximize total units on the truck.
Given an array prices where prices[i] is the price of a stock on day i, find the maximum profit. You may buy and sell multiple times (buy before you sell again). You can only hold one share at a time.
At a lemonade stand, each lemonade costs $5. Customers pay with $5, $10, or $20. You must provide correct change. You start with no money. Return true if you can provide change for every customer.
Given n = 2, generate all combinations of well-formed parentheses. Return the result sorted lexicographically.
Given an integer array of unique elements, return all possible subsets (the power set). The solution must not contain duplicate subsets. Return subsets sorted by length, then lexicographically.
Given an array of distinct integers, return all possible permutations in any order.
Given an integer n, generate all binary strings of length n. Return them sorted lexicographically.
Given n, return the total number of subsets of a set with n elements. While the answer is 2^n, implement it by actually generating all subsets via backtracking and counting them.
Given an integer n, return true if n is even and false if n is odd. Use bitwise operations instead of the modulo operator.
Given an integer n and a position p (0-indexed from the right), return the bit value (0 or 1) at that position.
Given an integer n and a position p (0-indexed from the right), set the bit at that position to 1 and return the result.
Given an integer n and a position p (0-indexed from the right), clear (set to 0) the bit at that position and return the result.
Level 1-beginner. Given an m x n matrix, return its transpose. The transpose of a matrix flips it over its main diagonal, switching rows and columns.
Level 1-beginner. Given a square matrix, return the sum of both diagonals. If a cell is on both diagonals (center of odd-sized matrix), count it only once.