Showing 20 questions
Given a sequence of words and a line width, format the text to fit within the specified width. You must justify the text, distributing extra spaces evenly between words.
#1. Text Justification
You are given an array of positive integers. Determine if you can transform an initial array of all ones into the target array by repeatedly replacing an element with the sum of all elements in the array.
#2. Construct Target Array With Multiple Sums
Calculate the product and sum of the digits of a given integer. Then, return the difference between the product and the sum.
#3. Subtract the Product and Sum of Digits of an Integer
Simulate seating students in an exam room, maximizing the distance between them. Implement methods to seat a student and release a seat, tracking the occupied seats over time.
#4. Exam Room
You're given a non-negative integer. Encode it using a special binary representation based on its position in a sequence of numbers formed by powers of two.
#5. Encode Number
You're given a matrix of numbers. Sort each of its diagonals in ascending order.
#6. Sort the Matrix Diagonally
Given an array, efficiently determine how many times a specific value appears within a given range of indices. You'll need to handle multiple queries with different ranges and values.
#7. Range Frequency Queries
You are given a string of text and a string of broken letters on a keyboard. Determine the maximum number of words from the text that you can fully type without using any broken letters.
#8. Maximum Number of Words You Can Type
You're given a sequence of bits representing characters, where each character is either one or two bits long. Determine if the sequence ends with a one-bit character.
#9. 1-bit and 2-bit Characters
Given a list of numbers and a target sum, find two numbers in the list that add up to the target. Return the indices of these two numbers.
#10. Finding Pairs With a Certain Sum
Find all rhombus shapes within a given grid of numbers. Return the three largest distinct sums of the numbers forming those rhombus shapes.
#11. Get Biggest Three Rhombus Sums in a Grid
Given an integer, determine how many of its substrings of length 'k' are divisors of the number represented by the substring. Return the count of these 'k-beautiful' substrings.
#12. Find the K-Beauty of a Number
Find the number of triplets in an array that sum to a target value, considering that the array may contain duplicate numbers. You need to count the multiplicity of each triplet combination.
#13. 3Sum With Multiplicity
Find the number of substrings of length three in a given string that contain only distinct characters (no repeating characters).
#14. Substrings of Size Three with Distinct Characters
Determine how many numbers in a given array have an even number of digits. Return the count of these numbers.
#15. Find Numbers with Even Number of Digits
Find the longest string that is a prefix of all strings in a given array. If no common prefix exists, return an empty string.
#16. Longest Common Prefix
Design a data structure that supports insertion, deletion, and random element retrieval, all in constant time on average. You'll need to handle edge cases carefully to achieve O(1) complexity.
#17. Insert Delete GetRandom O(1)
Find the number of contiguous subarrays within a given array where the maximum element in each subarray falls within a specified lower and upper bound.
#18. Number of Subarrays with Bounded Maximum
Determine the total number of continuous subarrays within a given array that sum up to a specific target value, k.
#19. Subarray Sum Equals K
You are given a binary tree. Place cameras on some nodes such that all nodes are either covered by a camera on itself, or on one of its parents or children. Minimize the number of cameras used.
#20. Binary Tree Cameras