diff --git a/scripts/populate.py b/scripts/populate.py new file mode 100644 index 0000000000..ddb2d9a2e7 --- /dev/null +++ b/scripts/populate.py @@ -0,0 +1,85 @@ +import json +import requests +import time +from typing import Dict, List +import os + +# Configuration +API_URL = "http://localhost:8001/api/v1/questions" # Update this with your actual API endpoint +QUESTIONS_FILE = "questions.json" +PROGRESS_FILE = "population_progress.json" +# Add your JWT token here +JWT_TOKEN = "" # Replace with actual admin JWT token + +def load_questions() -> List[Dict]: + """Load questions from JSON file.""" + with open(QUESTIONS_FILE, 'r') as f: + return json.load(f) + +def format_question(question: Dict) -> Dict: + """Format question data for API payload.""" + return { + "difficulty": question["difficulty"], + "description": question["description"], + "examples": question["examples"], + "constraints": question["constraints"], + "tags": question["tags"], + "title_slug": question["title-slug"], + "title": question["title"] + } + +def load_progress() -> List[str]: + """Load previously populated question titles.""" + if os.path.exists(PROGRESS_FILE): + with open(PROGRESS_FILE, 'r') as f: + return json.load(f) + return [] + +def save_progress(completed_questions: List[str]): + """Save progress of populated questions.""" + with open(PROGRESS_FILE, 'w') as f: + json.dump(completed_questions, f) + +def populate_questions(): + """Main function to populate questions.""" + questions = load_questions() + completed_questions = load_progress() + success_count = 0 + failure_count = 0 + + headers = { + 'Content-Type': 'application/json', + 'Authorization': f'Bearer {JWT_TOKEN}' + } + + remaining_questions = [q for q in questions if q['title'] not in completed_questions] + print(f"Found {len(remaining_questions)} questions to process") + print(f"Skipping {len(completed_questions)} previously completed questions") + + for question in remaining_questions: + try: + payload = format_question(question) + response = requests.post(API_URL, json=payload, headers=headers) + + if response.status_code == 201 or response.status_code == 200: + print(f"✅ Successfully added question: {question['title']}") + completed_questions.append(question['title']) + save_progress(completed_questions) # Save progress after each successful addition + success_count += 1 + else: + print(f"❌ Failed to add question: {question['title']}") + print(f"Status code: {response.status_code}") + print(f"Response: {response.text}") + failure_count += 1 + + except Exception as e: + print(f"❌ Error adding question {question['title']}: {str(e)}") + failure_count += 1 + + print("\nPopulation complete!") + print(f"Successfully added: {success_count} questions") + print(f"Failed to add: {failure_count} questions") + print(f"Total questions processed so far: {len(completed_questions)}") + +if __name__ == "__main__": + populate_questions() diff --git a/scripts/population_progress.json b/scripts/population_progress.json new file mode 100644 index 0000000000..cf0a8de546 --- /dev/null +++ b/scripts/population_progress.json @@ -0,0 +1 @@ +["Palindrome Number", "Roman to Integer", "Longest Common Prefix", "Valid Parentheses", "Merge Two Sorted Lists", "Remove Duplicates from Sorted Array", "Remove Element", "Find the Index of the First Occurrence in a String", "Search Insert Position", "Length of Last Word", "Plus One", "Add Binary", "Sqrt(x)", "Climbing Stairs", "Remove Duplicates from Sorted List", "Merge Sorted Array", "Binary Tree Inorder Traversal", "Same Tree", "Symmetric Tree", "Maximum Depth of Binary Tree", "Convert Sorted Array to Binary Search Tree", "Balanced Binary Tree", "Minimum Depth of Binary Tree", "Path Sum", "Pascal's Triangle", "Pascal's Triangle II", "Best Time to Buy and Sell Stock", "Valid Palindrome", "Single Number", "Linked List Cycle", "Binary Tree Preorder Traversal", "Binary Tree Postorder Traversal", "Intersection of Two Linked Lists", "Excel Sheet Column Title", "Majority Element", "Excel Sheet Column Number", "Reverse Bits", "Number of 1 Bits", "Happy Number", "Remove Linked List Elements", "Isomorphic Strings", "Reverse Linked List", "Contains Duplicate", "Contains Duplicate II", "Count Complete Tree Nodes", "Invert Binary Tree", "Summary Ranges", "Power of Two", "Implement Queue using Stacks", "Palindrome Linked List", "Valid Anagram", "Binary Tree Paths", "Add Digits", "Ugly Number", "Missing Number", "First Bad Version", "Move Zeroes", "Word Pattern", "Nim Game", "Range Sum Query - Immutable", "Power of Three", "Counting Bits", "Power of Four", "Reverse String", "Reverse Vowels of a String", "Intersection of Two Arrays", "Intersection of Two Arrays II", "Valid Perfect Square", "Guess Number Higher or Lower", "Ransom Note", "First Unique Character in a String", "Find the Difference", "Is Subsequence", "Binary Watch", "Sum of Left Leaves", "Convert a Number to Hexadecimal", "Longest Palindrome", "Fizz Buzz", "Third Maximum Number", "Add Strings", "Number of Segments in a String", "Arranging Coins", "Find All Numbers Disappeared in an Array", "Assign Cookies", "Repeated Substring Pattern", "Hamming Distance", "Island Perimeter", "Number Complement", "License Key Formatting", "Max Consecutive Ones", "Construct the Rectangle", "Teemo Attacking", "Next Greater Element I", "Keyboard Row", "Find Mode in Binary Search Tree", "Base 7", "Relative Ranks", "Perfect Number", "Add Two Numbers", "Longest Substring Without Repeating Characters", "Median of Two Sorted Arrays", "Longest Palindromic Substring", "Zigzag Conversion", "Reverse Integer", "String to Integer (atoi)", "Regular Expression Matching", "Container With Most Water", "Integer to Roman", "3Sum", "3Sum Closest", "Letter Combinations of a Phone Number", "4Sum", "Remove Nth Node From End of List", "Generate Parentheses", "Merge k Sorted Lists", "Swap Nodes in Pairs", "Reverse Nodes in k-Group", "Divide Two Integers", "Substring with Concatenation of All Words", "Next Permutation", "Longest Valid Parentheses", "Search in Rotated Sorted Array", "Find First and Last Position of Element in Sorted Array", "Valid Sudoku", "Sudoku Solver", "Count and Say", "Combination Sum", "Combination Sum II", "First Missing Positive", "Trapping Rain Water", "Multiply Strings", "Wildcard Matching", "Jump Game II", "Permutations", "Permutations II", "Rotate Image", "Group Anagrams", "Pow(x, n)", "N-Queens", "N-Queens II", "Maximum Subarray", "Spiral Matrix", "Jump Game", "Merge Intervals", "Insert Interval", "Spiral Matrix II", "Permutation Sequence", "Rotate List", "Unique Paths", "Unique Paths II", "Minimum Path Sum", "Valid Number", "Text Justification", "Simplify Path", "Edit Distance", "Set Matrix Zeroes", "Search a 2D Matrix", "Sort Colors", "Minimum Window Substring", "Combinations", "Subsets", "Word Search", "Remove Duplicates from Sorted Array II", "Search in Rotated Sorted Array II", "Remove Duplicates from Sorted List II", "Largest Rectangle in Histogram", "Maximal Rectangle", "Partition List", "Scramble String", "Gray Code", "Subsets II", "Decode Ways", "Reverse Linked List II", "Restore IP Addresses", "Unique Binary Search Trees II", "Unique Binary Search Trees", "Interleaving String", "Validate Binary Search Tree", "Recover Binary Search Tree", "Binary Tree Level Order Traversal", "Binary Tree Zigzag Level Order Traversal", "Construct Binary Tree from Preorder and Inorder Traversal", "Construct Binary Tree from Inorder and Postorder Traversal", "Binary Tree Level Order Traversal II", "Convert Sorted List to Binary Search Tree", "Path Sum II", "Flatten Binary Tree to Linked List", "Distinct Subsequences", "Populating Next Right Pointers in Each Node", "Populating Next Right Pointers in Each Node II", "Triangle", "Best Time to Buy and Sell Stock II", "Best Time to Buy and Sell Stock III", "Binary Tree Maximum Path Sum", "Word Ladder II", "Word Ladder", "Longest Consecutive Sequence", "Sum Root to Leaf Numbers", "Surrounded Regions", "Palindrome Partitioning", "Palindrome Partitioning II", "Clone Graph", "Gas Station", "Candy", "Single Number II", "Copy List with Random Pointer", "Word Break", "Word Break II", "Linked List Cycle II", "Reorder List", "LRU Cache", "Insertion Sort List", "Sort List", "Max Points on a Line", "Evaluate Reverse Polish Notation", "Reverse Words in a String", "Maximum Product Subarray", "Find Minimum in Rotated Sorted Array", "Find Minimum in Rotated Sorted Array II", "Min Stack", "Find Peak Element", "Maximum Gap", "Compare Version Numbers", "Fraction to Recurring Decimal", "Two Sum II - Input Array Is Sorted", "Factorial Trailing Zeroes", "Binary Search Tree Iterator", "Dungeon Game", "Largest Number", "Repeated DNA Sequences", "Best Time to Buy and Sell Stock IV", "Rotate Array", "House Robber", "Binary Tree Right Side View", "Number of Islands", "Bitwise AND of Numbers Range", "Count Primes", "Course Schedule", "Implement Trie (Prefix Tree)", "Minimum Size Subarray Sum", "Course Schedule II", "Design Add and Search Words Data Structure", "Word Search II", "House Robber II", "Shortest Palindrome", "Kth Largest Element in an Array", "Combination Sum III", "The Skyline Problem", "Contains Duplicate III", "Maximal Square", "Rectangle Area", "Basic Calculator", "Basic Calculator II", "Majority Element II", "Kth Smallest Element in a BST", "Number of Digit One", "Lowest Common Ancestor of a Binary Search Tree", "Lowest Common Ancestor of a Binary Tree", "Delete Node in a Linked List", "Product of Array Except Self", "Sliding Window Maximum", "Search a 2D Matrix II", "Different Ways to Add Parentheses", "Single Number III", "Ugly Number II", "Integer to English Words", "H-Index", "H-Index II", "Perfect Squares", "Expression Add Operators", "Peeking Iterator", "Find the Duplicate Number", "Game of Life", "Find Median from Data Stream", "Serialize and Deserialize Binary Tree", "Bulls and Cows", "Longest Increasing Subsequence", "Remove Invalid Parentheses", "Range Sum Query 2D - Immutable", "Additive Number", "Range Sum Query - Mutable", "Best Time to Buy and Sell Stock with Cooldown", "Minimum Height Trees", "Burst Balloons", "Super Ugly Number", "Count of Smaller Numbers After Self", "Remove Duplicate Letters", "Maximum Product of Word Lengths", "Bulb Switcher", "Create Maximum Number", "Coin Change", "Wiggle Sort II", "Count of Range Sum", "Odd Even Linked List", "Longest Increasing Path in a Matrix", "Patching Array", "Verify Preorder Serialization of a Binary Tree", "Reconstruct Itinerary", "Increasing Triplet Subsequence", "Self Crossing", "Palindrome Pairs", "House Robber III", "Flatten Nested List Iterator", "Integer Break", "Top K Frequent Elements", "Data Stream as Disjoint Intervals", "Russian Doll Envelopes", "Design Twitter", "Count Numbers with Unique Digits", "Max Sum of Rectangle No Larger Than K", "Water and Jug Problem", "Largest Divisible Subset", "Sum of Two Integers", "Super Pow", "Find K Pairs with Smallest Sums", "Guess Number Higher or Lower II", "Wiggle Subsequence", "Combination Sum IV", "Kth Smallest Element in a Sorted Matrix", "Insert Delete GetRandom O(1)", "Insert Delete GetRandom O(1) - Duplicates allowed", "Linked List Random Node", "Shuffle an Array", "Mini Parser", "Lexicographical Numbers", "Longest Absolute File Path", "Elimination Game", "Perfect Rectangle", "UTF-8 Validation", "Decode String", "Longest Substring with At Least K Repeating Characters", "Rotate Function", "Integer Replacement", "Random Pick Index", "Evaluate Division", "Nth Digit", "Remove K Digits", "Frog Jump", "Queue Reconstruction by Height", "Trapping Rain Water II", "Split Array Largest Sum", "Arithmetic Slices", "Partition Equal Subset Sum", "Pacific Atlantic Water Flow", "Battleships in a Board", "Strong Password Checker", "Maximum XOR of Two Numbers in an Array", "Reconstruct Original Digits from English", "Longest Repeating Character Replacement", "Construct Quad Tree", "N-ary Tree Level Order Traversal", "Flatten a Multilevel Doubly Linked List", "All O`one Data Structure", "Minimum Genetic Mutation", "Non-overlapping Intervals", "Find Right Interval", "Path Sum III", "Find All Anagrams in a String", "K-th Smallest in Lexicographical Order", "Find All Duplicates in an Array", "String Compression", "Add Two Numbers II", "Arithmetic Slices II - Subsequence", "Number of Boomerangs", "Serialize and Deserialize BST", "Delete Node in a BST", "Sort Characters By Frequency", "Minimum Number of Arrows to Burst Balloons", "Minimum Moves to Equal Array Elements", "4Sum II", "132 Pattern", "Circular Array Loop", "Poor Pigs", "LFU Cache", "Minimum Moves to Equal Array Elements II", "Can I Win", "Count The Repetitions", "Unique Substrings in Wraparound String", "Validate IP Address", "Implement Rand10() Using Rand7()", "Concatenated Words", "Matchsticks to Square", "Ones and Zeroes", "Heaters", "Total Hamming Distance", "Generate Random Point in a Circle", "Largest Palindrome Product", "Sliding Window Median", "Magical String", "Smallest Good Base", "Predict the Winner", "Zuma Game", "Non-decreasing Subsequences", "Reverse Pairs", "Target Sum", "Random Point in Non-overlapping Rectangles", "Diagonal Traverse", "IPO", "Next Greater Element II", "Most Frequent Subtree Sum", "Fibonacci Number", "Find Bottom Left Tree Value", "Freedom Trail", "Find Largest Value in Each Tree Row", "Longest Palindromic Subsequence", "Super Washing Machines", "Coin Change II", "Random Flip Matrix", "Detect Capital", "Longest Uncommon Subsequence I", "Longest Uncommon Subsequence II", "Continuous Subarray Sum", "Longest Word in Dictionary through Deleting", "Contiguous Array", "Beautiful Arrangement", "Random Pick with Weight", "Minesweeper", "Minimum Absolute Difference in BST", "K-diff Pairs in an Array", "Encode and Decode TinyURL", "Complex Number Multiplication", "Convert BST to Greater Tree", "Minimum Time Difference", "Single Element in a Sorted Array", "Reverse String II", "01 Matrix", "Diameter of Binary Tree", "Remove Boxes", "Number of Provinces", "Student Attendance Record I", "Student Attendance Record II", "Optimal Division", "Brick Wall", "Next Greater Element III", "Reverse Words in a String III", "Logical OR of Two Binary Grids Represented as Quad-Trees", "Maximum Depth of N-ary Tree", "Subarray Sum Equals K", "Array Partition", "Binary Tree Tilt", "Find the Closest Palindrome", "Array Nesting", "Reshape the Matrix", "Permutation in String", "Subtree of Another Tree", "Distribute Candies", "Out of Boundary Paths", "Shortest Unsorted Continuous Subarray", "Delete Operation for Two Strings", "Erect the Fence", "N-ary Tree Preorder Traversal", "N-ary Tree Postorder Traversal", "Tag Validator", "Fraction Addition and Subtraction", "Valid Square", "Longest Harmonious Subsequence", "Range Addition II", "Minimum Index Sum of Two Lists", "Non-negative Integers without Consecutive Ones", "Can Place Flowers", "Construct String from Binary Tree", "Find Duplicate File in System", "Valid Triangle Number", "Merge Two Binary Trees", "Task Scheduler", "Design Circular Queue", "Add One Row to Tree", "Maximum Product of Three Numbers", "K Inverse Pairs Array", "Course Schedule III", "Smallest Range Covering Elements from K Lists", "Sum of Square Numbers", "Exclusive Time of Functions", "Average of Levels in Binary Tree", "Shopping Offers", "Decode Ways II", "Solve the Equation", "Design Circular Deque", "Maximum Average Subarray I", "Set Mismatch", "Maximum Length of Pair Chain", "Palindromic Substrings", "Replace Words", "Dota2 Senate", "2 Keys Keyboard", "Find Duplicate Subtrees", "Two Sum IV - Input is a BST", "Maximum Binary Tree", "Print Binary Tree", "Robot Return to Origin", "Find K Closest Elements", "Split Array into Consecutive Subsequences", "Image Smoother", "Maximum Width of Binary Tree", "Strange Printer", "Non-decreasing Array", "Beautiful Arrangement II", "Kth Smallest Number in Multiplication Table", "Trim a Binary Search Tree", "Maximum Swap", "Second Minimum Node In a Binary Tree", "Bulb Switcher II", "Number of Longest Increasing Subsequence", "Longest Continuous Increasing Subsequence", "Cut Off Trees for Golf Event", "Implement Magic Dictionary", "Map Sum Pairs", "Valid Parenthesis String", "24 Game", "Valid Palindrome II", "Baseball Game", "Redundant Connection", "Redundant Connection II", "Repeated String Match", "Longest Univalue Path", "Knight Probability in Chessboard", "Maximum Sum of 3 Non-Overlapping Subarrays", "Employee Importance", "Stickers to Spell Word", "Top K Frequent Words", "Binary Number with Alternating Bits", "Max Area of Island", "Count Binary Substrings", "Degree of an Array", "Partition to K Equal Sum Subsets", "Falling Squares", "Search in a Binary Search Tree", "Insert into a Binary Search Tree", "Kth Largest Element in a Stream", "Binary Search", "Design HashSet", "Design HashMap", "Design Linked List", "To Lower Case", "Random Pick with Blacklist", "Minimum ASCII Delete Sum for Two Strings", "Subarray Product Less Than K", "Best Time to Buy and Sell Stock with Transaction Fee", "Range Module", "1-bit and 2-bit Characters", "Maximum Length of Repeated Subarray", "Find K-th Smallest Pair Distance", "Longest Word in Dictionary", "Accounts Merge", "Remove Comments", "Find Pivot Index", "Split Linked List in Parts", "Number of Atoms", "Self Dividing Numbers", "My Calendar I", "Count Different Palindromic Subsequences", "My Calendar II", "My Calendar III", "Flood Fill", "Asteroid Collision", "Parse Lisp Expression", "Monotone Increasing Digits", "Daily Temperatures", "Delete and Earn", "Cherry Pickup", "Network Delay Time", "Find Smallest Letter Greater Than Target", "Prefix and Suffix Search", "Min Cost Climbing Stairs", "Largest Number At Least Twice of Others", "Shortest Completing Word", "Contain Virus", "Open the Lock", "Cracking the Safe", "Reach a Number", "Pyramid Transition Matrix", "Set Intersection Size At Least Two", "Special Binary String", "Prime Number of Set Bits in Binary Representation", "Partition Labels", "Largest Plus Sign", "Couples Holding Hands", "Toeplitz Matrix", "Reorganize String", "Max Chunks To Make Sorted II", "Max Chunks To Make Sorted", "Basic Calculator IV", "Jewels and Stones", "Sliding Puzzle", "Global and Local Inversions", "Swap Adjacent in LR String", "Swim in Rising Water", "K-th Symbol in Grammar", "Reaching Points", "Rabbits in Forest", "Transform to Chessboard", "Minimum Distance Between BST Nodes", "Letter Case Permutation", "Is Graph Bipartite?", "K-th Smallest Prime Fraction", "Cheapest Flights Within K Stops", "Rotated Digits", "Escape The Ghosts", "Domino and Tromino Tiling", "Custom Sort String", "Number of Matching Subsequences", "Preimage Size of Factorial Zeroes Function", "Valid Tic-Tac-Toe State", "Number of Subarrays with Bounded Maximum", "Rotate String", "All Paths From Source to Target", "Smallest Rotation with Highest Score", "Champagne Tower", "Minimum Swaps To Make Sequences Increasing", "Find Eventual Safe States", "Bricks Falling When Hit", "Unique Morse Code Words", "Split Array With Same Average", "Number of Lines To Write String", "Max Increase to Keep City Skyline", "Soup Servings", "Expressive Words", "Chalkboard XOR Game", "Subdomain Visit Count", "Largest Triangle Area", "Largest Sum of Averages", "Binary Tree Pruning", "Bus Routes", "Ambiguous Coordinates", "Linked List Components", "Race Car", "Most Common Word", "Short Encoding of Words", "Shortest Distance to a Character", "Card Flipping Game", "Binary Trees With Factors", "Goat Latin", "Friends Of Appropriate Ages", "Most Profit Assigning Work", "Making A Large Island", "Count Unique Characters of All Substrings of a Given String", "Consecutive Numbers Sum", "Positions of Large Groups", "Masking Personal Information", "Flipping an Image", "Find And Replace in String", "Sum of Distances in Tree", "Image Overlap", "Rectangle Overlap", "New 21 Game", "Push Dominoes", "Similar String Groups", "Magic Squares In Grid", "Keys and Rooms", "Split Array into Fibonacci Sequence", "Guess the Word", "Backspace String Compare", "Longest Mountain in Array", "Hand of Straights", "Shortest Path Visiting All Nodes", "Shifting Letters", "Maximize Distance to Closest Person", "Rectangle Area II", "Loud and Rich", "Peak Index in a Mountain Array", "Car Fleet", "K-Similar Strings", "Exam Room", "Score of Parentheses", "Minimum Cost to Hire K Workers", "Mirror Reflection", "Buddy Strings", "Lemonade Change", "Score After Flipping Matrix", "Shortest Subarray with Sum at Least K", "All Nodes Distance K in Binary Tree", "Shortest Path to Get All Keys", "Smallest Subtree with all the Deepest Nodes", "Prime Palindrome", "Transpose Matrix", "Binary Gap", "Reordered Power of 2", "Advantage Shuffle", "Minimum Number of Refueling Stops", "Leaf-Similar Trees", "Length of Longest Fibonacci Subsequence", "Walking Robot Simulation", "Koko Eating Bananas", "Middle of the Linked List", "Stone Game", "Nth Magical Number", "Profitable Schemes", "Decoded String at Index", "Boats to Save People", "Reachable Nodes In Subdivided Graph", "Projection Area of 3D Shapes", "Uncommon Words from Two Sentences", "Spiral Matrix III", "Possible Bipartition", "Super Egg Drop", "Fair Candy Swap", "Construct Binary Tree from Preorder and Postorder Traversal", "Find and Replace Pattern", "Sum of Subsequence Widths", "Surface Area of 3D Shapes", "Groups of Special-Equivalent Strings", "All Possible Full Binary Trees", "Maximum Frequency Stack", "Monotonic Array", "Increasing Order Search Tree", "Bitwise ORs of Subarrays", "Orderly Queue", "RLE Iterator", "Online Stock Span", "Numbers At Most N Given Digit Set", "Valid Permutations for DI Sequence", "Fruit Into Baskets", "Sort Array By Parity", "Super Palindromes", "Sum of Subarray Minimums", "Smallest Range I", "Snakes and Ladders", "Smallest Range II", "Online Election", "Sort an Array", "Cat and Mouse", "X of a Kind in a Deck of Cards", "Partition Array into Disjoint Intervals", "Word Subsets", "Reverse Only Letters", "Maximum Sum Circular Subarray", "Complete Binary Tree Inserter", "Number of Music Playlists", "Minimum Add to Make Parentheses Valid", "Sort Array By Parity II", "3Sum With Multiplicity", "Minimize Malware Spread", "Long Pressed Name", "Flip String to Monotone Increasing", "Three Equal Parts", "Minimize Malware Spread II", "Unique Email Addresses", "Binary Subarrays With Sum", "Minimum Falling Path Sum", "Beautiful Array", "Number of Recent Calls", "Shortest Bridge", "Knight Dialer", "Stamping The Sequence", "Reorder Data in Log Files", "Range Sum of BST", "Minimum Area Rectangle", "Distinct Subsequences II", "Valid Mountain Array", "DI String Match", "Find the Shortest Superstring", "Delete Columns to Make Sorted", "Minimum Increment to Make Array Unique", "Validate Stack Sequences", "Most Stones Removed with Same Row or Column", "Bag of Tokens", "Largest Time for Given Digits", "Reveal Cards In Increasing Order", "Flip Equivalent Binary Trees", "Largest Component Size by Common Factor", "Verifying an Alien Dictionary", "Array of Doubled Pairs", "Delete Columns to Make Sorted II", "Tallest Billboard", "Prison Cells After N Days", "Check Completeness of a Binary Tree", "Regions Cut By Slashes", "Delete Columns to Make Sorted III", "N-Repeated Element in Size 2N Array", "Maximum Width Ramp", "Minimum Area Rectangle II", "Least Operators to Express Number", "Univalued Binary Tree", "Vowel Spellchecker", "Numbers With Same Consecutive Differences", "Binary Tree Cameras", "Pancake Sorting", "Powerful Integers", "Flip Binary Tree To Match Preorder Traversal", "Equal Rational Numbers", "K Closest Points to Origin", "Subarray Sums Divisible by K", "Odd Even Jump", "Largest Perimeter Triangle", "Squares of a Sorted Array", "Longest Turbulent Subarray", "Distribute Coins in Binary Tree", "Unique Paths III", "Time Based Key-Value Store", "Triples with Bitwise AND Equal To Zero", "Minimum Cost For Tickets", "String Without AAA or BBB", "Sum of Even Numbers After Queries", "Interval List Intersections", "Vertical Order Traversal of a Binary Tree", "Smallest String Starting From Leaf", "Add to Array-Form of Integer", "Satisfiability of Equality Equations", "Broken Calculator", "Subarrays with K Different Integers", "Cousins in Binary Tree", "Rotting Oranges", "Minimum Number of K Consecutive Bit Flips", "Number of Squareful Arrays", "Find the Town Judge", "Maximum Binary Tree II", "Available Captures for Rook", "Minimum Cost to Merge Stones", "Grid Illumination", "Find Common Characters", "Check If Word Is Valid After Substitutions", "Max Consecutive Ones III", "Maximize Sum Of Array After K Negations", "Clumsy Factorial", "Minimum Domino Rotations For Equal Row", "Construct Binary Search Tree from Preorder Traversal", "Complement of Base 10 Integer", "Pairs of Songs With Total Durations Divisible by 60", "Capacity To Ship Packages Within D Days", "Numbers With Repeated Digits", "Partition Array Into Three Parts With Equal Sum", "Best Sightseeing Pair", "Smallest Integer Divisible by K", "Binary String With Substrings Representing 1 To N", "Convert to Base -2", "Binary Prefix Divisible By 5", "Next Greater Node In Linked List", "Number of Enclaves", "Remove Outermost Parentheses", "Sum of Root To Leaf Binary Numbers", "Camelcase Matching", "Video Stitching", "Divisor Game", "Maximum Difference Between Node and Ancestor", "Longest Arithmetic Subsequence", "Recover a Tree From Preorder Traversal", "Two City Scheduling", "Matrix Cells in Distance Order", "Maximum Sum of Two Non-Overlapping Subarrays", "Stream of Characters", "Moving Stones Until Consecutive", "Coloring A Border", "Uncrossed Lines", "Escape a Large Maze", "Valid Boomerang", "Binary Search Tree to Greater Sum Tree", "Minimum Score Triangulation of Polygon", "Moving Stones Until Consecutive II", "Robot Bounded In Circle", "Flower Planting With No Adjacent", "Partition Array for Maximum Sum", "Longest Duplicate Substring", "Last Stone Weight", "Remove All Adjacent Duplicates In String", "Longest String Chain", "Last Stone Weight II", "Height Checker", "Grumpy Bookstore Owner", "Previous Permutation With One Swap", "Distant Barcodes", "Lexicographically Smallest Equivalent String", "Greatest Common Divisor of Strings", "Flip Columns For Maximum Number of Equal Rows", "Adding Two Negabinary Numbers", "Number of Submatrices That Sum to Target", "Occurrences After Bigram", "Letter Tile Possibilities", "Insufficient Nodes in Root to Leaf Paths", "Smallest Subsequence of Distinct Characters", "Duplicate Zeros", "Largest Values From Labels", "Shortest Path in Binary Matrix", "Shortest Common Supersequence ", "Statistics from a Large Sample", "Car Pooling", "Find in Mountain Array", "Brace Expansion II", "Distribute Candies to People", "Path In Zigzag Labelled Binary Tree", "Filling Bookcase Shelves", "Parsing A Boolean Expression", "Defanging an IP Address", "Corporate Flight Bookings", "Delete Nodes And Return Forest", "Maximum Nesting Depth of Two Valid Parentheses Strings", "Relative Sort Array", "Lowest Common Ancestor of Deepest Leaves", "Longest Well-Performing Interval", "Smallest Sufficient Team", "Number of Equivalent Domino Pairs", "Shortest Path with Alternating Colors", "Minimum Cost Tree From Leaf Values", "Maximum of Absolute Value Expression", "N-th Tribonacci Number", "Alphabet Board Path", "Largest 1-Bordered Square", "Stone Game II", "Longest Common Subsequence", "Decrease Elements To Make Array Zigzag", "Binary Tree Coloring Game", "Snapshot Array", "Longest Chunked Palindrome Decomposition", "Day of the Year", "Number of Dice Rolls With Target Sum", "Swap For Longest Repeated Character Substring", "Online Majority Element In Subarray", "Find Words That Can Be Formed by Characters", "Maximum Level Sum of a Binary Tree", "As Far from Land as Possible", "Last Substring in Lexicographical Order", "Invalid Transactions", "Compare Strings by Frequency of the Smallest Character", "Remove Zero Sum Consecutive Nodes from Linked List", "Dinner Plate Stacks", "Prime Arrangements", "Can Make Palindrome from Substring", "Number of Valid Words for Each Puzzle", "Distance Between Bus Stops", "Day of the Week", "Maximum Subarray Sum with One Deletion", "Make Array Strictly Increasing", "Maximum Number of Balloons", "Reverse Substrings Between Each Pair of Parentheses", "K-Concatenation Maximum Sum", "Critical Connections in a Network", "Minimum Absolute Difference", "Ugly Number III", "Smallest String With Swaps", "Sort Items by Groups Respecting Dependencies", "Design Skiplist", "Unique Number of Occurrences", "Get Equal Substrings Within Budget", "Remove All Adjacent Duplicates in String II", "Minimum Moves to Reach Target with Rotations", "Minimum Cost to Move Chips to The Same Position", "Longest Arithmetic Subsequence of Given Difference", "Path with Maximum Gold", "Count Vowels Permutation", "Split a String in Balanced Strings", "Queens That Can Attack the King", "Dice Roll Simulation", "Maximum Equal Frequency", "Airplane Seat Assignment Probability", "Check If It Is a Straight Line", "Remove Sub-Folders from the Filesystem", "Replace the Substring for Balanced String", "Maximum Profit in Job Scheduling", "Find Positive Integer Solution for a Given Equation", "Circular Permutation in Binary Representation", "Maximum Length of a Concatenated String with Unique Characters", "Tiling a Rectangle with the Fewest Squares", "Minimum Swaps to Make Strings Equal", "Count Number of Nice Subarrays", "Minimum Remove to Make Valid Parentheses", "Check If It Is a Good Array", "Cells with Odd Values in a Matrix", "Reconstruct a 2-Row Binary Matrix", "Number of Closed Islands", "Maximum Score Words Formed by Letters", "Shift 2D Grid", "Find Elements in a Contaminated Binary Tree", "Greatest Sum Divisible by Three", "Minimum Moves to Move a Box to Their Target Location", "Minimum Time Visiting All Points", "Count Servers that Communicate", "Search Suggestions System", "Number of Ways to Stay in the Same Place After Some Steps", "Find Winner on a Tic Tac Toe Game", "Number of Burgers with No Waste of Ingredients", "Count Square Submatrices with All Ones", "Palindrome Partitioning III", "Subtract the Product and Sum of Digits of an Integer", "Group the People Given the Group Size They Belong To", "Find the Smallest Divisor Given a Threshold", "Minimum Number of Flips to Convert Binary Matrix to Zero Matrix", "Iterator for Combination", "Element Appearing More Than 25% In Sorted Array", "Remove Covered Intervals", "Minimum Falling Path Sum II", "Convert Binary Number in a Linked List to Integer", "Sequential Digits", "Maximum Side Length of a Square with Sum Less than or Equal to Threshold", "Shortest Path in a Grid with Obstacles Elimination", "Find Numbers with Even Number of Digits", "Divide Array in Sets of K Consecutive Numbers", "Maximum Number of Occurrences of a Substring", "Maximum Candies You Can Get from Boxes", "Replace Elements with Greatest Element on Right Side", "Sum of Mutated Array Closest to Target", "Number of Paths with Max Score", "Deepest Leaves Sum", "Find N Unique Integers Sum up to Zero", "All Elements in Two Binary Search Trees", "Jump Game III", "Verbal Arithmetic Puzzle", "Decrypt String from Alphabet to Integer Mapping", "XOR Queries of a Subarray", "Get Watched Videos by Your Friends", "Minimum Insertion Steps to Make a String Palindrome", "Decompress Run-Length Encoded List", "Matrix Block Sum", "Sum of Nodes with Even-Valued Grandparent", "Distinct Echo Substrings", "Convert Integer to the Sum of Two No-Zero Integers", "Minimum Flips to Make a OR b Equal to c", "Number of Operations to Make Network Connected", "Minimum Distance to Type a Word Using Two Fingers", "Maximum 69 Number", "Print Words Vertically", "Delete Leaves With a Given Value", "Minimum Number of Taps to Open to Water a Garden", "Break a Palindrome", "Sort the Matrix Diagonally", "Reverse Subarray To Maximize Array Value", "Rank Transform of an Array", "Remove Palindromic Subsequences", "Filter Restaurants by Vegan-Friendly, Price and Distance", "Find the City With the Smallest Number of Neighbors at a Threshold Distance", "Minimum Difficulty of a Job Schedule", "The K Weakest Rows in a Matrix", "Reduce Array Size to The Half", "Maximum Product of Splitted Binary Tree", "Jump Game V", "Number of Steps to Reduce a Number to Zero", "Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold", "Angle Between Hands of a Clock", "Jump Game IV", "Check If N and Its Double Exist", "Minimum Number of Steps to Make Two Strings Anagram", "Tweet Counts Per Frequency", "Maximum Students Taking Exam", "Count Negative Numbers in a Sorted Matrix", "Product of the Last K Numbers", "Maximum Number of Events That Can Be Attended", "Construct Target Array With Multiple Sums", "Sort Integers by The Number of 1 Bits", "Apply Discount Every n Orders", "Number of Substrings Containing All Three Characters", "Count All Valid Pickup and Delivery Options", "Number of Days Between Two Dates", "Validate Binary Tree Nodes", "Closest Divisors", "Largest Multiple of Three", "How Many Numbers Are Smaller Than the Current Number", "Rank Teams by Votes", "Linked List in Binary Tree", "Minimum Cost to Make at Least One Valid Path in a Grid", "Increasing Decreasing String", "Find the Longest Substring Containing Vowels in Even Counts", "Longest ZigZag Path in a Binary Tree", "Maximum Sum BST in Binary Tree", "Generate a String With Characters That Have Odd Counts", "Number of Times Binary String Is Prefix-Aligned", "Time Needed to Inform All Employees", "Frog Position After T Seconds", "Find a Corresponding Node of a Binary Tree in a Clone of That Tree", "Lucky Numbers in a Matrix", "Design a Stack With Increment Operation", "Balance a Binary Search Tree", "Maximum Performance of a Team", "Find the Distance Value Between Two Arrays", "Cinema Seat Allocation", "Sort Integers by The Power Value", "Pizza With 3n Slices", "Create Target Array in the Given Order", "Four Divisors", "Check if There is a Valid Path in a Grid", "Longest Happy Prefix", "Find Lucky Integer in an Array", "Count Number of Teams", "Design Underground System", "Find All Good Strings", "Count Largest Group", "Construct K Palindrome Strings", "Circle and Rectangle Overlapping", "Reducing Dishes", "Minimum Subsequence in Non-Increasing Order", "Number of Steps to Reduce a Number in Binary Representation to One", "Longest Happy String", "Stone Game III", "String Matching in an Array", "Queries on a Permutation With Key", "HTML Entity Parser", "Number of Ways to Paint N \u00d7 3 Grid", "Minimum Value to Get Positive Step by Step Sum", "Find the Minimum Number of Fibonacci Numbers Whose Sum Is K", "The k-th Lexicographical String of All Happy Strings of Length n", "Restore The Array", "Reformat The String", "Display Table of Food Orders in a Restaurant", "Minimum Number of Frogs Croaking", "Build Array Where You Can Find The Maximum Exactly K Comparisons", "Maximum Score After Splitting a String", "Maximum Points You Can Obtain from Cards", "Diagonal Traverse II", "Constrained Subsequence Sum", "Kids With the Greatest Number of Candies", "Max Difference You Can Get From Changing an Integer", "Check If a String Can Break Another String", "Number of Ways to Wear Different Hats to Each Other", "Destination City", "Check If All 1's Are at Least Length K Places Away", "Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit", "Find the Kth Smallest Sum of a Matrix With Sorted Rows", "Build an Array With Stack Operations", "Count Triplets That Can Form Two Arrays of Equal XOR", "Minimum Time to Collect All Apples in a Tree", "Number of Ways of Cutting a Pizza", "Consecutive Characters", "Simplified Fractions", "Count Good Nodes in Binary Tree", "Form Largest Integer With Digits That Add up to Target", "Number of Students Doing Homework at a Given Time", "Rearrange Words in a Sentence", "People Whose List of Favorite Companies Is Not a Subset of Another List", "Maximum Number of Darts Inside of a Circular Dartboard", "Check If a Word Occurs As a Prefix of Any Word in a Sentence", "Maximum Number of Vowels in a Substring of Given Length", "Pseudo-Palindromic Paths in a Binary Tree", "Max Dot Product of Two Subsequences", "Make Two Arrays Equal by Reversing Subarrays", "Check If a String Contains All Binary Codes of Size K", "Course Schedule IV", "Cherry Pickup II", "Maximum Product of Two Elements in an Array", "Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts", "Reorder Routes to Make All Paths Lead to the City Zero", "Probability of a Two Boxes Having The Same Number of Distinct Balls", "Shuffle the Array", "The k Strongest Values in an Array", "Design Browser History", "Paint House III", "Final Prices With a Special Discount in a Shop", "Subrectangle Queries", "Find Two Non-overlapping Sub-arrays Each With Target Sum", "Allocate Mailboxes", "Running Sum of 1d Array", "Least Number of Unique Integers after K Removals", "Minimum Number of Days to Make m Bouquets", "Kth Ancestor of a Tree Node", "XOR Operation in an Array", "Making File Names Unique", "Avoid Flood in The City", "Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree", "Average Salary Excluding the Minimum and Maximum Salary", "The kth Factor of n", "Longest Subarray of 1's After Deleting One Element", "Parallel Courses II", "Path Crossing", "Check If Array Pairs Are Divisible by k", "Number of Subsequences That Satisfy the Given Sum Condition", "Max Value of Equation", "Can Make Arithmetic Progression From Sequence", "Last Moment Before All Ants Fall Out of a Plank", "Count Submatrices With All Ones", "Minimum Possible Integer After at Most K Adjacent Swaps On Digits", "Reformat Date", "Range Sum of Sorted Subarray Sums", "Minimum Difference Between Largest and Smallest Value in Three Moves", "Stone Game IV", "Number of Good Pairs", "Number of Substrings With Only 1s", "Path with Maximum Probability", "Best Position for a Service Centre", "Water Bottles", "Number of Nodes in the Sub-Tree With the Same Label", "Maximum Number of Non-Overlapping Substrings", "Find a Value of a Mysterious Function Closest to Target", "Count Odd Numbers in an Interval Range", "Number of Sub-arrays With Odd Sum", "Number of Good Ways to Split a String", "Minimum Number of Increments on Subarrays to Form a Target Array", "Shuffle String", "Minimum Suffix Flips", "Number of Good Leaf Nodes Pairs", "String Compression II", "Count Good Triplets", "Find the Winner of an Array Game", "Minimum Swaps to Arrange a Binary Grid", "Get the Maximum Score", "Kth Missing Positive Number", "Can Convert String in K Moves", "Minimum Insertions to Balance a Parentheses String", "Find Longest Awesome Substring", "Make The String Great", "Find Kth Bit in Nth Binary String", "Maximum Number of Non-Overlapping Subarrays With Sum Equals Target", "Minimum Cost to Cut a Stick", "Three Consecutive Odds", "Minimum Operations to Make Array Equal", "Magnetic Force Between Two Balls", "Minimum Number of Days to Eat N Oranges", "Thousand Separator", "Minimum Number of Vertices to Reach All Nodes", "Minimum Numbers of Function Calls to Make Target Array", "Detect Cycles in 2D Grid", "Most Visited Sector in a Circular Track", "Maximum Number of Coins You Can Get", "Find Latest Group of Size M", "Stone Game V", "Detect Pattern of Length M Repeated K or More Times", "Maximum Length of Subarray With Positive Product", "Minimum Number of Days to Disconnect Island", "Number of Ways to Reorder Array to Get Same BST", "Matrix Diagonal Sum", "Number of Ways to Split a String", "Shortest Subarray to be Removed to Make Array Sorted", "Count All Possible Routes", "Replace All ?'s to Avoid Consecutive Repeating Characters", "Number of Ways Where Square of Number Is Equal to Product of Two Numbers", "Minimum Time to Make Rope Colorful", "Remove Max Number of Edges to Keep Graph Fully Traversable", "Special Positions in a Binary Matrix", "Count Unhappy Friends", "Min Cost to Connect All Points", "Check If String Is Transformable With Substring Sort Operations", "Sum of All Odd Length Subarrays", "Maximum Sum Obtained of Any Permutation", "Make Sum Divisible by P", "Strange Printer II", "Rearrange Spaces Between Words", "Split a String Into the Max Number of Unique Substrings", "Maximum Non Negative Product in a Matrix", "Minimum Cost to Connect Two Groups of Points", "Crawler Log Folder", "Maximum Profit of Operating a Centennial Wheel", "Throne Inheritance", "Maximum Number of Achievable Transfer Requests", "Design Parking System", "Alert Using Same Key-Card Three or More Times in a One Hour Period", "Find Valid Matrix Given Row and Column Sums", "Find Servers That Handled Most Number of Requests", "Special Array With X Elements Greater Than or Equal X", "Even Odd Tree", "Maximum Number of Visible Points", "Minimum One Bit Operations to Make Integers Zero", "Maximum Nesting Depth of the Parentheses", "Maximal Network Rank", "Split Two Strings to Make Palindrome", "Count Subtrees With Max Distance Between Cities", "Mean of Array After Removing Some Elements", "Coordinate With Maximum Network Quality", "Number of Sets of K Non-Overlapping Line Segments", "Fancy Sequence", "Largest Substring Between Two Equal Characters", "Lexicographically Smallest String After Applying Operations", "Best Team With No Conflicts", "Graph Connectivity With Threshold", "Slowest Key", "Arithmetic Subarrays", "Path With Minimum Effort", "Rank Transform of a Matrix", "Sort Array by Increasing Frequency", "Widest Vertical Area Between Two Points Containing No Points", "Count Substrings That Differ by One Character", "Number of Ways to Form a Target String Given a Dictionary", "Check Array Formation Through Concatenation", "Count Sorted Vowel Strings", "Furthest Building You Can Reach", "Kth Smallest Instructions", "Get Maximum in Generated Array", "Minimum Deletions to Make Character Frequencies Unique", "Sell Diminishing-Valued Colored Balls", "Create Sorted Array through Instructions", "Defuse the Bomb", "Minimum Deletions to Make String Balanced", "Minimum Jumps to Reach Home", "Distribute Repeating Integers", "Design an Ordered Stream", "Determine if Two Strings Are Close", "Minimum Operations to Reduce X to Zero", "Maximize Grid Happiness", "Check If Two String Arrays are Equivalent", "Smallest String With A Given Numeric Value", "Ways to Make a Fair Array", "Minimum Initial Energy to Finish Tasks", "Maximum Repeating Substring", "Merge In Between Linked Lists", "Design Front Middle Back Queue", "Minimum Number of Removals to Make Mountain Array", "Richest Customer Wealth", "Find the Most Competitive Subsequence", "Minimum Moves to Make Array Complementary", "Minimize Deviation in Array", "Goal Parser Interpretation", "Max Number of K-Sum Pairs", "Concatenation of Consecutive Binary Numbers", "Minimum Incompatibility", "Count the Number of Consistent Strings", "Sum of Absolute Differences in a Sorted Array", "Stone Game VI", "Delivering Boxes from Storage to Ports", "Count of Matches in Tournament", "Partitioning Into Minimum Number Of Deci-Binary Numbers", "Stone Game VII", "Maximum Height by Stacking Cuboids ", "Reformat Phone Number", "Maximum Erasure Value", "Jump Game VI", "Checking Existence of Edge Length Limited Paths", "Average Waiting Time", "Maximum Binary String After Change", "Minimum Adjacent Swaps for K Consecutive Ones", "Determine if String Halves Are Alike", "Maximum Number of Eaten Apples", "Where Will the Ball Fall", "Maximum XOR With an Element From Array", "Maximum Units on a Truck", "Count Good Meals", "Ways to Split Array Into Three Subarrays", "Minimum Operations to Make a Subsequence", "Calculate Money in Leetcode Bank", "Maximum Score From Removing Substrings", "Construct the Lexicographically Largest Valid Sequence", "Number Of Ways To Reconstruct A Tree", "Decode XORed Array", "Swapping Nodes in a Linked List", "Minimize Hamming Distance After Swap Operations", "Find Minimum Time to Finish All Jobs", "Number Of Rectangles That Can Form The Largest Square", "Tuple with Same Product", "Largest Submatrix With Rearrangements", "Cat and Mouse II", "Find the Highest Altitude", "Minimum Number of People to Teach", "Decode XORed Permutation", "Count Ways to Make Array With Product", "Latest Time by Replacing Hidden Digits", "Change Minimum Characters to Satisfy One of Three Conditions", "Find Kth Largest XOR Coordinate Value", "Building Boxes", "Maximum Number of Balls in a Box", "Restore the Array From Adjacent Pairs", "Can You Eat Your Favorite Candy on Your Favorite Day?", "Palindrome Partitioning IV", "Sum of Unique Elements", "Maximum Absolute Sum of Any Subarray", "Minimum Length of String After Deleting Similar Ends", "Maximum Number of Events That Can Be Attended II", "Check if Array Is Sorted and Rotated", "Maximum Score From Removing Stones", "Largest Merge Of Two Strings", "Closest Subsequence Sum", "Minimum Changes To Make Alternating Binary String", "Count Number of Homogenous Substrings", "Minimum Limit of Balls in a Bag", "Minimum Degree of a Connected Trio in a Graph", "Longest Nice Substring", "Form Array by Concatenating Subarrays of Another Array", "Map of Highest Peak", "Tree of Coprimes", "Merge Strings Alternately", "Minimum Number of Operations to Move All Balls to Each Box", "Maximum Score from Performing Multiplication Operations", "Maximize Palindrome Length From Subsequences", "Count Items Matching a Rule", "Closest Dessert Cost", "Equal Sum Arrays With Minimum Number of Operations", "Car Fleet II", "Find Nearest Point That Has the Same X or Y Coordinate", "Check if Number is a Sum of Powers of Three", "Sum of Beauty of All Substrings", "Count Pairs Of Nodes", "Check if Binary String Has at Most One Segment of Ones", "Minimum Elements to Add to Form a Given Sum", "Number of Restricted Paths From First to Last Node", "Make the XOR of All Segments Equal to Zero", "Check if One String Swap Can Make Strings Equal", "Find Center of Star Graph", "Maximum Average Pass Ratio", "Maximum Score of a Good Subarray", "Second Largest Digit in a String", "Design Authentication Manager", "Maximum Number of Consecutive Values You Can Make", "Maximize Score After N Operations", "Maximum Ascending Subarray Sum", "Number of Orders in the Backlog", "Maximum Value at a Given Index in a Bounded Array", "Count Pairs With XOR in a Range", "Number of Different Integers in a String", "Minimum Number of Operations to Reinitialize a Permutation", "Evaluate the Bracket Pairs of a String", "Maximize Number of Nice Divisors", "Determine Color of a Chessboard Square", "Sentence Similarity III", "Count Nice Pairs in an Array", "Maximum Number of Groups Getting Fresh Donuts", "Truncate Sentence", "Finding the Users Active Minutes", "Minimum Absolute Sum Difference", "Number of Different Subsequences GCDs", "Sign of the Product of an Array", "Find the Winner of the Circular Game", "Minimum Sideway Jumps", "Finding MK Average", "Minimum Operations to Make the Array Increasing", "Queries on Number of Points Inside a Circle", "Maximum XOR for Each Query", "Minimum Number of Operations to Make String Sorted", "Check if the Sentence Is Pangram", "Maximum Ice Cream Bars", "Single-Threaded CPU", "Find XOR Sum of All Pairs Bitwise AND", "Sum of Digits in Base K", "Frequency of the Most Frequent Element", "Longest Substring Of All Vowels in Order", "Maximum Building Height", "Replace All Digits with Characters", "Seat Reservation Manager", "Maximum Element After Decreasing and Rearranging", "Closest Room", "Minimum Distance to the Target Element", "Splitting a String Into Descending Consecutive Values", "Minimum Adjacent Swaps to Reach the Kth Smallest Number", "Minimum Interval to Include Each Query", "Maximum Population Year", "Maximum Distance Between a Pair of Values", "Maximum Subarray Min-Product", "Largest Color Value in a Directed Graph", "Sorting the Sentence", "Incremental Memory Leak", "Rotating the Box", "Sum of Floored Pairs", "Sum of All Subset XOR Totals", "Minimum Number of Swaps to Make the Binary String Alternating", "Finding Pairs With a Certain Sum", "Number of Ways to Rearrange Sticks With K Sticks Visible", "Longer Contiguous Segments of Ones than Zeros", "Minimum Speed to Arrive on Time", "Jump Game VII", "Stone Game VIII", "Substrings of Size Three with Distinct Characters", "Minimize Maximum Pair Sum in Array", "Get Biggest Three Rhombus Sums in a Grid", "Minimum XOR Sum of Two Arrays", "Check if Word Equals Summation of Two Words", "Maximum Value after Insertion", "Process Tasks Using Servers", "Minimum Skips to Arrive at Meeting On Time", "Egg Drop With 2 Eggs and N Floors", "Determine Whether Matrix Can Be Obtained By Rotation", "Reduction Operations to Make the Array Elements Equal", "Minimum Number of Flips to Make the Binary String Alternating", "Minimum Space Wasted From Packaging", "Check if All the Integers in a Range Are Covered", "Find the Student that Will Replace the Chalk", "Largest Magic Square", "Minimum Cost to Change the Final Value of Expression", "Redistribute Characters to Make All Strings Equal", "Maximum Number of Removable Characters", "Merge Triplets to Form Target Triplet", "The Earliest and Latest Rounds Where Players Compete", "Find a Peak Element II", "Largest Odd Number in String", "The Number of Full Rounds You Have Played", "Count Sub Islands", "Minimum Absolute Difference Queries", "Remove One Element to Make the Array Strictly Increasing", "Remove All Occurrences of a Substring", "Maximum Alternating Subsequence Sum", "Design Movie Rental System", "Maximum Product Difference Between Two Pairs", "Cyclically Rotating a Grid", "Number of Wonderful Substrings", "Count Ways to Build Rooms in an Ant Colony", "Build Array from Permutation", "Eliminate Maximum Number of Monsters", "Count Good Numbers", "Longest Common Subpath", "Count Square Sum Triples", "Nearest Exit from Entrance in Maze", "Sum Game", "Minimum Cost to Reach Destination in Time", "Concatenation of Array", "Unique Length-3 Palindromic Subsequences", "Painting a Grid With Three Different Colors", "Merge BSTs to Create Single BST", "Maximum Number of Words You Can Type", "Add Minimum Number of Rungs", "Maximum Number of Points with Cost", "Maximum Genetic Difference Query", "Check if All Characters Have Equal Number of Occurrences", "The Number of the Smallest Unoccupied Chair", "Describe the Painting", "Number of Visible People in a Queue", "Sum of Digits of String After Convert", "Largest Number After Mutating Substring", "Maximum Compatibility Score Sum", "Delete Duplicate Folders in System", "Three Divisors", "Maximum Number of Weeks for Which You Can Work", "Minimum Garden Perimeter to Collect Enough Apples", "Count Number of Special Subsequences", "Delete Characters to Make Fancy String", "Check if Move is Legal", "Minimum Total Space Wasted With K Resizing Operations", "Maximum Product of the Length of Two Palindromic Substrings", "Check If String Is a Prefix of Array", "Remove Stones to Minimize the Total", "Minimum Number of Swaps to Make the String Balanced", "Find the Longest Valid Obstacle Course at Each Position", "Number of Strings That Appear as Substrings in Word", "Array With Elements Not Equal to Average of Neighbors", "Minimum Non-Zero Product of the Array Elements", "Last Day Where You Can Still Cross", "Find if Path Exists in Graph", "Minimum Time to Type Word Using Special Typewriter", "Maximum Matrix Sum", "Number of Ways to Arrive at Destination", "Number of Ways to Separate Numbers", "Find Greatest Common Divisor of Array", "Find Unique Binary String", "Minimize the Difference Between Target and Chosen Elements", "Find Array Given Subset Sums", "Minimum Difference Between Highest and Lowest of K Scores", "Find the Kth Largest Integer in the Array", "Minimum Number of Work Sessions to Finish the Tasks", "Number of Unique Good Subsequences", "Find the Middle Index in Array", "Find All Groups of Farmland", "Operations on Tree", "The Number of Good Subsets", "Count Special Quadruplets", "The Number of Weak Characters in the Game", "First Day Where You Have Been in All the Rooms", "GCD Sort of an Array", "Reverse Prefix of Word", "Number of Pairs of Interchangeable Rectangles", "Maximum Product of the Length of Two Palindromic Subsequences", "Smallest Missing Genetic Value in Each Subtree", "Count Number of Pairs With Absolute Difference K", "Find Original Array From Doubled Array", "Maximum Earnings From Taxi", "Minimum Number of Operations to Make Array Continuous", "Final Value of Variable After Performing Operations", "Sum of Beauty in the Array", "Detect Squares", "Longest Subsequence Repeated k Times", "Maximum Difference Between Increasing Elements", "Grid Game", "Check if Word Can Be Placed In Crossword", "The Score of Students Solving Math Expression", "Convert 1D Array Into 2D Array", "Number of Pairs of Strings With Concatenation Equal to Target", "Maximize the Confusion of an Exam", "Maximum Number of Ways to Partition an Array", "Minimum Moves to Convert String", "Find Missing Observations", "Stone Game IX", "Smallest K-Length Subsequence With Occurrences of a Letter", "Two Out of Three", "Minimum Operations to Make a Uni-Value Grid", "Stock Price Fluctuation ", "Partition Array Into Two Arrays to Minimize Sum Difference", "Minimum Number of Moves to Seat Everyone", "Remove Colored Pieces if Both Neighbors are the Same Color", "The Time When the Network Becomes Idle", "Kth Smallest Product of Two Sorted Arrays", "Check if Numbers Are Ascending in a Sentence", "Simple Bank System", "Count Number of Maximum Bitwise-OR Subsets", "Second Minimum Time to Reach Destination", "Number of Valid Words in a Sentence", "Next Greater Numerically Balanced Number", "Count Nodes With the Highest Score", "Parallel Courses III", "Kth Distinct String in an Array", "Two Best Non-Overlapping Events", "Plates Between Candles", "Number of Valid Move Combinations On Chessboard", "Smallest Index With Equal Value", "Find the Minimum and Maximum Number of Nodes Between Critical Points", "Minimum Operations to Convert Number", "Check if an Original String Exists Given Two Encoded Strings", "Count Vowel Substrings of a String", "Vowels of All Substrings", "Minimized Maximum of Products Distributed to Any Store", "Maximum Path Quality of a Graph", "Check Whether Two Strings are Almost Equivalent", "Walking Robot Simulation II", "Most Beautiful Item for Each Query", "Maximum Number of Tasks You Can Assign", "Time Needed to Buy Tickets", "Reverse Nodes in Even Length Groups", "Decode the Slanted Ciphertext", "Process Restricted Friend Requests", "Two Furthest Houses With Different Colors", "Watering Plants", "Range Frequency Queries", "Sum of k-Mirror Numbers", "Count Common Words With One Occurrence", "Minimum Number of Food Buckets to Feed the Hamsters", "Minimum Cost Homecoming of a Robot in a Grid", "Count Fertile Pyramids in a Land", "Find Target Indices After Sorting Array", "K Radius Subarray Averages", "Removing Minimum and Maximum From Array", "Find All People With Secret", "Finding 3-Digit Even Numbers", "Delete the Middle Node of a Linked List", "Step-By-Step Directions From a Binary Tree Node to Another", "Valid Arrangement of Pairs", "Find Subsequence of Length K With the Largest Sum", "Find Good Days to Rob the Bank", "Detonate the Maximum Bombs", "Sequentially Ordinal Rank Tracker", "Rings and Rods", "Sum of Subarray Ranges", "Watering Plants II", "Maximum Fruits Harvested After at Most K Steps", "Find First Palindromic String in the Array", "Adding Spaces to a String", "Number of Smooth Descent Periods of a Stock", "Minimum Operations to Make the Array K-Increasing", "Maximum Number of Words Found in Sentences", "Find All Possible Recipes from Given Supplies", "Check if a Parentheses String Can Be Valid", "Abbreviating the Product of a Range", "A Number After a Double Reversal", "Execution of All Suffix Instructions Staying in a Grid", "Intervals Between Identical Elements", "Recover the Original Array", "Check if All A's Appears Before All B's", "Number of Laser Beams in a Bank", "Destroying Asteroids", "Maximum Employees to Be Invited to a Meeting", "Capitalize the Title", "Maximum Twin Sum of a Linked List", "Longest Palindrome by Concatenating Two Letter Words", "Stamping the Grid", "Check if Every Row and Column Contains All Numbers", "Minimum Swaps to Group All 1's Together II", "Count Words Obtained After Adding a Letter", "Earliest Possible Day of Full Bloom", "Divide a String Into Groups of Size k", "Minimum Moves to Reach Target Score", "Solving Questions With Brainpower", "Maximum Running Time of N Computers", "Minimum Cost of Buying Candies With Discount", "Count the Hidden Sequences", "K Highest Ranked Items Within a Price Range", "Number of Ways to Divide a Long Corridor", "Count Elements With Strictly Smaller and Greater Elements ", "Rearrange Array Elements by Sign", "Find All Lonely Numbers in the Array", "Maximum Good People Based on Statements", "Keep Multiplying Found Values by Two", "All Divisions With the Highest Score of a Binary Array", "Find Substring With Given Hash Value", "Groups of Strings", "Minimum Sum of Four Digit Number After Splitting Digits", "Partition Array According to Given Pivot", "Minimum Cost to Set Cooking Time", "Minimum Difference in Sums After Removal of Elements", "Sort Even and Odd Indices Independently", "Smallest Value of the Rearranged Number", "Design Bitset", "Minimum Time to Remove All Cars Containing Illegal Goods", "Count Operations to Obtain Zero", "Minimum Operations to Make the Array Alternating", "Removing Minimum Number of Magic Beans", "Maximum AND Sum of Array", "Count Equal and Divisible Pairs in an Array", "Find Three Consecutive Integers That Sum to a Given Number", "Maximum Split of Positive Even Integers", "Count Good Triplets in an Array", "Count Integers With Even Digit Sum", "Merge Nodes in Between Zeros", "Construct String With Repeat Limit", "Count Array Pairs Divisible by K", "Counting Words With a Given Prefix", "Minimum Number of Steps to Make Two Strings Anagram II", "Minimum Time to Complete Trips", "Minimum Time to Finish the Race", "Most Frequent Number Following Key In an Array", "Sort the Jumbled Numbers", "All Ancestors of a Node in a Directed Acyclic Graph", "Minimum Number of Moves to Make Palindrome", "Cells in a Range on an Excel Sheet", "Append K Integers With Minimal Sum", "Create Binary Tree From Descriptions", "Replace Non-Coprime Numbers in Array", "Find All K-Distant Indices in an Array", "Count Artifacts That Can Be Extracted", "Maximize the Topmost Element After K Moves", "Minimum Weighted Subgraph With the Required Paths", "Divide Array Into Equal Pairs", "Maximize Number of Subsequences in a String", "Minimum Operations to Halve Array Sum", "Minimum White Tiles After Covering With Carpets", "Count Hills and Valleys in an Array", "Count Collisions on a Road", "Maximum Points in an Archery Competition", "Longest Substring of One Repeating Character", "Find the Difference of Two Arrays", "Minimum Deletions to Make Array Beautiful", "Find Palindrome With Fixed Length", "Maximum Value of K Coins From Piles", "Minimum Bit Flips to Convert Number", "Find Triangular Sum of an Array", "Number of Ways to Select Buildings", "Sum of Scores of Built Strings", "Minimum Number of Operations to Convert Time", "Find Players With Zero or One Losses", "Maximum Candies Allocated to K Children", "Encrypt and Decrypt Strings", "Largest Number After Digit Swaps by Parity", "Minimize Result by Adding Parentheses to Expression", "Maximum Product After K Increments", "Maximum Total Beauty of the Gardens", "Add Two Integers", "Root Equals Sum of Children", "Find Closest Number to Zero", "Number of Ways to Buy Pens and Pencils", "Design an ATM Machine", "Maximum Score of a Node Sequence", "Calculate Digit Sum of a String", "Minimum Rounds to Complete All Tasks", "Maximum Trailing Zeros in a Cornered Path", "Longest Path With Different Adjacent Characters", "Intersection of Multiple Arrays", "Count Lattice Points Inside a Circle", "Count Number of Rectangles Containing Each Point", "Number of Flowers in Full Bloom", "Count Prefixes of a Given String", "Minimum Average Difference", "Count Unguarded Cells in the Grid", "Escape the Spreading Fire", "Remove Digit From Number to Maximize Result", "Minimum Consecutive Cards to Pick Up", "K Divisible Elements Subarrays", "Total Appeal of A String", "Largest 3-Same-Digit Number in String", "Count Nodes Equal to Average of Subtree", "Count Number of Texts", " Check if There Is a Valid Parentheses String Path", "Find the K-Beauty of a Number", "Number of Ways to Split Array", "Maximum White Tiles Covered by a Carpet", "Substring With Largest Variance", "Find Resultant Array After Removing Anagrams", "Maximum Consecutive Floors Without Special Floors", "Largest Combination With Bitwise AND Greater Than Zero", "Count Integers in Intervals", "Percentage of Letter in String", "Maximum Bags With Full Capacity of Rocks", "Minimum Lines to Represent a Line Chart", "Sum of Total Strength of Wizards", "Check if Number Has Equal Digit Count and Digit Value", "Sender With Largest Word Count", "Maximum Total Importance of Roads", "Booking Concert Tickets in Groups", "Rearrange Characters to Make Target String", "Apply Discount to Prices", "Steps to Make Array Non-decreasing", "Minimum Obstacle Removal to Reach Corner", "Min Max Game", "Partition Array Such That Maximum Difference Is K", "Replace Elements in an Array", "Design a Text Editor", "Strong Password Checker II", "Successful Pairs of Spells and Potions", "Match Substring After Replacement", "Count Subarrays With Score Less Than K", "Calculate Amount Paid in Taxes", "Minimum Path Cost in a Grid", "Fair Distribution of Cookies", "Naming a Company", "Greatest English Letter in Upper and Lower Case", "Sum of Numbers With Units Digit K", "Longest Binary Subsequence Less Than or Equal to K", "Selling Pieces of Wood", "Count Asterisks", "Count Unreachable Pairs of Nodes in an Undirected Graph", "Maximum XOR After Operations ", "Number of Distinct Roll Sequences", "Check if Matrix Is X-Matrix", "Count Number of Ways to Place Houses", "Maximum Score Of Spliced Array", "Minimum Score After Removals on a Tree", "Decode the Message", "Spiral Matrix IV", "Number of People Aware of a Secret", "Number of Increasing Paths in a Grid", "Evaluate Boolean Binary Tree", "The Latest Time to Catch a Bus", "Minimum Sum of Squared Difference", "Subarray With Elements Greater Than Varying Threshold", "Minimum Amount of Time to Fill Cups", "Smallest Number in Infinite Set", "Move Pieces to Obtain a String", "Count the Number of Ideal Arrays", "Maximum Number of Pairs in Array", "Max Sum of a Pair With Equal Sum of Digits", "Query Kth Smallest Trimmed Number", "Minimum Deletions to Make Array Divisible", "Best Poker Hand", "Number of Zero-Filled Subarrays", "Design a Number Container System", "Shortest Impossible Sequence of Rolls", "First Letter to Appear Twice", "Equal Row and Column Pairs", "Design a Food Rating System", "Number of Excellent Pairs", "Make Array Zero by Subtracting Equal Amounts", "Maximum Number of Groups Entering a Competition", "Find Closest Node to Given Two Nodes", "Longest Cycle in a Graph", "Merge Similar Items", "Count Number of Bad Pairs", "Task Scheduler II", "Minimum Replacements to Sort the Array", "Number of Arithmetic Triplets", "Reachable Nodes With Restrictions", "Check if There is a Valid Partition For The Array", "Longest Ideal Subsequence", "Largest Local Values in a Matrix", "Node With Highest Edge Score", "Construct Smallest Number From DI String", "Count Special Integers", "Minimum Recolors to Get K Consecutive Black Blocks", "Time Needed to Rearrange a Binary String", "Shifting Letters II", "Maximum Segment Sum After Removals", "Minimum Hours of Training to Win a Competition", "Largest Palindromic Number", "Amount of Time for Binary Tree to Be Infected", "Find the K-Sum of an Array", "Longest Subsequence With Limited Sum", "Removing Stars From a String", "Minimum Amount of Time to Collect Garbage", "Build a Matrix With Conditions", "Find Subarrays With Equal Sum", "Strictly Palindromic Number", "Maximum Rows Covered by Columns", "Maximum Number of Robots Within Budget", "Check Distances Between Same Letters", "Number of Ways to Reach a Position After Exactly k Steps", "Longest Nice Subarray", "Meeting Rooms III", "Most Frequent Even Element", "Optimal Partition of String", "Divide Intervals Into Minimum Number of Groups", "Longest Increasing Subsequence II", "Count Days Spent Together", "Maximum Matching of Players With Trainers", "Smallest Subarrays With Maximum Bitwise OR", "Minimum Money Required Before Transactions", "Smallest Even Multiple", "Length of the Longest Alphabetical Continuous Substring", "Reverse Odd Levels of Binary Tree", "Sum of Prefix Scores of Strings", "Sort the People", "Longest Subarray With Maximum Bitwise AND", "Find All Good Indices", "Number of Good Paths", "Remove Letter To Equalize Frequency", "Longest Uploaded Prefix", "Bitwise XOR of All Pairings", "Number of Pairs Satisfying Inequality", "Number of Common Factors", "Maximum Sum of an Hourglass", "Minimize XOR", "Maximum Deletions on a String", "The Employee That Worked on the Longest Task", "Find The Original Array of Prefix Xor", "Using a Robot to Print the Lexicographically Smallest String", "Paths in Matrix Whose Sum Is Divisible by K", "Number of Valid Clock Times", "Range Product Queries of Powers", "Minimize Maximum of Array", "Create Components With Same Value", "Largest Positive Integer That Exists With Its Negative", "Count Number of Distinct Integers After Reverse Operations", "Sum of Number and Its Reverse", "Count Subarrays With Fixed Bounds", "Determine if Two Events Have Conflict", "Number of Subarrays With GCD Equal to K", "Minimum Cost to Make Array Equal", "Minimum Number of Operations to Make Arrays Similar", "Odd String Difference", "Words Within Two Edits of Dictionary", "Destroy Sequential Targets", "Next Greater Element IV", "Average Value of Even Numbers That Are Divisible by Three", "Most Popular Video Creator", "Minimum Addition to Make Integer Beautiful", "Height of Binary Tree After Subtree Removal Queries", "Apply Operations to an Array", "Maximum Sum of Distinct Subarrays With Length K", "Total Cost to Hire K Workers", "Minimum Total Distance Traveled", "Number of Distinct Averages", "Count Ways To Build Good Strings", "Most Profitable Path in a Tree", "Split Message Based on Limit", "Convert the Temperature", "Number of Subarrays With LCM Equal to K", "Minimum Number of Operations to Sort a Binary Tree by Level", "Maximum Number of Non-overlapping Palindrome Substrings", "Number of Unequal Triplets in Array", "Closest Nodes Queries in a Binary Search Tree", "Minimum Fuel Cost to Report to the Capital", "Number of Beautiful Partitions", "Minimum Cuts to Divide a Circle", "Difference Between Ones and Zeros in Row and Column", "Minimum Penalty for a Shop", "Count Palindromic Subsequences", "Find the Pivot Integer", "Append Characters to String to Make Subsequence", "Remove Nodes From Linked List", "Count Subarrays With Median K", "Circular Sentence", "Divide Players Into Teams of Equal Skill", "Minimum Score of a Path Between Two Cities", "Divide Nodes Into the Maximum Number of Groups", "Maximum Value of a String in an Array", "Maximum Star Sum of a Graph", "Frog Jump II", "Minimum Total Cost to Make Arrays Unequal", "Delete Greatest Value in Each Row", "Longest Square Streak in an Array", "Design Memory Allocator", "Maximum Number of Points From Grid Queries", "Count Pairs Of Similar Strings", "Smallest Value After Replacing With Sum of Prime Factors", "Add Edges to Make Degrees of All Nodes Even", "Cycle Length Queries in a Tree", "Maximum Enemy Forts That Can Be Captured", "Reward Top K Students", "Minimize the Maximum of Two Arrays", "Count Anagrams", "Shortest Distance to Target String in a Circular Array", "Take K of Each Character From Left and Right", "Maximum Tastiness of Candy Basket", "Number of Great Partitions", "Count the Digits That Divide a Number", "Distinct Prime Factors of Product of Array", "Partition String Into Substrings With Values at Most K", "Closest Prime Numbers in Range", "Categorize Box According to Criteria", "Find Consecutive Integers from a Data Stream", "Find Xor-Beauty of Array", "Maximize the Minimum Powered City", "Maximum Count of Positive Integer and Negative Integer", "Maximal Score After Applying K Operations", "Make Number of Distinct Characters Equal", "Time to Cross a Bridge", "Difference Between Element Sum and Digit Sum of an Array", "Increment Submatrices by One", "Count the Number of Good Subarrays", "Difference Between Maximum and Minimum Price Sum", "Minimum Common Value", "Minimum Operations to Make Array Equal II", "Maximum Subsequence Score", "Check if Point Is Reachable", "Alternating Digit Sum", "Sort the Students by Their Kth Score", "Apply Bitwise Operations to Make Strings Equal", "Minimum Cost to Split an Array", "Count Distinct Numbers on Board", "Count Collisions of Monkeys on a Polygon", "Put Marbles in Bags", "Count Increasing Quadruplets", "Separate the Digits in an Array", "Maximum Number of Integers to Choose From a Range I", "Maximize Win From Two Segments", "Disconnect Path in a Binary Matrix by at Most One Flip", "Take Gifts From the Richest Pile", "Count Vowel Strings in Ranges", "House Robber IV", "Rearranging Fruits", "Find the Array Concatenation Value", "Count the Number of Fair Pairs", "Substring XOR Queries", "Subsequence With the Minimum Score", "Maximum Difference by Remapping a Digit", "Minimum Score by Changing Two Elements", "Minimum Impossible OR", "Handling Sum Queries After Update", "Merge Two 2D Arrays by Summing Values", "Minimum Operations to Reduce an Integer to 0", "Count the Number of Square-Free Subsets", "Find the String with LCP", "Left and Right Sum Differences", "Find the Divisibility Array of a String", "Find the Maximum Number of Marked Indices", "Minimum Time to Visit a Cell In a Grid", "Split With Minimum Sum", "Count Total Number of Colored Cells", "Count Ways to Group Overlapping Ranges", "Count Number of Possible Root Nodes", "Pass the Pillow", "Kth Largest Sum in a Binary Tree", "Split the Array to Make Coprime Products", "Number of Ways to Earn Points", "Count the Number of Vowel Strings in Range", "Rearrange Array to Maximize Prefix Score", "Count the Number of Beautiful Subarrays", "Minimum Time to Complete All Tasks", "Distribute Money to Maximum Children", "Maximize Greatness of an Array", "Find Score of an Array After Marking All Elements", "Minimum Time to Repair Cars", "Number of Even and Odd Bits", "Check Knight Tour Configuration", "The Number of Beautiful Subsets", "Smallest Missing Non-negative Integer After Operations", "K Items With the Maximum Sum", "Prime Subtraction Operation", "Minimum Operations to Make All Array Elements Equal", "Collect Coins in a Tree", "Form Smallest Number From Two Digit Arrays", "Find the Substring With Maximum Cost", "Make K-Subarray Sums Equal", "Shortest Cycle in a Graph", "Find the Longest Balanced Substring of a Binary String", "Convert an Array Into a 2D Array With Conditions", "Mice and Cheese", "Minimum Reverse Operations", "Prime In Diagonal", "Sum of Distances", "Minimize the Maximum Difference of Pairs", "Minimum Number of Visited Cells in a Grid", "Find the Width of Columns of a Grid", "Find the Score of All Prefixes of an Array", "Cousins in Binary Tree II", "Design Graph With Shortest Path Calculator", "Row With Maximum Ones", "Find the Maximum Divisibility Score", "Minimum Additions to Make Valid String", "Minimize the Total Price of the Trips", "Calculate Delayed Arrival Time", "Sum Multiples", "Sliding Subarray Beauty", "Minimum Number of Operations to Make All Array Elements Equal to 1", "Maximum Sum With Exactly K Elements ", "Find the Prefix Common Array of Two Arrays", "Maximum Number of Fish in a Grid", "Make Array Empty", "Determine the Winner of a Bowling Game", "First Completely Painted Row or Column", "Minimum Cost of a Path With Special Roads", "Lexicographically Smallest Beautiful String", "Find the Distinct Difference Array", "Frequency Tracker", "Number of Adjacent Elements With the Same Color", "Make Costs of Paths Equal in a Binary Tree", "Number of Senior Citizens", "Sum in a Matrix", "Maximum OR", "Power of Heroes", "Find the Losers of the Circular Game", "Neighboring Bitwise XOR", "Maximum Number of Moves in a Grid", "Count the Number of Complete Components", "Minimum String Length After Removing Substrings", "Lexicographically Smallest Palindrome", "Find the Punishment Number of an Integer", "Modify Graph Edge Weights", "Buy Two Chocolates", "Extra Characters in a String", "Maximum Strength of a Group", "Greatest Common Divisor Traversal", "Remove Trailing Zeros From a String", "Difference of Number of Distinct Values on Diagonals", "Minimum Cost to Make All Characters Equal", "Maximum Strictly Increasing Cells in a Matrix", "Minimize String Length", "Semi-Ordered Permutation", "Sum of Matrix After Queries", "Count of Integers", "Check if The Number is Fascinating", "Find the Longest Semi-Repetitive Substring", "Movement of Robots", "Find a Good Subset of the Matrix", "Neither Minimum nor Maximum", "Lexicographically Smallest String After Substring Operation", "Collecting Chocolates", "Maximum Sum Queries", "Total Distance Traveled", "Find the Value of the Partition", "Special Permutations", "Painting the Walls", "Find Maximum Number of String Pairs", "Construct the Longest New String", "Decremental String Concatenation", "Count Zero Request Servers", "Number of Beautiful Pairs", "Minimum Operations to Make the Integer Zero", "Ways to Split Array Into Good Subarrays", "Robot Collisions", "Longest Even Odd Subarray With Threshold", "Prime Pairs With Target Sum", "Continuous Subarrays", "Sum of Imbalance Numbers of All Subarrays", "Longest Alternating Subarray", "Relocate Marbles", "Partition String Into Minimum Beautiful Substrings", "Number of Black Blocks", "Find the Maximum Achievable Number", "Maximum Number of Jumps to Reach the Last Index", "Longest Non-decreasing Subarray From Two Arrays", "Apply Operations to Make All Array Elements Equal to Zero", "Sum of Squares of Special Elements ", "Maximum Beauty of an Array After Applying Operation", "Minimum Index of a Valid Split", "Length of the Longest Valid Substring", "Check if Array is Good", "Sort Vowels in a String", "Visit Array Positions to Maximize Score", "Ways to Express an Integer as Sum of Powers", "Split Strings by Separator", "Largest Element in an Array after Merge Operations", "Maximum Number of Groups With Increasing Length", "Count Paths That Can Form a Palindrome in a Tree", "Number of Employees Who Met the Target", "Count Complete Subarrays in an Array", "Shortest String That Contains Three Strings", "Count Stepping Numbers in Range", "Account Balance After Rounded Purchase", "Insert Greatest Common Divisors in Linked List", "Minimum Seconds to Equalize a Circular Array", "Minimum Time to Make Array Sum At Most x", "Faulty Keyboard", "Check if it is Possible to Split Array", "Find the Safest Path in a Grid", "Maximum Elegance of a K-Length Subsequence", "Max Pair Sum in an Array", "Double a Number Represented as a Linked List", "Minimum Absolute Difference Between Elements With Constraint", "Apply Operations to Maximize Score", "Count Pairs Whose Sum is Less than Target", "Make String a Subsequence Using Cyclic Increments", "Sorting Three Groups", "Number of Beautiful Integers in the Range", "Check if a String Is an Acronym of Words", "Determine the Minimum Sum of a k-avoiding Array", "Maximize the Profit as the Salesman", "Find the Longest Equal Subarray", "Furthest Point From Origin", "Find the Minimum Possible Sum of a Beautiful Array", "Minimum Operations to Form Subsequence With Target Sum", "Maximize Value of Function in a Ball Passing Game", "Check if Strings Can be Made Equal With Operations I", "Check if Strings Can be Made Equal With Operations II", "Maximum Sum of Almost Unique Subarray", "Count K-Subsequences of a String With Maximum Beauty", " Count Symmetric Integers", "Minimum Operations to Make a Special Number", "Count of Interesting Subarrays", "Minimum Edge Weight Equilibrium Queries in a Tree", "Points That Intersect With Cars", "Determine if a Cell Is Reachable at a Given Time", "Minimum Moves to Spread Stones Over Grid", "String Transformation", "Minimum Right Shifts to Sort the Array", "Minimum Array Length After Pair Removals", "Count Pairs of Points With Distance k", "Minimum Edge Reversals So Every Node Is Reachable", "Sum of Values at Indices With K Set Bits", "Happy Students", "Maximum Number of Alloys", "Maximum Element-Sum of a Complete Subset of Indices", "Maximum Odd Binary Number", "Beautiful Towers I", "Beautiful Towers II", "Count Valid Paths in a Tree"] \ No newline at end of file diff --git a/scripts/questions.json b/scripts/questions.json new file mode 100644 index 0000000000..3f14a7112d --- /dev/null +++ b/scripts/questions.json @@ -0,0 +1,38023 @@ +[ + { + "leetcode-id": 1, + "title": "Two Sum", + "difficulty": 1, + "description": "Given an array of integers nums\u00a0and an integer target, return indices of the two numbers such that they add up to target.\nYou may assume that each input would have exactly one solution, and you may not use the same element twice.\nYou can return the answer in any order.", + "examples": [ + "Example 1:\nInput: nums = [2,7,11,15], target = 9\nOutput: [0,1]\nExplanation: Because nums[0] + nums[1] == 9, we return [0, 1].", + "Example 2:\nInput: nums = [3,2,4], target = 6\nOutput: [1,2]", + "Example 3:\nInput: nums = [3,3], target = 6\nOutput: [0,1]" + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 10^4\n-10^9 <= nums[i] <= 10^9\n-10^9 <= target <= 10^9\nOnly one valid answer exists.\n\n\u00a0\nFollow-up:\u00a0Can you come up with an algorithm that is less than O(n^2)\u00a0time complexity?", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "two-sum" + }, + { + "leetcode-id": 2, + "title": "Add Two Numbers", + "difficulty": 2, + "description": "You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum\u00a0as a linked list.\nYou may assume the two numbers do not contain any leading zero, except the number 0 itself.", + "examples": [ + "Example 1:\nInput: l1 = [2,4,3], l2 = [5,6,4]\nOutput: [7,0,8]\nExplanation: 342 + 465 = 807.", + "Example 2:\nInput: l1 = [0], l2 = [0]\nOutput: [0]", + "Example 3:\nInput: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]\nOutput: [8,9,9,9,0,0,0,1]" + ], + "constraints": "Constraints:\n\nThe number of nodes in each linked list is in the range [1, 100].\n0 <= Node.val <= 9\nIt is guaranteed that the list represents a number that does not have leading zeros.", + "tags": [ + "Linked List", + "Math", + "Recursion" + ], + "title-slug": "add-two-numbers" + }, + { + "leetcode-id": 3, + "title": "Longest Substring Without Repeating Characters", + "difficulty": 2, + "description": "Given a string s, find the length of the longest substring without repeating characters.", + "examples": [ + "Example 1:\nInput: s = \"abcabcbb\"\nOutput: 3\nExplanation: The answer is \"abc\", with the length of 3.", + "Example 2:\nInput: s = \"bbbbb\"\nOutput: 1\nExplanation: The answer is \"b\", with the length of 1.", + "Example 3:\nInput: s = \"pwwkew\"\nOutput: 3\nExplanation: The answer is \"wke\", with the length of 3.\nNotice that the answer must be a substring, \"pwke\" is a subsequence and not a substring." + ], + "constraints": "Constraints:\n\n0 <= s.length <= 5 * 10^4\ns consists of English letters, digits, symbols and spaces.", + "tags": [ + "Hash Table", + "String", + "Sliding Window" + ], + "title-slug": "longest-substring-without-repeating-characters" + }, + { + "leetcode-id": 4, + "title": "Median of Two Sorted Arrays", + "difficulty": 3, + "description": "Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.\nThe overall run time complexity should be O(log (m+n)).", + "examples": [ + "Example 1:\nInput: nums1 = [1,3], nums2 = [2]\nOutput: 2.00000\nExplanation: merged array = [1,2,3] and median is 2.", + "Example 2:\nInput: nums1 = [1,2], nums2 = [3,4]\nOutput: 2.50000\nExplanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5." + ], + "constraints": "Constraints:\n\nnums1.length == m\nnums2.length == n\n0 <= m <= 1000\n0 <= n <= 1000\n1 <= m + n <= 2000\n-10^6 <= nums1[i], nums2[i] <= 10^6", + "tags": [ + "Array", + "Binary Search", + "Divide and Conquer" + ], + "title-slug": "median-of-two-sorted-arrays" + }, + { + "leetcode-id": 5, + "title": "Longest Palindromic Substring", + "difficulty": 2, + "description": "Given a string s, return the longest palindromic substring in s.", + "examples": [ + "Example 1:\nInput: s = \"babad\"\nOutput: \"bab\"\nExplanation: \"aba\" is also a valid answer.", + "Example 2:\nInput: s = \"cbbd\"\nOutput: \"bb\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns consist of only digits and English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "longest-palindromic-substring" + }, + { + "leetcode-id": 6, + "title": "Zigzag Conversion", + "difficulty": 2, + "description": "The string \"PAYPALISHIRING\" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)\n\nP A H N\nA P L S I I G\nY I R\n\nAnd then read line by line: \"PAHNAPLSIIGYIR\"\nWrite the code that will take a string and make this conversion given a number of rows:\n\nstring convert(string s, int numRows);", + "examples": [ + "Example 1:\nInput: s = \"PAYPALISHIRING\", numRows = 3\nOutput: \"PAHNAPLSIIGYIR\"", + "Example 2:\nInput: s = \"PAYPALISHIRING\", numRows = 4\nOutput: \"PINALSIGYAHRPI\"\nExplanation:\nP I N\nA L S I G\nY A H R\nP I", + "Example 3:\nInput: s = \"A\", numRows = 1\nOutput: \"A\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns consists of English letters (lower-case and upper-case), ',' and '.'.\n1 <= numRows <= 1000", + "tags": [ + "String" + ], + "title-slug": "zigzag-conversion" + }, + { + "leetcode-id": 7, + "title": "Reverse Integer", + "difficulty": 2, + "description": "Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-2^31, 2^31 - 1], then return 0.\nAssume the environment does not allow you to store 64-bit integers (signed or unsigned).", + "examples": [ + "Example 1:\nInput: x = 123\nOutput: 321", + "Example 2:\nInput: x = -123\nOutput: -321", + "Example 3:\nInput: x = 120\nOutput: 21" + ], + "constraints": "Constraints:\n\n-2^31 <= x <= 2^31 - 1", + "tags": [ + "Math" + ], + "title-slug": "reverse-integer" + }, + { + "leetcode-id": 8, + "title": "String to Integer (atoi)", + "difficulty": 2, + "description": "Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).\nThe algorithm for myAtoi(string s) is as follows:\n\nRead in and ignore any leading whitespace.\nCheck if the next character (if not already at the end of the string) is '-' or '+'. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present.\nRead in next the characters until the next non-digit character or the end of the input is reached. The rest of the string is ignored.\nConvert these digits into an integer (i.e. \"123\" -> 123, \"0032\" -> 32). If no digits were read, then the integer is 0. Change the sign as necessary (from step 2).\nIf the integer is out of the 32-bit signed integer range [-2^31, 2^31 - 1], then clamp the integer so that it remains in the range. Specifically, integers less than -2^31 should be clamped to -2^31, and integers greater than 2^31 - 1 should be clamped to 2^31 - 1.\nReturn the integer as the final result.\n\nNote:\n\nOnly the space character ' ' is considered a whitespace character.\nDo not ignore any characters other than the leading whitespace or the rest of the string after the digits.", + "examples": [ + "Example 1:\nInput: s = \"42\"\nOutput: 42\nExplanation: The underlined characters are what is read in, the caret is the current reader position.\nStep 1: \"42\" (no characters read because there is no leading whitespace)\n ^\nStep 2: \"42\" (no characters read because there is neither a '-' nor '+')\n ^\nStep 3: \"42\" (\"42\" is read in)\n ^\nThe parsed integer is 42.\nSince 42 is in the range [-2^31, 2^31 - 1], the final result is 42.", + "Example 2:\nInput: s = \" -42\"\nOutput: -42\nExplanation:\nStep 1: \" -42\" (leading whitespace is read and ignored)\n ^\nStep 2: \" -42\" ('-' is read, so the result should be negative)\n ^\nStep 3: \" -42\" (\"42\" is read in)\n ^\nThe parsed integer is -42.\nSince -42 is in the range [-2^31, 2^31 - 1], the final result is -42.", + "Example 3:\nInput: s = \"4193 with words\"\nOutput: 4193\nExplanation:\nStep 1: \"4193 with words\" (no characters read because there is no leading whitespace)\n ^\nStep 2: \"4193 with words\" (no characters read because there is neither a '-' nor '+')\n ^\nStep 3: \"4193 with words\" (\"4193\" is read in; reading stops because the next character is a non-digit)\n ^\nThe parsed integer is 4193.\nSince 4193 is in the range [-2^31, 2^31 - 1], the final result is 4193." + ], + "constraints": "Constraints:\n\n0 <= s.length <= 200\ns consists of English letters (lower-case and upper-case), digits (0-9), ' ', '+', '-', and '.'.", + "tags": [ + "String" + ], + "title-slug": "string-to-integer-atoi" + }, + { + "leetcode-id": 9, + "title": "Palindrome Number", + "difficulty": 1, + "description": "Given an integer x, return true if x is a palindrome, and false otherwise.", + "examples": [ + "Example 1:\nInput: x = 121\nOutput: true\nExplanation: 121 reads as 121 from left to right and from right to left.", + "Example 2:\nInput: x = -121\nOutput: false\nExplanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.", + "Example 3:\nInput: x = 10\nOutput: false\nExplanation: Reads 01 from right to left. Therefore it is not a palindrome." + ], + "constraints": "Constraints:\n\n-2^31\u00a0<= x <= 2^31\u00a0- 1\n\n\u00a0\nFollow up: Could you solve it without converting the integer to a string?", + "tags": [ + "Math" + ], + "title-slug": "palindrome-number" + }, + { + "leetcode-id": 10, + "title": "Regular Expression Matching", + "difficulty": 3, + "description": "Given an input string s\u00a0and a pattern p, implement regular expression matching with support for '.' and '*' where:\n\n'.' Matches any single character.\u200b\u200b\u200b\u200b\n'*' Matches zero or more of the preceding element.\n\nThe matching should cover the entire input string (not partial).", + "examples": [ + "Example 1:\nInput: s = \"aa\", p = \"a\"\nOutput: false\nExplanation: \"a\" does not match the entire string \"aa\".", + "Example 2:\nInput: s = \"aa\", p = \"a*\"\nOutput: true\nExplanation: '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes \"aa\".", + "Example 3:\nInput: s = \"ab\", p = \".*\"\nOutput: true\nExplanation: \".*\" means \"zero or more (*) of any character (.)\"." + ], + "constraints": "Constraints:\n\n1 <= s.length\u00a0<= 20\n1 <= p.length\u00a0<= 20\ns contains only lowercase English letters.\np contains only lowercase English letters, '.', and\u00a0'*'.\nIt is guaranteed for each appearance of the character '*', there will be a previous valid character to match.", + "tags": [ + "String", + "Dynamic Programming", + "Recursion" + ], + "title-slug": "regular-expression-matching" + }, + { + "leetcode-id": 11, + "title": "Container With Most Water", + "difficulty": 2, + "description": "You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the i^th line are (i, 0) and (i, height[i]).\nFind two lines that together with the x-axis form a container, such that the container contains the most water.\nReturn the maximum amount of water a container can store.\nNotice that you may not slant the container.", + "examples": [ + "Example 1:\nInput: height = [1,8,6,2,5,4,8,3,7]\nOutput: 49\nExplanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.", + "Example 2:\nInput: height = [1,1]\nOutput: 1" + ], + "constraints": "Constraints:\n\nn == height.length\n2 <= n <= 10^5\n0 <= height[i] <= 10^4", + "tags": [ + "Array", + "Two Pointers", + "Greedy" + ], + "title-slug": "container-with-most-water" + }, + { + "leetcode-id": 12, + "title": "Integer to Roman", + "difficulty": 2, + "description": "Roman numerals are represented by seven different symbols:\u00a0I, V, X, L, C, D and M.\n\nSymbol Value\nI 1\nV 5\nX 10\nL 50\nC 100\nD 500\nM 1000\nFor example,\u00a02 is written as II\u00a0in Roman numeral, just two one's added together. 12 is written as\u00a0XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.\nRoman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:\n\nI can be placed before V (5) and X (10) to make 4 and 9.\u00a0\nX can be placed before L (50) and C (100) to make 40 and 90.\u00a0\nC can be placed before D (500) and M (1000) to make 400 and 900.\n\nGiven an integer, convert it to a roman numeral.", + "examples": [ + "Example 1:\nInput: num = 3\nOutput: \"III\"\nExplanation: 3 is represented as 3 ones.", + "Example 2:\nInput: num = 58\nOutput: \"LVIII\"\nExplanation: L = 50, V = 5, III = 3.", + "Example 3:\nInput: num = 1994\nOutput: \"MCMXCIV\"\nExplanation: M = 1000, CM = 900, XC = 90 and IV = 4." + ], + "constraints": "Constraints:\n\n1 <= num <= 3999", + "tags": [ + "Hash Table", + "Math", + "String" + ], + "title-slug": "integer-to-roman" + }, + { + "leetcode-id": 13, + "title": "Roman to Integer", + "difficulty": 1, + "description": "Roman numerals are represented by seven different symbols:\u00a0I, V, X, L, C, D and M.\n\nSymbol Value\nI 1\nV 5\nX 10\nL 50\nC 100\nD 500\nM 1000\nFor example,\u00a02 is written as II\u00a0in Roman numeral, just two ones added together. 12 is written as\u00a0XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.\nRoman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:\n\nI can be placed before V (5) and X (10) to make 4 and 9.\u00a0\nX can be placed before L (50) and C (100) to make 40 and 90.\u00a0\nC can be placed before D (500) and M (1000) to make 400 and 900.\n\nGiven a roman numeral, convert it to an integer.", + "examples": [ + "Example 1:\nInput: s = \"III\"\nOutput: 3\nExplanation: III = 3.", + "Example 2:\nInput: s = \"LVIII\"\nOutput: 58\nExplanation: L = 50, V= 5, III = 3.", + "Example 3:\nInput: s = \"MCMXCIV\"\nOutput: 1994\nExplanation: M = 1000, CM = 900, XC = 90 and IV = 4." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 15\ns contains only\u00a0the characters ('I', 'V', 'X', 'L', 'C', 'D', 'M').\nIt is guaranteed\u00a0that s is a valid roman numeral in the range [1, 3999].", + "tags": [ + "Hash Table", + "Math", + "String" + ], + "title-slug": "roman-to-integer" + }, + { + "leetcode-id": 14, + "title": "Longest Common Prefix", + "difficulty": 1, + "description": "Write a function to find the longest common prefix string amongst an array of strings.\nIf there is no common prefix, return an empty string \"\".", + "examples": [ + "Example 1:\nInput: strs = [\"flower\",\"flow\",\"flight\"]\nOutput: \"fl\"", + "Example 2:\nInput: strs = [\"dog\",\"racecar\",\"car\"]\nOutput: \"\"\nExplanation: There is no common prefix among the input strings." + ], + "constraints": "Constraints:\n\n1 <= strs.length <= 200\n0 <= strs[i].length <= 200\nstrs[i] consists of only lowercase English letters.", + "tags": [ + "String", + "Trie" + ], + "title-slug": "longest-common-prefix" + }, + { + "leetcode-id": 15, + "title": "3Sum", + "difficulty": 2, + "description": "Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.\nNotice that the solution set must not contain duplicate triplets.", + "examples": [ + "Example 1:\nInput: nums = [-1,0,1,2,-1,-4]\nOutput: [[-1,-1,2],[-1,0,1]]\nExplanation: \nnums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.\nnums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.\nnums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.\nThe distinct triplets are [-1,0,1] and [-1,-1,2].\nNotice that the order of the output and the order of the triplets does not matter.", + "Example 2:\nInput: nums = [0,1,1]\nOutput: []\nExplanation: The only possible triplet does not sum up to 0.", + "Example 3:\nInput: nums = [0,0,0]\nOutput: [[0,0,0]]\nExplanation: The only possible triplet sums up to 0." + ], + "constraints": "Constraints:\n\n3 <= nums.length <= 3000\n-10^5 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Two Pointers", + "Sorting" + ], + "title-slug": "3sum" + }, + { + "leetcode-id": 16, + "title": "3Sum Closest", + "difficulty": 2, + "description": "Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target.\nReturn the sum of the three integers.\nYou may assume that each input would have exactly one solution.", + "examples": [ + "Example 1:\nInput: nums = [-1,2,1,-4], target = 1\nOutput: 2\nExplanation: The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).", + "Example 2:\nInput: nums = [0,0,0], target = 1\nOutput: 0\nExplanation: The sum that is closest to the target is 0. (0 + 0 + 0 = 0)." + ], + "constraints": "Constraints:\n\n3 <= nums.length <= 500\n-1000 <= nums[i] <= 1000\n-10^4 <= target <= 10^4", + "tags": [ + "Array", + "Two Pointers", + "Sorting" + ], + "title-slug": "3sum-closest" + }, + { + "leetcode-id": 17, + "title": "Letter Combinations of a Phone Number", + "difficulty": 2, + "description": "Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.\nA mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.", + "examples": [ + "Example 1:\nInput: digits = \"23\"\nOutput: [\"ad\",\"ae\",\"af\",\"bd\",\"be\",\"bf\",\"cd\",\"ce\",\"cf\"]", + "Example 2:\nInput: digits = \"\"\nOutput: []", + "Example 3:\nInput: digits = \"2\"\nOutput: [\"a\",\"b\",\"c\"]" + ], + "constraints": "Constraints:\n\n0 <= digits.length <= 4\ndigits[i] is a digit in the range ['2', '9'].", + "tags": [ + "Hash Table", + "String", + "Backtracking" + ], + "title-slug": "letter-combinations-of-a-phone-number" + }, + { + "leetcode-id": 18, + "title": "4Sum", + "difficulty": 2, + "description": "Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:\n\n0 <= a, b, c, d\u00a0< n\na, b, c, and d are distinct.\nnums[a] + nums[b] + nums[c] + nums[d] == target\n\nYou may return the answer in any order.", + "examples": [ + "Example 1:\nInput: nums = [1,0,-1,0,-2,2], target = 0\nOutput: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]", + "Example 2:\nInput: nums = [2,2,2,2,2], target = 8\nOutput: [[2,2,2,2]]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 200\n-10^9 <= nums[i] <= 10^9\n-10^9 <= target <= 10^9", + "tags": [ + "Array", + "Two Pointers", + "Sorting" + ], + "title-slug": "4sum" + }, + { + "leetcode-id": 19, + "title": "Remove Nth Node From End of List", + "difficulty": 2, + "description": "Given the head of a linked list, remove the n^th node from the end of the list and return its head.", + "examples": [ + "Example 1:\nInput: head = [1,2,3,4,5], n = 2\nOutput: [1,2,3,5]", + "Example 2:\nInput: head = [1], n = 1\nOutput: []", + "Example 3:\nInput: head = [1,2], n = 1\nOutput: [1]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is sz.\n1 <= sz <= 30\n0 <= Node.val <= 100\n1 <= n <= sz\n\n\u00a0\nFollow up: Could you do this in one pass?", + "tags": [ + "Linked List", + "Two Pointers" + ], + "title-slug": "remove-nth-node-from-end-of-list" + }, + { + "leetcode-id": 20, + "title": "Valid Parentheses", + "difficulty": 1, + "description": "Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.\nAn input string is valid if:\n\nOpen brackets must be closed by the same type of brackets.\nOpen brackets must be closed in the correct order.\nEvery close bracket has a corresponding open bracket of the same type.", + "examples": [ + "Example 1:\nInput: s = \"()\"\nOutput: true", + "Example 2:\nInput: s = \"()[]{}\"\nOutput: true", + "Example 3:\nInput: s = \"(]\"\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^4\ns consists of parentheses only '()[]{}'.", + "tags": [ + "String", + "Stack" + ], + "title-slug": "valid-parentheses" + }, + { + "leetcode-id": 21, + "title": "Merge Two Sorted Lists", + "difficulty": 1, + "description": "You are given the heads of two sorted linked lists list1 and list2.\nMerge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists.\nReturn the head of the merged linked list.", + "examples": [ + "Example 1:\nInput: list1 = [1,2,4], list2 = [1,3,4]\nOutput: [1,1,2,3,4,4]", + "Example 2:\nInput: list1 = [], list2 = []\nOutput: []", + "Example 3:\nInput: list1 = [], list2 = [0]\nOutput: [0]" + ], + "constraints": "Constraints:\n\nThe number of nodes in both lists is in the range [0, 50].\n-100 <= Node.val <= 100\nBoth list1 and list2 are sorted in non-decreasing order.", + "tags": [ + "Linked List", + "Recursion" + ], + "title-slug": "merge-two-sorted-lists" + }, + { + "leetcode-id": 22, + "title": "Generate Parentheses", + "difficulty": 2, + "description": "Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: [\"((()))\",\"(()())\",\"(())()\",\"()(())\",\"()()()\"]", + "Example 2:\nInput: n = 1\nOutput: [\"()\"]" + ], + "constraints": "Constraints:\n\n1 <= n <= 8", + "tags": [ + "String", + "Dynamic Programming", + "Backtracking" + ], + "title-slug": "generate-parentheses" + }, + { + "leetcode-id": 23, + "title": "Merge k Sorted Lists", + "difficulty": 3, + "description": "You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.\nMerge all the linked-lists into one sorted linked-list and return it.", + "examples": [ + "Example 1:\nInput: lists = [[1,4,5],[1,3,4],[2,6]]\nOutput: [1,1,2,3,4,4,5,6]\nExplanation: The linked-lists are:\n[\n 1->4->5,\n 1->3->4,\n 2->6\n]\nmerging them into one sorted list:\n1->1->2->3->4->4->5->6", + "Example 2:\nInput: lists = []\nOutput: []", + "Example 3:\nInput: lists = [[]]\nOutput: []" + ], + "constraints": "Constraints:\n\nk == lists.length\n0 <= k <= 10^4\n0 <= lists[i].length <= 500\n-10^4 <= lists[i][j] <= 10^4\nlists[i] is sorted in ascending order.\nThe sum of lists[i].length will not exceed 10^4.", + "tags": [ + "Linked List", + "Divide and Conquer", + "Heap (Priority Queue)", + "Merge Sort" + ], + "title-slug": "merge-k-sorted-lists" + }, + { + "leetcode-id": 24, + "title": "Swap Nodes in Pairs", + "difficulty": 2, + "description": "Given a\u00a0linked list, swap every two adjacent nodes and return its head. You must solve the problem without\u00a0modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)", + "examples": [ + "Example 1:\nInput: head = [1,2,3,4]\nOutput: [2,1,4,3]", + "Example 2:\nInput: head = []\nOutput: []", + "Example 3:\nInput: head = [1]\nOutput: [1]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the\u00a0list\u00a0is in the range [0, 100].\n0 <= Node.val <= 100", + "tags": [ + "Linked List", + "Recursion" + ], + "title-slug": "swap-nodes-in-pairs" + }, + { + "leetcode-id": 25, + "title": "Reverse Nodes in k-Group", + "difficulty": 3, + "description": "Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list.\nk is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is.\nYou may not alter the values in the list's nodes, only nodes themselves may be changed.", + "examples": [ + "Example 1:\nInput: head = [1,2,3,4,5], k = 2\nOutput: [2,1,4,3,5]", + "Example 2:\nInput: head = [1,2,3,4,5], k = 3\nOutput: [3,2,1,4,5]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is n.\n1 <= k <= n <= 5000\n0 <= Node.val <= 1000\n\n\u00a0\nFollow-up: Can you solve the problem in O(1) extra memory space?", + "tags": [ + "Linked List", + "Recursion" + ], + "title-slug": "reverse-nodes-in-k-group" + }, + { + "leetcode-id": 26, + "title": "Remove Duplicates from Sorted Array", + "difficulty": 1, + "description": "Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums.\nConsider the number of unique elements of nums to be k, to get accepted, you need to do the following things:\n\nChange the array nums such that the first k elements of nums contain the unique elements in the order they were present in nums initially. The remaining elements of nums are not important as well as the size of nums.\nReturn k.\n\nCustom Judge:\nThe judge will test your solution with the following code:\n\nint[] nums = [...]; // Input array\nint[] expectedNums = [...]; // The expected answer with correct length\n\nint k = removeDuplicates(nums); // Calls your implementation\n\nassert k == expectedNums.length;\nfor (int i = 0; i < k; i++) {\n assert nums[i] == expectedNums[i];\n}\n\nIf all assertions pass, then your solution will be accepted.", + "examples": [ + "Example 1:\nInput: nums = [1,1,2]\nOutput: 2, nums = [1,2,_]\nExplanation: Your function should return k = 2, with the first two elements of nums being 1 and 2 respectively.\nIt does not matter what you leave beyond the returned k (hence they are underscores).", + "Example 2:\nInput: nums = [0,0,1,1,1,2,2,3,3,4]\nOutput: 5, nums = [0,1,2,3,4,_,_,_,_,_]\nExplanation: Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively.\nIt does not matter what you leave beyond the returned k (hence they are underscores)." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 3 * 10^4\n-100 <= nums[i] <= 100\nnums is sorted in non-decreasing order.", + "tags": [ + "Array", + "Two Pointers" + ], + "title-slug": "remove-duplicates-from-sorted-array" + }, + { + "leetcode-id": 27, + "title": "Remove Element", + "difficulty": 1, + "description": "Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.\nConsider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the following things:\n\nChange the array nums such that the first k elements of nums contain the elements which are not equal to val. The remaining elements of nums are not important as well as the size of nums.\nReturn k.\n\nCustom Judge:\nThe judge will test your solution with the following code:\n\nint[] nums = [...]; // Input array\nint val = ...; // Value to remove\nint[] expectedNums = [...]; // The expected answer with correct length.\n // It is sorted with no values equaling val.\n\nint k = removeElement(nums, val); // Calls your implementation\n\nassert k == expectedNums.length;\nsort(nums, 0, k); // Sort the first k elements of nums\nfor (int i = 0; i < actualLength; i++) {\n assert nums[i] == expectedNums[i];\n}\n\nIf all assertions pass, then your solution will be accepted.", + "examples": [ + "Example 1:\nInput: nums = [3,2,2,3], val = 3\nOutput: 2, nums = [2,2,_,_]\nExplanation: Your function should return k = 2, with the first two elements of nums being 2.\nIt does not matter what you leave beyond the returned k (hence they are underscores).", + "Example 2:\nInput: nums = [0,1,2,2,3,0,4,2], val = 2\nOutput: 5, nums = [0,1,4,0,3,_,_,_]\nExplanation: Your function should return k = 5, with the first five elements of nums containing 0, 0, 1, 3, and 4.\nNote that the five elements can be returned in any order.\nIt does not matter what you leave beyond the returned k (hence they are underscores)." + ], + "constraints": "Constraints:\n\n0 <= nums.length <= 100\n0 <= nums[i] <= 50\n0 <= val <= 100", + "tags": [ + "Array", + "Two Pointers" + ], + "title-slug": "remove-element" + }, + { + "leetcode-id": 28, + "title": "Find the Index of the First Occurrence in a String", + "difficulty": 1, + "description": "Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.", + "examples": [ + "Example 1:\nInput: haystack = \"sadbutsad\", needle = \"sad\"\nOutput: 0\nExplanation: \"sad\" occurs at index 0 and 6.\nThe first occurrence is at index 0, so we return 0.", + "Example 2:\nInput: haystack = \"leetcode\", needle = \"leeto\"\nOutput: -1\nExplanation: \"leeto\" did not occur in \"leetcode\", so we return -1." + ], + "constraints": "Constraints:\n\n1 <= haystack.length, needle.length <= 10^4\nhaystack and needle consist of only lowercase English characters.", + "tags": [ + "Two Pointers", + "String", + "String Matching" + ], + "title-slug": "find-the-index-of-the-first-occurrence-in-a-string" + }, + { + "leetcode-id": 29, + "title": "Divide Two Integers", + "difficulty": 2, + "description": "Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator.\nThe integer division should truncate toward zero, which means losing its fractional part. For example, 8.345 would be truncated to 8, and -2.7335 would be truncated to -2.\nReturn the quotient after dividing dividend by divisor.\nNote: Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [\u22122^31, 2^31 \u2212 1]. For this problem, if the quotient is strictly greater than 2^31 - 1, then return 2^31 - 1, and if the quotient is strictly less than -2^31, then return -2^31.", + "examples": [ + "Example 1:\nInput: dividend = 10, divisor = 3\nOutput: 3\nExplanation: 10/3 = 3.33333.. which is truncated to 3.", + "Example 2:\nInput: dividend = 7, divisor = -3\nOutput: -2\nExplanation: 7/-3 = -2.33333.. which is truncated to -2." + ], + "constraints": "Constraints:\n\n-2^31 <= dividend, divisor <= 2^31 - 1\ndivisor != 0", + "tags": [ + "Math", + "Bit Manipulation" + ], + "title-slug": "divide-two-integers" + }, + { + "leetcode-id": 30, + "title": "Substring with Concatenation of All Words", + "difficulty": 3, + "description": "You are given a string s and an array of strings words. All the strings of words are of the same length.\nA concatenated substring in s is a substring that contains all the strings of any permutation of words concatenated.\n\nFor example, if words = [\"ab\",\"cd\",\"ef\"], then \"abcdef\", \"abefcd\", \"cdabef\", \"cdefab\", \"efabcd\", and \"efcdab\" are all concatenated strings. \"acdbef\" is not a concatenated substring because it is not the concatenation of any permutation of words.\n\nReturn the starting indices of all the concatenated substrings in s. You can return the answer in any order.", + "examples": [ + "Example 1:\nInput: s = \"barfoothefoobarman\", words = [\"foo\",\"bar\"]\nOutput: [0,9]\nExplanation: Since words.length == 2 and words[i].length == 3, the concatenated substring has to be of length 6.\nThe substring starting at 0 is \"barfoo\". It is the concatenation of [\"bar\",\"foo\"] which is a permutation of words.\nThe substring starting at 9 is \"foobar\". It is the concatenation of [\"foo\",\"bar\"] which is a permutation of words.\nThe output order does not matter. Returning [9,0] is fine too.", + "Example 2:\nInput: s = \"wordgoodgoodgoodbestword\", words = [\"word\",\"good\",\"best\",\"word\"]\nOutput: []\nExplanation: Since words.length == 4 and words[i].length == 4, the concatenated substring has to be of length 16.\nThere is no substring of length 16 in s that is equal to the concatenation of any permutation of words.\nWe return an empty array.", + "Example 3:\nInput: s = \"barfoofoobarthefoobarman\", words = [\"bar\",\"foo\",\"the\"]\nOutput: [6,9,12]\nExplanation: Since words.length == 3 and words[i].length == 3, the concatenated substring has to be of length 9.\nThe substring starting at 6 is \"foobarthe\". It is the concatenation of [\"foo\",\"bar\",\"the\"] which is a permutation of words.\nThe substring starting at 9 is \"barthefoo\". It is the concatenation of [\"bar\",\"the\",\"foo\"] which is a permutation of words.\nThe substring starting at 12 is \"thefoobar\". It is the concatenation of [\"the\",\"foo\",\"bar\"] which is a permutation of words." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^4\n1 <= words.length <= 5000\n1 <= words[i].length <= 30\ns and words[i] consist of lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Sliding Window" + ], + "title-slug": "substring-with-concatenation-of-all-words" + }, + { + "leetcode-id": 31, + "title": "Next Permutation", + "difficulty": 2, + "description": "A permutation of an array of integers is an arrangement of its members into a sequence or linear order.\n\nFor example, for arr = [1,2,3], the following are all the permutations of arr: [1,2,3], [1,3,2], [2, 1, 3], [2, 3, 1], [3,1,2], [3,2,1].\n\nThe next permutation of an array of integers is the next lexicographically greater permutation of its integer. More formally, if all the permutations of the array are sorted in one container according to their lexicographical order, then the next permutation of that array is the permutation that follows it in the sorted container. If such arrangement is not possible, the array must be rearranged as the lowest possible order (i.e., sorted in ascending order).\n\nFor example, the next permutation of arr = [1,2,3] is [1,3,2].\nSimilarly, the next permutation of arr = [2,3,1] is [3,1,2].\nWhile the next permutation of arr = [3,2,1] is [1,2,3] because [3,2,1] does not have a lexicographical larger rearrangement.\n\nGiven an array of integers nums, find the next permutation of nums.\nThe replacement must be in place and use only constant extra memory.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3]\nOutput: [1,3,2]", + "Example 2:\nInput: nums = [3,2,1]\nOutput: [1,2,3]", + "Example 3:\nInput: nums = [1,1,5]\nOutput: [1,5,1]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n0 <= nums[i] <= 100", + "tags": [ + "Array", + "Two Pointers" + ], + "title-slug": "next-permutation" + }, + { + "leetcode-id": 32, + "title": "Longest Valid Parentheses", + "difficulty": 3, + "description": "Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring.", + "examples": [ + "Example 1:\nInput: s = \"(()\"\nOutput: 2\nExplanation: The longest valid parentheses substring is \"()\".", + "Example 2:\nInput: s = \")()())\"\nOutput: 4\nExplanation: The longest valid parentheses substring is \"()()\".", + "Example 3:\nInput: s = \"\"\nOutput: 0" + ], + "constraints": "Constraints:\n\n0 <= s.length <= 3 * 10^4\ns[i] is '(', or ')'.", + "tags": [ + "String", + "Dynamic Programming", + "Stack" + ], + "title-slug": "longest-valid-parentheses" + }, + { + "leetcode-id": 33, + "title": "Search in Rotated Sorted Array", + "difficulty": 2, + "description": "There is an integer array nums sorted in ascending order (with distinct values).\nPrior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). For example, [0,1,2,4,5,6,7] might be rotated at pivot index 3 and become [4,5,6,7,0,1,2].\nGiven the array nums after the possible rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums.\nYou must write an algorithm with O(log n) runtime complexity.", + "examples": [ + "Example 1:\nInput: nums = [4,5,6,7,0,1,2], target = 0\nOutput: 4", + "Example 2:\nInput: nums = [4,5,6,7,0,1,2], target = 3\nOutput: -1", + "Example 3:\nInput: nums = [1], target = 0\nOutput: -1" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 5000\n-10^4 <= nums[i] <= 10^4\nAll values of nums are unique.\nnums is an ascending array that is possibly rotated.\n-10^4 <= target <= 10^4", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "search-in-rotated-sorted-array" + }, + { + "leetcode-id": 34, + "title": "Find First and Last Position of Element in Sorted Array", + "difficulty": 2, + "description": "Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.\nIf target is not found in the array, return [-1, -1].\nYou must\u00a0write an algorithm with\u00a0O(log n) runtime complexity.", + "examples": [ + "Example 1:\nInput: nums = [5,7,7,8,8,10], target = 8\nOutput: [3,4]", + "Example 2:\nInput: nums = [5,7,7,8,8,10], target = 6\nOutput: [-1,-1]", + "Example 3:\nInput: nums = [], target = 0\nOutput: [-1,-1]" + ], + "constraints": "Constraints:\n\n0 <= nums.length <= 10^5\n-10^9\u00a0<= nums[i]\u00a0<= 10^9\nnums is a non-decreasing array.\n-10^9\u00a0<= target\u00a0<= 10^9", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "find-first-and-last-position-of-element-in-sorted-array" + }, + { + "leetcode-id": 35, + "title": "Search Insert Position", + "difficulty": 1, + "description": "Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.\nYou must\u00a0write an algorithm with\u00a0O(log n) runtime complexity.", + "examples": [ + "Example 1:\nInput: nums = [1,3,5,6], target = 5\nOutput: 2", + "Example 2:\nInput: nums = [1,3,5,6], target = 2\nOutput: 1", + "Example 3:\nInput: nums = [1,3,5,6], target = 7\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-10^4 <= nums[i] <= 10^4\nnums contains distinct values sorted in ascending order.\n-10^4 <= target <= 10^4", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "search-insert-position" + }, + { + "leetcode-id": 36, + "title": "Valid Sudoku", + "difficulty": 2, + "description": "Determine if a\u00a09 x 9 Sudoku board\u00a0is valid.\u00a0Only the filled cells need to be validated\u00a0according to the following rules:\n\nEach row\u00a0must contain the\u00a0digits\u00a01-9 without repetition.\nEach column must contain the digits\u00a01-9\u00a0without repetition.\nEach of the nine\u00a03 x 3 sub-boxes of the grid must contain the digits\u00a01-9\u00a0without repetition.\n\nNote:\n\nA Sudoku board (partially filled) could be valid but is not necessarily solvable.\nOnly the filled cells need to be validated according to the mentioned\u00a0rules.", + "examples": [ + "Example 1:\nInput: board = \n[[\"5\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"]\n,[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"]\n,[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"]\n,[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"]\n,[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"]\n,[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"]\n,[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"]\n,[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"]\n,[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\nOutput: true", + "Example 2:\nInput: board = \n[[\"8\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"]\n,[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"]\n,[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"]\n,[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"]\n,[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"]\n,[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"]\n,[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"]\n,[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"]\n,[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\nOutput: false\nExplanation: Same as", + "Example 1, except with the 5 in the top left corner being modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid.\n" + ], + "constraints": "Constraints:\n\nboard.length == 9\nboard[i].length == 9\nboard[i][j] is a digit 1-9 or '.'.", + "tags": [ + "Array", + "Hash Table", + "Matrix" + ], + "title-slug": "valid-sudoku" + }, + { + "leetcode-id": 37, + "title": "Sudoku Solver", + "difficulty": 3, + "description": "Write a program to solve a Sudoku puzzle by filling the empty cells.\nA sudoku solution must satisfy all of the following rules:\n\nEach of the digits 1-9 must occur exactly once in each row.\nEach of the digits 1-9 must occur exactly once in each column.\nEach of the digits 1-9 must occur exactly once in each of the 9 3x3 sub-boxes of the grid.\n\nThe '.' character indicates empty cells.", + "examples": [ + "Example 1:\nInput: board = [[\"5\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"],[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"],[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"],[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"],[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"],[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"],[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"],[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"],[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\nOutput: [[\"5\",\"3\",\"4\",\"6\",\"7\",\"8\",\"9\",\"1\",\"2\"],[\"6\",\"7\",\"2\",\"1\",\"9\",\"5\",\"3\",\"4\",\"8\"],[\"1\",\"9\",\"8\",\"3\",\"4\",\"2\",\"5\",\"6\",\"7\"],[\"8\",\"5\",\"9\",\"7\",\"6\",\"1\",\"4\",\"2\",\"3\"],[\"4\",\"2\",\"6\",\"8\",\"5\",\"3\",\"7\",\"9\",\"1\"],[\"7\",\"1\",\"3\",\"9\",\"2\",\"4\",\"8\",\"5\",\"6\"],[\"9\",\"6\",\"1\",\"5\",\"3\",\"7\",\"2\",\"8\",\"4\"],[\"2\",\"8\",\"7\",\"4\",\"1\",\"9\",\"6\",\"3\",\"5\"],[\"3\",\"4\",\"5\",\"2\",\"8\",\"6\",\"1\",\"7\",\"9\"]]\nExplanation:\u00a0The input board is shown above and the only valid solution is shown below:" + ], + "constraints": "Constraints:\n\nboard.length == 9\nboard[i].length == 9\nboard[i][j] is a digit or '.'.\nIt is guaranteed that the input board has only one solution.", + "tags": [ + "Array", + "Hash Table", + "Backtracking", + "Matrix" + ], + "title-slug": "sudoku-solver" + }, + { + "leetcode-id": 38, + "title": "Count and Say", + "difficulty": 2, + "description": "The count-and-say sequence is a sequence of digit strings defined by the recursive formula:\n\ncountAndSay(1) = \"1\"\ncountAndSay(n) is the way you would \"say\" the digit string from countAndSay(n-1), which is then converted into a different digit string.\n\nTo determine how you \"say\" a digit string, split it into the minimal number of substrings such that each substring contains exactly one unique digit. Then for each substring, say the number of digits, then say the digit. Finally, concatenate every said digit.\nFor example, the saying and conversion for digit string \"3322251\":\n\nGiven a positive integer n, return the n^th term of the count-and-say sequence.", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: \"1\"\nExplanation: This is the base case.", + "Example 2:\nInput: n = 4\nOutput: \"1211\"\nExplanation:\ncountAndSay(1) = \"1\"\ncountAndSay(2) = say \"1\" = one 1 = \"11\"\ncountAndSay(3) = say \"11\" = two 1's = \"21\"\ncountAndSay(4) = say \"21\" = one 2 + one 1 = \"12\" + \"11\" = \"1211\"" + ], + "constraints": "Constraints:\n\n1 <= n <= 30", + "tags": [ + "String" + ], + "title-slug": "count-and-say" + }, + { + "leetcode-id": 39, + "title": "Combination Sum", + "difficulty": 2, + "description": "Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order.\nThe same number may be chosen from candidates an unlimited number of times. Two combinations are unique if the frequency of at least one of the chosen numbers is different.\nThe test cases are generated such that the number of unique combinations that sum up to target is less than 150 combinations for the given input.", + "examples": [ + "Example 1:\nInput: candidates = [2,3,6,7], target = 7\nOutput: [[2,2,3],[7]]\nExplanation:\n2 and 3 are candidates, and 2 + 2 + 3 = 7. Note that 2 can be used multiple times.\n7 is a candidate, and 7 = 7.\nThese are the only two combinations.", + "Example 2:\nInput: candidates = [2,3,5], target = 8\nOutput: [[2,2,2,2],[2,3,3],[3,5]]", + "Example 3:\nInput: candidates = [2], target = 1\nOutput: []" + ], + "constraints": "Constraints:\n\n1 <= candidates.length <= 30\n2 <= candidates[i] <= 40\nAll elements of candidates are distinct.\n1 <= target <= 40", + "tags": [ + "Array", + "Backtracking" + ], + "title-slug": "combination-sum" + }, + { + "leetcode-id": 40, + "title": "Combination Sum II", + "difficulty": 2, + "description": "Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates\u00a0where the candidate numbers sum to target.\nEach number in candidates\u00a0may only be used once in the combination.\nNote:\u00a0The solution set must not contain duplicate combinations.", + "examples": [ + "Example 1:\nInput: candidates = [10,1,2,7,6,1,5], target = 8\nOutput: \n[\n[1,1,6],\n[1,2,5],\n[1,7],\n[2,6]\n]", + "Example 2:\nInput: candidates = [2,5,2,1,2], target = 5\nOutput: \n[\n[1,2,2],\n[5]\n]" + ], + "constraints": "Constraints:\n\n1 <=\u00a0candidates.length <= 100\n1 <=\u00a0candidates[i] <= 50\n1 <= target <= 30", + "tags": [ + "Array", + "Backtracking" + ], + "title-slug": "combination-sum-ii" + }, + { + "leetcode-id": 41, + "title": "First Missing Positive", + "difficulty": 3, + "description": "Given an unsorted integer array nums, return the smallest missing positive integer.\nYou must implement an algorithm that runs in O(n) time and uses O(1) auxiliary space.", + "examples": [ + "Example 1:\nInput: nums = [1,2,0]\nOutput: 3\nExplanation: The numbers in the range [1,2] are all in the array.", + "Example 2:\nInput: nums = [3,4,-1,1]\nOutput: 2\nExplanation: 1 is in the array but 2 is missing.", + "Example 3:\nInput: nums = [7,8,9,11,12]\nOutput: 1\nExplanation: The smallest positive integer 1 is missing." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-2^31 <= nums[i] <= 2^31 - 1", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "first-missing-positive" + }, + { + "leetcode-id": 42, + "title": "Trapping Rain Water", + "difficulty": 3, + "description": "Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.", + "examples": [ + "Example 1:\nInput: height = [0,1,0,2,1,0,1,3,2,1,2,1]\nOutput: 6\nExplanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.", + "Example 2:\nInput: height = [4,2,0,3,2,5]\nOutput: 9" + ], + "constraints": "Constraints:\n\nn == height.length\n1 <= n <= 2 * 10^4\n0 <= height[i] <= 10^5", + "tags": [ + "Array", + "Two Pointers", + "Dynamic Programming", + "Stack", + "Monotonic Stack" + ], + "title-slug": "trapping-rain-water" + }, + { + "leetcode-id": 43, + "title": "Multiply Strings", + "difficulty": 2, + "description": "Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.\nNote:\u00a0You must not use any built-in BigInteger library or convert the inputs to integer directly.", + "examples": [ + "Example 1:\nInput: num1 = \"2\", num2 = \"3\"\nOutput: \"6\"", + "Example 2:\nInput: num1 = \"123\", num2 = \"456\"\nOutput: \"56088\"" + ], + "constraints": "Constraints:\n\n1 <= num1.length, num2.length <= 200\nnum1 and num2 consist of digits only.\nBoth num1 and num2\u00a0do not contain any leading zero, except the number 0 itself.", + "tags": [ + "Math", + "String", + "Simulation" + ], + "title-slug": "multiply-strings" + }, + { + "leetcode-id": 44, + "title": "Wildcard Matching", + "difficulty": 3, + "description": "Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where:\n\n'?' Matches any single character.\n'*' Matches any sequence of characters (including the empty sequence).\n\nThe matching should cover the entire input string (not partial).", + "examples": [ + "Example 1:\nInput: s = \"aa\", p = \"a\"\nOutput: false\nExplanation: \"a\" does not match the entire string \"aa\".", + "Example 2:\nInput: s = \"aa\", p = \"*\"\nOutput: true\nExplanation:\u00a0'*' matches any sequence.", + "Example 3:\nInput: s = \"cb\", p = \"?a\"\nOutput: false\nExplanation:\u00a0'?' matches 'c', but the second letter is 'a', which does not match 'b'." + ], + "constraints": "Constraints:\n\n0 <= s.length, p.length <= 2000\ns contains only lowercase English letters.\np contains only lowercase English letters, '?' or '*'.", + "tags": [ + "String", + "Dynamic Programming", + "Greedy", + "Recursion" + ], + "title-slug": "wildcard-matching" + }, + { + "leetcode-id": 45, + "title": "Jump Game II", + "difficulty": 2, + "description": "You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0].\nEach element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at nums[i], you can jump to any nums[i + j] where:\n\n0 <= j <= nums[i] and\ni + j < n\n\nReturn the minimum number of jumps to reach nums[n - 1]. The test cases are generated such that you can reach nums[n - 1].", + "examples": [ + "Example 1:\nInput: nums = [2,3,1,1,4]\nOutput: 2\nExplanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.", + "Example 2:\nInput: nums = [2,3,0,1,4]\nOutput: 2" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n0 <= nums[i] <= 1000\nIt's guaranteed that you can reach nums[n - 1].", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "jump-game-ii" + }, + { + "leetcode-id": 46, + "title": "Permutations", + "difficulty": 2, + "description": "Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3]\nOutput: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]", + "Example 2:\nInput: nums = [0,1]\nOutput: [[0,1],[1,0]]", + "Example 3:\nInput: nums = [1]\nOutput: [[1]]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 6\n-10 <= nums[i] <= 10\nAll the integers of nums are unique.", + "tags": [ + "Array", + "Backtracking" + ], + "title-slug": "permutations" + }, + { + "leetcode-id": 47, + "title": "Permutations II", + "difficulty": 2, + "description": "Given a collection of numbers, nums,\u00a0that might contain duplicates, return all possible unique permutations in any order.", + "examples": [ + "Example 1:\nInput: nums = [1,1,2]\nOutput:\n[[1,1,2],\n [1,2,1],\n [2,1,1]]", + "Example 2:\nInput: nums = [1,2,3]\nOutput: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 8\n-10 <= nums[i] <= 10", + "tags": [ + "Array", + "Backtracking" + ], + "title-slug": "permutations-ii" + }, + { + "leetcode-id": 48, + "title": "Rotate Image", + "difficulty": 2, + "description": "You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).\nYou have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.", + "examples": [ + "Example 1:\nInput: matrix = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [[7,4,1],[8,5,2],[9,6,3]]", + "Example 2:\nInput: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]\nOutput: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]" + ], + "constraints": "Constraints:\n\nn == matrix.length == matrix[i].length\n1 <= n <= 20\n-1000 <= matrix[i][j] <= 1000", + "tags": [ + "Array", + "Math", + "Matrix" + ], + "title-slug": "rotate-image" + }, + { + "leetcode-id": 49, + "title": "Group Anagrams", + "difficulty": 2, + "description": "Given an array of strings strs, group the anagrams together. You can return the answer in any order.\nAn Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.", + "examples": [ + "Example 1:\nInput: strs = [\"eat\",\"tea\",\"tan\",\"ate\",\"nat\",\"bat\"]\nOutput: [[\"bat\"],[\"nat\",\"tan\"],[\"ate\",\"eat\",\"tea\"]]", + "Example 2:\nInput: strs = [\"\"]\nOutput: [[\"\"]]", + "Example 3:\nInput: strs = [\"a\"]\nOutput: [[\"a\"]]" + ], + "constraints": "Constraints:\n\n1 <= strs.length <= 10^4\n0 <= strs[i].length <= 100\nstrs[i] consists of lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Sorting" + ], + "title-slug": "group-anagrams" + }, + { + "leetcode-id": 50, + "title": "Pow(x, n)", + "difficulty": 2, + "description": "Implement pow(x, n), which calculates x raised to the power n (i.e., x^n).", + "examples": [ + "Example 1:\nInput: x = 2.00000, n = 10\nOutput: 1024.00000", + "Example 2:\nInput: x = 2.10000, n = 3\nOutput: 9.26100", + "Example 3:\nInput: x = 2.00000, n = -2\nOutput: 0.25000\nExplanation: 2^-2 = 1/2^2 = 1/4 = 0.25" + ], + "constraints": "Constraints:\n\n-100.0 < x < 100.0\n-2^31 <= n <= 2^31-1\nn is an integer.\nEither x is not zero or n > 0.\n-10^4 <= x^n <= 10^4", + "tags": [ + "Math", + "Recursion" + ], + "title-slug": "powx-n" + }, + { + "leetcode-id": 51, + "title": "N-Queens", + "difficulty": 3, + "description": "The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.\nGiven an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any order.\nEach solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space, respectively.", + "examples": [ + "Example 1:\nInput: n = 4\nOutput: [[\".Q..\",\"...Q\",\"Q...\",\"..Q.\"],[\"..Q.\",\"Q...\",\"...Q\",\".Q..\"]]\nExplanation: There exist two distinct solutions to the 4-queens puzzle as shown above", + "Example 2:\nInput: n = 1\nOutput: [[\"Q\"]]" + ], + "constraints": "Constraints:\n\n1 <= n <= 9", + "tags": [ + "Array", + "Backtracking" + ], + "title-slug": "n-queens" + }, + { + "leetcode-id": 52, + "title": "N-Queens II", + "difficulty": 3, + "description": "The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.\nGiven an integer n, return the number of distinct solutions to the\u00a0n-queens puzzle.", + "examples": [ + "Example 1:\nInput: n = 4\nOutput: 2\nExplanation: There are two distinct solutions to the 4-queens puzzle as shown.", + "Example 2:\nInput: n = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= n <= 9", + "tags": [ + "Backtracking" + ], + "title-slug": "n-queens-ii" + }, + { + "leetcode-id": 53, + "title": "Maximum Subarray", + "difficulty": 2, + "description": "Given an integer array nums, find the subarray with the largest sum, and return its sum.", + "examples": [ + "Example 1:\nInput: nums = [-2,1,-3,4,-1,2,1,-5,4]\nOutput: 6\nExplanation: The subarray [4,-1,2,1] has the largest sum 6.", + "Example 2:\nInput: nums = [1]\nOutput: 1\nExplanation: The subarray [1] has the largest sum 1.", + "Example 3:\nInput: nums = [5,4,-1,7,8]\nOutput: 23\nExplanation: The subarray [5,4,-1,7,8] has the largest sum 23." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^4 <= nums[i] <= 10^4\n\n\u00a0\nFollow up: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.", + "tags": [ + "Array", + "Divide and Conquer", + "Dynamic Programming" + ], + "title-slug": "maximum-subarray" + }, + { + "leetcode-id": 54, + "title": "Spiral Matrix", + "difficulty": 2, + "description": "Given an m x n matrix, return all elements of the matrix in spiral order.", + "examples": [ + "Example 1:\nInput: matrix = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [1,2,3,6,9,8,7,4,5]", + "Example 2:\nInput: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]\nOutput: [1,2,3,4,8,12,11,10,9,5,6,7]" + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= m, n <= 10\n-100 <= matrix[i][j] <= 100", + "tags": [ + "Array", + "Matrix", + "Simulation" + ], + "title-slug": "spiral-matrix" + }, + { + "leetcode-id": 55, + "title": "Jump Game", + "difficulty": 2, + "description": "You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.\nReturn true if you can reach the last index, or false otherwise.", + "examples": [ + "Example 1:\nInput: nums = [2,3,1,1,4]\nOutput: true\nExplanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.", + "Example 2:\nInput: nums = [3,2,1,0,4]\nOutput: false\nExplanation: You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n0 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "jump-game" + }, + { + "leetcode-id": 56, + "title": "Merge Intervals", + "difficulty": 2, + "description": "Given an array\u00a0of intervals\u00a0where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.", + "examples": [ + "Example 1:\nInput: intervals = [[1,3],[2,6],[8,10],[15,18]]\nOutput: [[1,6],[8,10],[15,18]]\nExplanation: Since intervals [1,3] and [2,6] overlap, merge them into [1,6].", + "Example 2:\nInput: intervals = [[1,4],[4,5]]\nOutput: [[1,5]]\nExplanation: Intervals [1,4] and [4,5] are considered overlapping." + ], + "constraints": "Constraints:\n\n1 <= intervals.length <= 10^4\nintervals[i].length == 2\n0 <= starti <= endi <= 10^4", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "merge-intervals" + }, + { + "leetcode-id": 57, + "title": "Insert Interval", + "difficulty": 2, + "description": "You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represent the start and the end of the i^th interval and intervals is sorted in ascending order by starti. You are also given an interval newInterval = [start, end] that represents the start and end of another interval.\nInsert newInterval into intervals such that intervals is still sorted in ascending order by starti and intervals still does not have any overlapping intervals (merge overlapping intervals if necessary).\nReturn intervals after the insertion.", + "examples": [ + "Example 1:\nInput: intervals = [[1,3],[6,9]], newInterval = [2,5]\nOutput: [[1,5],[6,9]]", + "Example 2:\nInput: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]\nOutput: [[1,2],[3,10],[12,16]]\nExplanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10]." + ], + "constraints": "Constraints:\n\n0 <= intervals.length <= 10^4\nintervals[i].length == 2\n0 <= starti <= endi <= 10^5\nintervals is sorted by starti in ascending order.\nnewInterval.length == 2\n0 <= start <= end <= 10^5", + "tags": [ + "Array" + ], + "title-slug": "insert-interval" + }, + { + "leetcode-id": 58, + "title": "Length of Last Word", + "difficulty": 1, + "description": "Given a string s consisting of words and spaces, return the length of the last word in the string.\nA word is a maximal substring consisting of non-space characters only.", + "examples": [ + "Example 1:\nInput: s = \"Hello World\"\nOutput: 5\nExplanation: The last word is \"World\" with length 5.", + "Example 2:\nInput: s = \" fly me to the moon \"\nOutput: 4\nExplanation: The last word is \"moon\" with length 4.", + "Example 3:\nInput: s = \"luffy is still joyboy\"\nOutput: 6\nExplanation: The last word is \"joyboy\" with length 6." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^4\ns consists of only English letters and spaces ' '.\nThere will be at least one word in s.", + "tags": [ + "String" + ], + "title-slug": "length-of-last-word" + }, + { + "leetcode-id": 59, + "title": "Spiral Matrix II", + "difficulty": 2, + "description": "Given a positive integer n, generate an n x n matrix filled with elements from 1 to n^2 in spiral order.", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: [[1,2,3],[8,9,4],[7,6,5]]", + "Example 2:\nInput: n = 1\nOutput: [[1]]" + ], + "constraints": "Constraints:\n\n1 <= n <= 20", + "tags": [ + "Array", + "Matrix", + "Simulation" + ], + "title-slug": "spiral-matrix-ii" + }, + { + "leetcode-id": 60, + "title": "Permutation Sequence", + "difficulty": 3, + "description": "The set [1, 2, 3, ...,\u00a0n] contains a total of n! unique permutations.\nBy listing and labeling all of the permutations in order, we get the following sequence for n = 3:\n\n\"123\"\n\"132\"\n\"213\"\n\"231\"\n\"312\"\n\"321\"\n\nGiven n and k, return the k^th permutation sequence.", + "examples": [ + "Example 1:\nInput: n = 3, k = 3\nOutput: \"213\"", + "Example 2:\nInput: n = 4, k = 9\nOutput: \"2314\"", + "Example 3:\nInput: n = 3, k = 1\nOutput: \"123\"" + ], + "constraints": "Constraints:\n\n1 <= n <= 9\n1 <= k <= n!", + "tags": [ + "Math", + "Recursion" + ], + "title-slug": "permutation-sequence" + }, + { + "leetcode-id": 61, + "title": "Rotate List", + "difficulty": 2, + "description": "Given the head of a linked\u00a0list, rotate the list to the right by k places.", + "examples": [ + "Example 1:\nInput: head = [1,2,3,4,5], k = 2\nOutput: [4,5,1,2,3]", + "Example 2:\nInput: head = [0,1,2], k = 4\nOutput: [2,0,1]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [0, 500].\n-100 <= Node.val <= 100\n0 <= k <= 2 * 10^9", + "tags": [ + "Linked List", + "Two Pointers" + ], + "title-slug": "rotate-list" + }, + { + "leetcode-id": 62, + "title": "Unique Paths", + "difficulty": 2, + "description": "There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or right at any point in time.\nGiven the two integers m and n, return the number of possible unique paths that the robot can take to reach the bottom-right corner.\nThe test cases are generated so that the answer will be less than or equal to 2 * 10^9.", + "examples": [ + "Example 1:\nInput: m = 3, n = 7\nOutput: 28", + "Example 2:\nInput: m = 3, n = 2\nOutput: 3\nExplanation: From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:\n1. Right -> Down -> Down\n2. Down -> Down -> Right\n3. Down -> Right -> Down" + ], + "constraints": "Constraints:\n\n1 <= m, n <= 100", + "tags": [ + "Math", + "Dynamic Programming", + "Combinatorics" + ], + "title-slug": "unique-paths" + }, + { + "leetcode-id": 63, + "title": "Unique Paths II", + "difficulty": 2, + "description": "You are given an m x n integer array grid. There is a robot initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or right at any point in time.\nAn obstacle and space are marked as 1 or 0 respectively in grid. A path that the robot takes cannot include any square that is an obstacle.\nReturn the number of possible unique paths that the robot can take to reach the bottom-right corner.\nThe testcases are generated so that the answer will be less than or equal to 2 * 10^9.", + "examples": [ + "Example 1:\nInput: obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]\nOutput: 2\nExplanation: There is one obstacle in the middle of the 3x3 grid above.\nThere are two ways to reach the bottom-right corner:\n1. Right -> Right -> Down -> Down\n2. Down -> Down -> Right -> Right", + "Example 2:\nInput: obstacleGrid = [[0,1],[0,0]]\nOutput: 1" + ], + "constraints": "Constraints:\n\nm == obstacleGrid.length\nn == obstacleGrid[i].length\n1 <= m, n <= 100\nobstacleGrid[i][j] is 0 or 1.", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "unique-paths-ii" + }, + { + "leetcode-id": 64, + "title": "Minimum Path Sum", + "difficulty": 2, + "description": "Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.\nNote: You can only move either down or right at any point in time.", + "examples": [ + "Example 1:\nInput: grid = [[1,3,1],[1,5,1],[4,2,1]]\nOutput: 7\nExplanation: Because the path 1 \u2192 3 \u2192 1 \u2192 1 \u2192 1 minimizes the sum.", + "Example 2:\nInput: grid = [[1,2,3],[4,5,6]]\nOutput: 12" + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 200\n0 <= grid[i][j] <= 200", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "minimum-path-sum" + }, + { + "leetcode-id": 65, + "title": "Valid Number", + "difficulty": 3, + "description": "A valid number can be split up into these components (in order):\n\nA decimal number or an integer.\n(Optional) An 'e' or 'E', followed by an integer.\n\nA decimal number can be split up into these components (in order):\n\n(Optional) A sign character (either '+' or '-').\nOne of the following formats:\n\t\nOne or more digits, followed by a dot '.'.\nOne or more digits, followed by a dot '.', followed by one or more digits.\nA dot '.', followed by one or more digits.\n\n\n\nAn integer can be split up into these components (in order):\n\n(Optional) A sign character (either '+' or '-').\nOne or more digits.\n\nFor example, all the following are valid numbers: [\"2\", \"0089\", \"-0.1\", \"+3.14\", \"4.\", \"-.9\", \"2e10\", \"-90E3\", \"3e+7\", \"+6e-1\", \"53.5e93\", \"-123.456e789\"], while the following are not valid numbers: [\"abc\", \"1a\", \"1e\", \"e3\", \"99e2.5\", \"--6\", \"-+3\", \"95a54e53\"].\nGiven a string s, return true if s is a valid number.", + "examples": [ + "Example 1:\nInput: s = \"0\"\nOutput: true", + "Example 2:\nInput: s = \"e\"\nOutput: false", + "Example 3:\nInput: s = \".\"\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 20\ns consists of only English letters (both uppercase and lowercase), digits (0-9), plus '+', minus '-', or dot '.'.", + "tags": [ + "String" + ], + "title-slug": "valid-number" + }, + { + "leetcode-id": 66, + "title": "Plus One", + "difficulty": 1, + "description": "You are given a large integer represented as an integer array digits, where each digits[i] is the i^th digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's.\nIncrement the large integer by one and return the resulting array of digits.", + "examples": [ + "Example 1:\nInput: digits = [1,2,3]\nOutput: [1,2,4]\nExplanation: The array represents the integer 123.\nIncrementing by one gives 123 + 1 = 124.\nThus, the result should be [1,2,4].", + "Example 2:\nInput: digits = [4,3,2,1]\nOutput: [4,3,2,2]\nExplanation: The array represents the integer 4321.\nIncrementing by one gives 4321 + 1 = 4322.\nThus, the result should be [4,3,2,2].", + "Example 3:\nInput: digits = [9]\nOutput: [1,0]\nExplanation: The array represents the integer 9.\nIncrementing by one gives 9 + 1 = 10.\nThus, the result should be [1,0]." + ], + "constraints": "Constraints:\n\n1 <= digits.length <= 100\n0 <= digits[i] <= 9\ndigits does not contain any leading 0's.", + "tags": [ + "Array", + "Math" + ], + "title-slug": "plus-one" + }, + { + "leetcode-id": 67, + "title": "Add Binary", + "difficulty": 1, + "description": "Given two binary strings a and b, return their sum as a binary string.", + "examples": [ + "Example 1:\nInput: a = \"11\", b = \"1\"\nOutput: \"100\"", + "Example 2:\nInput: a = \"1010\", b = \"1011\"\nOutput: \"10101\"" + ], + "constraints": "Constraints:\n\n1 <= a.length, b.length <= 10^4\na and b consist\u00a0only of '0' or '1' characters.\nEach string does not contain leading zeros except for the zero itself.", + "tags": [ + "Math", + "String", + "Bit Manipulation", + "Simulation" + ], + "title-slug": "add-binary" + }, + { + "leetcode-id": 68, + "title": "Text Justification", + "difficulty": 3, + "description": "Given an array of strings words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.\nYou should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters.\nExtra spaces between words should be distributed as evenly as possible. If the number of spaces on a line does not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.\nFor the last line of text, it should be left-justified, and no extra space is inserted between words.\nNote:\n\nA word is defined as a character sequence consisting of non-space characters only.\nEach word's length is guaranteed to be greater than 0 and not exceed maxWidth.\nThe input array words contains at least one word.", + "examples": [ + "Example 1:\nInput: words = [\"This\", \"is\", \"an\", \"example\", \"of\", \"text\", \"justification.\"], maxWidth = 16\nOutput:\n[\n\u00a0 \u00a0\"This \u00a0 \u00a0is \u00a0 \u00a0an\",\n\u00a0 \u00a0\"example \u00a0of text\",\n\u00a0 \u00a0\"justification. \u00a0\"\n]", + "Example 2:\nInput: words = [\"What\",\"must\",\"be\",\"acknowledgment\",\"shall\",\"be\"], maxWidth = 16\nOutput:\n[\n\u00a0 \"What \u00a0 must \u00a0 be\",\n\u00a0 \"acknowledgment \u00a0\",\n\u00a0 \"shall be \u00a0 \u00a0 \u00a0 \u00a0\"\n]\nExplanation: Note that the last line is \"shall be \" instead of \"shall be\", because the last line must be left-justified instead of fully-justified.\nNote that the second line is also left-justified because it contains only one word.", + "Example 3:\nInput: words = [\"Science\",\"is\",\"what\",\"we\",\"understand\",\"well\",\"enough\",\"to\",\"explain\",\"to\",\"a\",\"computer.\",\"Art\",\"is\",\"everything\",\"else\",\"we\",\"do\"], maxWidth = 20\nOutput:\n[\n\u00a0 \"Science \u00a0is \u00a0what we\",\n \"understand \u00a0 \u00a0 \u00a0well\",\n\u00a0 \"enough to explain to\",\n\u00a0 \"a \u00a0computer. \u00a0Art is\",\n\u00a0 \"everything \u00a0else \u00a0we\",\n\u00a0 \"do \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\"\n]" + ], + "constraints": "Constraints:\n\n1 <= words.length <= 300\n1 <= words[i].length <= 20\nwords[i] consists of only English letters and symbols.\n1 <= maxWidth <= 100\nwords[i].length <= maxWidth", + "tags": [ + "Array", + "String", + "Simulation" + ], + "title-slug": "text-justification" + }, + { + "leetcode-id": 69, + "title": "Sqrt(x)", + "difficulty": 1, + "description": "Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well.\nYou must not use any built-in exponent function or operator.\n\nFor example, do not use pow(x, 0.5) in c++ or x ** 0.5 in python.", + "examples": [ + "Example 1:\nInput: x = 4\nOutput: 2\nExplanation: The square root of 4 is 2, so we return 2.", + "Example 2:\nInput: x = 8\nOutput: 2\nExplanation: The square root of 8 is 2.82842..., and since we round it down to the nearest integer, 2 is returned." + ], + "constraints": "Constraints:\n\n0 <= x <= 2^31 - 1", + "tags": [ + "Math", + "Binary Search" + ], + "title-slug": "sqrtx" + }, + { + "leetcode-id": 70, + "title": "Climbing Stairs", + "difficulty": 1, + "description": "You are climbing a staircase. It takes n steps to reach the top.\nEach time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: 2\nExplanation: There are two ways to climb to the top.\n1. 1 step + 1 step\n2. 2 steps", + "Example 2:\nInput: n = 3\nOutput: 3\nExplanation: There are three ways to climb to the top.\n1. 1 step + 1 step + 1 step\n2. 1 step + 2 steps\n3. 2 steps + 1 step" + ], + "constraints": "Constraints:\n\n1 <= n <= 45", + "tags": [ + "Math", + "Dynamic Programming", + "Memoization" + ], + "title-slug": "climbing-stairs" + }, + { + "leetcode-id": 71, + "title": "Simplify Path", + "difficulty": 2, + "description": "Given a string path, which is an absolute path (starting with a slash '/') to a file or directory in a Unix-style file system, convert it to the simplified canonical path.\nIn a Unix-style file system, a period '.' refers to the current directory, a double period '..' refers to the directory up a level, and any multiple consecutive slashes (i.e. '//') are treated as a single slash '/'. For this problem, any other format of periods such as '...' are treated as file/directory names.\nThe canonical path should have the following format:\n\nThe path starts with a single slash '/'.\nAny two directories are separated by a single slash '/'.\nThe path does not end with a trailing '/'.\nThe path only contains the directories on the path from the root directory to the target file or directory (i.e., no period '.' or double period '..')\n\nReturn the simplified canonical path.", + "examples": [ + "Example 1:\nInput: path = \"/home/\"\nOutput: \"/home\"\nExplanation: Note that there is no trailing slash after the last directory name.", + "Example 2:\nInput: path = \"/../\"\nOutput: \"/\"\nExplanation: Going one level up from the root directory is a no-op, as the root level is the highest level you can go.", + "Example 3:\nInput: path = \"/home//foo/\"\nOutput: \"/home/foo\"\nExplanation: In the canonical path, multiple consecutive slashes are replaced by a single one." + ], + "constraints": "Constraints:\n\n1 <= path.length <= 3000\npath consists of English letters, digits, period '.', slash '/' or '_'.\npath is a valid absolute Unix path.", + "tags": [ + "String", + "Stack" + ], + "title-slug": "simplify-path" + }, + { + "leetcode-id": 72, + "title": "Edit Distance", + "difficulty": 2, + "description": "Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.\nYou have the following three operations permitted on a word:\n\nInsert a character\nDelete a character\nReplace a character", + "examples": [ + "Example 1:\nInput: word1 = \"horse\", word2 = \"ros\"\nOutput: 3\nExplanation: \nhorse -> rorse (replace 'h' with 'r')\nrorse -> rose (remove 'r')\nrose -> ros (remove 'e')", + "Example 2:\nInput: word1 = \"intention\", word2 = \"execution\"\nOutput: 5\nExplanation: \nintention -> inention (remove 't')\ninention -> enention (replace 'i' with 'e')\nenention -> exention (replace 'n' with 'x')\nexention -> exection (replace 'n' with 'c')\nexection -> execution (insert 'u')" + ], + "constraints": "Constraints:\n\n0 <= word1.length, word2.length <= 500\nword1 and word2 consist of lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "edit-distance" + }, + { + "leetcode-id": 73, + "title": "Set Matrix Zeroes", + "difficulty": 2, + "description": "Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's.\nYou must do it in place.", + "examples": [ + "Example 1:\nInput: matrix = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: [[1,0,1],[0,0,0],[1,0,1]]", + "Example 2:\nInput: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]\nOutput: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]" + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[0].length\n1 <= m, n <= 200\n-2^31 <= matrix[i][j] <= 2^31 - 1\n\n\u00a0\nFollow up:\n\nA straightforward solution using O(mn) space is probably a bad idea.\nA simple improvement uses O(m + n) space, but still not the best solution.\nCould you devise a constant space solution?", + "tags": [ + "Array", + "Hash Table", + "Matrix" + ], + "title-slug": "set-matrix-zeroes" + }, + { + "leetcode-id": 74, + "title": "Search a 2D Matrix", + "difficulty": 2, + "description": "You are given an m x n integer matrix matrix with the following two properties:\n\nEach row is sorted in non-decreasing order.\nThe first integer of each row is greater than the last integer of the previous row.\n\nGiven an integer target, return true if target is in matrix or false otherwise.\nYou must write a solution in O(log(m * n)) time complexity.", + "examples": [ + "Example 1:\nInput: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3\nOutput: true", + "Example 2:\nInput: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13\nOutput: false" + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= m, n <= 100\n-10^4 <= matrix[i][j], target <= 10^4", + "tags": [ + "Array", + "Binary Search", + "Matrix" + ], + "title-slug": "search-a-2d-matrix" + }, + { + "leetcode-id": 75, + "title": "Sort Colors", + "difficulty": 2, + "description": "Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.\nWe will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.\nYou must solve this problem without using the library's sort function.", + "examples": [ + "Example 1:\nInput: nums = [2,0,2,1,1,0]\nOutput: [0,0,1,1,2,2]", + "Example 2:\nInput: nums = [2,0,1]\nOutput: [0,1,2]" + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 300\nnums[i] is either 0, 1, or 2.\n\n\u00a0\nFollow up:\u00a0Could you come up with a one-pass algorithm using only\u00a0constant extra space?", + "tags": [ + "Array", + "Two Pointers", + "Sorting" + ], + "title-slug": "sort-colors" + }, + { + "leetcode-id": 76, + "title": "Minimum Window Substring", + "difficulty": 3, + "description": "Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string \"\".\nThe testcases will be generated such that the answer is unique.", + "examples": [ + "Example 1:\nInput: s = \"ADOBECODEBANC\", t = \"ABC\"\nOutput: \"BANC\"\nExplanation: The minimum window substring \"BANC\" includes 'A', 'B', and 'C' from string t.", + "Example 2:\nInput: s = \"a\", t = \"a\"\nOutput: \"a\"\nExplanation: The entire string s is the minimum window.", + "Example 3:\nInput: s = \"a\", t = \"aa\"\nOutput: \"\"\nExplanation: Both 'a's from t must be included in the window.\nSince the largest window of s only has one 'a', return empty string." + ], + "constraints": "Constraints:\n\nm == s.length\nn == t.length\n1 <= m, n <= 10^5\ns and t consist of uppercase and lowercase English letters.\n\n\u00a0\nFollow up: Could you find an algorithm that runs in O(m + n) time?", + "tags": [ + "Hash Table", + "String", + "Sliding Window" + ], + "title-slug": "minimum-window-substring" + }, + { + "leetcode-id": 77, + "title": "Combinations", + "difficulty": 2, + "description": "Given two integers n and k, return all possible combinations of k numbers chosen from the range [1, n].\nYou may return the answer in any order.", + "examples": [ + "Example 1:\nInput: n = 4, k = 2\nOutput: [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]\nExplanation: There are 4 choose 2 = 6 total combinations.\nNote that combinations are unordered, i.e., [1,2] and [2,1] are considered to be the same combination.", + "Example 2:\nInput: n = 1, k = 1\nOutput: [[1]]\nExplanation: There is 1 choose 1 = 1 total combination." + ], + "constraints": "Constraints:\n\n1 <= n <= 20\n1 <= k <= n", + "tags": [ + "Backtracking" + ], + "title-slug": "combinations" + }, + { + "leetcode-id": 78, + "title": "Subsets", + "difficulty": 2, + "description": "Given an integer array nums of unique elements, return all possible subsets (the power set).\nThe solution set must not contain duplicate subsets. Return the solution in any order.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3]\nOutput: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]", + "Example 2:\nInput: nums = [0]\nOutput: [[],[0]]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10\n-10 <= nums[i] <= 10\nAll the numbers of\u00a0nums are unique.", + "tags": [ + "Array", + "Backtracking", + "Bit Manipulation" + ], + "title-slug": "subsets" + }, + { + "leetcode-id": 79, + "title": "Word Search", + "difficulty": 2, + "description": "Given an m x n grid of characters board and a string word, return true if word exists in the grid.\nThe word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.", + "examples": [ + "Example 1:\nInput: board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCCED\"\nOutput: true", + "Example 2:\nInput: board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"SEE\"\nOutput: true", + "Example 3:\nInput: board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCB\"\nOutput: false" + ], + "constraints": "Constraints:\n\nm == board.length\nn = board[i].length\n1 <= m, n <= 6\n1 <= word.length <= 15\nboard and word consists of only lowercase and uppercase English letters.\n\n\u00a0\nFollow up: Could you use search pruning to make your solution faster with a larger board?", + "tags": [ + "Array", + "Backtracking", + "Matrix" + ], + "title-slug": "word-search" + }, + { + "leetcode-id": 80, + "title": "Remove Duplicates from Sorted Array II", + "difficulty": 2, + "description": "Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice. The relative order of the elements should be kept the same.\nSince it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elements after removing the duplicates, then the first k elements of nums\u00a0should hold the final result. It does not matter what you leave beyond the first\u00a0k\u00a0elements.\nReturn k after placing the final result in the first k slots of nums.\nDo not allocate extra space for another array. You must do this by modifying the input array in-place with O(1) extra memory.\nCustom Judge:\nThe judge will test your solution with the following code:\n\nint[] nums = [...]; // Input array\nint[] expectedNums = [...]; // The expected answer with correct length\n\nint k = removeDuplicates(nums); // Calls your implementation\n\nassert k == expectedNums.length;\nfor (int i = 0; i < k; i++) {\n assert nums[i] == expectedNums[i];\n}\n\nIf all assertions pass, then your solution will be accepted.", + "examples": [ + "Example 1:\nInput: nums = [1,1,1,2,2,3]\nOutput: 5, nums = [1,1,2,2,3,_]\nExplanation: Your function should return k = 5, with the first five elements of nums being 1, 1, 2, 2 and 3 respectively.\nIt does not matter what you leave beyond the returned k (hence they are underscores).", + "Example 2:\nInput: nums = [0,0,1,1,1,1,2,3,3]\nOutput: 7, nums = [0,0,1,1,2,3,3,_,_]\nExplanation: Your function should return k = 7, with the first seven elements of nums being 0, 0, 1, 1, 2, 3 and 3 respectively.\nIt does not matter what you leave beyond the returned k (hence they are underscores)." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 3 * 10^4\n-10^4 <= nums[i] <= 10^4\nnums is sorted in non-decreasing order.", + "tags": [ + "Array", + "Two Pointers" + ], + "title-slug": "remove-duplicates-from-sorted-array-ii" + }, + { + "leetcode-id": 81, + "title": "Search in Rotated Sorted Array II", + "difficulty": 2, + "description": "There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values).\nBefore being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). For example, [0,1,2,4,4,4,5,6,6,7] might be rotated at pivot index 5 and become [4,5,6,6,7,0,1,2,4,4].\nGiven the array nums after the rotation and an integer target, return true if target is in nums, or false if it is not in nums.\nYou must decrease the overall operation steps as much as possible.", + "examples": [ + "Example 1:\nInput: nums = [2,5,6,0,0,1,2], target = 0\nOutput: true", + "Example 2:\nInput: nums = [2,5,6,0,0,1,2], target = 3\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 5000\n-10^4 <= nums[i] <= 10^4\nnums is guaranteed to be rotated at some pivot.\n-10^4 <= target <= 10^4\n\n\u00a0\nFollow up: This problem is similar to\u00a0Search in Rotated Sorted Array, but\u00a0nums may contain duplicates. Would this affect the runtime complexity? How and why?", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "search-in-rotated-sorted-array-ii" + }, + { + "leetcode-id": 82, + "title": "Remove Duplicates from Sorted List II", + "difficulty": 2, + "description": "Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.", + "examples": [ + "Example 1:\nInput: head = [1,2,3,3,4,4,5]\nOutput: [1,2,5]", + "Example 2:\nInput: head = [1,1,1,2,3]\nOutput: [2,3]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [0, 300].\n-100 <= Node.val <= 100\nThe list is guaranteed to be sorted in ascending order.", + "tags": [ + "Linked List", + "Two Pointers" + ], + "title-slug": "remove-duplicates-from-sorted-list-ii" + }, + { + "leetcode-id": 83, + "title": "Remove Duplicates from Sorted List", + "difficulty": 1, + "description": "Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.", + "examples": [ + "Example 1:\nInput: head = [1,1,2]\nOutput: [1,2]", + "Example 2:\nInput: head = [1,1,2,3,3]\nOutput: [1,2,3]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [0, 300].\n-100 <= Node.val <= 100\nThe list is guaranteed to be sorted in ascending order.", + "tags": [ + "Linked List" + ], + "title-slug": "remove-duplicates-from-sorted-list" + }, + { + "leetcode-id": 84, + "title": "Largest Rectangle in Histogram", + "difficulty": 3, + "description": "Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.", + "examples": [ + "Example 1:\nInput: heights = [2,1,5,6,2,3]\nOutput: 10\nExplanation: The above is a histogram where width of each bar is 1.\nThe largest rectangle is shown in the red area, which has an area = 10 units.", + "Example 2:\nInput: heights = [2,4]\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= heights.length <= 10^5\n0 <= heights[i] <= 10^4", + "tags": [ + "Array", + "Stack", + "Monotonic Stack" + ], + "title-slug": "largest-rectangle-in-histogram" + }, + { + "leetcode-id": 85, + "title": "Maximal Rectangle", + "difficulty": 3, + "description": "Given a rows x cols\u00a0binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.", + "examples": [ + "Example 1:\nInput: matrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]\nOutput: 6\nExplanation: The maximal rectangle is shown in the above picture.", + "Example 2:\nInput: matrix = [[\"0\"]]\nOutput: 0", + "Example 3:\nInput: matrix = [[\"1\"]]\nOutput: 1" + ], + "constraints": "Constraints:\n\nrows == matrix.length\ncols == matrix[i].length\n1 <= row, cols <= 200\nmatrix[i][j] is '0' or '1'.", + "tags": [ + "Array", + "Dynamic Programming", + "Stack", + "Matrix", + "Monotonic Stack" + ], + "title-slug": "maximal-rectangle" + }, + { + "leetcode-id": 86, + "title": "Partition List", + "difficulty": 2, + "description": "Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.\nYou should preserve the original relative order of the nodes in each of the two partitions.", + "examples": [ + "Example 1:\nInput: head = [1,4,3,2,5,2], x = 3\nOutput: [1,2,2,4,3,5]", + "Example 2:\nInput: head = [2,1], x = 2\nOutput: [1,2]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [0, 200].\n-100 <= Node.val <= 100\n-200 <= x <= 200", + "tags": [ + "Linked List", + "Two Pointers" + ], + "title-slug": "partition-list" + }, + { + "leetcode-id": 87, + "title": "Scramble String", + "difficulty": 3, + "description": "We can scramble a string s to get a string t using the following algorithm:\n\nIf the length of the string is 1, stop.\nIf the length of the string is > 1, do the following:\n\t\nSplit the string into two non-empty substrings at a random index, i.e., if the string is s, divide it to x and y where s = x + y.\nRandomly\u00a0decide to swap the two substrings or to keep them in the same order. i.e., after this step, s may become s = x + y or s = y + x.\nApply step 1 recursively on each of the two substrings x and y.\n\n\n\nGiven two strings s1 and s2 of the same length, return true if s2 is a scrambled string of s1, otherwise, return false.", + "examples": [ + "Example 1:\nInput: s1 = \"great\", s2 = \"rgeat\"\nOutput: true\nExplanation: One possible scenario applied on s1 is:\n\"great\" --> \"gr/eat\" // divide at random index.\n\"gr/eat\" --> \"gr/eat\" // random decision is not to swap the two substrings and keep them in order.\n\"gr/eat\" --> \"g/r / e/at\" // apply the same algorithm recursively on both substrings. divide at random index each of them.\n\"g/r / e/at\" --> \"r/g / e/at\" // random decision was to swap the first substring and to keep the second substring in the same order.\n\"r/g / e/at\" --> \"r/g / e/ a/t\" // again apply the algorithm recursively, divide \"at\" to \"a/t\".\n\"r/g / e/ a/t\" --> \"r/g / e/ a/t\" // random decision is to keep both substrings in the same order.\nThe algorithm stops now, and the result string is \"rgeat\" which is s2.\nAs one possible scenario led s1 to be scrambled to s2, we return true.", + "Example 2:\nInput: s1 = \"abcde\", s2 = \"caebd\"\nOutput: false", + "Example 3:\nInput: s1 = \"a\", s2 = \"a\"\nOutput: true" + ], + "constraints": "Constraints:\n\ns1.length == s2.length\n1 <= s1.length <= 30\ns1 and s2 consist of lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "scramble-string" + }, + { + "leetcode-id": 88, + "title": "Merge Sorted Array", + "difficulty": 1, + "description": "You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.\nMerge nums1 and nums2 into a single array sorted in non-decreasing order.\nThe final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n.", + "examples": [ + "Example 1:\nInput: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3\nOutput: [1,2,2,3,5,6]\nExplanation: The arrays we are merging are [1,2,3] and [2,5,6].\nThe result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.", + "Example 2:\nInput: nums1 = [1], m = 1, nums2 = [], n = 0\nOutput: [1]\nExplanation: The arrays we are merging are [1] and [].\nThe result of the merge is [1].", + "Example 3:\nInput: nums1 = [0], m = 0, nums2 = [1], n = 1\nOutput: [1]\nExplanation: The arrays we are merging are [] and [1].\nThe result of the merge is [1].\nNote that because m = 0, there are no elements in nums1. The 0 is only there to ensure the merge result can fit in nums1." + ], + "constraints": "Constraints:\n\nnums1.length == m + n\nnums2.length == n\n0 <= m, n <= 200\n1 <= m + n <= 200\n-10^9 <= nums1[i], nums2[j] <= 10^9\n\n\u00a0\nFollow up: Can you come up with an algorithm that runs in O(m + n) time?", + "tags": [ + "Array", + "Two Pointers", + "Sorting" + ], + "title-slug": "merge-sorted-array" + }, + { + "leetcode-id": 89, + "title": "Gray Code", + "difficulty": 2, + "description": "An n-bit gray code sequence is a sequence of 2^n integers where:\n\nEvery integer is in the inclusive range [0, 2^n - 1],\nThe first integer is 0,\nAn integer appears no more than once in the sequence,\nThe binary representation of every pair of adjacent integers differs by exactly one bit, and\nThe binary representation of the first and last integers differs by exactly one bit.\n\nGiven an integer n, return any valid n-bit gray code sequence.", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: [0,1,3,2]\nExplanation:\nThe binary representation of [0,1,3,2] is [00,01,11,10].\n- 00 and 01 differ by one bit\n- 01 and 11 differ by one bit\n- 11 and 10 differ by one bit\n- 10 and 00 differ by one bit\n[0,2,3,1] is also a valid gray code sequence, whose binary representation is [00,10,11,01].\n- 00 and 10 differ by one bit\n- 10 and 11 differ by one bit\n- 11 and 01 differ by one bit\n- 01 and 00 differ by one bit", + "Example 2:\nInput: n = 1\nOutput: [0,1]" + ], + "constraints": "Constraints:\n\n1 <= n <= 16", + "tags": [ + "Math", + "Backtracking", + "Bit Manipulation" + ], + "title-slug": "gray-code" + }, + { + "leetcode-id": 90, + "title": "Subsets II", + "difficulty": 2, + "description": "Given an integer array nums that may contain duplicates, return all possible subsets (the power set).\nThe solution set must not contain duplicate subsets. Return the solution in any order.", + "examples": [ + "Example 1:\nInput: nums = [1,2,2]\nOutput: [[],[1],[1,2],[1,2,2],[2],[2,2]]", + "Example 2:\nInput: nums = [0]\nOutput: [[],[0]]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10\n-10 <= nums[i] <= 10", + "tags": [ + "Array", + "Backtracking", + "Bit Manipulation" + ], + "title-slug": "subsets-ii" + }, + { + "leetcode-id": 91, + "title": "Decode Ways", + "difficulty": 2, + "description": "A message containing letters from A-Z can be encoded into numbers using the following mapping:\n\n'A' -> \"1\"\n'B' -> \"2\"\n...\n'Z' -> \"26\"\n\nTo decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, \"11106\" can be mapped into:\n\n\"AAJF\" with the grouping (1 1 10 6)\n\"KJF\" with the grouping (11 10 6)\n\nNote that the grouping (1 11 06) is invalid because \"06\" cannot be mapped into 'F' since \"6\" is different from \"06\".\nGiven a string s containing only digits, return the number of ways to decode it.\nThe test cases are generated so that the answer fits in a 32-bit integer.", + "examples": [ + "Example 1:\nInput: s = \"12\"\nOutput: 2\nExplanation: \"12\" could be decoded as \"AB\" (1 2) or \"L\" (12).", + "Example 2:\nInput: s = \"226\"\nOutput: 3\nExplanation: \"226\" could be decoded as \"BZ\" (2 26), \"VF\" (22 6), or \"BBF\" (2 2 6).", + "Example 3:\nInput: s = \"06\"\nOutput: 0\nExplanation: \"06\" cannot be mapped to \"F\" because of the leading zero (\"6\" is different from \"06\")." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\ns contains only digits and may contain leading zero(s).", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "decode-ways" + }, + { + "leetcode-id": 92, + "title": "Reverse Linked List II", + "difficulty": 2, + "description": "Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.", + "examples": [ + "Example 1:\nInput: head = [1,2,3,4,5], left = 2, right = 4\nOutput: [1,4,3,2,5]", + "Example 2:\nInput: head = [5], left = 1, right = 1\nOutput: [5]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is n.\n1 <= n <= 500\n-500 <= Node.val <= 500\n1 <= left <= right <= n\n\n\u00a0\nFollow up: Could you do it in one pass?", + "tags": [ + "Linked List" + ], + "title-slug": "reverse-linked-list-ii" + }, + { + "leetcode-id": 93, + "title": "Restore IP Addresses", + "difficulty": 2, + "description": "A valid IP address consists of exactly four integers separated by single dots. Each integer is between 0 and 255 (inclusive) and cannot have leading zeros.\n\nFor example, \"0.1.2.201\" and \"192.168.1.1\" are valid IP addresses, but \"0.011.255.245\", \"192.168.1.312\" and \"192.168@1.1\" are invalid IP addresses.\n\nGiven a string s containing only digits, return all possible valid IP addresses that can be formed by inserting dots into s. You are not allowed to reorder or remove any digits in s. You may return the valid IP addresses in any order.", + "examples": [ + "Example 1:\nInput: s = \"25525511135\"\nOutput: [\"255.255.11.135\",\"255.255.111.35\"]", + "Example 2:\nInput: s = \"0000\"\nOutput: [\"0.0.0.0\"]", + "Example 3:\nInput: s = \"101023\"\nOutput: [\"1.0.10.23\",\"1.0.102.3\",\"10.1.0.23\",\"10.10.2.3\",\"101.0.2.3\"]" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 20\ns consists of digits only.", + "tags": [ + "String", + "Backtracking" + ], + "title-slug": "restore-ip-addresses" + }, + { + "leetcode-id": 94, + "title": "Binary Tree Inorder Traversal", + "difficulty": 1, + "description": "Given the root of a binary tree, return the inorder traversal of its nodes' values.", + "examples": [ + "Example 1:\nInput: root = [1,null,2,3]\nOutput: [1,3,2]", + "Example 2:\nInput: root = []\nOutput: []", + "Example 3:\nInput: root = [1]\nOutput: [1]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 100].\n-100 <= Node.val <= 100\n\n\u00a0\nFollow up: Recursive solution is trivial, could you do it iteratively?", + "tags": [ + "Stack", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "binary-tree-inorder-traversal" + }, + { + "leetcode-id": 95, + "title": "Unique Binary Search Trees II", + "difficulty": 2, + "description": "Given an integer n, return all the structurally unique BST's (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the answer in any order.", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: [[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null,null,2],[3,2,null,1]]", + "Example 2:\nInput: n = 1\nOutput: [[1]]" + ], + "constraints": "Constraints:\n\n1 <= n <= 8", + "tags": [ + "Dynamic Programming", + "Backtracking", + "Tree", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "unique-binary-search-trees-ii" + }, + { + "leetcode-id": 96, + "title": "Unique Binary Search Trees", + "difficulty": 2, + "description": "Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n.", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: 5", + "Example 2:\nInput: n = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= n <= 19", + "tags": [ + "Math", + "Dynamic Programming", + "Tree", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "unique-binary-search-trees" + }, + { + "leetcode-id": 97, + "title": "Interleaving String", + "difficulty": 2, + "description": "Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2.\nAn interleaving of two strings s and t is a configuration where s and t are divided into n and m substrings respectively, such that:\n\ns = s1 + s2 + ... + sn\nt = t1 + t2 + ... + tm\n|n - m| <= 1\nThe interleaving is s1 + t1 + s2 + t2 + s3 + t3 + ... or t1 + s1 + t2 + s2 + t3 + s3 + ...\n\nNote: a + b is the concatenation of strings a and b.", + "examples": [ + "Example 1:\nInput: s1 = \"aabcc\", s2 = \"dbbca\", s3 = \"aadbbcbcac\"\nOutput: true\nExplanation: One way to obtain s3 is:\nSplit s1 into s1 = \"aa\" + \"bc\" + \"c\", and s2 into s2 = \"dbbc\" + \"a\".\nInterleaving the two splits, we get \"aa\" + \"dbbc\" + \"bc\" + \"a\" + \"c\" = \"aadbbcbcac\".\nSince s3 can be obtained by interleaving s1 and s2, we return true.", + "Example 2:\nInput: s1 = \"aabcc\", s2 = \"dbbca\", s3 = \"aadbbbaccc\"\nOutput: false\nExplanation: Notice how it is impossible to interleave s2 with any other string to obtain s3.", + "Example 3:\nInput: s1 = \"\", s2 = \"\", s3 = \"\"\nOutput: true" + ], + "constraints": "Constraints:\n\n0 <= s1.length, s2.length <= 100\n0 <= s3.length <= 200\ns1, s2, and s3 consist of lowercase English letters.\n\n\u00a0\nFollow up: Could you solve it using only O(s2.length) additional memory space?", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "interleaving-string" + }, + { + "leetcode-id": 98, + "title": "Validate Binary Search Tree", + "difficulty": 2, + "description": "Given the root of a binary tree, determine if it is a valid binary search tree (BST).\nA valid BST is defined as follows:\n\nThe left subtree of a node contains only nodes with keys less than the node's key.\nThe right subtree of a node contains only nodes with keys greater than the node's key.\nBoth the left and right subtrees must also be binary search trees.", + "examples": [ + "Example 1:\nInput: root = [2,1,3]\nOutput: true", + "Example 2:\nInput: root = [5,1,4,null,null,3,6]\nOutput: false\nExplanation: The root node's value is 5 but its right child's value is 4." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n-2^31 <= Node.val <= 2^31 - 1", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "validate-binary-search-tree" + }, + { + "leetcode-id": 99, + "title": "Recover Binary Search Tree", + "difficulty": 2, + "description": "You are given the root of a binary search tree (BST), where the values of exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure.", + "examples": [ + "Example 1:\nInput: root = [1,3,null,null,2]\nOutput: [3,1,null,null,2]\nExplanation: 3 cannot be a left child of 1 because 3 > 1. Swapping 1 and 3 makes the BST valid.", + "Example 2:\nInput: root = [3,1,4,null,null,2]\nOutput: [2,1,4,null,null,3]\nExplanation: 2 cannot be in the right subtree of 3 because 2 < 3. Swapping 2 and 3 makes the BST valid." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [2, 1000].\n-2^31 <= Node.val <= 2^31 - 1\n\n\u00a0\nFollow up: A solution using O(n) space is pretty straight-forward. Could you devise a constant O(1) space solution?", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "recover-binary-search-tree" + }, + { + "leetcode-id": 100, + "title": "Same Tree", + "difficulty": 1, + "description": "Given the roots of two binary trees p and q, write a function to check if they are the same or not.\nTwo binary trees are considered the same if they are structurally identical, and the nodes have the same value.", + "examples": [ + "Example 1:\nInput: p = [1,2,3], q = [1,2,3]\nOutput: true", + "Example 2:\nInput: p = [1,2], q = [1,null,2]\nOutput: false", + "Example 3:\nInput: p = [1,2,1], q = [1,1,2]\nOutput: false" + ], + "constraints": "Constraints:\n\nThe number of nodes in both trees is in the range [0, 100].\n-10^4 <= Node.val <= 10^4", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "same-tree" + }, + { + "leetcode-id": 101, + "title": "Symmetric Tree", + "difficulty": 1, + "description": "Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).", + "examples": [ + "Example 1:\nInput: root = [1,2,2,3,4,4,3]\nOutput: true", + "Example 2:\nInput: root = [1,2,2,null,3,null,3]\nOutput: false" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 1000].\n-100 <= Node.val <= 100\n\n\u00a0\nFollow up: Could you solve it both recursively and iteratively?", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "symmetric-tree" + }, + { + "leetcode-id": 102, + "title": "Binary Tree Level Order Traversal", + "difficulty": 2, + "description": "Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).", + "examples": [ + "Example 1:\nInput: root = [3,9,20,null,null,15,7]\nOutput: [[3],[9,20],[15,7]]", + "Example 2:\nInput: root = [1]\nOutput: [[1]]", + "Example 3:\nInput: root = []\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 2000].\n-1000 <= Node.val <= 1000", + "tags": [ + "Tree", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "binary-tree-level-order-traversal" + }, + { + "leetcode-id": 103, + "title": "Binary Tree Zigzag Level Order Traversal", + "difficulty": 2, + "description": "Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between).", + "examples": [ + "Example 1:\nInput: root = [3,9,20,null,null,15,7]\nOutput: [[3],[20,9],[15,7]]", + "Example 2:\nInput: root = [1]\nOutput: [[1]]", + "Example 3:\nInput: root = []\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 2000].\n-100 <= Node.val <= 100", + "tags": [ + "Tree", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "binary-tree-zigzag-level-order-traversal" + }, + { + "leetcode-id": 104, + "title": "Maximum Depth of Binary Tree", + "difficulty": 1, + "description": "Given the root of a binary tree, return its maximum depth.\nA binary tree's maximum depth\u00a0is the number of nodes along the longest path from the root node down to the farthest leaf node.", + "examples": [ + "Example 1:\nInput: root = [3,9,20,null,null,15,7]\nOutput: 3", + "Example 2:\nInput: root = [1,null,2]\nOutput: 2" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 10^4].\n-100 <= Node.val <= 100", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "maximum-depth-of-binary-tree" + }, + { + "leetcode-id": 105, + "title": "Construct Binary Tree from Preorder and Inorder Traversal", + "difficulty": 2, + "description": "Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree.", + "examples": [ + "Example 1:\nInput: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]\nOutput: [3,9,20,null,null,15,7]", + "Example 2:\nInput: preorder = [-1], inorder = [-1]\nOutput: [-1]" + ], + "constraints": "Constraints:\n\n1 <= preorder.length <= 3000\ninorder.length == preorder.length\n-3000 <= preorder[i], inorder[i] <= 3000\npreorder and inorder consist of unique values.\nEach value of inorder also appears in preorder.\npreorder is guaranteed to be the preorder traversal of the tree.\ninorder is guaranteed to be the inorder traversal of the tree.", + "tags": [ + "Array", + "Hash Table", + "Divide and Conquer", + "Tree", + "Binary Tree" + ], + "title-slug": "construct-binary-tree-from-preorder-and-inorder-traversal" + }, + { + "leetcode-id": 106, + "title": "Construct Binary Tree from Inorder and Postorder Traversal", + "difficulty": 2, + "description": "Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the same tree, construct and return the binary tree.", + "examples": [ + "Example 1:\nInput: inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]\nOutput: [3,9,20,null,null,15,7]", + "Example 2:\nInput: inorder = [-1], postorder = [-1]\nOutput: [-1]" + ], + "constraints": "Constraints:\n\n1 <= inorder.length <= 3000\npostorder.length == inorder.length\n-3000 <= inorder[i], postorder[i] <= 3000\ninorder and postorder consist of unique values.\nEach value of postorder also appears in inorder.\ninorder is guaranteed to be the inorder traversal of the tree.\npostorder is guaranteed to be the postorder traversal of the tree.", + "tags": [ + "Array", + "Hash Table", + "Divide and Conquer", + "Tree", + "Binary Tree" + ], + "title-slug": "construct-binary-tree-from-inorder-and-postorder-traversal" + }, + { + "leetcode-id": 107, + "title": "Binary Tree Level Order Traversal II", + "difficulty": 2, + "description": "Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root).", + "examples": [ + "Example 1:\nInput: root = [3,9,20,null,null,15,7]\nOutput: [[15,7],[9,20],[3]]", + "Example 2:\nInput: root = [1]\nOutput: [[1]]", + "Example 3:\nInput: root = []\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 2000].\n-1000 <= Node.val <= 1000", + "tags": [ + "Tree", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "binary-tree-level-order-traversal-ii" + }, + { + "leetcode-id": 108, + "title": "Convert Sorted Array to Binary Search Tree", + "difficulty": 1, + "description": "Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.", + "examples": [ + "Example 1:\nInput: nums = [-10,-3,0,5,9]\nOutput: [0,-3,9,-10,null,5]\nExplanation: [0,-10,5,null,-3,null,9] is also accepted:", + "Example 2:\nInput: nums = [1,3]\nOutput: [3,1]\nExplanation: [1,null,3] and [3,1] are both height-balanced BSTs." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-10^4 <= nums[i] <= 10^4\nnums is sorted in a strictly increasing order.", + "tags": [ + "Array", + "Divide and Conquer", + "Tree", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "convert-sorted-array-to-binary-search-tree" + }, + { + "leetcode-id": 109, + "title": "Convert Sorted List to Binary Search Tree", + "difficulty": 2, + "description": "Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height-balanced binary search tree.", + "examples": [ + "Example 1:\nInput: head = [-10,-3,0,5,9]\nOutput: [0,-3,9,-10,null,5]\nExplanation: One possible answer is [0,-3,9,-10,null,5], which represents the shown height balanced BST.", + "Example 2:\nInput: head = []\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in head is in the range [0, 2 * 10^4].\n-10^5 <= Node.val <= 10^5", + "tags": [ + "Linked List", + "Divide and Conquer", + "Tree", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "convert-sorted-list-to-binary-search-tree" + }, + { + "leetcode-id": 110, + "title": "Balanced Binary Tree", + "difficulty": 1, + "description": "Given a binary tree, determine if it is height-balanced.", + "examples": [ + "Example 1:\nInput: root = [3,9,20,null,null,15,7]\nOutput: true", + "Example 2:\nInput: root = [1,2,2,3,3,null,null,4,4]\nOutput: false", + "Example 3:\nInput: root = []\nOutput: true" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 5000].\n-10^4 <= Node.val <= 10^4", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "balanced-binary-tree" + }, + { + "leetcode-id": 111, + "title": "Minimum Depth of Binary Tree", + "difficulty": 1, + "description": "Given a binary tree, find its minimum depth.\nThe minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.\nNote:\u00a0A leaf is a node with no children.", + "examples": [ + "Example 1:\nInput: root = [3,9,20,null,null,15,7]\nOutput: 2", + "Example 2:\nInput: root = [2,null,3,null,4,null,5,null,6]\nOutput: 5" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 10^5].\n-1000 <= Node.val <= 1000", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "minimum-depth-of-binary-tree" + }, + { + "leetcode-id": 112, + "title": "Path Sum", + "difficulty": 1, + "description": "Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum.\nA leaf is a node with no children.", + "examples": [ + "Example 1:\nInput: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22\nOutput: true\nExplanation: The root-to-leaf path with the target sum is shown.", + "Example 2:\nInput: root = [1,2,3], targetSum = 5\nOutput: false\nExplanation: There two root-to-leaf paths in the tree:\n(1 --> 2): The sum is 3.\n(1 --> 3): The sum is 4.\nThere is no root-to-leaf path with sum = 5.", + "Example 3:\nInput: root = [], targetSum = 0\nOutput: false\nExplanation: Since the tree is empty, there are no root-to-leaf paths." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 5000].\n-1000 <= Node.val <= 1000\n-1000 <= targetSum <= 1000", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "path-sum" + }, + { + "leetcode-id": 113, + "title": "Path Sum II", + "difficulty": 2, + "description": "Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum. Each path should be returned as a list of the node values, not node references.\nA root-to-leaf path is a path starting from the root and ending at any leaf node. A leaf is a node with no children.", + "examples": [ + "Example 1:\nInput: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22\nOutput: [[5,4,11,2],[5,8,4,5]]\nExplanation: There are two paths whose sum equals targetSum:\n5 + 4 + 11 + 2 = 22\n5 + 8 + 4 + 5 = 22", + "Example 2:\nInput: root = [1,2,3], targetSum = 5\nOutput: []", + "Example 3:\nInput: root = [1,2], targetSum = 0\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 5000].\n-1000 <= Node.val <= 1000\n-1000 <= targetSum <= 1000", + "tags": [ + "Backtracking", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "path-sum-ii" + }, + { + "leetcode-id": 114, + "title": "Flatten Binary Tree to Linked List", + "difficulty": 2, + "description": "Given the root of a binary tree, flatten the tree into a \"linked list\":\n\nThe \"linked list\" should use the same TreeNode class where the right child pointer points to the next node in the list and the left child pointer is always null.\nThe \"linked list\" should be in the same order as a pre-order traversal of the binary tree.", + "examples": [ + "Example 1:\nInput: root = [1,2,5,3,4,null,6]\nOutput: [1,null,2,null,3,null,4,null,5,null,6]", + "Example 2:\nInput: root = []\nOutput: []", + "Example 3:\nInput: root = [0]\nOutput: [0]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 2000].\n-100 <= Node.val <= 100\n\n\u00a0\nFollow up: Can you flatten the tree in-place (with O(1) extra space)?", + "tags": [ + "Linked List", + "Stack", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "flatten-binary-tree-to-linked-list" + }, + { + "leetcode-id": 115, + "title": "Distinct Subsequences", + "difficulty": 3, + "description": "Given two strings s and t, return the number of distinct subsequences of s which equals t.\nThe test cases are generated so that the answer fits on a 32-bit signed integer.", + "examples": [ + "Example 1:\nInput: s = \"rabbbit\", t = \"rabbit\"\nOutput: 3\nExplanation:\nAs shown below, there are 3 ways you can generate \"rabbit\" from s.\nrabbbit\nrabbbit\nrabbbit", + "Example 2:\nInput: s = \"babgbag\", t = \"bag\"\nOutput: 5\nExplanation:\nAs shown below, there are 5 ways you can generate \"bag\" from s.\nbabgbag\nbabgbag\nbabgbag\nbabgbag\nbabgbag" + ], + "constraints": "Constraints:\n\n1 <= s.length, t.length <= 1000\ns and t consist of English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "distinct-subsequences" + }, + { + "leetcode-id": 116, + "title": "Populating Next Right Pointers in Each Node", + "difficulty": 2, + "description": "You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:\n\nstruct Node {\n int val;\n Node *left;\n Node *right;\n Node *next;\n}\n\nPopulate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.\nInitially, all next pointers are set to NULL.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,4,5,6,7]\nOutput: [1,#,2,3,#,4,5,6,7,#]\nExplanation: Given the above perfect binary tree (Figure A), your function should populate each next pointer to point to its next right node, just like in Figure B. The serialized output is in level order as connected by the next pointers, with '#' signifying the end of each level.", + "Example 2:\nInput: root = []\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 2^12 - 1].\n-1000 <= Node.val <= 1000\n\n\u00a0\nFollow-up:\n\nYou may only use constant extra space.\nThe recursive approach is fine. You may assume implicit stack space does not count as extra space for this problem.", + "tags": [ + "Linked List", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "populating-next-right-pointers-in-each-node" + }, + { + "leetcode-id": 117, + "title": "Populating Next Right Pointers in Each Node II", + "difficulty": 2, + "description": "Given a binary tree\n\nstruct Node {\n int val;\n Node *left;\n Node *right;\n Node *next;\n}\n\nPopulate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.\nInitially, all next pointers are set to NULL.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,4,5,null,7]\nOutput: [1,#,2,3,#,4,5,7,#]\nExplanation: Given the above binary tree (Figure A), your function should populate each next pointer to point to its next right node, just like in Figure B. The serialized output is in level order as connected by the next pointers, with '#' signifying the end of each level.", + "Example 2:\nInput: root = []\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 6000].\n-100 <= Node.val <= 100\n\n\u00a0\nFollow-up:\n\nYou may only use constant extra space.\nThe recursive approach is fine. You may assume implicit stack space does not count as extra space for this problem.", + "tags": [ + "Linked List", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "populating-next-right-pointers-in-each-node-ii" + }, + { + "leetcode-id": 118, + "title": "Pascal's Triangle", + "difficulty": 1, + "description": "Given an integer numRows, return the first numRows of Pascal's triangle.\nIn Pascal's triangle, each number is the sum of the two numbers directly above it as shown:", + "examples": [ + "Example 1:\nInput: numRows = 5\nOutput: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]", + "Example 2:\nInput: numRows = 1\nOutput: [[1]]" + ], + "constraints": "Constraints:\n\n1 <= numRows <= 30", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "pascals-triangle" + }, + { + "leetcode-id": 119, + "title": "Pascal's Triangle II", + "difficulty": 1, + "description": "Given an integer rowIndex, return the rowIndex^th (0-indexed) row of the Pascal's triangle.\nIn Pascal's triangle, each number is the sum of the two numbers directly above it as shown:", + "examples": [ + "Example 1:\nInput: rowIndex = 3\nOutput: [1,3,3,1]", + "Example 2:\nInput: rowIndex = 0\nOutput: [1]", + "Example 3:\nInput: rowIndex = 1\nOutput: [1,1]" + ], + "constraints": "Constraints:\n\n0 <= rowIndex <= 33\n\n\u00a0\nFollow up: Could you optimize your algorithm to use only O(rowIndex) extra space?", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "pascals-triangle-ii" + }, + { + "leetcode-id": 120, + "title": "Triangle", + "difficulty": 2, + "description": "Given a triangle array, return the minimum path sum from top to bottom.\nFor each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row.", + "examples": [ + "Example 1:\nInput: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]\nOutput: 11\nExplanation: The triangle looks like:\n 2\n 3 4\n 6 5 7\n4 1 8 3\nThe minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above).", + "Example 2:\nInput: triangle = [[-10]]\nOutput: -10" + ], + "constraints": "Constraints:\n\n1 <= triangle.length <= 200\ntriangle[0].length == 1\ntriangle[i].length == triangle[i - 1].length + 1\n-10^4 <= triangle[i][j] <= 10^4\n\n\u00a0\nFollow up: Could you\u00a0do this using only O(n) extra space, where n is the total number of rows in the triangle?", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "triangle" + }, + { + "leetcode-id": 121, + "title": "Best Time to Buy and Sell Stock", + "difficulty": 1, + "description": "You are given an array prices where prices[i] is the price of a given stock on the i^th day.\nYou want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.\nReturn the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.", + "examples": [ + "Example 1:\nInput: prices = [7,1,5,3,6,4]\nOutput: 5\nExplanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.\nNote that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.", + "Example 2:\nInput: prices = [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transactions are done and the max profit = 0." + ], + "constraints": "Constraints:\n\n1 <= prices.length <= 10^5\n0 <= prices[i] <= 10^4", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "best-time-to-buy-and-sell-stock" + }, + { + "leetcode-id": 122, + "title": "Best Time to Buy and Sell Stock II", + "difficulty": 2, + "description": "You are given an integer array prices where prices[i] is the price of a given stock on the i^th day.\nOn each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, you can buy it then immediately sell it on the same day.\nFind and return the maximum profit you can achieve.", + "examples": [ + "Example 1:\nInput: prices = [7,1,5,3,6,4]\nOutput: 7\nExplanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.\nThen buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.\nTotal profit is 4 + 3 = 7.", + "Example 2:\nInput: prices = [1,2,3,4,5]\nOutput: 4\nExplanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.\nTotal profit is 4.", + "Example 3:\nInput: prices = [7,6,4,3,1]\nOutput: 0\nExplanation: There is no way to make a positive profit, so we never buy the stock to achieve the maximum profit of 0." + ], + "constraints": "Constraints:\n\n1 <= prices.length <= 3 * 10^4\n0 <= prices[i] <= 10^4", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "best-time-to-buy-and-sell-stock-ii" + }, + { + "leetcode-id": 123, + "title": "Best Time to Buy and Sell Stock III", + "difficulty": 3, + "description": "You are given an array prices where prices[i] is the price of a given stock on the i^th day.\nFind the maximum profit you can achieve. You may complete at most two transactions.\nNote: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).", + "examples": [ + "Example 1:\nInput: prices = [3,3,5,0,0,3,1,4]\nOutput: 6\nExplanation: Buy on day 4 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.\nThen buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3.", + "Example 2:\nInput: prices = [1,2,3,4,5]\nOutput: 4\nExplanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.\nNote that you cannot buy on day 1, buy on day 2 and sell them later, as you are engaging multiple transactions at the same time. You must sell before buying again.", + "Example 3:\nInput: prices = [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transaction is done, i.e. max profit = 0." + ], + "constraints": "Constraints:\n\n1 <= prices.length <= 10^5\n0 <= prices[i] <= 10^5", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "best-time-to-buy-and-sell-stock-iii" + }, + { + "leetcode-id": 124, + "title": "Binary Tree Maximum Path Sum", + "difficulty": 3, + "description": "A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root.\nThe path sum of a path is the sum of the node's values in the path.\nGiven the root of a binary tree, return the maximum path sum of any non-empty path.", + "examples": [ + "Example 1:\nInput: root = [1,2,3]\nOutput: 6\nExplanation: The optimal path is 2 -> 1 -> 3 with a path sum of 2 + 1 + 3 = 6.", + "Example 2:\nInput: root = [-10,9,20,null,null,15,7]\nOutput: 42\nExplanation: The optimal path is 15 -> 20 -> 7 with a path sum of 15 + 20 + 7 = 42." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 3 * 10^4].\n-1000 <= Node.val <= 1000", + "tags": [ + "Dynamic Programming", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "binary-tree-maximum-path-sum" + }, + { + "leetcode-id": 125, + "title": "Valid Palindrome", + "difficulty": 1, + "description": "A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.\nGiven a string s, return true if it is a palindrome, or false otherwise.", + "examples": [ + "Example 1:\nInput: s = \"A man, a plan, a canal: Panama\"\nOutput: true\nExplanation: \"amanaplanacanalpanama\" is a palindrome.", + "Example 2:\nInput: s = \"race a car\"\nOutput: false\nExplanation: \"raceacar\" is not a palindrome.", + "Example 3:\nInput: s = \" \"\nOutput: true\nExplanation: s is an empty string \"\" after removing non-alphanumeric characters.\nSince an empty string reads the same forward and backward, it is a palindrome." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 2 * 10^5\ns consists only of printable ASCII characters.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "valid-palindrome" + }, + { + "leetcode-id": 126, + "title": "Word Ladder II", + "difficulty": 3, + "description": "A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:\n\nEvery adjacent pair of words differs by a single letter.\nEvery si for 1 <= i <= k is in wordList. Note that beginWord does not need to be in wordList.\nsk == endWord\n\nGiven two words, beginWord and endWord, and a dictionary wordList, return all the shortest transformation sequences from beginWord to endWord, or an empty list if no such sequence exists. Each sequence should be returned as a list of the words [beginWord, s1, s2, ..., sk].", + "examples": [ + "Example 1:\nInput: beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]\nOutput: [[\"hit\",\"hot\",\"dot\",\"dog\",\"cog\"],[\"hit\",\"hot\",\"lot\",\"log\",\"cog\"]]\nExplanation:\u00a0There are 2 shortest transformation sequences:\n\"hit\" -> \"hot\" -> \"dot\" -> \"dog\" -> \"cog\"\n\"hit\" -> \"hot\" -> \"lot\" -> \"log\" -> \"cog\"", + "Example 2:\nInput: beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]\nOutput: []\nExplanation: The endWord \"cog\" is not in wordList, therefore there is no valid transformation sequence." + ], + "constraints": "Constraints:\n\n1 <= beginWord.length <= 5\nendWord.length == beginWord.length\n1 <= wordList.length <= 500\nwordList[i].length == beginWord.length\nbeginWord, endWord, and wordList[i] consist of lowercase English letters.\nbeginWord != endWord\nAll the words in wordList are unique.\nThe sum of all shortest transformation sequences does not exceed 10^5.", + "tags": [ + "Hash Table", + "String", + "Backtracking", + "Breadth-First Search" + ], + "title-slug": "word-ladder-ii" + }, + { + "leetcode-id": 127, + "title": "Word Ladder", + "difficulty": 3, + "description": "A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:\n\nEvery adjacent pair of words differs by a single letter.\nEvery si for 1 <= i <= k is in wordList. Note that beginWord does not need to be in wordList.\nsk == endWord\n\nGiven two words, beginWord and endWord, and a dictionary wordList, return the number of words in the shortest transformation sequence from beginWord to endWord, or 0 if no such sequence exists.", + "examples": [ + "Example 1:\nInput: beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]\nOutput: 5\nExplanation: One shortest transformation sequence is \"hit\" -> \"hot\" -> \"dot\" -> \"dog\" -> cog\", which is 5 words long.", + "Example 2:\nInput: beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]\nOutput: 0\nExplanation: The endWord \"cog\" is not in wordList, therefore there is no valid transformation sequence." + ], + "constraints": "Constraints:\n\n1 <= beginWord.length <= 10\nendWord.length == beginWord.length\n1 <= wordList.length <= 5000\nwordList[i].length == beginWord.length\nbeginWord, endWord, and wordList[i] consist of lowercase English letters.\nbeginWord != endWord\nAll the words in wordList are unique.", + "tags": [ + "Hash Table", + "String", + "Breadth-First Search" + ], + "title-slug": "word-ladder" + }, + { + "leetcode-id": 128, + "title": "Longest Consecutive Sequence", + "difficulty": 2, + "description": "Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.\nYou must write an algorithm that runs in\u00a0O(n)\u00a0time.", + "examples": [ + "Example 1:\nInput: nums = [100,4,200,1,3,2]\nOutput: 4\nExplanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.", + "Example 2:\nInput: nums = [0,3,7,2,5,8,4,6,0,1]\nOutput: 9" + ], + "constraints": "Constraints:\n\n0 <= nums.length <= 10^5\n-10^9 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Hash Table", + "Union Find" + ], + "title-slug": "longest-consecutive-sequence" + }, + { + "leetcode-id": 129, + "title": "Sum Root to Leaf Numbers", + "difficulty": 2, + "description": "You are given the root of a binary tree containing digits from 0 to 9 only.\nEach root-to-leaf path in the tree represents a number.\n\nFor example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123.\n\nReturn the total sum of all root-to-leaf numbers. Test cases are generated so that the answer will fit in a 32-bit integer.\nA leaf node is a node with no children.", + "examples": [ + "Example 1:\nInput: root = [1,2,3]\nOutput: 25\nExplanation:\nThe root-to-leaf path 1->2 represents the number 12.\nThe root-to-leaf path 1->3 represents the number 13.\nTherefore, sum = 12 + 13 = 25.", + "Example 2:\nInput: root = [4,9,0,5,1]\nOutput: 1026\nExplanation:\nThe root-to-leaf path 4->9->5 represents the number 495.\nThe root-to-leaf path 4->9->1 represents the number 491.\nThe root-to-leaf path 4->0 represents the number 40.\nTherefore, sum = 495 + 491 + 40 = 1026." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 1000].\n0 <= Node.val <= 9\nThe depth of the tree will not exceed 10.", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "sum-root-to-leaf-numbers" + }, + { + "leetcode-id": 130, + "title": "Surrounded Regions", + "difficulty": 2, + "description": "Given an m x n matrix board containing 'X' and 'O', capture all regions that are 4-directionally\u00a0surrounded by 'X'.\nA region is captured by flipping all 'O's into 'X's in that surrounded region.", + "examples": [ + "Example 1:\nInput: board = [[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"O\",\"O\",\"X\"],[\"X\",\"X\",\"O\",\"X\"],[\"X\",\"O\",\"X\",\"X\"]]\nOutput: [[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"O\",\"X\",\"X\"]]\nExplanation: Notice that an 'O' should not be flipped if:\n- It is on the border, or\n- It is adjacent to an 'O' that should not be flipped.\nThe bottom 'O' is on the border, so it is not flipped.\nThe other three 'O' form a surrounded region, so they are flipped.", + "Example 2:\nInput: board = [[\"X\"]]\nOutput: [[\"X\"]]" + ], + "constraints": "Constraints:\n\nm == board.length\nn == board[i].length\n1 <= m, n <= 200\nboard[i][j] is 'X' or 'O'.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Matrix" + ], + "title-slug": "surrounded-regions" + }, + { + "leetcode-id": 131, + "title": "Palindrome Partitioning", + "difficulty": 2, + "description": "Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.", + "examples": [ + "Example 1:\nInput: s = \"aab\"\nOutput: [[\"a\",\"a\",\"b\"],[\"aa\",\"b\"]]", + "Example 2:\nInput: s = \"a\"\nOutput: [[\"a\"]]" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 16\ns contains only lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming", + "Backtracking" + ], + "title-slug": "palindrome-partitioning" + }, + { + "leetcode-id": 132, + "title": "Palindrome Partitioning II", + "difficulty": 3, + "description": "Given a string s, partition s such that every substring of the partition is a palindrome.\nReturn the minimum cuts needed for a palindrome partitioning of s.", + "examples": [ + "Example 1:\nInput: s = \"aab\"\nOutput: 1\nExplanation: The palindrome partitioning [\"aa\",\"b\"] could be produced using 1 cut.", + "Example 2:\nInput: s = \"a\"\nOutput: 0", + "Example 3:\nInput: s = \"ab\"\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 2000\ns consists of lowercase English letters only.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "palindrome-partitioning-ii" + }, + { + "leetcode-id": 133, + "title": "Clone Graph", + "difficulty": 2, + "description": "Given a reference of a node in a connected undirected graph.\nReturn a deep copy (clone) of the graph.\nEach node in the graph contains a value (int) and a list (List[Node]) of its neighbors.\n\nclass Node {\n public int val;\n public List neighbors;\n}\n\n\u00a0\nTest case format:\nFor simplicity, each node's value is the same as the node's index (1-indexed). For example, the first node with val == 1, the second node with val == 2, and so on. The graph is represented in the test case using an adjacency list.\nAn adjacency list is a collection of unordered lists used to represent a finite graph. Each list describes the set of neighbors of a node in the graph.\nThe given node will always be the first node with val = 1. You must return the copy of the given node as a reference to the cloned graph.", + "examples": [ + "Example 1:\nInput: adjList = [[2,4],[1,3],[2,4],[1,3]]\nOutput: [[2,4],[1,3],[2,4],[1,3]]\nExplanation: There are 4 nodes in the graph.\n1st node (val = 1)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).\n2nd node (val = 2)'s neighbors are 1st node (val = 1) and 3rd node (val = 3).\n3rd node (val = 3)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).\n4th node (val = 4)'s neighbors are 1st node (val = 1) and 3rd node (val = 3).", + "Example 2:\nInput: adjList = [[]]\nOutput: [[]]\nExplanation: Note that the input contains one empty list. The graph consists of only one node with val = 1 and it does not have any neighbors.", + "Example 3:\nInput: adjList = []\nOutput: []\nExplanation: This an empty graph, it does not have any nodes." + ], + "constraints": "Constraints:\n\nThe number of nodes in the graph is in the range [0, 100].\n1 <= Node.val <= 100\nNode.val is unique for each node.\nThere are no repeated edges and no self-loops in the graph.\nThe Graph is connected and all nodes can be visited starting from the given node.", + "tags": [ + "Hash Table", + "Depth-First Search", + "Breadth-First Search", + "Graph" + ], + "title-slug": "clone-graph" + }, + { + "leetcode-id": 134, + "title": "Gas Station", + "difficulty": 2, + "description": "There are n gas stations along a circular route, where the amount of gas at the i^th station is gas[i].\nYou have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the i^th station to its next (i + 1)^th station. You begin the journey with an empty tank at one of the gas stations.\nGiven two integer arrays gas and cost, return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1. If there exists a solution, it is guaranteed to be unique", + "examples": [ + "Example 1:\nInput: gas = [1,2,3,4,5], cost = [3,4,5,1,2]\nOutput: 3\nExplanation:\nStart at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4\nTravel to station 4. Your tank = 4 - 1 + 5 = 8\nTravel to station 0. Your tank = 8 - 2 + 1 = 7\nTravel to station 1. Your tank = 7 - 3 + 2 = 6\nTravel to station 2. Your tank = 6 - 4 + 3 = 5\nTravel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.\nTherefore, return 3 as the starting index.", + "Example 2:\nInput: gas = [2,3,4], cost = [3,4,3]\nOutput: -1\nExplanation:\nYou can't start at station 0 or 1, as there is not enough gas to travel to the next station.\nLet's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4\nTravel to station 0. Your tank = 4 - 3 + 2 = 3\nTravel to station 1. Your tank = 3 - 3 + 3 = 3\nYou cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.\nTherefore, you can't travel around the circuit once no matter where you start." + ], + "constraints": "Constraints:\n\nn == gas.length == cost.length\n1 <= n <= 10^5\n0 <= gas[i], cost[i] <= 10^4", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "gas-station" + }, + { + "leetcode-id": 135, + "title": "Candy", + "difficulty": 3, + "description": "There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings.\nYou are giving candies to these children subjected to the following requirements:\n\nEach child must have at least one candy.\nChildren with a higher rating get more candies than their neighbors.\n\nReturn the minimum number of candies you need to have to distribute the candies to the children.", + "examples": [ + "Example 1:\nInput: ratings = [1,0,2]\nOutput: 5\nExplanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively.", + "Example 2:\nInput: ratings = [1,2,2]\nOutput: 4\nExplanation: You can allocate to the first, second and third child with 1, 2, 1 candies respectively.\nThe third child gets 1 candy because it satisfies the above two conditions." + ], + "constraints": "Constraints:\n\nn == ratings.length\n1 <= n <= 2 * 10^4\n0 <= ratings[i] <= 2 * 10^4", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "candy" + }, + { + "leetcode-id": 136, + "title": "Single Number", + "difficulty": 1, + "description": "Given a non-empty\u00a0array of integers nums, every element appears twice except for one. Find that single one.\nYou must\u00a0implement a solution with a linear runtime complexity and use\u00a0only constant\u00a0extra space.", + "examples": [ + "Example 1:\nInput: nums = [2,2,1]\nOutput: 1", + "Example 2:\nInput: nums = [4,1,2,1,2]\nOutput: 4", + "Example 3:\nInput: nums = [1]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 3 * 10^4\n-3 * 10^4 <= nums[i] <= 3 * 10^4\nEach element in the array appears twice except for one element which appears only once.", + "tags": [ + "Array", + "Bit Manipulation" + ], + "title-slug": "single-number" + }, + { + "leetcode-id": 137, + "title": "Single Number II", + "difficulty": 2, + "description": "Given an integer array nums where\u00a0every element appears three times except for one, which appears exactly once. Find the single element and return it.\nYou must\u00a0implement a solution with a linear runtime complexity and use\u00a0only constant\u00a0extra space.", + "examples": [ + "Example 1:\nInput: nums = [2,2,3,2]\nOutput: 3", + "Example 2:\nInput: nums = [0,1,0,1,0,1,99]\nOutput: 99" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 3 * 10^4\n-2^31 <= nums[i] <= 2^31 - 1\nEach element in nums appears exactly three times except for one element which appears once.", + "tags": [ + "Array", + "Bit Manipulation" + ], + "title-slug": "single-number-ii" + }, + { + "leetcode-id": 138, + "title": "Copy List with Random Pointer", + "difficulty": 2, + "description": "A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null.\nConstruct a deep copy of the list. The deep copy should consist of exactly n brand new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and random pointer of the new nodes should point to new nodes in the copied list such that the pointers in the original list and copied list represent the same list state. None of the pointers in the new list should point to nodes in the original list.\nFor example, if there are two nodes X and Y in the original list, where X.random --> Y, then for the corresponding two nodes x and y in the copied list, x.random --> y.\nReturn the head of the copied linked list.\nThe linked list is represented in the input/output as a list of n nodes. Each node is represented as a pair of [val, random_index] where:\n\nval: an integer representing Node.val\nrandom_index: the index of the node (range from 0 to n-1) that the random pointer points to, or null if it does not point to any node.\n\nYour code will only be given the head of the original linked list.", + "examples": [ + "Example 1:\nInput: head = [[7,null],[13,0],[11,4],[10,2],[1,0]]\nOutput: [[7,null],[13,0],[11,4],[10,2],[1,0]]", + "Example 2:\nInput: head = [[1,1],[2,1]]\nOutput: [[1,1],[2,1]]", + "Example 3:\nInput: head = [[3,null],[3,0],[3,null]]\nOutput: [[3,null],[3,0],[3,null]]" + ], + "constraints": "Constraints:\n\n0 <= n <= 1000\n-10^4 <= Node.val <= 10^4\nNode.random is null or is pointing to some node in the linked list.", + "tags": [ + "Hash Table", + "Linked List" + ], + "title-slug": "copy-list-with-random-pointer" + }, + { + "leetcode-id": 139, + "title": "Word Break", + "difficulty": 2, + "description": "Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.\nNote that the same word in the dictionary may be reused multiple times in the segmentation.", + "examples": [ + "Example 1:\nInput: s = \"leetcode\", wordDict = [\"leet\",\"code\"]\nOutput: true\nExplanation: Return true because \"leetcode\" can be segmented as \"leet code\".", + "Example 2:\nInput: s = \"applepenapple\", wordDict = [\"apple\",\"pen\"]\nOutput: true\nExplanation: Return true because \"applepenapple\" can be segmented as \"apple pen apple\".\nNote that you are allowed to reuse a dictionary word.", + "Example 3:\nInput: s = \"catsandog\", wordDict = [\"cats\",\"dog\",\"sand\",\"and\",\"cat\"]\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 300\n1 <= wordDict.length <= 1000\n1 <= wordDict[i].length <= 20\ns and wordDict[i] consist of only lowercase English letters.\nAll the strings of wordDict are unique.", + "tags": [ + "Array", + "Hash Table", + "String", + "Dynamic Programming", + "Trie", + "Memoization" + ], + "title-slug": "word-break" + }, + { + "leetcode-id": 140, + "title": "Word Break II", + "difficulty": 3, + "description": "Given a string s and a dictionary of strings wordDict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in any order.\nNote that the same word in the dictionary may be reused multiple times in the segmentation.", + "examples": [ + "Example 1:\nInput: s = \"catsanddog\", wordDict = [\"cat\",\"cats\",\"and\",\"sand\",\"dog\"]\nOutput: [\"cats and dog\",\"cat sand dog\"]", + "Example 2:\nInput: s = \"pineapplepenapple\", wordDict = [\"apple\",\"pen\",\"applepen\",\"pine\",\"pineapple\"]\nOutput: [\"pine apple pen apple\",\"pineapple pen apple\",\"pine applepen apple\"]\nExplanation: Note that you are allowed to reuse a dictionary word.", + "Example 3:\nInput: s = \"catsandog\", wordDict = [\"cats\",\"dog\",\"sand\",\"and\",\"cat\"]\nOutput: []" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 20\n1 <= wordDict.length <= 1000\n1 <= wordDict[i].length <= 10\ns and wordDict[i] consist of only lowercase English letters.\nAll the strings of wordDict are unique.\nInput is generated in a way that the length of the answer doesn't exceed\u00a010^5.", + "tags": [ + "Array", + "Hash Table", + "String", + "Dynamic Programming", + "Backtracking", + "Trie", + "Memoization" + ], + "title-slug": "word-break-ii" + }, + { + "leetcode-id": 141, + "title": "Linked List Cycle", + "difficulty": 1, + "description": "Given head, the head of a linked list, determine if the linked list has a cycle in it.\nThere is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the\u00a0next\u00a0pointer. Internally, pos\u00a0is used to denote the index of the node that\u00a0tail's\u00a0next\u00a0pointer is connected to.\u00a0Note that\u00a0pos\u00a0is not passed as a parameter.\nReturn\u00a0true if there is a cycle in the linked list. Otherwise, return false.", + "examples": [ + "Example 1:\nInput: head = [3,2,0,-4], pos = 1\nOutput: true\nExplanation: There is a cycle in the linked list, where the tail connects to the 1st node (0-indexed).", + "Example 2:\nInput: head = [1,2], pos = 0\nOutput: true\nExplanation: There is a cycle in the linked list, where the tail connects to the 0th node.", + "Example 3:\nInput: head = [1], pos = -1\nOutput: false\nExplanation: There is no cycle in the linked list." + ], + "constraints": "Constraints:\n\nThe number of the nodes in the list is in the range [0, 10^4].\n-10^5 <= Node.val <= 10^5\npos is -1 or a valid index in the linked-list.\n\n\u00a0\nFollow up: Can you solve it using O(1) (i.e. constant) memory?", + "tags": [ + "Hash Table", + "Linked List", + "Two Pointers" + ], + "title-slug": "linked-list-cycle" + }, + { + "leetcode-id": 142, + "title": "Linked List Cycle II", + "difficulty": 2, + "description": "Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.\nThere is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to (0-indexed). It is -1 if there is no cycle. Note that pos is not passed as a parameter.\nDo not modify the linked list.", + "examples": [ + "Example 1:\nInput: head = [3,2,0,-4], pos = 1\nOutput: tail connects to node index 1\nExplanation: There is a cycle in the linked list, where tail connects to the second node.", + "Example 2:\nInput: head = [1,2], pos = 0\nOutput: tail connects to node index 0\nExplanation: There is a cycle in the linked list, where tail connects to the first node.", + "Example 3:\nInput: head = [1], pos = -1\nOutput: no cycle\nExplanation: There is no cycle in the linked list." + ], + "constraints": "Constraints:\n\nThe number of the nodes in the list is in the range [0, 10^4].\n-10^5 <= Node.val <= 10^5\npos is -1 or a valid index in the linked-list.\n\n\u00a0\nFollow up: Can you solve it using O(1) (i.e. constant) memory?", + "tags": [ + "Hash Table", + "Linked List", + "Two Pointers" + ], + "title-slug": "linked-list-cycle-ii" + }, + { + "leetcode-id": 143, + "title": "Reorder List", + "difficulty": 2, + "description": "You are given the head of a singly linked-list. The list can be represented as:\n\nL0 \u2192 L1 \u2192 \u2026 \u2192 Ln - 1 \u2192 Ln\n\nReorder the list to be on the following form:\n\nL0 \u2192 Ln \u2192 L1 \u2192 Ln - 1 \u2192 L2 \u2192 Ln - 2 \u2192 \u2026\n\nYou may not modify the values in the list's nodes. Only nodes themselves may be changed.", + "examples": [ + "Example 1:\nInput: head = [1,2,3,4]\nOutput: [1,4,2,3]", + "Example 2:\nInput: head = [1,2,3,4,5]\nOutput: [1,5,2,4,3]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [1, 5 * 10^4].\n1 <= Node.val <= 1000", + "tags": [ + "Linked List", + "Two Pointers", + "Stack", + "Recursion" + ], + "title-slug": "reorder-list" + }, + { + "leetcode-id": 144, + "title": "Binary Tree Preorder Traversal", + "difficulty": 1, + "description": "Given the root of a binary tree, return the preorder traversal of its nodes' values.", + "examples": [ + "Example 1:\nInput: root = [1,null,2,3]\nOutput: [1,2,3]", + "Example 2:\nInput: root = []\nOutput: []", + "Example 3:\nInput: root = [1]\nOutput: [1]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 100].\n-100 <= Node.val <= 100\n\n\u00a0\nFollow up: Recursive solution is trivial, could you do it iteratively?", + "tags": [ + "Stack", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "binary-tree-preorder-traversal" + }, + { + "leetcode-id": 145, + "title": "Binary Tree Postorder Traversal", + "difficulty": 1, + "description": "Given the root of a\u00a0binary tree, return the postorder traversal of its nodes' values.", + "examples": [ + "Example 1:\nInput: root = [1,null,2,3]\nOutput: [3,2,1]", + "Example 2:\nInput: root = []\nOutput: []", + "Example 3:\nInput: root = [1]\nOutput: [1]" + ], + "constraints": "Constraints:\n\nThe number of the nodes in the tree is in the range [0, 100].\n-100 <= Node.val <= 100\n\n\u00a0\nFollow up: Recursive solution is trivial, could you do it iteratively?", + "tags": [ + "Stack", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "binary-tree-postorder-traversal" + }, + { + "leetcode-id": 146, + "title": "LRU Cache", + "difficulty": 2, + "description": "Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.\nImplement the LRUCache class:\n\nLRUCache(int capacity) Initialize the LRU cache with positive size capacity.\nint get(int key) Return the value of the key if the key exists, otherwise return -1.\nvoid put(int key, int value) Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used key.\n\nThe functions get and put must each run in O(1) average time complexity.", + "examples": [ + "Example 1:\nInput\n[\"LRUCache\", \"put\", \"put\", \"get\", \"put\", \"get\", \"put\", \"get\", \"get\", \"get\"]\n[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]\nOutput\n[null, null, null, 1, null, -1, null, -1, 3, 4]\n\nExplanation\nLRUCache lRUCache = new LRUCache(2);\nlRUCache.put(1, 1); // cache is {1=1}\nlRUCache.put(2, 2); // cache is {1=1, 2=2}\nlRUCache.get(1); // return 1\nlRUCache.put(3, 3); // LRU key was 2, evicts key 2, cache is {1=1, 3=3}\nlRUCache.get(2); // returns -1 (not found)\nlRUCache.put(4, 4); // LRU key was 1, evicts key 1, cache is {4=4, 3=3}\nlRUCache.get(1); // return -1 (not found)\nlRUCache.get(3); // return 3\nlRUCache.get(4); // return 4" + ], + "constraints": "Constraints:\n\n1 <= capacity <= 3000\n0 <= key <= 10^4\n0 <= value <= 10^5\nAt most 2 * 10^5 calls will be made to get and put.", + "tags": [ + "Hash Table", + "Linked List", + "Design", + "Doubly-Linked List" + ], + "title-slug": "lru-cache" + }, + { + "leetcode-id": 147, + "title": "Insertion Sort List", + "difficulty": 2, + "description": "Given the head of a singly linked list, sort the list using insertion sort, and return the sorted list's head.\nThe steps of the insertion sort algorithm:\n\nInsertion sort iterates, consuming one input element each repetition and growing a sorted output list.\nAt each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list and inserts it there.\nIt repeats until no input elements remain.\n\nThe following is a graphical example of the insertion sort algorithm. The partially sorted list (black) initially contains only the first element in the list. One element (red) is removed from the input data and inserted in-place into the sorted list with each iteration.", + "examples": [ + "Example 1:\nInput: head = [4,2,1,3]\nOutput: [1,2,3,4]", + "Example 2:\nInput: head = [-1,5,3,4,0]\nOutput: [-1,0,3,4,5]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [1, 5000].\n-5000 <= Node.val <= 5000", + "tags": [ + "Linked List", + "Sorting" + ], + "title-slug": "insertion-sort-list" + }, + { + "leetcode-id": 148, + "title": "Sort List", + "difficulty": 2, + "description": "Given the head of a linked list, return the list after sorting it in ascending order.", + "examples": [ + "Example 1:\nInput: head = [4,2,1,3]\nOutput: [1,2,3,4]", + "Example 2:\nInput: head = [-1,5,3,4,0]\nOutput: [-1,0,3,4,5]", + "Example 3:\nInput: head = []\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [0, 5 * 10^4].\n-10^5 <= Node.val <= 10^5\n\n\u00a0\nFollow up: Can you sort the linked list in O(n logn) time and O(1) memory (i.e. constant space)?", + "tags": [ + "Linked List", + "Two Pointers", + "Divide and Conquer", + "Sorting", + "Merge Sort" + ], + "title-slug": "sort-list" + }, + { + "leetcode-id": 149, + "title": "Max Points on a Line", + "difficulty": 3, + "description": "Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line.", + "examples": [ + "Example 1:\nInput: points = [[1,1],[2,2],[3,3]]\nOutput: 3", + "Example 2:\nInput: points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= points.length <= 300\npoints[i].length == 2\n-10^4 <= xi, yi <= 10^4\nAll the points are unique.", + "tags": [ + "Array", + "Hash Table", + "Math", + "Geometry" + ], + "title-slug": "max-points-on-a-line" + }, + { + "leetcode-id": 150, + "title": "Evaluate Reverse Polish Notation", + "difficulty": 2, + "description": "You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation.\nEvaluate the expression. Return an integer that represents the value of the expression.\nNote that:\n\nThe valid operators are '+', '-', '*', and '/'.\nEach operand may be an integer or another expression.\nThe division between two integers always truncates toward zero.\nThere will not be any division by zero.\nThe input represents a valid arithmetic expression in a reverse polish notation.\nThe answer and all the intermediate calculations can be represented in a 32-bit integer.", + "examples": [ + "Example 1:\nInput: tokens = [\"2\",\"1\",\"+\",\"3\",\"*\"]\nOutput: 9\nExplanation: ((2 + 1) * 3) = 9", + "Example 2:\nInput: tokens = [\"4\",\"13\",\"5\",\"/\",\"+\"]\nOutput: 6\nExplanation: (4 + (13 / 5)) = 6", + "Example 3:\nInput: tokens = [\"10\",\"6\",\"9\",\"3\",\"+\",\"-11\",\"*\",\"/\",\"*\",\"17\",\"+\",\"5\",\"+\"]\nOutput: 22\nExplanation: ((10 * (6 / ((9 + 3) * -11))) + 17) + 5\n= ((10 * (6 / (12 * -11))) + 17) + 5\n= ((10 * (6 / -132)) + 17) + 5\n= ((10 * 0) + 17) + 5\n= (0 + 17) + 5\n= 17 + 5\n= 22" + ], + "constraints": "Constraints:\n\n1 <= tokens.length <= 10^4\ntokens[i] is either an operator: \"+\", \"-\", \"*\", or \"/\", or an integer in the range [-200, 200].", + "tags": [ + "Array", + "Math", + "Stack" + ], + "title-slug": "evaluate-reverse-polish-notation" + }, + { + "leetcode-id": 151, + "title": "Reverse Words in a String", + "difficulty": 2, + "description": "Given an input string s, reverse the order of the words.\nA word is defined as a sequence of non-space characters. The words in s will be separated by at least one space.\nReturn a string of the words in reverse order concatenated by a single space.\nNote that s may contain leading or trailing spaces or multiple spaces between two words. The returned string should only have a single space separating the words. Do not include any extra spaces.", + "examples": [ + "Example 1:\nInput: s = \"the sky is blue\"\nOutput: \"blue is sky the\"", + "Example 2:\nInput: s = \" hello world \"\nOutput: \"world hello\"\nExplanation: Your reversed string should not contain leading or trailing spaces.", + "Example 3:\nInput: s = \"a good example\"\nOutput: \"example good a\"\nExplanation: You need to reduce multiple spaces between two words to a single space in the reversed string." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^4\ns contains English letters (upper-case and lower-case), digits, and spaces ' '.\nThere is at least one word in s.\n\n\u00a0\nFollow-up:\u00a0If the string data type is mutable in your language, can\u00a0you solve it\u00a0in-place\u00a0with\u00a0O(1)\u00a0extra space?", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "reverse-words-in-a-string" + }, + { + "leetcode-id": 152, + "title": "Maximum Product Subarray", + "difficulty": 2, + "description": "Given an integer array nums, find a subarray that has the largest product, and return the product.\nThe test cases are generated so that the answer will fit in a 32-bit integer.", + "examples": [ + "Example 1:\nInput: nums = [2,3,-2,4]\nOutput: 6\nExplanation: [2,3] has the largest product 6.", + "Example 2:\nInput: nums = [-2,0,-1]\nOutput: 0\nExplanation: The result cannot be 2, because [-2,-1] is not a subarray." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 2 * 10^4\n-10 <= nums[i] <= 10\nThe product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "maximum-product-subarray" + }, + { + "leetcode-id": 153, + "title": "Find Minimum in Rotated Sorted Array", + "difficulty": 2, + "description": "Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:\n\n[4,5,6,7,0,1,2] if it was rotated 4 times.\n[0,1,2,4,5,6,7] if it was rotated 7 times.\n\nNotice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].\nGiven the sorted rotated array nums of unique elements, return the minimum element of this array.\nYou must write an algorithm that runs in\u00a0O(log n) time.", + "examples": [ + "Example 1:\nInput: nums = [3,4,5,1,2]\nOutput: 1\nExplanation: The original array was [1,2,3,4,5] rotated 3 times.", + "Example 2:\nInput: nums = [4,5,6,7,0,1,2]\nOutput: 0\nExplanation: The original array was [0,1,2,4,5,6,7] and it was rotated 4 times.", + "Example 3:\nInput: nums = [11,13,15,17]\nOutput: 11\nExplanation: The original array was [11,13,15,17] and it was rotated 4 times." + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 5000\n-5000 <= nums[i] <= 5000\nAll the integers of nums are unique.\nnums is sorted and rotated between 1 and n times.", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "find-minimum-in-rotated-sorted-array" + }, + { + "leetcode-id": 154, + "title": "Find Minimum in Rotated Sorted Array II", + "difficulty": 3, + "description": "Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become:\n\n[4,5,6,7,0,1,4] if it was rotated 4 times.\n[0,1,4,4,5,6,7] if it was rotated 7 times.\n\nNotice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].\nGiven the sorted rotated array nums that may contain duplicates, return the minimum element of this array.\nYou must decrease the overall operation steps as much as possible.", + "examples": [ + "Example 1:\nInput: nums = [1,3,5]\nOutput: 1", + "Example 2:\nInput: nums = [2,2,2,0,1]\nOutput: 0" + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 5000\n-5000 <= nums[i] <= 5000\nnums is sorted and rotated between 1 and n times.\n\n\u00a0\nFollow up: This problem is similar to\u00a0Find Minimum in Rotated Sorted Array, but\u00a0nums may contain duplicates. Would this affect the runtime complexity? How and why?", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "find-minimum-in-rotated-sorted-array-ii" + }, + { + "leetcode-id": 155, + "title": "Min Stack", + "difficulty": 2, + "description": "Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.\nImplement the MinStack class:\n\nMinStack() initializes the stack object.\nvoid push(int val) pushes the element val onto the stack.\nvoid pop() removes the element on the top of the stack.\nint top() gets the top element of the stack.\nint getMin() retrieves the minimum element in the stack.\n\nYou must implement a solution with O(1) time complexity for each function.", + "examples": [ + "Example 1:\nInput\n[\"MinStack\",\"push\",\"push\",\"push\",\"getMin\",\"pop\",\"top\",\"getMin\"]\n[[],[-2],[0],[-3],[],[],[],[]]\n\nOutput\n[null,null,null,null,-3,null,0,-2]\n\nExplanation\nMinStack minStack = new MinStack();\nminStack.push(-2);\nminStack.push(0);\nminStack.push(-3);\nminStack.getMin(); // return -3\nminStack.pop();\nminStack.top(); // return 0\nminStack.getMin(); // return -2" + ], + "constraints": "Constraints:\n\n-2^31 <= val <= 2^31 - 1\nMethods pop, top and getMin operations will always be called on non-empty stacks.\nAt most 3 * 10^4 calls will be made to push, pop, top, and getMin.", + "tags": [ + "Stack", + "Design" + ], + "title-slug": "min-stack" + }, + { + "leetcode-id": 160, + "title": "Intersection of Two Linked Lists", + "difficulty": 1, + "description": "Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.\nFor example, the following two linked lists begin to intersect at node c1:\n\nThe test cases are generated such that there are no cycles anywhere in the entire linked structure.\nNote that the linked lists must retain their original structure after the function returns.\nCustom Judge:\nThe inputs to the judge are given as follows (your program is not given these inputs):\n\nintersectVal - The value of the node where the intersection occurs. This is 0 if there is no intersected node.\nlistA - The first linked list.\nlistB - The second linked list.\nskipA - The number of nodes to skip ahead in listA (starting from the head) to get to the intersected node.\nskipB - The number of nodes to skip ahead in listB (starting from the head) to get to the intersected node.\n\nThe judge will then create the linked structure based on these inputs and pass the two heads, headA and headB to your program. If you correctly return the intersected node, then your solution will be accepted.", + "examples": [ + "Example 1:\nInput: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,6,1,8,4,5], skipA = 2, skipB = 3\nOutput: Intersected at '8'\nExplanation: The intersected node's value is 8 (note that this must not be 0 if the two lists intersect).\nFrom the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,6,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B.\n- Note that the intersected node's value is not 1 because the nodes with value 1 in A and B (2^nd node in A and 3^rd node in B) are different node references. In other words, they point to two different locations in memory, while the nodes with value 8 in A and B (3^rd node in A and 4^th node in B) point to the same location in memory.", + "Example 2:\nInput: intersectVal = 2, listA = [1,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1\nOutput: Intersected at '2'\nExplanation: The intersected node's value is 2 (note that this must not be 0 if the two lists intersect).\nFrom the head of A, it reads as [1,9,1,2,4]. From the head of B, it reads as [3,2,4]. There are 3 nodes before the intersected node in A; There are 1 node before the intersected node in B.", + "Example 3:\nInput: intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2\nOutput: No intersection\nExplanation: From the head of A, it reads as [2,6,4]. From the head of B, it reads as [1,5]. Since the two lists do not intersect, intersectVal must be 0, while skipA and skipB can be arbitrary values.\nExplanation: The two lists do not intersect, so return null." + ], + "constraints": "Constraints:\n\nThe number of nodes of listA is in the m.\nThe number of nodes of listB is in the n.\n1 <= m, n <= 3 * 10^4\n1 <= Node.val <= 10^5\n0 <= skipA <\u00a0m\n0 <= skipB <\u00a0n\nintersectVal is 0 if listA and listB do not intersect.\nintersectVal == listA[skipA] == listB[skipB] if listA and listB intersect.\n\n\u00a0\nFollow up: Could you write a solution that runs in O(m + n) time and use only O(1) memory?", + "tags": [ + "Hash Table", + "Linked List", + "Two Pointers" + ], + "title-slug": "intersection-of-two-linked-lists" + }, + { + "leetcode-id": 162, + "title": "Find Peak Element", + "difficulty": 2, + "description": "A peak element is an element that is strictly greater than its neighbors.\nGiven a 0-indexed integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.\nYou may imagine that nums[-1] = nums[n] = -\u221e. In other words, an element is always considered to be strictly greater than a neighbor that is outside the array.\nYou must write an algorithm that runs in O(log n) time.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,1]\nOutput: 2\nExplanation: 3 is a peak element and your function should return the index number 2.", + "Example 2:\nInput: nums = [1,2,1,3,5,6,4]\nOutput: 5\nExplanation: Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n-2^31 <= nums[i] <= 2^31 - 1\nnums[i] != nums[i + 1] for all valid i.", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "find-peak-element" + }, + { + "leetcode-id": 164, + "title": "Maximum Gap", + "difficulty": 3, + "description": "Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains less than two elements, return 0.\nYou must write an algorithm that runs in linear time and uses linear extra space.", + "examples": [ + "Example 1:\nInput: nums = [3,6,9,1]\nOutput: 3\nExplanation: The sorted form of the array is [1,3,6,9], either (3,6) or (6,9) has the maximum difference 3.", + "Example 2:\nInput: nums = [10]\nOutput: 0\nExplanation: The array contains less than 2 elements, therefore return 0." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Sorting", + "Bucket Sort", + "Radix Sort" + ], + "title-slug": "maximum-gap" + }, + { + "leetcode-id": 165, + "title": "Compare Version Numbers", + "difficulty": 2, + "description": "Given two version numbers,\u00a0version1 and version2, compare them.\n\n\nVersion numbers consist of one or more revisions joined by a dot\u00a0'.'. Each revision\u00a0consists of digits\u00a0and may contain leading zeros. Every revision contains at least one character. Revisions are 0-indexed from left to right, with the leftmost revision being revision 0, the next revision being revision 1, and so on. For example\u00a02.5.33\u00a0and\u00a00.1\u00a0are valid version numbers.\nTo compare version numbers, compare their revisions in left-to-right order. Revisions are compared using their\u00a0integer value ignoring any leading zeros. This means that revisions\u00a01\u00a0and\u00a0001\u00a0are considered\u00a0equal. If a version number does not specify a revision at an index, then\u00a0treat the revision as\u00a00. For example, version\u00a01.0 is less than version\u00a01.1\u00a0because their revision 0s are the same, but their revision 1s are\u00a00\u00a0and\u00a01\u00a0respectively, and\u00a00 < 1.\nReturn the following:\n\nIf version1 < version2, return -1.\nIf version1 > version2, return 1.\nOtherwise, return 0.", + "examples": [ + "Example 1:\nInput: version1 = \"1.01\", version2 = \"1.001\"\nOutput: 0\nExplanation: Ignoring leading zeroes, both \"01\" and \"001\" represent the same integer \"1\".", + "Example 2:\nInput: version1 = \"1.0\", version2 = \"1.0.0\"\nOutput: 0\nExplanation: version1 does not specify revision 2, which means it is treated as \"0\".", + "Example 3:\nInput: version1 = \"0.1\", version2 = \"1.1\"\nOutput: -1\nExplanation: version1's revision 0 is \"0\", while version2's revision 0 is \"1\". 0 < 1, so version1 < version2." + ], + "constraints": "Constraints:\n\n1 <= version1.length, version2.length <= 500\nversion1 and version2\u00a0only contain digits and '.'.\nversion1 and version2\u00a0are valid version numbers.\nAll the given revisions in\u00a0version1 and version2\u00a0can be stored in\u00a0a\u00a032-bit integer.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "compare-version-numbers" + }, + { + "leetcode-id": 166, + "title": "Fraction to Recurring Decimal", + "difficulty": 2, + "description": "Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.\nIf the fractional part is repeating, enclose the repeating part in parentheses.\nIf multiple answers are possible, return any of them.\nIt is guaranteed that the length of the answer string is less than 10^4 for all the given inputs.", + "examples": [ + "Example 1:\nInput: numerator = 1, denominator = 2\nOutput: \"0.5\"", + "Example 2:\nInput: numerator = 2, denominator = 1\nOutput: \"2\"", + "Example 3:\nInput: numerator = 4, denominator = 333\nOutput: \"0.(012)\"" + ], + "constraints": "Constraints:\n\n-2^31 <=\u00a0numerator, denominator <= 2^31 - 1\ndenominator != 0", + "tags": [ + "Hash Table", + "Math", + "String" + ], + "title-slug": "fraction-to-recurring-decimal" + }, + { + "leetcode-id": 167, + "title": "Two Sum II - Input Array Is Sorted", + "difficulty": 2, + "description": "Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <\u00a0numbers.length.\nReturn the indices of the two numbers, index1 and index2, added by one as an integer array [index1, index2] of length 2.\nThe tests are generated such that there is exactly one solution. You may not use the same element twice.\nYour solution must use only constant extra space.", + "examples": [ + "Example 1:\nInput: numbers = [2,7,11,15], target = 9\nOutput: [1,2]\nExplanation: The sum of 2 and 7 is 9. Therefore, index1 = 1, index2 = 2. We return [1, 2].", + "Example 2:\nInput: numbers = [2,3,4], target = 6\nOutput: [1,3]\nExplanation: The sum of 2 and 4 is 6. Therefore index1 = 1, index2 = 3. We return [1, 3].", + "Example 3:\nInput: numbers = [-1,0], target = -1\nOutput: [1,2]\nExplanation: The sum of -1 and 0 is -1. Therefore index1 = 1, index2 = 2. We return [1, 2]." + ], + "constraints": "Constraints:\n\n2 <= numbers.length <= 3 * 10^4\n-1000 <= numbers[i] <= 1000\nnumbers is sorted in non-decreasing order.\n-1000 <= target <= 1000\nThe tests are generated such that there is exactly one solution.", + "tags": [ + "Array", + "Two Pointers", + "Binary Search" + ], + "title-slug": "two-sum-ii-input-array-is-sorted" + }, + { + "leetcode-id": 168, + "title": "Excel Sheet Column Title", + "difficulty": 1, + "description": "Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet.\nFor example:\n\nA -> 1\nB -> 2\nC -> 3\n...\nZ -> 26\nAA -> 27\nAB -> 28 \n...", + "examples": [ + "Example 1:\nInput: columnNumber = 1\nOutput: \"A\"", + "Example 2:\nInput: columnNumber = 28\nOutput: \"AB\"", + "Example 3:\nInput: columnNumber = 701\nOutput: \"ZY\"" + ], + "constraints": "Constraints:\n\n1 <= columnNumber <= 2^31 - 1", + "tags": [ + "Math", + "String" + ], + "title-slug": "excel-sheet-column-title" + }, + { + "leetcode-id": 169, + "title": "Majority Element", + "difficulty": 1, + "description": "Given an array nums of size n, return the majority element.\nThe majority element is the element that appears more than \u230an / 2\u230b times. You may assume that the majority element always exists in the array.", + "examples": [ + "Example 1:\nInput: nums = [3,2,3]\nOutput: 3", + "Example 2:\nInput: nums = [2,2,1,1,1,2,2]\nOutput: 2" + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 5 * 10^4\n-10^9 <= nums[i] <= 10^9\n\n\u00a0\nFollow-up: Could you solve the problem in linear time and in O(1) space?", + "tags": [ + "Array", + "Hash Table", + "Divide and Conquer", + "Sorting", + "Counting" + ], + "title-slug": "majority-element" + }, + { + "leetcode-id": 171, + "title": "Excel Sheet Column Number", + "difficulty": 1, + "description": "Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number.\nFor example:\n\nA -> 1\nB -> 2\nC -> 3\n...\nZ -> 26\nAA -> 27\nAB -> 28 \n...", + "examples": [ + "Example 1:\nInput: columnTitle = \"A\"\nOutput: 1", + "Example 2:\nInput: columnTitle = \"AB\"\nOutput: 28", + "Example 3:\nInput: columnTitle = \"ZY\"\nOutput: 701" + ], + "constraints": "Constraints:\n\n1 <= columnTitle.length <= 7\ncolumnTitle consists only of uppercase English letters.\ncolumnTitle is in the range [\"A\", \"FXSHRXW\"].", + "tags": [ + "Math", + "String" + ], + "title-slug": "excel-sheet-column-number" + }, + { + "leetcode-id": 172, + "title": "Factorial Trailing Zeroes", + "difficulty": 2, + "description": "Given an integer n, return the number of trailing zeroes in n!.\nNote that n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1.", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: 0\nExplanation: 3! = 6, no trailing zero.", + "Example 2:\nInput: n = 5\nOutput: 1\nExplanation: 5! = 120, one trailing zero.", + "Example 3:\nInput: n = 0\nOutput: 0" + ], + "constraints": "Constraints:\n\n0 <= n <= 10^4\n\n\u00a0\nFollow up: Could you write a solution that works in logarithmic time complexity?", + "tags": [ + "Math" + ], + "title-slug": "factorial-trailing-zeroes" + }, + { + "leetcode-id": 173, + "title": "Binary Search Tree Iterator", + "difficulty": 2, + "description": "Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST):\n\nBSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any element in the BST.\nboolean hasNext() Returns true if there exists a number in the traversal to the right of the pointer, otherwise returns false.\nint next() Moves the pointer to the right, then returns the number at the pointer.\n\nNotice that by initializing the pointer to a non-existent smallest number, the first call to next() will return the smallest element in the BST.\nYou may assume that next() calls will always be valid. That is, there will be at least a next number in the in-order traversal when next() is called.", + "examples": [ + "Example 1:\nInput\n[\"BSTIterator\", \"next\", \"next\", \"hasNext\", \"next\", \"hasNext\", \"next\", \"hasNext\", \"next\", \"hasNext\"]\n[[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []]\nOutput\n[null, 3, 7, true, 9, true, 15, true, 20, false]\n\nExplanation\nBSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]);\nbSTIterator.next(); // return 3\nbSTIterator.next(); // return 7\nbSTIterator.hasNext(); // return True\nbSTIterator.next(); // return 9\nbSTIterator.hasNext(); // return True\nbSTIterator.next(); // return 15\nbSTIterator.hasNext(); // return True\nbSTIterator.next(); // return 20\nbSTIterator.hasNext(); // return False" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^5].\n0 <= Node.val <= 10^6\nAt most 10^5 calls will be made to hasNext, and next.\n\n\u00a0\nFollow up:\n\nCould you implement next() and hasNext() to run in average O(1) time and use\u00a0O(h) memory, where h is the height of the tree?", + "tags": [ + "Stack", + "Tree", + "Design", + "Binary Search Tree", + "Binary Tree", + "Iterator" + ], + "title-slug": "binary-search-tree-iterator" + }, + { + "leetcode-id": 174, + "title": "Dungeon Game", + "difficulty": 3, + "description": "The demons had captured the princess and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of m x n rooms laid out in a 2D grid. Our valiant knight was initially positioned in the top-left room and must fight his way through dungeon to rescue the princess.\nThe knight has an initial health point represented by a positive integer. If at any point his health point drops to 0 or below, he dies immediately.\nSome of the rooms are guarded by demons (represented by negative integers), so the knight loses health upon entering these rooms; other rooms are either empty (represented as 0) or contain magic orbs that increase the knight's health (represented by positive integers).\nTo reach the princess as quickly as possible, the knight decides to move only rightward or downward in each step.\nReturn the knight's minimum initial health so that he can rescue the princess.\nNote that any room can contain threats or power-ups, even the first room the knight enters and the bottom-right room where the princess is imprisoned.", + "examples": [ + "Example 1:\nInput: dungeon = [[-2,-3,3],[-5,-10,1],[10,30,-5]]\nOutput: 7\nExplanation: The initial health of the knight must be at least 7 if he follows the optimal path: RIGHT-> RIGHT -> DOWN -> DOWN.", + "Example 2:\nInput: dungeon = [[0]]\nOutput: 1" + ], + "constraints": "Constraints:\n\nm == dungeon.length\nn == dungeon[i].length\n1 <= m, n <= 200\n-1000 <= dungeon[i][j] <= 1000", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "dungeon-game" + }, + { + "leetcode-id": 179, + "title": "Largest Number", + "difficulty": 2, + "description": "Given a list of non-negative integers nums, arrange them such that they form the largest number and return it.\nSince the result may be very large, so you need to return a string instead of an integer.", + "examples": [ + "Example 1:\nInput: nums = [10,2]\nOutput: \"210\"", + "Example 2:\nInput: nums = [3,30,34,5,9]\nOutput: \"9534330\"" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n0 <= nums[i] <= 10^9", + "tags": [ + "Array", + "String", + "Greedy", + "Sorting" + ], + "title-slug": "largest-number" + }, + { + "leetcode-id": 187, + "title": "Repeated DNA Sequences", + "difficulty": 2, + "description": "The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'.\n\nFor example, \"ACGAATTCCG\" is a DNA sequence.\n\nWhen studying DNA, it is useful to identify repeated sequences within the DNA.\nGiven a string s that represents a DNA sequence, return all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule. You may return the answer in any order.", + "examples": [ + "Example 1:\nInput: s = \"AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT\"\nOutput: [\"AAAAACCCCC\",\"CCCCCAAAAA\"]", + "Example 2:\nInput: s = \"AAAAAAAAAAAAA\"\nOutput: [\"AAAAAAAAAA\"]" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns[i] is either 'A', 'C', 'G', or 'T'.", + "tags": [ + "Hash Table", + "String", + "Bit Manipulation", + "Sliding Window", + "Rolling Hash", + "Hash Function" + ], + "title-slug": "repeated-dna-sequences" + }, + { + "leetcode-id": 188, + "title": "Best Time to Buy and Sell Stock IV", + "difficulty": 3, + "description": "You are given an integer array prices where prices[i] is the price of a given stock on the i^th day, and an integer k.\nFind the maximum profit you can achieve. You may complete at most k transactions: i.e. you may buy at most k times and sell at most k times.\nNote: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).", + "examples": [ + "Example 1:\nInput: k = 2, prices = [2,4,1]\nOutput: 2\nExplanation: Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2.", + "Example 2:\nInput: k = 2, prices = [3,2,6,5,0,3]\nOutput: 7\nExplanation: Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4. Then buy on day 5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3." + ], + "constraints": "Constraints:\n\n1 <= k <= 100\n1 <= prices.length <= 1000\n0 <= prices[i] <= 1000", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "best-time-to-buy-and-sell-stock-iv" + }, + { + "leetcode-id": 189, + "title": "Rotate Array", + "difficulty": 2, + "description": "Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4,5,6,7], k = 3\nOutput: [5,6,7,1,2,3,4]\nExplanation:\nrotate 1 steps to the right: [7,1,2,3,4,5,6]\nrotate 2 steps to the right: [6,7,1,2,3,4,5]\nrotate 3 steps to the right: [5,6,7,1,2,3,4]", + "Example 2:\nInput: nums = [-1,-100,3,99], k = 2\nOutput: [3,99,-1,-100]\nExplanation: \nrotate 1 steps to the right: [99,-1,-100,3]\nrotate 2 steps to the right: [3,99,-1,-100]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-2^31 <= nums[i] <= 2^31 - 1\n0 <= k <= 10^5\n\n\u00a0\nFollow up:\n\nTry to come up with as many solutions as you can. There are at least three different ways to solve this problem.\nCould you do it in-place with O(1) extra space?", + "tags": [ + "Array", + "Math", + "Two Pointers" + ], + "title-slug": "rotate-array" + }, + { + "leetcode-id": 190, + "title": "Reverse Bits", + "difficulty": 1, + "description": "Reverse bits of a given 32 bits unsigned integer.\nNote:\n\nNote that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned.\nIn Java, the compiler represents the signed integers using 2's complement notation. Therefore, in", + "examples": [ + "Example 2 above, the input represents the signed integer -3 and the output represents the signed integer -1073741825.\n", + "Example 1:\nInput: n = 00000010100101000001111010011100\nOutput: 964176192 (00111001011110000010100101000000)\nExplanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000.", + "Example 2:\nInput: n = 11111111111111111111111111111101\nOutput: 3221225471 (10111111111111111111111111111111)\nExplanation: The input binary string 11111111111111111111111111111101 represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is 10111111111111111111111111111111." + ], + "constraints": "Constraints:\n\nThe input must be a binary string of length 32\n\n\u00a0\nFollow up: If this function is called many times, how would you optimize it?", + "tags": [ + "Divide and Conquer", + "Bit Manipulation" + ], + "title-slug": "reverse-bits" + }, + { + "leetcode-id": 191, + "title": "Number of 1 Bits", + "difficulty": 1, + "description": "Write a function that takes\u00a0the binary representation of an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).\nNote:\n\nNote that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned.\nIn Java, the compiler represents the signed integers using 2's complement notation. Therefore, in", + "examples": [ + "Example 3, the input represents the signed integer. -3.\n", + "Example 1:\nInput: n = 00000000000000000000000000001011\nOutput: 3\nExplanation: The input binary string 00000000000000000000000000001011 has a total of three '1' bits.", + "Example 2:\nInput: n = 00000000000000000000000010000000\nOutput: 1\nExplanation: The input binary string 00000000000000000000000010000000 has a total of one '1' bit.", + "Example 3:\nInput: n = 11111111111111111111111111111101\nOutput: 31\nExplanation: The input binary string 11111111111111111111111111111101 has a total of thirty one '1' bits." + ], + "constraints": "Constraints:\n\nThe input must be a binary string of length 32.\n\n\u00a0\nFollow up: If this function is called many times, how would you optimize it?", + "tags": [ + "Divide and Conquer", + "Bit Manipulation" + ], + "title-slug": "number-of-1-bits" + }, + { + "leetcode-id": 198, + "title": "House Robber", + "difficulty": 2, + "description": "You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.\nGiven an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,1]\nOutput: 4\nExplanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).\nTotal amount you can rob = 1 + 3 = 4.", + "Example 2:\nInput: nums = [2,7,9,3,1]\nOutput: 12\nExplanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).\nTotal amount you can rob = 2 + 9 + 1 = 12." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n0 <= nums[i] <= 400", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "house-robber" + }, + { + "leetcode-id": 199, + "title": "Binary Tree Right Side View", + "difficulty": 2, + "description": "Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,null,5,null,4]\nOutput: [1,3,4]", + "Example 2:\nInput: root = [1,null,3]\nOutput: [1,3]", + "Example 3:\nInput: root = []\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 100].\n-100 <= Node.val <= 100", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "binary-tree-right-side-view" + }, + { + "leetcode-id": 200, + "title": "Number of Islands", + "difficulty": 2, + "description": "Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.\nAn island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.", + "examples": [ + "Example 1:\nInput: grid = [\n [\"1\",\"1\",\"1\",\"1\",\"0\"],\n [\"1\",\"1\",\"0\",\"1\",\"0\"],\n [\"1\",\"1\",\"0\",\"0\",\"0\"],\n [\"0\",\"0\",\"0\",\"0\",\"0\"]\n]\nOutput: 1", + "Example 2:\nInput: grid = [\n [\"1\",\"1\",\"0\",\"0\",\"0\"],\n [\"1\",\"1\",\"0\",\"0\",\"0\"],\n [\"0\",\"0\",\"1\",\"0\",\"0\"],\n [\"0\",\"0\",\"0\",\"1\",\"1\"]\n]\nOutput: 3" + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 300\ngrid[i][j] is '0' or '1'.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Matrix" + ], + "title-slug": "number-of-islands" + }, + { + "leetcode-id": 201, + "title": "Bitwise AND of Numbers Range", + "difficulty": 2, + "description": "Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive.", + "examples": [ + "Example 1:\nInput: left = 5, right = 7\nOutput: 4", + "Example 2:\nInput: left = 0, right = 0\nOutput: 0", + "Example 3:\nInput: left = 1, right = 2147483647\nOutput: 0" + ], + "constraints": "Constraints:\n\n0 <= left <= right <= 2^31 - 1", + "tags": [ + "Bit Manipulation" + ], + "title-slug": "bitwise-and-of-numbers-range" + }, + { + "leetcode-id": 202, + "title": "Happy Number", + "difficulty": 1, + "description": "Write an algorithm to determine if a number n is happy.\nA happy number is a number defined by the following process:\n\nStarting with any positive integer, replace the number by the sum of the squares of its digits.\nRepeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1.\nThose numbers for which this process ends in 1 are happy.\n\nReturn true if n is a happy number, and false if not.", + "examples": [ + "Example 1:\nInput: n = 19\nOutput: true\nExplanation:\n1^2 + 9^2 = 82\n8^2 + 2^2 = 68\n6^2 + 8^2 = 100\n1^2 + 0^2 + 0^2 = 1", + "Example 2:\nInput: n = 2\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= n <= 2^31 - 1", + "tags": [ + "Hash Table", + "Math", + "Two Pointers" + ], + "title-slug": "happy-number" + }, + { + "leetcode-id": 203, + "title": "Remove Linked List Elements", + "difficulty": 1, + "description": "Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head.", + "examples": [ + "Example 1:\nInput: head = [1,2,6,3,4,5,6], val = 6\nOutput: [1,2,3,4,5]", + "Example 2:\nInput: head = [], val = 1\nOutput: []", + "Example 3:\nInput: head = [7,7,7,7], val = 7\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [0, 10^4].\n1 <= Node.val <= 50\n0 <= val <= 50", + "tags": [ + "Linked List", + "Recursion" + ], + "title-slug": "remove-linked-list-elements" + }, + { + "leetcode-id": 204, + "title": "Count Primes", + "difficulty": 2, + "description": "Given an integer n, return the number of prime numbers that are strictly less than n.", + "examples": [ + "Example 1:\nInput: n = 10\nOutput: 4\nExplanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.", + "Example 2:\nInput: n = 0\nOutput: 0", + "Example 3:\nInput: n = 1\nOutput: 0" + ], + "constraints": "Constraints:\n\n0 <= n <= 5 * 10^6", + "tags": [ + "Array", + "Math", + "Enumeration", + "Number Theory" + ], + "title-slug": "count-primes" + }, + { + "leetcode-id": 205, + "title": "Isomorphic Strings", + "difficulty": 1, + "description": "Given two strings s and t, determine if they are isomorphic.\nTwo strings s and t are isomorphic if the characters in s can be replaced to get t.\nAll occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.", + "examples": [ + "Example 1:\nInput: s = \"egg\", t = \"add\"\nOutput: true", + "Example 2:\nInput: s = \"foo\", t = \"bar\"\nOutput: false", + "Example 3:\nInput: s = \"paper\", t = \"title\"\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 5 * 10^4\nt.length == s.length\ns and t consist of any valid ascii character.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "isomorphic-strings" + }, + { + "leetcode-id": 206, + "title": "Reverse Linked List", + "difficulty": 1, + "description": "Given the head of a singly linked list, reverse the list, and return the reversed list.", + "examples": [ + "Example 1:\nInput: head = [1,2,3,4,5]\nOutput: [5,4,3,2,1]", + "Example 2:\nInput: head = [1,2]\nOutput: [2,1]", + "Example 3:\nInput: head = []\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is the range [0, 5000].\n-5000 <= Node.val <= 5000\n\n\u00a0\nFollow up: A linked list can be reversed either iteratively or recursively. Could you implement both?", + "tags": [ + "Linked List", + "Recursion" + ], + "title-slug": "reverse-linked-list" + }, + { + "leetcode-id": 207, + "title": "Course Schedule", + "difficulty": 2, + "description": "There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.\n\nFor example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.\n\nReturn true if you can finish all courses. Otherwise, return false.", + "examples": [ + "Example 1:\nInput: numCourses = 2, prerequisites = [[1,0]]\nOutput: true\nExplanation: There are a total of 2 courses to take. \nTo take course 1 you should have finished course 0. So it is possible.", + "Example 2:\nInput: numCourses = 2, prerequisites = [[1,0],[0,1]]\nOutput: false\nExplanation: There are a total of 2 courses to take. \nTo take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible." + ], + "constraints": "Constraints:\n\n1 <= numCourses <= 2000\n0 <= prerequisites.length <= 5000\nprerequisites[i].length == 2\n0 <= ai, bi < numCourses\nAll the pairs prerequisites[i] are unique.", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Graph", + "Topological Sort" + ], + "title-slug": "course-schedule" + }, + { + "leetcode-id": 208, + "title": "Implement Trie (Prefix Tree)", + "difficulty": 2, + "description": "A trie (pronounced as \"try\") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.\nImplement the Trie class:\n\nTrie() Initializes the trie object.\nvoid insert(String word) Inserts the string word into the trie.\nboolean search(String word) Returns true if the string word is in the trie (i.e., was inserted before), and false otherwise.\nboolean startsWith(String prefix) Returns true if there is a previously inserted string word that has the prefix prefix, and false otherwise.", + "examples": [ + "Example 1:\nInput\n[\"Trie\", \"insert\", \"search\", \"search\", \"startsWith\", \"insert\", \"search\"]\n[[], [\"apple\"], [\"apple\"], [\"app\"], [\"app\"], [\"app\"], [\"app\"]]\nOutput\n[null, null, true, false, true, null, true]\n\nExplanation\nTrie trie = new Trie();\ntrie.insert(\"apple\");\ntrie.search(\"apple\"); // return True\ntrie.search(\"app\"); // return False\ntrie.startsWith(\"app\"); // return True\ntrie.insert(\"app\");\ntrie.search(\"app\"); // return True" + ], + "constraints": "Constraints:\n\n1 <= word.length, prefix.length <= 2000\nword and prefix consist only of lowercase English letters.\nAt most 3 * 10^4 calls in total will be made to insert, search, and startsWith.", + "tags": [ + "Hash Table", + "String", + "Design", + "Trie" + ], + "title-slug": "implement-trie-prefix-tree" + }, + { + "leetcode-id": 209, + "title": "Minimum Size Subarray Sum", + "difficulty": 2, + "description": "Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. If there is no such subarray, return 0 instead.", + "examples": [ + "Example 1:\nInput: target = 7, nums = [2,3,1,2,4,3]\nOutput: 2\nExplanation: The subarray [4,3] has the minimal length under the problem constraint.", + "Example 2:\nInput: target = 4, nums = [1,4,4]\nOutput: 1", + "Example 3:\nInput: target = 11, nums = [1,1,1,1,1,1,1,1]\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= target <= 10^9\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^4\n\n\u00a0\nFollow up: If you have figured out the O(n) solution, try coding another solution of which the time complexity is O(n log(n)).", + "tags": [ + "Array", + "Binary Search", + "Sliding Window", + "Prefix Sum" + ], + "title-slug": "minimum-size-subarray-sum" + }, + { + "leetcode-id": 210, + "title": "Course Schedule II", + "difficulty": 2, + "description": "There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.\n\nFor example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.\n\nReturn the ordering of courses you should take to finish all courses. If there are many valid answers, return any of them. If it is impossible to finish all courses, return an empty array.", + "examples": [ + "Example 1:\nInput: numCourses = 2, prerequisites = [[1,0]]\nOutput: [0,1]\nExplanation: There are a total of 2 courses to take. To take course 1 you should have finished course 0. So the correct course order is [0,1].", + "Example 2:\nInput: numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]]\nOutput: [0,2,1,3]\nExplanation: There are a total of 4 courses to take. To take course 3 you should have finished both courses 1 and 2. Both courses 1 and 2 should be taken after you finished course 0.\nSo one correct course order is [0,1,2,3]. Another correct ordering is [0,2,1,3].", + "Example 3:\nInput: numCourses = 1, prerequisites = []\nOutput: [0]" + ], + "constraints": "Constraints:\n\n1 <= numCourses <= 2000\n0 <= prerequisites.length <= numCourses * (numCourses - 1)\nprerequisites[i].length == 2\n0 <= ai, bi < numCourses\nai != bi\nAll the pairs [ai, bi] are distinct.", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Graph", + "Topological Sort" + ], + "title-slug": "course-schedule-ii" + }, + { + "leetcode-id": 211, + "title": "Design Add and Search Words Data Structure", + "difficulty": 2, + "description": "Design a data structure that supports adding new words and finding if a string matches any previously added string.\nImplement the WordDictionary class:\n\nWordDictionary()\u00a0Initializes the object.\nvoid addWord(word) Adds word to the data structure, it can be matched later.\nbool search(word)\u00a0Returns true if there is any string in the data structure that matches word\u00a0or false otherwise. word may contain dots '.' where dots can be matched with any letter.\n\n\u00a0\nExample:\n\nInput\n[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\",\"search\"]\n[[],[\"bad\"],[\"dad\"],[\"mad\"],[\"pad\"],[\"bad\"],[\".ad\"],[\"b..\"]]\nOutput\n[null,null,null,null,false,true,true,true]\n\nExplanation\nWordDictionary wordDictionary = new WordDictionary();\nwordDictionary.addWord(\"bad\");\nwordDictionary.addWord(\"dad\");\nwordDictionary.addWord(\"mad\");\nwordDictionary.search(\"pad\"); // return False\nwordDictionary.search(\"bad\"); // return True\nwordDictionary.search(\".ad\"); // return True\nwordDictionary.search(\"b..\"); // return True\n\n\u00a0\nConstraints:\n\n1 <= word.length <= 25\nword in addWord consists of lowercase English letters.\nword in search consist of '.' or lowercase English letters.\nThere will be at most 2 dots in word for search queries.\nAt most 10^4 calls will be made to addWord and search.", + "examples": [], + "constraints": "Constraints:\n\n1 <= word.length <= 25\nword in addWord consists of lowercase English letters.\nword in search consist of '.' or lowercase English letters.\nThere will be at most 2 dots in word for search queries.\nAt most 10^4 calls will be made to addWord and search.", + "tags": [ + "String", + "Depth-First Search", + "Design", + "Trie" + ], + "title-slug": "design-add-and-search-words-data-structure" + }, + { + "leetcode-id": 212, + "title": "Word Search II", + "difficulty": 3, + "description": "Given an m x n board\u00a0of characters and a list of strings words, return all words on the board.\nEach word must be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.", + "examples": [ + "Example 1:\nInput: board = [[\"o\",\"a\",\"a\",\"n\"],[\"e\",\"t\",\"a\",\"e\"],[\"i\",\"h\",\"k\",\"r\"],[\"i\",\"f\",\"l\",\"v\"]], words = [\"oath\",\"pea\",\"eat\",\"rain\"]\nOutput: [\"eat\",\"oath\"]", + "Example 2:\nInput: board = [[\"a\",\"b\"],[\"c\",\"d\"]], words = [\"abcb\"]\nOutput: []" + ], + "constraints": "Constraints:\n\nm == board.length\nn == board[i].length\n1 <= m, n <= 12\nboard[i][j] is a lowercase English letter.\n1 <= words.length <= 3 * 10^4\n1 <= words[i].length <= 10\nwords[i] consists of lowercase English letters.\nAll the strings of words are unique.", + "tags": [ + "Array", + "String", + "Backtracking", + "Trie", + "Matrix" + ], + "title-slug": "word-search-ii" + }, + { + "leetcode-id": 213, + "title": "House Robber II", + "difficulty": 2, + "description": "You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and\u00a0it will automatically contact the police if two adjacent houses were broken into on the same night.\nGiven an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.", + "examples": [ + "Example 1:\nInput: nums = [2,3,2]\nOutput: 3\nExplanation: You cannot rob house 1 (money = 2) and then rob house 3 (money = 2), because they are adjacent houses.", + "Example 2:\nInput: nums = [1,2,3,1]\nOutput: 4\nExplanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).\nTotal amount you can rob = 1 + 3 = 4.", + "Example 3:\nInput: nums = [1,2,3]\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n0 <= nums[i] <= 1000", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "house-robber-ii" + }, + { + "leetcode-id": 214, + "title": "Shortest Palindrome", + "difficulty": 3, + "description": "You are given a string s. You can convert s to a palindrome by adding characters in front of it.\nReturn the shortest palindrome you can find by performing this transformation.", + "examples": [ + "Example 1:\nInput: s = \"aacecaaa\"\nOutput: \"aaacecaaa\"", + "Example 2:\nInput: s = \"abcd\"\nOutput: \"dcbabcd\"" + ], + "constraints": "Constraints:\n\n0 <= s.length <= 5 * 10^4\ns consists of lowercase English letters only.", + "tags": [ + "String", + "Rolling Hash", + "String Matching", + "Hash Function" + ], + "title-slug": "shortest-palindrome" + }, + { + "leetcode-id": 215, + "title": "Kth Largest Element in an Array", + "difficulty": 2, + "description": "Given an integer array nums and an integer k, return the k^th largest element in the array.\nNote that it is the k^th largest element in the sorted order, not the k^th distinct element.\nCan you solve it without sorting?", + "examples": [ + "Example 1:\nInput: nums = [3,2,1,5,6,4], k = 2\nOutput: 5", + "Example 2:\nInput: nums = [3,2,3,1,2,4,5,5,6], k = 4\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= k <= nums.length <= 10^5\n-10^4 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Divide and Conquer", + "Sorting", + "Heap (Priority Queue)", + "Quickselect" + ], + "title-slug": "kth-largest-element-in-an-array" + }, + { + "leetcode-id": 216, + "title": "Combination Sum III", + "difficulty": 2, + "description": "Find all valid combinations of k numbers that sum up to n such that the following conditions are true:\n\nOnly numbers 1 through 9 are used.\nEach number is used at most once.\n\nReturn a list of all possible valid combinations. The list must not contain the same combination twice, and the combinations may be returned in any order.", + "examples": [ + "Example 1:\nInput: k = 3, n = 7\nOutput: [[1,2,4]]\nExplanation:\n1 + 2 + 4 = 7\nThere are no other valid combinations.", + "Example 2:\nInput: k = 3, n = 9\nOutput: [[1,2,6],[1,3,5],[2,3,4]]\nExplanation:\n1 + 2 + 6 = 9\n1 + 3 + 5 = 9\n2 + 3 + 4 = 9\nThere are no other valid combinations.", + "Example 3:\nInput: k = 4, n = 1\nOutput: []\nExplanation: There are no valid combinations.\nUsing 4 different numbers in the range [1,9], the smallest sum we can get is 1+2+3+4 = 10 and since 10 > 1, there are no valid combination." + ], + "constraints": "Constraints:\n\n2 <= k <= 9\n1 <= n <= 60", + "tags": [ + "Array", + "Backtracking" + ], + "title-slug": "combination-sum-iii" + }, + { + "leetcode-id": 217, + "title": "Contains Duplicate", + "difficulty": 1, + "description": "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.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,1]\nOutput: true", + "Example 2:\nInput: nums = [1,2,3,4]\nOutput: false", + "Example 3:\nInput: nums = [1,1,1,3,3,4,3,2,4,2]\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^9 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Hash Table", + "Sorting" + ], + "title-slug": "contains-duplicate" + }, + { + "leetcode-id": 218, + "title": "The Skyline Problem", + "difficulty": 3, + "description": "A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return the skyline formed by these buildings collectively.\nThe geometric information of each building is given in the array buildings where buildings[i] = [lefti, righti, heighti]:\n\nlefti is the x coordinate of the left edge of the i^th building.\nrighti is the x coordinate of the right edge of the i^th building.\nheighti is the height of the i^th building.\n\nYou may assume all buildings are perfect rectangles grounded on an absolutely flat surface at height 0.\nThe skyline should be represented as a list of \"key points\" sorted by their x-coordinate in the form [[x1,y1],[x2,y2],...]. Each key point is the left endpoint of some horizontal segment in the skyline except the last point in the list, which always has a y-coordinate 0 and is used to mark the skyline's termination where the rightmost building ends. Any ground between the leftmost and rightmost buildings should be part of the skyline's contour.\nNote: There must be no consecutive horizontal lines of equal height in the output skyline. For instance, [...,[2 3],[4 5],[7 5],[11 5],[12 7],...] is not acceptable; the three lines of height 5 should be merged into one in the final output as such: [...,[2 3],[4 5],[12 7],...]", + "examples": [ + "Example 1:\nInput: buildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]\nOutput: [[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]\nExplanation:\nFigure A shows the buildings of the input.\nFigure B shows the skyline formed by those buildings. The red points in figure B represent the key points in the output list.", + "Example 2:\nInput: buildings = [[0,2,3],[2,5,3]]\nOutput: [[0,3],[5,0]]" + ], + "constraints": "Constraints:\n\n1 <= buildings.length <= 10^4\n0 <= lefti < righti <= 2^31 - 1\n1 <= heighti <= 2^31 - 1\nbuildings is sorted by lefti in\u00a0non-decreasing order.", + "tags": [ + "Array", + "Divide and Conquer", + "Binary Indexed Tree", + "Segment Tree", + "Line Sweep", + "Heap (Priority Queue)", + "Ordered Set" + ], + "title-slug": "the-skyline-problem" + }, + { + "leetcode-id": 219, + "title": "Contains Duplicate II", + "difficulty": 1, + "description": "Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,1], k = 3\nOutput: true", + "Example 2:\nInput: nums = [1,0,1,1], k = 1\nOutput: true", + "Example 3:\nInput: nums = [1,2,3,1,2,3], k = 2\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^9 <= nums[i] <= 10^9\n0 <= k <= 10^5", + "tags": [ + "Array", + "Hash Table", + "Sliding Window" + ], + "title-slug": "contains-duplicate-ii" + }, + { + "leetcode-id": 220, + "title": "Contains Duplicate III", + "difficulty": 3, + "description": "You are given an integer array nums and two integers indexDiff and valueDiff.\nFind a pair of indices (i, j) such that:\n\ni != j,\nabs(i - j) <= indexDiff.\nabs(nums[i] - nums[j]) <= valueDiff, and\n\nReturn true if such pair exists or false otherwise.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,1], indexDiff = 3, valueDiff = 0\nOutput: true\nExplanation: We can choose (i, j) = (0, 3).\nWe satisfy the three conditions:\ni != j --> 0 != 3\nabs(i - j) <= indexDiff --> abs(0 - 3) <= 3\nabs(nums[i] - nums[j]) <= valueDiff --> abs(1 - 1) <= 0", + "Example 2:\nInput: nums = [1,5,9,1,5,9], indexDiff = 2, valueDiff = 3\nOutput: false\nExplanation: After trying all the possible pairs (i, j), we cannot satisfy the three conditions, so we return false." + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 10^5\n-10^9 <= nums[i] <= 10^9\n1 <= indexDiff <= nums.length\n0 <= valueDiff <= 10^9", + "tags": [ + "Array", + "Sliding Window", + "Sorting", + "Bucket Sort", + "Ordered Set" + ], + "title-slug": "contains-duplicate-iii" + }, + { + "leetcode-id": 221, + "title": "Maximal Square", + "difficulty": 2, + "description": "Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.", + "examples": [ + "Example 1:\nInput: matrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]\nOutput: 4", + "Example 2:\nInput: matrix = [[\"0\",\"1\"],[\"1\",\"0\"]]\nOutput: 1", + "Example 3:\nInput: matrix = [[\"0\"]]\nOutput: 0" + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= m, n <= 300\nmatrix[i][j] is '0' or '1'.", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "maximal-square" + }, + { + "leetcode-id": 222, + "title": "Count Complete Tree Nodes", + "difficulty": 1, + "description": "Given the root of a complete binary tree, return the number of the nodes in the tree.\nAccording to Wikipedia, every level, except possibly the last, is completely filled in a complete binary tree, and all nodes in the last level are as far left as possible. It can have between 1 and 2^h nodes inclusive at the last level h.\nDesign an algorithm that runs in less than\u00a0O(n)\u00a0time complexity.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,4,5,6]\nOutput: 6", + "Example 2:\nInput: root = []\nOutput: 0", + "Example 3:\nInput: root = [1]\nOutput: 1" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 5 * 10^4].\n0 <= Node.val <= 5 * 10^4\nThe tree is guaranteed to be complete.", + "tags": [ + "Binary Search", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "count-complete-tree-nodes" + }, + { + "leetcode-id": 223, + "title": "Rectangle Area", + "difficulty": 2, + "description": "Given the coordinates of two rectilinear rectangles in a 2D plane, return the total area covered by the two rectangles.\nThe first rectangle is defined by its bottom-left corner (ax1, ay1) and its top-right corner (ax2, ay2).\nThe second rectangle is defined by its bottom-left corner (bx1, by1) and its top-right corner (bx2, by2).", + "examples": [ + "Example 1:\nInput: ax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2\nOutput: 45", + "Example 2:\nInput: ax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -2, by1 = -2, bx2 = 2, by2 = 2\nOutput: 16" + ], + "constraints": "Constraints:\n\n-10^4 <= ax1 <= ax2 <= 10^4\n-10^4 <= ay1 <= ay2 <= 10^4\n-10^4 <= bx1 <= bx2 <= 10^4\n-10^4 <= by1 <= by2 <= 10^4", + "tags": [ + "Math", + "Geometry" + ], + "title-slug": "rectangle-area" + }, + { + "leetcode-id": 224, + "title": "Basic Calculator", + "difficulty": 3, + "description": "Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.\nNote: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().", + "examples": [ + "Example 1:\nInput: s = \"1 + 1\"\nOutput: 2", + "Example 2:\nInput: s = \" 2-1 + 2 \"\nOutput: 3", + "Example 3:\nInput: s = \"(1+(4+5+2)-3)+(6+8)\"\nOutput: 23" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 3 * 10^5\ns consists of digits, '+', '-', '(', ')', and ' '.\ns represents a valid expression.\n'+' is not used as a unary operation (i.e., \"+1\" and \"+(2 + 3)\" is invalid).\n'-' could be used as a unary operation (i.e., \"-1\" and \"-(2 + 3)\" is valid).\nThere will be no two consecutive operators in the input.\nEvery number and running calculation will fit in a signed 32-bit integer.", + "tags": [ + "Math", + "String", + "Stack", + "Recursion" + ], + "title-slug": "basic-calculator" + }, + { + "leetcode-id": 225, + "title": "Implement Stack using Queues", + "difficulty": 1, + "description": "Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (push, top, pop, and empty).\nImplement the MyStack class:\n\nvoid push(int x) Pushes element x to the top of the stack.\nint pop() Removes the element on the top of the stack and returns it.\nint top() Returns the element on the top of the stack.\nboolean empty() Returns true if the stack is empty, false otherwise.\n\nNotes:\n\nYou must use only standard operations of a queue, which means that only push to back, peek/pop from front, size and is empty operations are valid.\nDepending on your language, the queue may not be supported natively. You may simulate a queue using a list or deque (double-ended queue) as long as you use only a queue's standard operations.", + "examples": [ + "Example 1:\nInput\n[\"MyStack\", \"push\", \"push\", \"top\", \"pop\", \"empty\"]\n[[], [1], [2], [], [], []]\nOutput\n[null, null, null, 2, 2, false]\n\nExplanation\nMyStack myStack = new MyStack();\nmyStack.push(1);\nmyStack.push(2);\nmyStack.top(); // return 2\nmyStack.pop(); // return 2\nmyStack.empty(); // return False" + ], + "constraints": "Constraints:\n\n1 <= x <= 9\nAt most 100 calls will be made to push, pop, top, and empty.\nAll the calls to pop and top are valid.\n\n\u00a0\nFollow-up: Can you implement the stack using only one queue?", + "tags": [ + "Stack", + "Design", + "Queue" + ], + "title-slug": "implement-stack-using-queues" + }, + { + "leetcode-id": 226, + "title": "Invert Binary Tree", + "difficulty": 1, + "description": "Given the root of a binary tree, invert the tree, and return its root.", + "examples": [ + "Example 1:\nInput: root = [4,2,7,1,3,6,9]\nOutput: [4,7,2,9,6,3,1]", + "Example 2:\nInput: root = [2,1,3]\nOutput: [2,3,1]", + "Example 3:\nInput: root = []\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 100].\n-100 <= Node.val <= 100", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "invert-binary-tree" + }, + { + "leetcode-id": 227, + "title": "Basic Calculator II", + "difficulty": 2, + "description": "Given a string s which represents an expression, evaluate this expression and return its value.\u00a0\nThe integer division should truncate toward zero.\nYou may assume that the given expression is always valid. All intermediate results will be in the range of [-2^31, 2^31 - 1].\nNote: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().", + "examples": [ + "Example 1:\nInput: s = \"3+2*2\"\nOutput: 7", + "Example 2:\nInput: s = \" 3/2 \"\nOutput: 1", + "Example 3:\nInput: s = \" 3+5 / 2 \"\nOutput: 5" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 3 * 10^5\ns consists of integers and operators ('+', '-', '*', '/') separated by some number of spaces.\ns represents a valid expression.\nAll the integers in the expression are non-negative integers in the range [0, 2^31 - 1].\nThe answer is guaranteed to fit in a 32-bit integer.", + "tags": [ + "Math", + "String", + "Stack" + ], + "title-slug": "basic-calculator-ii" + }, + { + "leetcode-id": 228, + "title": "Summary Ranges", + "difficulty": 1, + "description": "You are given a sorted unique integer array nums.\nA range [a,b] is the set of all integers from a to b (inclusive).\nReturn the smallest sorted list of ranges that cover all the numbers in the array exactly. That is, each element of nums is covered by exactly one of the ranges, and there is no integer x such that x is in one of the ranges but not in nums.\nEach range [a,b] in the list should be output as:\n\n\"a->b\" if a != b\n\"a\" if a == b", + "examples": [ + "Example 1:\nInput: nums = [0,1,2,4,5,7]\nOutput: [\"0->2\",\"4->5\",\"7\"]\nExplanation: The ranges are:\n[0,2] --> \"0->2\"\n[4,5] --> \"4->5\"\n[7,7] --> \"7\"", + "Example 2:\nInput: nums = [0,2,3,4,6,8,9]\nOutput: [\"0\",\"2->4\",\"6\",\"8->9\"]\nExplanation: The ranges are:\n[0,0] --> \"0\"\n[2,4] --> \"2->4\"\n[6,6] --> \"6\"\n[8,9] --> \"8->9\"" + ], + "constraints": "Constraints:\n\n0 <= nums.length <= 20\n-2^31 <= nums[i] <= 2^31 - 1\nAll the values of nums are unique.\nnums is sorted in ascending order.", + "tags": [ + "Array" + ], + "title-slug": "summary-ranges" + }, + { + "leetcode-id": 229, + "title": "Majority Element II", + "difficulty": 2, + "description": "Given an integer array of size n, find all elements that appear more than \u230a n/3 \u230b times.", + "examples": [ + "Example 1:\nInput: nums = [3,2,3]\nOutput: [3]", + "Example 2:\nInput: nums = [1]\nOutput: [1]", + "Example 3:\nInput: nums = [1,2]\nOutput: [1,2]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 5 * 10^4\n-10^9 <= nums[i] <= 10^9\n\n\u00a0\nFollow up: Could you solve the problem in linear time and in O(1) space?", + "tags": [ + "Array", + "Hash Table", + "Sorting", + "Counting" + ], + "title-slug": "majority-element-ii" + }, + { + "leetcode-id": 230, + "title": "Kth Smallest Element in a BST", + "difficulty": 2, + "description": "Given the root of a binary search tree, and an integer k, return the k^th smallest value (1-indexed) of all the values of the nodes in the tree.", + "examples": [ + "Example 1:\nInput: root = [3,1,4,null,2], k = 1\nOutput: 1", + "Example 2:\nInput: root = [5,3,6,2,4,null,null,1], k = 3\nOutput: 3" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is n.\n1 <= k <= n <= 10^4\n0 <= Node.val <= 10^4\n\n\u00a0\nFollow up: If the BST is modified often (i.e., we can do insert and delete operations) and you need to find the kth smallest frequently, how would you optimize?", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "kth-smallest-element-in-a-bst" + }, + { + "leetcode-id": 231, + "title": "Power of Two", + "difficulty": 1, + "description": "Given an integer n, return true if it is a power of two. Otherwise, return false.\nAn integer n is a power of two, if there exists an integer x such that n == 2^x.", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: true\nExplanation: 2^0 = 1", + "Example 2:\nInput: n = 16\nOutput: true\nExplanation: 2^4 = 16", + "Example 3:\nInput: n = 3\nOutput: false" + ], + "constraints": "Constraints:\n\n-2^31 <= n <= 2^31 - 1\n\n\u00a0\nFollow up: Could you solve it without loops/recursion?", + "tags": [ + "Math", + "Bit Manipulation", + "Recursion" + ], + "title-slug": "power-of-two" + }, + { + "leetcode-id": 232, + "title": "Implement Queue using Stacks", + "difficulty": 1, + "description": "Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty).\nImplement the MyQueue class:\n\nvoid push(int x) Pushes element x to the back of the queue.\nint pop() Removes the element from the front of the queue and returns it.\nint peek() Returns the element at the front of the queue.\nboolean empty() Returns true if the queue is empty, false otherwise.\n\nNotes:\n\nYou must use only standard operations of a stack, which means only push to top, peek/pop from top, size, and is empty operations are valid.\nDepending on your language, the stack may not be supported natively. You may simulate a stack using a list or deque (double-ended queue) as long as you use only a stack's standard operations.", + "examples": [ + "Example 1:\nInput\n[\"MyQueue\", \"push\", \"push\", \"peek\", \"pop\", \"empty\"]\n[[], [1], [2], [], [], []]\nOutput\n[null, null, null, 1, 1, false]\n\nExplanation\nMyQueue myQueue = new MyQueue();\nmyQueue.push(1); // queue is: [1]\nmyQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)\nmyQueue.peek(); // return 1\nmyQueue.pop(); // return 1, queue is [2]\nmyQueue.empty(); // return false" + ], + "constraints": "Constraints:\n\n1 <= x <= 9\nAt most 100\u00a0calls will be made to push, pop, peek, and empty.\nAll the calls to pop and peek are valid.\n\n\u00a0\nFollow-up: Can you implement the queue such that each operation is amortized O(1) time complexity? In other words, performing n operations will take overall O(n) time even if one of those operations may take longer.", + "tags": [ + "Stack", + "Design", + "Queue" + ], + "title-slug": "implement-queue-using-stacks" + }, + { + "leetcode-id": 233, + "title": "Number of Digit One", + "difficulty": 3, + "description": "Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.", + "examples": [ + "Example 1:\nInput: n = 13\nOutput: 6", + "Example 2:\nInput: n = 0\nOutput: 0" + ], + "constraints": "Constraints:\n\n0 <= n <= 10^9", + "tags": [ + "Math", + "Dynamic Programming", + "Recursion" + ], + "title-slug": "number-of-digit-one" + }, + { + "leetcode-id": 234, + "title": "Palindrome Linked List", + "difficulty": 1, + "description": "Given the head of a singly linked list, return true if it is a palindrome or false otherwise.", + "examples": [ + "Example 1:\nInput: head = [1,2,2,1]\nOutput: true", + "Example 2:\nInput: head = [1,2]\nOutput: false" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [1, 10^5].\n0 <= Node.val <= 9\n\n\u00a0\nFollow up: Could you do it in O(n) time and O(1) space?", + "tags": [ + "Linked List", + "Two Pointers", + "Stack", + "Recursion" + ], + "title-slug": "palindrome-linked-list" + }, + { + "leetcode-id": 235, + "title": "Lowest Common Ancestor of a Binary Search Tree", + "difficulty": 2, + "description": "Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.\nAccording to the definition of LCA on Wikipedia: \u201cThe lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).\u201d", + "examples": [ + "Example 1:\nInput: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8\nOutput: 6\nExplanation: The LCA of nodes 2 and 8 is 6.", + "Example 2:\nInput: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4\nOutput: 2\nExplanation: The LCA of nodes 2 and 4 is 2, since a node can be a descendant of itself according to the LCA definition.", + "Example 3:\nInput: root = [2,1], p = 2, q = 1\nOutput: 2" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [2, 10^5].\n-10^9 <= Node.val <= 10^9\nAll Node.val are unique.\np != q\np and q will exist in the BST.", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "lowest-common-ancestor-of-a-binary-search-tree" + }, + { + "leetcode-id": 236, + "title": "Lowest Common Ancestor of a Binary Tree", + "difficulty": 2, + "description": "Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.\nAccording to the definition of LCA on Wikipedia: \u201cThe lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).\u201d", + "examples": [ + "Example 1:\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1\nOutput: 3\nExplanation: The LCA of nodes 5 and 1 is 3.", + "Example 2:\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\nOutput: 5\nExplanation: The LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition.", + "Example 3:\nInput: root = [1,2], p = 1, q = 2\nOutput: 1" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [2, 10^5].\n-10^9 <= Node.val <= 10^9\nAll Node.val are unique.\np != q\np and q will exist in the tree.", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "lowest-common-ancestor-of-a-binary-tree" + }, + { + "leetcode-id": 237, + "title": "Delete Node in a Linked List", + "difficulty": 2, + "description": "There is a singly-linked list head and we want to delete a node node in it.\nYou are given the node to be deleted node. You will not be given access to the first node of head.\nAll the values of the linked list are unique, and it is guaranteed that the given node node is not the last node in the linked list.\nDelete the given node. Note that by deleting the node, we do not mean removing it from memory. We mean:\n\nThe value of the given node should not exist in the linked list.\nThe number of nodes in the linked list should decrease by one.\nAll the values before node should be in the same order.\nAll the values after node should be in the same order.\n\nCustom testing:\n\nFor the input, you should provide the entire linked list head and the node to be given node. node should not be the last node of the list and should be an actual node in the list.\nWe will build the linked list and pass the node to your function.\nThe output will be the entire list after calling your function.", + "examples": [ + "Example 1:\nInput: head = [4,5,1,9], node = 5\nOutput: [4,1,9]\nExplanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.", + "Example 2:\nInput: head = [4,5,1,9], node = 1\nOutput: [4,5,9]\nExplanation: You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function." + ], + "constraints": "Constraints:\n\nThe number of the nodes in the given list is in the range [2, 1000].\n-1000 <= Node.val <= 1000\nThe value of each node in the list is unique.\nThe node to be deleted is in the list and is not a tail node.", + "tags": [ + "Linked List" + ], + "title-slug": "delete-node-in-a-linked-list" + }, + { + "leetcode-id": 238, + "title": "Product of Array Except Self", + "difficulty": 2, + "description": "Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].\nThe product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.\nYou must write an algorithm that runs in\u00a0O(n)\u00a0time and without using the division operation.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4]\nOutput: [24,12,8,6]", + "Example 2:\nInput: nums = [-1,1,0,-3,3]\nOutput: [0,0,9,0,0]" + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 10^5\n-30 <= nums[i] <= 30\nThe product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.\n\n\u00a0\nFollow up:\u00a0Can you solve the problem in O(1)\u00a0extra\u00a0space complexity? (The output array does not count as extra space for space complexity analysis.)", + "tags": [ + "Array", + "Prefix Sum" + ], + "title-slug": "product-of-array-except-self" + }, + { + "leetcode-id": 239, + "title": "Sliding Window Maximum", + "difficulty": 3, + "description": "You are given an array of integers\u00a0nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.\nReturn the max sliding window.", + "examples": [ + "Example 1:\nInput: nums = [1,3,-1,-3,5,3,6,7], k = 3\nOutput: [3,3,5,5,6,7]\nExplanation: \nWindow position Max\n--------------- -----\n[1 3 -1] -3 5 3 6 7 3\n 1 [3 -1 -3] 5 3 6 7 3\n 1 3 [-1 -3 5] 3 6 7 5\n 1 3 -1 [-3 5 3] 6 7 5\n 1 3 -1 -3 [5 3 6] 7 6\n 1 3 -1 -3 5 [3 6 7] 7", + "Example 2:\nInput: nums = [1], k = 1\nOutput: [1]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^4 <= nums[i] <= 10^4\n1 <= k <= nums.length", + "tags": [ + "Array", + "Queue", + "Sliding Window", + "Heap (Priority Queue)", + "Monotonic Queue" + ], + "title-slug": "sliding-window-maximum" + }, + { + "leetcode-id": 240, + "title": "Search a 2D Matrix II", + "difficulty": 2, + "description": "Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties:\n\nIntegers in each row are sorted in ascending from left to right.\nIntegers in each column are sorted in ascending from top to bottom.", + "examples": [ + "Example 1:\nInput: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5\nOutput: true", + "Example 2:\nInput: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20\nOutput: false" + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= n, m <= 300\n-10^9 <= matrix[i][j] <= 10^9\nAll the integers in each row are sorted in ascending order.\nAll the integers in each column are sorted in ascending order.\n-10^9 <= target <= 10^9", + "tags": [ + "Array", + "Binary Search", + "Divide and Conquer", + "Matrix" + ], + "title-slug": "search-a-2d-matrix-ii" + }, + { + "leetcode-id": 241, + "title": "Different Ways to Add Parentheses", + "difficulty": 2, + "description": "Given a string expression of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. You may return the answer in any order.\nThe test cases are generated such that the output values fit in a 32-bit integer and the number of different results does not exceed 10^4.", + "examples": [ + "Example 1:\nInput: expression = \"2-1-1\"\nOutput: [0,2]\nExplanation:\n((2-1)-1) = 0 \n(2-(1-1)) = 2", + "Example 2:\nInput: expression = \"2*3-4*5\"\nOutput: [-34,-14,-10,-10,10]\nExplanation:\n(2*(3-(4*5))) = -34 \n((2*3)-(4*5)) = -14 \n((2*(3-4))*5) = -10 \n(2*((3-4)*5)) = -10 \n(((2*3)-4)*5) = 10" + ], + "constraints": "Constraints:\n\n1 <= expression.length <= 20\nexpression consists of digits and the operator '+', '-', and '*'.\nAll the integer values in the input expression are in the range [0, 99].", + "tags": [ + "Math", + "String", + "Dynamic Programming", + "Recursion", + "Memoization" + ], + "title-slug": "different-ways-to-add-parentheses" + }, + { + "leetcode-id": 242, + "title": "Valid Anagram", + "difficulty": 1, + "description": "Given two strings s and t, return true if t is an anagram of s, and false otherwise.\nAn Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.", + "examples": [ + "Example 1:\nInput: s = \"anagram\", t = \"nagaram\"\nOutput: true", + "Example 2:\nInput: s = \"rat\", t = \"car\"\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= s.length, t.length <= 5 * 10^4\ns and t consist of lowercase English letters.\n\n\u00a0\nFollow up: What if the inputs contain Unicode characters? How would you adapt your solution to such a case?", + "tags": [ + "Hash Table", + "String", + "Sorting" + ], + "title-slug": "valid-anagram" + }, + { + "leetcode-id": 257, + "title": "Binary Tree Paths", + "difficulty": 1, + "description": "Given the root of a binary tree, return all root-to-leaf paths in any order.\nA leaf is a node with no children.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,null,5]\nOutput: [\"1->2->5\",\"1->3\"]", + "Example 2:\nInput: root = [1]\nOutput: [\"1\"]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 100].\n-100 <= Node.val <= 100", + "tags": [ + "String", + "Backtracking", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "binary-tree-paths" + }, + { + "leetcode-id": 258, + "title": "Add Digits", + "difficulty": 1, + "description": "Given an integer num, repeatedly add all its digits until the result has only one digit, and return it.", + "examples": [ + "Example 1:\nInput: num = 38\nOutput: 2\nExplanation: The process is\n38 --> 3 + 8 --> 11\n11 --> 1 + 1 --> 2 \nSince 2 has only one digit, return it.", + "Example 2:\nInput: num = 0\nOutput: 0" + ], + "constraints": "Constraints:\n\n0 <= num <= 2^31 - 1\n\n\u00a0\nFollow up: Could you do it without any loop/recursion in O(1) runtime?", + "tags": [ + "Math", + "Simulation", + "Number Theory" + ], + "title-slug": "add-digits" + }, + { + "leetcode-id": 260, + "title": "Single Number III", + "difficulty": 2, + "description": "Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order.\nYou must write an\u00a0algorithm that runs in linear runtime complexity and uses\u00a0only constant extra space.", + "examples": [ + "Example 1:\nInput: nums = [1,2,1,3,2,5]\nOutput: [3,5]\nExplanation: [5, 3] is also a valid answer.", + "Example 2:\nInput: nums = [-1,0]\nOutput: [-1,0]", + "Example 3:\nInput: nums = [0,1]\nOutput: [1,0]" + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 3 * 10^4\n-2^31 <= nums[i] <= 2^31 - 1\nEach integer in nums will appear twice, only two integers will appear once.", + "tags": [ + "Array", + "Bit Manipulation" + ], + "title-slug": "single-number-iii" + }, + { + "leetcode-id": 263, + "title": "Ugly Number", + "difficulty": 1, + "description": "An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.\nGiven an integer n, return true if n is an ugly number.", + "examples": [ + "Example 1:\nInput: n = 6\nOutput: true\nExplanation: 6 = 2 \u00d7 3", + "Example 2:\nInput: n = 1\nOutput: true\nExplanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.", + "Example 3:\nInput: n = 14\nOutput: false\nExplanation: 14 is not ugly since it includes the prime factor 7." + ], + "constraints": "Constraints:\n\n-2^31 <= n <= 2^31 - 1", + "tags": [ + "Math" + ], + "title-slug": "ugly-number" + }, + { + "leetcode-id": 264, + "title": "Ugly Number II", + "difficulty": 2, + "description": "An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.\nGiven an integer n, return the n^th ugly number.", + "examples": [ + "Example 1:\nInput: n = 10\nOutput: 12\nExplanation: [1, 2, 3, 4, 5, 6, 8, 9, 10, 12] is the sequence of the first 10 ugly numbers.", + "Example 2:\nInput: n = 1\nOutput: 1\nExplanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5." + ], + "constraints": "Constraints:\n\n1 <= n <= 1690", + "tags": [ + "Hash Table", + "Math", + "Dynamic Programming", + "Heap (Priority Queue)" + ], + "title-slug": "ugly-number-ii" + }, + { + "leetcode-id": 268, + "title": "Missing Number", + "difficulty": 1, + "description": "Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.", + "examples": [ + "Example 1:\nInput: nums = [3,0,1]\nOutput: 2\nExplanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3]. 2 is the missing number in the range since it does not appear in nums.", + "Example 2:\nInput: nums = [0,1]\nOutput: 2\nExplanation: n = 2 since there are 2 numbers, so all numbers are in the range [0,2]. 2 is the missing number in the range since it does not appear in nums.", + "Example 3:\nInput: nums = [9,6,4,2,3,5,7,0,1]\nOutput: 8\nExplanation: n = 9 since there are 9 numbers, so all numbers are in the range [0,9]. 8 is the missing number in the range since it does not appear in nums." + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^4\n0 <= nums[i] <= n\nAll the numbers of nums are unique.\n\n\u00a0\nFollow up: Could you implement a solution using only O(1) extra space complexity and O(n) runtime complexity?", + "tags": [ + "Array", + "Hash Table", + "Math", + "Binary Search", + "Bit Manipulation", + "Sorting" + ], + "title-slug": "missing-number" + }, + { + "leetcode-id": 273, + "title": "Integer to English Words", + "difficulty": 3, + "description": "Convert a non-negative integer num to its English words representation.", + "examples": [ + "Example 1:\nInput: num = 123\nOutput: \"One Hundred Twenty Three\"", + "Example 2:\nInput: num = 12345\nOutput: \"Twelve Thousand Three Hundred Forty Five\"", + "Example 3:\nInput: num = 1234567\nOutput: \"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven\"" + ], + "constraints": "Constraints:\n\n0 <= num <= 2^31 - 1", + "tags": [ + "Math", + "String", + "Recursion" + ], + "title-slug": "integer-to-english-words" + }, + { + "leetcode-id": 274, + "title": "H-Index", + "difficulty": 2, + "description": "Given an array of integers citations where citations[i] is the number of citations a researcher received for their i^th paper, return the researcher's h-index.\nAccording to the definition of h-index on Wikipedia: The h-index is defined as the maximum value of h such that the given researcher has published at least h papers that have each been cited at least h times.", + "examples": [ + "Example 1:\nInput: citations = [3,0,6,1,5]\nOutput: 3\nExplanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively.\nSince the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.", + "Example 2:\nInput: citations = [1,3,1]\nOutput: 1" + ], + "constraints": "Constraints:\n\nn == citations.length\n1 <= n <= 5000\n0 <= citations[i] <= 1000", + "tags": [ + "Array", + "Sorting", + "Counting Sort" + ], + "title-slug": "h-index" + }, + { + "leetcode-id": 275, + "title": "H-Index II", + "difficulty": 2, + "description": "Given an array of integers citations where citations[i] is the number of citations a researcher received for their i^th paper and citations is sorted in ascending order, return the researcher's h-index.\nAccording to the definition of h-index on Wikipedia: The h-index is defined as the maximum value of h such that the given researcher has published at least h papers that have each been cited at least h times.\nYou must write an algorithm that runs in logarithmic time.", + "examples": [ + "Example 1:\nInput: citations = [0,1,3,5,6]\nOutput: 3\nExplanation: [0,1,3,5,6] means the researcher has 5 papers in total and each of them had received 0, 1, 3, 5, 6 citations respectively.\nSince the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.", + "Example 2:\nInput: citations = [1,2,100]\nOutput: 2" + ], + "constraints": "Constraints:\n\nn == citations.length\n1 <= n <= 10^5\n0 <= citations[i] <= 1000\ncitations is sorted in ascending order.", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "h-index-ii" + }, + { + "leetcode-id": 278, + "title": "First Bad Version", + "difficulty": 1, + "description": "You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.\nSuppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad.\nYou are given an API bool isBadVersion(version) which returns whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.", + "examples": [ + "Example 1:\nInput: n = 5, bad = 4\nOutput: 4\nExplanation:\ncall isBadVersion(3) -> false\ncall isBadVersion(5)\u00a0-> true\ncall isBadVersion(4)\u00a0-> true\nThen 4 is the first bad version.", + "Example 2:\nInput: n = 1, bad = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= bad <= n <= 2^31 - 1", + "tags": [ + "Binary Search", + "Interactive" + ], + "title-slug": "first-bad-version" + }, + { + "leetcode-id": 279, + "title": "Perfect Squares", + "difficulty": 2, + "description": "Given an integer n, return the least number of perfect square numbers that sum to n.\nA perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not.", + "examples": [ + "Example 1:\nInput: n = 12\nOutput: 3\nExplanation: 12 = 4 + 4 + 4.", + "Example 2:\nInput: n = 13\nOutput: 2\nExplanation: 13 = 4 + 9." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^4", + "tags": [ + "Math", + "Dynamic Programming", + "Breadth-First Search" + ], + "title-slug": "perfect-squares" + }, + { + "leetcode-id": 282, + "title": "Expression Add Operators", + "difficulty": 3, + "description": "Given a string num that contains only digits and an integer target, return all possibilities to insert the binary operators '+', '-', and/or '*' between the digits of num so that the resultant expression evaluates to the target value.\nNote that operands in the returned expressions should not contain leading zeros.", + "examples": [ + "Example 1:\nInput: num = \"123\", target = 6\nOutput: [\"1*2*3\",\"1+2+3\"]\nExplanation: Both \"1*2*3\" and \"1+2+3\" evaluate to 6.", + "Example 2:\nInput: num = \"232\", target = 8\nOutput: [\"2*3+2\",\"2+3*2\"]\nExplanation: Both \"2*3+2\" and \"2+3*2\" evaluate to 8.", + "Example 3:\nInput: num = \"3456237490\", target = 9191\nOutput: []\nExplanation: There are no expressions that can be created from \"3456237490\" to evaluate to 9191." + ], + "constraints": "Constraints:\n\n1 <= num.length <= 10\nnum consists of only digits.\n-2^31 <= target <= 2^31 - 1", + "tags": [ + "Math", + "String", + "Backtracking" + ], + "title-slug": "expression-add-operators" + }, + { + "leetcode-id": 283, + "title": "Move Zeroes", + "difficulty": 1, + "description": "Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.\nNote that you must do this in-place without making a copy of the array.", + "examples": [ + "Example 1:\nInput: nums = [0,1,0,3,12]\nOutput: [1,3,12,0,0]", + "Example 2:\nInput: nums = [0]\nOutput: [0]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-2^31 <= nums[i] <= 2^31 - 1\n\n\u00a0\nFollow up: Could you minimize the total number of operations done?", + "tags": [ + "Array", + "Two Pointers" + ], + "title-slug": "move-zeroes" + }, + { + "leetcode-id": 284, + "title": "Peeking Iterator", + "difficulty": 2, + "description": "Design an iterator that supports the peek operation on an existing iterator in addition to the hasNext and the next operations.\nImplement the PeekingIterator class:\n\nPeekingIterator(Iterator nums) Initializes the object with the given integer iterator iterator.\nint next() Returns the next element in the array and moves the pointer to the next element.\nboolean hasNext() Returns true if there are still elements in the array.\nint peek() Returns the next element in the array without moving the pointer.\n\nNote: Each language may have a different implementation of the constructor and Iterator, but they all support the int next() and boolean hasNext() functions.", + "examples": [ + "Example 1:\nInput\n[\"PeekingIterator\", \"next\", \"peek\", \"next\", \"next\", \"hasNext\"]\n[[[1, 2, 3]], [], [], [], [], []]\nOutput\n[null, 1, 2, 2, 3, false]\n\nExplanation\nPeekingIterator peekingIterator = new PeekingIterator([1, 2, 3]); // [1,2,3]\npeekingIterator.next(); // return 1, the pointer moves to the next element [1,2,3].\npeekingIterator.peek(); // return 2, the pointer does not move [1,2,3].\npeekingIterator.next(); // return 2, the pointer moves to the next element [1,2,3]\npeekingIterator.next(); // return 3, the pointer moves to the next element [1,2,3]\npeekingIterator.hasNext(); // return False" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 1000\nAll the calls to next and peek are valid.\nAt most 1000 calls will be made to next, hasNext, and peek.\n\n\u00a0\nFollow up: How would you extend your design to be generic and work with all types, not just integer?", + "tags": [ + "Array", + "Design", + "Iterator" + ], + "title-slug": "peeking-iterator" + }, + { + "leetcode-id": 287, + "title": "Find the Duplicate Number", + "difficulty": 2, + "description": "Given an array of integers nums containing\u00a0n + 1 integers where each integer is in the range [1, n] inclusive.\nThere is only one repeated number in nums, return this\u00a0repeated\u00a0number.\nYou must solve the problem without modifying the array nums\u00a0and uses only constant extra space.", + "examples": [ + "Example 1:\nInput: nums = [1,3,4,2,2]\nOutput: 2", + "Example 2:\nInput: nums = [3,1,3,4,2]\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5\nnums.length == n + 1\n1 <= nums[i] <= n\nAll the integers in nums appear only once except for precisely one integer which appears two or more times.\n\n\u00a0\nFollow up:\n\nHow can we prove that at least one duplicate number must exist in nums?\nCan you solve the problem in linear runtime complexity?", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Bit Manipulation" + ], + "title-slug": "find-the-duplicate-number" + }, + { + "leetcode-id": 289, + "title": "Game of Life", + "difficulty": 2, + "description": "According to\u00a0Wikipedia's article: \"The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.\"\nThe board is made up of an m x n grid of cells, where each cell has an initial state: live (represented by a 1) or dead (represented by a 0). Each cell interacts with its eight neighbors (horizontal, vertical, diagonal) using the following four rules (taken from the above Wikipedia article):\n\nAny live cell with fewer than two live neighbors dies as if caused by under-population.\nAny live cell with two or three live neighbors lives on to the next generation.\nAny live cell with more than three live neighbors dies, as if by over-population.\nAny dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.\n\nThe next state is created by applying the above rules simultaneously to every cell in the current state, where births and deaths occur simultaneously. Given the current state of the m x n grid board, return the next state.", + "examples": [ + "Example 1:\nInput: board = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]]\nOutput: [[0,0,0],[1,0,1],[0,1,1],[0,1,0]]", + "Example 2:\nInput: board = [[1,1],[1,0]]\nOutput: [[1,1],[1,1]]" + ], + "constraints": "Constraints:\n\nm == board.length\nn == board[i].length\n1 <= m, n <= 25\nboard[i][j] is 0 or 1.\n\n\u00a0\nFollow up:\n\nCould you solve it in-place? Remember that the board needs to be updated simultaneously: You cannot update some cells first and then use their updated values to update other cells.\nIn this question, we represent the board using a 2D array. In principle, the board is infinite, which would cause problems when the active area encroaches upon the border of the array (i.e., live cells reach the border). How would you address these problems?", + "tags": [ + "Array", + "Matrix", + "Simulation" + ], + "title-slug": "game-of-life" + }, + { + "leetcode-id": 290, + "title": "Word Pattern", + "difficulty": 1, + "description": "Given a pattern and a string s, find if s\u00a0follows the same pattern.\nHere follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in s.", + "examples": [ + "Example 1:\nInput: pattern = \"abba\", s = \"dog cat cat dog\"\nOutput: true", + "Example 2:\nInput: pattern = \"abba\", s = \"dog cat cat fish\"\nOutput: false", + "Example 3:\nInput: pattern = \"aaaa\", s = \"dog cat cat dog\"\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= pattern.length <= 300\npattern contains only lower-case English letters.\n1 <= s.length <= 3000\ns contains only lowercase English letters and spaces ' '.\ns does not contain any leading or trailing spaces.\nAll the words in s are separated by a single space.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "word-pattern" + }, + { + "leetcode-id": 292, + "title": "Nim Game", + "difficulty": 1, + "description": "You are playing the following Nim Game with your friend:\n\nInitially, there is a heap of stones on the table.\nYou and your friend will alternate taking turns, and you go first.\nOn each turn, the person whose turn it is will remove 1 to 3 stones from the heap.\nThe one who removes the last stone is the winner.\n\nGiven n, the number of stones in the heap, return true if you can win the game assuming both you and your friend play optimally, otherwise return false.", + "examples": [ + "Example 1:\nInput: n = 4\nOutput: false\nExplanation: These are the possible outcomes:\n1. You remove 1 stone. Your friend removes 3 stones, including the last stone. Your friend wins.\n2. You remove 2 stones. Your friend removes 2 stones, including the last stone. Your friend wins.\n3. You remove 3 stones. Your friend removes the last stone. Your friend wins.\nIn all outcomes, your friend wins.", + "Example 2:\nInput: n = 1\nOutput: true", + "Example 3:\nInput: n = 2\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= n <= 2^31 - 1", + "tags": [ + "Math", + "Brainteaser", + "Game Theory" + ], + "title-slug": "nim-game" + }, + { + "leetcode-id": 295, + "title": "Find Median from Data Stream", + "difficulty": 3, + "description": "The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values.\n\nFor example, for arr = [2,3,4], the median is 3.\nFor example, for arr = [2,3], the median is (2 + 3) / 2 = 2.5.\n\nImplement the MedianFinder class:\n\nMedianFinder() initializes the MedianFinder object.\nvoid addNum(int num) adds the integer num from the data stream to the data structure.\ndouble findMedian() returns the median of all elements so far. Answers within 10^-5 of the actual answer will be accepted.", + "examples": [ + "Example 1:\nInput\n[\"MedianFinder\", \"addNum\", \"addNum\", \"findMedian\", \"addNum\", \"findMedian\"]\n[[], [1], [2], [], [3], []]\nOutput\n[null, null, null, 1.5, null, 2.0]\n\nExplanation\nMedianFinder medianFinder = new MedianFinder();\nmedianFinder.addNum(1); // arr = [1]\nmedianFinder.addNum(2); // arr = [1, 2]\nmedianFinder.findMedian(); // return 1.5 (i.e., (1 + 2) / 2)\nmedianFinder.addNum(3); // arr[1, 2, 3]\nmedianFinder.findMedian(); // return 2.0" + ], + "constraints": "Constraints:\n\n-10^5 <= num <= 10^5\nThere will be at least one element in the data structure before calling findMedian.\nAt most 5 * 10^4 calls will be made to addNum and findMedian.\n\n\u00a0\nFollow up:\n\nIf all integer numbers from the stream are in the range [0, 100], how would you optimize your solution?\nIf 99% of all integer numbers from the stream are in the range [0, 100], how would you optimize your solution?", + "tags": [ + "Two Pointers", + "Design", + "Sorting", + "Heap (Priority Queue)", + "Data Stream" + ], + "title-slug": "find-median-from-data-stream" + }, + { + "leetcode-id": 297, + "title": "Serialize and Deserialize Binary Tree", + "difficulty": 3, + "description": "Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.\nDesign an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.\nClarification: The input/output format is the same as how LeetCode serializes a binary tree. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,null,null,4,5]\nOutput: [1,2,3,null,null,4,5]", + "Example 2:\nInput: root = []\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 10^4].\n-1000 <= Node.val <= 1000", + "tags": [ + "String", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Design", + "Binary Tree" + ], + "title-slug": "serialize-and-deserialize-binary-tree" + }, + { + "leetcode-id": 299, + "title": "Bulls and Cows", + "difficulty": 2, + "description": "You are playing the Bulls and Cows game with your friend.\nYou write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:\n\nThe number of \"bulls\", which are digits in the guess that are in the correct position.\nThe number of \"cows\", which are digits in the guess that are in your secret number but are located in the wrong position. Specifically, the non-bull digits in the guess that could be rearranged such that they become bulls.\n\nGiven the secret number secret and your friend's guess guess, return the hint for your friend's guess.\nThe hint should be formatted as \"xAyB\", where x is the number of bulls and y is the number of cows. Note that both secret and guess may contain duplicate digits.", + "examples": [ + "Example 1:\nInput: secret = \"1807\", guess = \"7810\"\nOutput: \"1A3B\"\nExplanation: Bulls are connected with a '|' and cows are underlined:\n\"1807\"\n |\n\"7810\"", + "Example 2:\nInput: secret = \"1123\", guess = \"0111\"\nOutput: \"1A1B\"\nExplanation: Bulls are connected with a '|' and cows are underlined:\n\"1123\" \"1123\"\n | or |\n\"0111\" \"0111\"\nNote that only one of the two unmatched 1s is counted as a cow since the non-bull digits can only be rearranged to allow one 1 to be a bull." + ], + "constraints": "Constraints:\n\n1 <= secret.length, guess.length <= 1000\nsecret.length == guess.length\nsecret and guess consist of digits only.", + "tags": [ + "Hash Table", + "String", + "Counting" + ], + "title-slug": "bulls-and-cows" + }, + { + "leetcode-id": 300, + "title": "Longest Increasing Subsequence", + "difficulty": 2, + "description": "Given an integer array nums, return the length of the longest strictly increasing subsequence.", + "examples": [ + "Example 1:\nInput: nums = [10,9,2,5,3,7,101,18]\nOutput: 4\nExplanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.", + "Example 2:\nInput: nums = [0,1,0,3,2,3]\nOutput: 4", + "Example 3:\nInput: nums = [7,7,7,7,7,7,7]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 2500\n-10^4 <= nums[i] <= 10^4\n\n\u00a0\nFollow up:\u00a0Can you come up with an algorithm that runs in\u00a0O(n log(n)) time complexity?", + "tags": [ + "Array", + "Binary Search", + "Dynamic Programming" + ], + "title-slug": "longest-increasing-subsequence" + }, + { + "leetcode-id": 301, + "title": "Remove Invalid Parentheses", + "difficulty": 3, + "description": "Given a string s that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.\nReturn a list of unique strings that are valid with the minimum number of removals. You may return the answer in any order.", + "examples": [ + "Example 1:\nInput: s = \"()())()\"\nOutput: [\"(())()\",\"()()()\"]", + "Example 2:\nInput: s = \"(a)())()\"\nOutput: [\"(a())()\",\"(a)()()\"]", + "Example 3:\nInput: s = \")(\"\nOutput: [\"\"]" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 25\ns consists of lowercase English letters and parentheses '(' and ')'.\nThere will be at most 20 parentheses in s.", + "tags": [ + "String", + "Backtracking", + "Breadth-First Search" + ], + "title-slug": "remove-invalid-parentheses" + }, + { + "leetcode-id": 303, + "title": "Range Sum Query - Immutable", + "difficulty": 1, + "description": "Given an integer array nums, handle multiple queries of the following type:\n\nCalculate the sum of the elements of nums between indices left and right inclusive where left <= right.\n\nImplement the NumArray class:\n\nNumArray(int[] nums) Initializes the object with the integer array nums.\nint sumRange(int left, int right) Returns the sum of the elements of nums between indices left and right inclusive (i.e. nums[left] + nums[left + 1] + ... + nums[right]).", + "examples": [ + "Example 1:\nInput\n[\"NumArray\", \"sumRange\", \"sumRange\", \"sumRange\"]\n[[[-2, 0, 3, -5, 2, -1]], [0, 2], [2, 5], [0, 5]]\nOutput\n[null, 1, -1, -3]\n\nExplanation\nNumArray numArray = new NumArray([-2, 0, 3, -5, 2, -1]);\nnumArray.sumRange(0, 2); // return (-2) + 0 + 3 = 1\nnumArray.sumRange(2, 5); // return 3 + (-5) + 2 + (-1) = -1\nnumArray.sumRange(0, 5); // return (-2) + 0 + 3 + (-5) + 2 + (-1) = -3" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-10^5 <= nums[i] <= 10^5\n0 <= left <= right < nums.length\nAt most 10^4 calls will be made to sumRange.", + "tags": [ + "Array", + "Design", + "Prefix Sum" + ], + "title-slug": "range-sum-query-immutable" + }, + { + "leetcode-id": 304, + "title": "Range Sum Query 2D - Immutable", + "difficulty": 2, + "description": "Given a 2D matrix matrix, handle multiple queries of the following type:\n\nCalculate the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).\n\nImplement the NumMatrix class:\n\nNumMatrix(int[][] matrix) Initializes the object with the integer matrix matrix.\nint sumRegion(int row1, int col1, int row2, int col2) Returns the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).\n\nYou must design an algorithm where sumRegion works on O(1) time complexity.", + "examples": [ + "Example 1:\nInput\n[\"NumMatrix\", \"sumRegion\", \"sumRegion\", \"sumRegion\"]\n[[[[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5], [4, 1, 0, 1, 7], [1, 0, 3, 0, 5]]], [2, 1, 4, 3], [1, 1, 2, 2], [1, 2, 2, 4]]\nOutput\n[null, 8, 11, 12]\n\nExplanation\nNumMatrix numMatrix = new NumMatrix([[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5], [4, 1, 0, 1, 7], [1, 0, 3, 0, 5]]);\nnumMatrix.sumRegion(2, 1, 4, 3); // return 8 (i.e sum of the red rectangle)\nnumMatrix.sumRegion(1, 1, 2, 2); // return 11 (i.e sum of the green rectangle)\nnumMatrix.sumRegion(1, 2, 2, 4); // return 12 (i.e sum of the blue rectangle)" + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= m, n <= 200\n-10^4 <= matrix[i][j] <= 10^4\n0 <= row1 <= row2 < m\n0 <= col1 <= col2 < n\nAt most 10^4 calls will be made to sumRegion.", + "tags": [ + "Array", + "Design", + "Matrix", + "Prefix Sum" + ], + "title-slug": "range-sum-query-2d-immutable" + }, + { + "leetcode-id": 306, + "title": "Additive Number", + "difficulty": 2, + "description": "An additive number is a string whose digits can form an additive sequence.\nA valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the sequence must be the sum of the preceding two.\nGiven a string containing only digits, return true if it is an additive number or false otherwise.\nNote: Numbers in the additive sequence cannot have leading zeros, so sequence 1, 2, 03 or 1, 02, 3 is invalid.", + "examples": [ + "Example 1:\nInput: \"112358\"\nOutput: true\nExplanation: \nThe digits can form an additive sequence: 1, 1, 2, 3, 5, 8. \n1 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, 3 + 5 = 8", + "Example 2:\nInput: \"199100199\"\nOutput: true\nExplanation: \nThe additive sequence is: 1, 99, 100, 199.\u00a0\n1 + 99 = 100, 99 + 100 = 199" + ], + "constraints": "Constraints:\n\n1 <= num.length <= 35\nnum consists only of digits.\n\n\u00a0\nFollow up: How would you handle overflow for very large input integers?", + "tags": [ + "String", + "Backtracking" + ], + "title-slug": "additive-number" + }, + { + "leetcode-id": 307, + "title": "Range Sum Query - Mutable", + "difficulty": 2, + "description": "Given an integer array nums, handle multiple queries of the following types:\n\nUpdate the value of an element in nums.\nCalculate the sum of the elements of nums between indices left and right inclusive where left <= right.\n\nImplement the NumArray class:\n\nNumArray(int[] nums) Initializes the object with the integer array nums.\nvoid update(int index, int val) Updates the value of nums[index] to be val.\nint sumRange(int left, int right) Returns the sum of the elements of nums between indices left and right inclusive (i.e. nums[left] + nums[left + 1] + ... + nums[right]).", + "examples": [ + "Example 1:\nInput\n[\"NumArray\", \"sumRange\", \"update\", \"sumRange\"]\n[[[1, 3, 5]], [0, 2], [1, 2], [0, 2]]\nOutput\n[null, 9, null, 8]\n\nExplanation\nNumArray numArray = new NumArray([1, 3, 5]);\nnumArray.sumRange(0, 2); // return 1 + 3 + 5 = 9\nnumArray.update(1, 2); // nums = [1, 2, 5]\nnumArray.sumRange(0, 2); // return 1 + 2 + 5 = 8" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 3 * 10^4\n-100 <= nums[i] <= 100\n0 <= index < nums.length\n-100 <= val <= 100\n0 <= left <= right < nums.length\nAt most 3 * 10^4 calls will be made to update and sumRange.", + "tags": [ + "Array", + "Design", + "Binary Indexed Tree", + "Segment Tree" + ], + "title-slug": "range-sum-query-mutable" + }, + { + "leetcode-id": 309, + "title": "Best Time to Buy and Sell Stock with Cooldown", + "difficulty": 2, + "description": "You are given an array prices where prices[i] is the price of a given stock on the i^th day.\nFind the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times) with the following restrictions:\n\nAfter you sell your stock, you cannot buy stock on the next day (i.e., cooldown one day).\n\nNote: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).", + "examples": [ + "Example 1:\nInput: prices = [1,2,3,0,2]\nOutput: 3\nExplanation: transactions = [buy, sell, cooldown, buy, sell]", + "Example 2:\nInput: prices = [1]\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= prices.length <= 5000\n0 <= prices[i] <= 1000", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "best-time-to-buy-and-sell-stock-with-cooldown" + }, + { + "leetcode-id": 310, + "title": "Minimum Height Trees", + "difficulty": 2, + "description": "A tree is an undirected graph in which any two vertices are connected by\u00a0exactly\u00a0one path. In other words, any connected graph without simple cycles is a tree.\nGiven a tree of n nodes\u00a0labelled from 0 to n - 1, and an array of\u00a0n - 1\u00a0edges where edges[i] = [ai, bi] indicates that there is an undirected edge between the two nodes\u00a0ai and\u00a0bi in the tree,\u00a0you can choose any node of the tree as the root. When you select a node x as the root, the result tree has height h. Among all possible rooted trees, those with minimum height (i.e. min(h))\u00a0 are called minimum height trees (MHTs).\nReturn a list of all MHTs' root labels.\u00a0You can return the answer in any order.\nThe height of a rooted tree is the number of edges on the longest downward path between the root and a leaf.", + "examples": [ + "Example 1:\nInput: n = 4, edges = [[1,0],[1,2],[1,3]]\nOutput: [1]\nExplanation: As shown, the height of the tree is 1 when the root is the node with label 1 which is the only MHT.", + "Example 2:\nInput: n = 6, edges = [[3,0],[3,1],[3,2],[3,4],[5,4]]\nOutput: [3,4]" + ], + "constraints": "Constraints:\n\n1 <= n <= 2 * 10^4\nedges.length == n - 1\n0 <= ai, bi < n\nai != bi\nAll the pairs (ai, bi) are distinct.\nThe given input is guaranteed to be a tree and there will be no repeated edges.", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Graph", + "Topological Sort" + ], + "title-slug": "minimum-height-trees" + }, + { + "leetcode-id": 312, + "title": "Burst Balloons", + "difficulty": 3, + "description": "You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked to burst all the balloons.\nIf you burst the i^th balloon, you will get nums[i - 1] * nums[i] * nums[i + 1] coins. If i - 1 or i + 1 goes out of bounds of the array, then treat it as if there is a balloon with a 1 painted on it.\nReturn the maximum coins you can collect by bursting the balloons wisely.", + "examples": [ + "Example 1:\nInput: nums = [3,1,5,8]\nOutput: 167\nExplanation:\nnums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []\ncoins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167", + "Example 2:\nInput: nums = [1,5]\nOutput: 10" + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 300\n0 <= nums[i] <= 100", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "burst-balloons" + }, + { + "leetcode-id": 313, + "title": "Super Ugly Number", + "difficulty": 2, + "description": "A super ugly number is a positive integer whose prime factors are in the array primes.\nGiven an integer n and an array of integers primes, return the n^th super ugly number.\nThe n^th super ugly number is guaranteed to fit in a 32-bit signed integer.", + "examples": [ + "Example 1:\nInput: n = 12, primes = [2,7,13,19]\nOutput: 32\nExplanation: [1,2,4,7,8,13,14,16,19,26,28,32] is the sequence of the first 12 super ugly numbers given primes = [2,7,13,19].", + "Example 2:\nInput: n = 1, primes = [2,3,5]\nOutput: 1\nExplanation: 1 has no prime factors, therefore all of its prime factors are in the array primes = [2,3,5]." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5\n1 <= primes.length <= 100\n2 <= primes[i] <= 1000\nprimes[i] is guaranteed to be a prime number.\nAll the values of primes are unique and sorted in ascending order.", + "tags": [ + "Array", + "Math", + "Dynamic Programming" + ], + "title-slug": "super-ugly-number" + }, + { + "leetcode-id": 315, + "title": "Count of Smaller Numbers After Self", + "difficulty": 3, + "description": "Given an integer array nums, return an integer array counts where counts[i] is the number of smaller elements to the right of nums[i].", + "examples": [ + "Example 1:\nInput: nums = [5,2,6,1]\nOutput: [2,1,1,0]\nExplanation:\nTo the right of 5 there are 2 smaller elements (2 and 1).\nTo the right of 2 there is only 1 smaller element (1).\nTo the right of 6 there is 1 smaller element (1).\nTo the right of 1 there is 0 smaller element.", + "Example 2:\nInput: nums = [-1]\nOutput: [0]", + "Example 3:\nInput: nums = [-1,-1]\nOutput: [0,0]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^4 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Binary Search", + "Divide and Conquer", + "Binary Indexed Tree", + "Segment Tree", + "Merge Sort", + "Ordered Set" + ], + "title-slug": "count-of-smaller-numbers-after-self" + }, + { + "leetcode-id": 316, + "title": "Remove Duplicate Letters", + "difficulty": 2, + "description": "Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.", + "examples": [ + "Example 1:\nInput: s = \"bcabc\"\nOutput: \"abc\"", + "Example 2:\nInput: s = \"cbacdcbc\"\nOutput: \"acdb\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^4\ns consists of lowercase English letters.\n\n\u00a0\nNote: This question is the same as 1081: https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/", + "tags": [ + "String", + "Stack", + "Greedy", + "Monotonic Stack" + ], + "title-slug": "remove-duplicate-letters" + }, + { + "leetcode-id": 318, + "title": "Maximum Product of Word Lengths", + "difficulty": 2, + "description": "Given a string array words, return the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. If no such two words exist, return 0.", + "examples": [ + "Example 1:\nInput: words = [\"abcw\",\"baz\",\"foo\",\"bar\",\"xtfn\",\"abcdef\"]\nOutput: 16\nExplanation: The two words can be \"abcw\", \"xtfn\".", + "Example 2:\nInput: words = [\"a\",\"ab\",\"abc\",\"d\",\"cd\",\"bcd\",\"abcd\"]\nOutput: 4\nExplanation: The two words can be \"ab\", \"cd\".", + "Example 3:\nInput: words = [\"a\",\"aa\",\"aaa\",\"aaaa\"]\nOutput: 0\nExplanation: No such pair of words." + ], + "constraints": "Constraints:\n\n2 <= words.length <= 1000\n1 <= words[i].length <= 1000\nwords[i] consists only of lowercase English letters.", + "tags": [ + "Array", + "String", + "Bit Manipulation" + ], + "title-slug": "maximum-product-of-word-lengths" + }, + { + "leetcode-id": 319, + "title": "Bulb Switcher", + "difficulty": 2, + "description": "There are n bulbs that are initially off. You first turn on all the bulbs, then\u00a0you turn off every second bulb.\nOn the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the i^th round, you toggle every i bulb. For the n^th round, you only toggle the last bulb.\nReturn the number of bulbs that are on after n rounds.", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: 1\nExplanation: At first, the three bulbs are [off, off, off].\nAfter the first round, the three bulbs are [on, on, on].\nAfter the second round, the three bulbs are [on, off, on].\nAfter the third round, the three bulbs are [on, off, off]. \nSo you should return 1 because there is only one bulb is on.", + "Example 2:\nInput: n = 0\nOutput: 0", + "Example 3:\nInput: n = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n0 <= n <= 10^9", + "tags": [ + "Math", + "Brainteaser" + ], + "title-slug": "bulb-switcher" + }, + { + "leetcode-id": 321, + "title": "Create Maximum Number", + "difficulty": 3, + "description": "You are given two integer arrays nums1 and nums2 of lengths m and n respectively. nums1 and nums2 represent the digits of two numbers. You are also given an integer k.\nCreate the maximum number of length k <= m + n from digits of the two numbers. The relative order of the digits from the same array must be preserved.\nReturn an array of the k digits representing the answer.", + "examples": [ + "Example 1:\nInput: nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5\nOutput: [9,8,6,5,3]", + "Example 2:\nInput: nums1 = [6,7], nums2 = [6,0,4], k = 5\nOutput: [6,7,6,0,4]", + "Example 3:\nInput: nums1 = [3,9], nums2 = [8,9], k = 3\nOutput: [9,8,9]" + ], + "constraints": "Constraints:\n\nm == nums1.length\nn == nums2.length\n1 <= m, n <= 500\n0 <= nums1[i], nums2[i] <= 9\n1 <= k <= m + n", + "tags": [ + "Stack", + "Greedy", + "Monotonic Stack" + ], + "title-slug": "create-maximum-number" + }, + { + "leetcode-id": 322, + "title": "Coin Change", + "difficulty": 2, + "description": "You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.\nReturn the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.\nYou may assume that you have an infinite number of each kind of coin.", + "examples": [ + "Example 1:\nInput: coins = [1,2,5], amount = 11\nOutput: 3\nExplanation: 11 = 5 + 5 + 1", + "Example 2:\nInput: coins = [2], amount = 3\nOutput: -1", + "Example 3:\nInput: coins = [1], amount = 0\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= coins.length <= 12\n1 <= coins[i] <= 2^31 - 1\n0 <= amount <= 10^4", + "tags": [ + "Array", + "Dynamic Programming", + "Breadth-First Search" + ], + "title-slug": "coin-change" + }, + { + "leetcode-id": 324, + "title": "Wiggle Sort II", + "difficulty": 2, + "description": "Given an integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....\nYou may assume the input array always has a valid answer.", + "examples": [ + "Example 1:\nInput: nums = [1,5,1,1,6,4]\nOutput: [1,6,1,5,1,4]\nExplanation: [1,4,1,5,1,6] is also accepted.", + "Example 2:\nInput: nums = [1,3,2,2,3,1]\nOutput: [2,3,1,3,1,2]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 5 * 10^4\n0 <= nums[i] <= 5000\nIt is guaranteed that there will be an answer for the given input nums.\n\n\u00a0\nFollow Up: Can you do it in O(n) time and/or in-place with O(1) extra space?", + "tags": [ + "Array", + "Divide and Conquer", + "Sorting", + "Quickselect" + ], + "title-slug": "wiggle-sort-ii" + }, + { + "leetcode-id": 326, + "title": "Power of Three", + "difficulty": 1, + "description": "Given an integer n, return true if it is a power of three. Otherwise, return false.\nAn integer n is a power of three, if there exists an integer x such that n == 3^x.", + "examples": [ + "Example 1:\nInput: n = 27\nOutput: true\nExplanation: 27 = 3^3", + "Example 2:\nInput: n = 0\nOutput: false\nExplanation: There is no x where 3^x = 0.", + "Example 3:\nInput: n = -1\nOutput: false\nExplanation: There is no x where 3^x = (-1)." + ], + "constraints": "Constraints:\n\n-2^31 <= n <= 2^31 - 1\n\n\u00a0\nFollow up: Could you solve it without loops/recursion?", + "tags": [ + "Math", + "Recursion" + ], + "title-slug": "power-of-three" + }, + { + "leetcode-id": 327, + "title": "Count of Range Sum", + "difficulty": 3, + "description": "Given an integer array nums and two integers lower and upper, return the number of range sums that lie in [lower, upper] inclusive.\nRange sum S(i, j) is defined as the sum of the elements in nums between indices i and j inclusive, where i <= j.", + "examples": [ + "Example 1:\nInput: nums = [-2,5,-1], lower = -2, upper = 2\nOutput: 3\nExplanation: The three ranges are: [0,0], [2,2], and [0,2] and their respective sums are: -2, -1, 2.", + "Example 2:\nInput: nums = [0], lower = 0, upper = 0\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-2^31 <= nums[i] <= 2^31 - 1\n-10^5 <= lower <= upper <= 10^5\nThe answer is guaranteed to fit in a 32-bit integer.", + "tags": [ + "Array", + "Binary Search", + "Divide and Conquer", + "Binary Indexed Tree", + "Segment Tree", + "Merge Sort", + "Ordered Set" + ], + "title-slug": "count-of-range-sum" + }, + { + "leetcode-id": 328, + "title": "Odd Even Linked List", + "difficulty": 2, + "description": "Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list.\nThe first node is considered odd, and the second node is even, and so on.\nNote that the relative order inside both the even and odd groups should remain as it was in the input.\nYou must solve the problem\u00a0in O(1)\u00a0extra space complexity and O(n) time complexity.", + "examples": [ + "Example 1:\nInput: head = [1,2,3,4,5]\nOutput: [1,3,5,2,4]", + "Example 2:\nInput: head = [2,1,3,5,6,4,7]\nOutput: [2,3,6,7,1,5,4]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the linked list is in the range [0, 10^4].\n-10^6 <= Node.val <= 10^6", + "tags": [ + "Linked List" + ], + "title-slug": "odd-even-linked-list" + }, + { + "leetcode-id": 329, + "title": "Longest Increasing Path in a Matrix", + "difficulty": 3, + "description": "Given an m x n integers matrix, return the length of the longest increasing path in matrix.\nFrom each cell, you can either move in four directions: left, right, up, or down. You may not move diagonally or move outside the boundary (i.e., wrap-around is not allowed).", + "examples": [ + "Example 1:\nInput: matrix = [[9,9,4],[6,6,8],[2,1,1]]\nOutput: 4\nExplanation: The longest increasing path is [1, 2, 6, 9].", + "Example 2:\nInput: matrix = [[3,4,5],[3,2,6],[2,2,1]]\nOutput: 4\nExplanation: The longest increasing path is [3, 4, 5, 6]. Moving diagonally is not allowed.", + "Example 3:\nInput: matrix = [[1]]\nOutput: 1" + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= m, n <= 200\n0 <= matrix[i][j] <= 2^31 - 1", + "tags": [ + "Array", + "Dynamic Programming", + "Depth-First Search", + "Breadth-First Search", + "Graph", + "Topological Sort", + "Memoization", + "Matrix" + ], + "title-slug": "longest-increasing-path-in-a-matrix" + }, + { + "leetcode-id": 330, + "title": "Patching Array", + "difficulty": 3, + "description": "Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array.\nReturn the minimum number of patches required.", + "examples": [ + "Example 1:\nInput: nums = [1,3], n = 6\nOutput: 1\nExplanation:\nCombinations of nums are [1], [3], [1,3], which form possible sums of: 1, 3, 4.\nNow if we add/patch 2 to nums, the combinations are: [1], [2], [3], [1,3], [2,3], [1,2,3].\nPossible sums are 1, 2, 3, 4, 5, 6, which now covers the range [1, 6].\nSo we only need 1 patch.", + "Example 2:\nInput: nums = [1,5,10], n = 20\nOutput: 2\nExplanation: The two patches can be [2, 4].", + "Example 3:\nInput: nums = [1,2,2], n = 5\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 10^4\nnums is sorted in ascending order.\n1 <= n <= 2^31 - 1", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "patching-array" + }, + { + "leetcode-id": 331, + "title": "Verify Preorder Serialization of a Binary Tree", + "difficulty": 2, + "description": "One way to serialize a binary tree is to use preorder traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as '#'.\n\nFor example, the above binary tree can be serialized to the string \"9,3,4,#,#,1,#,#,2,#,6,#,#\", where '#' represents a null node.\nGiven a string of comma-separated values preorder, return true if it is a correct preorder traversal serialization of a binary tree.\nIt is guaranteed that each comma-separated value in the string must be either an integer or a character '#' representing null pointer.\nYou may assume that the input format is always valid.\n\nFor example, it could never contain two consecutive commas, such as \"1,,3\".\n\nNote:\u00a0You are not allowed to reconstruct the tree.", + "examples": [ + "Example 1:\nInput: preorder = \"9,3,4,#,#,1,#,#,2,#,6,#,#\"\nOutput: true", + "Example 2:\nInput: preorder = \"1,#\"\nOutput: false", + "Example 3:\nInput: preorder = \"9,#,#,1\"\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= preorder.length <= 10^4\npreorder consist of integers in the range [0, 100] and '#' separated by commas ','.", + "tags": [ + "String", + "Stack", + "Tree", + "Binary Tree" + ], + "title-slug": "verify-preorder-serialization-of-a-binary-tree" + }, + { + "leetcode-id": 332, + "title": "Reconstruct Itinerary", + "difficulty": 3, + "description": "You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.\nAll of the tickets belong to a man who departs from \"JFK\", thus, the itinerary must begin with \"JFK\". If there are multiple valid itineraries, you should return the itinerary that has the smallest lexical order when read as a single string.\n\nFor example, the itinerary [\"JFK\", \"LGA\"] has a smaller lexical order than [\"JFK\", \"LGB\"].\n\nYou may assume all tickets form at least one valid itinerary. You must use all the tickets once and only once.", + "examples": [ + "Example 1:\nInput: tickets = [[\"MUC\",\"LHR\"],[\"JFK\",\"MUC\"],[\"SFO\",\"SJC\"],[\"LHR\",\"SFO\"]]\nOutput: [\"JFK\",\"MUC\",\"LHR\",\"SFO\",\"SJC\"]", + "Example 2:\nInput: tickets = [[\"JFK\",\"SFO\"],[\"JFK\",\"ATL\"],[\"SFO\",\"ATL\"],[\"ATL\",\"JFK\"],[\"ATL\",\"SFO\"]]\nOutput: [\"JFK\",\"ATL\",\"JFK\",\"SFO\",\"ATL\",\"SFO\"]\nExplanation: Another possible reconstruction is [\"JFK\",\"SFO\",\"ATL\",\"JFK\",\"ATL\",\"SFO\"] but it is larger in lexical order." + ], + "constraints": "Constraints:\n\n1 <= tickets.length <= 300\ntickets[i].length == 2\nfromi.length == 3\ntoi.length == 3\nfromi and toi consist of uppercase English letters.\nfromi != toi", + "tags": [ + "Depth-First Search", + "Graph", + "Eulerian Circuit" + ], + "title-slug": "reconstruct-itinerary" + }, + { + "leetcode-id": 334, + "title": "Increasing Triplet Subsequence", + "difficulty": 2, + "description": "Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. If no such indices exists, return false.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4,5]\nOutput: true\nExplanation: Any triplet where i < j < k is valid.", + "Example 2:\nInput: nums = [5,4,3,2,1]\nOutput: false\nExplanation: No triplet exists.", + "Example 3:\nInput: nums = [2,1,5,0,4,6]\nOutput: true\nExplanation: The triplet (3, 4, 5) is valid because nums[3] == 0 < nums[4] == 4 < nums[5] == 6." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 5 * 10^5\n-2^31 <= nums[i] <= 2^31 - 1\n\n\u00a0\nFollow up: Could you implement a solution that runs in O(n) time complexity and O(1) space complexity?", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "increasing-triplet-subsequence" + }, + { + "leetcode-id": 335, + "title": "Self Crossing", + "difficulty": 3, + "description": "You are given an array of integers distance.\nYou start at the point (0, 0) on an X-Y plane, and you move distance[0] meters to the north, then distance[1] meters to the west, distance[2] meters to the south, distance[3] meters to the east, and so on. In other words, after each move, your direction changes counter-clockwise.\nReturn true if your path crosses itself or false if it does not.", + "examples": [ + "Example 1:\nInput: distance = [2,1,1,2]\nOutput: true\nExplanation: The path crosses itself at the point (0, 1).", + "Example 2:\nInput: distance = [1,2,3,4]\nOutput: false\nExplanation: The path does not cross itself at any point.", + "Example 3:\nInput: distance = [1,1,1,2,1]\nOutput: true\nExplanation: The path crosses itself at the point (0, 0)." + ], + "constraints": "Constraints:\n\n1 <=\u00a0distance.length <= 10^5\n1 <=\u00a0distance[i] <= 10^5", + "tags": [ + "Array", + "Math", + "Geometry" + ], + "title-slug": "self-crossing" + }, + { + "leetcode-id": 336, + "title": "Palindrome Pairs", + "difficulty": 3, + "description": "You are given a 0-indexed array of unique strings words.\nA palindrome pair is a pair of integers (i, j) such that:\n\n0 <= i, j < words.length,\ni != j, and\nwords[i] + words[j] (the concatenation of the two strings) is a palindrome.\n\nReturn an array of all the palindrome pairs of words.\nYou must write an algorithm with\u00a0O(sum of words[i].length)\u00a0runtime complexity.", + "examples": [ + "Example 1:\nInput: words = [\"abcd\",\"dcba\",\"lls\",\"s\",\"sssll\"]\nOutput: [[0,1],[1,0],[3,2],[2,4]]\nExplanation: The palindromes are [\"abcddcba\",\"dcbaabcd\",\"slls\",\"llssssll\"]", + "Example 2:\nInput: words = [\"bat\",\"tab\",\"cat\"]\nOutput: [[0,1],[1,0]]\nExplanation: The palindromes are [\"battab\",\"tabbat\"]", + "Example 3:\nInput: words = [\"a\",\"\"]\nOutput: [[0,1],[1,0]]\nExplanation: The palindromes are [\"a\",\"a\"]" + ], + "constraints": "Constraints:\n\n1 <= words.length <= 5000\n0 <= words[i].length <= 300\nwords[i] consists of lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Trie" + ], + "title-slug": "palindrome-pairs" + }, + { + "leetcode-id": 337, + "title": "House Robber III", + "difficulty": 2, + "description": "The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root.\nBesides the root, each house has one and only one parent house. After a tour, the smart thief realized that all houses in this place form a binary tree. It will automatically contact the police if two directly-linked houses were broken into on the same night.\nGiven the root of the binary tree, return the maximum amount of money the thief can rob without alerting the police.", + "examples": [ + "Example 1:\nInput: root = [3,2,3,null,3,null,1]\nOutput: 7\nExplanation: Maximum amount of money the thief can rob = 3 + 3 + 1 = 7.", + "Example 2:\nInput: root = [3,4,5,1,3,null,1]\nOutput: 9\nExplanation: Maximum amount of money the thief can rob = 4 + 5 = 9." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n0 <= Node.val <= 10^4", + "tags": [ + "Dynamic Programming", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "house-robber-iii" + }, + { + "leetcode-id": 338, + "title": "Counting Bits", + "difficulty": 1, + "description": "Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation of i.", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: [0,1,1]\nExplanation:\n0 --> 0\n1 --> 1\n2 --> 10", + "Example 2:\nInput: n = 5\nOutput: [0,1,1,2,1,2]\nExplanation:\n0 --> 0\n1 --> 1\n2 --> 10\n3 --> 11\n4 --> 100\n5 --> 101" + ], + "constraints": "Constraints:\n\n0 <= n <= 10^5\n\n\u00a0\nFollow up:\n\nIt is very easy to come up with a solution with a runtime of O(n log n). Can you do it in linear time O(n) and possibly in a single pass?\nCan you do it without using any built-in function (i.e., like __builtin_popcount in C++)?", + "tags": [ + "Dynamic Programming", + "Bit Manipulation" + ], + "title-slug": "counting-bits" + }, + { + "leetcode-id": 341, + "title": "Flatten Nested List Iterator", + "difficulty": 2, + "description": "You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Implement an iterator to flatten it.\nImplement the NestedIterator class:\n\nNestedIterator(List nestedList) Initializes the iterator with the nested list nestedList.\nint next() Returns the next integer in the nested list.\nboolean hasNext() Returns true if there are still some integers in the nested list and false otherwise.\n\nYour code will be tested with the following pseudocode:\n\ninitialize iterator with nestedList\nres = []\nwhile iterator.hasNext()\n append iterator.next() to the end of res\nreturn res\n\nIf res matches the expected flattened list, then your code will be judged as correct.", + "examples": [ + "Example 1:\nInput: nestedList = [[1,1],2,[1,1]]\nOutput: [1,1,2,1,1]\nExplanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,1,2,1,1].", + "Example 2:\nInput: nestedList = [1,[4,[6]]]\nOutput: [1,4,6]\nExplanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,4,6]." + ], + "constraints": "Constraints:\n\n1 <= nestedList.length <= 500\nThe values of the integers in the nested list is in the range [-10^6, 10^6].", + "tags": [ + "Stack", + "Tree", + "Depth-First Search", + "Design", + "Queue", + "Iterator" + ], + "title-slug": "flatten-nested-list-iterator" + }, + { + "leetcode-id": 342, + "title": "Power of Four", + "difficulty": 1, + "description": "Given an integer n, return true if it is a power of four. Otherwise, return false.\nAn integer n is a power of four, if there exists an integer x such that n == 4^x.", + "examples": [ + "Example 1:\nInput: n = 16\nOutput: true", + "Example 2:\nInput: n = 5\nOutput: false", + "Example 3:\nInput: n = 1\nOutput: true" + ], + "constraints": "Constraints:\n\n-2^31 <= n <= 2^31 - 1\n\n\u00a0\nFollow up: Could you solve it without loops/recursion?", + "tags": [ + "Math", + "Bit Manipulation", + "Recursion" + ], + "title-slug": "power-of-four" + }, + { + "leetcode-id": 343, + "title": "Integer Break", + "difficulty": 2, + "description": "Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers.\nReturn the maximum product you can get.", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: 1\nExplanation: 2 = 1 + 1, 1 \u00d7 1 = 1.", + "Example 2:\nInput: n = 10\nOutput: 36\nExplanation: 10 = 3 + 3 + 4, 3 \u00d7 3 \u00d7 4 = 36." + ], + "constraints": "Constraints:\n\n2 <= n <= 58", + "tags": [ + "Math", + "Dynamic Programming" + ], + "title-slug": "integer-break" + }, + { + "leetcode-id": 344, + "title": "Reverse String", + "difficulty": 1, + "description": "Write a function that reverses a string. The input string is given as an array of characters s.\nYou must do this by modifying the input array in-place with O(1) extra memory.", + "examples": [ + "Example 1:\nInput: s = [\"h\",\"e\",\"l\",\"l\",\"o\"]\nOutput: [\"o\",\"l\",\"l\",\"e\",\"h\"]", + "Example 2:\nInput: s = [\"H\",\"a\",\"n\",\"n\",\"a\",\"h\"]\nOutput: [\"h\",\"a\",\"n\",\"n\",\"a\",\"H\"]" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns[i] is a printable ascii character.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "reverse-string" + }, + { + "leetcode-id": 345, + "title": "Reverse Vowels of a String", + "difficulty": 1, + "description": "Given a string s, reverse only all the vowels in the string and return it.\nThe vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once.", + "examples": [ + "Example 1:\nInput: s = \"hello\"\nOutput: \"holle\"", + "Example 2:\nInput: s = \"leetcode\"\nOutput: \"leotcede\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 3 * 10^5\ns consist of printable ASCII characters.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "reverse-vowels-of-a-string" + }, + { + "leetcode-id": 347, + "title": "Top K Frequent Elements", + "difficulty": 2, + "description": "Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.", + "examples": [ + "Example 1:\nInput: nums = [1,1,1,2,2,3], k = 2\nOutput: [1,2]", + "Example 2:\nInput: nums = [1], k = 1\nOutput: [1]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^4 <= nums[i] <= 10^4\nk is in the range [1, the number of unique elements in the array].\nIt is guaranteed that the answer is unique.\n\n\u00a0\nFollow up: Your algorithm's time complexity must be better than O(n log n), where n is the array's size.", + "tags": [ + "Array", + "Hash Table", + "Divide and Conquer", + "Sorting", + "Heap (Priority Queue)", + "Bucket Sort", + "Counting", + "Quickselect" + ], + "title-slug": "top-k-frequent-elements" + }, + { + "leetcode-id": 349, + "title": "Intersection of Two Arrays", + "difficulty": 1, + "description": "Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order.", + "examples": [ + "Example 1:\nInput: nums1 = [1,2,2,1], nums2 = [2,2]\nOutput: [2]", + "Example 2:\nInput: nums1 = [4,9,5], nums2 = [9,4,9,8,4]\nOutput: [9,4]\nExplanation: [4,9] is also accepted." + ], + "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 1000\n0 <= nums1[i], nums2[i] <= 1000", + "tags": [ + "Array", + "Hash Table", + "Two Pointers", + "Binary Search", + "Sorting" + ], + "title-slug": "intersection-of-two-arrays" + }, + { + "leetcode-id": 350, + "title": "Intersection of Two Arrays II", + "difficulty": 1, + "description": "Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order.", + "examples": [ + "Example 1:\nInput: nums1 = [1,2,2,1], nums2 = [2,2]\nOutput: [2,2]", + "Example 2:\nInput: nums1 = [4,9,5], nums2 = [9,4,9,8,4]\nOutput: [4,9]\nExplanation: [9,4] is also accepted." + ], + "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 1000\n0 <= nums1[i], nums2[i] <= 1000\n\n\u00a0\nFollow up:\n\nWhat if the given array is already sorted? How would you optimize your algorithm?\nWhat if nums1's size is small compared to nums2's size? Which algorithm is better?\nWhat if elements of nums2 are stored on disk, and the memory is limited such that you cannot load all elements into the memory at once?", + "tags": [ + "Array", + "Hash Table", + "Two Pointers", + "Binary Search", + "Sorting" + ], + "title-slug": "intersection-of-two-arrays-ii" + }, + { + "leetcode-id": 352, + "title": "Data Stream as Disjoint Intervals", + "difficulty": 3, + "description": "Given a data stream input of non-negative integers a1, a2, ..., an, summarize the numbers seen so far as a list of disjoint intervals.\nImplement the SummaryRanges class:\n\nSummaryRanges() Initializes the object with an empty stream.\nvoid addNum(int value) Adds the integer value to the stream.\nint[][] getIntervals() Returns a summary of the integers in the stream currently as a list of disjoint intervals [starti, endi]. The answer should be sorted by starti.", + "examples": [ + "Example 1:\nInput\n[\"SummaryRanges\", \"addNum\", \"getIntervals\", \"addNum\", \"getIntervals\", \"addNum\", \"getIntervals\", \"addNum\", \"getIntervals\", \"addNum\", \"getIntervals\"]\n[[], [1], [], [3], [], [7], [], [2], [], [6], []]\nOutput\n[null, null, [[1, 1]], null, [[1, 1], [3, 3]], null, [[1, 1], [3, 3], [7, 7]], null, [[1, 3], [7, 7]], null, [[1, 3], [6, 7]]]\n\nExplanation\nSummaryRanges summaryRanges = new SummaryRanges();\nsummaryRanges.addNum(1); // arr = [1]\nsummaryRanges.getIntervals(); // return [[1, 1]]\nsummaryRanges.addNum(3); // arr = [1, 3]\nsummaryRanges.getIntervals(); // return [[1, 1], [3, 3]]\nsummaryRanges.addNum(7); // arr = [1, 3, 7]\nsummaryRanges.getIntervals(); // return [[1, 1], [3, 3], [7, 7]]\nsummaryRanges.addNum(2); // arr = [1, 2, 3, 7]\nsummaryRanges.getIntervals(); // return [[1, 3], [7, 7]]\nsummaryRanges.addNum(6); // arr = [1, 2, 3, 6, 7]\nsummaryRanges.getIntervals(); // return [[1, 3], [6, 7]]" + ], + "constraints": "Constraints:\n\n0 <= value <= 10^4\nAt most 3 * 10^4 calls will be made to addNum and getIntervals.\nAt most 10^2\u00a0calls will be made to\u00a0getIntervals.\n\n\u00a0\nFollow up: What if there are lots of merges and the number of disjoint intervals is small compared to the size of the data stream?", + "tags": [ + "Binary Search", + "Design", + "Ordered Set" + ], + "title-slug": "data-stream-as-disjoint-intervals" + }, + { + "leetcode-id": 354, + "title": "Russian Doll Envelopes", + "difficulty": 3, + "description": "You are given a 2D array of integers envelopes where envelopes[i] = [wi, hi] represents the width and the height of an envelope.\nOne envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's width and height.\nReturn the maximum number of envelopes you can Russian doll (i.e., put one inside the other).\nNote: You cannot rotate an envelope.", + "examples": [ + "Example 1:\nInput: envelopes = [[5,4],[6,4],[6,7],[2,3]]\nOutput: 3\nExplanation: The maximum number of envelopes you can Russian doll is 3 ([2,3] => [5,4] => [6,7]).", + "Example 2:\nInput: envelopes = [[1,1],[1,1],[1,1]]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= envelopes.length <= 10^5\nenvelopes[i].length == 2\n1 <= wi, hi <= 10^5", + "tags": [ + "Array", + "Binary Search", + "Dynamic Programming", + "Sorting" + ], + "title-slug": "russian-doll-envelopes" + }, + { + "leetcode-id": 355, + "title": "Design Twitter", + "difficulty": 2, + "description": "Design a simplified version of Twitter where users can post tweets, follow/unfollow another user, and is able to see the 10 most recent tweets in the user's news feed.\nImplement the Twitter class:\n\nTwitter() Initializes your twitter object.\nvoid postTweet(int userId, int tweetId) Composes a new tweet with ID tweetId by the user userId. Each call to this function will be made with a unique tweetId.\nList getNewsFeed(int userId) Retrieves the 10 most recent tweet IDs in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user themself. Tweets must be ordered from most recent to least recent.\nvoid follow(int followerId, int followeeId) The user with ID followerId started following the user with ID followeeId.\nvoid unfollow(int followerId, int followeeId) The user with ID followerId started unfollowing the user with ID followeeId.", + "examples": [ + "Example 1:\nInput\n[\"Twitter\", \"postTweet\", \"getNewsFeed\", \"follow\", \"postTweet\", \"getNewsFeed\", \"unfollow\", \"getNewsFeed\"]\n[[], [1, 5], [1], [1, 2], [2, 6], [1], [1, 2], [1]]\nOutput\n[null, null, [5], null, null, [6, 5], null, [5]]\n\nExplanation\nTwitter twitter = new Twitter();\ntwitter.postTweet(1, 5); // User 1 posts a new tweet (id = 5).\ntwitter.getNewsFeed(1); // User 1's news feed should return a list with 1 tweet id -> [5]. return [5]\ntwitter.follow(1, 2); // User 1 follows user 2.\ntwitter.postTweet(2, 6); // User 2 posts a new tweet (id = 6).\ntwitter.getNewsFeed(1); // User 1's news feed should return a list with 2 tweet ids -> [6, 5]. Tweet id 6 should precede tweet id 5 because it is posted after tweet id 5.\ntwitter.unfollow(1, 2); // User 1 unfollows user 2.\ntwitter.getNewsFeed(1); // User 1's news feed should return a list with 1 tweet id -> [5], since user 1 is no longer following user 2." + ], + "constraints": "Constraints:\n\n1 <= userId, followerId, followeeId <= 500\n0 <= tweetId <= 10^4\nAll the tweets have unique IDs.\nAt most 3 * 10^4 calls will be made to postTweet, getNewsFeed, follow, and unfollow.", + "tags": [ + "Hash Table", + "Linked List", + "Design", + "Heap (Priority Queue)" + ], + "title-slug": "design-twitter" + }, + { + "leetcode-id": 357, + "title": "Count Numbers with Unique Digits", + "difficulty": 2, + "description": "Given an integer n, return the count of all numbers with unique digits, x, where 0 <= x < 10^n.", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: 91\nExplanation: The answer should be the total numbers in the range of 0 \u2264 x < 100, excluding 11,22,33,44,55,66,77,88,99", + "Example 2:\nInput: n = 0\nOutput: 1" + ], + "constraints": "Constraints:\n\n0 <= n <= 8", + "tags": [ + "Math", + "Dynamic Programming", + "Backtracking" + ], + "title-slug": "count-numbers-with-unique-digits" + }, + { + "leetcode-id": 363, + "title": "Max Sum of Rectangle No Larger Than K", + "difficulty": 3, + "description": "Given an m x n matrix matrix and an integer k, return the max sum of a rectangle in the matrix such that its sum is no larger than k.\nIt is guaranteed that there will be a rectangle with a sum no larger than k.", + "examples": [ + "Example 1:\nInput: matrix = [[1,0,1],[0,-2,3]], k = 2\nOutput: 2\nExplanation: Because the sum of the blue rectangle [[0, 1], [-2, 3]] is 2, and 2 is the max number no larger than k (k = 2).", + "Example 2:\nInput: matrix = [[2,2,-1]], k = 3\nOutput: 3" + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= m, n <= 100\n-100 <= matrix[i][j] <= 100\n-10^5 <= k <= 10^5\n\n\u00a0\nFollow up: What if the number of rows is much larger than the number of columns?", + "tags": [ + "Array", + "Binary Search", + "Matrix", + "Prefix Sum", + "Ordered Set" + ], + "title-slug": "max-sum-of-rectangle-no-larger-than-k" + }, + { + "leetcode-id": 365, + "title": "Water and Jug Problem", + "difficulty": 2, + "description": "You are given two jugs with capacities jug1Capacity and jug2Capacity liters. There is an infinite amount of water supply available. Determine whether it is possible to measure exactly targetCapacity liters using these two jugs.\nIf targetCapacity liters of water are measurable, you must have targetCapacity liters of water contained within one or both buckets by the end.\nOperations allowed:\n\nFill any of the jugs with water.\nEmpty any of the jugs.\nPour water from one jug into another till the other jug is completely full, or the first jug itself is empty.", + "examples": [ + "Example 1:\nInput: jug1Capacity = 3, jug2Capacity = 5, targetCapacity = 4\nOutput: true\nExplanation: The famous Die Hard example", + "Example 2:\nInput: jug1Capacity = 2, jug2Capacity = 6, targetCapacity = 5\nOutput: false", + "Example 3:\nInput: jug1Capacity = 1, jug2Capacity = 2, targetCapacity = 3\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= jug1Capacity, jug2Capacity, targetCapacity <= 10^6", + "tags": [ + "Math", + "Depth-First Search", + "Breadth-First Search" + ], + "title-slug": "water-and-jug-problem" + }, + { + "leetcode-id": 367, + "title": "Valid Perfect Square", + "difficulty": 1, + "description": "Given a positive integer num, return true if num is a perfect square or false otherwise.\nA perfect square is an integer that is the square of an integer. In other words, it is the product of some integer with itself.\nYou must not use any built-in library function, such as sqrt.", + "examples": [ + "Example 1:\nInput: num = 16\nOutput: true\nExplanation: We return true because 4 * 4 = 16 and 4 is an integer.", + "Example 2:\nInput: num = 14\nOutput: false\nExplanation: We return false because 3.742 * 3.742 = 14 and 3.742 is not an integer." + ], + "constraints": "Constraints:\n\n1 <= num <= 2^31 - 1", + "tags": [ + "Math", + "Binary Search" + ], + "title-slug": "valid-perfect-square" + }, + { + "leetcode-id": 368, + "title": "Largest Divisible Subset", + "difficulty": 2, + "description": "Given a set of distinct positive integers nums, return the largest subset answer such that every pair (answer[i], answer[j]) of elements in this subset satisfies:\n\nanswer[i] % answer[j] == 0, or\nanswer[j] % answer[i] == 0\n\nIf there are multiple solutions, return any of them.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3]\nOutput: [1,2]\nExplanation: [1,3] is also accepted.", + "Example 2:\nInput: nums = [1,2,4,8]\nOutput: [1,2,4,8]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 2 * 10^9\nAll the integers in nums are unique.", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Sorting" + ], + "title-slug": "largest-divisible-subset" + }, + { + "leetcode-id": 371, + "title": "Sum of Two Integers", + "difficulty": 2, + "description": "Given two integers a and b, return the sum of the two integers without using the operators + and -.", + "examples": [ + "Example 1:\nInput: a = 1, b = 2\nOutput: 3", + "Example 2:\nInput: a = 2, b = 3\nOutput: 5" + ], + "constraints": "Constraints:\n\n-1000 <= a, b <= 1000", + "tags": [ + "Math", + "Bit Manipulation" + ], + "title-slug": "sum-of-two-integers" + }, + { + "leetcode-id": 372, + "title": "Super Pow", + "difficulty": 2, + "description": "Your task is to calculate a^b mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.", + "examples": [ + "Example 1:\nInput: a = 2, b = [3]\nOutput: 8", + "Example 2:\nInput: a = 2, b = [1,0]\nOutput: 1024", + "Example 3:\nInput: a = 1, b = [4,3,3,8,5,2]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= a <= 2^31 - 1\n1 <= b.length <= 2000\n0 <= b[i] <= 9\nb does not contain leading zeros.", + "tags": [ + "Math", + "Divide and Conquer" + ], + "title-slug": "super-pow" + }, + { + "leetcode-id": 373, + "title": "Find K Pairs with Smallest Sums", + "difficulty": 2, + "description": "You are given two integer arrays nums1 and nums2 sorted in non-decreasing\u00a0order and an integer k.\nDefine a pair (u, v) which consists of one element from the first array and one element from the second array.\nReturn the k pairs (u1, v1), (u2, v2), ..., (uk, vk) with the smallest sums.", + "examples": [ + "Example 1:\nInput: nums1 = [1,7,11], nums2 = [2,4,6], k = 3\nOutput: [[1,2],[1,4],[1,6]]\nExplanation: The first 3 pairs are returned from the sequence: [1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6]", + "Example 2:\nInput: nums1 = [1,1,2], nums2 = [1,2,3], k = 2\nOutput: [[1,1],[1,1]]\nExplanation: The first 2 pairs are returned from the sequence: [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3]", + "Example 3:\nInput: nums1 = [1,2], nums2 = [3], k = 3\nOutput: [[1,3],[2,3]]\nExplanation: All possible pairs are returned from the sequence: [1,3],[2,3]" + ], + "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 10^5\n-10^9 <= nums1[i], nums2[i] <= 10^9\nnums1 and nums2 both are sorted in non-decreasing order.\n1 <= k <= 10^4", + "tags": [ + "Array", + "Heap (Priority Queue)" + ], + "title-slug": "find-k-pairs-with-smallest-sums" + }, + { + "leetcode-id": 374, + "title": "Guess Number Higher or Lower", + "difficulty": 1, + "description": "We are playing the Guess Game. The game is as follows:\nI pick a number from 1 to n. You have to guess which number I picked.\nEvery time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess.\nYou call a pre-defined API int guess(int num), which returns three possible results:\n\n-1: Your guess is higher than the number I picked (i.e. num > pick).\n1: Your guess is lower than the number I picked (i.e. num < pick).\n0: your guess is equal to the number I picked (i.e. num == pick).\n\nReturn the number that I picked.", + "examples": [ + "Example 1:\nInput: n = 10, pick = 6\nOutput: 6", + "Example 2:\nInput: n = 1, pick = 1\nOutput: 1", + "Example 3:\nInput: n = 2, pick = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= n <= 2^31 - 1\n1 <= pick <= n", + "tags": [ + "Binary Search", + "Interactive" + ], + "title-slug": "guess-number-higher-or-lower" + }, + { + "leetcode-id": 375, + "title": "Guess Number Higher or Lower II", + "difficulty": 2, + "description": "We are playing the Guessing Game. The game will work as follows:\n\nI pick a number between\u00a01\u00a0and\u00a0n.\nYou guess a number.\nIf you guess the right number, you win the game.\nIf you guess the wrong number, then I will tell you whether the number I picked is higher or lower, and you will continue guessing.\nEvery time you guess a wrong number\u00a0x, you will pay\u00a0x\u00a0dollars. If you run out of money, you lose the game.\n\nGiven a particular\u00a0n, return\u00a0the minimum amount of money you need to\u00a0guarantee a win regardless of what number I pick.", + "examples": [ + "Example 1:\nInput: n = 10\nOutput: 16\nExplanation: The winning strategy is as follows:\n- The range is [1,10]. Guess 7.\n\u00a0 - If this is my number, your total is $0. Otherwise, you pay $7.\n\u00a0 - If my number is higher, the range is [8,10]. Guess 9.\n\u00a0 - If this is my number, your total is $7. Otherwise, you pay $9.\n\u00a0 - If my number is higher, it must be 10. Guess 10. Your total is $7 + $9 = $16.\n\u00a0 - If my number is lower, it must be 8. Guess 8. Your total is $7 + $9 = $16.\n\u00a0 - If my number is lower, the range is [1,6]. Guess 3.\n\u00a0 - If this is my number, your total is $7. Otherwise, you pay $3.\n\u00a0 - If my number is higher, the range is [4,6]. Guess 5.\n\u00a0 - If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $5.\n\u00a0 - If my number is higher, it must be 6. Guess 6. Your total is $7 + $3 + $5 = $15.\n\u00a0 - If my number is lower, it must be 4. Guess 4. Your total is $7 + $3 + $5 = $15.\n\u00a0 - If my number is lower, the range is [1,2]. Guess 1.\n\u00a0 - If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $1.\n\u00a0 - If my number is higher, it must be 2. Guess 2. Your total is $7 + $3 + $1 = $11.\nThe worst case in all these scenarios is that you pay $16. Hence, you only need $16 to guarantee a win.", + "Example 2:\nInput: n = 1\nOutput: 0\nExplanation:\u00a0There is only one possible number, so you can guess 1 and not have to pay anything.", + "Example 3:\nInput: n = 2\nOutput: 1\nExplanation:\u00a0There are two possible numbers, 1 and 2.\n- Guess 1.\n\u00a0 - If this is my number, your total is $0. Otherwise, you pay $1.\n\u00a0 - If my number is higher, it must be 2. Guess 2. Your total is $1.\nThe worst case is that you pay $1." + ], + "constraints": "Constraints:\n\n1 <= n <= 200", + "tags": [ + "Math", + "Dynamic Programming", + "Game Theory" + ], + "title-slug": "guess-number-higher-or-lower-ii" + }, + { + "leetcode-id": 376, + "title": "Wiggle Subsequence", + "difficulty": 2, + "description": "A wiggle sequence is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequences.\n\nFor example, [1, 7, 4, 9, 2, 5] is a wiggle sequence because the differences (6, -3, 5, -7, 3) alternate between positive and negative.\nIn contrast, [1, 4, 7, 2, 5] and [1, 7, 4, 5, 5] are not wiggle sequences. The first is not because its first two differences are positive, and the second is not because its last difference is zero.\n\nA subsequence is obtained by deleting some elements (possibly zero) from the original sequence, leaving the remaining elements in their original order.\nGiven an integer array nums, return the length of the longest wiggle subsequence of nums.", + "examples": [ + "Example 1:\nInput: nums = [1,7,4,9,2,5]\nOutput: 6\nExplanation: The entire sequence is a wiggle sequence with differences (6, -3, 5, -7, 3).", + "Example 2:\nInput: nums = [1,17,5,10,13,15,10,5,16,8]\nOutput: 7\nExplanation: There are several subsequences that achieve this length.\nOne is [1, 17, 10, 13, 10, 16, 8] with differences (16, -7, 3, -3, 6, -8).", + "Example 3:\nInput: nums = [1,2,3,4,5,6,7,8,9]\nOutput: 2" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n0 <= nums[i] <= 1000\n\n\u00a0\nFollow up: Could you solve this in O(n) time?", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "wiggle-subsequence" + }, + { + "leetcode-id": 377, + "title": "Combination Sum IV", + "difficulty": 2, + "description": "Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to\u00a0target.\nThe test cases are generated so that the answer can fit in a 32-bit integer.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3], target = 4\nOutput: 7\nExplanation:\nThe possible combination ways are:\n(1, 1, 1, 1)\n(1, 1, 2)\n(1, 2, 1)\n(1, 3)\n(2, 1, 1)\n(2, 2)\n(3, 1)\nNote that different sequences are counted as different combinations.", + "Example 2:\nInput: nums = [9], target = 3\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 200\n1 <= nums[i] <= 1000\nAll the elements of nums are unique.\n1 <= target <= 1000\n\n\u00a0\nFollow up: What if negative numbers are allowed in the given array? How does it change the problem? What limitation we need to add to the question to allow negative numbers?", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "combination-sum-iv" + }, + { + "leetcode-id": 378, + "title": "Kth Smallest Element in a Sorted Matrix", + "difficulty": 2, + "description": "Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the k^th smallest element in the matrix.\nNote that it is the k^th smallest element in the sorted order, not the k^th distinct element.\nYou must find a solution with a memory complexity better than O(n^2).", + "examples": [ + "Example 1:\nInput: matrix = [[1,5,9],[10,11,13],[12,13,15]], k = 8\nOutput: 13\nExplanation: The elements in the matrix are [1,5,9,10,11,12,13,13,15], and the 8^th smallest number is 13", + "Example 2:\nInput: matrix = [[-5]], k = 1\nOutput: -5" + ], + "constraints": "Constraints:\n\nn == matrix.length == matrix[i].length\n1 <= n <= 300\n-10^9 <= matrix[i][j] <= 10^9\nAll the rows and columns of matrix are guaranteed to be sorted in non-decreasing order.\n1 <= k <= n^2\n\n\u00a0\nFollow up:\n\nCould you solve the problem with a constant memory (i.e., O(1) memory complexity)?\nCould you solve the problem in O(n) time complexity? The solution may be too advanced for an interview but you may find reading this paper fun.", + "tags": [ + "Array", + "Binary Search", + "Sorting", + "Heap (Priority Queue)", + "Matrix" + ], + "title-slug": "kth-smallest-element-in-a-sorted-matrix" + }, + { + "leetcode-id": 380, + "title": "Insert Delete GetRandom O(1)", + "difficulty": 2, + "description": "Implement the RandomizedSet class:\n\nRandomizedSet() Initializes the RandomizedSet object.\nbool insert(int val) Inserts an item val into the set if not present. Returns true if the item was not present, false otherwise.\nbool remove(int val) Removes an item val from the set if present. Returns true if the item was present, false otherwise.\nint getRandom() Returns a random element from the current set of elements (it's guaranteed that at least one element exists when this method is called). Each element must have the same probability of being returned.\n\nYou must implement the functions of the class such that each function works in\u00a0average\u00a0O(1)\u00a0time complexity.", + "examples": [ + "Example 1:\nInput\n[\"RandomizedSet\", \"insert\", \"remove\", \"insert\", \"getRandom\", \"remove\", \"insert\", \"getRandom\"]\n[[], [1], [2], [2], [], [1], [2], []]\nOutput\n[null, true, false, true, 2, true, false, 2]\n\nExplanation\nRandomizedSet randomizedSet = new RandomizedSet();\nrandomizedSet.insert(1); // Inserts 1 to the set. Returns true as 1 was inserted successfully.\nrandomizedSet.remove(2); // Returns false as 2 does not exist in the set.\nrandomizedSet.insert(2); // Inserts 2 to the set, returns true. Set now contains [1,2].\nrandomizedSet.getRandom(); // getRandom() should return either 1 or 2 randomly.\nrandomizedSet.remove(1); // Removes 1 from the set, returns true. Set now contains [2].\nrandomizedSet.insert(2); // 2 was already in the set, so return false.\nrandomizedSet.getRandom(); // Since 2 is the only number in the set, getRandom() will always return 2." + ], + "constraints": "Constraints:\n\n-2^31 <= val <= 2^31 - 1\nAt most 2 *\u00a010^5 calls will be made to insert, remove, and getRandom.\nThere will be at least one element in the data structure when getRandom is called.", + "tags": [ + "Array", + "Hash Table", + "Math", + "Design", + "Randomized" + ], + "title-slug": "insert-delete-getrandom-o1" + }, + { + "leetcode-id": 381, + "title": "Insert Delete GetRandom O(1) - Duplicates allowed", + "difficulty": 3, + "description": "RandomizedCollection is a data structure that contains a collection of numbers, possibly duplicates (i.e., a multiset). It should support inserting and removing specific elements and also reporting a random element.\nImplement the RandomizedCollection class:\n\nRandomizedCollection() Initializes the empty RandomizedCollection object.\nbool insert(int val) Inserts an item val into the multiset, even if the item is already present. Returns true if the item is not present, false otherwise.\nbool remove(int val) Removes an item val from the multiset if present. Returns true if the item is present, false otherwise. Note that if val has multiple occurrences in the multiset, we only remove one of them.\nint getRandom() Returns a random element from the current multiset of elements. The probability of each element being returned is linearly related to the number of the same values the multiset contains.\n\nYou must implement the functions of the class such that each function works on average O(1) time complexity.\nNote: The test cases are generated such that getRandom will only be called if there is at least one item in the RandomizedCollection.", + "examples": [ + "Example 1:\nInput\n[\"RandomizedCollection\", \"insert\", \"insert\", \"insert\", \"getRandom\", \"remove\", \"getRandom\"]\n[[], [1], [1], [2], [], [1], []]\nOutput\n[null, true, false, true, 2, true, 1]\n\nExplanation\nRandomizedCollection randomizedCollection = new RandomizedCollection();\nrandomizedCollection.insert(1); // return true since the collection does not contain 1.\n // Inserts 1 into the collection.\nrandomizedCollection.insert(1); // return false since the collection contains 1.\n // Inserts another 1 into the collection. Collection now contains [1,1].\nrandomizedCollection.insert(2); // return true since the collection does not contain 2.\n // Inserts 2 into the collection. Collection now contains [1,1,2].\nrandomizedCollection.getRandom(); // getRandom should:\n // - return 1 with probability 2/3, or\n // - return 2 with probability 1/3.\nrandomizedCollection.remove(1); // return true since the collection contains 1.\n // Removes 1 from the collection. Collection now contains [1,2].\nrandomizedCollection.getRandom(); // getRandom should return 1 or 2, both equally likely." + ], + "constraints": "Constraints:\n\n-2^31 <= val <= 2^31 - 1\nAt most 2 * 10^5 calls in total will be made to insert, remove, and getRandom.\nThere will be at least one element in the data structure when getRandom is called.", + "tags": [ + "Array", + "Hash Table", + "Math", + "Design", + "Randomized" + ], + "title-slug": "insert-delete-getrandom-o1-duplicates-allowed" + }, + { + "leetcode-id": 382, + "title": "Linked List Random Node", + "difficulty": 2, + "description": "Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen.\nImplement the Solution class:\n\nSolution(ListNode head) Initializes the object with the head of the singly-linked list head.\nint getRandom() Chooses a node randomly from the list and returns its value. All the nodes of the list should be equally likely to be chosen.", + "examples": [ + "Example 1:\nInput\n[\"Solution\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\"]\n[[[1, 2, 3]], [], [], [], [], []]\nOutput\n[null, 1, 3, 2, 2, 3]\n\nExplanation\nSolution solution = new Solution([1, 2, 3]);\nsolution.getRandom(); // return 1\nsolution.getRandom(); // return 3\nsolution.getRandom(); // return 2\nsolution.getRandom(); // return 2\nsolution.getRandom(); // return 3\n// getRandom() should return either 1, 2, or 3 randomly. Each element should have equal probability of returning." + ], + "constraints": "Constraints:\n\nThe number of nodes in the linked list will be in the range [1, 10^4].\n-10^4 <= Node.val <= 10^4\nAt most 10^4 calls will be made to getRandom.\n\n\u00a0\nFollow up:\n\nWhat if the linked list is extremely large and its length is unknown to you?\nCould you solve this efficiently without using extra space?", + "tags": [ + "Linked List", + "Math", + "Reservoir Sampling", + "Randomized" + ], + "title-slug": "linked-list-random-node" + }, + { + "leetcode-id": 383, + "title": "Ransom Note", + "difficulty": 1, + "description": "Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise.\nEach letter in magazine can only be used once in ransomNote.", + "examples": [ + "Example 1:\nInput: ransomNote = \"a\", magazine = \"b\"\nOutput: false", + "Example 2:\nInput: ransomNote = \"aa\", magazine = \"ab\"\nOutput: false", + "Example 3:\nInput: ransomNote = \"aa\", magazine = \"aab\"\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= ransomNote.length, magazine.length <= 10^5\nransomNote and magazine consist of lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Counting" + ], + "title-slug": "ransom-note" + }, + { + "leetcode-id": 384, + "title": "Shuffle an Array", + "difficulty": 2, + "description": "Given an integer array nums, design an algorithm to randomly shuffle the array. All permutations of the array should be equally likely as a result of the shuffling.\nImplement the Solution class:\n\nSolution(int[] nums) Initializes the object with the integer array nums.\nint[] reset() Resets the array to its original configuration and returns it.\nint[] shuffle() Returns a random shuffling of the array.", + "examples": [ + "Example 1:\nInput\n[\"Solution\", \"shuffle\", \"reset\", \"shuffle\"]\n[[[1, 2, 3]], [], [], []]\nOutput\n[null, [3, 1, 2], [1, 2, 3], [1, 3, 2]]\n\nExplanation\nSolution solution = new Solution([1, 2, 3]);\nsolution.shuffle(); // Shuffle the array [1,2,3] and return its result.\n // Any permutation of [1,2,3] must be equally likely to be returned.\n // Example: return [3, 1, 2]\nsolution.reset(); // Resets the array back to its original configuration [1,2,3]. Return [1, 2, 3]\nsolution.shuffle(); // Returns the random shuffling of array [1,2,3]. Example: return [1, 3, 2]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 50\n-10^6 <= nums[i] <= 10^6\nAll the elements of nums are unique.\nAt most 10^4 calls in total will be made to reset and shuffle.", + "tags": [ + "Array", + "Math", + "Randomized" + ], + "title-slug": "shuffle-an-array" + }, + { + "leetcode-id": 385, + "title": "Mini Parser", + "difficulty": 2, + "description": "Given a string s represents the serialization of a nested list, implement a parser to deserialize it and return the deserialized NestedInteger.\nEach element is either an integer or a list whose elements may also be integers or other lists.", + "examples": [ + "Example 1:\nInput: s = \"324\"\nOutput: 324\nExplanation: You should return a NestedInteger object which contains a single integer 324.", + "Example 2:\nInput: s = \"[123,[456,[789]]]\"\nOutput: [123,[456,[789]]]\nExplanation: Return a NestedInteger object containing a nested list with 2 elements:\n1. An integer containing value 123.\n2. A nested list containing two elements:\n i. An integer containing value 456.\n ii. A nested list with one element:\n a. An integer containing value 789" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 5 * 10^4\ns consists of digits, square brackets \"[]\", negative sign '-', and commas ','.\ns is the serialization of valid NestedInteger.\nAll the values in the input are in the range [-10^6, 10^6].", + "tags": [ + "String", + "Stack", + "Depth-First Search" + ], + "title-slug": "mini-parser" + }, + { + "leetcode-id": 386, + "title": "Lexicographical Numbers", + "difficulty": 2, + "description": "Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.\nYou must write an algorithm that runs in\u00a0O(n)\u00a0time and uses O(1) extra space.", + "examples": [ + "Example 1:\nInput: n = 13\nOutput: [1,10,11,12,13,2,3,4,5,6,7,8,9]", + "Example 2:\nInput: n = 2\nOutput: [1,2]" + ], + "constraints": "Constraints:\n\n1 <= n <= 5 * 10^4", + "tags": [ + "Depth-First Search", + "Trie" + ], + "title-slug": "lexicographical-numbers" + }, + { + "leetcode-id": 387, + "title": "First Unique Character in a String", + "difficulty": 1, + "description": "Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.", + "examples": [ + "Example 1:\nInput: s = \"leetcode\"\nOutput: 0", + "Example 2:\nInput: s = \"loveleetcode\"\nOutput: 2", + "Example 3:\nInput: s = \"aabb\"\nOutput: -1" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of only lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Queue", + "Counting" + ], + "title-slug": "first-unique-character-in-a-string" + }, + { + "leetcode-id": 388, + "title": "Longest Absolute File Path", + "difficulty": 2, + "description": "Suppose we have a file system that stores both files and directories. An example of one system is represented in the following picture:\n\nHere, we have dir as the only directory in the root. dir contains two subdirectories, subdir1 and subdir2. subdir1 contains a file file1.ext and subdirectory subsubdir1. subdir2 contains a subdirectory subsubdir2, which contains a file file2.ext.\nIn text form, it looks like this (with \u27f6 representing the tab character):\n\ndir\n\u27f6 subdir1\n\u27f6 \u27f6 file1.ext\n\u27f6 \u27f6 subsubdir1\n\u27f6 subdir2\n\u27f6 \u27f6 subsubdir2\n\u27f6 \u27f6 \u27f6 file2.ext\n\nIf we were to write this representation in code, it will look like this: \"dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext\". Note that the '\\n' and '\\t' are the new-line and tab characters.\nEvery file and directory has a unique absolute path in the file system, which is the order of directories that must be opened to reach the file/directory itself, all concatenated by '/'s. Using the above example, the absolute path to file2.ext is \"dir/subdir2/subsubdir2/file2.ext\". Each directory name consists of letters, digits, and/or spaces. Each file name is of the form name.extension, where name and extension consist of letters, digits, and/or spaces.\nGiven a string input representing the file system in the explained format, return the length of the longest absolute path to a file in the abstracted file system. If there is no file in the system, return 0.\nNote that the testcases are generated such that the file system is valid and no file or directory name has length 0.", + "examples": [ + "Example 1:\nInput: input = \"dir\\n\\tsubdir1\\n\\tsubdir2\\n\\t\\tfile.ext\"\nOutput: 20\nExplanation: We have only one file, and the absolute path is \"dir/subdir2/file.ext\" of length 20.", + "Example 2:\nInput: input = \"dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext\"\nOutput: 32\nExplanation: We have two files:\n\"dir/subdir1/file1.ext\" of length 21\n\"dir/subdir2/subsubdir2/file2.ext\" of length 32.\nWe return 32 since it is the longest absolute path to a file.", + "Example 3:\nInput: input = \"a\"\nOutput: 0\nExplanation: We do not have any files, just a single directory named \"a\"." + ], + "constraints": "Constraints:\n\n1 <= input.length <= 10^4\ninput may contain lowercase or uppercase English letters, a new line character '\\n', a tab character '\\t', a dot '.', a space ' ', and digits.\nAll file and directory names have positive length.", + "tags": [ + "String", + "Stack", + "Depth-First Search" + ], + "title-slug": "longest-absolute-file-path" + }, + { + "leetcode-id": 389, + "title": "Find the Difference", + "difficulty": 1, + "description": "You are given two strings s and t.\nString t is generated by random shuffling string s and then add one more letter at a random position.\nReturn the letter that was added to t.", + "examples": [ + "Example 1:\nInput: s = \"abcd\", t = \"abcde\"\nOutput: \"e\"\nExplanation: 'e' is the letter that was added.", + "Example 2:\nInput: s = \"\", t = \"y\"\nOutput: \"y\"" + ], + "constraints": "Constraints:\n\n0 <= s.length <= 1000\nt.length == s.length + 1\ns and t consist of lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Bit Manipulation", + "Sorting" + ], + "title-slug": "find-the-difference" + }, + { + "leetcode-id": 390, + "title": "Elimination Game", + "difficulty": 2, + "description": "You have a list arr of all integers in the range [1, n] sorted in a strictly increasing order. Apply the following algorithm on arr:\n\nStarting from left to right, remove the first number and every other number afterward until you reach the end of the list.\nRepeat the previous step again, but this time from right to left, remove the rightmost number and every other number from the remaining numbers.\nKeep repeating the steps again, alternating left to right and right to left, until a single number remains.\n\nGiven the integer n, return the last number that remains in arr.", + "examples": [ + "Example 1:\nInput: n = 9\nOutput: 6\nExplanation:\narr = [1, 2, 3, 4, 5, 6, 7, 8, 9]\narr = [2, 4, 6, 8]\narr = [2, 6]\narr = [6]", + "Example 2:\nInput: n = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^9", + "tags": [ + "Math", + "Recursion" + ], + "title-slug": "elimination-game" + }, + { + "leetcode-id": 391, + "title": "Perfect Rectangle", + "difficulty": 3, + "description": "Given an array rectangles where rectangles[i] = [xi, yi, ai, bi] represents an axis-aligned rectangle. The bottom-left point of the rectangle is (xi, yi) and the top-right point of it is (ai, bi).\nReturn true if all the rectangles together form an exact cover of a rectangular region.", + "examples": [ + "Example 1:\nInput: rectangles = [[1,1,3,3],[3,1,4,2],[3,2,4,4],[1,3,2,4],[2,3,3,4]]\nOutput: true\nExplanation: All 5 rectangles together form an exact cover of a rectangular region.", + "Example 2:\nInput: rectangles = [[1,1,2,3],[1,3,2,4],[3,1,4,2],[3,2,4,4]]\nOutput: false\nExplanation: Because there is a gap between the two rectangular regions.", + "Example 3:\nInput: rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[2,2,4,4]]\nOutput: false\nExplanation: Because two of the rectangles overlap with each other." + ], + "constraints": "Constraints:\n\n1 <= rectangles.length <= 2 * 10^4\nrectangles[i].length == 4\n-10^5 <= xi, yi, ai, bi <= 10^5", + "tags": [ + "Array", + "Line Sweep" + ], + "title-slug": "perfect-rectangle" + }, + { + "leetcode-id": 392, + "title": "Is Subsequence", + "difficulty": 1, + "description": "Given two strings s and t, return true if s is a subsequence of t, or false otherwise.\nA subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., \"ace\" is a subsequence of \"abcde\" while \"aec\" is not).", + "examples": [ + "Example 1:\nInput: s = \"abc\", t = \"ahbgdc\"\nOutput: true", + "Example 2:\nInput: s = \"axc\", t = \"ahbgdc\"\nOutput: false" + ], + "constraints": "Constraints:\n\n0 <= s.length <= 100\n0 <= t.length <= 10^4\ns and t consist only of lowercase English letters.\n\n\u00a0\nFollow up: Suppose there are lots of incoming s, say s1, s2, ..., sk where k >= 10^9, and you want to check one by one to see if t has its subsequence. In this scenario, how would you change your code?", + "tags": [ + "Two Pointers", + "String", + "Dynamic Programming" + ], + "title-slug": "is-subsequence" + }, + { + "leetcode-id": 393, + "title": "UTF-8 Validation", + "difficulty": 2, + "description": "Given an integer array data representing the data, return whether it is a valid UTF-8 encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).\nA character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:\n\nFor a 1-byte character, the first bit is a 0, followed by its Unicode code.\nFor an n-bytes character, the first n bits are all one's, the n + 1 bit is 0, followed by n - 1 bytes with the most significant 2 bits being 10.\n\nThis is how the UTF-8 encoding would work:\n\n Number of Bytes | UTF-8 Octet Sequence\n | (binary)\n --------------------+-----------------------------------------\n 1 | 0xxxxxxx\n 2 | 110xxxxx 10xxxxxx\n 3 | 1110xxxx 10xxxxxx 10xxxxxx\n 4 | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx\n\nx denotes a bit in the binary form of a byte that may be either 0 or 1.\nNote: The input is an array of integers. Only the least significant 8 bits of each integer is used to store the data. This means each integer represents only 1 byte of data.", + "examples": [ + "Example 1:\nInput: data = [197,130,1]\nOutput: true\nExplanation: data represents the octet sequence: 11000101 10000010 00000001.\nIt is a valid utf-8 encoding for a 2-bytes character followed by a 1-byte character.", + "Example 2:\nInput: data = [235,140,4]\nOutput: false\nExplanation: data represented the octet sequence: 11101011 10001100 00000100.\nThe first 3 bits are all one's and the 4th bit is 0 means it is a 3-bytes character.\nThe next byte is a continuation byte which starts with 10 and that's correct.\nBut the second continuation byte does not start with 10, so it is invalid." + ], + "constraints": "Constraints:\n\n1 <= data.length <= 2 * 10^4\n0 <= data[i] <= 255", + "tags": [ + "Array", + "Bit Manipulation" + ], + "title-slug": "utf-8-validation" + }, + { + "leetcode-id": 394, + "title": "Decode String", + "difficulty": 2, + "description": "Given an encoded string, return its decoded string.\nThe encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.\nYou may assume that the input string is always valid; there are no extra white spaces, square brackets are well-formed, etc. Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, k. For example, there will not be input like 3a or 2[4].\nThe test cases are generated so that the length of the output will never exceed 10^5.", + "examples": [ + "Example 1:\nInput: s = \"3[a]2[bc]\"\nOutput: \"aaabcbc\"", + "Example 2:\nInput: s = \"3[a2[c]]\"\nOutput: \"accaccacc\"", + "Example 3:\nInput: s = \"2[abc]3[cd]ef\"\nOutput: \"abcabccdcdcdef\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 30\ns consists of lowercase English letters, digits, and square brackets '[]'.\ns is guaranteed to be a valid input.\nAll the integers in s are in the range [1, 300].", + "tags": [ + "String", + "Stack", + "Recursion" + ], + "title-slug": "decode-string" + }, + { + "leetcode-id": 395, + "title": "Longest Substring with At Least K Repeating Characters", + "difficulty": 2, + "description": "Given a string s and an integer k, return the length of the longest substring of s such that the frequency of each character in this substring is greater than or equal to k.\nif no such substring exists, return 0.", + "examples": [ + "Example 1:\nInput: s = \"aaabb\", k = 3\nOutput: 3\nExplanation: The longest substring is \"aaa\", as 'a' is repeated 3 times.", + "Example 2:\nInput: s = \"ababbc\", k = 2\nOutput: 5\nExplanation: The longest substring is \"ababb\", as 'a' is repeated 2 times and 'b' is repeated 3 times." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^4\ns consists of only lowercase English letters.\n1 <= k <= 10^5", + "tags": [ + "Hash Table", + "String", + "Divide and Conquer", + "Sliding Window" + ], + "title-slug": "longest-substring-with-at-least-k-repeating-characters" + }, + { + "leetcode-id": 396, + "title": "Rotate Function", + "difficulty": 2, + "description": "You are given an integer array nums of length n.\nAssume arrk to be an array obtained by rotating nums by k positions clock-wise. We define the rotation function F on nums as follow:\n\nF(k) = 0 * arrk[0] + 1 * arrk[1] + ... + (n - 1) * arrk[n - 1].\n\nReturn the maximum value of F(0), F(1), ..., F(n-1).\nThe test cases are generated so that the answer fits in a 32-bit integer.", + "examples": [ + "Example 1:\nInput: nums = [4,3,2,6]\nOutput: 26\nExplanation:\nF(0) = (0 * 4) + (1 * 3) + (2 * 2) + (3 * 6) = 0 + 3 + 4 + 18 = 25\nF(1) = (0 * 6) + (1 * 4) + (2 * 3) + (3 * 2) = 0 + 4 + 6 + 6 = 16\nF(2) = (0 * 2) + (1 * 6) + (2 * 4) + (3 * 3) = 0 + 6 + 8 + 9 = 23\nF(3) = (0 * 3) + (1 * 2) + (2 * 6) + (3 * 4) = 0 + 2 + 12 + 12 = 26\nSo the maximum value of F(0), F(1), F(2), F(3) is F(3) = 26.", + "Example 2:\nInput: nums = [100]\nOutput: 0" + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^5\n-100 <= nums[i] <= 100", + "tags": [ + "Array", + "Math", + "Dynamic Programming" + ], + "title-slug": "rotate-function" + }, + { + "leetcode-id": 397, + "title": "Integer Replacement", + "difficulty": 2, + "description": "Given a positive integer n,\u00a0you can apply one of the following\u00a0operations:\n\nIf n is even, replace n with n / 2.\nIf n is odd, replace n with either n + 1 or n - 1.\n\nReturn the minimum number of operations needed for n to become 1.", + "examples": [ + "Example 1:\nInput: n = 8\nOutput: 3\nExplanation: 8 -> 4 -> 2 -> 1", + "Example 2:\nInput: n = 7\nOutput: 4\nExplanation: 7 -> 8 -> 4 -> 2 -> 1\nor 7 -> 6 -> 3 -> 2 -> 1", + "Example 3:\nInput: n = 4\nOutput: 2" + ], + "constraints": "Constraints:\n\n1 <= n <= 2^31 - 1", + "tags": [ + "Dynamic Programming", + "Greedy", + "Bit Manipulation", + "Memoization" + ], + "title-slug": "integer-replacement" + }, + { + "leetcode-id": 398, + "title": "Random Pick Index", + "difficulty": 2, + "description": "Given an integer array nums with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.\nImplement the Solution class:\n\nSolution(int[] nums) Initializes the object with the array nums.\nint pick(int target) Picks a random index i from nums where nums[i] == target. If there are multiple valid i's, then each index should have an equal probability of returning.", + "examples": [ + "Example 1:\nInput\n[\"Solution\", \"pick\", \"pick\", \"pick\"]\n[[[1, 2, 3, 3, 3]], [3], [1], [3]]\nOutput\n[null, 4, 0, 2]\n\nExplanation\nSolution solution = new Solution([1, 2, 3, 3, 3]);\nsolution.pick(3); // It should return either index 2, 3, or 4 randomly. Each index should have equal probability of returning.\nsolution.pick(1); // It should return 0. Since in the array only nums[0] is equal to 1.\nsolution.pick(3); // It should return either index 2, 3, or 4 randomly. Each index should have equal probability of returning." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 2 * 10^4\n-2^31 <= nums[i] <= 2^31 - 1\ntarget is an integer from nums.\nAt most 10^4 calls will be made to pick.", + "tags": [ + "Hash Table", + "Math", + "Reservoir Sampling", + "Randomized" + ], + "title-slug": "random-pick-index" + }, + { + "leetcode-id": 399, + "title": "Evaluate Division", + "difficulty": 2, + "description": "You are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equation Ai / Bi = values[i]. Each Ai or Bi is a string that represents a single variable.\nYou are also given some queries, where queries[j] = [Cj, Dj] represents the j^th query where you must find the answer for Cj / Dj = ?.\nReturn the answers to all queries. If a single answer cannot be determined, return -1.0.\nNote: The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction.\nNote:\u00a0The variables that do not occur in the list of equations are undefined, so the answer cannot be determined for them.", + "examples": [ + "Example 1:\nInput: equations = [[\"a\",\"b\"],[\"b\",\"c\"]], values = [2.0,3.0], queries = [[\"a\",\"c\"],[\"b\",\"a\"],[\"a\",\"e\"],[\"a\",\"a\"],[\"x\",\"x\"]]\nOutput: [6.00000,0.50000,-1.00000,1.00000,-1.00000]\nExplanation: \nGiven: a / b = 2.0, b / c = 3.0\nqueries are: a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ? \nreturn: [6.0, 0.5, -1.0, 1.0, -1.0 ]\nnote: x is undefined => -1.0", + "Example 2:\nInput: equations = [[\"a\",\"b\"],[\"b\",\"c\"],[\"bc\",\"cd\"]], values = [1.5,2.5,5.0], queries = [[\"a\",\"c\"],[\"c\",\"b\"],[\"bc\",\"cd\"],[\"cd\",\"bc\"]]\nOutput: [3.75000,0.40000,5.00000,0.20000]", + "Example 3:\nInput: equations = [[\"a\",\"b\"]], values = [0.5], queries = [[\"a\",\"b\"],[\"b\",\"a\"],[\"a\",\"c\"],[\"x\",\"y\"]]\nOutput: [0.50000,2.00000,-1.00000,-1.00000]" + ], + "constraints": "Constraints:\n\n1 <= equations.length <= 20\nequations[i].length == 2\n1 <= Ai.length, Bi.length <= 5\nvalues.length == equations.length\n0.0 < values[i] <= 20.0\n1 <= queries.length <= 20\nqueries[i].length == 2\n1 <= Cj.length, Dj.length <= 5\nAi, Bi, Cj, Dj consist of lower case English letters and digits.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Graph", + "Shortest Path" + ], + "title-slug": "evaluate-division" + }, + { + "leetcode-id": 400, + "title": "Nth Digit", + "difficulty": 2, + "description": "Given an integer n, return the n^th digit of the infinite integer sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...].", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: 3", + "Example 2:\nInput: n = 11\nOutput: 0\nExplanation: The 11^th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... is a 0, which is part of the number 10." + ], + "constraints": "Constraints:\n\n1 <= n <= 2^31 - 1", + "tags": [ + "Math", + "Binary Search" + ], + "title-slug": "nth-digit" + }, + { + "leetcode-id": 401, + "title": "Binary Watch", + "difficulty": 1, + "description": "A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent\u00a0the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right.\n\nFor example, the below binary watch reads \"4:51\".\n\n\nGiven an integer turnedOn which represents the number of LEDs that are currently on (ignoring the PM), return all possible times the watch could represent. You may return the answer in any order.\nThe hour must not contain a leading zero.\n\nFor example, \"01:00\" is not valid. It should be \"1:00\".\n\nThe minute must\u00a0consist of two digits and may contain a leading zero.\n\nFor example, \"10:2\" is not valid. It should be \"10:02\".", + "examples": [ + "Example 1:\nInput: turnedOn = 1\nOutput: [\"0:01\",\"0:02\",\"0:04\",\"0:08\",\"0:16\",\"0:32\",\"1:00\",\"2:00\",\"4:00\",\"8:00\"]", + "Example 2:\nInput: turnedOn = 9\nOutput: []" + ], + "constraints": "Constraints:\n\n0 <= turnedOn <= 10", + "tags": [ + "Backtracking", + "Bit Manipulation" + ], + "title-slug": "binary-watch" + }, + { + "leetcode-id": 402, + "title": "Remove K Digits", + "difficulty": 2, + "description": "Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.", + "examples": [ + "Example 1:\nInput: num = \"1432219\", k = 3\nOutput: \"1219\"\nExplanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.", + "Example 2:\nInput: num = \"10200\", k = 1\nOutput: \"200\"\nExplanation: Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.", + "Example 3:\nInput: num = \"10\", k = 2\nOutput: \"0\"\nExplanation: Remove all the digits from the number and it is left with nothing which is 0." + ], + "constraints": "Constraints:\n\n1 <= k <= num.length <= 10^5\nnum consists of only digits.\nnum does not have any leading zeros except for the zero itself.", + "tags": [ + "String", + "Stack", + "Greedy", + "Monotonic Stack" + ], + "title-slug": "remove-k-digits" + }, + { + "leetcode-id": 403, + "title": "Frog Jump", + "difficulty": 3, + "description": "A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.\nGiven a list of stones\u00a0positions (in units) in sorted ascending order, determine if the frog can cross the river by landing on the last stone. Initially, the frog is on the first stone and assumes the first jump must be 1 unit.\nIf the frog's last jump was k units, its next jump must be either k - 1, k, or k + 1 units. The frog can only jump in the forward direction.", + "examples": [ + "Example 1:\nInput: stones = [0,1,3,5,6,8,12,17]\nOutput: true\nExplanation: The frog can jump to the last stone by jumping 1 unit to the 2nd stone, then 2 units to the 3rd stone, then 2 units to the 4th stone, then 3 units to the 6th stone, 4 units to the 7th stone, and 5 units to the 8th stone.", + "Example 2:\nInput: stones = [0,1,2,3,4,8,9,11]\nOutput: false\nExplanation: There is no way to jump to the last stone as the gap between the 5th and 6th stone is too large." + ], + "constraints": "Constraints:\n\n2 <= stones.length <= 2000\n0 <= stones[i] <= 2^31 - 1\nstones[0] == 0\nstones\u00a0is sorted in a strictly increasing order.", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "frog-jump" + }, + { + "leetcode-id": 404, + "title": "Sum of Left Leaves", + "difficulty": 1, + "description": "Given the root of a binary tree, return the sum of all left leaves.\nA leaf is a node with no children. A left leaf is a leaf that is the left child of another node.", + "examples": [ + "Example 1:\nInput: root = [3,9,20,null,null,15,7]\nOutput: 24\nExplanation: There are two left leaves in the binary tree, with values 9 and 15 respectively.", + "Example 2:\nInput: root = [1]\nOutput: 0" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 1000].\n-1000 <= Node.val <= 1000", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "sum-of-left-leaves" + }, + { + "leetcode-id": 405, + "title": "Convert a Number to Hexadecimal", + "difficulty": 1, + "description": "Given an integer num, return a string representing its hexadecimal representation. For negative integers, two\u2019s complement method is used.\nAll the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer except for the zero itself.\nNote:\u00a0You are not allowed to use any built-in library method to directly solve this problem.", + "examples": [ + "Example 1:\nInput: num = 26\nOutput: \"1a\"", + "Example 2:\nInput: num = -1\nOutput: \"ffffffff\"" + ], + "constraints": "Constraints:\n\n-2^31 <= num <= 2^31 - 1", + "tags": [ + "Math", + "Bit Manipulation" + ], + "title-slug": "convert-a-number-to-hexadecimal" + }, + { + "leetcode-id": 406, + "title": "Queue Reconstruction by Height", + "difficulty": 2, + "description": "You are given an array of people, people, which are the attributes of some people in a queue (not necessarily in order). Each people[i] = [hi, ki] represents the i^th person of height hi with exactly ki other people in front who have a height greater than or equal to hi.\nReconstruct and return the queue that is represented by the input array people. The returned queue should be formatted as an array queue, where queue[j] = [hj, kj] is the attributes of the j^th person in the queue (queue[0] is the person at the front of the queue).", + "examples": [ + "Example 1:\nInput: people = [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]\nOutput: [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]]\nExplanation:\nPerson 0 has height 5 with no other people taller or the same height in front.\nPerson 1 has height 7 with no other people taller or the same height in front.\nPerson 2 has height 5 with two persons taller or the same height in front, which is person 0 and 1.\nPerson 3 has height 6 with one person taller or the same height in front, which is person 1.\nPerson 4 has height 4 with four people taller or the same height in front, which are people 0, 1, 2, and 3.\nPerson 5 has height 7 with one person taller or the same height in front, which is person 1.\nHence [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]] is the reconstructed queue.", + "Example 2:\nInput: people = [[6,0],[5,0],[4,0],[3,2],[2,2],[1,4]]\nOutput: [[4,0],[5,0],[2,2],[3,2],[1,4],[6,0]]" + ], + "constraints": "Constraints:\n\n1 <= people.length <= 2000\n0 <= hi <= 10^6\n0 <= ki < people.length\nIt is guaranteed that the queue can be reconstructed.", + "tags": [ + "Array", + "Greedy", + "Binary Indexed Tree", + "Segment Tree", + "Sorting" + ], + "title-slug": "queue-reconstruction-by-height" + }, + { + "leetcode-id": 407, + "title": "Trapping Rain Water II", + "difficulty": 3, + "description": "Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.", + "examples": [ + "Example 1:\nInput: heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]\nOutput: 4\nExplanation: After the rain, water is trapped between the blocks.\nWe have two small ponds 1 and 3 units trapped.\nThe total volume of water trapped is 4.", + "Example 2:\nInput: heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]\nOutput: 10" + ], + "constraints": "Constraints:\n\nm == heightMap.length\nn == heightMap[i].length\n1 <= m, n <= 200\n0 <= heightMap[i][j] <= 2 * 10^4", + "tags": [ + "Array", + "Breadth-First Search", + "Heap (Priority Queue)", + "Matrix" + ], + "title-slug": "trapping-rain-water-ii" + }, + { + "leetcode-id": 409, + "title": "Longest Palindrome", + "difficulty": 1, + "description": "Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome\u00a0that can be built with those letters.\nLetters are case sensitive, for example,\u00a0\"Aa\" is not considered a palindrome here.", + "examples": [ + "Example 1:\nInput: s = \"abccccdd\"\nOutput: 7\nExplanation: One longest palindrome that can be built is \"dccaccd\", whose length is 7.", + "Example 2:\nInput: s = \"a\"\nOutput: 1\nExplanation: The longest palindrome that can be built is \"a\", whose length is 1." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 2000\ns consists of lowercase and/or uppercase English\u00a0letters only.", + "tags": [ + "Hash Table", + "String", + "Greedy" + ], + "title-slug": "longest-palindrome" + }, + { + "leetcode-id": 410, + "title": "Split Array Largest Sum", + "difficulty": 3, + "description": "Given an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized.\nReturn the minimized largest sum of the split.\nA subarray is a contiguous part of the array.", + "examples": [ + "Example 1:\nInput: nums = [7,2,5,10,8], k = 2\nOutput: 18\nExplanation: There are four ways to split nums into two subarrays.\nThe best way is to split it into [7,2,5] and [10,8], where the largest sum among the two subarrays is only 18.", + "Example 2:\nInput: nums = [1,2,3,4,5], k = 2\nOutput: 9\nExplanation: There are four ways to split nums into two subarrays.\nThe best way is to split it into [1,2,3] and [4,5], where the largest sum among the two subarrays is only 9." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n0 <= nums[i] <= 10^6\n1 <= k <= min(50, nums.length)", + "tags": [ + "Array", + "Binary Search", + "Dynamic Programming", + "Greedy", + "Prefix Sum" + ], + "title-slug": "split-array-largest-sum" + }, + { + "leetcode-id": 412, + "title": "Fizz Buzz", + "difficulty": 1, + "description": "Given an integer n, return a string array answer (1-indexed) where:\n\nanswer[i] == \"FizzBuzz\" if i is divisible by 3 and 5.\nanswer[i] == \"Fizz\" if i is divisible by 3.\nanswer[i] == \"Buzz\" if i is divisible by 5.\nanswer[i] == i (as a string) if none of the above conditions are true.", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: [\"1\",\"2\",\"Fizz\"]", + "Example 2:\nInput: n = 5\nOutput: [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\"]", + "Example 3:\nInput: n = 15\nOutput: [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\",\"Fizz\",\"7\",\"8\",\"Fizz\",\"Buzz\",\"11\",\"Fizz\",\"13\",\"14\",\"FizzBuzz\"]" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^4", + "tags": [ + "Math", + "String", + "Simulation" + ], + "title-slug": "fizz-buzz" + }, + { + "leetcode-id": 413, + "title": "Arithmetic Slices", + "difficulty": 2, + "description": "An integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.\n\nFor example, [1,3,5,7,9], [7,7,7,7], and [3,-1,-5,-9] are arithmetic sequences.\n\nGiven an integer array nums, return the number of arithmetic subarrays of nums.\nA subarray is a contiguous subsequence of the array.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4]\nOutput: 3\nExplanation: We have 3 arithmetic slices in nums: [1, 2, 3], [2, 3, 4] and [1,2,3,4] itself.", + "Example 2:\nInput: nums = [1]\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 5000\n-1000 <= nums[i] <= 1000", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "arithmetic-slices" + }, + { + "leetcode-id": 414, + "title": "Third Maximum Number", + "difficulty": 1, + "description": "Given an integer array nums, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number.", + "examples": [ + "Example 1:\nInput: nums = [3,2,1]\nOutput: 1\nExplanation:\nThe first distinct maximum is 3.\nThe second distinct maximum is 2.\nThe third distinct maximum is 1.", + "Example 2:\nInput: nums = [1,2]\nOutput: 2\nExplanation:\nThe first distinct maximum is 2.\nThe second distinct maximum is 1.\nThe third distinct maximum does not exist, so the maximum (2) is returned instead.", + "Example 3:\nInput: nums = [2,2,3,1]\nOutput: 1\nExplanation:\nThe first distinct maximum is 3.\nThe second distinct maximum is 2 (both 2's are counted together since they have the same value).\nThe third distinct maximum is 1." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-2^31 <= nums[i] <= 2^31 - 1\n\n\u00a0\nFollow up: Can you find an O(n) solution?", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "third-maximum-number" + }, + { + "leetcode-id": 415, + "title": "Add Strings", + "difficulty": 1, + "description": "Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string.\nYou must solve the problem without using any built-in library for handling large integers (such as BigInteger). You must also not convert the inputs to integers directly.", + "examples": [ + "Example 1:\nInput: num1 = \"11\", num2 = \"123\"\nOutput: \"134\"", + "Example 2:\nInput: num1 = \"456\", num2 = \"77\"\nOutput: \"533\"", + "Example 3:\nInput: num1 = \"0\", num2 = \"0\"\nOutput: \"0\"" + ], + "constraints": "Constraints:\n\n1 <= num1.length, num2.length <= 10^4\nnum1 and num2 consist of only digits.\nnum1 and num2 don't have any leading zeros except for the zero itself.", + "tags": [ + "Math", + "String", + "Simulation" + ], + "title-slug": "add-strings" + }, + { + "leetcode-id": 416, + "title": "Partition Equal Subset Sum", + "difficulty": 2, + "description": "Given an integer array nums, return true if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or false otherwise.", + "examples": [ + "Example 1:\nInput: nums = [1,5,11,5]\nOutput: true\nExplanation: The array can be partitioned as [1, 5, 5] and [11].", + "Example 2:\nInput: nums = [1,2,3,5]\nOutput: false\nExplanation: The array cannot be partitioned into equal sum subsets." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 200\n1 <= nums[i] <= 100", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "partition-equal-subset-sum" + }, + { + "leetcode-id": 417, + "title": "Pacific Atlantic Water Flow", + "difficulty": 2, + "description": "There is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island's left and top edges, and the Atlantic Ocean touches the island's right and bottom edges.\nThe island is partitioned into a grid of square cells. You are given an m x n integer matrix heights where heights[r][c] represents the height above sea level of the cell at coordinate (r, c).\nThe island receives a lot of rain, and the rain water can flow to neighboring cells directly north, south, east, and west if the neighboring cell's height is less than or equal to the current cell's height. Water can flow from any cell adjacent to an ocean into the ocean.\nReturn a 2D list of grid coordinates result where result[i] = [ri, ci] denotes that rain water can flow from cell (ri, ci) to both the Pacific and Atlantic oceans.", + "examples": [ + "Example 1:\nInput: heights = [[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]]\nOutput: [[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]]\nExplanation: The following cells can flow to the Pacific and Atlantic oceans, as shown below:\n[0,4]: [0,4] -> Pacific Ocean \n\u00a0 [0,4] -> Atlantic Ocean\n[1,3]: [1,3] -> [0,3] -> Pacific Ocean \n\u00a0 [1,3] -> [1,4] -> Atlantic Ocean\n[1,4]: [1,4] -> [1,3] -> [0,3] -> Pacific Ocean \n\u00a0 [1,4] -> Atlantic Ocean\n[2,2]: [2,2] -> [1,2] -> [0,2] -> Pacific Ocean \n\u00a0 [2,2] -> [2,3] -> [2,4] -> Atlantic Ocean\n[3,0]: [3,0] -> Pacific Ocean \n\u00a0 [3,0] -> [4,0] -> Atlantic Ocean\n[3,1]: [3,1] -> [3,0] -> Pacific Ocean \n\u00a0 [3,1] -> [4,1] -> Atlantic Ocean\n[4,0]: [4,0] -> Pacific Ocean \n [4,0] -> Atlantic Ocean\nNote that there are other possible paths for these cells to flow to the Pacific and Atlantic oceans.", + "Example 2:\nInput: heights = [[1]]\nOutput: [[0,0]]\nExplanation: The water can flow from the only cell to the Pacific and Atlantic oceans." + ], + "constraints": "Constraints:\n\nm == heights.length\nn == heights[r].length\n1 <= m, n <= 200\n0 <= heights[r][c] <= 10^5", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "pacific-atlantic-water-flow" + }, + { + "leetcode-id": 419, + "title": "Battleships in a Board", + "difficulty": 2, + "description": "Given an m x n matrix board where each cell is a battleship 'X' or empty '.', return the number of the battleships on board.\nBattleships can only be placed horizontally or vertically on board. In other words, they can only be made of the shape 1 x k (1 row, k columns) or k x 1 (k rows, 1 column), where k can be of any size. At least one horizontal or vertical cell separates between two battleships (i.e., there are no adjacent battleships).", + "examples": [ + "Example 1:\nInput: board = [[\"X\",\".\",\".\",\"X\"],[\".\",\".\",\".\",\"X\"],[\".\",\".\",\".\",\"X\"]]\nOutput: 2", + "Example 2:\nInput: board = [[\".\"]]\nOutput: 0" + ], + "constraints": "Constraints:\n\nm == board.length\nn == board[i].length\n1 <= m, n <= 200\nboard[i][j] is either '.' or 'X'.\n\n\u00a0\nFollow up: Could you do it in one-pass, using only O(1) extra memory and without modifying the values board?", + "tags": [ + "Array", + "Depth-First Search", + "Matrix" + ], + "title-slug": "battleships-in-a-board" + }, + { + "leetcode-id": 420, + "title": "Strong Password Checker", + "difficulty": 3, + "description": "A password is considered strong if the below conditions are all met:\n\nIt has at least 6 characters and at most 20 characters.\nIt contains at least one lowercase letter, at least one uppercase letter, and at least one digit.\nIt does not contain three repeating characters in a row (i.e., \"Baaabb0\" is weak, but \"Baaba0\" is strong).\n\nGiven a string password, return the minimum number of steps required to make password strong. if password is already strong, return 0.\nIn one step, you can:\n\nInsert one character to password,\nDelete one character from password, or\nReplace one character of password with another character.", + "examples": [ + "Example 1:\nInput: password = \"a\"\nOutput: 5", + "Example 2:\nInput: password = \"aA1\"\nOutput: 3", + "Example 3:\nInput: password = \"1337C0d3\"\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= password.length <= 50\npassword consists of letters, digits, dot\u00a0'.' or exclamation mark '!'.", + "tags": [ + "String", + "Greedy", + "Heap (Priority Queue)" + ], + "title-slug": "strong-password-checker" + }, + { + "leetcode-id": 421, + "title": "Maximum XOR of Two Numbers in an Array", + "difficulty": 2, + "description": "Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n.", + "examples": [ + "Example 1:\nInput: nums = [3,10,5,25,2,8]\nOutput: 28\nExplanation: The maximum result is 5 XOR 25 = 28.", + "Example 2:\nInput: nums = [14,70,53,83,49,91,36,80,92,51,66,70]\nOutput: 127" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 2 * 10^5\n0 <= nums[i] <= 2^31 - 1", + "tags": [ + "Array", + "Hash Table", + "Bit Manipulation", + "Trie" + ], + "title-slug": "maximum-xor-of-two-numbers-in-an-array" + }, + { + "leetcode-id": 423, + "title": "Reconstruct Original Digits from English", + "difficulty": 2, + "description": "Given a string s containing an out-of-order English representation of digits 0-9, return the digits in ascending order.", + "examples": [ + "Example 1:\nInput: s = \"owoztneoer\"\nOutput: \"012\"", + "Example 2:\nInput: s = \"fviefuro\"\nOutput: \"45\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns[i] is one of the characters [\"e\",\"g\",\"f\",\"i\",\"h\",\"o\",\"n\",\"s\",\"r\",\"u\",\"t\",\"w\",\"v\",\"x\",\"z\"].\ns is guaranteed to be valid.", + "tags": [ + "Hash Table", + "Math", + "String" + ], + "title-slug": "reconstruct-original-digits-from-english" + }, + { + "leetcode-id": 424, + "title": "Longest Repeating Character Replacement", + "difficulty": 2, + "description": "You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times.\nReturn the length of the longest substring containing the same letter you can get after performing the above operations.", + "examples": [ + "Example 1:\nInput: s = \"ABAB\", k = 2\nOutput: 4\nExplanation: Replace the two 'A's with two 'B's or vice versa.", + "Example 2:\nInput: s = \"AABABBA\", k = 1\nOutput: 4\nExplanation: Replace the one 'A' in the middle with 'B' and form \"AABBBBA\".\nThe substring \"BBBB\" has the longest repeating letters, which is 4.\nThere may exists other ways to achive this answer too." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of only uppercase English letters.\n0 <= k <= s.length", + "tags": [ + "Hash Table", + "String", + "Sliding Window" + ], + "title-slug": "longest-repeating-character-replacement" + }, + { + "leetcode-id": 427, + "title": "Construct Quad Tree", + "difficulty": 2, + "description": "Given a n * n matrix grid of 0's and 1's only. We want to represent grid with a Quad-Tree.\nReturn the root of the Quad-Tree representing grid.\nA Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes:\n\nval: True if the node represents a grid of 1's or False if the node represents a grid of 0's. Notice that you can assign the val to True or False when isLeaf is False, and both are accepted in the answer.\nisLeaf: True if the node is a leaf node on the tree or False if the node has four children.\n\n\nclass Node {\n public boolean val;\n public boolean isLeaf;\n public Node topLeft;\n public Node topRight;\n public Node bottomLeft;\n public Node bottomRight;\n}\nWe can construct a Quad-Tree from a two-dimensional area using the following steps:\n\nIf the current grid has the same value (i.e all 1's or all 0's) set isLeaf True and set val to the value of the grid and set the four children to Null and stop.\nIf the current grid has different values, set isLeaf to False and set val to any value and divide the current grid into four sub-grids as shown in the photo.\nRecurse for each of the children with the proper sub-grid.\n\n\nIf you want to know more about the Quad-Tree, you can refer to the wiki.\nQuad-Tree format:\nYou don't need to read this section for solving the problem. This is only if you want to understand the output format here. The output represents the serialized format of a Quad-Tree using level order traversal, where null signifies a path terminator where no node exists below.\nIt is very similar to the serialization of the binary tree. The only difference is that the node is represented as a list [isLeaf, val].\nIf the value of isLeaf or val is True we represent it as 1 in the list [isLeaf, val] and if the value of isLeaf or val is False we represent it as 0.", + "examples": [ + "Example 1:\nInput: grid = [[0,1],[1,0]]\nOutput: [[0,1],[1,0],[1,1],[1,1],[1,0]]\nExplanation: The explanation of this example is shown below:\nNotice that 0 represents False and 1 represents True in the photo representing the Quad-Tree.", + "Example 2:\nInput: grid = [[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0]]\nOutput: [[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\nExplanation: All values in the grid are not the same. We divide the grid into four sub-grids.\nThe topLeft, bottomLeft and bottomRight each has the same value.\nThe topRight have different values so we divide it into 4 sub-grids where each has the same value.\nExplanation is shown in the photo below:" + ], + "constraints": "Constraints:\n\nn == grid.length == grid[i].length\nn == 2^x where 0 <= x <= 6", + "tags": [ + "Array", + "Divide and Conquer", + "Tree", + "Matrix" + ], + "title-slug": "construct-quad-tree" + }, + { + "leetcode-id": 429, + "title": "N-ary Tree Level Order Traversal", + "difficulty": 2, + "description": "Given an n-ary tree, return the level order traversal of its nodes' values.\nNary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).", + "examples": [ + "Example 1:\nInput: root = [1,null,3,2,4,null,5,6]\nOutput: [[1],[3,2,4],[5,6]]", + "Example 2:\nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: [[1],[2,3,4,5],[6,7,8,9,10],[11,12,13],[14]]" + ], + "constraints": "Constraints:\n\nThe height of the n-ary tree is less than or equal to 1000\nThe total number of nodes is between [0, 10^4]", + "tags": [ + "Tree", + "Breadth-First Search" + ], + "title-slug": "n-ary-tree-level-order-traversal" + }, + { + "leetcode-id": 430, + "title": "Flatten a Multilevel Doubly Linked List", + "difficulty": 2, + "description": "You are given a doubly linked list, which contains nodes that have a next pointer, a previous pointer, and an additional child pointer. This child pointer may or may not point to a separate doubly linked list, also containing these special nodes. These child lists may have one or more children of their own, and so on, to produce a multilevel data structure as shown in the example below.\nGiven the head of the first level of the list, flatten the list so that all the nodes appear in a single-level, doubly linked list. Let curr be a node with a child list. The nodes in the child list should appear after curr and before curr.next in the flattened list.\nReturn the head of the flattened list. The nodes in the list must have all of their child pointers set to null.", + "examples": [ + "Example 1:\nInput: head = [1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]\nOutput: [1,2,3,7,8,11,12,9,10,4,5,6]\nExplanation: The multilevel linked list in the input is shown.\nAfter flattening the multilevel linked list it becomes:", + "Example 2:\nInput: head = [1,2,null,3]\nOutput: [1,3,2]\nExplanation: The multilevel linked list in the input is shown.\nAfter flattening the multilevel linked list it becomes:", + "Example 3:\nInput: head = []\nOutput: []\nExplanation: There could be empty list in the input.", + "Example 1 above:\n1---2---3---4---5---6--NULL\n |\n 7---8---9---10--NULL\n |\n 11--12--NULL\nThe serialization of each level is as follows:\n\n[1,2,3,4,5,6,null]\n[7,8,9,10,null]\n[11,12,null]\n\nTo serialize all levels together, we will add nulls in each level to signify no node connects to the upper node of the previous level. The serialization becomes:\n\n[1, 2, 3, 4, 5, 6, null]\n |\n[null, null, 7, 8, 9, 10, null]\n |\n[ null, 11, 12, null]\n\nMerging the serialization of each level and removing trailing nulls we obtain:\n\n[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]" + ], + "constraints": "Constraints:\n\nThe number of Nodes will not exceed 1000.\n1 <= Node.val <= 10^5\n\n\u00a0\nHow the multilevel linked list is represented in test cases:\nWe use the multilevel linked list from Example 1 above:\n\n 1---2---3---4---5---6--NULL\n |\n 7---8---9---10--NULL\n |\n 11--12--NULL\nThe serialization of each level is as follows:\n\n[1,2,3,4,5,6,null]\n[7,8,9,10,null]\n[11,12,null]\n\nTo serialize all levels together, we will add nulls in each level to signify no node connects to the upper node of the previous level. The serialization becomes:\n\n[1, 2, 3, 4, 5, 6, null]\n |\n[null, null, 7, 8, 9, 10, null]\n |\n[ null, 11, 12, null]\n\nMerging the serialization of each level and removing trailing nulls we obtain:\n\n[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]", + "tags": [ + "Linked List", + "Depth-First Search", + "Doubly-Linked List" + ], + "title-slug": "flatten-a-multilevel-doubly-linked-list" + }, + { + "leetcode-id": 432, + "title": "All O`one Data Structure", + "difficulty": 3, + "description": "Design a data structure to store the strings' count with the ability to return the strings with minimum and maximum counts.\nImplement the AllOne class:\n\nAllOne() Initializes the object of the data structure.\ninc(String key) Increments the count of the string key by 1. If key does not exist in the data structure, insert it with count 1.\ndec(String key) Decrements the count of the string key by 1. If the count of key is 0 after the decrement, remove it from the data structure. It is guaranteed that key exists in the data structure before the decrement.\ngetMaxKey() Returns one of the keys with the maximal count. If no element exists, return an empty string \"\".\ngetMinKey() Returns one of the keys with the minimum count. If no element exists, return an empty string \"\".\n\nNote that each function must run in O(1) average time complexity.", + "examples": [ + "Example 1:\nInput\n[\"AllOne\", \"inc\", \"inc\", \"getMaxKey\", \"getMinKey\", \"inc\", \"getMaxKey\", \"getMinKey\"]\n[[], [\"hello\"], [\"hello\"], [], [], [\"leet\"], [], []]\nOutput\n[null, null, null, \"hello\", \"hello\", null, \"hello\", \"leet\"]\n\nExplanation\nAllOne allOne = new AllOne();\nallOne.inc(\"hello\");\nallOne.inc(\"hello\");\nallOne.getMaxKey(); // return \"hello\"\nallOne.getMinKey(); // return \"hello\"\nallOne.inc(\"leet\");\nallOne.getMaxKey(); // return \"hello\"\nallOne.getMinKey(); // return \"leet\"" + ], + "constraints": "Constraints:\n\n1 <= key.length <= 10\nkey consists of lowercase English letters.\nIt is guaranteed that for each call to dec, key is existing in the data structure.\nAt most 5 * 10^4\u00a0calls will be made to inc, dec, getMaxKey, and getMinKey.", + "tags": [ + "Hash Table", + "Linked List", + "Design", + "Doubly-Linked List" + ], + "title-slug": "all-oone-data-structure" + }, + { + "leetcode-id": 433, + "title": "Minimum Genetic Mutation", + "difficulty": 2, + "description": "A gene string can be represented by an 8-character long string, with choices from 'A', 'C', 'G', and 'T'.\nSuppose we need to investigate a mutation from a gene string startGene to a gene string endGene where one mutation is defined as one single character changed in the gene string.\n\nFor example, \"AACCGGTT\" --> \"AACCGGTA\" is one mutation.\n\nThere is also a gene bank bank that records all the valid gene mutations. A gene must be in bank to make it a valid gene string.\nGiven the two gene strings startGene and endGene and the gene bank bank, return the minimum number of mutations needed to mutate from startGene to endGene. If there is no such a mutation, return -1.\nNote that the starting point is assumed to be valid, so it might not be included in the bank.", + "examples": [ + "Example 1:\nInput: startGene = \"AACCGGTT\", endGene = \"AACCGGTA\", bank = [\"AACCGGTA\"]\nOutput: 1", + "Example 2:\nInput: startGene = \"AACCGGTT\", endGene = \"AAACGGTA\", bank = [\"AACCGGTA\",\"AACCGCTA\",\"AAACGGTA\"]\nOutput: 2" + ], + "constraints": "Constraints:\n\n0 <= bank.length <= 10\nstartGene.length == endGene.length == bank[i].length == 8\nstartGene, endGene, and bank[i] consist of only the characters ['A', 'C', 'G', 'T'].", + "tags": [ + "Hash Table", + "String", + "Breadth-First Search" + ], + "title-slug": "minimum-genetic-mutation" + }, + { + "leetcode-id": 434, + "title": "Number of Segments in a String", + "difficulty": 1, + "description": "Given a string s, return the number of segments in the string.\nA segment is defined to be a contiguous sequence of non-space characters.", + "examples": [ + "Example 1:\nInput: s = \"Hello, my name is John\"\nOutput: 5\nExplanation: The five segments are [\"Hello,\", \"my\", \"name\", \"is\", \"John\"]", + "Example 2:\nInput: s = \"Hello\"\nOutput: 1" + ], + "constraints": "Constraints:\n\n0 <= s.length <= 300\ns consists of lowercase and uppercase English letters, digits, or one of the following characters \"!@#$%^&*()_+-=',.:\".\nThe only space character in s is ' '.", + "tags": [ + "String" + ], + "title-slug": "number-of-segments-in-a-string" + }, + { + "leetcode-id": 435, + "title": "Non-overlapping Intervals", + "difficulty": 2, + "description": "Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.", + "examples": [ + "Example 1:\nInput: intervals = [[1,2],[2,3],[3,4],[1,3]]\nOutput: 1\nExplanation: [1,3] can be removed and the rest of the intervals are non-overlapping.", + "Example 2:\nInput: intervals = [[1,2],[1,2],[1,2]]\nOutput: 2\nExplanation: You need to remove two [1,2] to make the rest of the intervals non-overlapping.", + "Example 3:\nInput: intervals = [[1,2],[2,3]]\nOutput: 0\nExplanation: You don't need to remove any of the intervals since they're already non-overlapping." + ], + "constraints": "Constraints:\n\n1 <= intervals.length <= 10^5\nintervals[i].length == 2\n-5 * 10^4 <= starti < endi <= 5 * 10^4", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy", + "Sorting" + ], + "title-slug": "non-overlapping-intervals" + }, + { + "leetcode-id": 436, + "title": "Find Right Interval", + "difficulty": 2, + "description": "You are given an array of intervals, where intervals[i] = [starti, endi] and each starti is unique.\nThe right interval for an interval i is an interval j such that startj >= endi and startj is minimized. Note that i may equal j.\nReturn an array of right interval indices for each interval i. If no right interval exists for interval i, then put -1 at index i.", + "examples": [ + "Example 1:\nInput: intervals = [[1,2]]\nOutput: [-1]\nExplanation: There is only one interval in the collection, so it outputs -1.", + "Example 2:\nInput: intervals = [[3,4],[2,3],[1,2]]\nOutput: [-1,0,1]\nExplanation: There is no right interval for [3,4].\nThe right interval for [2,3] is [3,4] since start0 = 3 is the smallest start that is >= end1 = 3.\nThe right interval for [1,2] is [2,3] since start1 = 2 is the smallest start that is >= end2 = 2.", + "Example 3:\nInput: intervals = [[1,4],[2,3],[3,4]]\nOutput: [-1,2,-1]\nExplanation: There is no right interval for [1,4] and [3,4].\nThe right interval for [2,3] is [3,4] since start2 = 3 is the smallest start that is >= end1 = 3." + ], + "constraints": "Constraints:\n\n1 <= intervals.length <= 2 * 10^4\nintervals[i].length == 2\n-10^6 <= starti <= endi <= 10^6\nThe start point of each interval is unique.", + "tags": [ + "Array", + "Binary Search", + "Sorting" + ], + "title-slug": "find-right-interval" + }, + { + "leetcode-id": 437, + "title": "Path Sum III", + "difficulty": 2, + "description": "Given the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values\u00a0along the path equals\u00a0targetSum.\nThe path does not need to start or end at the root or a leaf, but it must go downwards (i.e., traveling only from parent nodes to child nodes).", + "examples": [ + "Example 1:\nInput: root = [10,5,-3,3,2,null,11,3,-2,null,1], targetSum = 8\nOutput: 3\nExplanation: The paths that sum to 8 are shown.", + "Example 2:\nInput: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22\nOutput: 3" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 1000].\n-10^9 <= Node.val <= 10^9\n-1000 <= targetSum <= 1000", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "path-sum-iii" + }, + { + "leetcode-id": 438, + "title": "Find All Anagrams in a String", + "difficulty": 2, + "description": "Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order.\nAn Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.", + "examples": [ + "Example 1:\nInput: s = \"cbaebabacd\", p = \"abc\"\nOutput: [0,6]\nExplanation:\nThe substring with start index = 0 is \"cba\", which is an anagram of \"abc\".\nThe substring with start index = 6 is \"bac\", which is an anagram of \"abc\".", + "Example 2:\nInput: s = \"abab\", p = \"ab\"\nOutput: [0,1,2]\nExplanation:\nThe substring with start index = 0 is \"ab\", which is an anagram of \"ab\".\nThe substring with start index = 1 is \"ba\", which is an anagram of \"ab\".\nThe substring with start index = 2 is \"ab\", which is an anagram of \"ab\"." + ], + "constraints": "Constraints:\n\n1 <= s.length, p.length <= 3 * 10^4\ns and p consist of lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Sliding Window" + ], + "title-slug": "find-all-anagrams-in-a-string" + }, + { + "leetcode-id": 440, + "title": "K-th Smallest in Lexicographical Order", + "difficulty": 3, + "description": "Given two integers n and k, return the k^th lexicographically smallest integer in the range [1, n].", + "examples": [ + "Example 1:\nInput: n = 13, k = 2\nOutput: 10\nExplanation: The lexicographical order is [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9], so the second smallest number is 10.", + "Example 2:\nInput: n = 1, k = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= k <= n <= 10^9", + "tags": [ + "Trie" + ], + "title-slug": "k-th-smallest-in-lexicographical-order" + }, + { + "leetcode-id": 441, + "title": "Arranging Coins", + "difficulty": 1, + "description": "You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the i^th row has exactly i coins. The last row of the staircase may be incomplete.\nGiven the integer n, return the number of complete rows of the staircase you will build.", + "examples": [ + "Example 1:\nInput: n = 5\nOutput: 2\nExplanation: Because the 3^rd row is incomplete, we return 2.", + "Example 2:\nInput: n = 8\nOutput: 3\nExplanation: Because the 4^th row is incomplete, we return 3." + ], + "constraints": "Constraints:\n\n1 <= n <= 2^31 - 1", + "tags": [ + "Math", + "Binary Search" + ], + "title-slug": "arranging-coins" + }, + { + "leetcode-id": 442, + "title": "Find All Duplicates in an Array", + "difficulty": 2, + "description": "Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice.\nYou must write an algorithm that runs in\u00a0O(n)\u00a0time and uses only constant extra space.", + "examples": [ + "Example 1:\nInput: nums = [4,3,2,7,8,2,3,1]\nOutput: [2,3]", + "Example 2:\nInput: nums = [1,1,2]\nOutput: [1]", + "Example 3:\nInput: nums = [1]\nOutput: []" + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^5\n1 <= nums[i] <= n\nEach element in nums appears once or twice.", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "find-all-duplicates-in-an-array" + }, + { + "leetcode-id": 443, + "title": "String Compression", + "difficulty": 2, + "description": "Given an array of characters chars, compress it using the following algorithm:\nBegin with an empty string s. For each group of consecutive repeating characters in chars:\n\nIf the group's length is 1, append the character to s.\nOtherwise, append the character followed by the group's length.\n\nThe compressed string s should not be returned separately, but instead, be stored in the input character array chars. Note that group lengths that are 10 or longer will be split into multiple characters in chars.\nAfter you are done modifying the input array, return the new length of the array.\nYou must write an algorithm that uses only constant extra space.", + "examples": [ + "Example 1:\nInput: chars = [\"a\",\"a\",\"b\",\"b\",\"c\",\"c\",\"c\"]\nOutput: Return 6, and the first 6 characters of the input array should be: [\"a\",\"2\",\"b\",\"2\",\"c\",\"3\"]\nExplanation: The groups are \"aa\", \"bb\", and \"ccc\". This compresses to \"a2b2c3\".", + "Example 2:\nInput: chars = [\"a\"]\nOutput: Return 1, and the first character of the input array should be: [\"a\"]\nExplanation: The only group is \"a\", which remains uncompressed since it's a single character.", + "Example 3:\nInput: chars = [\"a\",\"b\",\"b\",\"b\",\"b\",\"b\",\"b\",\"b\",\"b\",\"b\",\"b\",\"b\",\"b\"]\nOutput: Return 4, and the first 4 characters of the input array should be: [\"a\",\"b\",\"1\",\"2\"].\nExplanation: The groups are \"a\" and \"bbbbbbbbbbbb\". This compresses to \"ab12\"." + ], + "constraints": "Constraints:\n\n1 <= chars.length <= 2000\nchars[i] is a lowercase English letter, uppercase English letter, digit, or symbol.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "string-compression" + }, + { + "leetcode-id": 445, + "title": "Add Two Numbers II", + "difficulty": 2, + "description": "You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.\nYou may assume the two numbers do not contain any leading zero, except the number 0 itself.", + "examples": [ + "Example 1:\nInput: l1 = [7,2,4,3], l2 = [5,6,4]\nOutput: [7,8,0,7]", + "Example 2:\nInput: l1 = [2,4,3], l2 = [5,6,4]\nOutput: [8,0,7]", + "Example 3:\nInput: l1 = [0], l2 = [0]\nOutput: [0]" + ], + "constraints": "Constraints:\n\nThe number of nodes in each linked list is in the range [1, 100].\n0 <= Node.val <= 9\nIt is guaranteed that the list represents a number that does not have leading zeros.\n\n\u00a0\nFollow up:\u00a0Could you solve it without reversing the input lists?", + "tags": [ + "Linked List", + "Math", + "Stack" + ], + "title-slug": "add-two-numbers-ii" + }, + { + "leetcode-id": 446, + "title": "Arithmetic Slices II - Subsequence", + "difficulty": 3, + "description": "Given an integer array nums, return the number of all the arithmetic subsequences of nums.\nA sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.\n\nFor example, [1, 3, 5, 7, 9], [7, 7, 7, 7], and [3, -1, -5, -9] are arithmetic sequences.\nFor example, [1, 1, 2, 5, 7] is not an arithmetic sequence.\n\nA subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array.\n\nFor example, [2,5,10] is a subsequence of [1,2,1,2,4,1,5,10].\n\nThe test cases are generated so that the answer fits in 32-bit integer.", + "examples": [ + "Example 1:\nInput: nums = [2,4,6,8,10]\nOutput: 7\nExplanation: All arithmetic subsequence slices are:\n[2,4,6]\n[4,6,8]\n[6,8,10]\n[2,4,6,8]\n[4,6,8,10]\n[2,4,6,8,10]\n[2,6,10]", + "Example 2:\nInput: nums = [7,7,7,7,7]\nOutput: 16\nExplanation: Any subsequence of this array is arithmetic." + ], + "constraints": "Constraints:\n\n1\u00a0 <= nums.length <= 1000\n-2^31 <= nums[i] <= 2^31 - 1", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "arithmetic-slices-ii-subsequence" + }, + { + "leetcode-id": 447, + "title": "Number of Boomerangs", + "difficulty": 2, + "description": "You are given n points in the plane that are all distinct, where points[i] = [xi, yi]. A boomerang is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of the tuple matters).\nReturn the number of boomerangs.", + "examples": [ + "Example 1:\nInput: points = [[0,0],[1,0],[2,0]]\nOutput: 2\nExplanation: The two boomerangs are [[1,0],[0,0],[2,0]] and [[1,0],[2,0],[0,0]].", + "Example 2:\nInput: points = [[1,1],[2,2],[3,3]]\nOutput: 2", + "Example 3:\nInput: points = [[1,1]]\nOutput: 0" + ], + "constraints": "Constraints:\n\nn == points.length\n1 <= n <= 500\npoints[i].length == 2\n-10^4 <= xi, yi <= 10^4\nAll the points are unique.", + "tags": [ + "Array", + "Hash Table", + "Math" + ], + "title-slug": "number-of-boomerangs" + }, + { + "leetcode-id": 448, + "title": "Find All Numbers Disappeared in an Array", + "difficulty": 1, + "description": "Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.", + "examples": [ + "Example 1:\nInput: nums = [4,3,2,7,8,2,3,1]\nOutput: [5,6]", + "Example 2:\nInput: nums = [1,1]\nOutput: [2]" + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^5\n1 <= nums[i] <= n\n\n\u00a0\nFollow up: Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "find-all-numbers-disappeared-in-an-array" + }, + { + "leetcode-id": 449, + "title": "Serialize and Deserialize BST", + "difficulty": 2, + "description": "Serialization is converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.\nDesign an algorithm to serialize and deserialize a binary search tree. There is no restriction on how your serialization/deserialization algorithm should work. You need to ensure that a binary search tree can be serialized to a string, and this string can be deserialized to the original tree structure.\nThe encoded string should be as compact as possible.", + "examples": [ + "Example 1:\nInput: root = [2,1,3]\nOutput: [2,1,3]", + "Example 2:\nInput: root = []\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 10^4].\n0 <= Node.val <= 10^4\nThe input tree is guaranteed to be a binary search tree.", + "tags": [ + "String", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Design", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "serialize-and-deserialize-bst" + }, + { + "leetcode-id": 450, + "title": "Delete Node in a BST", + "difficulty": 2, + "description": "Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.\nBasically, the deletion can be divided into two stages:\n\nSearch for a node to remove.\nIf the node is found, delete the node.", + "examples": [ + "Example 1:\nInput: root = [5,3,6,2,4,null,7], key = 3\nOutput: [5,4,6,2,null,null,7]\nExplanation: Given key to delete is 3. So we find the node with value 3 and delete it.\nOne valid answer is [5,4,6,2,null,null,7], shown in the above BST.\nPlease notice that another valid answer is [5,2,6,null,4,null,7] and it's also accepted.", + "Example 2:\nInput: root = [5,3,6,2,4,null,7], key = 0\nOutput: [5,3,6,2,4,null,7]\nExplanation: The tree does not contain a node with value = 0.", + "Example 3:\nInput: root = [], key = 0\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 10^4].\n-10^5 <= Node.val <= 10^5\nEach node has a unique value.\nroot is a valid binary search tree.\n-10^5 <= key <= 10^5\n\n\u00a0\nFollow up: Could you solve it with time complexity O(height of tree)?", + "tags": [ + "Tree", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "delete-node-in-a-bst" + }, + { + "leetcode-id": 451, + "title": "Sort Characters By Frequency", + "difficulty": 2, + "description": "Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.\nReturn the sorted string. If there are multiple answers, return any of them.", + "examples": [ + "Example 1:\nInput: s = \"tree\"\nOutput: \"eert\"\nExplanation: 'e' appears twice while 'r' and 't' both appear once.\nSo 'e' must appear before both 'r' and 't'. Therefore \"eetr\" is also a valid answer.", + "Example 2:\nInput: s = \"cccaaa\"\nOutput: \"aaaccc\"\nExplanation: Both 'c' and 'a' appear three times, so both \"cccaaa\" and \"aaaccc\" are valid answers.\nNote that \"cacaca\" is incorrect, as the same characters must be together.", + "Example 3:\nInput: s = \"Aabb\"\nOutput: \"bbAa\"\nExplanation: \"bbaA\" is also a valid answer, but \"Aabb\" is incorrect.\nNote that 'A' and 'a' are treated as two different characters." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 5 * 10^5\ns consists of uppercase and lowercase English letters and digits.", + "tags": [ + "Hash Table", + "String", + "Sorting", + "Heap (Priority Queue)", + "Bucket Sort", + "Counting" + ], + "title-slug": "sort-characters-by-frequency" + }, + { + "leetcode-id": 452, + "title": "Minimum Number of Arrows to Burst Balloons", + "difficulty": 2, + "description": "There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [xstart, xend] denotes a balloon whose horizontal diameter stretches between xstart and xend. You do not know the exact y-coordinates of the balloons.\nArrows can be shot up directly vertically (in the positive y-direction) from different points along the x-axis. A balloon with xstart and xend is burst by an arrow shot at x if xstart <= x <= xend. There is no limit to the number of arrows that can be shot. A shot arrow keeps traveling up infinitely, bursting any balloons in its path.\nGiven the array points, return the minimum number of arrows that must be shot to burst all balloons.", + "examples": [ + "Example 1:\nInput: points = [[10,16],[2,8],[1,6],[7,12]]\nOutput: 2\nExplanation: The balloons can be burst by 2 arrows:\n- Shoot an arrow at x = 6, bursting the balloons [2,8] and [1,6].\n- Shoot an arrow at x = 11, bursting the balloons [10,16] and [7,12].", + "Example 2:\nInput: points = [[1,2],[3,4],[5,6],[7,8]]\nOutput: 4\nExplanation: One arrow needs to be shot for each balloon for a total of 4 arrows.", + "Example 3:\nInput: points = [[1,2],[2,3],[3,4],[4,5]]\nOutput: 2\nExplanation: The balloons can be burst by 2 arrows:\n- Shoot an arrow at x = 2, bursting the balloons [1,2] and [2,3].\n- Shoot an arrow at x = 4, bursting the balloons [3,4] and [4,5]." + ], + "constraints": "Constraints:\n\n1 <= points.length <= 10^5\npoints[i].length == 2\n-2^31 <= xstart < xend <= 2^31 - 1", + "tags": [ + "Array", + "Greedy", + "Sorting" + ], + "title-slug": "minimum-number-of-arrows-to-burst-balloons" + }, + { + "leetcode-id": 453, + "title": "Minimum Moves to Equal Array Elements", + "difficulty": 2, + "description": "Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal.\nIn one move, you can increment n - 1 elements of the array by 1.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3]\nOutput: 3\nExplanation: Only three moves are needed (remember each move increments two elements):\n[1,2,3] => [2,3,3] => [3,4,3] => [4,4,4]", + "Example 2:\nInput: nums = [1,1,1]\nOutput: 0" + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= nums.length <= 10^5\n-10^9 <= nums[i] <= 10^9\nThe answer is guaranteed to fit in a 32-bit integer.", + "tags": [ + "Array", + "Math" + ], + "title-slug": "minimum-moves-to-equal-array-elements" + }, + { + "leetcode-id": 454, + "title": "4Sum II", + "difficulty": 2, + "description": "Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that:\n\n0 <= i, j, k, l < n\nnums1[i] + nums2[j] + nums3[k] + nums4[l] == 0", + "examples": [ + "Example 1:\nInput: nums1 = [1,2], nums2 = [-2,-1], nums3 = [-1,2], nums4 = [0,2]\nOutput: 2\nExplanation:\nThe two tuples are:\n1. (0, 0, 0, 1) -> nums1[0] + nums2[0] + nums3[0] + nums4[1] = 1 + (-2) + (-1) + 2 = 0\n2. (1, 1, 0, 0) -> nums1[1] + nums2[1] + nums3[0] + nums4[0] = 2 + (-1) + (-1) + 0 = 0", + "Example 2:\nInput: nums1 = [0], nums2 = [0], nums3 = [0], nums4 = [0]\nOutput: 1" + ], + "constraints": "Constraints:\n\nn == nums1.length\nn == nums2.length\nn == nums3.length\nn == nums4.length\n1 <= n <= 200\n-2^28 <= nums1[i], nums2[i], nums3[i], nums4[i] <= 2^28", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "4sum-ii" + }, + { + "leetcode-id": 455, + "title": "Assign Cookies", + "difficulty": 1, + "description": "Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie.\nEach child i has a greed factor g[i], which is the minimum size of a cookie that the child will be content with; and each cookie j has a size s[j]. If s[j] >= g[i], we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.", + "examples": [ + "Example 1:\nInput: g = [1,2,3], s = [1,1]\nOutput: 1\nExplanation: You have 3 children and 2 cookies. The greed factors of 3 children are 1, 2, 3. \nAnd even though you have 2 cookies, since their size is both 1, you could only make the child whose greed factor is 1 content.\nYou need to output 1.", + "Example 2:\nInput: g = [1,2], s = [1,2,3]\nOutput: 2\nExplanation: You have 2 children and 3 cookies. The greed factors of 2 children are 1, 2. \nYou have 3 cookies and their sizes are big enough to gratify all of the children, \nYou need to output 2." + ], + "constraints": "Constraints:\n\n1 <= g.length <= 3 * 10^4\n0 <= s.length <= 3 * 10^4\n1 <= g[i], s[j] <= 2^31 - 1", + "tags": [ + "Array", + "Two Pointers", + "Greedy", + "Sorting" + ], + "title-slug": "assign-cookies" + }, + { + "leetcode-id": 456, + "title": "132 Pattern", + "difficulty": 2, + "description": "Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].\nReturn true if there is a 132 pattern in nums, otherwise, return false.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4]\nOutput: false\nExplanation: There is no 132 pattern in the sequence.", + "Example 2:\nInput: nums = [3,1,4,2]\nOutput: true\nExplanation: There is a 132 pattern in the sequence: [1, 4, 2].", + "Example 3:\nInput: nums = [-1,3,2,0]\nOutput: true\nExplanation: There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0]." + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 2 * 10^5\n-10^9 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Binary Search", + "Stack", + "Monotonic Stack", + "Ordered Set" + ], + "title-slug": "132-pattern" + }, + { + "leetcode-id": 457, + "title": "Circular Array Loop", + "difficulty": 2, + "description": "You are playing a game involving a circular array of non-zero integers nums. Each nums[i] denotes the number of indices forward/backward you must move if you are located at index i:\n\nIf nums[i] is positive, move nums[i] steps forward, and\nIf nums[i] is negative, move nums[i] steps backward.\n\nSince the array is circular, you may assume that moving forward from the last element puts you on the first element, and moving backwards from the first element puts you on the last element.\nA cycle in the array consists of a sequence of indices seq of length k where:\n\nFollowing the movement rules above results in the repeating index sequence seq[0] -> seq[1] -> ... -> seq[k - 1] -> seq[0] -> ...\nEvery nums[seq[j]] is either all positive or all negative.\nk > 1\n\nReturn true if there is a cycle in nums, or false otherwise.", + "examples": [ + "Example 1:\nInput: nums = [2,-1,1,2,2]\nOutput: true\nExplanation: The graph shows how the indices are connected. White nodes are jumping forward, while red is jumping backward.\nWe can see the cycle 0 --> 2 --> 3 --> 0 --> ..., and all of its nodes are white (jumping in the same direction).", + "Example 2:\nInput: nums = [-1,-2,-3,-4,-5,6]\nOutput: false\nExplanation: The graph shows how the indices are connected. White nodes are jumping forward, while red is jumping backward.\nThe only cycle is of size 1, so we return false.", + "Example 3:\nInput: nums = [1,-1,5,1,4]\nOutput: true\nExplanation: The graph shows how the indices are connected. White nodes are jumping forward, while red is jumping backward.\nWe can see the cycle 0 --> 1 --> 0 --> ..., and while it is of size > 1, it has a node jumping forward and a node jumping backward, so it is not a cycle.\nWe can see the cycle 3 --> 4 --> 3 --> ..., and all of its nodes are white (jumping in the same direction)." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 5000\n-1000 <= nums[i] <= 1000\nnums[i] != 0\n\n\u00a0\nFollow up: Could you solve it in O(n) time complexity and O(1) extra space complexity?", + "tags": [ + "Array", + "Hash Table", + "Two Pointers" + ], + "title-slug": "circular-array-loop" + }, + { + "leetcode-id": 458, + "title": "Poor Pigs", + "difficulty": 3, + "description": "There are buckets buckets of liquid, where exactly one of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have minutesToTest minutes to determine which bucket is poisonous.\nYou can feed the pigs according to these steps:\n\nChoose some live pigs to feed.\nFor each pig, choose which buckets to feed it. The pig will consume all the chosen buckets simultaneously and will take no time. Each pig can feed from any number of buckets, and each bucket can be fed from by any number of pigs.\nWait for minutesToDie minutes. You may not feed any other pigs during this time.\nAfter minutesToDie minutes have passed, any pigs that have been fed the poisonous bucket will die, and all others will survive.\nRepeat this process until you run out of time.\n\nGiven buckets, minutesToDie, and minutesToTest, return the minimum number of pigs needed to figure out which bucket is poisonous within the allotted time.", + "examples": [ + "Example 1:\nInput: buckets = 4, minutesToDie = 15, minutesToTest = 15\nOutput: 2\nExplanation: We can determine the poisonous bucket as follows:\nAt time 0, feed the first pig buckets 1 and 2, and feed the second pig buckets 2 and 3.\nAt time 15, there are 4 possible outcomes:\n- If only the first pig dies, then bucket 1 must be poisonous.\n- If only the second pig dies, then bucket 3 must be poisonous.\n- If both pigs die, then bucket 2 must be poisonous.\n- If neither pig dies, then bucket 4 must be poisonous.", + "Example 2:\nInput: buckets = 4, minutesToDie = 15, minutesToTest = 30\nOutput: 2\nExplanation: We can determine the poisonous bucket as follows:\nAt time 0, feed the first pig bucket 1, and feed the second pig bucket 2.\nAt time 15, there are 2 possible outcomes:\n- If either pig dies, then the poisonous bucket is the one it was fed.\n- If neither pig dies, then feed the first pig bucket 3, and feed the second pig bucket 4.\nAt time 30, one of the two pigs must die, and the poisonous bucket is the one it was fed." + ], + "constraints": "Constraints:\n\n1 <= buckets <= 1000\n1 <=\u00a0minutesToDie <=\u00a0minutesToTest <= 100", + "tags": [ + "Math", + "Dynamic Programming", + "Combinatorics" + ], + "title-slug": "poor-pigs" + }, + { + "leetcode-id": 459, + "title": "Repeated Substring Pattern", + "difficulty": 1, + "description": "Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.", + "examples": [ + "Example 1:\nInput: s = \"abab\"\nOutput: true\nExplanation: It is the substring \"ab\" twice.", + "Example 2:\nInput: s = \"aba\"\nOutput: false", + "Example 3:\nInput: s = \"abcabcabcabc\"\nOutput: true\nExplanation: It is the substring \"abc\" four times or the substring \"abcabc\" twice." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^4\ns consists of lowercase English letters.", + "tags": [ + "String", + "String Matching" + ], + "title-slug": "repeated-substring-pattern" + }, + { + "leetcode-id": 460, + "title": "LFU Cache", + "difficulty": 3, + "description": "Design and implement a data structure for a Least Frequently Used (LFU) cache.\nImplement the LFUCache class:\n\nLFUCache(int capacity) Initializes the object with the capacity of the data structure.\nint get(int key) Gets the value of the key if the key exists in the cache. Otherwise, returns -1.\nvoid put(int key, int value) Update the value of the key if present, or inserts the key if not already present. When the cache reaches its capacity, it should invalidate and remove the least frequently used key before inserting a new item. For this problem, when there is a tie (i.e., two or more keys with the same frequency), the least recently used key would be invalidated.\n\nTo determine the least frequently used key, a use counter is maintained for each key in the cache. The key with the smallest use counter is the least frequently used key.\nWhen a key is first inserted into the cache, its use counter is set to 1 (due to the put operation). The use counter for a key in the cache is incremented either a get or put operation is called on it.\nThe functions\u00a0get\u00a0and\u00a0put\u00a0must each run in O(1) average time complexity.", + "examples": [ + "Example 1:\nInput\n[\"LFUCache\", \"put\", \"put\", \"get\", \"put\", \"get\", \"get\", \"put\", \"get\", \"get\", \"get\"]\n[[2], [1, 1], [2, 2], [1], [3, 3], [2], [3], [4, 4], [1], [3], [4]]\nOutput\n[null, null, null, 1, null, -1, 3, null, -1, 3, 4]\n\nExplanation\n// cnt(x) = the use counter for key x\n// cache=[] will show the last used order for tiebreakers (leftmost element is most recent)\nLFUCache lfu = new LFUCache(2);\nlfu.put(1, 1); // cache=[1,_], cnt(1)=1\nlfu.put(2, 2); // cache=[2,1], cnt(2)=1, cnt(1)=1\nlfu.get(1); // return 1\n // cache=[1,2], cnt(2)=1, cnt(1)=2\nlfu.put(3, 3); // 2 is the LFU key because cnt(2)=1 is the smallest, invalidate 2.\n\u00a0 // cache=[3,1], cnt(3)=1, cnt(1)=2\nlfu.get(2); // return -1 (not found)\nlfu.get(3); // return 3\n // cache=[3,1], cnt(3)=2, cnt(1)=2\nlfu.put(4, 4); // Both 1 and 3 have the same cnt, but 1 is LRU, invalidate 1.\n // cache=[4,3], cnt(4)=1, cnt(3)=2\nlfu.get(1); // return -1 (not found)\nlfu.get(3); // return 3\n // cache=[3,4], cnt(4)=1, cnt(3)=3\nlfu.get(4); // return 4\n // cache=[4,3], cnt(4)=2, cnt(3)=3" + ], + "constraints": "Constraints:\n\n1 <= capacity\u00a0<= 10^4\n0 <= key <= 10^5\n0 <= value <= 10^9\nAt most 2 * 10^5\u00a0calls will be made to get and put.", + "tags": [ + "Hash Table", + "Linked List", + "Design", + "Doubly-Linked List" + ], + "title-slug": "lfu-cache" + }, + { + "leetcode-id": 461, + "title": "Hamming Distance", + "difficulty": 1, + "description": "The Hamming distance between two integers is the number of positions at which the corresponding bits are different.\nGiven two integers x and y, return the Hamming distance between them.", + "examples": [ + "Example 1:\nInput: x = 1, y = 4\nOutput: 2\nExplanation:\n1 (0 0 0 1)\n4 (0 1 0 0)\n \u2191 \u2191\nThe above arrows point to positions where the corresponding bits are different.", + "Example 2:\nInput: x = 3, y = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n0 <=\u00a0x, y <= 2^31 - 1", + "tags": [ + "Bit Manipulation" + ], + "title-slug": "hamming-distance" + }, + { + "leetcode-id": 462, + "title": "Minimum Moves to Equal Array Elements II", + "difficulty": 2, + "description": "Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal.\nIn one move, you can increment or decrement an element of the array by 1.\nTest cases are designed so that the answer will fit in a 32-bit integer.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3]\nOutput: 2\nExplanation:\nOnly two moves are needed (remember each move increments or decrements one element):\n[1,2,3] => [2,2,3] => [2,2,2]", + "Example 2:\nInput: nums = [1,10,2,9]\nOutput: 16" + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= nums.length <= 10^5\n-10^9 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Math", + "Sorting" + ], + "title-slug": "minimum-moves-to-equal-array-elements-ii" + }, + { + "leetcode-id": 463, + "title": "Island Perimeter", + "difficulty": 1, + "description": "You are given row x col grid representing a map where grid[i][j] = 1 represents\u00a0land and grid[i][j] = 0 represents water.\nGrid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).\nThe island doesn't have \"lakes\", meaning the water inside isn't connected to the water around the island. One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island.", + "examples": [ + "Example 1:\nInput: grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]\nOutput: 16\nExplanation: The perimeter is the 16 yellow stripes in the image above.", + "Example 2:\nInput: grid = [[1]]\nOutput: 4", + "Example 3:\nInput: grid = [[1,0]]\nOutput: 4" + ], + "constraints": "Constraints:\n\nrow == grid.length\ncol == grid[i].length\n1 <= row, col <= 100\ngrid[i][j] is 0 or 1.\nThere is exactly one island in grid.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "island-perimeter" + }, + { + "leetcode-id": 464, + "title": "Can I Win", + "difficulty": 2, + "description": "In the \"100 game\" two players take turns adding, to a running total, any integer from 1 to 10. The player who first causes the running total to reach or exceed 100 wins.\nWhat if we change the game so that players cannot re-use integers?\nFor example, two players might take turns drawing from a common pool of numbers from 1 to 15 without replacement until they reach a total >= 100.\nGiven two integers maxChoosableInteger and desiredTotal, return true if the first player to move can force a win, otherwise, return false. Assume both players play optimally.", + "examples": [ + "Example 1:\nInput: maxChoosableInteger = 10, desiredTotal = 11\nOutput: false\nExplanation:\nNo matter which integer the first player choose, the first player will lose.\nThe first player can choose an integer from 1 up to 10.\nIf the first player choose 1, the second player can only choose integers from 2 up to 10.\nThe second player will win by choosing 10 and get a total = 11, which is >= desiredTotal.\nSame with other integers chosen by the first player, the second player will always win.", + "Example 2:\nInput: maxChoosableInteger = 10, desiredTotal = 0\nOutput: true", + "Example 3:\nInput: maxChoosableInteger = 10, desiredTotal = 1\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= maxChoosableInteger <= 20\n0 <= desiredTotal <= 300", + "tags": [ + "Math", + "Dynamic Programming", + "Bit Manipulation", + "Memoization", + "Game Theory", + "Bitmask" + ], + "title-slug": "can-i-win" + }, + { + "leetcode-id": 466, + "title": "Count The Repetitions", + "difficulty": 3, + "description": "We define str = [s, n] as the string str which consists of the string s concatenated n times.\n\nFor example, str == [\"abc\", 3] ==\"abcabcabc\".\n\nWe define that string s1 can be obtained from string s2 if we can remove some characters from s2 such that it becomes s1.\n\nFor example, s1 = \"abc\" can be obtained from s2 = \"abdbec\" based on our definition by removing the bolded underlined characters.\n\nYou are given two strings s1 and s2 and two integers n1 and n2. You have the two strings str1 = [s1, n1] and str2 = [s2, n2].\nReturn the maximum integer m such that str = [str2, m] can be obtained from str1.", + "examples": [ + "Example 1:\nInput: s1 = \"acb\", n1 = 4, s2 = \"ab\", n2 = 2\nOutput: 2", + "Example 2:\nInput: s1 = \"acb\", n1 = 1, s2 = \"acb\", n2 = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= s1.length, s2.length <= 100\ns1 and s2 consist of lowercase English letters.\n1 <= n1, n2 <= 10^6", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "count-the-repetitions" + }, + { + "leetcode-id": 467, + "title": "Unique Substrings in Wraparound String", + "difficulty": 2, + "description": "We define the string base to be the infinite wraparound string of \"abcdefghijklmnopqrstuvwxyz\", so base will look like this:\n\n\"...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....\".\n\nGiven a string s, return the number of unique non-empty substrings of s are present in base.", + "examples": [ + "Example 1:\nInput: s = \"a\"\nOutput: 1\nExplanation: Only the substring \"a\" of s is in base.", + "Example 2:\nInput: s = \"cac\"\nOutput: 2\nExplanation: There are two substrings (\"a\", \"c\") of s in base.", + "Example 3:\nInput: s = \"zab\"\nOutput: 6\nExplanation: There are six substrings (\"z\", \"a\", \"b\", \"za\", \"ab\", and \"zab\") of s in base." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "unique-substrings-in-wraparound-string" + }, + { + "leetcode-id": 468, + "title": "Validate IP Address", + "difficulty": 2, + "description": "Given a string queryIP, return \"IPv4\" if IP is a valid IPv4 address, \"IPv6\" if IP is a valid IPv6 address or \"Neither\" if IP is not a correct IP of any type.\nA valid IPv4 address is an IP in the form \"x1.x2.x3.x4\" where 0 <= xi <= 255 and xi cannot contain leading zeros. For example, \"192.168.1.1\" and \"192.168.1.0\" are valid IPv4 addresses while \"192.168.01.1\", \"192.168.1.00\", and \"192.168@1.1\" are invalid IPv4 addresses.\nA valid IPv6 address is an IP in the form \"x1:x2:x3:x4:x5:x6:x7:x8\" where:\n\n1 <= xi.length <= 4\nxi is a hexadecimal string which may contain digits, lowercase English letter ('a' to 'f') and upper-case English letters ('A' to 'F').\nLeading zeros are allowed in xi.\n\nFor example, \"2001:0db8:85a3:0000:0000:8a2e:0370:7334\" and \"2001:db8:85a3:0:0:8A2E:0370:7334\" are valid IPv6 addresses, while \"2001:0db8:85a3::8A2E:037j:7334\" and \"02001:0db8:85a3:0000:0000:8a2e:0370:7334\" are invalid IPv6 addresses.", + "examples": [ + "Example 1:\nInput: queryIP = \"172.16.254.1\"\nOutput: \"IPv4\"\nExplanation: This is a valid IPv4 address, return \"IPv4\".", + "Example 2:\nInput: queryIP = \"2001:0db8:85a3:0:0:8A2E:0370:7334\"\nOutput: \"IPv6\"\nExplanation: This is a valid IPv6 address, return \"IPv6\".", + "Example 3:\nInput: queryIP = \"256.256.256.256\"\nOutput: \"Neither\"\nExplanation: This is neither a IPv4 address nor a IPv6 address." + ], + "constraints": "Constraints:\n\nqueryIP consists only of English letters, digits and the characters '.' and ':'.", + "tags": [ + "String" + ], + "title-slug": "validate-ip-address" + }, + { + "leetcode-id": 470, + "title": "Implement Rand10() Using Rand7()", + "difficulty": 2, + "description": "Given the API rand7() that generates a uniform random integer in the range [1, 7], write a function rand10() that generates a uniform random integer in the range [1, 10]. You can only call the API rand7(), and you shouldn't call any other API. Please do not use a language's built-in random API.\nEach test case will have one internal argument n, the number of times that your implemented function rand10() will be called while testing. Note that this is not an argument passed to rand10().", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: [2]", + "Example 2:\nInput: n = 2\nOutput: [2,8]", + "Example 3:\nInput: n = 3\nOutput: [3,8,10]" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5\n\n\u00a0\nFollow up:\n\nWhat is the expected value for the number of calls to rand7() function?\nCould you minimize the number of calls to rand7()?", + "tags": [ + "Math", + "Rejection Sampling", + "Randomized", + "Probability and Statistics" + ], + "title-slug": "implement-rand10-using-rand7" + }, + { + "leetcode-id": 472, + "title": "Concatenated Words", + "difficulty": 3, + "description": "Given an array of strings words (without duplicates), return all the concatenated words in the given list of words.\nA concatenated word is defined as a string that is comprised entirely of at least two shorter words (not necesssarily distinct)\u00a0in the given array.", + "examples": [ + "Example 1:\nInput: words = [\"cat\",\"cats\",\"catsdogcats\",\"dog\",\"dogcatsdog\",\"hippopotamuses\",\"rat\",\"ratcatdogcat\"]\nOutput: [\"catsdogcats\",\"dogcatsdog\",\"ratcatdogcat\"]\nExplanation: \"catsdogcats\" can be concatenated by \"cats\", \"dog\" and \"cats\"; \n\"dogcatsdog\" can be concatenated by \"dog\", \"cats\" and \"dog\"; \n\"ratcatdogcat\" can be concatenated by \"rat\", \"cat\", \"dog\" and \"cat\".", + "Example 2:\nInput: words = [\"cat\",\"dog\",\"catdog\"]\nOutput: [\"catdog\"]" + ], + "constraints": "Constraints:\n\n1 <= words.length <= 10^4\n1 <= words[i].length <= 30\nwords[i] consists of only lowercase English letters.\nAll the strings of words are unique.\n1 <= sum(words[i].length) <= 10^5", + "tags": [ + "Array", + "String", + "Dynamic Programming", + "Depth-First Search", + "Trie" + ], + "title-slug": "concatenated-words" + }, + { + "leetcode-id": 473, + "title": "Matchsticks to Square", + "difficulty": 2, + "description": "You are given an integer array matchsticks where matchsticks[i] is the length of the i^th matchstick. You want to use all the matchsticks to make one square. You should not break any stick, but you can link them up, and each matchstick must be used exactly one time.\nReturn true if you can make this square and false otherwise.", + "examples": [ + "Example 1:\nInput: matchsticks = [1,1,2,2,2]\nOutput: true\nExplanation: You can form a square with length 2, one side of the square came two sticks with length 1.", + "Example 2:\nInput: matchsticks = [3,3,3,3,4]\nOutput: false\nExplanation: You cannot find a way to form a square with all the matchsticks." + ], + "constraints": "Constraints:\n\n1 <= matchsticks.length <= 15\n1 <= matchsticks[i] <= 10^8", + "tags": [ + "Array", + "Dynamic Programming", + "Backtracking", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "matchsticks-to-square" + }, + { + "leetcode-id": 474, + "title": "Ones and Zeroes", + "difficulty": 2, + "description": "You are given an array of binary strings strs and two integers m and n.\nReturn the size of the largest subset of strs such that there are at most m 0's and n 1's in the subset.\nA set x is a subset of a set y if all elements of x are also elements of y.", + "examples": [ + "Example 1:\nInput: strs = [\"10\",\"0001\",\"111001\",\"1\",\"0\"], m = 5, n = 3\nOutput: 4\nExplanation: The largest subset with at most 5 0's and 3 1's is {\"10\", \"0001\", \"1\", \"0\"}, so the answer is 4.\nOther valid but smaller subsets include {\"0001\", \"1\"} and {\"10\", \"1\", \"0\"}.\n{\"111001\"} is an invalid subset because it contains 4 1's, greater than the maximum of 3.", + "Example 2:\nInput: strs = [\"10\",\"0\",\"1\"], m = 1, n = 1\nOutput: 2\nExplanation: The largest subset is {\"0\", \"1\"}, so the answer is 2." + ], + "constraints": "Constraints:\n\n1 <= strs.length <= 600\n1 <= strs[i].length <= 100\nstrs[i] consists only of digits '0' and '1'.\n1 <= m, n <= 100", + "tags": [ + "Array", + "String", + "Dynamic Programming" + ], + "title-slug": "ones-and-zeroes" + }, + { + "leetcode-id": 475, + "title": "Heaters", + "difficulty": 2, + "description": "Winter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses.\nEvery house can be warmed, as long as the house is within the heater's warm radius range.\u00a0\nGiven the positions of houses and heaters on a horizontal line, return the minimum radius standard of heaters\u00a0so that those heaters could cover all houses.\nNotice that\u00a0all the heaters follow your radius standard, and the warm radius will the same.", + "examples": [ + "Example 1:\nInput: houses = [1,2,3], heaters = [2]\nOutput: 1\nExplanation: The only heater was placed in the position 2, and if we use the radius 1 standard, then all the houses can be warmed.", + "Example 2:\nInput: houses = [1,2,3,4], heaters = [1,4]\nOutput: 1\nExplanation: The two heaters were placed at positions 1 and 4. We need to use a radius 1 standard, then all the houses can be warmed.", + "Example 3:\nInput: houses = [1,5], heaters = [2]\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= houses.length, heaters.length <= 3 * 10^4\n1 <= houses[i], heaters[i] <= 10^9", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Sorting" + ], + "title-slug": "heaters" + }, + { + "leetcode-id": 476, + "title": "Number Complement", + "difficulty": 1, + "description": "The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.\n\nFor example, The integer 5 is \"101\" in binary and its complement is \"010\" which is the integer 2.\n\nGiven an integer num, return its complement.", + "examples": [ + "Example 1:\nInput: num = 5\nOutput: 2\nExplanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.", + "Example 2:\nInput: num = 1\nOutput: 0\nExplanation: The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0." + ], + "constraints": "Constraints:\n\n1 <= num < 2^31\n\n\u00a0\nNote: This question is the same as 1009: https://leetcode.com/problems/complement-of-base-10-integer/", + "tags": [ + "Bit Manipulation" + ], + "title-slug": "number-complement" + }, + { + "leetcode-id": 477, + "title": "Total Hamming Distance", + "difficulty": 2, + "description": "The Hamming distance between two integers is the number of positions at which the corresponding bits are different.\nGiven an integer array nums, return the sum of Hamming distances between all the pairs of the integers in nums.", + "examples": [ + "Example 1:\nInput: nums = [4,14,2]\nOutput: 6\nExplanation: In binary representation, the 4 is 0100, 14 is 1110, and 2 is 0010 (just\nshowing the four bits relevant in this case).\nThe answer will be:\nHammingDistance(4, 14) + HammingDistance(4, 2) + HammingDistance(14, 2) = 2 + 2 + 2 = 6.", + "Example 2:\nInput: nums = [4,14,4]\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n0 <= nums[i] <= 10^9\nThe answer for the given input will fit in a 32-bit integer.", + "tags": [ + "Array", + "Math", + "Bit Manipulation" + ], + "title-slug": "total-hamming-distance" + }, + { + "leetcode-id": 478, + "title": "Generate Random Point in a Circle", + "difficulty": 2, + "description": "Given the radius and the position of the center of a circle, implement the function randPoint which generates a uniform random point inside the circle.\nImplement the Solution class:\n\nSolution(double radius, double x_center, double y_center) initializes the object with the radius of the circle radius and the position of the center (x_center, y_center).\nrandPoint() returns a random point inside the circle. A point on the circumference of the circle is considered to be in the circle. The answer is returned as an array [x, y].", + "examples": [ + "Example 1:\nInput\n[\"Solution\", \"randPoint\", \"randPoint\", \"randPoint\"]\n[[1.0, 0.0, 0.0], [], [], []]\nOutput\n[null, [-0.02493, -0.38077], [0.82314, 0.38945], [0.36572, 0.17248]]\n\nExplanation\nSolution solution = new Solution(1.0, 0.0, 0.0);\nsolution.randPoint(); // return [-0.02493, -0.38077]\nsolution.randPoint(); // return [0.82314, 0.38945]\nsolution.randPoint(); // return [0.36572, 0.17248]" + ], + "constraints": "Constraints:\n\n0 <\u00a0radius <= 10^8\n-10^7 <= x_center, y_center <= 10^7\nAt most 3 * 10^4 calls will be made to randPoint.", + "tags": [ + "Math", + "Geometry", + "Rejection Sampling", + "Randomized" + ], + "title-slug": "generate-random-point-in-a-circle" + }, + { + "leetcode-id": 479, + "title": "Largest Palindrome Product", + "difficulty": 3, + "description": "Given an integer n, return the largest palindromic integer that can be represented as the product of two n-digits integers. Since the answer can be very large, return it modulo 1337.", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: 987\nExplanation: 99 x 91 = 9009, 9009 % 1337 = 987", + "Example 2:\nInput: n = 1\nOutput: 9" + ], + "constraints": "Constraints:\n\n1 <= n <= 8", + "tags": [ + "Math" + ], + "title-slug": "largest-palindrome-product" + }, + { + "leetcode-id": 480, + "title": "Sliding Window Median", + "difficulty": 3, + "description": "The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.\n\nFor examples, if arr = [2,3,4], the median is 3.\nFor examples, if arr = [1,2,3,4], the median is (2 + 3) / 2 = 2.5.\n\nYou are given an integer array nums and an integer k. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.\nReturn the median array for each window in the original array. Answers within 10^-5 of the actual value will be accepted.", + "examples": [ + "Example 1:\nInput: nums = [1,3,-1,-3,5,3,6,7], k = 3\nOutput: [1.00000,-1.00000,-1.00000,3.00000,5.00000,6.00000]\nExplanation: \nWindow position Median\n--------------- -----\n[1 3 -1] -3 5 3 6 7 1\n 1 [3 -1 -3] 5 3 6 7 -1\n 1 3 [-1 -3 5] 3 6 7 -1\n 1 3 -1 [-3 5 3] 6 7 3\n 1 3 -1 -3 [5 3 6] 7 5\n 1 3 -1 -3 5 [3 6 7] 6", + "Example 2:\nInput: nums = [1,2,3,4,2,3,1,4,2], k = 3\nOutput: [2.00000,3.00000,3.00000,3.00000,2.00000,3.00000,2.00000]" + ], + "constraints": "Constraints:\n\n1 <= k <= nums.length <= 10^5\n-2^31 <= nums[i] <= 2^31 - 1", + "tags": [ + "Array", + "Hash Table", + "Sliding Window", + "Heap (Priority Queue)" + ], + "title-slug": "sliding-window-median" + }, + { + "leetcode-id": 481, + "title": "Magical String", + "difficulty": 2, + "description": "A magical string s consists of only '1' and '2' and obeys the following rules:\n\nThe string s is magical because concatenating the number of contiguous occurrences of characters '1' and '2' generates the string s itself.\n\nThe first few elements of s is s = \"1221121221221121122\u2026\u2026\". If we group the consecutive 1's and 2's in s, it will be \"1 22 11 2 1 22 1 22 11 2 11 22 ......\" and the occurrences of 1's or 2's in each group are \"1 2 2 1 1 2 1 2 2 1 2 2 ......\". You can see that the occurrence sequence is s itself.\nGiven an integer n, return the number of 1's in the first n number in the magical string s.", + "examples": [ + "Example 1:\nInput: n = 6\nOutput: 3\nExplanation: The first 6 elements of magical string s is \"122112\" and it contains three 1's, so return 3.", + "Example 2:\nInput: n = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "magical-string" + }, + { + "leetcode-id": 482, + "title": "License Key Formatting", + "difficulty": 1, + "description": "You are given a license key represented as a string s that consists of only alphanumeric characters and dashes. The string is separated into n + 1 groups by n dashes. You are also given an integer k.\nWe want to reformat the string s such that each group contains exactly k characters, except for the first group, which could be shorter than k but still must contain at least one character. Furthermore, there must be a dash inserted between two groups, and you should convert all lowercase letters to uppercase.\nReturn the reformatted license key.", + "examples": [ + "Example 1:\nInput: s = \"5F3Z-2e-9-w\", k = 4\nOutput: \"5F3Z-2E9W\"\nExplanation: The string s has been split into two parts, each part has 4 characters.\nNote that the two extra dashes are not needed and can be removed.", + "Example 2:\nInput: s = \"2-5g-3-J\", k = 2\nOutput: \"2-5G-3J\"\nExplanation: The string s has been split into three parts, each part has 2 characters except the first part as it could be shorter as mentioned above." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of English letters, digits, and dashes '-'.\n1 <= k <= 10^4", + "tags": [ + "String" + ], + "title-slug": "license-key-formatting" + }, + { + "leetcode-id": 483, + "title": "Smallest Good Base", + "difficulty": 3, + "description": "Given an integer n represented as a string, return the smallest good base of n.\nWe call k >= 2 a good base of n, if all digits of n base k are 1's.", + "examples": [ + "Example 1:\nInput: n = \"13\"\nOutput: \"3\"\nExplanation: 13 base 3 is 111.", + "Example 2:\nInput: n = \"4681\"\nOutput: \"8\"\nExplanation: 4681 base 8 is 11111.", + "Example 3:\nInput: n = \"1000000000000000000\"\nOutput: \"999999999999999999\"\nExplanation: 1000000000000000000 base 999999999999999999 is 11." + ], + "constraints": "Constraints:\n\nn is an integer in the range [3, 10^18].\nn does not contain any leading zeros.", + "tags": [ + "Math", + "Binary Search" + ], + "title-slug": "smallest-good-base" + }, + { + "leetcode-id": 485, + "title": "Max Consecutive Ones", + "difficulty": 1, + "description": "Given a binary array nums, return the maximum number of consecutive 1's in the array.", + "examples": [ + "Example 1:\nInput: nums = [1,1,0,1,1,1]\nOutput: 3\nExplanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.", + "Example 2:\nInput: nums = [1,0,1,1,0,1]\nOutput: 2" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\nnums[i] is either 0 or 1.", + "tags": [ + "Array" + ], + "title-slug": "max-consecutive-ones" + }, + { + "leetcode-id": 486, + "title": "Predict the Winner", + "difficulty": 2, + "description": "You are given an integer array nums. Two players are playing a game with this array: player 1 and player 2.\nPlayer 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of 0. At each turn, the player takes one of the numbers from either end of the array (i.e., nums[0] or nums[nums.length - 1]) which reduces the size of the array by 1. The player adds the chosen number to their score. The game ends when there are no more elements in the array.\nReturn true if Player 1 can win the game. If the scores of both players are equal, then player 1 is still the winner, and you should also return true. You may assume that both players are playing optimally.", + "examples": [ + "Example 1:\nInput: nums = [1,5,2]\nOutput: false\nExplanation: Initially, player 1 can choose between 1 and 2. \nIf he chooses 2 (or 1), then player 2 can choose from 1 (or 2) and 5. If player 2 chooses 5, then player 1 will be left with 1 (or 2). \nSo, final score of player 1 is 1 + 2 = 3, and player 2 is 5. \nHence, player 1 will never be the winner and you need to return false.", + "Example 2:\nInput: nums = [1,5,233,7]\nOutput: true\nExplanation: Player 1 first chooses 1. Then player 2 has to choose between 5 and 7. No matter which number player 2 choose, player 1 can choose 233.\nFinally, player 1 has more score (234) than player 2 (12), so you need to return True representing player1 can win." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 20\n0 <= nums[i] <= 10^7", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Recursion", + "Game Theory" + ], + "title-slug": "predict-the-winner" + }, + { + "leetcode-id": 488, + "title": "Zuma Game", + "difficulty": 3, + "description": "You are playing a variation of the game Zuma.\nIn this variation of Zuma, there is a single row of colored balls on a board, where each ball can be colored red 'R', yellow 'Y', blue 'B', green 'G', or white 'W'. You also have several colored balls in your hand.\nYour goal is to clear all of the balls from the board. On each turn:\n\nPick any ball from your hand and insert it in between two balls in the row or on either end of the row.\nIf there is a group of three or more consecutive balls of the same color, remove the group of balls from the board.\n\t\nIf this removal causes more groups of three or more of the same color to form, then continue removing each group until there are none left.\n\n\nIf there are no more balls on the board, then you win the game.\nRepeat this process until you either win or do not have any more balls in your hand.\n\nGiven a string board, representing the row of balls on the board, and a string hand, representing the balls in your hand, return the minimum number of balls you have to insert to clear all the balls from the board. If you cannot clear all the balls from the board using the balls in your hand, return -1.", + "examples": [ + "Example 1:\nInput: board = \"WRRBBW\", hand = \"RB\"\nOutput: -1\nExplanation: It is impossible to clear all the balls. The best you can do is:\n- Insert 'R' so the board becomes WRRRBBW. WRRRBBW -> WBBW.\n- Insert 'B' so the board becomes WBBBW. WBBBW -> WW.\nThere are still balls remaining on the board, and you are out of balls to insert.", + "Example 2:\nInput: board = \"WWRRBBWW\", hand = \"WRBRW\"\nOutput: 2\nExplanation: To make the board empty:\n- Insert 'R' so the board becomes WWRRRBBWW. WWRRRBBWW -> WWBBWW.\n- Insert 'B' so the board becomes WWBBBWW. WWBBBWW -> WWWW -> empty.\n2 balls from your hand were needed to clear the board.", + "Example 3:\nInput: board = \"G\", hand = \"GGGGG\"\nOutput: 2\nExplanation: To make the board empty:\n- Insert 'G' so the board becomes GG.\n- Insert 'G' so the board becomes GGG. GGG -> empty.\n2 balls from your hand were needed to clear the board." + ], + "constraints": "Constraints:\n\n1 <= board.length <= 16\n1 <= hand.length <= 5\nboard and hand consist of the characters 'R', 'Y', 'B', 'G', and 'W'.\nThe initial row of balls on the board will not have any groups of three or more consecutive balls of the same color.", + "tags": [ + "String", + "Dynamic Programming", + "Stack", + "Breadth-First Search", + "Memoization" + ], + "title-slug": "zuma-game" + }, + { + "leetcode-id": 491, + "title": "Non-decreasing Subsequences", + "difficulty": 2, + "description": "Given an integer array nums, return all the different possible non-decreasing subsequences of the given array with at least two elements. You may return the answer in any order.", + "examples": [ + "Example 1:\nInput: nums = [4,6,7,7]\nOutput: [[4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7],[6,7,7],[7,7]]", + "Example 2:\nInput: nums = [4,4,3,2,1]\nOutput: [[4,4]]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 15\n-100 <= nums[i] <= 100", + "tags": [ + "Array", + "Hash Table", + "Backtracking", + "Bit Manipulation" + ], + "title-slug": "non-decreasing-subsequences" + }, + { + "leetcode-id": 492, + "title": "Construct the Rectangle", + "difficulty": 1, + "description": "A web developer needs to know how to design a web page's size. So, given a specific rectangular web page\u2019s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements:\n\nThe area of the rectangular web page you designed must equal to the given target area.\nThe width W should not be larger than the length L, which means L >= W.\nThe difference between length L and width W should be as small as possible.\n\nReturn an array [L, W] where L and W are the length and width of the\u00a0web page you designed in sequence.", + "examples": [ + "Example 1:\nInput: area = 4\nOutput: [2,2]\nExplanation: The target area is 4, and all the possible ways to construct it are [1,4], [2,2], [4,1]. \nBut according to requirement 2, [1,4] is illegal; according to requirement 3, [4,1] is not optimal compared to [2,2]. So the length L is 2, and the width W is 2.", + "Example 2:\nInput: area = 37\nOutput: [37,1]", + "Example 3:\nInput: area = 122122\nOutput: [427,286]" + ], + "constraints": "Constraints:\n\n1 <= area <= 10^7", + "tags": [ + "Math" + ], + "title-slug": "construct-the-rectangle" + }, + { + "leetcode-id": 493, + "title": "Reverse Pairs", + "difficulty": 3, + "description": "Given an integer array nums, return the number of reverse pairs in the array.\nA reverse pair is a pair (i, j) where:\n\n0 <= i < j < nums.length and\nnums[i] > 2 * nums[j].", + "examples": [ + "Example 1:\nInput: nums = [1,3,2,3,1]\nOutput: 2\nExplanation: The reverse pairs are:\n(1, 4) --> nums[1] = 3, nums[4] = 1, 3 > 2 * 1\n(3, 4) --> nums[3] = 3, nums[4] = 1, 3 > 2 * 1", + "Example 2:\nInput: nums = [2,4,3,5,1]\nOutput: 3\nExplanation: The reverse pairs are:\n(1, 4) --> nums[1] = 4, nums[4] = 1, 4 > 2 * 1\n(2, 4) --> nums[2] = 3, nums[4] = 1, 3 > 2 * 1\n(3, 4) --> nums[3] = 5, nums[4] = 1, 5 > 2 * 1" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 5 * 10^4\n-2^31 <= nums[i] <= 2^31 - 1", + "tags": [ + "Array", + "Binary Search", + "Divide and Conquer", + "Binary Indexed Tree", + "Segment Tree", + "Merge Sort", + "Ordered Set" + ], + "title-slug": "reverse-pairs" + }, + { + "leetcode-id": 494, + "title": "Target Sum", + "difficulty": 2, + "description": "You are given an integer array nums and an integer target.\nYou want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums and then concatenate all the integers.\n\nFor example, if nums = [2, 1], you can add a '+' before 2 and a '-' before 1 and concatenate them to build the expression \"+2-1\".\n\nReturn the number of different expressions that you can build, which evaluates to target.", + "examples": [ + "Example 1:\nInput: nums = [1,1,1,1,1], target = 3\nOutput: 5\nExplanation: There are 5 ways to assign symbols to make the sum of nums be target 3.\n-1 + 1 + 1 + 1 + 1 = 3\n+1 - 1 + 1 + 1 + 1 = 3\n+1 + 1 - 1 + 1 + 1 = 3\n+1 + 1 + 1 - 1 + 1 = 3\n+1 + 1 + 1 + 1 - 1 = 3", + "Example 2:\nInput: nums = [1], target = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 20\n0 <= nums[i] <= 1000\n0 <= sum(nums[i]) <= 1000\n-1000 <= target <= 1000", + "tags": [ + "Array", + "Dynamic Programming", + "Backtracking" + ], + "title-slug": "target-sum" + }, + { + "leetcode-id": 495, + "title": "Teemo Attacking", + "difficulty": 1, + "description": "Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds. More formally, an attack at second t will mean Ashe is poisoned during the inclusive time interval [t, t + duration - 1]. If Teemo attacks again before the poison effect ends, the timer for it is reset, and the poison effect will end duration seconds after the new attack.\nYou are given a non-decreasing integer array timeSeries, where timeSeries[i] denotes that Teemo attacks Ashe at second timeSeries[i], and an integer duration.\nReturn the total number of seconds that Ashe is poisoned.", + "examples": [ + "Example 1:\nInput: timeSeries = [1,4], duration = 2\nOutput: 4\nExplanation: Teemo's attacks on Ashe go as follows:\n- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.\n- At second 4, Teemo attacks, and Ashe is poisoned for seconds 4 and 5.\nAshe is poisoned for seconds 1, 2, 4, and 5, which is 4 seconds in total.", + "Example 2:\nInput: timeSeries = [1,2], duration = 2\nOutput: 3\nExplanation: Teemo's attacks on Ashe go as follows:\n- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.\n- At second 2 however, Teemo attacks again and resets the poison timer. Ashe is poisoned for seconds 2 and 3.\nAshe is poisoned for seconds 1, 2, and 3, which is 3 seconds in total." + ], + "constraints": "Constraints:\n\n1 <= timeSeries.length <= 10^4\n0 <= timeSeries[i], duration <= 10^7\ntimeSeries is sorted in non-decreasing order.", + "tags": [ + "Array", + "Simulation" + ], + "title-slug": "teemo-attacking" + }, + { + "leetcode-id": 496, + "title": "Next Greater Element I", + "difficulty": 1, + "description": "The next greater element of some element x in an array is the first greater element that is to the right of x in the same array.\nYou are given two distinct 0-indexed integer arrays nums1 and nums2, where nums1 is a subset of nums2.\nFor each 0 <= i < nums1.length, find the index j such that nums1[i] == nums2[j] and determine the next greater element of nums2[j] in nums2. If there is no next greater element, then the answer for this query is -1.\nReturn an array ans of length nums1.length such that ans[i] is the next greater element as described above.", + "examples": [ + "Example 1:\nInput: nums1 = [4,1,2], nums2 = [1,3,4,2]\nOutput: [-1,3,-1]\nExplanation: The next greater element for each value of nums1 is as follows:\n- 4 is underlined in nums2 = [1,3,4,2]. There is no next greater element, so the answer is -1.\n- 1 is underlined in nums2 = [1,3,4,2]. The next greater element is 3.\n- 2 is underlined in nums2 = [1,3,4,2]. There is no next greater element, so the answer is -1.", + "Example 2:\nInput: nums1 = [2,4], nums2 = [1,2,3,4]\nOutput: [3,-1]\nExplanation: The next greater element for each value of nums1 is as follows:\n- 2 is underlined in nums2 = [1,2,3,4]. The next greater element is 3.\n- 4 is underlined in nums2 = [1,2,3,4]. There is no next greater element, so the answer is -1." + ], + "constraints": "Constraints:\n\n1 <= nums1.length <= nums2.length <= 1000\n0 <= nums1[i], nums2[i] <= 10^4\nAll integers in nums1 and nums2 are unique.\nAll the integers of nums1 also appear in nums2.\n\n\u00a0\nFollow up: Could you find an O(nums1.length + nums2.length) solution?", + "tags": [ + "Array", + "Hash Table", + "Stack", + "Monotonic Stack" + ], + "title-slug": "next-greater-element-i" + }, + { + "leetcode-id": 497, + "title": "Random Point in Non-overlapping Rectangles", + "difficulty": 2, + "description": "You are given an array of non-overlapping axis-aligned rectangles rects where rects[i] = [ai, bi, xi, yi] indicates that (ai, bi) is the bottom-left corner point of the i^th rectangle and (xi, yi) is the top-right corner point of the i^th rectangle. Design an algorithm to pick a random integer point inside the space covered by one of the given rectangles. A point on the perimeter of a rectangle is included in the space covered by the rectangle.\nAny integer point inside the space covered by one of the given rectangles should be equally likely to be returned.\nNote that an integer point is a point that has integer coordinates.\nImplement the Solution class:\n\nSolution(int[][] rects) Initializes the object with the given rectangles rects.\nint[] pick() Returns a random integer point [u, v] inside the space covered by one of the given rectangles.", + "examples": [ + "Example 1:\nInput\n[\"Solution\", \"pick\", \"pick\", \"pick\", \"pick\", \"pick\"]\n[[[[-2, -2, 1, 1], [2, 2, 4, 6]]], [], [], [], [], []]\nOutput\n[null, [1, -2], [1, -1], [-1, -2], [-2, -2], [0, 0]]\n\nExplanation\nSolution solution = new Solution([[-2, -2, 1, 1], [2, 2, 4, 6]]);\nsolution.pick(); // return [1, -2]\nsolution.pick(); // return [1, -1]\nsolution.pick(); // return [-1, -2]\nsolution.pick(); // return [-2, -2]\nsolution.pick(); // return [0, 0]" + ], + "constraints": "Constraints:\n\n1 <= rects.length <= 100\nrects[i].length == 4\n-10^9 <= ai < xi <= 10^9\n-10^9 <= bi < yi <= 10^9\nxi - ai <= 2000\nyi - bi <= 2000\nAll the rectangles do not overlap.\nAt most 10^4 calls will be made to pick.", + "tags": [ + "Array", + "Math", + "Binary Search", + "Reservoir Sampling", + "Prefix Sum", + "Ordered Set", + "Randomized" + ], + "title-slug": "random-point-in-non-overlapping-rectangles" + }, + { + "leetcode-id": 498, + "title": "Diagonal Traverse", + "difficulty": 2, + "description": "Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order.", + "examples": [ + "Example 1:\nInput: mat = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [1,2,4,7,5,3,6,8,9]", + "Example 2:\nInput: mat = [[1,2],[3,4]]\nOutput: [1,2,3,4]" + ], + "constraints": "Constraints:\n\nm == mat.length\nn == mat[i].length\n1 <= m, n <= 10^4\n1 <= m * n <= 10^4\n-10^5 <= mat[i][j] <= 10^5", + "tags": [ + "Array", + "Matrix", + "Simulation" + ], + "title-slug": "diagonal-traverse" + }, + { + "leetcode-id": 500, + "title": "Keyboard Row", + "difficulty": 1, + "description": "Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.\nIn the American keyboard:\n\nthe first row consists of the characters \"qwertyuiop\",\nthe second row consists of the characters \"asdfghjkl\", and\nthe third row consists of the characters \"zxcvbnm\".", + "examples": [ + "Example 1:\nInput: words = [\"Hello\",\"Alaska\",\"Dad\",\"Peace\"]\nOutput: [\"Alaska\",\"Dad\"]", + "Example 2:\nInput: words = [\"omk\"]\nOutput: []", + "Example 3:\nInput: words = [\"adsdf\",\"sfd\"]\nOutput: [\"adsdf\",\"sfd\"]" + ], + "constraints": "Constraints:\n\n1 <= words.length <= 20\n1 <= words[i].length <= 100\nwords[i] consists of English letters (both lowercase and uppercase).", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "keyboard-row" + }, + { + "leetcode-id": 501, + "title": "Find Mode in Binary Search Tree", + "difficulty": 1, + "description": "Given the root of a binary search tree (BST) with duplicates, return all the mode(s) (i.e., the most frequently occurred element) in it.\nIf the tree has more than one mode, return them in any order.\nAssume a BST is defined as follows:\n\nThe left subtree of a node contains only nodes with keys less than or equal to the node's key.\nThe right subtree of a node contains only nodes with keys greater than or equal to the node's key.\nBoth the left and right subtrees must also be binary search trees.", + "examples": [ + "Example 1:\nInput: root = [1,null,2,2]\nOutput: [2]", + "Example 2:\nInput: root = [0]\nOutput: [0]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n-10^5 <= Node.val <= 10^5\n\n\u00a0\nFollow up: Could you do that without using any extra space? (Assume that the implicit stack space incurred due to recursion does not count).", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "find-mode-in-binary-search-tree" + }, + { + "leetcode-id": 502, + "title": "IPO", + "difficulty": 3, + "description": "Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before the IPO. Since it has limited resources, it can only finish at most k distinct projects before the IPO. Help LeetCode design the best way to maximize its total capital after finishing at most k distinct projects.\nYou are given n projects where the i^th project has a pure profit profits[i] and a minimum capital of capital[i] is needed to start it.\nInitially, you have w capital. When you finish a project, you will obtain its pure profit and the profit will be added to your total capital.\nPick a list of at most k distinct projects from given projects to maximize your final capital, and return the final maximized capital.\nThe answer is guaranteed to fit in a 32-bit signed integer.", + "examples": [ + "Example 1:\nInput: k = 2, w = 0, profits = [1,2,3], capital = [0,1,1]\nOutput: 4\nExplanation: Since your initial capital is 0, you can only start the project indexed 0.\nAfter finishing it you will obtain profit 1 and your capital becomes 1.\nWith capital 1, you can either start the project indexed 1 or the project indexed 2.\nSince you can choose at most 2 projects, you need to finish the project indexed 2 to get the maximum capital.\nTherefore, output the final maximized capital, which is 0 + 1 + 3 = 4.", + "Example 2:\nInput: k = 3, w = 0, profits = [1,2,3], capital = [0,1,2]\nOutput: 6" + ], + "constraints": "Constraints:\n\n1 <= k <= 10^5\n0 <= w <= 10^9\nn == profits.length\nn == capital.length\n1 <= n <= 10^5\n0 <= profits[i] <= 10^4\n0 <= capital[i] <= 10^9", + "tags": [ + "Array", + "Greedy", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "ipo" + }, + { + "leetcode-id": 503, + "title": "Next Greater Element II", + "difficulty": 2, + "description": "Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums.\nThe next greater number of a number x is the first greater number to its traversing-order next in the array, which means you could search circularly to find its next greater number. If it doesn't exist, return -1 for this number.", + "examples": [ + "Example 1:\nInput: nums = [1,2,1]\nOutput: [2,-1,2]\nExplanation: The first 1's next greater number is 2; \nThe number 2 can't find next greater number. \nThe second 1's next greater number needs to search circularly, which is also 2.", + "Example 2:\nInput: nums = [1,2,3,4,3]\nOutput: [2,3,4,-1,4]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-10^9 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Stack", + "Monotonic Stack" + ], + "title-slug": "next-greater-element-ii" + }, + { + "leetcode-id": 504, + "title": "Base 7", + "difficulty": 1, + "description": "Given an integer num, return a string of its base 7 representation.", + "examples": [ + "Example 1:\nInput: num = 100\nOutput: \"202\"", + "Example 2:\nInput: num = -7\nOutput: \"-10\"" + ], + "constraints": "Constraints:\n\n-10^7 <= num <= 10^7", + "tags": [ + "Math" + ], + "title-slug": "base-7" + }, + { + "leetcode-id": 506, + "title": "Relative Ranks", + "difficulty": 1, + "description": "You are given an integer array score of size n, where score[i] is the score of the i^th athlete in a competition. All the scores are guaranteed to be unique.\nThe athletes are placed based on their scores, where the 1^st place athlete has the highest score, the 2^nd place athlete has the 2^nd highest score, and so on. The placement of each athlete determines their rank:\n\nThe 1^st place athlete's rank is \"Gold Medal\".\nThe 2^nd place athlete's rank is \"Silver Medal\".\nThe 3^rd place athlete's rank is \"Bronze Medal\".\nFor the 4^th place to the n^th place athlete, their rank is their placement number (i.e., the x^th place athlete's rank is \"x\").\n\nReturn an array answer of size n where answer[i] is the rank of the i^th athlete.", + "examples": [ + "Example 1:\nInput: score = [5,4,3,2,1]\nOutput: [\"Gold Medal\",\"Silver Medal\",\"Bronze Medal\",\"4\",\"5\"]\nExplanation: The placements are [1^st, 2^nd, 3^rd, 4^th, 5^th].", + "Example 2:\nInput: score = [10,3,8,9,4]\nOutput: [\"Gold Medal\",\"5\",\"Bronze Medal\",\"Silver Medal\",\"4\"]\nExplanation: The placements are [1^st, 5^th, 3^rd, 2^nd, 4^th]." + ], + "constraints": "Constraints:\n\nn == score.length\n1 <= n <= 10^4\n0 <= score[i] <= 10^6\nAll the values in score are unique.", + "tags": [ + "Array", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "relative-ranks" + }, + { + "leetcode-id": 507, + "title": "Perfect Number", + "difficulty": 1, + "description": "A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly.\nGiven an integer n, return true if n is a perfect number, otherwise return false.", + "examples": [ + "Example 1:\nInput: num = 28\nOutput: true\nExplanation: 28 = 1 + 2 + 4 + 7 + 14\n1, 2, 4, 7, and 14 are all divisors of 28.", + "Example 2:\nInput: num = 7\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= num <= 10^8", + "tags": [ + "Math" + ], + "title-slug": "perfect-number" + }, + { + "leetcode-id": 508, + "title": "Most Frequent Subtree Sum", + "difficulty": 2, + "description": "Given the root of a binary tree, return the most frequent subtree sum. If there is a tie, return all the values with the highest frequency in any order.\nThe subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (including the node itself).", + "examples": [ + "Example 1:\nInput: root = [5,2,-3]\nOutput: [2,-3,4]", + "Example 2:\nInput: root = [5,2,-5]\nOutput: [2]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n-10^5 <= Node.val <= 10^5", + "tags": [ + "Hash Table", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "most-frequent-subtree-sum" + }, + { + "leetcode-id": 509, + "title": "Fibonacci Number", + "difficulty": 1, + "description": "The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,\n\nF(0) = 0, F(1) = 1\nF(n) = F(n - 1) + F(n - 2), for n > 1.\n\nGiven n, calculate F(n).", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: 1\nExplanation: F(2) = F(1) + F(0) = 1 + 0 = 1.", + "Example 2:\nInput: n = 3\nOutput: 2\nExplanation: F(3) = F(2) + F(1) = 1 + 1 = 2.", + "Example 3:\nInput: n = 4\nOutput: 3\nExplanation: F(4) = F(3) + F(2) = 2 + 1 = 3." + ], + "constraints": "Constraints:\n\n0 <= n <= 30", + "tags": [ + "Math", + "Dynamic Programming", + "Recursion", + "Memoization" + ], + "title-slug": "fibonacci-number" + }, + { + "leetcode-id": 513, + "title": "Find Bottom Left Tree Value", + "difficulty": 2, + "description": "Given the root of a binary tree, return the leftmost value in the last row of the tree.", + "examples": [ + "Example 1:\nInput: root = [2,1,3]\nOutput: 1", + "Example 2:\nInput: root = [1,2,3,4,null,5,6,null,null,7]\nOutput: 7" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n-2^31 <= Node.val <= 2^31 - 1", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "find-bottom-left-tree-value" + }, + { + "leetcode-id": 514, + "title": "Freedom Trail", + "difficulty": 3, + "description": "In the video game Fallout 4, the quest \"Road to Freedom\" requires players to reach a metal dial called the \"Freedom Trail Ring\" and use the dial to spell a specific keyword to open the door.\nGiven a string ring that represents the code engraved on the outer ring and another string key that represents the keyword that needs to be spelled, return the minimum number of steps to spell all the characters in the keyword.\nInitially, the first character of the ring is aligned at the \"12:00\" direction. You should spell all the characters in key one by one by rotating ring clockwise or anticlockwise to make each character of the string key aligned at the \"12:00\" direction and then by pressing the center button.\nAt the stage of rotating the ring to spell the key character key[i]:\n\nYou can rotate the ring clockwise or anticlockwise by one place, which counts as one step. The final purpose of the rotation is to align one of ring's characters at the \"12:00\" direction, where this character must equal key[i].\nIf the character key[i] has been aligned at the \"12:00\" direction, press the center button to spell, which also counts as one step. After the pressing, you could begin to spell the next character in the key (next stage). Otherwise, you have finished all the spelling.", + "examples": [ + "Example 1:\nInput: ring = \"godding\", key = \"gd\"\nOutput: 4\nExplanation:\nFor the first key character 'g', since it is already in place, we just need 1 step to spell this character. \nFor the second key character 'd', we need to rotate the ring \"godding\" anticlockwise by two steps to make it become \"ddinggo\".\nAlso, we need 1 more step for spelling.\nSo the final output is 4.", + "Example 2:\nInput: ring = \"godding\", key = \"godding\"\nOutput: 13" + ], + "constraints": "Constraints:\n\n1 <= ring.length, key.length <= 100\nring and key consist of only lower case English letters.\nIt is guaranteed that key could always be spelled by rotating ring.", + "tags": [ + "String", + "Dynamic Programming", + "Depth-First Search", + "Breadth-First Search" + ], + "title-slug": "freedom-trail" + }, + { + "leetcode-id": 515, + "title": "Find Largest Value in Each Tree Row", + "difficulty": 2, + "description": "Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed).", + "examples": [ + "Example 1:\nInput: root = [1,3,2,5,3,null,9]\nOutput: [1,3,9]", + "Example 2:\nInput: root = [1,2,3]\nOutput: [1,3]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree will be in the range [0, 10^4].\n-2^31 <= Node.val <= 2^31 - 1", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "find-largest-value-in-each-tree-row" + }, + { + "leetcode-id": 516, + "title": "Longest Palindromic Subsequence", + "difficulty": 2, + "description": "Given a string s, find the longest palindromic subsequence's length in s.\nA subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.", + "examples": [ + "Example 1:\nInput: s = \"bbbab\"\nOutput: 4\nExplanation: One possible longest palindromic subsequence is \"bbbb\".", + "Example 2:\nInput: s = \"cbbd\"\nOutput: 2\nExplanation: One possible longest palindromic subsequence is \"bb\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns consists only of lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "longest-palindromic-subsequence" + }, + { + "leetcode-id": 517, + "title": "Super Washing Machines", + "difficulty": 3, + "description": "You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty.\nFor each move, you could choose any m (1 <= m <= n) washing machines, and pass one dress of each washing machine to one of its adjacent washing machines at the same time.\nGiven an integer array machines representing the number of dresses in each washing machine from left to right on the line, return the minimum number of moves to make all the washing machines have the same number of dresses. If it is not possible to do it, return -1.", + "examples": [ + "Example 1:\nInput: machines = [1,0,5]\nOutput: 3\nExplanation:\n1st move: 1 0 <-- 5 => 1 1 4\n2nd move: 1 <-- 1 <-- 4 => 2 1 3\n3rd move: 2 1 <-- 3 => 2 2 2", + "Example 2:\nInput: machines = [0,3,0]\nOutput: 2\nExplanation:\n1st move: 0 <-- 3 0 => 1 2 0\n2nd move: 1 2 --> 0 => 1 1 1", + "Example 3:\nInput: machines = [0,2,0]\nOutput: -1\nExplanation:\nIt's impossible to make all three washing machines have the same number of dresses." + ], + "constraints": "Constraints:\n\nn == machines.length\n1 <= n <= 10^4\n0 <= machines[i] <= 10^5", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "super-washing-machines" + }, + { + "leetcode-id": 518, + "title": "Coin Change II", + "difficulty": 2, + "description": "You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.\nReturn the number of combinations that make up that amount. If that amount of money cannot be made up by any combination of the coins, return 0.\nYou may assume that you have an infinite number of each kind of coin.\nThe answer is guaranteed to fit into a signed 32-bit integer.", + "examples": [ + "Example 1:\nInput: amount = 5, coins = [1,2,5]\nOutput: 4\nExplanation: there are four ways to make up the amount:\n5=5\n5=2+2+1\n5=2+1+1+1\n5=1+1+1+1+1", + "Example 2:\nInput: amount = 3, coins = [2]\nOutput: 0\nExplanation: the amount of 3 cannot be made up just with coins of 2.", + "Example 3:\nInput: amount = 10, coins = [10]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= coins.length <= 300\n1 <= coins[i] <= 5000\nAll the values of coins are unique.\n0 <= amount <= 5000", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "coin-change-ii" + }, + { + "leetcode-id": 519, + "title": "Random Flip Matrix", + "difficulty": 2, + "description": "There is an m x n binary grid matrix with all the values set 0 initially. Design an algorithm to randomly pick an index (i, j) where matrix[i][j] == 0 and flips it to 1. All the indices (i, j) where matrix[i][j] == 0 should be equally likely to be returned.\nOptimize your algorithm to minimize the number of calls made to the built-in random function of your language and optimize the time and space complexity.\nImplement the Solution class:\n\nSolution(int m, int n) Initializes the object with the size of the binary matrix m and n.\nint[] flip() Returns a random index [i, j] of the matrix where matrix[i][j] == 0 and flips it to 1.\nvoid reset() Resets all the values of the matrix to be 0.", + "examples": [ + "Example 1:\nInput\n[\"Solution\", \"flip\", \"flip\", \"flip\", \"reset\", \"flip\"]\n[[3, 1], [], [], [], [], []]\nOutput\n[null, [1, 0], [2, 0], [0, 0], null, [2, 0]]\n\nExplanation\nSolution solution = new Solution(3, 1);\nsolution.flip(); // return [1, 0], [0,0], [1,0], and [2,0] should be equally likely to be returned.\nsolution.flip(); // return [2, 0], Since [1,0] was returned, [2,0] and [0,0]\nsolution.flip(); // return [0, 0], Based on the previously returned indices, only [0,0] can be returned.\nsolution.reset(); // All the values are reset to 0 and can be returned.\nsolution.flip(); // return [2, 0], [0,0], [1,0], and [2,0] should be equally likely to be returned." + ], + "constraints": "Constraints:\n\n1 <= m, n <= 10^4\nThere will be at least one free cell for each call to flip.\nAt most 1000 calls will be made to flip and reset.", + "tags": [ + "Hash Table", + "Math", + "Reservoir Sampling", + "Randomized" + ], + "title-slug": "random-flip-matrix" + }, + { + "leetcode-id": 520, + "title": "Detect Capital", + "difficulty": 1, + "description": "We define the usage of capitals in a word to be right when one of the following cases holds:\n\nAll letters in this word are capitals, like \"USA\".\nAll letters in this word are not capitals, like \"leetcode\".\nOnly the first letter in this word is capital, like \"Google\".\n\nGiven a string word, return true if the usage of capitals in it is right.", + "examples": [ + "Example 1:\nInput: word = \"USA\"\nOutput: true", + "Example 2:\nInput: word = \"FlaG\"\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= word.length <= 100\nword consists of lowercase and uppercase English letters.", + "tags": [ + "String" + ], + "title-slug": "detect-capital" + }, + { + "leetcode-id": 521, + "title": "Longest Uncommon Subsequence I", + "difficulty": 1, + "description": "Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If the longest uncommon subsequence does not exist, return -1.\nAn uncommon subsequence between two strings is a string that is a subsequence of one but not the other.\nA subsequence of a string s is a string that can be obtained after deleting any number of characters from s.\n\nFor example, \"abc\" is a subsequence of \"aebdc\" because you can delete the underlined characters in \"aebdc\" to get \"abc\". Other subsequences of \"aebdc\" include \"aebdc\", \"aeb\", and \"\" (empty string).", + "examples": [ + "Example 1:\nInput: a = \"aba\", b = \"cdc\"\nOutput: 3\nExplanation: One longest uncommon subsequence is \"aba\" because \"aba\" is a subsequence of \"aba\" but not \"cdc\".\nNote that \"cdc\" is also a longest uncommon subsequence.", + "Example 2:\nInput: a = \"aaa\", b = \"bbb\"\nOutput: 3\nExplanation:\u00a0The longest uncommon subsequences are \"aaa\" and \"bbb\".", + "Example 3:\nInput: a = \"aaa\", b = \"aaa\"\nOutput: -1\nExplanation:\u00a0Every subsequence of string a is also a subsequence of string b. Similarly, every subsequence of string b is also a subsequence of string a." + ], + "constraints": "Constraints:\n\n1 <= a.length, b.length <= 100\na and b consist of lower-case English letters.", + "tags": [ + "String" + ], + "title-slug": "longest-uncommon-subsequence-i" + }, + { + "leetcode-id": 522, + "title": "Longest Uncommon Subsequence II", + "difficulty": 2, + "description": "Given an array of strings strs, return the length of the longest uncommon subsequence between them. If the longest uncommon subsequence does not exist, return -1.\nAn uncommon subsequence between an array of strings is a string that is a subsequence of one string but not the others.\nA subsequence of a string s is a string that can be obtained after deleting any number of characters from s.\n\nFor example, \"abc\" is a subsequence of \"aebdc\" because you can delete the underlined characters in \"aebdc\" to get \"abc\". Other subsequences of \"aebdc\" include \"aebdc\", \"aeb\", and \"\" (empty string).", + "examples": [ + "Example 1:\nInput: strs = [\"aba\",\"cdc\",\"eae\"]\nOutput: 3", + "Example 2:\nInput: strs = [\"aaa\",\"aaa\",\"aa\"]\nOutput: -1" + ], + "constraints": "Constraints:\n\n2 <= strs.length <= 50\n1 <= strs[i].length <= 10\nstrs[i] consists of lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "Two Pointers", + "String", + "Sorting" + ], + "title-slug": "longest-uncommon-subsequence-ii" + }, + { + "leetcode-id": 523, + "title": "Continuous Subarray Sum", + "difficulty": 2, + "description": "Given an integer array nums and an integer k, return true if nums has a good subarray or false otherwise.\nA good subarray is a subarray where:\n\nits length is at least two, and\nthe sum of the elements of the subarray is a multiple of k.\n\nNote that:\n\nA subarray is a contiguous part of the array.\nAn integer x is a multiple of k if there exists an integer n such that x = n * k. 0 is always a multiple of k.", + "examples": [ + "Example 1:\nInput: nums = [23,2,4,6,7], k = 6\nOutput: true\nExplanation: [2, 4] is a continuous subarray of size 2 whose elements sum up to 6.", + "Example 2:\nInput: nums = [23,2,6,4,7], k = 6\nOutput: true\nExplanation: [23, 2, 6, 4, 7] is an continuous subarray of size 5 whose elements sum up to 42.\n42 is a multiple of 6 because 42 = 7 * 6 and 7 is an integer.", + "Example 3:\nInput: nums = [23,2,6,4,7], k = 13\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^9\n0 <= sum(nums[i]) <= 2^31 - 1\n1 <= k <= 2^31 - 1", + "tags": [ + "Array", + "Hash Table", + "Math", + "Prefix Sum" + ], + "title-slug": "continuous-subarray-sum" + }, + { + "leetcode-id": 524, + "title": "Longest Word in Dictionary through Deleting", + "difficulty": 2, + "description": "Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. If there is more than one possible result, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string.", + "examples": [ + "Example 1:\nInput: s = \"abpcplea\", dictionary = [\"ale\",\"apple\",\"monkey\",\"plea\"]\nOutput: \"apple\"", + "Example 2:\nInput: s = \"abpcplea\", dictionary = [\"a\",\"b\",\"c\"]\nOutput: \"a\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\n1 <= dictionary.length <= 1000\n1 <= dictionary[i].length <= 1000\ns and dictionary[i] consist of lowercase English letters.", + "tags": [ + "Array", + "Two Pointers", + "String", + "Sorting" + ], + "title-slug": "longest-word-in-dictionary-through-deleting" + }, + { + "leetcode-id": 525, + "title": "Contiguous Array", + "difficulty": 2, + "description": "Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1.", + "examples": [ + "Example 1:\nInput: nums = [0,1]\nOutput: 2\nExplanation: [0, 1] is the longest contiguous subarray with an equal number of 0 and 1.", + "Example 2:\nInput: nums = [0,1,0]\nOutput: 2\nExplanation: [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\nnums[i] is either 0 or 1.", + "tags": [ + "Array", + "Hash Table", + "Prefix Sum" + ], + "title-slug": "contiguous-array" + }, + { + "leetcode-id": 526, + "title": "Beautiful Arrangement", + "difficulty": 2, + "description": "Suppose you have n integers labeled 1 through n. A permutation of those n integers perm (1-indexed) is considered a beautiful arrangement if for every i (1 <= i <= n), either of the following is true:\n\nperm[i] is divisible by i.\ni is divisible by perm[i].\n\nGiven an integer n, return the number of the beautiful arrangements that you can construct.", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: 2\nExplanation: \nThe first beautiful arrangement is [1,2]:\n - perm[1] = 1 is divisible by i = 1\n - perm[2] = 2 is divisible by i = 2\nThe second beautiful arrangement is [2,1]:\n - perm[1] = 2 is divisible by i = 1\n - i = 2 is divisible by perm[2] = 1", + "Example 2:\nInput: n = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= n <= 15", + "tags": [ + "Array", + "Dynamic Programming", + "Backtracking", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "beautiful-arrangement" + }, + { + "leetcode-id": 528, + "title": "Random Pick with Weight", + "difficulty": 2, + "description": "You are given a 0-indexed array of positive integers w where w[i] describes the weight of the i^th index.\nYou need to implement the function pickIndex(), which randomly picks an index in the range [0, w.length - 1] (inclusive) and returns it. The probability of picking an index i is w[i] / sum(w).\n\nFor example, if w = [1, 3], the probability of picking index 0 is 1 / (1 + 3) = 0.25 (i.e., 25%), and the probability of picking index 1 is 3 / (1 + 3) = 0.75 (i.e., 75%).", + "examples": [ + "Example 1:\nInput\n[\"Solution\",\"pickIndex\"]\n[[[1]],[]]\nOutput\n[null,0]\n\nExplanation\nSolution solution = new Solution([1]);\nsolution.pickIndex(); // return 0. The only option is to return 0 since there is only one element in w.", + "Example 2:\nInput\n[\"Solution\",\"pickIndex\",\"pickIndex\",\"pickIndex\",\"pickIndex\",\"pickIndex\"]\n[[[1,3]],[],[],[],[],[]]\nOutput\n[null,1,1,1,1,0]\n\nExplanation\nSolution solution = new Solution([1, 3]);\nsolution.pickIndex(); // return 1. It is returning the second element (index = 1) that has a probability of 3/4.\nsolution.pickIndex(); // return 1\nsolution.pickIndex(); // return 1\nsolution.pickIndex(); // return 1\nsolution.pickIndex(); // return 0. It is returning the first element (index = 0) that has a probability of 1/4.\n\nSince this is a randomization problem, multiple answers are allowed.\nAll of the following outputs can be considered correct:\n[null,1,1,1,1,0]\n[null,1,1,1,1,1]\n[null,1,1,1,0,0]\n[null,1,1,1,0,1]\n[null,1,0,1,0,0]\n......\nand so on." + ], + "constraints": "Constraints:\n\n1 <= w.length <= 10^4\n1 <= w[i] <= 10^5\npickIndex will be called at most 10^4 times.", + "tags": [ + "Array", + "Math", + "Binary Search", + "Prefix Sum", + "Randomized" + ], + "title-slug": "random-pick-with-weight" + }, + { + "leetcode-id": 529, + "title": "Minesweeper", + "difficulty": 2, + "description": "Let's play the minesweeper game (Wikipedia, online game)!\nYou are given an m x n char matrix board representing the game board where:\n\n'M' represents an unrevealed mine,\n'E' represents an unrevealed empty square,\n'B' represents a revealed blank square that has no adjacent mines (i.e., above, below, left, right, and all 4 diagonals),\ndigit ('1' to '8') represents how many mines are adjacent to this revealed square, and\n'X' represents a revealed mine.\n\nYou are also given an integer array click where click = [clickr, clickc] represents the next click position among all the unrevealed squares ('M' or 'E').\nReturn the board after revealing this position according to the following rules:\n\nIf a mine 'M' is revealed, then the game is over. You should change it to 'X'.\nIf an empty square 'E' with no adjacent mines is revealed, then change it to a revealed blank 'B' and all of its adjacent unrevealed squares should be revealed recursively.\nIf an empty square 'E' with at least one adjacent mine is revealed, then change it to a digit ('1' to '8') representing the number of adjacent mines.\nReturn the board when no more squares will be revealed.", + "examples": [ + "Example 1:\nInput: board = [[\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"M\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\"]], click = [3,0]\nOutput: [[\"B\",\"1\",\"E\",\"1\",\"B\"],[\"B\",\"1\",\"M\",\"1\",\"B\"],[\"B\",\"1\",\"1\",\"1\",\"B\"],[\"B\",\"B\",\"B\",\"B\",\"B\"]]", + "Example 2:\nInput: board = [[\"B\",\"1\",\"E\",\"1\",\"B\"],[\"B\",\"1\",\"M\",\"1\",\"B\"],[\"B\",\"1\",\"1\",\"1\",\"B\"],[\"B\",\"B\",\"B\",\"B\",\"B\"]], click = [1,2]\nOutput: [[\"B\",\"1\",\"E\",\"1\",\"B\"],[\"B\",\"1\",\"X\",\"1\",\"B\"],[\"B\",\"1\",\"1\",\"1\",\"B\"],[\"B\",\"B\",\"B\",\"B\",\"B\"]]" + ], + "constraints": "Constraints:\n\nm == board.length\nn == board[i].length\n1 <= m, n <= 50\nboard[i][j] is either 'M', 'E', 'B', or a digit from '1' to '8'.\nclick.length == 2\n0 <= clickr < m\n0 <= clickc < n\nboard[clickr][clickc] is either 'M' or 'E'.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "minesweeper" + }, + { + "leetcode-id": 530, + "title": "Minimum Absolute Difference in BST", + "difficulty": 1, + "description": "Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.", + "examples": [ + "Example 1:\nInput: root = [4,2,6,1,3]\nOutput: 1", + "Example 2:\nInput: root = [1,0,48,null,null,12,49]\nOutput: 1" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [2, 10^4].\n0 <= Node.val <= 10^5\n\n\u00a0\nNote: This question is the same as 783: https://leetcode.com/problems/minimum-distance-between-bst-nodes/", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "minimum-absolute-difference-in-bst" + }, + { + "leetcode-id": 532, + "title": "K-diff Pairs in an Array", + "difficulty": 2, + "description": "Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array.\nA k-diff pair is an integer pair (nums[i], nums[j]), where the following are true:\n\n0 <= i, j < nums.length\ni != j\n|nums[i] - nums[j]| == k\n\nNotice that |val| denotes the absolute value of val.", + "examples": [ + "Example 1:\nInput: nums = [3,1,4,1,5], k = 2\nOutput: 2\nExplanation: There are two 2-diff pairs in the array, (1, 3) and (3, 5).\nAlthough we have two 1s in the input, we should only return the number of unique pairs.", + "Example 2:\nInput: nums = [1,2,3,4,5], k = 1\nOutput: 4\nExplanation: There are four 1-diff pairs in the array, (1, 2), (2, 3), (3, 4) and (4, 5).", + "Example 3:\nInput: nums = [1,3,1,5,4], k = 0\nOutput: 1\nExplanation: There is one 0-diff pair in the array, (1, 1)." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-10^7 <= nums[i] <= 10^7\n0 <= k <= 10^7", + "tags": [ + "Array", + "Hash Table", + "Two Pointers", + "Binary Search", + "Sorting" + ], + "title-slug": "k-diff-pairs-in-an-array" + }, + { + "leetcode-id": 535, + "title": "Encode and Decode TinyURL", + "difficulty": 2, + "description": "Note: This is a companion problem to the System Design problem: Design TinyURL.\nTinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk. Design a class to encode a URL and decode a tiny URL.\nThere is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL.\nImplement the Solution class:\n\nSolution() Initializes the object of the system.\nString encode(String longUrl) Returns a tiny URL for the given longUrl.\nString decode(String shortUrl) Returns the original long URL for the given shortUrl. It is guaranteed that the given shortUrl was encoded by the same object.", + "examples": [ + "Example 1:\nInput: url = \"https://leetcode.com/problems/design-tinyurl\"\nOutput: \"https://leetcode.com/problems/design-tinyurl\"\n\nExplanation:\nSolution obj = new Solution();\nstring tiny = obj.encode(url); // returns the encoded tiny url.\nstring ans = obj.decode(tiny); // returns the original url after decoding it." + ], + "constraints": "Constraints:\n\n1 <= url.length <= 10^4\nurl is guranteed to be a valid URL.", + "tags": [ + "Hash Table", + "String", + "Design", + "Hash Function" + ], + "title-slug": "encode-and-decode-tinyurl" + }, + { + "leetcode-id": 537, + "title": "Complex Number Multiplication", + "difficulty": 2, + "description": "A complex number can be represented as a string on the form \"real+imaginaryi\" where:\n\nreal is the real part and is an integer in the range [-100, 100].\nimaginary is the imaginary part and is an integer in the range [-100, 100].\ni^2 == -1.\n\nGiven two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplications.", + "examples": [ + "Example 1:\nInput: num1 = \"1+1i\", num2 = \"1+1i\"\nOutput: \"0+2i\"\nExplanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.", + "Example 2:\nInput: num1 = \"1+-1i\", num2 = \"1+-1i\"\nOutput: \"0+-2i\"\nExplanation: (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i, and you need convert it to the form of 0+-2i." + ], + "constraints": "Constraints:\n\nnum1 and num2 are valid complex numbers.", + "tags": [ + "Math", + "String", + "Simulation" + ], + "title-slug": "complex-number-multiplication" + }, + { + "leetcode-id": 538, + "title": "Convert BST to Greater Tree", + "difficulty": 2, + "description": "Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.\nAs a reminder, a binary search tree is a tree that satisfies these constraints:\n\nThe left subtree of a node contains only nodes with keys less than the node's key.\nThe right subtree of a node contains only nodes with keys greater than the node's key.\nBoth the left and right subtrees must also be binary search trees.", + "examples": [ + "Example 1:\nInput: root = [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]\nOutput: [30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]", + "Example 2:\nInput: root = [0,null,1]\nOutput: [1,null,1]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 10^4].\n-10^4 <= Node.val <= 10^4\nAll the values in the tree are unique.\nroot is guaranteed to be a valid binary search tree.\n\n\u00a0\nNote: This question is the same as 1038: https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree/", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "convert-bst-to-greater-tree" + }, + { + "leetcode-id": 539, + "title": "Minimum Time Difference", + "difficulty": 2, + "description": "Given a list of 24-hour clock time points in \"HH:MM\" format, return the minimum minutes difference between any two time-points in the list.", + "examples": [ + "Example 1:\nInput: timePoints = [\"23:59\",\"00:00\"]\nOutput: 1", + "Example 2:\nInput: timePoints = [\"00:00\",\"23:59\",\"00:00\"]\nOutput: 0" + ], + "constraints": "Constraints:\n\n2 <= timePoints.length <= 2 * 10^4\ntimePoints[i] is in the format \"HH:MM\".", + "tags": [ + "Array", + "Math", + "String", + "Sorting" + ], + "title-slug": "minimum-time-difference" + }, + { + "leetcode-id": 540, + "title": "Single Element in a Sorted Array", + "difficulty": 2, + "description": "You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once.\nReturn the single element that appears only once.\nYour solution must run in O(log n) time and O(1) space.", + "examples": [ + "Example 1:\nInput: nums = [1,1,2,3,3,4,4,8,8]\nOutput: 2", + "Example 2:\nInput: nums = [3,3,7,7,10,11,11]\nOutput: 10" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "single-element-in-a-sorted-array" + }, + { + "leetcode-id": 541, + "title": "Reverse String II", + "difficulty": 1, + "description": "Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string.\nIf there are fewer than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and leave the other as original.", + "examples": [ + "Example 1:\nInput: s = \"abcdefg\", k = 2\nOutput: \"bacdfeg\"", + "Example 2:\nInput: s = \"abcd\", k = 2\nOutput: \"bacd\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^4\ns consists of only lowercase English letters.\n1 <= k <= 10^4", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "reverse-string-ii" + }, + { + "leetcode-id": 542, + "title": "01 Matrix", + "difficulty": 2, + "description": "Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell.\nThe distance between two adjacent cells is 1.", + "examples": [ + "Example 1:\nInput: mat = [[0,0,0],[0,1,0],[0,0,0]]\nOutput: [[0,0,0],[0,1,0],[0,0,0]]", + "Example 2:\nInput: mat = [[0,0,0],[0,1,0],[1,1,1]]\nOutput: [[0,0,0],[0,1,0],[1,2,1]]" + ], + "constraints": "Constraints:\n\nm == mat.length\nn == mat[i].length\n1 <= m, n <= 10^4\n1 <= m * n <= 10^4\nmat[i][j] is either 0 or 1.\nThere is at least one 0 in mat.", + "tags": [ + "Array", + "Dynamic Programming", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "01-matrix" + }, + { + "leetcode-id": 543, + "title": "Diameter of Binary Tree", + "difficulty": 1, + "description": "Given the root of a binary tree, return the length of the diameter of the tree.\nThe diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root.\nThe length of a path between two nodes is represented by the number of edges between them.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,4,5]\nOutput: 3\nExplanation: 3 is the length of the path [4,2,1,3] or [5,2,1,3].", + "Example 2:\nInput: root = [1,2]\nOutput: 1" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n-100 <= Node.val <= 100", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "diameter-of-binary-tree" + }, + { + "leetcode-id": 546, + "title": "Remove Boxes", + "difficulty": 3, + "description": "You are given several boxes with different colors represented by different positive numbers.\nYou may experience several rounds to remove boxes until there is no box left. Each time you can choose some continuous boxes with the same color (i.e., composed of k boxes, k >= 1), remove them and get k * k points.\nReturn the maximum points you can get.", + "examples": [ + "Example 1:\nInput: boxes = [1,3,2,2,2,3,4,3,1]\nOutput: 23\nExplanation:\n[1, 3, 2, 2, 2, 3, 4, 3, 1] \n----> [1, 3, 3, 4, 3, 1] (3*3=9 points) \n----> [1, 3, 3, 3, 1] (1*1=1 points) \n----> [1, 1] (3*3=9 points) \n----> [] (2*2=4 points)", + "Example 2:\nInput: boxes = [1,1,1]\nOutput: 9", + "Example 3:\nInput: boxes = [1]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= boxes.length <= 100\n1 <= boxes[i]\u00a0<= 100", + "tags": [ + "Array", + "Dynamic Programming", + "Memoization" + ], + "title-slug": "remove-boxes" + }, + { + "leetcode-id": 547, + "title": "Number of Provinces", + "difficulty": 2, + "description": "There are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly with city c, then city a is connected indirectly with city c.\nA province is a group of directly or indirectly connected cities and no other cities outside of the group.\nYou are given an n x n matrix isConnected where isConnected[i][j] = 1 if the i^th city and the j^th city are directly connected, and isConnected[i][j] = 0 otherwise.\nReturn the total number of provinces.", + "examples": [ + "Example 1:\nInput: isConnected = [[1,1,0],[1,1,0],[0,0,1]]\nOutput: 2", + "Example 2:\nInput: isConnected = [[1,0,0],[0,1,0],[0,0,1]]\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= n <= 200\nn == isConnected.length\nn == isConnected[i].length\nisConnected[i][j] is 1 or 0.\nisConnected[i][i] == 1\nisConnected[i][j] == isConnected[j][i]", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Graph" + ], + "title-slug": "number-of-provinces" + }, + { + "leetcode-id": 551, + "title": "Student Attendance Record I", + "difficulty": 1, + "description": "You are given a string s representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:\n\n'A': Absent.\n'L': Late.\n'P': Present.\n\nThe student is eligible for an attendance award if they meet both of the following criteria:\n\nThe student was absent ('A') for strictly fewer than 2 days total.\nThe student was never late ('L') for 3 or more consecutive days.\n\nReturn true if the student is eligible for an attendance award, or false otherwise.", + "examples": [ + "Example 1:\nInput: s = \"PPALLP\"\nOutput: true\nExplanation: The student has fewer than 2 absences and was never late 3 or more consecutive days.", + "Example 2:\nInput: s = \"PPALLL\"\nOutput: false\nExplanation: The student was late 3 consecutive days in the last 3 days, so is not eligible for the award." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns[i] is either 'A', 'L', or 'P'.", + "tags": [ + "String" + ], + "title-slug": "student-attendance-record-i" + }, + { + "leetcode-id": 552, + "title": "Student Attendance Record II", + "difficulty": 3, + "description": "An attendance record for a student can be represented as a string where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:\n\n'A': Absent.\n'L': Late.\n'P': Present.\n\nAny student is eligible for an attendance award if they meet both of the following criteria:\n\nThe student was absent ('A') for strictly fewer than 2 days total.\nThe student was never late ('L') for 3 or more consecutive days.\n\nGiven an integer n, return the number of possible attendance records of length n that make a student eligible for an attendance award. The answer may be very large, so return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: 8\nExplanation: There are 8 records with length 2 that are eligible for an award:\n\"PP\", \"AP\", \"PA\", \"LP\", \"PL\", \"AL\", \"LA\", \"LL\"\nOnly \"AA\" is not eligible because there are 2 absences (there need to be fewer than 2).", + "Example 2:\nInput: n = 1\nOutput: 3", + "Example 3:\nInput: n = 10101\nOutput: 183236316" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "student-attendance-record-ii" + }, + { + "leetcode-id": 553, + "title": "Optimal Division", + "difficulty": 2, + "description": "You are given an integer array nums. The adjacent integers in nums will perform the float division.\n\nFor example, for nums = [2,3,4], we will evaluate the expression \"2/3/4\".\n\nHowever, you can add any number of parenthesis at any position to change the priority of operations. You want to add these parentheses such the value of the expression after the evaluation is maximum.\nReturn the corresponding expression that has the maximum value in string format.\nNote: your expression should not contain redundant parenthesis.", + "examples": [ + "Example 1:\nInput: nums = [1000,100,10,2]\nOutput: \"1000/(100/10/2)\"\nExplanation: 1000/(100/10/2) = 1000/((100/10)/2) = 200\nHowever, the bold parenthesis in \"1000/((100/10)/2)\" are redundant since they do not influence the operation priority.\nSo you should return \"1000/(100/10/2)\".\nOther cases:\n1000/(100/10)/2 = 50\n1000/(100/(10/2)) = 50\n1000/100/10/2 = 0.5\n1000/100/(10/2) = 2", + "Example 2:\nInput: nums = [2,3,4]\nOutput: \"2/(3/4)\"\nExplanation: (2/(3/4)) = 8/3 = 2.667\nIt can be shown that after trying all possibilities, we cannot get an expression with evaluation greater than 2.667" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10\n2 <= nums[i] <= 1000\nThere is only one optimal division for the given input.", + "tags": [ + "Array", + "Math", + "Dynamic Programming" + ], + "title-slug": "optimal-division" + }, + { + "leetcode-id": 554, + "title": "Brick Wall", + "difficulty": 2, + "description": "There is a rectangular brick wall in front of you with n rows of bricks. The i^th row has some number of bricks each of the same height (i.e., one unit) but they can be of different widths. The total width of each row is the same.\nDraw a vertical line from the top to the bottom and cross the least bricks. If your line goes through the edge of a brick, then the brick is not considered as crossed. You cannot draw a line just along one of the two vertical edges of the wall, in which case the line will obviously cross no bricks.\nGiven the 2D array wall that contains the information about the wall, return the minimum number of crossed bricks after drawing such a vertical line.", + "examples": [ + "Example 1:\nInput: wall = [[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]\nOutput: 2", + "Example 2:\nInput: wall = [[1],[1],[1]]\nOutput: 3" + ], + "constraints": "Constraints:\n\nn == wall.length\n1 <= n <= 10^4\n1 <= wall[i].length <= 10^4\n1 <= sum(wall[i].length) <= 2 * 10^4\nsum(wall[i]) is the same for each row i.\n1 <= wall[i][j] <= 2^31 - 1", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "brick-wall" + }, + { + "leetcode-id": 556, + "title": "Next Greater Element III", + "difficulty": 2, + "description": "Given a positive integer n, find the smallest integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive integer exists, return -1.\nNote that the returned integer should fit in 32-bit integer, if there is a valid answer but it does not fit in 32-bit integer, return -1.", + "examples": [ + "Example 1:\nInput: n = 12\nOutput: 21", + "Example 2:\nInput: n = 21\nOutput: -1" + ], + "constraints": "Constraints:\n\n1 <= n <= 2^31 - 1", + "tags": [ + "Math", + "Two Pointers", + "String" + ], + "title-slug": "next-greater-element-iii" + }, + { + "leetcode-id": 557, + "title": "Reverse Words in a String III", + "difficulty": 1, + "description": "Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.", + "examples": [ + "Example 1:\nInput: s = \"Let's take LeetCode contest\"\nOutput: \"s'teL ekat edoCteeL tsetnoc\"", + "Example 2:\nInput: s = \"God Ding\"\nOutput: \"doG gniD\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 5 * 10^4\ns contains printable ASCII characters.\ns does not contain any leading or trailing spaces.\nThere is at least one word in s.\nAll the words in s are separated by a single space.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "reverse-words-in-a-string-iii" + }, + { + "leetcode-id": 558, + "title": "Logical OR of Two Binary Grids Represented as Quad-Trees", + "difficulty": 2, + "description": "A Binary Matrix is a matrix in which all the elements are either 0 or 1.\nGiven quadTree1 and quadTree2. quadTree1 represents a n * n binary matrix and quadTree2 represents another n * n binary matrix.\nReturn a Quad-Tree representing the n * n binary matrix which is the result of logical bitwise OR of the two binary matrixes represented by quadTree1 and quadTree2.\nNotice that you can assign the value of a node to True or False when isLeaf is False, and both are accepted in the answer.\nA Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes:\n\nval: True if the node represents a grid of 1's or False if the node represents a grid of 0's.\nisLeaf: True if the node is leaf node on the tree or False if the node has the four children.\n\n\nclass Node {\n public boolean val;\n public boolean isLeaf;\n public Node topLeft;\n public Node topRight;\n public Node bottomLeft;\n public Node bottomRight;\n}\nWe can construct a Quad-Tree from a two-dimensional area using the following steps:\n\nIf the current grid has the same value (i.e all 1's or all 0's) set isLeaf True and set val to the value of the grid and set the four children to Null and stop.\nIf the current grid has different values, set isLeaf to False and set val to any value and divide the current grid into four sub-grids as shown in the photo.\nRecurse for each of the children with the proper sub-grid.\n\n\nIf you want to know more about the Quad-Tree, you can refer to the wiki.\nQuad-Tree format:\nThe input/output represents the serialized format of a Quad-Tree using level order traversal, where null signifies a path terminator where no node exists below.\nIt is very similar to the serialization of the binary tree. The only difference is that the node is represented as a list [isLeaf, val].\nIf the value of isLeaf or val is True we represent it as 1 in the list [isLeaf, val] and if the value of isLeaf or val is False we represent it as 0.", + "examples": [ + "Example 1:\nInput: quadTree1 = [[0,1],[1,1],[1,1],[1,0],[1,0]]\n, quadTree2 = [[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\nOutput: [[0,0],[1,1],[1,1],[1,1],[1,0]]\nExplanation: quadTree1 and quadTree2 are shown above. You can see the binary matrix which is represented by each Quad-Tree.\nIf we apply logical bitwise OR on the two binary matrices we get the binary matrix below which is represented by the result Quad-Tree.\nNotice that the binary matrices shown are only for illustration, you don't have to construct the binary matrix to get the result tree.", + "Example 2:\nInput: quadTree1 = [[1,0]], quadTree2 = [[1,0]]\nOutput: [[1,0]]\nExplanation: Each tree represents a binary matrix of size 1*1. Each matrix contains only zero.\nThe resulting matrix is of size 1*1 with also zero." + ], + "constraints": "Constraints:\n\nquadTree1 and quadTree2 are both valid Quad-Trees each representing a n * n grid.\nn == 2^x where 0 <= x <= 9.", + "tags": [ + "Divide and Conquer", + "Tree" + ], + "title-slug": "logical-or-of-two-binary-grids-represented-as-quad-trees" + }, + { + "leetcode-id": 559, + "title": "Maximum Depth of N-ary Tree", + "difficulty": 1, + "description": "Given a n-ary tree, find its maximum depth.\nThe maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.\nNary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).", + "examples": [ + "Example 1:\nInput: root = [1,null,3,2,4,null,5,6]\nOutput: 3", + "Example 2:\nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: 5" + ], + "constraints": "Constraints:\n\nThe total number of nodes is in the range [0, 10^4].\nThe depth of the n-ary tree is less than or equal to 1000.", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search" + ], + "title-slug": "maximum-depth-of-n-ary-tree" + }, + { + "leetcode-id": 560, + "title": "Subarray Sum Equals K", + "difficulty": 2, + "description": "Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k.\nA subarray is a contiguous non-empty sequence of elements within an array.", + "examples": [ + "Example 1:\nInput: nums = [1,1,1], k = 2\nOutput: 2", + "Example 2:\nInput: nums = [1,2,3], k = 3\nOutput: 2" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 2 * 10^4\n-1000 <= nums[i] <= 1000\n-10^7 <= k <= 10^7", + "tags": [ + "Array", + "Hash Table", + "Prefix Sum" + ], + "title-slug": "subarray-sum-equals-k" + }, + { + "leetcode-id": 561, + "title": "Array Partition", + "difficulty": 1, + "description": "Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum.", + "examples": [ + "Example 1:\nInput: nums = [1,4,3,2]\nOutput: 4\nExplanation: All possible pairings (ignoring the ordering of elements) are:\n1. (1, 4), (2, 3) -> min(1, 4) + min(2, 3) = 1 + 2 = 3\n2. (1, 3), (2, 4) -> min(1, 3) + min(2, 4) = 1 + 2 = 3\n3. (1, 2), (3, 4) -> min(1, 2) + min(3, 4) = 1 + 3 = 4\nSo the maximum possible sum is 4.", + "Example 2:\nInput: nums = [6,2,6,5,1,2]\nOutput: 9\nExplanation: The optimal pairing is (2, 1), (2, 5), (6, 6). min(2, 1) + min(2, 5) + min(6, 6) = 1 + 2 + 6 = 9." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^4\nnums.length == 2 * n\n-10^4 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Greedy", + "Sorting", + "Counting Sort" + ], + "title-slug": "array-partition" + }, + { + "leetcode-id": 563, + "title": "Binary Tree Tilt", + "difficulty": 1, + "description": "Given the root of a binary tree, return the sum of every tree node's tilt.\nThe tilt of a tree node is the absolute difference between the sum of all left subtree node values and all right subtree node values. If a node does not have a left child, then the sum of the left subtree node values is treated as 0. The rule is similar if the node does not have a right child.", + "examples": [ + "Example 1:\nInput: root = [1,2,3]\nOutput: 1\nExplanation: \nTilt of node 2 : |0-0| = 0 (no children)\nTilt of node 3 : |0-0| = 0 (no children)\nTilt of node 1 : |2-3| = 1 (left subtree is just left child, so sum is 2; right subtree is just right child, so sum is 3)\nSum of every tilt : 0 + 0 + 1 = 1", + "Example 2:\nInput: root = [4,2,9,3,5,null,7]\nOutput: 15\nExplanation: \nTilt of node 3 : |0-0| = 0 (no children)\nTilt of node 5 : |0-0| = 0 (no children)\nTilt of node 7 : |0-0| = 0 (no children)\nTilt of node 2 : |3-5| = 2 (left subtree is just left child, so sum is 3; right subtree is just right child, so sum is 5)\nTilt of node 9 : |0-7| = 7 (no left child, so sum is 0; right subtree is just right child, so sum is 7)\nTilt of node 4 : |(3+5+2)-(9+7)| = |10-16| = 6 (left subtree values are 3, 5, and 2, which sums to 10; right subtree values are 9 and 7, which sums to 16)\nSum of every tilt : 0 + 0 + 0 + 2 + 7 + 6 = 15", + "Example 3:\nInput: root = [21,7,14,1,1,2,2,3,3]\nOutput: 9" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 10^4].\n-1000 <= Node.val <= 1000", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "binary-tree-tilt" + }, + { + "leetcode-id": 564, + "title": "Find the Closest Palindrome", + "difficulty": 3, + "description": "Given a string n representing an integer, return the closest integer (not including itself), which is a palindrome. If there is a tie, return the smaller one.\nThe closest is defined as the absolute difference minimized between two integers.", + "examples": [ + "Example 1:\nInput: n = \"123\"\nOutput: \"121\"", + "Example 2:\nInput: n = \"1\"\nOutput: \"0\"\nExplanation: 0 and 2 are the closest palindromes but we return the smallest which is 0." + ], + "constraints": "Constraints:\n\n1 <= n.length <= 18\nn consists of only digits.\nn does not have leading zeros.\nn is representing an integer in the range [1, 10^18 - 1].", + "tags": [ + "Math", + "String" + ], + "title-slug": "find-the-closest-palindrome" + }, + { + "leetcode-id": 565, + "title": "Array Nesting", + "difficulty": 2, + "description": "You are given an integer array nums of length n where nums is a permutation of the numbers in the range [0, n - 1].\nYou should build a set s[k] = {nums[k], nums[nums[k]], nums[nums[nums[k]]], ... } subjected to the following rule:\n\nThe first element in s[k] starts with the selection of the element nums[k] of index = k.\nThe next element in s[k] should be nums[nums[k]], and then nums[nums[nums[k]]], and so on.\nWe stop adding right before a duplicate element occurs in s[k].\n\nReturn the longest length of a set s[k].", + "examples": [ + "Example 1:\nInput: nums = [5,4,0,3,1,6,2]\nOutput: 4\nExplanation: \nnums[0] = 5, nums[1] = 4, nums[2] = 0, nums[3] = 3, nums[4] = 1, nums[5] = 6, nums[6] = 2.\nOne of the longest sets s[k]:\ns[0] = {nums[0], nums[5], nums[6], nums[2]} = {5, 6, 2, 0}", + "Example 2:\nInput: nums = [0,1,2]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] < nums.length\nAll the values of nums are unique.", + "tags": [ + "Array", + "Depth-First Search" + ], + "title-slug": "array-nesting" + }, + { + "leetcode-id": 566, + "title": "Reshape the Matrix", + "difficulty": 1, + "description": "In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original data.\nYou are given an m x n matrix mat and two integers r and c representing the number of rows and the number of columns of the wanted reshaped matrix.\nThe reshaped matrix should be filled with all the elements of the original matrix in the same row-traversing order as they were.\nIf the reshape operation with given parameters is possible and legal, output the new reshaped matrix; Otherwise, output the original matrix.", + "examples": [ + "Example 1:\nInput: mat = [[1,2],[3,4]], r = 1, c = 4\nOutput: [[1,2,3,4]]", + "Example 2:\nInput: mat = [[1,2],[3,4]], r = 2, c = 4\nOutput: [[1,2],[3,4]]" + ], + "constraints": "Constraints:\n\nm == mat.length\nn == mat[i].length\n1 <= m, n <= 100\n-1000 <= mat[i][j] <= 1000\n1 <= r, c <= 300", + "tags": [ + "Array", + "Matrix", + "Simulation" + ], + "title-slug": "reshape-the-matrix" + }, + { + "leetcode-id": 567, + "title": "Permutation in String", + "difficulty": 2, + "description": "Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.\nIn other words, return true if one of s1's permutations is the substring of s2.", + "examples": [ + "Example 1:\nInput: s1 = \"ab\", s2 = \"eidbaooo\"\nOutput: true\nExplanation: s2 contains one permutation of s1 (\"ba\").", + "Example 2:\nInput: s1 = \"ab\", s2 = \"eidboaoo\"\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= s1.length, s2.length <= 10^4\ns1 and s2 consist of lowercase English letters.", + "tags": [ + "Hash Table", + "Two Pointers", + "String", + "Sliding Window" + ], + "title-slug": "permutation-in-string" + }, + { + "leetcode-id": 572, + "title": "Subtree of Another Tree", + "difficulty": 1, + "description": "Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.\nA subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants. The tree tree could also be considered as a subtree of itself.", + "examples": [ + "Example 1:\nInput: root = [3,4,5,1,2], subRoot = [4,1,2]\nOutput: true", + "Example 2:\nInput: root = [3,4,5,1,2,null,null,null,null,0], subRoot = [4,1,2]\nOutput: false" + ], + "constraints": "Constraints:\n\nThe number of nodes in the root tree is in the range [1, 2000].\nThe number of nodes in the subRoot tree is in the range [1, 1000].\n-10^4 <= root.val <= 10^4\n-10^4 <= subRoot.val <= 10^4", + "tags": [ + "Tree", + "Depth-First Search", + "String Matching", + "Binary Tree", + "Hash Function" + ], + "title-slug": "subtree-of-another-tree" + }, + { + "leetcode-id": 575, + "title": "Distribute Candies", + "difficulty": 1, + "description": "Alice has n candies, where the i^th candy is of type candyType[i]. Alice noticed that she started to gain weight, so she visited a doctor.\nThe doctor advised Alice to only eat n / 2 of the candies she has (n is always even). Alice likes her candies very much, and she wants to eat the maximum number of different types of candies while still following the doctor's advice.\nGiven the integer array candyType of length n, return the maximum number of different types of candies she can eat if she only eats n / 2 of them.", + "examples": [ + "Example 1:\nInput: candyType = [1,1,2,2,3,3]\nOutput: 3\nExplanation: Alice can only eat 6 / 2 = 3 candies. Since there are only 3 types, she can eat one of each type.", + "Example 2:\nInput: candyType = [1,1,2,3]\nOutput: 2\nExplanation: Alice can only eat 4 / 2 = 2 candies. Whether she eats types [1,2], [1,3], or [2,3], she still can only eat 2 different types.", + "Example 3:\nInput: candyType = [6,6,6,6]\nOutput: 1\nExplanation: Alice can only eat 4 / 2 = 2 candies. Even though she can eat 2 candies, she only has 1 type." + ], + "constraints": "Constraints:\n\nn == candyType.length\n2 <= n <= 10^4\nn\u00a0is even.\n-10^5 <= candyType[i] <= 10^5", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "distribute-candies" + }, + { + "leetcode-id": 576, + "title": "Out of Boundary Paths", + "difficulty": 2, + "description": "There is an m x n grid with a ball. The ball is initially at the position [startRow, startColumn]. You are allowed to move the ball to one of the four adjacent cells in the grid (possibly out of the grid crossing the grid boundary). You can apply at most maxMove moves to the ball.\nGiven the five integers m, n, maxMove, startRow, startColumn, return the number of paths to move the ball out of the grid boundary. Since the answer can be very large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: m = 2, n = 2, maxMove = 2, startRow = 0, startColumn = 0\nOutput: 6", + "Example 2:\nInput: m = 1, n = 3, maxMove = 3, startRow = 0, startColumn = 1\nOutput: 12" + ], + "constraints": "Constraints:\n\n1 <= m, n <= 50\n0 <= maxMove <= 50\n0 <= startRow < m\n0 <= startColumn < n", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "out-of-boundary-paths" + }, + { + "leetcode-id": 581, + "title": "Shortest Unsorted Continuous Subarray", + "difficulty": 2, + "description": "Given an integer array nums, you need to find one continuous subarray such that if you only sort this subarray in non-decreasing order, then the whole array will be sorted in non-decreasing order.\nReturn the shortest such subarray and output its length.", + "examples": [ + "Example 1:\nInput: nums = [2,6,4,8,10,9,15]\nOutput: 5\nExplanation: You need to sort [6, 4, 8, 10, 9] in ascending order to make the whole array sorted in ascending order.", + "Example 2:\nInput: nums = [1,2,3,4]\nOutput: 0", + "Example 3:\nInput: nums = [1]\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-10^5 <= nums[i] <= 10^5\n\n\u00a0\nFollow up: Can you solve it in O(n) time complexity?", + "tags": [ + "Array", + "Two Pointers", + "Stack", + "Greedy", + "Sorting", + "Monotonic Stack" + ], + "title-slug": "shortest-unsorted-continuous-subarray" + }, + { + "leetcode-id": 583, + "title": "Delete Operation for Two Strings", + "difficulty": 2, + "description": "Given two strings word1 and word2, return the minimum number of steps required to make word1 and word2 the same.\nIn one step, you can delete exactly one character in either string.", + "examples": [ + "Example 1:\nInput: word1 = \"sea\", word2 = \"eat\"\nOutput: 2\nExplanation: You need one step to make \"sea\" to \"ea\" and another step to make \"eat\" to \"ea\".", + "Example 2:\nInput: word1 = \"leetcode\", word2 = \"etco\"\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= word1.length, word2.length <= 500\nword1 and word2 consist of only lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "delete-operation-for-two-strings" + }, + { + "leetcode-id": 587, + "title": "Erect the Fence", + "difficulty": 3, + "description": "You are given an array trees where trees[i] = [xi, yi] represents the location of a tree in the garden.\nFence the entire garden using the minimum length of rope, as it is expensive. The garden is well-fenced only if all the trees are enclosed.\nReturn the coordinates of trees that are exactly located on the fence perimeter. You may return the answer in any order.", + "examples": [ + "Example 1:\nInput: trees = [[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]]\nOutput: [[1,1],[2,0],[4,2],[3,3],[2,4]]\nExplanation: All the trees will be on the perimeter of the fence except the tree at [2, 2], which will be inside the fence.", + "Example 2:\nInput: trees = [[1,2],[2,2],[4,2]]\nOutput: [[4,2],[2,2],[1,2]]\nExplanation: The fence forms a line that passes through all the trees." + ], + "constraints": "Constraints:\n\n1 <= trees.length <= 3000\ntrees[i].length == 2\n0 <= xi, yi <= 100\nAll the given positions are unique.", + "tags": [ + "Array", + "Math", + "Geometry" + ], + "title-slug": "erect-the-fence" + }, + { + "leetcode-id": 589, + "title": "N-ary Tree Preorder Traversal", + "difficulty": 1, + "description": "Given the root of an n-ary tree, return the preorder traversal of its nodes' values.\nNary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)", + "examples": [ + "Example 1:\nInput: root = [1,null,3,2,4,null,5,6]\nOutput: [1,3,5,6,2,4]", + "Example 2:\nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: [1,2,3,6,7,11,14,4,8,12,5,9,13,10]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 10^4].\n0 <= Node.val <= 10^4\nThe height of the n-ary tree is less than or equal to 1000.\n\n\u00a0\nFollow up: Recursive solution is trivial, could you do it iteratively?", + "tags": [ + "Stack", + "Tree", + "Depth-First Search" + ], + "title-slug": "n-ary-tree-preorder-traversal" + }, + { + "leetcode-id": 590, + "title": "N-ary Tree Postorder Traversal", + "difficulty": 1, + "description": "Given the root of an n-ary tree, return the postorder traversal of its nodes' values.\nNary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)", + "examples": [ + "Example 1:\nInput: root = [1,null,3,2,4,null,5,6]\nOutput: [5,6,3,2,4,1]", + "Example 2:\nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: [2,6,14,11,7,3,12,8,4,13,9,10,5,1]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 10^4].\n0 <= Node.val <= 10^4\nThe height of the n-ary tree is less than or equal to 1000.\n\n\u00a0\nFollow up: Recursive solution is trivial, could you do it iteratively?", + "tags": [ + "Stack", + "Tree", + "Depth-First Search" + ], + "title-slug": "n-ary-tree-postorder-traversal" + }, + { + "leetcode-id": 591, + "title": "Tag Validator", + "difficulty": 3, + "description": "Given a string representing a code snippet, implement a tag validator to parse the code and return whether it is valid.\nA code snippet is valid if all the following rules hold:\n\nThe code must be wrapped in a valid closed tag. Otherwise, the code is invalid.\nA closed tag (not necessarily valid) has exactly the following format : TAG_CONTENT. Among them, is the start tag, and is the end tag. The TAG_NAME in start and end tags should be the same. A closed tag is valid if and only if the TAG_NAME and TAG_CONTENT are valid.\nA valid TAG_NAME only contain upper-case letters, and has length in range [1,9]. Otherwise, the TAG_NAME is invalid.\nA valid TAG_CONTENT may contain other valid closed tags, cdata and any characters (see note1) EXCEPT unmatched <, unmatched start and end tag, and unmatched or closed tags with invalid TAG_NAME. Otherwise, the TAG_CONTENT is invalid.\nA start tag is unmatched if no end tag exists with the same TAG_NAME, and vice versa. However, you also need to consider the issue of unbalanced when tags are nested.\nA < is unmatched if you cannot find a subsequent >. And when you find a < or should be parsed as TAG_NAME (not necessarily valid).\nThe cdata has the following format : . The range of CDATA_CONTENT is defined as the characters between .\nCDATA_CONTENT may contain any characters. The function of cdata is to forbid the validator to parse CDATA_CONTENT, so even it has some characters that can be parsed as tag (no matter valid or invalid), you should treat it as regular characters.", + "examples": [ + "Example 1:\nInput: code = \"
This is the first line ]]>
\"\nOutput: true\nExplanation: \nThe code is wrapped in a closed tag :
and
. \nThe TAG_NAME is valid, the TAG_CONTENT consists of some characters and cdata. \nAlthough CDATA_CONTENT has an unmatched start tag with invalid TAG_NAME, it should be considered as plain text, not parsed as a tag.\nSo TAG_CONTENT is valid, and then the code is valid. Thus return true.", + "Example 2:\nInput: code = \"
>> ![cdata[]] ]>]]>]]>>]
\"\nOutput: true\nExplanation:\nWe first separate the code into : start_tag|tag_content|end_tag.\nstart_tag -> \"
\"\nend_tag -> \"
\"\ntag_content could also be separated into : text1|cdata|text2.\ntext1 -> \">> ![cdata[]] \"\ncdata -> \"]>]]>\", where the CDATA_CONTENT is \"
]>\"\ntext2 -> \"]]>>]\"\nThe reason why start_tag is NOT \"
>>\" is because of the rule 6.\nThe reason why cdata is NOT \"]>]]>]]>\" is because of the rule 7.", + "Example 3:\nInput: code = \" \"\nOutput: false\nExplanation: Unbalanced. If \"\" is closed, then \"\" must be unmatched, and vice versa." + ], + "constraints": "Constraints:\n\n1 <= code.length <= 500\ncode consists of English letters, digits, '<', '>', '/', '!', '[', ']', '.', and ' '.", + "tags": [ + "String", + "Stack" + ], + "title-slug": "tag-validator" + }, + { + "leetcode-id": 592, + "title": "Fraction Addition and Subtraction", + "difficulty": 2, + "description": "Given a string expression representing an expression of fraction addition and subtraction, return the calculation result in string format.\nThe final result should be an irreducible fraction. If your final result is an integer, change it to the format of a fraction that has a denominator 1. So in this case, 2 should be converted to 2/1.", + "examples": [ + "Example 1:\nInput: expression = \"-1/2+1/2\"\nOutput: \"0/1\"", + "Example 2:\nInput: expression = \"-1/2+1/2+1/3\"\nOutput: \"1/3\"", + "Example 3:\nInput: expression = \"1/3-1/2\"\nOutput: \"-1/6\"" + ], + "constraints": "Constraints:\n\nThe input string only contains '0' to '9', '/', '+' and '-'. So does the output.\nEach fraction (input and output) has the format \u00b1numerator/denominator. If the first input fraction or the output is positive, then '+' will be omitted.\nThe input only contains valid irreducible fractions, where the numerator and denominator of each fraction will always be in the range [1, 10]. If the denominator is 1, it means this fraction is actually an integer in a fraction format defined above.\nThe number of given fractions will be in the range [1, 10].\nThe numerator and denominator of the final result are guaranteed to be valid and in the range of 32-bit int.", + "tags": [ + "Math", + "String", + "Simulation" + ], + "title-slug": "fraction-addition-and-subtraction" + }, + { + "leetcode-id": 593, + "title": "Valid Square", + "difficulty": 2, + "description": "Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square.\nThe coordinate of a point pi is represented as [xi, yi]. The input is not given in any order.\nA valid square has four equal sides with positive length and four equal angles (90-degree angles).", + "examples": [ + "Example 1:\nInput: p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,1]\nOutput: true", + "Example 2:\nInput: p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,12]\nOutput: false", + "Example 3:\nInput: p1 = [1,0], p2 = [-1,0], p3 = [0,1], p4 = [0,-1]\nOutput: true" + ], + "constraints": "Constraints:\n\np1.length == p2.length == p3.length == p4.length == 2\n-10^4 <= xi, yi <= 10^4", + "tags": [ + "Math", + "Geometry" + ], + "title-slug": "valid-square" + }, + { + "leetcode-id": 594, + "title": "Longest Harmonious Subsequence", + "difficulty": 1, + "description": "We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1.\nGiven an integer array nums, return the length of its longest harmonious subsequence among all its possible subsequences.\nA subsequence of array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements.", + "examples": [ + "Example 1:\nInput: nums = [1,3,2,2,5,2,3,7]\r\nOutput: 5\r\nExplanation: The longest harmonious subsequence is [3,2,2,2,3].", + "Example 2:\nInput: nums = [1,2,3,4]\r\nOutput: 2", + "Example 3:\nInput: nums = [1,1,1,1]\r\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 2 * 10^4\n-10^9 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Hash Table", + "Sorting" + ], + "title-slug": "longest-harmonious-subsequence" + }, + { + "leetcode-id": 598, + "title": "Range Addition II", + "difficulty": 1, + "description": "You are given an m x n matrix M initialized with all 0's and an array of operations ops, where ops[i] = [ai, bi] means M[x][y] should be incremented by one for all 0 <= x < ai and 0 <= y < bi.\nCount and return the number of maximum integers in the matrix after performing all the operations.", + "examples": [ + "Example 1:\nInput: m = 3, n = 3, ops = [[2,2],[3,3]]\nOutput: 4\nExplanation: The maximum integer in M is 2, and there are four of it in M. So return 4.", + "Example 2:\nInput: m = 3, n = 3, ops = [[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3]]\nOutput: 4", + "Example 3:\nInput: m = 3, n = 3, ops = []\nOutput: 9" + ], + "constraints": "Constraints:\n\n1 <= m, n <= 4 * 10^4\n0 <= ops.length <= 10^4\nops[i].length == 2\n1 <= ai <= m\n1 <= bi <= n", + "tags": [ + "Array", + "Math" + ], + "title-slug": "range-addition-ii" + }, + { + "leetcode-id": 599, + "title": "Minimum Index Sum of Two Lists", + "difficulty": 1, + "description": "Given two arrays of strings list1 and list2, find the common strings with the least index sum.\nA common string is a string that appeared in both list1 and list2.\nA common string with the least index sum is a common string such that if it appeared at list1[i] and list2[j] then i + j should be the minimum value among all the other common strings.\nReturn all the common strings with the least index sum. Return the answer in any order.", + "examples": [ + "Example 1:\nInput: list1 = [\"Shogun\",\"Tapioca Express\",\"Burger King\",\"KFC\"], list2 = [\"Piatti\",\"The Grill at Torrey Pines\",\"Hungry Hunter Steakhouse\",\"Shogun\"]\nOutput: [\"Shogun\"]\nExplanation: The only common string is \"Shogun\".", + "Example 2:\nInput: list1 = [\"Shogun\",\"Tapioca Express\",\"Burger King\",\"KFC\"], list2 = [\"KFC\",\"Shogun\",\"Burger King\"]\nOutput: [\"Shogun\"]\nExplanation: The common string with the least index sum is \"Shogun\" with index sum = (0 + 1) = 1.", + "Example 3:\nInput: list1 = [\"happy\",\"sad\",\"good\"], list2 = [\"sad\",\"happy\",\"good\"]\nOutput: [\"sad\",\"happy\"]\nExplanation: There are three common strings:\n\"happy\" with index sum = (0 + 1) = 1.\n\"sad\" with index sum = (1 + 0) = 1.\n\"good\" with index sum = (2 + 2) = 4.\nThe strings with the least index sum are \"sad\" and \"happy\"." + ], + "constraints": "Constraints:\n\n1 <= list1.length, list2.length <= 1000\n1 <= list1[i].length, list2[i].length <= 30\nlist1[i] and list2[i] consist of spaces ' ' and English letters.\nAll the strings of list1 are unique.\nAll the strings of list2 are unique.\nThere is at least a common string between list1 and list2.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "minimum-index-sum-of-two-lists" + }, + { + "leetcode-id": 600, + "title": "Non-negative Integers without Consecutive Ones", + "difficulty": 3, + "description": "Given a positive integer n, return the number of the integers in the range [0, n] whose binary representations do not contain consecutive ones.", + "examples": [ + "Example 1:\nInput: n = 5\nOutput: 5\nExplanation:\nHere are the non-negative integers <= 5 with their corresponding binary representations:\n0 : 0\n1 : 1\n2 : 10\n3 : 11\n4 : 100\n5 : 101\nAmong them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule.", + "Example 2:\nInput: n = 1\nOutput: 2", + "Example 3:\nInput: n = 2\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^9", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "non-negative-integers-without-consecutive-ones" + }, + { + "leetcode-id": 605, + "title": "Can Place Flowers", + "difficulty": 1, + "description": "You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.\nGiven an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return true\u00a0if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule and false otherwise.", + "examples": [ + "Example 1:\nInput: flowerbed = [1,0,0,0,1], n = 1\nOutput: true", + "Example 2:\nInput: flowerbed = [1,0,0,0,1], n = 2\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= flowerbed.length <= 2 * 10^4\nflowerbed[i] is 0 or 1.\nThere are no two adjacent flowers in flowerbed.\n0 <= n <= flowerbed.length", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "can-place-flowers" + }, + { + "leetcode-id": 606, + "title": "Construct String from Binary Tree", + "difficulty": 1, + "description": "Given the root of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way, and return it.\nOmit all the empty parenthesis pairs that do not affect the one-to-one mapping relationship between the string and the original binary tree.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,4]\nOutput: \"1(2(4))(3)\"\nExplanation: Originally, it needs to be \"1(2(4)())(3()())\", but you need to omit all the unnecessary empty parenthesis pairs. And it will be \"1(2(4))(3)\"", + "Example 2:\nInput: root = [1,2,3,null,4]\nOutput: \"1(2()(4))(3)\"\nExplanation: Almost the same as the first example, except we cannot omit the first parenthesis pair to break the one-to-one mapping relationship between the input and the output." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n-1000 <= Node.val <= 1000", + "tags": [ + "String", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "construct-string-from-binary-tree" + }, + { + "leetcode-id": 609, + "title": "Find Duplicate File in System", + "difficulty": 2, + "description": "Given a list paths of directory info, including the directory path, and all the files with contents in this directory, return all the duplicate files in the file system in terms of their paths. You may return the answer in any order.\nA group of duplicate files consists of at least two files that have the same content.\nA single directory info string in the input list has the following format:\n\n\"root/d1/d2/.../dm f1.txt(f1_content) f2.txt(f2_content) ... fn.txt(fn_content)\"\n\nIt means there are n files (f1.txt, f2.txt ... fn.txt) with content (f1_content, f2_content ... fn_content) respectively in the directory \"root/d1/d2/.../dm\". Note that n >= 1 and m >= 0. If m = 0, it means the directory is just the root directory.\nThe output is a list of groups of duplicate file paths. For each group, it contains all the file paths of the files that have the same content. A file path is a string that has the following format:\n\n\"directory_path/file_name.txt\"", + "examples": [ + "Example 1:\nInput: paths = [\"root/a 1.txt(abcd) 2.txt(efgh)\",\"root/c 3.txt(abcd)\",\"root/c/d 4.txt(efgh)\",\"root 4.txt(efgh)\"]\nOutput: [[\"root/a/2.txt\",\"root/c/d/4.txt\",\"root/4.txt\"],[\"root/a/1.txt\",\"root/c/3.txt\"]]", + "Example 2:\nInput: paths = [\"root/a 1.txt(abcd) 2.txt(efgh)\",\"root/c 3.txt(abcd)\",\"root/c/d 4.txt(efgh)\"]\nOutput: [[\"root/a/2.txt\",\"root/c/d/4.txt\"],[\"root/a/1.txt\",\"root/c/3.txt\"]]" + ], + "constraints": "Constraints:\n\n1 <= paths.length <= 2 * 10^4\n1 <= paths[i].length <= 3000\n1 <= sum(paths[i].length) <= 5 * 10^5\npaths[i] consist of English letters, digits, '/', '.', '(', ')', and ' '.\nYou may assume no files or directories share the same name in the same directory.\nYou may assume each given directory info represents a unique directory. A single blank space separates the directory path and file info.\n\n\u00a0\nFollow up:\n\nImagine you are given a real file system, how will you search files? DFS or BFS?\nIf the file content is very large (GB level), how will you modify your solution?\nIf you can only read the file by 1kb each time, how will you modify your solution?\nWhat is the time complexity of your modified solution? What is the most time-consuming part and memory-consuming part of it? How to optimize?\nHow to make sure the duplicated files you find are not false positive?", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "find-duplicate-file-in-system" + }, + { + "leetcode-id": 611, + "title": "Valid Triangle Number", + "difficulty": 2, + "description": "Given an integer array nums, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.", + "examples": [ + "Example 1:\nInput: nums = [2,2,3,4]\nOutput: 3\nExplanation: Valid combinations are: \n2,3,4 (using the first 2)\n2,3,4 (using the second 2)\n2,2,3", + "Example 2:\nInput: nums = [4,2,3,4]\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n0 <= nums[i] <= 1000", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Greedy", + "Sorting" + ], + "title-slug": "valid-triangle-number" + }, + { + "leetcode-id": 617, + "title": "Merge Two Binary Trees", + "difficulty": 1, + "description": "You are given two binary trees root1 and root2.\nImagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of the new tree.\nReturn the merged tree.\nNote: The merging process must start from the root nodes of both trees.", + "examples": [ + "Example 1:\nInput: root1 = [1,3,2,5], root2 = [2,1,3,null,4,null,7]\nOutput: [3,4,5,5,4,null,7]", + "Example 2:\nInput: root1 = [1], root2 = [1,2]\nOutput: [2,2]" + ], + "constraints": "Constraints:\n\nThe number of nodes in both trees is in the range [0, 2000].\n-10^4 <= Node.val <= 10^4", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "merge-two-binary-trees" + }, + { + "leetcode-id": 621, + "title": "Task Scheduler", + "difficulty": 2, + "description": "Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle.\nHowever, there is a non-negative integer\u00a0n that represents the cooldown period between\u00a0two same tasks\u00a0(the same letter in the array), that is that there must be at least n units of time between any two same tasks.\nReturn the least number of units of times that the CPU will take to finish all the given tasks.", + "examples": [ + "Example 1:\nInput: tasks = [\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"], n = 2\nOutput: 8\nExplanation: \nA -> B -> idle -> A -> B -> idle -> A -> B\nThere is at least 2 units of time between any two same tasks.", + "Example 2:\nInput: tasks = [\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"], n = 0\nOutput: 6\nExplanation: On this case any permutation of size 6 would work since n = 0.\n[\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"]\n[\"A\",\"B\",\"A\",\"B\",\"A\",\"B\"]\n[\"B\",\"B\",\"B\",\"A\",\"A\",\"A\"]\n...\nAnd so on.", + "Example 3:\nInput: tasks = [\"A\",\"A\",\"A\",\"A\",\"A\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\"], n = 2\nOutput: 16\nExplanation: \nOne possible solution is\nA -> B -> C -> A -> D -> E -> A -> F -> G -> A -> idle -> idle -> A -> idle -> idle -> A" + ], + "constraints": "Constraints:\n\n1 <= task.length <= 10^4\ntasks[i] is upper-case English letter.\nThe integer n is in the range [0, 100].", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Sorting", + "Heap (Priority Queue)", + "Counting" + ], + "title-slug": "task-scheduler" + }, + { + "leetcode-id": 622, + "title": "Design Circular Queue", + "difficulty": 2, + "description": "Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle, and the last position is connected back to the first position to make a circle. It is also called \"Ring Buffer\".\nOne of the benefits of the circular queue is that we can make use of the spaces in front of the queue. In a normal queue, once the queue becomes full, we cannot insert the next element even if there is a space in front of the queue. But using the circular queue, we can use the space to store new values.\nImplement the MyCircularQueue class:\n\nMyCircularQueue(k) Initializes the object with the size of the queue to be k.\nint Front() Gets the front item from the queue. If the queue is empty, return -1.\nint Rear() Gets the last item from the queue. If the queue is empty, return -1.\nboolean enQueue(int value) Inserts an element into the circular queue. Return true if the operation is successful.\nboolean deQueue() Deletes an element from the circular queue. Return true if the operation is successful.\nboolean isEmpty() Checks whether the circular queue is empty or not.\nboolean isFull() Checks whether the circular queue is full or not.\n\nYou must solve the problem without using the built-in queue data structure in your programming language.", + "examples": [ + "Example 1:\nInput\n[\"MyCircularQueue\", \"enQueue\", \"enQueue\", \"enQueue\", \"enQueue\", \"Rear\", \"isFull\", \"deQueue\", \"enQueue\", \"Rear\"]\n[[3], [1], [2], [3], [4], [], [], [], [4], []]\nOutput\n[null, true, true, true, false, 3, true, true, true, 4]\n\nExplanation\nMyCircularQueue myCircularQueue = new MyCircularQueue(3);\nmyCircularQueue.enQueue(1); // return True\nmyCircularQueue.enQueue(2); // return True\nmyCircularQueue.enQueue(3); // return True\nmyCircularQueue.enQueue(4); // return False\nmyCircularQueue.Rear(); // return 3\nmyCircularQueue.isFull(); // return True\nmyCircularQueue.deQueue(); // return True\nmyCircularQueue.enQueue(4); // return True\nmyCircularQueue.Rear(); // return 4" + ], + "constraints": "Constraints:\n\n1 <= k <= 1000\n0 <= value <= 1000\nAt most 3000 calls will be made to\u00a0enQueue, deQueue,\u00a0Front,\u00a0Rear,\u00a0isEmpty, and\u00a0isFull.", + "tags": [ + "Array", + "Linked List", + "Design", + "Queue" + ], + "title-slug": "design-circular-queue" + }, + { + "leetcode-id": 623, + "title": "Add One Row to Tree", + "difficulty": 2, + "description": "Given the root of a binary tree and two integers val and depth, add a row of nodes with value val at the given depth depth.\nNote that the root node is at depth 1.\nThe adding rule is:\n\nGiven the integer depth, for each not null tree node cur at the depth depth - 1, create two tree nodes with value val as cur's left subtree root and right subtree root.\ncur's original left subtree should be the left subtree of the new left subtree root.\ncur's original right subtree should be the right subtree of the new right subtree root.\nIf depth == 1 that means there is no depth depth - 1 at all, then create a tree node with value val as the new root of the whole original tree, and the original tree is the new root's left subtree.", + "examples": [ + "Example 1:\nInput: root = [4,2,6,3,1,5], val = 1, depth = 2\nOutput: [4,1,1,2,null,null,6,3,1,5]", + "Example 2:\nInput: root = [4,2,null,3,1], val = 1, depth = 3\nOutput: [4,2,null,1,1,3,null,null,1]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\nThe depth of the tree is in the range [1, 10^4].\n-100 <= Node.val <= 100\n-10^5 <= val <= 10^5\n1 <= depth <= the depth of tree + 1", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "add-one-row-to-tree" + }, + { + "leetcode-id": 628, + "title": "Maximum Product of Three Numbers", + "difficulty": 1, + "description": "Given an integer array nums, find three numbers whose product is maximum and return the maximum product.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3]\nOutput: 6", + "Example 2:\nInput: nums = [1,2,3,4]\nOutput: 24", + "Example 3:\nInput: nums = [-1,-2,-3]\nOutput: -6" + ], + "constraints": "Constraints:\n\n3 <= nums.length <=\u00a010^4\n-1000 <= nums[i] <= 1000", + "tags": [ + "Array", + "Math", + "Sorting" + ], + "title-slug": "maximum-product-of-three-numbers" + }, + { + "leetcode-id": 629, + "title": "K Inverse Pairs Array", + "difficulty": 3, + "description": "For an integer array nums, an inverse pair is a pair of integers [i, j] where 0 <= i < j < nums.length and nums[i] > nums[j].\nGiven two integers n and k, return the number of different arrays consist of numbers from 1 to n such that there are exactly k inverse pairs. Since the answer can be huge, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 3, k = 0\nOutput: 1\nExplanation: Only the array [1,2,3] which consists of numbers from 1 to 3 has exactly 0 inverse pairs.", + "Example 2:\nInput: n = 3, k = 1\nOutput: 2\nExplanation: The array [1,3,2] and [2,1,3] have exactly 1 inverse pair." + ], + "constraints": "Constraints:\n\n1 <= n <= 1000\n0 <= k <= 1000", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "k-inverse-pairs-array" + }, + { + "leetcode-id": 630, + "title": "Course Schedule III", + "difficulty": 3, + "description": "There are n different online courses numbered from 1 to n. You are given an array courses where courses[i] = [durationi, lastDayi] indicate that the i^th course should be taken continuously for durationi days and must be finished before or on lastDayi.\nYou will start on the 1^st day and you cannot take two or more courses simultaneously.\nReturn the maximum number of courses that you can take.", + "examples": [ + "Example 1:\nInput: courses = [[100,200],[200,1300],[1000,1250],[2000,3200]]\nOutput: 3\nExplanation: \nThere are totally 4 courses, but you can take 3 courses at most:\nFirst, take the 1^st course, it costs 100 days so you will finish it on the 100^th day, and ready to take the next course on the 101^st day.\nSecond, take the 3^rd course, it costs 1000 days so you will finish it on the 1100^th day, and ready to take the next course on the 1101^st day. \nThird, take the 2^nd course, it costs 200 days so you will finish it on the 1300^th day. \nThe 4^th course cannot be taken now, since you will finish it on the 3300^th day, which exceeds the closed date.", + "Example 2:\nInput: courses = [[1,2]]\nOutput: 1", + "Example 3:\nInput: courses = [[3,2],[4,3]]\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= courses.length <= 10^4\n1 <= durationi, lastDayi <= 10^4", + "tags": [ + "Array", + "Greedy", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "course-schedule-iii" + }, + { + "leetcode-id": 632, + "title": "Smallest Range Covering Elements from K Lists", + "difficulty": 3, + "description": "You have k lists of sorted integers in non-decreasing\u00a0order. Find the smallest range that includes at least one number from each of the k lists.\nWe define the range [a, b] is smaller than range [c, d] if b - a < d - c or a < c if b - a == d - c.", + "examples": [ + "Example 1:\nInput: nums = [[4,10,15,24,26],[0,9,12,20],[5,18,22,30]]\nOutput: [20,24]\nExplanation: \nList 1: [4, 10, 15, 24,26], 24 is in range [20,24].\nList 2: [0, 9, 12, 20], 20 is in range [20,24].\nList 3: [5, 18, 22, 30], 22 is in range [20,24].", + "Example 2:\nInput: nums = [[1,2,3],[1,2,3],[1,2,3]]\nOutput: [1,1]" + ], + "constraints": "Constraints:\n\nnums.length == k\n1 <= k <= 3500\n1 <= nums[i].length <= 50\n-10^5 <= nums[i][j] <= 10^5\nnums[i]\u00a0is sorted in non-decreasing order.", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Sliding Window", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "smallest-range-covering-elements-from-k-lists" + }, + { + "leetcode-id": 633, + "title": "Sum of Square Numbers", + "difficulty": 2, + "description": "Given a non-negative integer c, decide whether there're two integers a and b such that a^2 + b^2 = c.", + "examples": [ + "Example 1:\nInput: c = 5\nOutput: true\nExplanation: 1 * 1 + 2 * 2 = 5", + "Example 2:\nInput: c = 3\nOutput: false" + ], + "constraints": "Constraints:\n\n0 <= c <= 2^31 - 1", + "tags": [ + "Math", + "Two Pointers", + "Binary Search" + ], + "title-slug": "sum-of-square-numbers" + }, + { + "leetcode-id": 636, + "title": "Exclusive Time of Functions", + "difficulty": 2, + "description": "On a single-threaded CPU, we execute a program containing n functions. Each function has a unique ID between 0 and n-1.\nFunction calls are stored in a call stack: when a function call starts, its ID is pushed onto the stack, and when a function call ends, its ID is popped off the stack. The function whose ID is at the top of the stack is the current function being executed. Each time a function starts or ends, we write a log with the ID, whether it started or ended, and the timestamp.\nYou are given a list logs, where logs[i] represents the i^th log message formatted as a string \"{function_id}:{\"start\" | \"end\"}:{timestamp}\". For example, \"0:start:3\" means a function call with function ID 0 started at the beginning of timestamp 3, and \"1:end:2\" means a function call with function ID 1 ended at the end of timestamp 2. Note that a function can be called multiple times, possibly recursively.\nA function's exclusive time is the sum of execution times for all function calls in the program. For example, if a function is called twice, one call executing for 2 time units and another call executing for 1 time unit, the exclusive time is 2 + 1 = 3.\nReturn the exclusive time of each function in an array, where the value at the i^th index represents the exclusive time for the function with ID i.", + "examples": [ + "Example 1:\nInput: n = 2, logs = [\"0:start:0\",\"1:start:2\",\"1:end:5\",\"0:end:6\"]\nOutput: [3,4]\nExplanation:\nFunction 0 starts at the beginning of time 0, then it executes 2 for units of time and reaches the end of time 1.\nFunction 1 starts at the beginning of time 2, executes for 4 units of time, and ends at the end of time 5.\nFunction 0 resumes execution at the beginning of time 6 and executes for 1 unit of time.\nSo function 0 spends 2 + 1 = 3 units of total time executing, and function 1 spends 4 units of total time executing.", + "Example 2:\nInput: n = 1, logs = [\"0:start:0\",\"0:start:2\",\"0:end:5\",\"0:start:6\",\"0:end:6\",\"0:end:7\"]\nOutput: [8]\nExplanation:\nFunction 0 starts at the beginning of time 0, executes for 2 units of time, and recursively calls itself.\nFunction 0 (recursive call) starts at the beginning of time 2 and executes for 4 units of time.\nFunction 0 (initial call) resumes execution then immediately calls itself again.\nFunction 0 (2nd recursive call) starts at the beginning of time 6 and executes for 1 unit of time.\nFunction 0 (initial call) resumes execution at the beginning of time 7 and executes for 1 unit of time.\nSo function 0 spends 2 + 4 + 1 + 1 = 8 units of total time executing.", + "Example 3:\nInput: n = 2, logs = [\"0:start:0\",\"0:start:2\",\"0:end:5\",\"1:start:6\",\"1:end:6\",\"0:end:7\"]\nOutput: [7,1]\nExplanation:\nFunction 0 starts at the beginning of time 0, executes for 2 units of time, and recursively calls itself.\nFunction 0 (recursive call) starts at the beginning of time 2 and executes for 4 units of time.\nFunction 0 (initial call) resumes execution then immediately calls function 1.\nFunction 1 starts at the beginning of time 6, executes 1 unit of time, and ends at the end of time 6.\nFunction 0 resumes execution at the beginning of time 6 and executes for 2 units of time.\nSo function 0 spends 2 + 4 + 1 = 7 units of total time executing, and function 1 spends 1 unit of total time executing." + ], + "constraints": "Constraints:\n\n1 <= n <= 100\n1 <= logs.length <= 500\n0 <= function_id < n\n0 <= timestamp <= 10^9\nNo two start events will happen at the same timestamp.\nNo two end events will happen at the same timestamp.\nEach function has an \"end\" log for each \"start\" log.", + "tags": [ + "Array", + "Stack" + ], + "title-slug": "exclusive-time-of-functions" + }, + { + "leetcode-id": 637, + "title": "Average of Levels in Binary Tree", + "difficulty": 1, + "description": "Given the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10^-5 of the actual answer will be accepted.", + "examples": [ + "Example 1:\nInput: root = [3,9,20,null,null,15,7]\nOutput: [3.00000,14.50000,11.00000]\nExplanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11.\nHence return [3, 14.5, 11].", + "Example 2:\nInput: root = [3,9,20,15,7]\nOutput: [3.00000,14.50000,11.00000]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n-2^31 <= Node.val <= 2^31 - 1", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "average-of-levels-in-binary-tree" + }, + { + "leetcode-id": 638, + "title": "Shopping Offers", + "difficulty": 2, + "description": "In LeetCode Store, there are n items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.\nYou are given an integer array price where price[i] is the price of the i^th item, and an integer array needs where needs[i] is the number of pieces of the i^th item you want to buy.\nYou are also given an array special where special[i] is of size n + 1 where special[i][j] is the number of pieces of the j^th item in the i^th offer and special[i][n] (i.e., the last integer in the array) is the price of the i^th offer.\nReturn the lowest price you have to pay for exactly certain items as given, where you could make optimal use of the special offers. You are not allowed to buy more items than you want, even if that would lower the overall price. You could use any of the special offers as many times as you want.", + "examples": [ + "Example 1:\nInput: price = [2,5], special = [[3,0,5],[1,2,10]], needs = [3,2]\nOutput: 14\nExplanation: There are two kinds of items, A and B. Their prices are $2 and $5 respectively. \nIn special offer 1, you can pay $5 for 3A and 0B\nIn special offer 2, you can pay $10 for 1A and 2B. \nYou need to buy 3A and 2B, so you may pay $10 for 1A and 2B (special offer #2), and $4 for 2A.", + "Example 2:\nInput: price = [2,3,4], special = [[1,1,0,4],[2,2,1,9]], needs = [1,2,1]\nOutput: 11\nExplanation: The price of A is $2, and $3 for B, $4 for C. \nYou may pay $4 for 1A and 1B, and $9 for 2A ,2B and 1C. \nYou need to buy 1A ,2B and 1C, so you may pay $4 for 1A and 1B (special offer #1), and $3 for 1B, $4 for 1C. \nYou cannot add more items, though only $9 for 2A ,2B and 1C." + ], + "constraints": "Constraints:\n\nn == price.length == needs.length\n1 <= n <= 6\n0 <= price[i], needs[i] <= 10\n1 <= special.length <= 100\nspecial[i].length == n + 1\n0 <= special[i][j] <= 50", + "tags": [ + "Array", + "Dynamic Programming", + "Backtracking", + "Bit Manipulation", + "Memoization", + "Bitmask" + ], + "title-slug": "shopping-offers" + }, + { + "leetcode-id": 639, + "title": "Decode Ways II", + "difficulty": 3, + "description": "A message containing letters from A-Z can be encoded into numbers using the following mapping:\n\n'A' -> \"1\"\n'B' -> \"2\"\n...\n'Z' -> \"26\"\n\nTo decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, \"11106\" can be mapped into:\n\n\"AAJF\" with the grouping (1 1 10 6)\n\"KJF\" with the grouping (11 10 6)\n\nNote that the grouping (1 11 06) is invalid because \"06\" cannot be mapped into 'F' since \"6\" is different from \"06\".\nIn addition to the mapping above, an encoded message may contain the '*' character, which can represent any digit from '1' to '9' ('0' is excluded). For example, the encoded message \"1*\" may represent any of the encoded messages \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", or \"19\". Decoding \"1*\" is equivalent to decoding any of the encoded messages it can represent.\nGiven a string s consisting of digits and '*' characters, return the number of ways to decode it.\nSince the answer may be very large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: s = \"*\"\nOutput: 9\nExplanation: The encoded message can represent any of the encoded messages \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", or \"9\".\nEach of these can be decoded to the strings \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", and \"I\" respectively.\nHence, there are a total of 9 ways to decode \"*\".", + "Example 2:\nInput: s = \"1*\"\nOutput: 18\nExplanation: The encoded message can represent any of the encoded messages \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", or \"19\".\nEach of these encoded messages have 2 ways to be decoded (e.g. \"11\" can be decoded to \"AA\" or \"K\").\nHence, there are a total of 9 * 2 = 18 ways to decode \"1*\".", + "Example 3:\nInput: s = \"2*\"\nOutput: 15\nExplanation: The encoded message can represent any of the encoded messages \"21\", \"22\", \"23\", \"24\", \"25\", \"26\", \"27\", \"28\", or \"29\".\n\"21\", \"22\", \"23\", \"24\", \"25\", and \"26\" have 2 ways of being decoded, but \"27\", \"28\", and \"29\" only have 1 way.\nHence, there are a total of (6 * 2) + (3 * 1) = 12 + 3 = 15 ways to decode \"2*\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns[i] is a digit or '*'.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "decode-ways-ii" + }, + { + "leetcode-id": 640, + "title": "Solve the Equation", + "difficulty": 2, + "description": "Solve a given equation and return the value of 'x' in the form of a string \"x=#value\". The equation contains only '+', '-' operation, the variable 'x' and its coefficient. You should return \"No solution\" if there is no solution for the equation, or \"Infinite solutions\" if there are infinite solutions for the equation.\nIf there is exactly one solution for the equation, we ensure that the value of 'x' is an integer.", + "examples": [ + "Example 1:\nInput: equation = \"x+5-3+x=6+x-2\"\nOutput: \"x=2\"", + "Example 2:\nInput: equation = \"x=x\"\nOutput: \"Infinite solutions\"", + "Example 3:\nInput: equation = \"2x=x\"\nOutput: \"x=0\"" + ], + "constraints": "Constraints:\n\n3 <= equation.length <= 1000\nequation has exactly one '='.\nequation consists of integers with an absolute value in the range [0, 100] without any leading zeros, and the variable 'x'.", + "tags": [ + "Math", + "String", + "Simulation" + ], + "title-slug": "solve-the-equation" + }, + { + "leetcode-id": 641, + "title": "Design Circular Deque", + "difficulty": 2, + "description": "Design your implementation of the circular double-ended queue (deque).\nImplement the MyCircularDeque class:\n\nMyCircularDeque(int k) Initializes the deque with a maximum size of k.\nboolean insertFront() Adds an item at the front of Deque. Returns true if the operation is successful, or false otherwise.\nboolean insertLast() Adds an item at the rear of Deque. Returns true if the operation is successful, or false otherwise.\nboolean deleteFront() Deletes an item from the front of Deque. Returns true if the operation is successful, or false otherwise.\nboolean deleteLast() Deletes an item from the rear of Deque. Returns true if the operation is successful, or false otherwise.\nint getFront() Returns the front item from the Deque. Returns -1 if the deque is empty.\nint getRear() Returns the last item from Deque. Returns -1 if the deque is empty.\nboolean isEmpty() Returns true if the deque is empty, or false otherwise.\nboolean isFull() Returns true if the deque is full, or false otherwise.", + "examples": [ + "Example 1:\nInput\n[\"MyCircularDeque\", \"insertLast\", \"insertLast\", \"insertFront\", \"insertFront\", \"getRear\", \"isFull\", \"deleteLast\", \"insertFront\", \"getFront\"]\n[[3], [1], [2], [3], [4], [], [], [], [4], []]\nOutput\n[null, true, true, true, false, 2, true, true, true, 4]\n\nExplanation\nMyCircularDeque myCircularDeque = new MyCircularDeque(3);\nmyCircularDeque.insertLast(1); // return True\nmyCircularDeque.insertLast(2); // return True\nmyCircularDeque.insertFront(3); // return True\nmyCircularDeque.insertFront(4); // return False, the queue is full.\nmyCircularDeque.getRear(); // return 2\nmyCircularDeque.isFull(); // return True\nmyCircularDeque.deleteLast(); // return True\nmyCircularDeque.insertFront(4); // return True\nmyCircularDeque.getFront(); // return 4" + ], + "constraints": "Constraints:\n\n1 <= k <= 1000\n0 <= value <= 1000\nAt most 2000 calls will be made to insertFront, insertLast, deleteFront, deleteLast, getFront, getRear, isEmpty, isFull.", + "tags": [ + "Array", + "Linked List", + "Design", + "Queue" + ], + "title-slug": "design-circular-deque" + }, + { + "leetcode-id": 643, + "title": "Maximum Average Subarray I", + "difficulty": 1, + "description": "You are given an integer array nums consisting of n elements, and an integer k.\nFind a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10^-5 will be accepted.", + "examples": [ + "Example 1:\nInput: nums = [1,12,-5,-6,50,3], k = 4\nOutput: 12.75000\nExplanation: Maximum average is (12 - 5 - 6 + 50) / 4 = 51 / 4 = 12.75", + "Example 2:\nInput: nums = [5], k = 1\nOutput: 5.00000" + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= k <= n <= 10^5\n-10^4 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Sliding Window" + ], + "title-slug": "maximum-average-subarray-i" + }, + { + "leetcode-id": 645, + "title": "Set Mismatch", + "difficulty": 1, + "description": "You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number.\nYou are given an integer array nums representing the data status of this set after the error.\nFind the number that occurs twice and the number that is missing and return them in the form of an array.", + "examples": [ + "Example 1:\nInput: nums = [1,2,2,4]\nOutput: [2,3]", + "Example 2:\nInput: nums = [1,1]\nOutput: [1,2]" + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 10^4\n1 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Hash Table", + "Bit Manipulation", + "Sorting" + ], + "title-slug": "set-mismatch" + }, + { + "leetcode-id": 646, + "title": "Maximum Length of Pair Chain", + "difficulty": 2, + "description": "You are given an array of n pairs pairs where pairs[i] = [lefti, righti] and lefti < righti.\nA pair p2 = [c, d] follows a pair p1 = [a, b] if b < c. A chain of pairs can be formed in this fashion.\nReturn the length longest chain which can be formed.\nYou do not need to use up all the given intervals. You can select pairs in any order.", + "examples": [ + "Example 1:\nInput: pairs = [[1,2],[2,3],[3,4]]\nOutput: 2\nExplanation: The longest chain is [1,2] -> [3,4].", + "Example 2:\nInput: pairs = [[1,2],[7,8],[4,5]]\nOutput: 3\nExplanation: The longest chain is [1,2] -> [4,5] -> [7,8]." + ], + "constraints": "Constraints:\n\nn == pairs.length\n1 <= n <= 1000\n-1000 <= lefti < righti <= 1000", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy", + "Sorting" + ], + "title-slug": "maximum-length-of-pair-chain" + }, + { + "leetcode-id": 647, + "title": "Palindromic Substrings", + "difficulty": 2, + "description": "Given a string s, return the number of palindromic substrings in it.\nA string is a palindrome when it reads the same backward as forward.\nA substring is a contiguous sequence of characters within the string.", + "examples": [ + "Example 1:\nInput: s = \"abc\"\nOutput: 3\nExplanation: Three palindromic strings: \"a\", \"b\", \"c\".", + "Example 2:\nInput: s = \"aaa\"\nOutput: 6\nExplanation: Six palindromic strings: \"a\", \"a\", \"a\", \"aa\", \"aa\", \"aaa\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns consists of lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "palindromic-substrings" + }, + { + "leetcode-id": 648, + "title": "Replace Words", + "difficulty": 2, + "description": "In English, we have a concept called root, which can be followed by some other word to form another longer word - let's call this word successor. For example, when the root \"an\" is followed by the successor word \"other\", we can form a new word \"another\".\nGiven a dictionary consisting of many roots and a sentence consisting of words separated by spaces, replace all the successors in the sentence with the root forming it. If a successor can be replaced by more than one root, replace it with the root that has the shortest length.\nReturn the sentence after the replacement.", + "examples": [ + "Example 1:\nInput: dictionary = [\"cat\",\"bat\",\"rat\"], sentence = \"the cattle was rattled by the battery\"\nOutput: \"the cat was rat by the bat\"", + "Example 2:\nInput: dictionary = [\"a\",\"b\",\"c\"], sentence = \"aadsfasf absbs bbab cadsfafs\"\nOutput: \"a a b c\"" + ], + "constraints": "Constraints:\n\n1 <= dictionary.length <= 1000\n1 <= dictionary[i].length <= 100\ndictionary[i] consists of only lower-case letters.\n1 <= sentence.length <= 10^6\nsentence consists of only lower-case letters and spaces.\nThe number of words in sentence is in the range [1, 1000]\nThe length of each word in sentence is in the range [1, 1000]\nEvery two consecutive words in sentence will be separated by exactly one space.\nsentence does not have leading or trailing spaces.", + "tags": [ + "Array", + "Hash Table", + "String", + "Trie" + ], + "title-slug": "replace-words" + }, + { + "leetcode-id": 649, + "title": "Dota2 Senate", + "difficulty": 2, + "description": "In the world of Dota2, there are two parties: the Radiant and the Dire.\nThe Dota2 senate consists of senators coming from two parties. Now the Senate wants to decide on a change in the Dota2 game. The voting for this change is a round-based procedure. In each round, each senator can exercise one of the two rights:\n\nBan one senator's right: A senator can make another senator lose all his rights in this and all the following rounds.\nAnnounce the victory: If this senator found the senators who still have rights to vote are all from the same party, he can announce the victory and decide on the change in the game.\n\nGiven a string senate representing each senator's party belonging. The character 'R' and 'D' represent the Radiant party and the Dire party. Then if there are n senators, the size of the given string will be n.\nThe round-based procedure starts from the first senator to the last senator in the given order. This procedure will last until the end of voting. All the senators who have lost their rights will be skipped during the procedure.\nSuppose every senator is smart enough and will play the best strategy for his own party. Predict which party will finally announce the victory and change the Dota2 game. The output should be \"Radiant\" or \"Dire\".", + "examples": [ + "Example 1:\nInput: senate = \"RD\"\nOutput: \"Radiant\"\nExplanation: \nThe first senator comes from Radiant and he can just ban the next senator's right in round 1. \nAnd the second senator can't exercise any rights anymore since his right has been banned. \nAnd in round 2, the first senator can just announce the victory since he is the only guy in the senate who can vote.", + "Example 2:\nInput: senate = \"RDD\"\nOutput: \"Dire\"\nExplanation: \nThe first senator comes from Radiant and he can just ban the next senator's right in round 1. \nAnd the second senator can't exercise any rights anymore since his right has been banned. \nAnd the third senator comes from Dire and he can ban the first senator's right in round 1. \nAnd in round 2, the third senator can just announce the victory since he is the only guy in the senate who can vote." + ], + "constraints": "Constraints:\n\nn == senate.length\n1 <= n <= 10^4\nsenate[i] is either 'R' or 'D'.", + "tags": [ + "String", + "Greedy", + "Queue" + ], + "title-slug": "dota2-senate" + }, + { + "leetcode-id": 650, + "title": "2 Keys Keyboard", + "difficulty": 2, + "description": "There is only one character 'A' on the screen of a notepad. You can perform one of two operations on this notepad for each step:\n\nCopy All: You can copy all the characters present on the screen (a partial copy is not allowed).\nPaste: You can paste the characters which are copied last time.\n\nGiven an integer n, return the minimum number of operations to get the character 'A' exactly n times on the screen.", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: 3\nExplanation: Initially, we have one character 'A'.\nIn step 1, we use Copy All operation.\nIn step 2, we use Paste operation to get 'AA'.\nIn step 3, we use Paste operation to get 'AAA'.", + "Example 2:\nInput: n = 1\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= n <= 1000", + "tags": [ + "Math", + "Dynamic Programming" + ], + "title-slug": "2-keys-keyboard" + }, + { + "leetcode-id": 652, + "title": "Find Duplicate Subtrees", + "difficulty": 2, + "description": "Given the root\u00a0of a binary tree, return all duplicate subtrees.\nFor each kind of duplicate subtrees, you only need to return the root node of any one of them.\nTwo trees are duplicate if they have the same structure with the same node values.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,4,null,2,4,null,null,4]\nOutput: [[2,4],[4]]", + "Example 2:\nInput: root = [2,1,1]\nOutput: [[1]]", + "Example 3:\nInput: root = [2,2,2,3,null,3,null]\nOutput: [[2,3],[3]]" + ], + "constraints": "Constraints:\n\nThe number of the nodes in the tree will be in the range [1, 5000]\n-200 <= Node.val <= 200", + "tags": [ + "Hash Table", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "find-duplicate-subtrees" + }, + { + "leetcode-id": 653, + "title": "Two Sum IV - Input is a BST", + "difficulty": 1, + "description": "Given the root of a binary search tree and an integer k, return true if there exist two elements in the BST such that their sum is equal to k, or false otherwise.", + "examples": [ + "Example 1:\nInput: root = [5,3,6,2,4,null,7], k = 9\nOutput: true", + "Example 2:\nInput: root = [5,3,6,2,4,null,7], k = 28\nOutput: false" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n-10^4 <= Node.val <= 10^4\nroot is guaranteed to be a valid binary search tree.\n-10^5 <= k <= 10^5", + "tags": [ + "Hash Table", + "Two Pointers", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "two-sum-iv-input-is-a-bst" + }, + { + "leetcode-id": 654, + "title": "Maximum Binary Tree", + "difficulty": 2, + "description": "You are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorithm:\n\nCreate a root node whose value is the maximum value in nums.\nRecursively build the left subtree on the subarray prefix to the left of the maximum value.\nRecursively build the right subtree on the subarray suffix to the right of the maximum value.\n\nReturn the maximum binary tree built from nums.", + "examples": [ + "Example 1:\nInput: nums = [3,2,1,6,0,5]\nOutput: [6,3,5,null,2,0,null,null,1]\nExplanation: The recursive calls are as follow:\n- The largest value in [3,2,1,6,0,5] is 6. Left prefix is [3,2,1] and right suffix is [0,5].\n - The largest value in [3,2,1] is 3. Left prefix is [] and right suffix is [2,1].\n - Empty array, so no child.\n - The largest value in [2,1] is 2. Left prefix is [] and right suffix is [1].\n - Empty array, so no child.\n - Only one element, so child is a node with value 1.\n - The largest value in [0,5] is 5. Left prefix is [0] and right suffix is [].\n - Only one element, so child is a node with value 0.\n - Empty array, so no child.", + "Example 2:\nInput: nums = [3,2,1]\nOutput: [3,null,2,null,1]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n0 <= nums[i] <= 1000\nAll integers in nums are unique.", + "tags": [ + "Array", + "Divide and Conquer", + "Stack", + "Tree", + "Monotonic Stack", + "Binary Tree" + ], + "title-slug": "maximum-binary-tree" + }, + { + "leetcode-id": 655, + "title": "Print Binary Tree", + "difficulty": 2, + "description": "Given the root of a binary tree, construct a 0-indexed m x n string matrix res that represents a formatted layout of the tree. The formatted layout matrix should be constructed using the following rules:\n\nThe height of the tree is height\u00a0and the number of rows m should be equal to height + 1.\nThe number of columns n should be equal to 2^height+1 - 1.\nPlace the root node in the middle of the top row (more formally, at location res[0][(n-1)/2]).\nFor each node that has been placed in the matrix at position res[r][c], place its left child at res[r+1][c-2^height-r-1] and its right child at res[r+1][c+2^height-r-1].\nContinue this process until all the nodes in the tree have been placed.\nAny empty cells should contain the empty string \"\".\n\nReturn the constructed matrix res.", + "examples": [ + "Example 1:\nInput: root = [1,2]\nOutput: \n[[\"\",\"1\",\"\"],\n\u00a0[\"2\",\"\",\"\"]]", + "Example 2:\nInput: root = [1,2,3,null,4]\nOutput: \n[[\"\",\"\",\"\",\"1\",\"\",\"\",\"\"],\n\u00a0[\"\",\"2\",\"\",\"\",\"\",\"3\",\"\"],\n\u00a0[\"\",\"\",\"4\",\"\",\"\",\"\",\"\"]]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 2^10].\n-99 <= Node.val <= 99\nThe depth of the tree will be in the range [1, 10].", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "print-binary-tree" + }, + { + "leetcode-id": 657, + "title": "Robot Return to Origin", + "difficulty": 1, + "description": "There is a robot starting at the position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves.\nYou are given a string moves that represents the move sequence of the robot where moves[i] represents its i^th move. Valid moves are 'R' (right), 'L' (left), 'U' (up), and 'D' (down).\nReturn true if the robot returns to the origin after it finishes all of its moves, or false otherwise.\nNote: The way that the robot is \"facing\" is irrelevant. 'R' will always make the robot move to the right once, 'L' will always make it move left, etc. Also, assume that the magnitude of the robot's movement is the same for each move.", + "examples": [ + "Example 1:\nInput: moves = \"UD\"\nOutput: true\nExplanation: The robot moves up once, and then down once. All moves have the same magnitude, so it ended up at the origin where it started. Therefore, we return true.", + "Example 2:\nInput: moves = \"LL\"\nOutput: false\nExplanation: The robot moves left twice. It ends up two \"moves\" to the left of the origin. We return false because it is not at the origin at the end of its moves." + ], + "constraints": "Constraints:\n\n1 <= moves.length <= 2 * 10^4\nmoves only contains the characters 'U', 'D', 'L' and 'R'.", + "tags": [ + "String", + "Simulation" + ], + "title-slug": "robot-return-to-origin" + }, + { + "leetcode-id": 658, + "title": "Find K Closest Elements", + "difficulty": 2, + "description": "Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order.\nAn integer a is closer to x than an integer b if:\n\n|a - x| < |b - x|, or\n|a - x| == |b - x| and a < b", + "examples": [ + "Example 1:\nInput: arr = [1,2,3,4,5], k = 4, x = 3\nOutput: [1,2,3,4]", + "Example 2:\nInput: arr = [1,2,3,4,5], k = 4, x = -1\nOutput: [1,2,3,4]" + ], + "constraints": "Constraints:\n\n1 <= k <= arr.length\n1 <= arr.length <= 10^4\narr is sorted in ascending order.\n-10^4 <= arr[i], x <= 10^4", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Sliding Window", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "find-k-closest-elements" + }, + { + "leetcode-id": 659, + "title": "Split Array into Consecutive Subsequences", + "difficulty": 2, + "description": "You are given an integer array nums that is sorted in non-decreasing order.\nDetermine if it is possible to split nums into one or more subsequences such that both of the following conditions are true:\n\nEach subsequence is a consecutive increasing sequence (i.e. each integer is exactly one more than the previous integer).\nAll subsequences have a length of 3 or more.\n\nReturn true if you can split nums according to the above conditions, or false otherwise.\nA subsequence of an array is a new array that is formed from the original array by deleting some (can be none) of the elements without disturbing the relative positions of the remaining elements. (i.e., [1,3,5] is a subsequence of [1,2,3,4,5] while [1,3,2] is not).", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,3,4,5]\nOutput: true\nExplanation: nums can be split into the following subsequences:\n[1,2,3,3,4,5] --> 1, 2, 3\n[1,2,3,3,4,5] --> 3, 4, 5", + "Example 2:\nInput: nums = [1,2,3,3,4,4,5,5]\nOutput: true\nExplanation: nums can be split into the following subsequences:\n[1,2,3,3,4,4,5,5] --> 1, 2, 3, 4, 5\n[1,2,3,3,4,4,5,5] --> 3, 4, 5", + "Example 3:\nInput: nums = [1,2,3,4,4,5]\nOutput: false\nExplanation: It is impossible to split nums into consecutive increasing subsequences of length 3 or more." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-1000 <= nums[i] <= 1000\nnums is sorted in non-decreasing order.", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Heap (Priority Queue)" + ], + "title-slug": "split-array-into-consecutive-subsequences" + }, + { + "leetcode-id": 661, + "title": "Image Smoother", + "difficulty": 1, + "description": "An image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells (i.e., the average of the nine cells in the blue smoother). If one or more of the surrounding cells of a cell is not present, we do not consider it in the average (i.e., the average of the four cells in the red smoother).\n\nGiven an m x n integer matrix img representing the grayscale of an image, return the image after applying the smoother on each cell of it.", + "examples": [ + "Example 1:\nInput: img = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: [[0,0,0],[0,0,0],[0,0,0]]\nExplanation:\nFor the points (0,0), (0,2), (2,0), (2,2): floor(3/4) = floor(0.75) = 0\nFor the points (0,1), (1,0), (1,2), (2,1): floor(5/6) = floor(0.83333333) = 0\nFor the point (1,1): floor(8/9) = floor(0.88888889) = 0", + "Example 2:\nInput: img = [[100,200,100],[200,50,200],[100,200,100]]\nOutput: [[137,141,137],[141,138,141],[137,141,137]]\nExplanation:\nFor the points (0,0), (0,2), (2,0), (2,2): floor((100+200+200+50)/4) = floor(137.5) = 137\nFor the points (0,1), (1,0), (1,2), (2,1): floor((200+200+50+200+100+100)/6) = floor(141.666667) = 141\nFor the point (1,1): floor((50+200+200+200+200+100+100+100+100)/9) = floor(138.888889) = 138" + ], + "constraints": "Constraints:\n\nm == img.length\nn == img[i].length\n1 <= m, n <= 200\n0 <= img[i][j] <= 255", + "tags": [ + "Array", + "Matrix" + ], + "title-slug": "image-smoother" + }, + { + "leetcode-id": 662, + "title": "Maximum Width of Binary Tree", + "difficulty": 2, + "description": "Given the root of a binary tree, return the maximum width of the given tree.\nThe maximum width of a tree is the maximum width among all levels.\nThe width of one level is defined as the length between the end-nodes (the leftmost and rightmost non-null nodes), where the null nodes between the end-nodes that would be present in a complete binary tree extending down to that level are also counted into the length calculation.\nIt is guaranteed that the answer will in the range of a 32-bit signed integer.", + "examples": [ + "Example 1:\nInput: root = [1,3,2,5,3,null,9]\nOutput: 4\nExplanation: The maximum width exists in the third level with length 4 (5,3,null,9).", + "Example 2:\nInput: root = [1,3,2,5,null,null,9,6,null,7]\nOutput: 7\nExplanation: The maximum width exists in the fourth level with length 7 (6,null,null,null,null,null,7).", + "Example 3:\nInput: root = [1,3,2,5]\nOutput: 2\nExplanation: The maximum width exists in the second level with length 2 (3,2)." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 3000].\n-100 <= Node.val <= 100", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "maximum-width-of-binary-tree" + }, + { + "leetcode-id": 664, + "title": "Strange Printer", + "difficulty": 3, + "description": "There is a strange printer with the following two special properties:\n\nThe printer can only print a sequence of the same character each time.\nAt each turn, the printer can print new characters starting from and ending at any place and will cover the original existing characters.\n\nGiven a string s, return the minimum number of turns the printer needed to print it.", + "examples": [ + "Example 1:\nInput: s = \"aaabbb\"\nOutput: 2\nExplanation: Print \"aaa\" first and then print \"bbb\".", + "Example 2:\nInput: s = \"aba\"\nOutput: 2\nExplanation: Print \"aaa\" first and then print \"b\" from the second place of the string, which will cover the existing character 'a'." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\ns consists of lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "strange-printer" + }, + { + "leetcode-id": 665, + "title": "Non-decreasing Array", + "difficulty": 2, + "description": "Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element.\nWe define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2).", + "examples": [ + "Example 1:\nInput: nums = [4,2,3]\nOutput: true\nExplanation: You could modify the first 4 to 1 to get a non-decreasing array.", + "Example 2:\nInput: nums = [4,2,1]\nOutput: false\nExplanation: You cannot get a non-decreasing array by modifying at most one element." + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^4\n-10^5 <= nums[i] <= 10^5", + "tags": [ + "Array" + ], + "title-slug": "non-decreasing-array" + }, + { + "leetcode-id": 667, + "title": "Beautiful Arrangement II", + "difficulty": 2, + "description": "Given two integers n and k, construct a list answer that contains n different positive integers ranging from 1 to n and obeys the following requirement:\n\nSuppose this list is answer =\u00a0[a1, a2, a3, ... , an], then the list [|a1 - a2|, |a2 - a3|, |a3 - a4|, ... , |an-1 - an|] has exactly k distinct integers.\n\nReturn the list answer. If there multiple valid answers, return any of them.", + "examples": [ + "Example 1:\nInput: n = 3, k = 1\nOutput: [1,2,3]\nExplanation: The [1,2,3] has three different positive integers ranging from 1 to 3, and the [1,1] has exactly 1 distinct integer: 1", + "Example 2:\nInput: n = 3, k = 2\nOutput: [1,3,2]\nExplanation: The [1,3,2] has three different positive integers ranging from 1 to 3, and the [2,1] has exactly 2 distinct integers: 1 and 2." + ], + "constraints": "Constraints:\n\n1 <= k < n <= 10^4", + "tags": [ + "Array", + "Math" + ], + "title-slug": "beautiful-arrangement-ii" + }, + { + "leetcode-id": 668, + "title": "Kth Smallest Number in Multiplication Table", + "difficulty": 3, + "description": "Nearly everyone has used the Multiplication Table. The multiplication table of size m x n is an integer matrix mat where mat[i][j] == i * j (1-indexed).\nGiven three integers m, n, and k, return the k^th smallest element in the m x n multiplication table.", + "examples": [ + "Example 1:\nInput: m = 3, n = 3, k = 5\nOutput: 3\nExplanation: The 5^th smallest number is 3.", + "Example 2:\nInput: m = 2, n = 3, k = 6\nOutput: 6\nExplanation: The 6^th smallest number is 6." + ], + "constraints": "Constraints:\n\n1 <= m, n <= 3 * 10^4\n1 <= k <= m * n", + "tags": [ + "Math", + "Binary Search" + ], + "title-slug": "kth-smallest-number-in-multiplication-table" + }, + { + "leetcode-id": 669, + "title": "Trim a Binary Search Tree", + "difficulty": 2, + "description": "Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node's descendant should remain a descendant). It can be proven that there is a unique answer.\nReturn the root of the trimmed binary search tree. Note that the root may change depending on the given bounds.", + "examples": [ + "Example 1:\nInput: root = [1,0,2], low = 1, high = 2\nOutput: [1,null,2]", + "Example 2:\nInput: root = [3,0,4,null,2,null,null,1], low = 1, high = 3\nOutput: [3,2,null,1]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n0 <= Node.val <= 10^4\nThe value of each node in the tree is unique.\nroot is guaranteed to be a valid binary search tree.\n0 <= low <= high <= 10^4", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "trim-a-binary-search-tree" + }, + { + "leetcode-id": 670, + "title": "Maximum Swap", + "difficulty": 2, + "description": "You are given an integer num. You can swap two digits at most once to get the maximum valued number.\nReturn the maximum valued number you can get.", + "examples": [ + "Example 1:\nInput: num = 2736\nOutput: 7236\nExplanation: Swap the number 2 and the number 7.", + "Example 2:\nInput: num = 9973\nOutput: 9973\nExplanation: No swap." + ], + "constraints": "Constraints:\n\n0 <= num <= 10^8", + "tags": [ + "Math", + "Greedy" + ], + "title-slug": "maximum-swap" + }, + { + "leetcode-id": 671, + "title": "Second Minimum Node In a Binary Tree", + "difficulty": 1, + "description": "Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes. More formally, the property\u00a0root.val = min(root.left.val, root.right.val)\u00a0always holds.\nGiven such a binary tree, you need to output the second minimum value in the set made of all the nodes' value in the whole tree.\nIf no such second minimum value exists, output -1 instead.", + "examples": [ + "Example 1:\nInput: root = [2,2,5,null,null,5,7]\nOutput: 5\nExplanation: The smallest value is 2, the second smallest value is 5.", + "Example 2:\nInput: root = [2,2,2]\nOutput: -1\nExplanation: The smallest value is 2, but there isn't any second smallest value." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 25].\n1 <= Node.val <= 2^31 - 1\nroot.val == min(root.left.val, root.right.val)\u00a0for each internal node of the tree.", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "second-minimum-node-in-a-binary-tree" + }, + { + "leetcode-id": 672, + "title": "Bulb Switcher II", + "difficulty": 2, + "description": "There is a room with n bulbs labeled from 1 to n that all are turned on initially, and four buttons on the wall. Each of the four buttons has a different functionality where:\n\nButton 1: Flips the status of all the bulbs.\nButton 2: Flips the status of all the bulbs with even labels (i.e., 2, 4, ...).\nButton 3: Flips the status of all the bulbs with odd labels (i.e., 1, 3, ...).\nButton 4: Flips the status of all the bulbs with a label j = 3k + 1 where k = 0, 1, 2, ... (i.e., 1, 4, 7, 10, ...).\n\nYou must make exactly presses button presses in total. For each press, you may pick any of the four buttons to press.\nGiven the two integers n and presses, return the number of different possible statuses after performing all presses button presses.", + "examples": [ + "Example 1:\nInput: n = 1, presses = 1\nOutput: 2\nExplanation: Status can be:\n- [off] by pressing button 1\n- [on] by pressing button 2", + "Example 2:\nInput: n = 2, presses = 1\nOutput: 3\nExplanation: Status can be:\n- [off, off] by pressing button 1\n- [on, off] by pressing button 2\n- [off, on] by pressing button 3", + "Example 3:\nInput: n = 3, presses = 1\nOutput: 4\nExplanation: Status can be:\n- [off, off, off] by pressing button 1\n- [off, on, off] by pressing button 2\n- [on, off, on] by pressing button 3\n- [off, on, on] by pressing button 4" + ], + "constraints": "Constraints:\n\n1 <= n <= 1000\n0 <= presses <= 1000", + "tags": [ + "Math", + "Bit Manipulation", + "Depth-First Search", + "Breadth-First Search" + ], + "title-slug": "bulb-switcher-ii" + }, + { + "leetcode-id": 673, + "title": "Number of Longest Increasing Subsequence", + "difficulty": 2, + "description": "Given an integer array\u00a0nums, return the number of longest increasing subsequences.\nNotice that the sequence has to be strictly increasing.", + "examples": [ + "Example 1:\nInput: nums = [1,3,5,4,7]\nOutput: 2\nExplanation: The two longest increasing subsequences are [1, 3, 4, 7] and [1, 3, 5, 7].", + "Example 2:\nInput: nums = [2,2,2,2,2]\nOutput: 5\nExplanation: The length of the longest increasing subsequence is 1, and there are 5 increasing subsequences of length 1, so output 5." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 2000\n-10^6 <= nums[i] <= 10^6", + "tags": [ + "Array", + "Dynamic Programming", + "Binary Indexed Tree", + "Segment Tree" + ], + "title-slug": "number-of-longest-increasing-subsequence" + }, + { + "leetcode-id": 674, + "title": "Longest Continuous Increasing Subsequence", + "difficulty": 1, + "description": "Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (i.e. subarray). The subsequence must be strictly increasing.\nA continuous increasing subsequence is defined by two indices l and r (l < r) such that it is [nums[l], nums[l + 1], ..., nums[r - 1], nums[r]] and for each l <= i < r, nums[i] < nums[i + 1].", + "examples": [ + "Example 1:\nInput: nums = [1,3,5,4,7]\nOutput: 3\nExplanation: The longest continuous increasing subsequence is [1,3,5] with length 3.\nEven though [1,3,5,7] is an increasing subsequence, it is not continuous as elements 5 and 7 are separated by element\n4.", + "Example 2:\nInput: nums = [2,2,2,2,2]\nOutput: 1\nExplanation: The longest continuous increasing subsequence is [2] with length 1. Note that it must be strictly\nincreasing." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-10^9 <= nums[i] <= 10^9", + "tags": [ + "Array" + ], + "title-slug": "longest-continuous-increasing-subsequence" + }, + { + "leetcode-id": 675, + "title": "Cut Off Trees for Golf Event", + "difficulty": 3, + "description": "You are asked to cut off all the trees in a forest for a golf event. The forest is represented as an m x n matrix. In this matrix:\n\n0 means the cell cannot be walked through.\n1 represents an empty cell that can be walked through.\nA number greater than 1 represents a tree in a cell that can be walked through, and this number is the tree's height.\n\nIn one step, you can walk in any of the four directions: north, east, south, and west. If you are standing in a cell with a tree, you can choose whether to cut it off.\nYou must cut off the trees in order from shortest to tallest. When you cut off a tree, the value at its cell becomes 1 (an empty cell).\nStarting from the point (0, 0), return the minimum steps you need to walk to cut off all the trees. If you cannot cut off all the trees, return -1.\nNote: The input is generated such that no two trees have the same height, and there is at least one tree needs to be cut off.", + "examples": [ + "Example 1:\nInput: forest = [[1,2,3],[0,0,4],[7,6,5]]\nOutput: 6\nExplanation: Following the path above allows you to cut off the trees from shortest to tallest in 6 steps.", + "Example 2:\nInput: forest = [[1,2,3],[0,0,0],[7,6,5]]\nOutput: -1\nExplanation: The trees in the bottom row cannot be accessed as the middle row is blocked.", + "Example 3:\nInput: forest = [[2,3,4],[0,0,5],[8,7,6]]\nOutput: 6\nExplanation: You can follow the same path as", + "Example 1 to cut off all the trees.\nNote that you can cut off the first tree at (0, 0) before making any steps." + ], + "constraints": "Constraints:\n\nm == forest.length\nn == forest[i].length\n1 <= m, n <= 50\n0 <= forest[i][j] <= 10^9\nHeights of all trees are distinct.", + "tags": [ + "Array", + "Breadth-First Search", + "Heap (Priority Queue)", + "Matrix" + ], + "title-slug": "cut-off-trees-for-golf-event" + }, + { + "leetcode-id": 676, + "title": "Implement Magic Dictionary", + "difficulty": 2, + "description": "Design a data structure that is initialized with a list of different words. Provided a string, you should determine if you can change exactly one character in this string to match any word in the data structure.\nImplement the\u00a0MagicDictionary\u00a0class:\n\nMagicDictionary()\u00a0Initializes the object.\nvoid buildDict(String[]\u00a0dictionary)\u00a0Sets the data structure\u00a0with an array of distinct strings dictionary.\nbool search(String searchWord) Returns true if you can change exactly one character in searchWord to match any string in the data structure, otherwise returns false.", + "examples": [ + "Example 1:\nInput\n[\"MagicDictionary\", \"buildDict\", \"search\", \"search\", \"search\", \"search\"]\n[[], [[\"hello\", \"leetcode\"]], [\"hello\"], [\"hhllo\"], [\"hell\"], [\"leetcoded\"]]\nOutput\n[null, null, false, true, false, false]\n\nExplanation\nMagicDictionary magicDictionary = new MagicDictionary();\nmagicDictionary.buildDict([\"hello\", \"leetcode\"]);\nmagicDictionary.search(\"hello\"); // return False\nmagicDictionary.search(\"hhllo\"); // We can change the second 'h' to 'e' to match \"hello\" so we return True\nmagicDictionary.search(\"hell\"); // return False\nmagicDictionary.search(\"leetcoded\"); // return False" + ], + "constraints": "Constraints:\n\n1 <=\u00a0dictionary.length <= 100\n1 <=\u00a0dictionary[i].length <= 100\ndictionary[i] consists of only lower-case English letters.\nAll the strings in\u00a0dictionary\u00a0are distinct.\n1 <=\u00a0searchWord.length <= 100\nsearchWord\u00a0consists of only lower-case English letters.\nbuildDict\u00a0will be called only once before search.\nAt most 100 calls will be made to search.", + "tags": [ + "Hash Table", + "String", + "Depth-First Search", + "Design", + "Trie" + ], + "title-slug": "implement-magic-dictionary" + }, + { + "leetcode-id": 677, + "title": "Map Sum Pairs", + "difficulty": 2, + "description": "Design a map that allows you to do the following:\n\nMaps a string key to a given value.\nReturns the sum of the values that have a key with a prefix equal to a given string.\n\nImplement the MapSum class:\n\nMapSum() Initializes the MapSum object.\nvoid insert(String key, int val) Inserts the key-val pair into the map. If the key already existed, the original key-value pair will be overridden to the new one.\nint sum(string prefix) Returns the sum of all the pairs' value whose key starts with the prefix.", + "examples": [ + "Example 1:\nInput\n[\"MapSum\", \"insert\", \"sum\", \"insert\", \"sum\"]\n[[], [\"apple\", 3], [\"ap\"], [\"app\", 2], [\"ap\"]]\nOutput\n[null, null, 3, null, 5]\n\nExplanation\nMapSum mapSum = new MapSum();\nmapSum.insert(\"apple\", 3); \nmapSum.sum(\"ap\"); // return 3 (apple = 3)\nmapSum.insert(\"app\", 2); \nmapSum.sum(\"ap\"); // return 5 (apple + app = 3 + 2 = 5)" + ], + "constraints": "Constraints:\n\n1 <= key.length, prefix.length <= 50\nkey and prefix consist of only lowercase English letters.\n1 <= val <= 1000\nAt most 50 calls will be made to insert and sum.", + "tags": [ + "Hash Table", + "String", + "Design", + "Trie" + ], + "title-slug": "map-sum-pairs" + }, + { + "leetcode-id": 678, + "title": "Valid Parenthesis String", + "difficulty": 2, + "description": "Given a string s containing only three types of characters: '(', ')' and '*', return true if s is valid.\nThe following rules define a valid string:\n\nAny left parenthesis '(' must have a corresponding right parenthesis ')'.\nAny right parenthesis ')' must have a corresponding left parenthesis '('.\nLeft parenthesis '(' must go before the corresponding right parenthesis ')'.\n'*' could be treated as a single right parenthesis ')' or a single left parenthesis '(' or an empty string \"\".", + "examples": [ + "Example 1:\nInput: s = \"()\"\nOutput: true", + "Example 2:\nInput: s = \"(*)\"\nOutput: true", + "Example 3:\nInput: s = \"(*))\"\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\ns[i] is '(', ')' or '*'.", + "tags": [ + "String", + "Dynamic Programming", + "Stack", + "Greedy" + ], + "title-slug": "valid-parenthesis-string" + }, + { + "leetcode-id": 679, + "title": "24 Game", + "difficulty": 3, + "description": "You are given an integer array cards of length 4. You have four cards, each containing a number in the range [1, 9]. You should arrange the numbers on these cards in a mathematical expression using the operators ['+', '-', '*', '/'] and the parentheses '(' and ')' to get the value 24.\nYou are restricted with the following rules:\n\nThe division operator '/' represents real division, not integer division.\n\n\t\nFor example, 4 / (1 - 2 / 3) = 4 / (1 / 3) = 12.\n\n\nEvery operation done is between two numbers. In particular, we cannot use '-' as a unary operator.\n\t\nFor example, if cards = [1, 1, 1, 1], the expression \"-1 - 1 - 1 - 1\" is not allowed.\n\n\nYou cannot concatenate numbers together\n\t\nFor example, if cards = [1, 2, 1, 2], the expression \"12 + 12\" is not valid.\n\n\n\nReturn true if you can get such expression that evaluates to 24, and false otherwise.", + "examples": [ + "Example 1:\nInput: cards = [4,1,8,7]\nOutput: true\nExplanation: (8-4) * (7-1) = 24", + "Example 2:\nInput: cards = [1,2,1,2]\nOutput: false" + ], + "constraints": "Constraints:\n\ncards.length == 4\n1 <= cards[i] <= 9", + "tags": [ + "Array", + "Math", + "Backtracking" + ], + "title-slug": "24-game" + }, + { + "leetcode-id": 680, + "title": "Valid Palindrome II", + "difficulty": 1, + "description": "Given a string s, return true if the s can be palindrome after deleting at most one character from it.", + "examples": [ + "Example 1:\nInput: s = \"aba\"\nOutput: true", + "Example 2:\nInput: s = \"abca\"\nOutput: true\nExplanation: You could delete the character 'c'.", + "Example 3:\nInput: s = \"abc\"\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of lowercase English letters.", + "tags": [ + "Two Pointers", + "String", + "Greedy" + ], + "title-slug": "valid-palindrome-ii" + }, + { + "leetcode-id": 682, + "title": "Baseball Game", + "difficulty": 1, + "description": "You are keeping the scores for a baseball game with strange rules. At the beginning of the game, you start with an empty record.\nYou are given a list of strings operations, where operations[i] is the i^th operation you must apply to the record and is one of the following:\n\nAn integer x.\n\n\t\nRecord a new score of x.\n\n\n'+'.\n\t\nRecord a new score that is the sum of the previous two scores.\n\n\n'D'.\n\t\nRecord a new score that is the double of the previous score.\n\n\n'C'.\n\t\nInvalidate the previous score, removing it from the record.\n\n\n\nReturn the sum of all the scores on the record after applying all the operations.\nThe test cases are generated such that the answer and all intermediate calculations fit in a 32-bit integer and that all operations are valid.", + "examples": [ + "Example 1:\nInput: ops = [\"5\",\"2\",\"C\",\"D\",\"+\"]\nOutput: 30\nExplanation:\n\"5\" - Add 5 to the record, record is now [5].\n\"2\" - Add 2 to the record, record is now [5, 2].\n\"C\" - Invalidate and remove the previous score, record is now [5].\n\"D\" - Add 2 * 5 = 10 to the record, record is now [5, 10].\n\"+\" - Add 5 + 10 = 15 to the record, record is now [5, 10, 15].\nThe total sum is 5 + 10 + 15 = 30.", + "Example 2:\nInput: ops = [\"5\",\"-2\",\"4\",\"C\",\"D\",\"9\",\"+\",\"+\"]\nOutput: 27\nExplanation:\n\"5\" - Add 5 to the record, record is now [5].\n\"-2\" - Add -2 to the record, record is now [5, -2].\n\"4\" - Add 4 to the record, record is now [5, -2, 4].\n\"C\" - Invalidate and remove the previous score, record is now [5, -2].\n\"D\" - Add 2 * -2 = -4 to the record, record is now [5, -2, -4].\n\"9\" - Add 9 to the record, record is now [5, -2, -4, 9].\n\"+\" - Add -4 + 9 = 5 to the record, record is now [5, -2, -4, 9, 5].\n\"+\" - Add 9 + 5 = 14 to the record, record is now [5, -2, -4, 9, 5, 14].\nThe total sum is 5 + -2 + -4 + 9 + 5 + 14 = 27.", + "Example 3:\nInput: ops = [\"1\",\"C\"]\nOutput: 0\nExplanation:\n\"1\" - Add 1 to the record, record is now [1].\n\"C\" - Invalidate and remove the previous score, record is now [].\nSince the record is empty, the total sum is 0." + ], + "constraints": "Constraints:\n\n1 <= operations.length <= 1000\noperations[i] is \"C\", \"D\", \"+\", or a string representing an integer in the range [-3 * 10^4, 3 * 10^4].\nFor operation \"+\", there will always be at least two previous scores on the record.\nFor operations \"C\" and \"D\", there will always be at least one previous score on the record.", + "tags": [ + "Array", + "Stack", + "Simulation" + ], + "title-slug": "baseball-game" + }, + { + "leetcode-id": 684, + "title": "Redundant Connection", + "difficulty": 2, + "description": "In this problem, a tree is an undirected graph that is connected and has no cycles.\nYou are given a graph that started as a tree with n nodes labeled from 1 to n, with one additional edge added. The added edge has two different vertices chosen from 1 to n, and was not an edge that already existed. The graph is represented as an array edges of length n where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the graph.\nReturn an edge that can be removed so that the resulting graph is a tree of n nodes. If there are multiple answers, return the answer that occurs last in the input.", + "examples": [ + "Example 1:\nInput: edges = [[1,2],[1,3],[2,3]]\nOutput: [2,3]", + "Example 2:\nInput: edges = [[1,2],[2,3],[3,4],[1,4],[1,5]]\nOutput: [1,4]" + ], + "constraints": "Constraints:\n\nn == edges.length\n3 <= n <= 1000\nedges[i].length == 2\n1 <= ai < bi <= edges.length\nai != bi\nThere are no repeated edges.\nThe given graph is connected.", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Graph" + ], + "title-slug": "redundant-connection" + }, + { + "leetcode-id": 685, + "title": "Redundant Connection II", + "difficulty": 3, + "description": "In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, except for the root node which has no parents.\nThe given input is a directed graph that started as a rooted tree with n nodes (with distinct values from 1 to n), with one additional directed edge added. The added edge has two different vertices chosen from 1 to n, and was not an edge that already existed.\nThe resulting graph is given as a 2D-array of edges. Each element of edges is a pair [ui, vi] that represents a directed edge connecting nodes ui and vi, where ui is a parent of child vi.\nReturn an edge that can be removed so that the resulting graph is a rooted tree of n nodes. If there are multiple answers, return the answer that occurs last in the given 2D-array.", + "examples": [ + "Example 1:\nInput: edges = [[1,2],[1,3],[2,3]]\nOutput: [2,3]", + "Example 2:\nInput: edges = [[1,2],[2,3],[3,4],[4,1],[1,5]]\nOutput: [4,1]" + ], + "constraints": "Constraints:\n\nn == edges.length\n3 <= n <= 1000\nedges[i].length == 2\n1 <= ui, vi <= n\nui != vi", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Graph" + ], + "title-slug": "redundant-connection-ii" + }, + { + "leetcode-id": 686, + "title": "Repeated String Match", + "difficulty": 2, + "description": "Given two strings a and b, return the minimum number of times you should repeat string a so that string b is a substring of it. If it is impossible for b\u200b\u200b\u200b\u200b\u200b\u200b to be a substring of a after repeating it, return -1.\nNotice: string \"abc\" repeated 0 times is \"\", repeated 1 time is \"abc\" and repeated 2 times is \"abcabc\".", + "examples": [ + "Example 1:\nInput: a = \"abcd\", b = \"cdabcdab\"\nOutput: 3\nExplanation: We return 3 because by repeating a three times \"abcdabcdabcd\", b is a substring of it.", + "Example 2:\nInput: a = \"a\", b = \"aa\"\nOutput: 2" + ], + "constraints": "Constraints:\n\n1 <= a.length, b.length <= 10^4\na and b consist of lowercase English letters.", + "tags": [ + "String", + "String Matching" + ], + "title-slug": "repeated-string-match" + }, + { + "leetcode-id": 687, + "title": "Longest Univalue Path", + "difficulty": 2, + "description": "Given the root of a binary tree, return the length of the longest path, where each node in the path has the same value. This path may or may not pass through the root.\nThe length of the path between two nodes is represented by the number of edges between them.", + "examples": [ + "Example 1:\nInput: root = [5,4,5,1,1,null,5]\nOutput: 2\nExplanation: The shown image shows that the longest path of the same value (i.e. 5).", + "Example 2:\nInput: root = [1,4,5,4,4,null,5]\nOutput: 2\nExplanation: The shown image shows that the longest path of the same value (i.e. 4)." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [0, 10^4].\n-1000 <= Node.val <= 1000\nThe depth of the tree will not exceed 1000.", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "longest-univalue-path" + }, + { + "leetcode-id": 688, + "title": "Knight Probability in Chessboard", + "difficulty": 2, + "description": "On an n x n chessboard, a knight starts at the cell (row, column) and attempts to make exactly k moves. The rows and columns are 0-indexed, so the top-left cell is (0, 0), and the bottom-right cell is (n - 1, n - 1).\nA chess knight has eight possible moves it can make, as illustrated below. Each move is two cells in a cardinal direction, then one cell in an orthogonal direction.\n\nEach time the knight is to move, it chooses one of eight possible moves uniformly at random (even if the piece would go off the chessboard) and moves there.\nThe knight continues moving until it has made exactly k moves or has moved off the chessboard.\nReturn the probability that the knight remains on the board after it has stopped moving.", + "examples": [ + "Example 1:\nInput: n = 3, k = 2, row = 0, column = 0\nOutput: 0.06250\nExplanation: There are two moves (to (1,2), (2,1)) that will keep the knight on the board.\nFrom each of those positions, there are also two moves that will keep the knight on the board.\nThe total probability the knight stays on the board is 0.0625.", + "Example 2:\nInput: n = 1, k = 0, row = 0, column = 0\nOutput: 1.00000" + ], + "constraints": "Constraints:\n\n1 <= n <= 25\n0 <= k <= 100\n0 <= row, column <= n - 1", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "knight-probability-in-chessboard" + }, + { + "leetcode-id": 689, + "title": "Maximum Sum of 3 Non-Overlapping Subarrays", + "difficulty": 3, + "description": "Given an integer array nums and an integer k, find three non-overlapping subarrays of length k with maximum sum and return them.\nReturn the result as a list of indices representing the starting position of each interval (0-indexed). If there are multiple answers, return the lexicographically smallest one.", + "examples": [ + "Example 1:\nInput: nums = [1,2,1,2,6,7,5,1], k = 2\nOutput: [0,3,5]\nExplanation: Subarrays [1, 2], [2, 6], [7, 5] correspond to the starting indices [0, 3, 5].\nWe could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically larger.", + "Example 2:\nInput: nums = [1,2,1,2,1,2,1,2,1], k = 2\nOutput: [0,2,4]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 2 * 10^4\n1 <= nums[i] <\u00a02^16\n1 <= k <= floor(nums.length / 3)", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "maximum-sum-of-3-non-overlapping-subarrays" + }, + { + "leetcode-id": 690, + "title": "Employee Importance", + "difficulty": 2, + "description": "You have a data structure of employee information, including the employee's unique ID, importance value, and direct subordinates' IDs.\nYou are given an array of employees employees where:\n\nemployees[i].id is the ID of the i^th employee.\nemployees[i].importance is the importance value of the i^th employee.\nemployees[i].subordinates is a list of the IDs of the direct subordinates of the i^th employee.\n\nGiven an integer id that represents an employee's ID, return the total importance value of this employee and all their direct and indirect subordinates.", + "examples": [ + "Example 1:\nInput: employees = [[1,5,[2,3]],[2,3,[]],[3,3,[]]], id = 1\nOutput: 11\nExplanation: Employee 1 has an importance value of 5 and has two direct subordinates: employee 2 and employee 3.\nThey both have an importance value of 3.\nThus, the total importance value of employee 1 is 5 + 3 + 3 = 11.", + "Example 2:\nInput: employees = [[1,2,[5]],[5,-3,[]]], id = 5\nOutput: -3\nExplanation: Employee 5 has an importance value of -3 and has no direct subordinates.\nThus, the total importance value of employee 5 is -3." + ], + "constraints": "Constraints:\n\n1 <= employees.length <= 2000\n1 <= employees[i].id <= 2000\nAll employees[i].id are unique.\n-100 <= employees[i].importance <= 100\nOne employee has at most one direct leader and may have several subordinates.\nThe IDs in employees[i].subordinates are valid IDs.", + "tags": [ + "Hash Table", + "Depth-First Search", + "Breadth-First Search" + ], + "title-slug": "employee-importance" + }, + { + "leetcode-id": 691, + "title": "Stickers to Spell Word", + "difficulty": 3, + "description": "We are given n different types of stickers. Each sticker has a lowercase English word on it.\nYou would like to spell out the given string target by cutting individual letters from your collection of stickers and rearranging them. You can use each sticker more than once if you want, and you have infinite quantities of each sticker.\nReturn the minimum number of stickers that you need to spell out target. If the task is impossible, return -1.\nNote: In all test cases, all words were chosen randomly from the 1000 most common US English words, and target was chosen as a concatenation of two random words.", + "examples": [ + "Example 1:\nInput: stickers = [\"with\",\"example\",\"science\"], target = \"thehat\"\nOutput: 3\nExplanation:\nWe can use 2 \"with\" stickers, and 1 \"example\" sticker.\nAfter cutting and rearrange the letters of those stickers, we can form the target \"thehat\".\nAlso, this is the minimum number of stickers necessary to form the target string.", + "Example 2:\nInput: stickers = [\"notice\",\"possible\"], target = \"basicbasic\"\nOutput: -1\nExplanation:\nWe cannot form the target \"basicbasic\" from cutting letters from the given stickers." + ], + "constraints": "Constraints:\n\nn == stickers.length\n1 <= n <= 50\n1 <= stickers[i].length <= 10\n1 <= target.length <= 15\nstickers[i] and target consist of lowercase English letters.", + "tags": [ + "Array", + "String", + "Dynamic Programming", + "Backtracking", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "stickers-to-spell-word" + }, + { + "leetcode-id": 692, + "title": "Top K Frequent Words", + "difficulty": 2, + "description": "Given an array of strings words and an integer k, return the k most frequent strings.\nReturn the answer sorted by the frequency from highest to lowest. Sort the words with the same frequency by their lexicographical order.", + "examples": [ + "Example 1:\nInput: words = [\"i\",\"love\",\"leetcode\",\"i\",\"love\",\"coding\"], k = 2\nOutput: [\"i\",\"love\"]\nExplanation: \"i\" and \"love\" are the two most frequent words.\nNote that \"i\" comes before \"love\" due to a lower alphabetical order.", + "Example 2:\nInput: words = [\"the\",\"day\",\"is\",\"sunny\",\"the\",\"the\",\"the\",\"sunny\",\"is\",\"is\"], k = 4\nOutput: [\"the\",\"is\",\"sunny\",\"day\"]\nExplanation: \"the\", \"is\", \"sunny\" and \"day\" are the four most frequent words, with the number of occurrence being 4, 3, 2 and 1 respectively." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 500\n1 <= words[i].length <= 10\nwords[i] consists of lowercase English letters.\nk is in the range [1, The number of unique words[i]]\n\n\u00a0\nFollow-up: Could you solve it in O(n log(k)) time and O(n) extra space?", + "tags": [ + "Hash Table", + "String", + "Trie", + "Sorting", + "Heap (Priority Queue)", + "Bucket Sort", + "Counting" + ], + "title-slug": "top-k-frequent-words" + }, + { + "leetcode-id": 693, + "title": "Binary Number with Alternating Bits", + "difficulty": 1, + "description": "Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.", + "examples": [ + "Example 1:\nInput: n = 5\nOutput: true\nExplanation: The binary representation of 5 is: 101", + "Example 2:\nInput: n = 7\nOutput: false\nExplanation: The binary representation of 7 is: 111.", + "Example 3:\nInput: n = 11\nOutput: false\nExplanation: The binary representation of 11 is: 1011." + ], + "constraints": "Constraints:\n\n1 <= n <= 2^31 - 1", + "tags": [ + "Bit Manipulation" + ], + "title-slug": "binary-number-with-alternating-bits" + }, + { + "leetcode-id": 695, + "title": "Max Area of Island", + "difficulty": 2, + "description": "You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.\nThe area of an island is the number of cells with a value 1 in the island.\nReturn the maximum area of an island in grid. If there is no island, return 0.", + "examples": [ + "Example 1:\nInput: grid = [[0,0,1,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,1,1,0,0,1,0,1,0,0],[0,1,0,0,1,1,0,0,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0]]\nOutput: 6\nExplanation: The answer is not 11, because the island must be connected 4-directionally.", + "Example 2:\nInput: grid = [[0,0,0,0,0,0,0,0]]\nOutput: 0" + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 50\ngrid[i][j] is either 0 or 1.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Matrix" + ], + "title-slug": "max-area-of-island" + }, + { + "leetcode-id": 696, + "title": "Count Binary Substrings", + "difficulty": 1, + "description": "Given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively.\nSubstrings that occur multiple times are counted the number of times they occur.", + "examples": [ + "Example 1:\nInput: s = \"00110011\"\nOutput: 6\nExplanation: There are 6 substrings that have equal number of consecutive 1's and 0's: \"0011\", \"01\", \"1100\", \"10\", \"0011\", and \"01\".\nNotice that some of these substrings repeat and are counted the number of times they occur.\nAlso, \"00110011\" is not a valid substring because all the 0's (and 1's) are not grouped together.", + "Example 2:\nInput: s = \"10101\"\nOutput: 4\nExplanation: There are 4 substrings: \"10\", \"01\", \"10\", \"01\" that have equal number of consecutive 1's and 0's." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns[i] is either '0' or '1'.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "count-binary-substrings" + }, + { + "leetcode-id": 697, + "title": "Degree of an Array", + "difficulty": 1, + "description": "Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.\nYour task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.", + "examples": [ + "Example 1:\nInput: nums = [1,2,2,3,1]\nOutput: 2\nExplanation: \nThe input array has a degree of 2 because both elements 1 and 2 appear twice.\nOf the subarrays that have the same degree:\n[1, 2, 2, 3, 1], [1, 2, 2, 3], [2, 2, 3, 1], [1, 2, 2], [2, 2, 3], [2, 2]\nThe shortest length is 2. So return 2.", + "Example 2:\nInput: nums = [1,2,2,3,1,4,2]\nOutput: 6\nExplanation: \nThe degree is 3 because the element 2 is repeated 3 times.\nSo [2,2,3,1,4,2] is the shortest subarray, therefore returning 6." + ], + "constraints": "Constraints:\n\nnums.length will be between 1 and 50,000.\nnums[i] will be an integer between 0 and 49,999.", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "degree-of-an-array" + }, + { + "leetcode-id": 698, + "title": "Partition to K Equal Sum Subsets", + "difficulty": 2, + "description": "Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal.", + "examples": [ + "Example 1:\nInput: nums = [4,3,2,3,5,2,1], k = 4\nOutput: true\nExplanation: It is possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal sums.", + "Example 2:\nInput: nums = [1,2,3,4], k = 3\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= k <= nums.length <= 16\n1 <= nums[i] <= 10^4\nThe frequency of each element is in the range [1, 4].", + "tags": [ + "Array", + "Dynamic Programming", + "Backtracking", + "Bit Manipulation", + "Memoization", + "Bitmask" + ], + "title-slug": "partition-to-k-equal-sum-subsets" + }, + { + "leetcode-id": 699, + "title": "Falling Squares", + "difficulty": 3, + "description": "There are several squares being dropped onto the X-axis of a 2D plane.\nYou are given a 2D integer array positions where positions[i] = [lefti, sideLengthi] represents the i^th square with a side length of sideLengthi that is dropped with its left edge aligned with X-coordinate lefti.\nEach square is dropped one at a time from a height above any landed squares. It then falls downward (negative Y direction) until it either lands on the top side of another square or on the X-axis. A square brushing the left/right side of another square does not count as landing on it. Once it lands, it freezes in place and cannot be moved.\nAfter each square is dropped, you must record the height of the current tallest stack of squares.\nReturn an integer array ans where ans[i] represents the height described above after dropping the i^th square.", + "examples": [ + "Example 1:\nInput: positions = [[1,2],[2,3],[6,1]]\nOutput: [2,5,5]\nExplanation:\nAfter the first drop, the tallest stack is square 1 with a height of 2.\nAfter the second drop, the tallest stack is squares 1 and 2 with a height of 5.\nAfter the third drop, the tallest stack is still squares 1 and 2 with a height of 5.\nThus, we return an answer of [2, 5, 5].", + "Example 2:\nInput: positions = [[100,100],[200,100]]\nOutput: [100,100]\nExplanation:\nAfter the first drop, the tallest stack is square 1 with a height of 100.\nAfter the second drop, the tallest stack is either square 1 or square 2, both with heights of 100.\nThus, we return an answer of [100, 100].\nNote that square 2 only brushes the right side of square 1, which does not count as landing on it." + ], + "constraints": "Constraints:\n\n1 <= positions.length <= 1000\n1 <= lefti <= 10^8\n1 <= sideLengthi <= 10^6", + "tags": [ + "Array", + "Segment Tree", + "Ordered Set" + ], + "title-slug": "falling-squares" + }, + { + "leetcode-id": 700, + "title": "Search in a Binary Search Tree", + "difficulty": 1, + "description": "You are given the root of a binary search tree (BST) and an integer val.\nFind the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does not exist, return null.", + "examples": [ + "Example 1:\nInput: root = [4,2,7,1,3], val = 2\nOutput: [2,1,3]", + "Example 2:\nInput: root = [4,2,7,1,3], val = 5\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 5000].\n1 <= Node.val <= 10^7\nroot is a binary search tree.\n1 <= val <= 10^7", + "tags": [ + "Tree", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "search-in-a-binary-search-tree" + }, + { + "leetcode-id": 701, + "title": "Insert into a Binary Search Tree", + "difficulty": 2, + "description": "You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.\nNotice\u00a0that there may exist\u00a0multiple valid ways for the\u00a0insertion, as long as the tree remains a BST after insertion. You can return any of them.", + "examples": [ + "Example 1:\nInput: root = [4,2,7,1,3], val = 5\nOutput: [4,2,7,1,3,5]\nExplanation: Another accepted tree is:", + "Example 2:\nInput: root = [40,20,60,10,30,50,70], val = 25\nOutput: [40,20,60,10,30,50,70,null,null,25]", + "Example 3:\nInput: root = [4,2,7,1,3,null,null,null,null,null,null], val = 5\nOutput: [4,2,7,1,3,5]" + ], + "constraints": "Constraints:\n\nThe number of nodes in\u00a0the tree will be in the range [0,\u00a010^4].\n-10^8 <= Node.val <= 10^8\nAll the values Node.val are unique.\n-10^8 <= val <= 10^8\nIt's guaranteed that val does not exist in the original BST.", + "tags": [ + "Tree", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "insert-into-a-binary-search-tree" + }, + { + "leetcode-id": 703, + "title": "Kth Largest Element in a Stream", + "difficulty": 1, + "description": "Design a class to find the k^th largest element in a stream. Note that it is the k^th largest element in the sorted order, not the k^th distinct element.\nImplement KthLargest class:\n\nKthLargest(int k, int[] nums) Initializes the object with the integer k and the stream of integers nums.\nint add(int val) Appends the integer val to the stream and returns the element representing the k^th largest element in the stream.", + "examples": [ + "Example 1:\nInput\n[\"KthLargest\", \"add\", \"add\", \"add\", \"add\", \"add\"]\n[[3, [4, 5, 8, 2]], [3], [5], [10], [9], [4]]\nOutput\n[null, 4, 5, 5, 8, 8]\n\nExplanation\nKthLargest kthLargest = new KthLargest(3, [4, 5, 8, 2]);\nkthLargest.add(3); // return 4\nkthLargest.add(5); // return 5\nkthLargest.add(10); // return 5\nkthLargest.add(9); // return 8\nkthLargest.add(4); // return 8" + ], + "constraints": "Constraints:\n\n1 <= k <= 10^4\n0 <= nums.length <= 10^4\n-10^4 <= nums[i] <= 10^4\n-10^4 <= val <= 10^4\nAt most 10^4 calls will be made to add.\nIt is guaranteed that there will be at least k elements in the array when you search for the k^th element.", + "tags": [ + "Tree", + "Design", + "Binary Search Tree", + "Heap (Priority Queue)", + "Binary Tree", + "Data Stream" + ], + "title-slug": "kth-largest-element-in-a-stream" + }, + { + "leetcode-id": 704, + "title": "Binary Search", + "difficulty": 1, + "description": "Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.\nYou must write an algorithm with O(log n) runtime complexity.", + "examples": [ + "Example 1:\nInput: nums = [-1,0,3,5,9,12], target = 9\nOutput: 4\nExplanation: 9 exists in nums and its index is 4", + "Example 2:\nInput: nums = [-1,0,3,5,9,12], target = 2\nOutput: -1\nExplanation: 2 does not exist in nums so return -1" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-10^4 < nums[i], target < 10^4\nAll the integers in nums are unique.\nnums is sorted in ascending order.", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "binary-search" + }, + { + "leetcode-id": 705, + "title": "Design HashSet", + "difficulty": 1, + "description": "Design a HashSet without using any built-in hash table libraries.\nImplement MyHashSet class:\n\nvoid add(key) Inserts the value key into the HashSet.\nbool contains(key) Returns whether the value key exists in the HashSet or not.\nvoid remove(key) Removes the value key in the HashSet. If key does not exist in the HashSet, do nothing.", + "examples": [ + "Example 1:\nInput\n[\"MyHashSet\", \"add\", \"add\", \"contains\", \"contains\", \"add\", \"contains\", \"remove\", \"contains\"]\n[[], [1], [2], [1], [3], [2], [2], [2], [2]]\nOutput\n[null, null, null, true, false, null, true, null, false]\n\nExplanation\nMyHashSet myHashSet = new MyHashSet();\nmyHashSet.add(1); // set = [1]\nmyHashSet.add(2); // set = [1, 2]\nmyHashSet.contains(1); // return True\nmyHashSet.contains(3); // return False, (not found)\nmyHashSet.add(2); // set = [1, 2]\nmyHashSet.contains(2); // return True\nmyHashSet.remove(2); // set = [1]\nmyHashSet.contains(2); // return False, (already removed)" + ], + "constraints": "Constraints:\n\n0 <= key <= 10^6\nAt most 10^4 calls will be made to add, remove, and contains.", + "tags": [ + "Array", + "Hash Table", + "Linked List", + "Design", + "Hash Function" + ], + "title-slug": "design-hashset" + }, + { + "leetcode-id": 706, + "title": "Design HashMap", + "difficulty": 1, + "description": "Design a HashMap without using any built-in hash table libraries.\nImplement the MyHashMap class:\n\nMyHashMap() initializes the object with an empty map.\nvoid put(int key, int value) inserts a (key, value) pair into the HashMap. If the key already exists in the map, update the corresponding value.\nint get(int key) returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key.\nvoid remove(key) removes the key and its corresponding value if the map contains the mapping for the key.", + "examples": [ + "Example 1:\nInput\n[\"MyHashMap\", \"put\", \"put\", \"get\", \"get\", \"put\", \"get\", \"remove\", \"get\"]\n[[], [1, 1], [2, 2], [1], [3], [2, 1], [2], [2], [2]]\nOutput\n[null, null, null, 1, -1, null, 1, null, -1]\n\nExplanation\nMyHashMap myHashMap = new MyHashMap();\nmyHashMap.put(1, 1); // The map is now [[1,1]]\nmyHashMap.put(2, 2); // The map is now [[1,1], [2,2]]\nmyHashMap.get(1); // return 1, The map is now [[1,1], [2,2]]\nmyHashMap.get(3); // return -1 (i.e., not found), The map is now [[1,1], [2,2]]\nmyHashMap.put(2, 1); // The map is now [[1,1], [2,1]] (i.e., update the existing value)\nmyHashMap.get(2); // return 1, The map is now [[1,1], [2,1]]\nmyHashMap.remove(2); // remove the mapping for 2, The map is now [[1,1]]\nmyHashMap.get(2); // return -1 (i.e., not found), The map is now [[1,1]]" + ], + "constraints": "Constraints:\n\n0 <= key, value <= 10^6\nAt most 10^4 calls will be made to put, get, and remove.", + "tags": [ + "Array", + "Hash Table", + "Linked List", + "Design", + "Hash Function" + ], + "title-slug": "design-hashmap" + }, + { + "leetcode-id": 707, + "title": "Design Linked List", + "difficulty": 2, + "description": "Design your implementation of the linked list. You can choose to use a singly or doubly linked list.\nA node in a singly linked list should have two attributes: val and next. val is the value of the current node, and next is a pointer/reference to the next node.\nIf you want to use the doubly linked list, you will need one more attribute prev to indicate the previous node in the linked list. Assume all nodes in the linked list are 0-indexed.\nImplement the MyLinkedList class:\n\nMyLinkedList() Initializes the MyLinkedList object.\nint get(int index) Get the value of the index^th node in the linked list. If the index is invalid, return -1.\nvoid addAtHead(int val) Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.\nvoid addAtTail(int val) Append a node of value val as the last element of the linked list.\nvoid addAtIndex(int index, int val) Add a node of value val before the index^th node in the linked list. If index equals the length of the linked list, the node will be appended to the end of the linked list. If index is greater than the length, the node will not be inserted.\nvoid deleteAtIndex(int index) Delete the index^th node in the linked list, if the index is valid.", + "examples": [ + "Example 1:\nInput\n[\"MyLinkedList\", \"addAtHead\", \"addAtTail\", \"addAtIndex\", \"get\", \"deleteAtIndex\", \"get\"]\n[[], [1], [3], [1, 2], [1], [1], [1]]\nOutput\n[null, null, null, null, 2, null, 3]\n\nExplanation\nMyLinkedList myLinkedList = new MyLinkedList();\nmyLinkedList.addAtHead(1);\nmyLinkedList.addAtTail(3);\nmyLinkedList.addAtIndex(1, 2); // linked list becomes 1->2->3\nmyLinkedList.get(1); // return 2\nmyLinkedList.deleteAtIndex(1); // now the linked list is 1->3\nmyLinkedList.get(1); // return 3" + ], + "constraints": "Constraints:\n\n0 <= index, val <= 1000\nPlease do not use the built-in LinkedList library.\nAt most 2000 calls will be made to get, addAtHead, addAtTail, addAtIndex and deleteAtIndex.", + "tags": [ + "Linked List", + "Design" + ], + "title-slug": "design-linked-list" + }, + { + "leetcode-id": 709, + "title": "To Lower Case", + "difficulty": 1, + "description": "Given a string s, return the string after replacing every uppercase letter with the same lowercase letter.", + "examples": [ + "Example 1:\nInput: s = \"Hello\"\nOutput: \"hello\"", + "Example 2:\nInput: s = \"here\"\nOutput: \"here\"", + "Example 3:\nInput: s = \"LOVELY\"\nOutput: \"lovely\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\ns consists of printable ASCII characters.", + "tags": [ + "String" + ], + "title-slug": "to-lower-case" + }, + { + "leetcode-id": 710, + "title": "Random Pick with Blacklist", + "difficulty": 3, + "description": "You are given an integer n and an array of unique integers blacklist. Design an algorithm to pick a random integer in the range [0, n - 1] that is not in blacklist. Any integer that is in the mentioned range and not in blacklist should be equally likely to be returned.\nOptimize your algorithm such that it minimizes the number of calls to the built-in random function of your language.\nImplement the Solution class:\n\nSolution(int n, int[] blacklist) Initializes the object with the integer n and the blacklisted integers blacklist.\nint pick() Returns a random integer in the range [0, n - 1] and not in blacklist.", + "examples": [ + "Example 1:\nInput\n[\"Solution\", \"pick\", \"pick\", \"pick\", \"pick\", \"pick\", \"pick\", \"pick\"]\n[[7, [2, 3, 5]], [], [], [], [], [], [], []]\nOutput\n[null, 0, 4, 1, 6, 1, 0, 4]\n\nExplanation\nSolution solution = new Solution(7, [2, 3, 5]);\nsolution.pick(); // return 0, any integer from [0,1,4,6] should be ok. Note that for every call of pick,\n // 0, 1, 4, and 6 must be equally likely to be returned (i.e., with probability 1/4).\nsolution.pick(); // return 4\nsolution.pick(); // return 1\nsolution.pick(); // return 6\nsolution.pick(); // return 1\nsolution.pick(); // return 0\nsolution.pick(); // return 4" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^9\n0 <= blacklist.length <= min(10^5, n - 1)\n0 <= blacklist[i] < n\nAll the values of blacklist are unique.\nAt most 2 * 10^4 calls will be made to pick.", + "tags": [ + "Array", + "Hash Table", + "Math", + "Binary Search", + "Sorting", + "Randomized" + ], + "title-slug": "random-pick-with-blacklist" + }, + { + "leetcode-id": 712, + "title": "Minimum ASCII Delete Sum for Two Strings", + "difficulty": 2, + "description": "Given two strings s1 and\u00a0s2, return the lowest ASCII sum of deleted characters to make two strings equal.", + "examples": [ + "Example 1:\nInput: s1 = \"sea\", s2 = \"eat\"\nOutput: 231\nExplanation: Deleting \"s\" from \"sea\" adds the ASCII value of \"s\" (115) to the sum.\nDeleting \"t\" from \"eat\" adds 116 to the sum.\nAt the end, both strings are equal, and 115 + 116 = 231 is the minimum sum possible to achieve this.", + "Example 2:\nInput: s1 = \"delete\", s2 = \"leet\"\nOutput: 403\nExplanation: Deleting \"dee\" from \"delete\" to turn the string into \"let\",\nadds 100[d] + 101[e] + 101[e] to the sum.\nDeleting \"e\" from \"leet\" adds 101[e] to the sum.\nAt the end, both strings are equal to \"let\", and the answer is 100+101+101+101 = 403.\nIf instead we turned both strings into \"lee\" or \"eet\", we would get answers of 433 or 417, which are higher." + ], + "constraints": "Constraints:\n\n1 <= s1.length, s2.length <= 1000\ns1 and s2 consist of lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "minimum-ascii-delete-sum-for-two-strings" + }, + { + "leetcode-id": 713, + "title": "Subarray Product Less Than K", + "difficulty": 2, + "description": "Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than k.", + "examples": [ + "Example 1:\nInput: nums = [10,5,2,6], k = 100\nOutput: 8\nExplanation: The 8 subarrays that have product less than 100 are:\n[10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [5, 2, 6]\nNote that [10, 5, 2] is not included as the product of 100 is not strictly less than k.", + "Example 2:\nInput: nums = [1,2,3], k = 0\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 3 * 10^4\n1 <= nums[i] <= 1000\n0 <= k <= 10^6", + "tags": [ + "Array", + "Sliding Window" + ], + "title-slug": "subarray-product-less-than-k" + }, + { + "leetcode-id": 714, + "title": "Best Time to Buy and Sell Stock with Transaction Fee", + "difficulty": 2, + "description": "You are given an array prices where prices[i] is the price of a given stock on the i^th day, and an integer fee representing a transaction fee.\nFind the maximum profit you can achieve. You may complete as many transactions as you like, but you need to pay the transaction fee for each transaction.\nNote:\n\nYou may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).\nThe transaction fee is only charged once for each stock purchase and sale.", + "examples": [ + "Example 1:\nInput: prices = [1,3,2,8,4,9], fee = 2\nOutput: 8\nExplanation: The maximum profit can be achieved by:\n- Buying at prices[0] = 1\n- Selling at prices[3] = 8\n- Buying at prices[4] = 4\n- Selling at prices[5] = 9\nThe total profit is ((8 - 1) - 2) + ((9 - 4) - 2) = 8.", + "Example 2:\nInput: prices = [1,3,7,5,10,3], fee = 3\nOutput: 6" + ], + "constraints": "Constraints:\n\n1 <= prices.length <= 5 * 10^4\n1 <= prices[i] < 5 * 10^4\n0 <= fee < 5 * 10^4", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "best-time-to-buy-and-sell-stock-with-transaction-fee" + }, + { + "leetcode-id": 715, + "title": "Range Module", + "difficulty": 3, + "description": "A Range Module is a module that tracks ranges of numbers. Design a data structure to track the ranges represented as half-open intervals and query about them.\nA half-open interval [left, right) denotes all the real numbers x where left <= x < right.\nImplement the RangeModule class:\n\nRangeModule() Initializes the object of the data structure.\nvoid addRange(int left, int right) Adds the half-open interval [left, right), tracking every real number in that interval. Adding an interval that partially overlaps with currently tracked numbers should add any numbers in the interval [left, right) that are not already tracked.\nboolean queryRange(int left, int right) Returns true if every real number in the interval [left, right) is currently being tracked, and false otherwise.\nvoid removeRange(int left, int right) Stops tracking every real number currently being tracked in the half-open interval [left, right).", + "examples": [ + "Example 1:\nInput\n[\"RangeModule\", \"addRange\", \"removeRange\", \"queryRange\", \"queryRange\", \"queryRange\"]\n[[], [10, 20], [14, 16], [10, 14], [13, 15], [16, 17]]\nOutput\n[null, null, null, true, false, true]\n\nExplanation\nRangeModule rangeModule = new RangeModule();\nrangeModule.addRange(10, 20);\nrangeModule.removeRange(14, 16);\nrangeModule.queryRange(10, 14); // return True,(Every number in [10, 14) is being tracked)\nrangeModule.queryRange(13, 15); // return False,(Numbers like 14, 14.03, 14.17 in [13, 15) are not being tracked)\nrangeModule.queryRange(16, 17); // return True, (The number 16 in [16, 17) is still being tracked, despite the remove operation)" + ], + "constraints": "Constraints:\n\n1 <= left < right <= 10^9\nAt most 10^4 calls will be made to addRange, queryRange, and removeRange.", + "tags": [ + "Design", + "Segment Tree", + "Ordered Set" + ], + "title-slug": "range-module" + }, + { + "leetcode-id": 717, + "title": "1-bit and 2-bit Characters", + "difficulty": 1, + "description": "We have two special characters:\n\nThe first character can be represented by one bit 0.\nThe second character can be represented by two bits (10 or 11).\n\nGiven a binary array bits that ends with 0, return true if the last character must be a one-bit character.", + "examples": [ + "Example 1:\nInput: bits = [1,0,0]\nOutput: true\nExplanation: The only way to decode it is two-bit character and one-bit character.\nSo the last character is one-bit character.", + "Example 2:\nInput: bits = [1,1,1,0]\nOutput: false\nExplanation: The only way to decode it is two-bit character and two-bit character.\nSo the last character is not one-bit character." + ], + "constraints": "Constraints:\n\n1 <= bits.length <= 1000\nbits[i] is either 0 or 1.", + "tags": [ + "Array" + ], + "title-slug": "1-bit-and-2-bit-characters" + }, + { + "leetcode-id": 718, + "title": "Maximum Length of Repeated Subarray", + "difficulty": 2, + "description": "Given two integer arrays nums1 and nums2, return the maximum length of a subarray that appears in both arrays.", + "examples": [ + "Example 1:\nInput: nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]\nOutput: 3\nExplanation: The repeated subarray with maximum length is [3,2,1].", + "Example 2:\nInput: nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]\nOutput: 5\nExplanation: The repeated subarray with maximum length is [0,0,0,0,0]." + ], + "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 1000\n0 <= nums1[i], nums2[i] <= 100", + "tags": [ + "Array", + "Binary Search", + "Dynamic Programming", + "Sliding Window", + "Rolling Hash", + "Hash Function" + ], + "title-slug": "maximum-length-of-repeated-subarray" + }, + { + "leetcode-id": 719, + "title": "Find K-th Smallest Pair Distance", + "difficulty": 3, + "description": "The distance of a pair of integers a and b is defined as the absolute difference between a and b.\nGiven an integer array nums and an integer k, return the k^th smallest distance among all the pairs nums[i] and nums[j] where 0 <= i < j < nums.length.", + "examples": [ + "Example 1:\nInput: nums = [1,3,1], k = 1\nOutput: 0\nExplanation: Here are all the pairs:\n(1,3) -> 2\n(1,1) -> 0\n(3,1) -> 2\nThen the 1^st smallest distance pair is (1,1), and its distance is 0.", + "Example 2:\nInput: nums = [1,1,1], k = 2\nOutput: 0", + "Example 3:\nInput: nums = [1,6,1], k = 3\nOutput: 5" + ], + "constraints": "Constraints:\n\nn == nums.length\n2 <= n <= 10^4\n0 <= nums[i] <= 10^6\n1 <= k <= n * (n - 1) / 2", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Sorting" + ], + "title-slug": "find-k-th-smallest-pair-distance" + }, + { + "leetcode-id": 720, + "title": "Longest Word in Dictionary", + "difficulty": 2, + "description": "Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.\nIf there is more than one possible answer, return the longest word with the smallest lexicographical order. If there is no answer, return the empty string.\nNote that the word should be built from left to right with each additional character being added to the end of a previous word.", + "examples": [ + "Example 1:\nInput: words = [\"w\",\"wo\",\"wor\",\"worl\",\"world\"]\nOutput: \"world\"\nExplanation: The word \"world\" can be built one character at a time by \"w\", \"wo\", \"wor\", and \"worl\".", + "Example 2:\nInput: words = [\"a\",\"banana\",\"app\",\"appl\",\"ap\",\"apply\",\"apple\"]\nOutput: \"apple\"\nExplanation: Both \"apply\" and \"apple\" can be built from other words in the dictionary. However, \"apple\" is lexicographically smaller than \"apply\"." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 1000\n1 <= words[i].length <= 30\nwords[i] consists of lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Trie", + "Sorting" + ], + "title-slug": "longest-word-in-dictionary" + }, + { + "leetcode-id": 721, + "title": "Accounts Merge", + "difficulty": 2, + "description": "Given a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account.\nNow, we would like to merge these accounts. Two accounts definitely belong to the same person if there is some common email to both accounts. Note that even if two accounts have the same name, they may belong to different people as people could have the same name. A person can have any number of accounts initially, but all of their accounts definitely have the same name.\nAfter merging the accounts, return the accounts in the following format: the first element of each account is the name, and the rest of the elements are emails in sorted order. The accounts themselves can be returned in any order.", + "examples": [ + "Example 1:\nInput: accounts = [[\"John\",\"johnsmith@mail.com\",\"john_newyork@mail.com\"],[\"John\",\"johnsmith@mail.com\",\"john00@mail.com\"],[\"Mary\",\"mary@mail.com\"],[\"John\",\"johnnybravo@mail.com\"]]\nOutput: [[\"John\",\"john00@mail.com\",\"john_newyork@mail.com\",\"johnsmith@mail.com\"],[\"Mary\",\"mary@mail.com\"],[\"John\",\"johnnybravo@mail.com\"]]\nExplanation:\nThe first and second John's are the same person as they have the common email \"johnsmith@mail.com\".\nThe third John and Mary are different people as none of their email addresses are used by other accounts.\nWe could return these lists in any order, for example the answer [['Mary', 'mary@mail.com'], ['John', 'johnnybravo@mail.com'], \n['John', 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com']] would still be accepted.", + "Example 2:\nInput: accounts = [[\"Gabe\",\"Gabe0@m.co\",\"Gabe3@m.co\",\"Gabe1@m.co\"],[\"Kevin\",\"Kevin3@m.co\",\"Kevin5@m.co\",\"Kevin0@m.co\"],[\"Ethan\",\"Ethan5@m.co\",\"Ethan4@m.co\",\"Ethan0@m.co\"],[\"Hanzo\",\"Hanzo3@m.co\",\"Hanzo1@m.co\",\"Hanzo0@m.co\"],[\"Fern\",\"Fern5@m.co\",\"Fern1@m.co\",\"Fern0@m.co\"]]\nOutput: [[\"Ethan\",\"Ethan0@m.co\",\"Ethan4@m.co\",\"Ethan5@m.co\"],[\"Gabe\",\"Gabe0@m.co\",\"Gabe1@m.co\",\"Gabe3@m.co\"],[\"Hanzo\",\"Hanzo0@m.co\",\"Hanzo1@m.co\",\"Hanzo3@m.co\"],[\"Kevin\",\"Kevin0@m.co\",\"Kevin3@m.co\",\"Kevin5@m.co\"],[\"Fern\",\"Fern0@m.co\",\"Fern1@m.co\",\"Fern5@m.co\"]]" + ], + "constraints": "Constraints:\n\n1 <= accounts.length <= 1000\n2 <= accounts[i].length <= 10\n1 <= accounts[i][j].length <= 30\naccounts[i][0] consists of English letters.\naccounts[i][j] (for j > 0) is a valid email.", + "tags": [ + "Array", + "Hash Table", + "String", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Sorting" + ], + "title-slug": "accounts-merge" + }, + { + "leetcode-id": 722, + "title": "Remove Comments", + "difficulty": 2, + "description": "Given a C++ program, remove comments from it. The program source is an array of strings source where source[i] is the i^th line of the source code. This represents the result of splitting the original source code string by the newline character '\\n'.\nIn C++, there are two types of comments, line comments, and block comments.\n\nThe string \"//\" denotes a line comment, which represents that it and the rest of the characters to the right of it in the same line should be ignored.\nThe string \"/*\" denotes a block comment, which represents that all characters until the next (non-overlapping) occurrence of \"*/\" should be ignored. (Here, occurrences happen in reading order: line by line from left to right.) To be clear, the string \"/*/\" does not yet end the block comment, as the ending would be overlapping the beginning.\n\nThe first effective comment takes precedence over others.\n\nFor example, if the string \"//\" occurs in a block comment, it is ignored.\nSimilarly, if the string \"/*\" occurs in a line or block comment, it is also ignored.\n\nIf a certain line of code is empty after removing comments, you must not output that line: each string in the answer list will be non-empty.\nThere will be no control characters, single quote, or double quote characters.\n\nFor example, source = \"string s = \"/* Not a comment. */\";\" will not be a test case.\n\nAlso, nothing else such as defines or macros will interfere with the comments.\nIt is guaranteed that every open block comment will eventually be closed, so \"/*\" outside of a line or block comment always starts a new comment.\nFinally, implicit newline characters can be deleted by block comments. Please see the examples below for details.\nAfter removing the comments from the source code, return the source code in the same format.", + "examples": [ + "Example 1:\nInput: source = [\"/*Test program */\", \"int main()\", \"{ \", \" // variable declaration \", \"int a, b, c;\", \"/* This is a test\", \" multiline \", \" comment for \", \" testing */\", \"a = b + c;\", \"}\"]\nOutput: [\"int main()\",\"{ \",\" \",\"int a, b, c;\",\"a = b + c;\",\"}\"]\nExplanation: The line by line code is visualized as below:\n/*Test program */\nint main()\n{ \n // variable declaration \nint a, b, c;\n/* This is a test\n multiline \n comment for \n testing */\na = b + c;\n}\nThe string /* denotes a block comment, including line 1 and lines 6-9. The string // denotes line 4 as comments.\nThe line by line output code is visualized as below:\nint main()\n{ \n \nint a, b, c;\na = b + c;\n}", + "Example 2:\nInput: source = [\"a/*comment\", \"line\", \"more_comment*/b\"]\nOutput: [\"ab\"]\nExplanation: The original source string is \"a/*comment\\nline\\nmore_comment*/b\", where we have bolded the newline characters. After deletion, the implicit newline characters are deleted, leaving the string \"ab\", which when delimited by newline characters becomes [\"ab\"]." + ], + "constraints": "Constraints:\n\n1 <= source.length <= 100\n0 <= source[i].length <= 80\nsource[i] consists of printable ASCII characters.\nEvery open block comment is eventually closed.\nThere are no single-quote or\u00a0double-quote in the input.", + "tags": [ + "Array", + "String" + ], + "title-slug": "remove-comments" + }, + { + "leetcode-id": 724, + "title": "Find Pivot Index", + "difficulty": 1, + "description": "Given an array of integers nums, calculate the pivot index of this array.\nThe pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.\nIf the index is on the left edge of the array, then the left sum is 0 because there are no elements to the left. This also applies to the right edge of the array.\nReturn the leftmost pivot index. If no such index exists, return -1.", + "examples": [ + "Example 1:\nInput: nums = [1,7,3,6,5,6]\nOutput: 3\nExplanation:\nThe pivot index is 3.\nLeft sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11\nRight sum = nums[4] + nums[5] = 5 + 6 = 11", + "Example 2:\nInput: nums = [1,2,3]\nOutput: -1\nExplanation:\nThere is no index that satisfies the conditions in the problem statement.", + "Example 3:\nInput: nums = [2,1,-1]\nOutput: 0\nExplanation:\nThe pivot index is 0.\nLeft sum = 0 (no elements to the left of index 0)\nRight sum = nums[1] + nums[2] = 1 + -1 = 0" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-1000 <= nums[i] <= 1000\n\n\u00a0\nNote: This question is the same as\u00a01991:\u00a0https://leetcode.com/problems/find-the-middle-index-in-array/", + "tags": [ + "Array", + "Prefix Sum" + ], + "title-slug": "find-pivot-index" + }, + { + "leetcode-id": 725, + "title": "Split Linked List in Parts", + "difficulty": 2, + "description": "Given the head of a singly linked list and an integer k, split the linked list into k consecutive linked list parts.\nThe length of each part should be as equal as possible: no two parts should have a size differing by more than one. This may lead to some parts being null.\nThe parts should be in the order of occurrence in the input list, and parts occurring earlier should always have a size greater than or equal to parts occurring later.\nReturn an array of the k parts.", + "examples": [ + "Example 1:\nInput: head = [1,2,3], k = 5\nOutput: [[1],[2],[3],[],[]]\nExplanation:\nThe first element output[0] has output[0].val = 1, output[0].next = null.\nThe last element output[4] is null, but its string representation as a ListNode is [].", + "Example 2:\nInput: head = [1,2,3,4,5,6,7,8,9,10], k = 3\nOutput: [[1,2,3,4],[5,6,7],[8,9,10]]\nExplanation:\nThe input has been split into consecutive parts with size difference at most 1, and earlier parts are a larger size than the later parts." + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [0, 1000].\n0 <= Node.val <= 1000\n1 <= k <= 50", + "tags": [ + "Linked List" + ], + "title-slug": "split-linked-list-in-parts" + }, + { + "leetcode-id": 726, + "title": "Number of Atoms", + "difficulty": 3, + "description": "Given a string formula representing a chemical formula, return the count of each atom.\nThe atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name.\nOne or more digits representing that element's count may follow if the count is greater than 1. If the count is 1, no digits will follow.\n\nFor example, \"H2O\" and \"H2O2\" are possible, but \"H1O2\" is impossible.\n\nTwo formulas are concatenated together to produce another formula.\n\nFor example, \"H2O2He3Mg4\" is also a formula.\n\nA formula placed in parentheses, and a count (optionally added) is also a formula.\n\nFor example, \"(H2O2)\" and \"(H2O2)3\" are formulas.\n\nReturn the count of all elements as a string in the following form: the first name (in sorted order), followed by its count (if that count is more than 1), followed by the second name (in sorted order), followed by its count (if that count is more than 1), and so on.\nThe test cases are generated so that all the values in the output fit in a 32-bit integer.", + "examples": [ + "Example 1:\nInput: formula = \"H2O\"\nOutput: \"H2O\"\nExplanation: The count of elements are {'H': 2, 'O': 1}.", + "Example 2:\nInput: formula = \"Mg(OH)2\"\nOutput: \"H2MgO2\"\nExplanation: The count of elements are {'H': 2, 'Mg': 1, 'O': 2}.", + "Example 3:\nInput: formula = \"K4(ON(SO3)2)2\"\nOutput: \"K4N2O14S4\"\nExplanation: The count of elements are {'K': 4, 'N': 2, 'O': 14, 'S': 4}." + ], + "constraints": "Constraints:\n\n1 <= formula.length <= 1000\nformula consists of English letters, digits, '(', and ')'.\nformula is always valid.", + "tags": [ + "Hash Table", + "String", + "Stack", + "Sorting" + ], + "title-slug": "number-of-atoms" + }, + { + "leetcode-id": 728, + "title": "Self Dividing Numbers", + "difficulty": 1, + "description": "A self-dividing number is a number that is divisible by every digit it contains.\n\nFor example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.\n\nA self-dividing number is not allowed to contain the digit zero.\nGiven two integers left and right, return a list of all the self-dividing numbers in the range [left, right].", + "examples": [ + "Example 1:\nInput: left = 1, right = 22\nOutput: [1,2,3,4,5,6,7,8,9,11,12,15,22]", + "Example 2:\nInput: left = 47, right = 85\nOutput: [48,55,66,77]" + ], + "constraints": "Constraints:\n\n1 <= left <= right <= 10^4", + "tags": [ + "Math" + ], + "title-slug": "self-dividing-numbers" + }, + { + "leetcode-id": 729, + "title": "My Calendar I", + "difficulty": 2, + "description": "You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a double booking.\nA double booking happens when two events have some non-empty intersection (i.e., some moment is common to both events.).\nThe event can be represented as a pair of integers start and end that represents a booking on the half-open interval [start, end), the range of real numbers x such that start <= x < end.\nImplement the MyCalendar class:\n\nMyCalendar() Initializes the calendar object.\nboolean book(int start, int end) Returns true if the event can be added to the calendar successfully without causing a double booking. Otherwise, return false and do not add the event to the calendar.", + "examples": [ + "Example 1:\nInput\n[\"MyCalendar\", \"book\", \"book\", \"book\"]\n[[], [10, 20], [15, 25], [20, 30]]\nOutput\n[null, true, false, true]\n\nExplanation\nMyCalendar myCalendar = new MyCalendar();\nmyCalendar.book(10, 20); // return True\nmyCalendar.book(15, 25); // return False, It can not be booked because time 15 is already booked by another event.\nmyCalendar.book(20, 30); // return True, The event can be booked, as the first event takes every time less than 20, but not including 20." + ], + "constraints": "Constraints:\n\n0 <= start < end <= 10^9\nAt most 1000 calls will be made to book.", + "tags": [ + "Binary Search", + "Design", + "Segment Tree", + "Ordered Set" + ], + "title-slug": "my-calendar-i" + }, + { + "leetcode-id": 730, + "title": "Count Different Palindromic Subsequences", + "difficulty": 3, + "description": "Given a string s, return the number of different non-empty palindromic subsequences in s. Since the answer may be very large, return it modulo 10^9 + 7.\nA subsequence of a string is obtained by deleting zero or more characters from the string.\nA sequence is palindromic if it is equal to the sequence reversed.\nTwo sequences a1, a2, ... and b1, b2, ... are different if there is some i for which ai != bi.", + "examples": [ + "Example 1:\nInput: s = \"bccb\"\nOutput: 6\nExplanation: The 6 different non-empty palindromic subsequences are 'b', 'c', 'bb', 'cc', 'bcb', 'bccb'.\nNote that 'bcb' is counted only once, even though it occurs twice.", + "Example 2:\nInput: s = \"abcdabcdabcdabcdabcdabcdabcdabcddcbadcbadcbadcbadcbadcbadcbadcba\"\nOutput: 104860361\nExplanation: There are 3104860382 different non-empty palindromic subsequences, which is 104860361 modulo 10^9 + 7." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns[i] is either 'a', 'b', 'c', or 'd'.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "count-different-palindromic-subsequences" + }, + { + "leetcode-id": 731, + "title": "My Calendar II", + "difficulty": 2, + "description": "You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a triple booking.\nA triple booking happens when three events have some non-empty intersection (i.e., some moment is common to all the three events.).\nThe event can be represented as a pair of integers start and end that represents a booking on the half-open interval [start, end), the range of real numbers x such that start <= x < end.\nImplement the MyCalendarTwo class:\n\nMyCalendarTwo() Initializes the calendar object.\nboolean book(int start, int end) Returns true if the event can be added to the calendar successfully without causing a triple booking. Otherwise, return false and do not add the event to the calendar.", + "examples": [ + "Example 1:\nInput\n[\"MyCalendarTwo\", \"book\", \"book\", \"book\", \"book\", \"book\", \"book\"]\n[[], [10, 20], [50, 60], [10, 40], [5, 15], [5, 10], [25, 55]]\nOutput\n[null, true, true, true, false, true, true]\n\nExplanation\nMyCalendarTwo myCalendarTwo = new MyCalendarTwo();\nmyCalendarTwo.book(10, 20); // return True, The event can be booked. \nmyCalendarTwo.book(50, 60); // return True, The event can be booked. \nmyCalendarTwo.book(10, 40); // return True, The event can be double booked. \nmyCalendarTwo.book(5, 15); // return False, The event cannot be booked, because it would result in a triple booking.\nmyCalendarTwo.book(5, 10); // return True, The event can be booked, as it does not use time 10 which is already double booked.\nmyCalendarTwo.book(25, 55); // return True, The event can be booked, as the time in [25, 40) will be double booked with the third event, the time [40, 50) will be single booked, and the time [50, 55) will be double booked with the second event." + ], + "constraints": "Constraints:\n\n0 <= start < end <= 10^9\nAt most 1000 calls will be made to book.", + "tags": [ + "Binary Search", + "Design", + "Segment Tree", + "Ordered Set" + ], + "title-slug": "my-calendar-ii" + }, + { + "leetcode-id": 732, + "title": "My Calendar III", + "difficulty": 3, + "description": "A k-booking happens when k events have some non-empty intersection (i.e., there is some time that is common to all k events.)\nYou are given some events [startTime, endTime), after each given event, return an integer k representing the maximum k-booking between all the previous events.\nImplement the MyCalendarThree class:\n\nMyCalendarThree() Initializes the object.\nint book(int startTime, int endTime) Returns an integer k representing the largest integer such that there exists a k-booking in the calendar.", + "examples": [ + "Example 1:\nInput\n[\"MyCalendarThree\", \"book\", \"book\", \"book\", \"book\", \"book\", \"book\"]\n[[], [10, 20], [50, 60], [10, 40], [5, 15], [5, 10], [25, 55]]\nOutput\n[null, 1, 1, 2, 3, 3, 3]\n\nExplanation\nMyCalendarThree myCalendarThree = new MyCalendarThree();\nmyCalendarThree.book(10, 20); // return 1\nmyCalendarThree.book(50, 60); // return 1\nmyCalendarThree.book(10, 40); // return 2\nmyCalendarThree.book(5, 15); // return 3\nmyCalendarThree.book(5, 10); // return 3\nmyCalendarThree.book(25, 55); // return 3" + ], + "constraints": "Constraints:\n\n0 <= startTime < endTime <= 10^9\nAt most 400 calls will be made to book.", + "tags": [ + "Binary Search", + "Design", + "Segment Tree", + "Ordered Set" + ], + "title-slug": "my-calendar-iii" + }, + { + "leetcode-id": 733, + "title": "Flood Fill", + "difficulty": 1, + "description": "An image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image.\nYou are also given three integers sr, sc, and color. You should perform a flood fill on the image starting from the pixel image[sr][sc].\nTo perform a flood fill, consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also with the same color), and so on. Replace the color of all of the aforementioned pixels with color.\nReturn the modified image after performing the flood fill.", + "examples": [ + "Example 1:\nInput: image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2\nOutput: [[2,2,2],[2,2,0],[2,0,1]]\nExplanation: From the center of the image with position (sr, sc) = (1, 1) (i.e., the red pixel), all pixels connected by a path of the same color as the starting pixel (i.e., the blue pixels) are colored with the new color.\nNote the bottom corner is not colored 2, because it is not 4-directionally connected to the starting pixel.", + "Example 2:\nInput: image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0\nOutput: [[0,0,0],[0,0,0]]\nExplanation: The starting pixel is already colored 0, so no changes are made to the image." + ], + "constraints": "Constraints:\n\nm == image.length\nn == image[i].length\n1 <= m, n <= 50\n0 <= image[i][j], color < 2^16\n0 <= sr < m\n0 <= sc < n", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "flood-fill" + }, + { + "leetcode-id": 735, + "title": "Asteroid Collision", + "difficulty": 2, + "description": "We are given an array asteroids of integers representing asteroids in a row.\nFor each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed.\nFind out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.", + "examples": [ + "Example 1:\nInput: asteroids = [5,10,-5]\nOutput: [5,10]\nExplanation: The 10 and -5 collide resulting in 10. The 5 and 10 never collide.", + "Example 2:\nInput: asteroids = [8,-8]\nOutput: []\nExplanation: The 8 and -8 collide exploding each other.", + "Example 3:\nInput: asteroids = [10,2,-5]\nOutput: [10]\nExplanation: The 2 and -5 collide resulting in -5. The 10 and -5 collide resulting in 10." + ], + "constraints": "Constraints:\n\n2 <= asteroids.length <= 10^4\n-1000 <= asteroids[i] <= 1000\nasteroids[i] != 0", + "tags": [ + "Array", + "Stack", + "Simulation" + ], + "title-slug": "asteroid-collision" + }, + { + "leetcode-id": 736, + "title": "Parse Lisp Expression", + "difficulty": 3, + "description": "You are given a string expression representing a Lisp-like expression to return the integer value of.\nThe syntax for these expressions is given as follows.\n\nAn expression is either an integer, let expression, add expression, mult expression, or an assigned variable. Expressions always evaluate to a single integer.\n(An integer could be positive or negative.)\nA let expression takes the form \"(let v1 e1 v2 e2 ... vn en expr)\", where let is always the string \"let\", then there are one or more pairs of alternating variables and expressions, meaning that the first variable v1 is assigned the value of the expression e1, the second variable v2 is assigned the value of the expression e2, and so on sequentially; and then the value of this let expression is the value of the expression expr.\nAn add expression takes the form \"(add e1 e2)\" where add is always the string \"add\", there are always two expressions e1, e2 and the result is the addition of the evaluation of e1 and the evaluation of e2.\nA mult expression takes the form \"(mult e1 e2)\" where mult is always the string \"mult\", there are always two expressions e1, e2 and the result is the multiplication of the evaluation of e1 and the evaluation of e2.\nFor this question, we will use a smaller subset of variable names. A variable starts with a lowercase letter, then zero or more lowercase letters or digits. Additionally, for your convenience, the names \"add\", \"let\", and \"mult\" are protected and will never be used as variable names.\nFinally, there is the concept of scope. When an expression of a variable name is evaluated, within the context of that evaluation, the innermost scope (in terms of parentheses) is checked first for the value of that variable, and then outer scopes are checked sequentially. It is guaranteed that every expression is legal. Please see the examples for more details on the scope.", + "examples": [ + "Example 1:\nInput: expression = \"(let x 2 (mult x (let x 3 y 4 (add x y))))\"\nOutput: 14\nExplanation: In the expression (add x y), when checking for the value of the variable x,\nwe check from the innermost scope to the outermost in the context of the variable we are trying to evaluate.\nSince x = 3 is found first, the value of x is 3.", + "Example 2:\nInput: expression = \"(let x 3 x 2 x)\"\nOutput: 2\nExplanation: Assignment in let statements is processed sequentially.", + "Example 3:\nInput: expression = \"(let x 1 y 2 x (add x y) (add x y))\"\nOutput: 5\nExplanation: The first (add x y) evaluates as 3, and is assigned to x.\nThe second (add x y) evaluates as 3+2 = 5." + ], + "constraints": "Constraints:\n\n1 <= expression.length <= 2000\nThere are no leading or trailing spaces in expression.\nAll tokens are separated by a single space in expression.\nThe answer and all intermediate calculations of that answer are guaranteed to fit in a 32-bit integer.\nThe expression is guaranteed to be legal and evaluate to an integer.", + "tags": [ + "Hash Table", + "String", + "Stack", + "Recursion" + ], + "title-slug": "parse-lisp-expression" + }, + { + "leetcode-id": 738, + "title": "Monotone Increasing Digits", + "difficulty": 2, + "description": "An integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y.\nGiven an integer n, return the largest number that is less than or equal to n with monotone increasing digits.", + "examples": [ + "Example 1:\nInput: n = 10\nOutput: 9", + "Example 2:\nInput: n = 1234\nOutput: 1234", + "Example 3:\nInput: n = 332\nOutput: 299" + ], + "constraints": "Constraints:\n\n0 <= n <= 10^9", + "tags": [ + "Math", + "Greedy" + ], + "title-slug": "monotone-increasing-digits" + }, + { + "leetcode-id": 739, + "title": "Daily Temperatures", + "difficulty": 2, + "description": "Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the i^th day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.", + "examples": [ + "Example 1:\nInput: temperatures = [73,74,75,71,69,72,76,73]\nOutput: [1,1,4,2,1,1,0,0]", + "Example 2:\nInput: temperatures = [30,40,50,60]\nOutput: [1,1,1,0]", + "Example 3:\nInput: temperatures = [30,60,90]\nOutput: [1,1,0]" + ], + "constraints": "Constraints:\n\n1 <=\u00a0temperatures.length <= 10^5\n30 <=\u00a0temperatures[i] <= 100", + "tags": [ + "Array", + "Stack", + "Monotonic Stack" + ], + "title-slug": "daily-temperatures" + }, + { + "leetcode-id": 740, + "title": "Delete and Earn", + "difficulty": 2, + "description": "You are given an integer array nums. You want to maximize the number of points you get by performing the following operation any number of times:\n\nPick any nums[i] and delete it to earn nums[i] points. Afterwards, you must delete every element equal to nums[i] - 1 and every element equal to nums[i] + 1.\n\nReturn the maximum number of points you can earn by applying the above operation some number of times.", + "examples": [ + "Example 1:\nInput: nums = [3,4,2]\nOutput: 6\nExplanation: You can perform the following operations:\n- Delete 4 to earn 4 points. Consequently, 3 is also deleted. nums = [2].\n- Delete 2 to earn 2 points. nums = [].\nYou earn a total of 6 points.", + "Example 2:\nInput: nums = [2,2,3,3,3,4]\nOutput: 9\nExplanation: You can perform the following operations:\n- Delete a 3 to earn 3 points. All 2's and 4's are also deleted. nums = [3,3].\n- Delete a 3 again to earn 3 points. nums = [3].\n- Delete a 3 once more to earn 3 points. nums = [].\nYou earn a total of 9 points." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 2 * 10^4\n1 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Hash Table", + "Dynamic Programming" + ], + "title-slug": "delete-and-earn" + }, + { + "leetcode-id": 741, + "title": "Cherry Pickup", + "difficulty": 3, + "description": "You are given an n x n grid representing a field of cherries, each cell is one of three possible integers.\n\n0 means the cell is empty, so you can pass through,\n1 means the cell contains a cherry that you can pick up and pass through, or\n-1 means the cell contains a thorn that blocks your way.\n\nReturn the maximum number of cherries you can collect by following the rules below:\n\nStarting at the position (0, 0) and reaching (n - 1, n - 1) by moving right or down through valid path cells (cells with value 0 or 1).\nAfter reaching (n - 1, n - 1), returning to (0, 0) by moving left or up through valid path cells.\nWhen passing through a path cell containing a cherry, you pick it up, and the cell becomes an empty cell 0.\nIf there is no valid path between (0, 0) and (n - 1, n - 1), then no cherries can be collected.", + "examples": [ + "Example 1:\nInput: grid = [[0,1,-1],[1,0,-1],[1,1,1]]\nOutput: 5\nExplanation: The player started at (0, 0) and went down, down, right right to reach (2, 2).\n4 cherries were picked up during this single trip, and the matrix becomes [[0,1,-1],[0,0,-1],[0,0,0]].\nThen, the player went left, up, up, left to return home, picking up one more cherry.\nThe total number of cherries picked up is 5, and this is the maximum possible.", + "Example 2:\nInput: grid = [[1,1,-1],[1,-1,1],[-1,1,1]]\nOutput: 0" + ], + "constraints": "Constraints:\n\nn == grid.length\nn == grid[i].length\n1 <= n <= 50\ngrid[i][j] is -1, 0, or 1.\ngrid[0][0] != -1\ngrid[n - 1][n - 1] != -1", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "cherry-pickup" + }, + { + "leetcode-id": 743, + "title": "Network Delay Time", + "difficulty": 2, + "description": "You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the time it takes for a signal to travel from source to target.\nWe will send a signal from a given node k. Return the minimum time it takes for all the n nodes to receive the signal. If it is impossible for all the n nodes to receive the signal, return -1.", + "examples": [ + "Example 1:\nInput: times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2\nOutput: 2", + "Example 2:\nInput: times = [[1,2,1]], n = 2, k = 1\nOutput: 1", + "Example 3:\nInput: times = [[1,2,1]], n = 2, k = 2\nOutput: -1" + ], + "constraints": "Constraints:\n\n1 <= k <= n <= 100\n1 <= times.length <= 6000\ntimes[i].length == 3\n1 <= ui, vi <= n\nui != vi\n0 <= wi <= 100\nAll the pairs (ui, vi) are unique. (i.e., no multiple edges.)", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Graph", + "Heap (Priority Queue)", + "Shortest Path" + ], + "title-slug": "network-delay-time" + }, + { + "leetcode-id": 744, + "title": "Find Smallest Letter Greater Than Target", + "difficulty": 1, + "description": "You are given an array of characters letters that is sorted in non-decreasing order, and a character target. There are at least two different characters in letters.\nReturn the smallest character in letters that is lexicographically greater than target. If such a character does not exist, return the first character in letters.", + "examples": [ + "Example 1:\nInput: letters = [\"c\",\"f\",\"j\"], target = \"a\"\nOutput: \"c\"\nExplanation: The smallest character that is lexicographically greater than 'a' in letters is 'c'.", + "Example 2:\nInput: letters = [\"c\",\"f\",\"j\"], target = \"c\"\nOutput: \"f\"\nExplanation: The smallest character that is lexicographically greater than 'c' in letters is 'f'.", + "Example 3:\nInput: letters = [\"x\",\"x\",\"y\",\"y\"], target = \"z\"\nOutput: \"x\"\nExplanation: There are no characters in letters that is lexicographically greater than 'z' so we return letters[0]." + ], + "constraints": "Constraints:\n\n2 <= letters.length <= 10^4\nletters[i] is a lowercase English letter.\nletters is sorted in non-decreasing order.\nletters contains at least two different characters.\ntarget is a lowercase English letter.", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "find-smallest-letter-greater-than-target" + }, + { + "leetcode-id": 745, + "title": "Prefix and Suffix Search", + "difficulty": 3, + "description": "Design a special dictionary that searches the words in it by a prefix and a suffix.\nImplement the WordFilter class:\n\nWordFilter(string[] words) Initializes the object with the words in the dictionary.\nf(string pref, string suff) Returns the index of the word in the dictionary, which has the prefix pref and the suffix suff. If there is more than one valid index, return the largest of them. If there is no such word in the dictionary, return -1.", + "examples": [ + "Example 1:\nInput\n[\"WordFilter\", \"f\"]\n[[[\"apple\"]], [\"a\", \"e\"]]\nOutput\n[null, 0]\nExplanation\nWordFilter wordFilter = new WordFilter([\"apple\"]);\nwordFilter.f(\"a\", \"e\"); // return 0, because the word at index 0 has prefix = \"a\" and suffix = \"e\"." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 10^4\n1 <= words[i].length <= 7\n1 <= pref.length, suff.length <= 7\nwords[i], pref and suff consist of lowercase English letters only.\nAt most 10^4 calls will be made to the function f.", + "tags": [ + "Hash Table", + "String", + "Design", + "Trie" + ], + "title-slug": "prefix-and-suffix-search" + }, + { + "leetcode-id": 746, + "title": "Min Cost Climbing Stairs", + "difficulty": 1, + "description": "You are given an integer array cost where cost[i] is the cost of i^th step on a staircase. Once you pay the cost, you can either climb one or two steps.\nYou can either start from the step with index 0, or the step with index 1.\nReturn the minimum cost to reach the top of the floor.", + "examples": [ + "Example 1:\nInput: cost = [10,15,20]\nOutput: 15\nExplanation: You will start at index 1.\n- Pay 15 and climb two steps to reach the top.\nThe total cost is 15.", + "Example 2:\nInput: cost = [1,100,1,1,1,100,1,1,100,1]\nOutput: 6\nExplanation: You will start at index 0.\n- Pay 1 and climb two steps to reach index 2.\n- Pay 1 and climb two steps to reach index 4.\n- Pay 1 and climb two steps to reach index 6.\n- Pay 1 and climb one step to reach index 7.\n- Pay 1 and climb two steps to reach index 9.\n- Pay 1 and climb one step to reach the top.\nThe total cost is 6." + ], + "constraints": "Constraints:\n\n2 <= cost.length <= 1000\n0 <= cost[i] <= 999", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "min-cost-climbing-stairs" + }, + { + "leetcode-id": 747, + "title": "Largest Number At Least Twice of Others", + "difficulty": 1, + "description": "You are given an integer array nums where the largest integer is unique.\nDetermine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, or return -1 otherwise.", + "examples": [ + "Example 1:\nInput: nums = [3,6,1,0]\nOutput: 1\nExplanation: 6 is the largest integer.\nFor every other number in the array x, 6 is at least twice as big as x.\nThe index of value 6 is 1, so we return 1.", + "Example 2:\nInput: nums = [1,2,3,4]\nOutput: -1\nExplanation: 4 is less than twice the value of 3, so we return -1." + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 50\n0 <= nums[i] <= 100\nThe largest element in nums is unique.", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "largest-number-at-least-twice-of-others" + }, + { + "leetcode-id": 748, + "title": "Shortest Completing Word", + "difficulty": 1, + "description": "Given a string licensePlate and an array of strings words, find the shortest completing word in words.\nA completing word is a word that contains all the letters in licensePlate. Ignore numbers and spaces in licensePlate, and treat letters as case insensitive. If a letter appears more than once in licensePlate, then it must appear in the word the same number of times or more.\nFor example, if licensePlate = \"aBc 12c\", then it contains letters 'a', 'b' (ignoring case), and 'c' twice. Possible completing words are \"abccdef\", \"caaacab\", and \"cbca\".\nReturn the shortest completing word in words. It is guaranteed an answer exists. If there are multiple shortest completing words, return the first one that occurs in words.", + "examples": [ + "Example 1:\nInput: licensePlate = \"1s3 PSt\", words = [\"step\",\"steps\",\"stripe\",\"stepple\"]\nOutput: \"steps\"\nExplanation: licensePlate contains letters 's', 'p', 's' (ignoring case), and 't'.\n\"step\" contains 't' and 'p', but only contains 1 's'.\n\"steps\" contains 't', 'p', and both 's' characters.\n\"stripe\" is missing an 's'.\n\"stepple\" is missing an 's'.\nSince \"steps\" is the only word containing all the letters, that is the answer.", + "Example 2:\nInput: licensePlate = \"1s3 456\", words = [\"looks\",\"pest\",\"stew\",\"show\"]\nOutput: \"pest\"\nExplanation: licensePlate only contains the letter 's'. All the words contain 's', but among these \"pest\", \"stew\", and \"show\" are shortest. The answer is \"pest\" because it is the word that appears earliest of the 3." + ], + "constraints": "Constraints:\n\n1 <= licensePlate.length <= 7\nlicensePlate contains digits, letters (uppercase or lowercase), or space ' '.\n1 <= words.length <= 1000\n1 <= words[i].length <= 15\nwords[i] consists of lower case English letters.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "shortest-completing-word" + }, + { + "leetcode-id": 749, + "title": "Contain Virus", + "difficulty": 3, + "description": "A virus is spreading rapidly, and your task is to quarantine the infected area by installing walls.\nThe world is modeled as an m x n binary grid isInfected, where isInfected[i][j] == 0 represents uninfected cells, and isInfected[i][j] == 1 represents cells contaminated with the virus. A wall (and only one wall) can be installed between any two 4-directionally adjacent cells, on the shared boundary.\nEvery night, the virus spreads to all neighboring cells in all four directions unless blocked by a wall. Resources are limited. Each day, you can install walls around only one region (i.e., the affected area (continuous block of infected cells) that threatens the most uninfected cells the following night). There will never be a tie.\nReturn the number of walls used to quarantine all the infected regions. If the world will become fully infected, return the number of walls used.", + "examples": [ + "Example 1:\nInput: isInfected = [[0,1,0,0,0,0,0,1],[0,1,0,0,0,0,0,1],[0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,0]]\nOutput: 10\nExplanation: There are 2 contaminated regions.\nOn the first day, add 5 walls to quarantine the viral region on the left. The board after the virus spreads is:\n\nOn the second day, add 5 walls to quarantine the viral region on the right. The virus is fully contained.", + "Example 2:\nInput: isInfected = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: 4\nExplanation: Even though there is only one cell saved, there are 4 walls built.\nNotice that walls are only built on the shared boundary of two different cells.", + "Example 3:\nInput: isInfected = [[1,1,1,0,0,0,0,0,0],[1,0,1,0,1,1,1,1,1],[1,1,1,0,0,0,0,0,0]]\nOutput: 13\nExplanation: The region on the left only builds two new walls." + ], + "constraints": "Constraints:\n\nm ==\u00a0isInfected.length\nn ==\u00a0isInfected[i].length\n1 <= m, n <= 50\nisInfected[i][j] is either 0 or 1.\nThere is always a contiguous viral region throughout the described process that will infect strictly more uncontaminated squares in the next round.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Matrix", + "Simulation" + ], + "title-slug": "contain-virus" + }, + { + "leetcode-id": 752, + "title": "Open the Lock", + "difficulty": 2, + "description": "You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around: for example we can turn '9' to be '0', or '0' to be '9'. Each move consists of turning one wheel one slot.\nThe lock initially starts at '0000', a string representing the state of the 4 wheels.\nYou are given a list of deadends dead ends, meaning if the lock displays any of these codes, the wheels of the lock will stop turning and you will be unable to open it.\nGiven a target representing the value of the wheels that will unlock the lock, return the minimum total number of turns required to open the lock, or -1 if it is impossible.", + "examples": [ + "Example 1:\nInput: deadends = [\"0201\",\"0101\",\"0102\",\"1212\",\"2002\"], target = \"0202\"\nOutput: 6\nExplanation: \nA sequence of valid moves would be \"0000\" -> \"1000\" -> \"1100\" -> \"1200\" -> \"1201\" -> \"1202\" -> \"0202\".\nNote that a sequence like \"0000\" -> \"0001\" -> \"0002\" -> \"0102\" -> \"0202\" would be invalid,\nbecause the wheels of the lock become stuck after the display becomes the dead end \"0102\".", + "Example 2:\nInput: deadends = [\"8888\"], target = \"0009\"\nOutput: 1\nExplanation: We can turn the last wheel in reverse to move from \"0000\" -> \"0009\".", + "Example 3:\nInput: deadends = [\"8887\",\"8889\",\"8878\",\"8898\",\"8788\",\"8988\",\"7888\",\"9888\"], target = \"8888\"\nOutput: -1\nExplanation: We cannot reach the target without getting stuck." + ], + "constraints": "Constraints:\n\n1 <= deadends.length <= 500\ndeadends[i].length == 4\ntarget.length == 4\ntarget will not be in the list deadends.\ntarget and deadends[i] consist of digits only.", + "tags": [ + "Array", + "Hash Table", + "String", + "Breadth-First Search" + ], + "title-slug": "open-the-lock" + }, + { + "leetcode-id": 753, + "title": "Cracking the Safe", + "difficulty": 3, + "description": "There is a safe protected by a password. The password is a sequence of n digits where each digit can be in the range [0, k - 1].\nThe safe has a peculiar way of checking the password. When you enter in a sequence, it checks the most recent n digits that were entered each time you type a digit.\n\nFor example, the correct password is \"345\" and you enter in \"012345\":\n\n\t\nAfter typing 0, the most recent 3 digits is \"0\", which is incorrect.\nAfter typing 1, the most recent 3 digits is \"01\", which is incorrect.\nAfter typing 2, the most recent 3 digits is \"012\", which is incorrect.\nAfter typing 3, the most recent 3 digits is \"123\", which is incorrect.\nAfter typing 4, the most recent 3 digits is \"234\", which is incorrect.\nAfter typing 5, the most recent 3 digits is \"345\", which is correct and the safe unlocks.\n\n\n\nReturn any string of minimum length that will unlock the safe at some point of entering it.", + "examples": [ + "Example 1:\nInput: n = 1, k = 2\nOutput: \"10\"\nExplanation: The password is a single digit, so enter each digit. \"01\" would also unlock the safe.", + "Example 2:\nInput: n = 2, k = 2\nOutput: \"01100\"\nExplanation: For each possible password:\n- \"00\" is typed in starting from the 4^th digit.\n- \"01\" is typed in starting from the 1^st digit.\n- \"10\" is typed in starting from the 3^rd digit.\n- \"11\" is typed in starting from the 2^nd digit.\nThus \"01100\" will unlock the safe. \"10011\", and \"11001\" would also unlock the safe." + ], + "constraints": "Constraints:\n\n1 <= n <= 4\n1 <= k <= 10\n1 <= k^n <= 4096", + "tags": [ + "Depth-First Search", + "Graph", + "Eulerian Circuit" + ], + "title-slug": "cracking-the-safe" + }, + { + "leetcode-id": 754, + "title": "Reach a Number", + "difficulty": 2, + "description": "You are standing at position 0 on an infinite number line. There is a destination at position target.\nYou can make some number of moves numMoves so that:\n\nOn each move, you can either go left or right.\nDuring the i^th move (starting from i == 1 to i == numMoves), you take i steps in the chosen direction.\n\nGiven the integer target, return the minimum number of moves required (i.e., the minimum numMoves) to reach the destination.", + "examples": [ + "Example 1:\nInput: target = 2\nOutput: 3\nExplanation:\nOn the 1^st move, we step from 0 to 1 (1 step).\nOn the 2^nd move, we step from 1 to -1 (2 steps).\nOn the 3^rd move, we step from -1 to 2 (3 steps).", + "Example 2:\nInput: target = 3\nOutput: 2\nExplanation:\nOn the 1^st move, we step from 0 to 1 (1 step).\nOn the 2^nd move, we step from 1 to 3 (2 steps)." + ], + "constraints": "Constraints:\n\n-10^9 <= target <= 10^9\ntarget != 0", + "tags": [ + "Math", + "Binary Search" + ], + "title-slug": "reach-a-number" + }, + { + "leetcode-id": 756, + "title": "Pyramid Transition Matrix", + "difficulty": 2, + "description": "You are stacking blocks to form a pyramid. Each block has a color, which is represented by a single letter. Each row of blocks contains one less block than the row beneath it and is centered on top.\nTo make the pyramid aesthetically pleasing, there are only specific triangular patterns that are allowed. A triangular pattern consists of a single block stacked on top of two blocks. The patterns are given\u00a0as a list of\u00a0three-letter strings allowed, where the first two characters of a pattern represent the left and right bottom blocks respectively, and the third character is the top block.\n\nFor example, \"ABC\" represents a triangular pattern with a 'C' block stacked on top of an 'A' (left) and 'B' (right) block. Note that this is different from \"BAC\" where 'B' is on the left bottom and 'A' is on the right bottom.\n\nYou start with a bottom row of blocks bottom, given as a single string, that you must use as the base of the pyramid.\nGiven bottom and allowed, return true if you can build the pyramid all the way to the top such that every triangular pattern in the pyramid is in allowed, or false otherwise.", + "examples": [ + "Example 1:\nInput: bottom = \"BCD\", allowed = [\"BCC\",\"CDE\",\"CEA\",\"FFF\"]\nOutput: true\nExplanation: The allowed triangular patterns are shown on the right.\nStarting from the bottom (level 3), we can build \"CE\" on level 2 and then build \"A\" on level 1.\nThere are three triangular patterns in the pyramid, which are \"BCC\", \"CDE\", and \"CEA\". All are allowed.", + "Example 2:\nInput: bottom = \"AAAA\", allowed = [\"AAB\",\"AAC\",\"BCD\",\"BBE\",\"DEF\"]\nOutput: false\nExplanation: The allowed triangular patterns are shown on the right.\nStarting from the bottom (level 4), there are multiple ways to build level 3, but trying all the possibilites, you will get always stuck before building level 1." + ], + "constraints": "Constraints:\n\n2 <= bottom.length <= 6\n0 <= allowed.length <= 216\nallowed[i].length == 3\nThe letters in all input strings are from the set {'A', 'B', 'C', 'D', 'E', 'F'}.\nAll the values of allowed are unique.", + "tags": [ + "Bit Manipulation", + "Depth-First Search", + "Breadth-First Search" + ], + "title-slug": "pyramid-transition-matrix" + }, + { + "leetcode-id": 757, + "title": "Set Intersection Size At Least Two", + "difficulty": 3, + "description": "You are given a 2D integer array intervals where intervals[i] = [starti, endi] represents all the integers from starti to endi inclusively.\nA containing set is an array nums where each interval from intervals has at least two integers in nums.\n\nFor example, if intervals = [[1,3], [3,7], [8,9]], then [1,2,4,7,8,9] and [2,3,4,8,9] are containing sets.\n\nReturn the minimum possible size of a containing set.", + "examples": [ + "Example 1:\nInput: intervals = [[1,3],[3,7],[8,9]]\nOutput: 5\nExplanation: let nums = [2, 3, 4, 8, 9].\nIt can be shown that there cannot be any containing array of size 4.", + "Example 2:\nInput: intervals = [[1,3],[1,4],[2,5],[3,5]]\nOutput: 3\nExplanation: let nums = [2, 3, 4].\nIt can be shown that there cannot be any containing array of size 2.", + "Example 3:\nInput: intervals = [[1,2],[2,3],[2,4],[4,5]]\nOutput: 5\nExplanation: let nums = [1, 2, 3, 4, 5].\nIt can be shown that there cannot be any containing array of size 4." + ], + "constraints": "Constraints:\n\n1 <= intervals.length <= 3000\nintervals[i].length == 2\n0 <= starti < endi <= 10^8", + "tags": [ + "Array", + "Greedy", + "Sorting" + ], + "title-slug": "set-intersection-size-at-least-two" + }, + { + "leetcode-id": 761, + "title": "Special Binary String", + "difficulty": 3, + "description": "Special binary strings are binary strings with the following two properties:\n\nThe number of 0's is equal to the number of 1's.\nEvery prefix of the binary string has at least as many 1's as 0's.\n\nYou are given a special binary string s.\nA move consists of choosing two consecutive, non-empty, special substrings of s, and swapping them. Two strings are consecutive if the last character of the first string is exactly one index before the first character of the second string.\nReturn the lexicographically largest resulting string possible after applying the mentioned operations on the string.", + "examples": [ + "Example 1:\nInput: s = \"11011000\"\nOutput: \"11100100\"\nExplanation: The strings \"10\" [occuring at s[1]] and \"1100\" [at s[3]] are swapped.\nThis is the lexicographically largest string possible after some number of swaps.", + "Example 2:\nInput: s = \"10\"\nOutput: \"10\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 50\ns[i] is either '0' or '1'.\ns is a special binary string.", + "tags": [ + "String", + "Recursion" + ], + "title-slug": "special-binary-string" + }, + { + "leetcode-id": 762, + "title": "Prime Number of Set Bits in Binary Representation", + "difficulty": 1, + "description": "Given two integers left and right, return the count of numbers in the inclusive range [left, right] having a prime number of set bits in their binary representation.\nRecall that the number of set bits an integer has is the number of 1's present when written in binary.\n\nFor example, 21 written in binary is 10101, which has 3 set bits.", + "examples": [ + "Example 1:\nInput: left = 6, right = 10\nOutput: 4\nExplanation:\n6 -> 110 (2 set bits, 2 is prime)\n7 -> 111 (3 set bits, 3 is prime)\n8 -> 1000 (1 set bit, 1 is not prime)\n9 -> 1001 (2 set bits, 2 is prime)\n10 -> 1010 (2 set bits, 2 is prime)\n4 numbers have a prime number of set bits.", + "Example 2:\nInput: left = 10, right = 15\nOutput: 5\nExplanation:\n10 -> 1010 (2 set bits, 2 is prime)\n11 -> 1011 (3 set bits, 3 is prime)\n12 -> 1100 (2 set bits, 2 is prime)\n13 -> 1101 (3 set bits, 3 is prime)\n14 -> 1110 (3 set bits, 3 is prime)\n15 -> 1111 (4 set bits, 4 is not prime)\n5 numbers have a prime number of set bits." + ], + "constraints": "Constraints:\n\n1 <= left <= right <= 10^6\n0 <= right - left <= 10^4", + "tags": [ + "Math", + "Bit Manipulation" + ], + "title-slug": "prime-number-of-set-bits-in-binary-representation" + }, + { + "leetcode-id": 763, + "title": "Partition Labels", + "difficulty": 2, + "description": "You are given a string s. We want to partition the string into as many parts as possible so that each letter appears in at most one part.\nNote that the partition is done so that after concatenating all the parts in order, the resultant string should be s.\nReturn a list of integers representing the size of these parts.", + "examples": [ + "Example 1:\nInput: s = \"ababcbacadefegdehijhklij\"\nOutput: [9,7,8]\nExplanation:\nThe partition is \"ababcbaca\", \"defegde\", \"hijhklij\".\nThis is a partition so that each letter appears in at most one part.\nA partition like \"ababcbacadefegde\", \"hijhklij\" is incorrect, because it splits s into less parts.", + "Example 2:\nInput: s = \"eccbbbbdec\"\nOutput: [10]" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 500\ns consists of lowercase English letters.", + "tags": [ + "Hash Table", + "Two Pointers", + "String", + "Greedy" + ], + "title-slug": "partition-labels" + }, + { + "leetcode-id": 764, + "title": "Largest Plus Sign", + "difficulty": 2, + "description": "You are given an integer n. You have an n x n binary grid grid with all values initially 1's except for some indices given in the array mines. The i^th element of the array mines is defined as mines[i] = [xi, yi] where grid[xi][yi] == 0.\nReturn the order of the largest axis-aligned plus sign of 1's contained in grid. If there is none, return 0.\nAn axis-aligned plus sign of 1's of order k has some center grid[r][c] == 1 along with four arms of length k - 1 going up, down, left, and right, and made of 1's. Note that there could be 0's or 1's beyond the arms of the plus sign, only the relevant area of the plus sign is checked for 1's.", + "examples": [ + "Example 1:\nInput: n = 5, mines = [[4,2]]\nOutput: 2\nExplanation: In the above grid, the largest plus sign can only be of order 2. One of them is shown.", + "Example 2:\nInput: n = 1, mines = [[0,0]]\nOutput: 0\nExplanation: There is no plus sign, so return 0." + ], + "constraints": "Constraints:\n\n1 <= n <= 500\n1 <= mines.length <= 5000\n0 <= xi, yi < n\nAll the pairs (xi, yi) are unique.", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "largest-plus-sign" + }, + { + "leetcode-id": 765, + "title": "Couples Holding Hands", + "difficulty": 3, + "description": "There are n couples sitting in 2n seats arranged in a row and want to hold hands.\nThe people and seats are represented by an integer array row where row[i] is the ID of the person sitting in the i^th seat. The couples are numbered in order, the first couple being (0, 1), the second couple being (2, 3), and so on with the last couple being (2n - 2, 2n - 1).\nReturn the minimum number of swaps so that every couple is sitting side by side. A swap consists of choosing any two people, then they stand up and switch seats.", + "examples": [ + "Example 1:\nInput: row = [0,2,1,3]\nOutput: 1\nExplanation: We only need to swap the second (row[1]) and third (row[2]) person.", + "Example 2:\nInput: row = [3,2,0,1]\nOutput: 0\nExplanation: All couples are already seated side by side." + ], + "constraints": "Constraints:\n\n2n == row.length\n2 <= n <= 30\nn is even.\n0 <= row[i] < 2n\nAll the elements of row are unique.", + "tags": [ + "Greedy", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Graph" + ], + "title-slug": "couples-holding-hands" + }, + { + "leetcode-id": 766, + "title": "Toeplitz Matrix", + "difficulty": 1, + "description": "Given an m x n matrix, return\u00a0true\u00a0if the matrix is Toeplitz. Otherwise, return false.\nA matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.", + "examples": [ + "Example 1:\nInput: matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]\nOutput: true\nExplanation:\nIn the above grid, the\u00a0diagonals are:\n\"[9]\", \"[5, 5]\", \"[1, 1, 1]\", \"[2, 2, 2]\", \"[3, 3]\", \"[4]\".\nIn each diagonal all elements are the same, so the answer is True.", + "Example 2:\nInput: matrix = [[1,2],[2,2]]\nOutput: false\nExplanation:\nThe diagonal \"[1, 2]\" has different elements." + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= m, n <= 20\n0 <= matrix[i][j] <= 99\n\n\u00a0\nFollow up:\n\nWhat if the matrix is stored on disk, and the memory is limited such that you can only load at most one row of the matrix into the memory at once?\nWhat if the matrix is so large that you can only load up a partial row into the memory at once?", + "tags": [ + "Array", + "Matrix" + ], + "title-slug": "toeplitz-matrix" + }, + { + "leetcode-id": 767, + "title": "Reorganize String", + "difficulty": 2, + "description": "Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.\nReturn any possible rearrangement of s or return \"\" if not possible.", + "examples": [ + "Example 1:\nInput: s = \"aab\"\nOutput: \"aba\"", + "Example 2:\nInput: s = \"aaab\"\nOutput: \"\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 500\ns consists of lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Greedy", + "Sorting", + "Heap (Priority Queue)", + "Counting" + ], + "title-slug": "reorganize-string" + }, + { + "leetcode-id": 768, + "title": "Max Chunks To Make Sorted II", + "difficulty": 3, + "description": "You are given an integer array arr.\nWe split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array.\nReturn the largest number of chunks we can make to sort the array.", + "examples": [ + "Example 1:\nInput: arr = [5,4,3,2,1]\nOutput: 1\nExplanation:\nSplitting into two or more chunks will not return the required result.\nFor example, splitting into [5, 4], [3, 2, 1] will result in [4, 5, 1, 2, 3], which isn't sorted.", + "Example 2:\nInput: arr = [2,1,3,4,4]\nOutput: 4\nExplanation:\nWe can split into two chunks, such as [2, 1], [3, 4, 4].\nHowever, splitting into [2, 1], [3], [4], [4] is the highest number of chunks possible." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 2000\n0 <= arr[i] <= 10^8", + "tags": [ + "Array", + "Stack", + "Greedy", + "Sorting", + "Monotonic Stack" + ], + "title-slug": "max-chunks-to-make-sorted-ii" + }, + { + "leetcode-id": 769, + "title": "Max Chunks To Make Sorted", + "difficulty": 2, + "description": "You are given an integer array arr of length n that represents a permutation of the integers in the range [0, n - 1].\nWe split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array.\nReturn the largest number of chunks we can make to sort the array.", + "examples": [ + "Example 1:\nInput: arr = [4,3,2,1,0]\nOutput: 1\nExplanation:\nSplitting into two or more chunks will not return the required result.\nFor example, splitting into [4, 3], [2, 1, 0] will result in [3, 4, 0, 1, 2], which isn't sorted.", + "Example 2:\nInput: arr = [1,0,2,3,4]\nOutput: 4\nExplanation:\nWe can split into two chunks, such as [1, 0], [2, 3, 4].\nHowever, splitting into [1, 0], [2], [3], [4] is the highest number of chunks possible." + ], + "constraints": "Constraints:\n\nn == arr.length\n1 <= n <= 10\n0 <= arr[i] < n\nAll the elements of arr are unique.", + "tags": [ + "Array", + "Stack", + "Greedy", + "Sorting", + "Monotonic Stack" + ], + "title-slug": "max-chunks-to-make-sorted" + }, + { + "leetcode-id": 770, + "title": "Basic Calculator IV", + "difficulty": 3, + "description": "Given an expression such as expression = \"e + 8 - a + 5\" and an evaluation map such as {\"e\": 1} (given in terms of evalvars = [\"e\"] and evalints = [1]), return a list of tokens representing the simplified expression, such as [\"-1*a\",\"14\"]\n\nAn expression alternates chunks and symbols, with a space separating each chunk and symbol.\nA chunk is either an expression in parentheses, a variable, or a non-negative integer.\nA variable is a string of lowercase letters (not including digits.) Note that variables can be multiple letters, and note that variables never have a leading coefficient or unary operator like \"2x\" or \"-x\".\n\nExpressions are evaluated in the usual order: brackets first, then multiplication, then addition and subtraction.\n\nFor example, expression = \"1 + 2 * 3\" has an answer of [\"7\"].\n\nThe format of the output is as follows:\n\nFor each term of free variables with a non-zero coefficient, we write the free variables within a term in sorted order lexicographically.\n\t\nFor example, we would never write a term like \"b*a*c\", only \"a*b*c\".\n\n\nTerms have degrees equal to the number of free variables being multiplied, counting multiplicity. We write the largest degree terms of our answer first, breaking ties by lexicographic order ignoring the leading coefficient of the term.\n\t\nFor example, \"a*a*b*c\" has degree 4.\n\n\nThe leading coefficient of the term is placed directly to the left with an asterisk separating it from the variables (if they exist.) A leading coefficient of 1 is still printed.\nAn example of a well-formatted answer is [\"-2*a*a*a\", \"3*a*a*b\", \"3*b*b\", \"4*a\", \"5*c\", \"-6\"].\nTerms (including constant terms) with coefficient 0 are not included.\n\t\nFor example, an expression of \"0\" has an output of [].\n\n\n\nNote: You may assume that the given expression is always valid. All intermediate results will be in the range of [-2^31, 2^31 - 1].", + "examples": [ + "Example 1:\nInput: expression = \"e + 8 - a + 5\", evalvars = [\"e\"], evalints = [1]\nOutput: [\"-1*a\",\"14\"]", + "Example 2:\nInput: expression = \"e - 8 + temperature - pressure\", evalvars = [\"e\", \"temperature\"], evalints = [1, 12]\nOutput: [\"-1*pressure\",\"5\"]", + "Example 3:\nInput: expression = \"(e + 8) * (e - 8)\", evalvars = [], evalints = []\nOutput: [\"1*e*e\",\"-64\"]" + ], + "constraints": "Constraints:\n\n1 <= expression.length <= 250\nexpression consists of lowercase English letters, digits, '+', '-', '*', '(', ')', ' '.\nexpression does not contain any leading or trailing spaces.\nAll the tokens in expression are separated by a single space.\n0 <= evalvars.length <= 100\n1 <= evalvars[i].length <= 20\nevalvars[i] consists of lowercase English letters.\nevalints.length == evalvars.length\n-100 <= evalints[i] <= 100", + "tags": [ + "Hash Table", + "Math", + "String", + "Stack", + "Recursion" + ], + "title-slug": "basic-calculator-iv" + }, + { + "leetcode-id": 771, + "title": "Jewels and Stones", + "difficulty": 1, + "description": "You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels.\nLetters are case sensitive, so \"a\" is considered a different type of stone from \"A\".", + "examples": [ + "Example 1:\nInput: jewels = \"aA\", stones = \"aAAbbbb\"\nOutput: 3", + "Example 2:\nInput: jewels = \"z\", stones = \"ZZ\"\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <=\u00a0jewels.length, stones.length <= 50\njewels and stones consist of only English letters.\nAll the characters of\u00a0jewels are unique.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "jewels-and-stones" + }, + { + "leetcode-id": 773, + "title": "Sliding Puzzle", + "difficulty": 3, + "description": "On an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0. A move consists of choosing 0 and a 4-directionally adjacent number and swapping it.\nThe state of the board is solved if and only if the board is [[1,2,3],[4,5,0]].\nGiven the puzzle board board, return the least number of moves required so that the state of the board is solved. If it is impossible for the state of the board to be solved, return -1.", + "examples": [ + "Example 1:\nInput: board = [[1,2,3],[4,0,5]]\nOutput: 1\nExplanation: Swap the 0 and the 5 in one move.", + "Example 2:\nInput: board = [[1,2,3],[5,4,0]]\nOutput: -1\nExplanation: No number of moves will make the board solved.", + "Example 3:\nInput: board = [[4,1,2],[5,0,3]]\nOutput: 5\nExplanation: 5 is the smallest number of moves that solves the board.\nAn example path:\nAfter move 0: [[4,1,2],[5,0,3]]\nAfter move 1: [[4,1,2],[0,5,3]]\nAfter move 2: [[0,1,2],[4,5,3]]\nAfter move 3: [[1,0,2],[4,5,3]]\nAfter move 4: [[1,2,0],[4,5,3]]\nAfter move 5: [[1,2,3],[4,5,0]]" + ], + "constraints": "Constraints:\n\nboard.length == 2\nboard[i].length == 3\n0 <= board[i][j] <= 5\nEach value board[i][j] is unique.", + "tags": [ + "Array", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "sliding-puzzle" + }, + { + "leetcode-id": 775, + "title": "Global and Local Inversions", + "difficulty": 2, + "description": "You are given an integer array nums of length n which represents a permutation of all the integers in the range [0, n - 1].\nThe number of global inversions is the number of the different pairs (i, j) where:\n\n0 <= i < j < n\nnums[i] > nums[j]\n\nThe number of local inversions is the number of indices i where:\n\n0 <= i < n - 1\nnums[i] > nums[i + 1]\n\nReturn true if the number of global inversions is equal to the number of local inversions.", + "examples": [ + "Example 1:\nInput: nums = [1,0,2]\nOutput: true\nExplanation: There is 1 global inversion and 1 local inversion.", + "Example 2:\nInput: nums = [1,2,0]\nOutput: false\nExplanation: There are 2 global inversions and 1 local inversion." + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^5\n0 <= nums[i] < n\nAll the integers of nums are unique.\nnums is a permutation of all the numbers in the range [0, n - 1].", + "tags": [ + "Array", + "Math" + ], + "title-slug": "global-and-local-inversions" + }, + { + "leetcode-id": 777, + "title": "Swap Adjacent in LR String", + "difficulty": 2, + "description": "In a string composed of 'L', 'R', and 'X' characters, like \"RXXLRXRXL\", a move consists of either replacing one occurrence of \"XL\" with \"LX\", or replacing one occurrence of \"RX\" with \"XR\". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform one string to the other.", + "examples": [ + "Example 1:\nInput: start = \"RXXLRXRXL\", end = \"XRLXXRRLX\"\nOutput: true\nExplanation: We can transform start to end following these steps:\nRXXLRXRXL ->\nXRXLRXRXL ->\nXRLXRXRXL ->\nXRLXXRRXL ->\nXRLXXRRLX", + "Example 2:\nInput: start = \"X\", end = \"L\"\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= start.length\u00a0<= 10^4\nstart.length == end.length\nBoth start and end will only consist of characters in 'L', 'R', and\u00a0'X'.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "swap-adjacent-in-lr-string" + }, + { + "leetcode-id": 778, + "title": "Swim in Rising Water", + "difficulty": 3, + "description": "You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j).\nThe rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to another 4-directionally adjacent square if and only if the elevation of both squares individually are at most t. You can swim infinite distances in zero time. Of course, you must stay within the boundaries of the grid during your swim.\nReturn the least time until you can reach the bottom right square (n - 1, n - 1) if you start at the top left square (0, 0).", + "examples": [ + "Example 1:\nInput: grid = [[0,2],[1,3]]\nOutput: 3\nExplanation:\nAt time 0, you are in grid location (0, 0).\nYou cannot go anywhere else because 4-directionally adjacent neighbors have a higher elevation than t = 0.\nYou cannot reach point (1, 1) until time 3.\nWhen the depth of water is 3, we can swim anywhere inside the grid.", + "Example 2:\nInput: grid = [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]]\nOutput: 16\nExplanation: The final route is shown.\nWe need to wait until time 16 so that (0, 0) and (4, 4) are connected." + ], + "constraints": "Constraints:\n\nn == grid.length\nn == grid[i].length\n1 <= n <= 50\n0 <= grid[i][j] <\u00a0n^2\nEach value grid[i][j] is unique.", + "tags": [ + "Array", + "Binary Search", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Heap (Priority Queue)", + "Matrix" + ], + "title-slug": "swim-in-rising-water" + }, + { + "leetcode-id": 779, + "title": "K-th Symbol in Grammar", + "difficulty": 2, + "description": "We build a table of n rows (1-indexed). We start by writing 0 in the 1^st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.\n\nFor example, for n = 3, the 1^st row is 0, the 2^nd row is 01, and the 3^rd row is 0110.\n\nGiven two integer n and k, return the k^th (1-indexed) symbol in the n^th row of a table of n rows.", + "examples": [ + "Example 1:\nInput: n = 1, k = 1\nOutput: 0\nExplanation: row 1: 0", + "Example 2:\nInput: n = 2, k = 1\nOutput: 0\nExplanation: \nrow 1: 0\nrow 2: 01", + "Example 3:\nInput: n = 2, k = 2\nOutput: 1\nExplanation: \nrow 1: 0\nrow 2: 01" + ], + "constraints": "Constraints:\n\n1 <= n <= 30\n1 <= k <= 2^n - 1", + "tags": [ + "Math", + "Bit Manipulation", + "Recursion" + ], + "title-slug": "k-th-symbol-in-grammar" + }, + { + "leetcode-id": 780, + "title": "Reaching Points", + "difficulty": 3, + "description": "Given four integers sx, sy, tx, and ty, return true if it is possible to convert the point (sx, sy) to the point (tx, ty) through some operations, or false otherwise.\nThe allowed operation on some point (x, y) is to convert it to either (x, x + y) or (x + y, y).", + "examples": [ + "Example 1:\nInput: sx = 1, sy = 1, tx = 3, ty = 5\nOutput: true\nExplanation:\nOne series of moves that transforms the starting point to the target is:\n(1, 1) -> (1, 2)\n(1, 2) -> (3, 2)\n(3, 2) -> (3, 5)", + "Example 2:\nInput: sx = 1, sy = 1, tx = 2, ty = 2\nOutput: false", + "Example 3:\nInput: sx = 1, sy = 1, tx = 1, ty = 1\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= sx, sy, tx, ty <= 10^9", + "tags": [ + "Math" + ], + "title-slug": "reaching-points" + }, + { + "leetcode-id": 781, + "title": "Rabbits in Forest", + "difficulty": 2, + "description": "There is a forest with an unknown number of rabbits. We asked n rabbits \"How many rabbits have the same color as you?\" and collected the answers in an integer array answers where answers[i] is the answer of the i^th rabbit.\nGiven the array answers, return the minimum number of rabbits that could be in the forest.", + "examples": [ + "Example 1:\nInput: answers = [1,1,2]\nOutput: 5\nExplanation:\nThe two rabbits that answered \"1\" could both be the same color, say red.\nThe rabbit that answered \"2\" can't be red or the answers would be inconsistent.\nSay the rabbit that answered \"2\" was blue.\nThen there should be 2 other blue rabbits in the forest that didn't answer into the array.\nThe smallest possible number of rabbits in the forest is therefore 5: 3 that answered plus 2 that didn't.", + "Example 2:\nInput: answers = [10,10,10]\nOutput: 11" + ], + "constraints": "Constraints:\n\n1 <= answers.length <= 1000\n0 <= answers[i] < 1000", + "tags": [ + "Array", + "Hash Table", + "Math", + "Greedy" + ], + "title-slug": "rabbits-in-forest" + }, + { + "leetcode-id": 782, + "title": "Transform to Chessboard", + "difficulty": 3, + "description": "You are given an n x n binary grid board. In each move, you can swap any two rows with each other, or any two columns with each other.\nReturn the minimum number of moves to transform the board into a chessboard board. If the task is impossible, return -1.\nA chessboard board is a board where no 0's and no 1's are 4-directionally adjacent.", + "examples": [ + "Example 1:\nInput: board = [[0,1,1,0],[0,1,1,0],[1,0,0,1],[1,0,0,1]]\nOutput: 2\nExplanation: One potential sequence of moves is shown.\nThe first move swaps the first and second column.\nThe second move swaps the second and third row.", + "Example 2:\nInput: board = [[0,1],[1,0]]\nOutput: 0\nExplanation: Also note that the board with 0 in the top left corner, is also a valid chessboard.", + "Example 3:\nInput: board = [[1,0],[1,0]]\nOutput: -1\nExplanation: No matter what sequence of moves you make, you cannot end with a valid chessboard." + ], + "constraints": "Constraints:\n\nn == board.length\nn == board[i].length\n2 <= n <= 30\nboard[i][j] is either\u00a00 or 1.", + "tags": [ + "Array", + "Math", + "Bit Manipulation", + "Matrix" + ], + "title-slug": "transform-to-chessboard" + }, + { + "leetcode-id": 783, + "title": "Minimum Distance Between BST Nodes", + "difficulty": 1, + "description": "Given the root of a Binary Search Tree (BST), return the minimum difference between the values of any two different nodes in the tree.", + "examples": [ + "Example 1:\nInput: root = [4,2,6,1,3]\nOutput: 1", + "Example 2:\nInput: root = [1,0,48,null,null,12,49]\nOutput: 1" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [2, 100].\n0 <= Node.val <= 10^5\n\n\u00a0\nNote: This question is the same as 530: https://leetcode.com/problems/minimum-absolute-difference-in-bst/", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "minimum-distance-between-bst-nodes" + }, + { + "leetcode-id": 784, + "title": "Letter Case Permutation", + "difficulty": 2, + "description": "Given a string s, you\u00a0can transform every letter individually to be lowercase or uppercase to create another string.\nReturn a list of all possible strings we could create. Return the output in any order.", + "examples": [ + "Example 1:\nInput: s = \"a1b2\"\nOutput: [\"a1b2\",\"a1B2\",\"A1b2\",\"A1B2\"]", + "Example 2:\nInput: s = \"3z4\"\nOutput: [\"3z4\",\"3Z4\"]" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 12\ns consists of lowercase English letters, uppercase English letters, and digits.", + "tags": [ + "String", + "Backtracking", + "Bit Manipulation" + ], + "title-slug": "letter-case-permutation" + }, + { + "leetcode-id": 785, + "title": "Is Graph Bipartite?", + "difficulty": 2, + "description": "There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. More formally, for each v in graph[u], there is an undirected edge between node u and node v. The graph has the following properties:\n\nThere are no self-edges (graph[u] does not contain u).\nThere are no parallel edges (graph[u] does not contain duplicate values).\nIf v is in graph[u], then u is in graph[v] (the graph is undirected).\nThe graph may not be connected, meaning there may be two nodes u and v such that there is no path between them.\n\nA graph is bipartite if the nodes can be partitioned into two independent sets A and B such that every edge in the graph connects a node in set A and a node in set B.\nReturn true if and only if it is bipartite.", + "examples": [ + "Example 1:\nInput: graph = [[1,2,3],[0,2],[0,1,3],[0,2]]\nOutput: false\nExplanation: There is no way to partition the nodes into two independent sets such that every edge connects a node in one and a node in the other.", + "Example 2:\nInput: graph = [[1,3],[0,2],[1,3],[0,2]]\nOutput: true\nExplanation: We can partition the nodes into two sets: {0, 2} and {1, 3}." + ], + "constraints": "Constraints:\n\ngraph.length == n\n1 <= n <= 100\n0 <= graph[u].length < n\n0 <= graph[u][i] <= n - 1\ngraph[u]\u00a0does not contain\u00a0u.\nAll the values of graph[u] are unique.\nIf graph[u] contains v, then graph[v] contains u.", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Graph" + ], + "title-slug": "is-graph-bipartite" + }, + { + "leetcode-id": 786, + "title": "K-th Smallest Prime Fraction", + "difficulty": 2, + "description": "You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k.\nFor every i and j where 0 <= i < j < arr.length, we consider the fraction arr[i] / arr[j].\nReturn the k^th smallest fraction considered. Return your answer as an array of integers of size 2, where answer[0] == arr[i] and answer[1] == arr[j].", + "examples": [ + "Example 1:\nInput: arr = [1,2,3,5], k = 3\nOutput: [2,5]\nExplanation: The fractions to be considered in sorted order are:\n1/5, 1/3, 2/5, 1/2, 3/5, and 2/3.\nThe third fraction is 2/5.", + "Example 2:\nInput: arr = [1,7], k = 1\nOutput: [1,7]" + ], + "constraints": "Constraints:\n\n2 <= arr.length <= 1000\n1 <= arr[i] <= 3 * 10^4\narr[0] == 1\narr[i] is a prime number for i > 0.\nAll the numbers of arr are unique and sorted in strictly increasing order.\n1 <= k <= arr.length * (arr.length - 1) / 2\n\n\u00a0\nFollow up: Can you solve the problem with better than O(n^2) complexity?", + "tags": [ + "Array", + "Binary Search", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "k-th-smallest-prime-fraction" + }, + { + "leetcode-id": 787, + "title": "Cheapest Flights Within K Stops", + "difficulty": 2, + "description": "There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is a flight from city fromi to city toi with cost pricei.\nYou are also given three integers src, dst, and k, return the cheapest price from src to dst with at most k stops. If there is no such route, return -1.", + "examples": [ + "Example 1:\nInput: n = 4, flights = [[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]], src = 0, dst = 3, k = 1\nOutput: 700\nExplanation:\nThe graph is shown above.\nThe optimal path with at most 1 stop from city 0 to 3 is marked in red and has cost 100 + 600 = 700.\nNote that the path through cities [0,1,2,3] is cheaper but is invalid because it uses 2 stops.", + "Example 2:\nInput: n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 1\nOutput: 200\nExplanation:\nThe graph is shown above.\nThe optimal path with at most 1 stop from city 0 to 2 is marked in red and has cost 100 + 100 = 200.", + "Example 3:\nInput: n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 0\nOutput: 500\nExplanation:\nThe graph is shown above.\nThe optimal path with no stops from city 0 to 2 is marked in red and has cost 500." + ], + "constraints": "Constraints:\n\n1 <= n <= 100\n0 <= flights.length <= (n * (n - 1) / 2)\nflights[i].length == 3\n0 <= fromi, toi < n\nfromi != toi\n1 <= pricei <= 10^4\nThere will not be any multiple flights between two cities.\n0 <= src, dst, k < n\nsrc != dst", + "tags": [ + "Dynamic Programming", + "Depth-First Search", + "Breadth-First Search", + "Graph", + "Heap (Priority Queue)", + "Shortest Path" + ], + "title-slug": "cheapest-flights-within-k-stops" + }, + { + "leetcode-id": 788, + "title": "Rotated Digits", + "difficulty": 2, + "description": "An integer x is a good if after rotating each digit individually by 180 degrees, we get a valid number that is different from x. Each digit must be rotated - we cannot choose to leave it alone.\nA number is valid if each digit remains a digit after rotation. For example:\n\n0, 1, and 8 rotate to themselves,\n2 and 5 rotate to each other (in this case they are rotated in a different direction, in other words, 2 or 5 gets mirrored),\n6 and 9 rotate to each other, and\nthe rest of the numbers do not rotate to any other number and become invalid.\n\nGiven an integer n, return the number of good integers in the range [1, n].", + "examples": [ + "Example 1:\nInput: n = 10\nOutput: 4\nExplanation: There are four good numbers in the range [1, 10] : 2, 5, 6, 9.\nNote that 1 and 10 are not good numbers, since they remain unchanged after rotating.", + "Example 2:\nInput: n = 1\nOutput: 0", + "Example 3:\nInput: n = 2\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^4", + "tags": [ + "Math", + "Dynamic Programming" + ], + "title-slug": "rotated-digits" + }, + { + "leetcode-id": 789, + "title": "Escape The Ghosts", + "difficulty": 2, + "description": "You are playing a simplified PAC-MAN game on an infinite 2-D grid. You start at the point [0, 0], and you are given a destination point target = [xtarget, ytarget] that you are trying to get to. There are several ghosts on the map with their starting positions given as a 2D array ghosts, where ghosts[i] = [xi, yi] represents the starting position of the i^th ghost. All inputs are integral coordinates.\nEach turn, you and all the ghosts may independently choose to either move 1 unit in any of the four cardinal directions: north, east, south, or west, or stay still. All actions happen simultaneously.\nYou escape if and only if you can reach the target before any ghost reaches you. If you reach any square (including the target) at the same time as a ghost, it does not count as an escape.\nReturn true if it is possible to escape regardless of how the ghosts move, otherwise return false.", + "examples": [ + "Example 1:\nInput: ghosts = [[1,0],[0,3]], target = [0,1]\nOutput: true\nExplanation: You can reach the destination (0, 1) after 1 turn, while the ghosts located at (1, 0) and (0, 3) cannot catch up with you.", + "Example 2:\nInput: ghosts = [[1,0]], target = [2,0]\nOutput: false\nExplanation: You need to reach the destination (2, 0), but the ghost at (1, 0) lies between you and the destination.", + "Example 3:\nInput: ghosts = [[2,0]], target = [1,0]\nOutput: false\nExplanation: The ghost can reach the target at the same time as you." + ], + "constraints": "Constraints:\n\n1 <= ghosts.length <= 100\nghosts[i].length == 2\n-10^4 <= xi, yi <= 10^4\nThere can be multiple ghosts in the same location.\ntarget.length == 2\n-10^4 <= xtarget, ytarget <= 10^4", + "tags": [ + "Array", + "Math" + ], + "title-slug": "escape-the-ghosts" + }, + { + "leetcode-id": 790, + "title": "Domino and Tromino Tiling", + "difficulty": 2, + "description": "You have two types of tiles: a 2 x 1 domino shape and a tromino shape. You may rotate these shapes.\n\nGiven an integer n, return the number of ways to tile an 2 x n board. Since the answer may be very large, return it modulo 10^9 + 7.\nIn a tiling, every square must be covered by a tile. Two tilings are different if and only if there are two 4-directionally adjacent cells on the board such that exactly one of the tilings has both squares occupied by a tile.", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: 5\nExplanation: The five different ways are show above.", + "Example 2:\nInput: n = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= n <= 1000", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "domino-and-tromino-tiling" + }, + { + "leetcode-id": 791, + "title": "Custom Sort String", + "difficulty": 2, + "description": "You are given two strings order and s. All the characters of order are unique and were sorted in some custom order previously.\nPermute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a character y in order, then x should occur before y in the permuted string.\nReturn any permutation of s that satisfies this property.", + "examples": [ + "Example 1:\nInput: order = \"cba\", s = \"abcd\"\nOutput: \"cbad\"\nExplanation: \n\"a\", \"b\", \"c\" appear in order, so the order of \"a\", \"b\", \"c\" should be \"c\", \"b\", and \"a\". \nSince \"d\" does not appear in order, it can be at any position in the returned string. \"dcba\", \"cdba\", \"cbda\" are also valid outputs.", + "Example 2:\nInput: order = \"cbafg\", s = \"abcd\"\nOutput: \"cbad\"" + ], + "constraints": "Constraints:\n\n1 <= order.length <= 26\n1 <= s.length <= 200\norder and s consist of lowercase English letters.\nAll the characters of order are unique.", + "tags": [ + "Hash Table", + "String", + "Sorting" + ], + "title-slug": "custom-sort-string" + }, + { + "leetcode-id": 792, + "title": "Number of Matching Subsequences", + "difficulty": 2, + "description": "Given a string s and an array of strings words, return the number of words[i] that is a subsequence of s.\nA subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.\n\nFor example, \"ace\" is a subsequence of \"abcde\".", + "examples": [ + "Example 1:\nInput: s = \"abcde\", words = [\"a\",\"bb\",\"acd\",\"ace\"]\nOutput: 3\nExplanation: There are three strings in words that are a subsequence of s: \"a\", \"acd\", \"ace\".", + "Example 2:\nInput: s = \"dsahjpjauf\", words = [\"ahjpjau\",\"ja\",\"ahbwzgqnuk\",\"tnmlanowax\"]\nOutput: 2" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 5 * 10^4\n1 <= words.length <= 5000\n1 <= words[i].length <= 50\ns and words[i] consist of only lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Binary Search", + "Dynamic Programming", + "Trie", + "Sorting" + ], + "title-slug": "number-of-matching-subsequences" + }, + { + "leetcode-id": 793, + "title": "Preimage Size of Factorial Zeroes Function", + "difficulty": 3, + "description": "Let f(x) be the number of zeroes at the end of x!. Recall that x! = 1 * 2 * 3 * ... * x and by convention, 0! = 1.\n\nFor example, f(3) = 0 because 3! = 6 has no zeroes at the end, while f(11) = 2 because 11! = 39916800 has two zeroes at the end.\n\nGiven an integer k, return the number of non-negative integers x have the property that f(x) = k.", + "examples": [ + "Example 1:\nInput: k = 0\nOutput: 5\nExplanation: 0!, 1!, 2!, 3!, and 4! end with k = 0 zeroes.", + "Example 2:\nInput: k = 5\nOutput: 0\nExplanation: There is no x such that x! ends in k = 5 zeroes.", + "Example 3:\nInput: k = 3\nOutput: 5" + ], + "constraints": "Constraints:\n\n0 <= k <= 10^9", + "tags": [ + "Math", + "Binary Search" + ], + "title-slug": "preimage-size-of-factorial-zeroes-function" + }, + { + "leetcode-id": 794, + "title": "Valid Tic-Tac-Toe State", + "difficulty": 2, + "description": "Given a Tic-Tac-Toe board as a string array board, return true if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.\nThe board is a 3 x 3 array that consists of characters ' ', 'X', and 'O'. The ' ' character represents an empty square.\nHere are the rules of Tic-Tac-Toe:\n\nPlayers take turns placing characters into empty squares ' '.\nThe first player always places 'X' characters, while the second player always places 'O' characters.\n'X' and 'O' characters are always placed into empty squares, never filled ones.\nThe game ends when there are three of the same (non-empty) character filling any row, column, or diagonal.\nThe game also ends if all squares are non-empty.\nNo more moves can be played if the game is over.", + "examples": [ + "Example 1:\nInput: board = [\"O \",\" \",\" \"]\nOutput: false\nExplanation: The first player always plays \"X\".", + "Example 2:\nInput: board = [\"XOX\",\" X \",\" \"]\nOutput: false\nExplanation: Players take turns making moves.", + "Example 3:\nInput: board = [\"XOX\",\"O O\",\"XOX\"]\nOutput: true" + ], + "constraints": "Constraints:\n\nboard.length == 3\nboard[i].length == 3\nboard[i][j] is either 'X', 'O', or ' '.", + "tags": [ + "Array", + "String" + ], + "title-slug": "valid-tic-tac-toe-state" + }, + { + "leetcode-id": 795, + "title": "Number of Subarrays with Bounded Maximum", + "difficulty": 2, + "description": "Given an integer array nums and two integers left and right, return the number of contiguous non-empty subarrays such that the value of the maximum array element in that subarray is in the range [left, right].\nThe test cases are generated so that the answer will fit in a 32-bit integer.", + "examples": [ + "Example 1:\nInput: nums = [2,1,4,3], left = 2, right = 3\nOutput: 3\nExplanation: There are three subarrays that meet the requirements: [2], [2, 1], [3].", + "Example 2:\nInput: nums = [2,9,2,5,6], left = 2, right = 8\nOutput: 7" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^9\n0 <= left <= right <= 10^9", + "tags": [ + "Array", + "Two Pointers" + ], + "title-slug": "number-of-subarrays-with-bounded-maximum" + }, + { + "leetcode-id": 796, + "title": "Rotate String", + "difficulty": 1, + "description": "Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.\nA shift on s consists of moving the leftmost character of s to the rightmost position.\n\nFor example, if s = \"abcde\", then it will be \"bcdea\" after one shift.", + "examples": [ + "Example 1:\nInput: s = \"abcde\", goal = \"cdeab\"\nOutput: true", + "Example 2:\nInput: s = \"abcde\", goal = \"abced\"\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= s.length, goal.length <= 100\ns and goal consist of lowercase English letters.", + "tags": [ + "String", + "String Matching" + ], + "title-slug": "rotate-string" + }, + { + "leetcode-id": 797, + "title": "All Paths From Source to Target", + "difficulty": 2, + "description": "Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1 and return them in any order.\nThe graph is given as follows: graph[i] is a list of all nodes you can visit from node i (i.e., there is a directed edge from node i to node graph[i][j]).", + "examples": [ + "Example 1:\nInput: graph = [[1,2],[3],[3],[]]\nOutput: [[0,1,3],[0,2,3]]\nExplanation: There are two paths: 0 -> 1 -> 3 and 0 -> 2 -> 3.", + "Example 2:\nInput: graph = [[4,3,1],[3,2,4],[3],[4],[]]\nOutput: [[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]" + ], + "constraints": "Constraints:\n\nn == graph.length\n2 <= n <= 15\n0 <= graph[i][j] < n\ngraph[i][j] != i (i.e., there will be no self-loops).\nAll the elements of graph[i] are unique.\nThe input graph is guaranteed to be a DAG.", + "tags": [ + "Backtracking", + "Depth-First Search", + "Breadth-First Search", + "Graph" + ], + "title-slug": "all-paths-from-source-to-target" + }, + { + "leetcode-id": 798, + "title": "Smallest Rotation with Highest Score", + "difficulty": 3, + "description": "You are given an array nums. You can rotate it by a non-negative integer k so that the array becomes [nums[k], nums[k + 1], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1]]. Afterward, any entries that are less than or equal to their index are worth one point.\n\nFor example, if we have nums = [2,4,1,3,0], and we rotate by k = 2, it becomes [1,3,0,2,4]. This is worth 3 points because 1 > 0 [no points], 3 > 1 [no points], 0 <= 2 [one point], 2 <= 3 [one point], 4 <= 4 [one point].\n\nReturn the rotation index k that corresponds to the highest score we can achieve if we rotated nums by it. If there are multiple answers, return the smallest such index k.", + "examples": [ + "Example 1:\nInput: nums = [2,3,1,4,0]\nOutput: 3\nExplanation: Scores for each k are listed below: \nk = 0, nums = [2,3,1,4,0], score 2\nk = 1, nums = [3,1,4,0,2], score 3\nk = 2, nums = [1,4,0,2,3], score 3\nk = 3, nums = [4,0,2,3,1], score 4\nk = 4, nums = [0,2,3,1,4], score 3\nSo we should choose k = 3, which has the highest score.", + "Example 2:\nInput: nums = [1,3,0,2,4]\nOutput: 0\nExplanation: nums will always have 3 points no matter how it shifts.\nSo we will choose the smallest k, which is 0." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] < nums.length", + "tags": [ + "Array", + "Prefix Sum" + ], + "title-slug": "smallest-rotation-with-highest-score" + }, + { + "leetcode-id": 799, + "title": "Champagne Tower", + "difficulty": 2, + "description": "We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100^th row.\u00a0 Each glass holds one cup\u00a0of champagne.\nThen, some champagne is poured into the first glass at the top.\u00a0 When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and right of it.\u00a0 When those glasses become full, any excess champagne will fall equally to the left and right of those glasses, and so on.\u00a0 (A glass at the bottom row has its excess champagne fall on the floor.)\nFor example, after one cup of champagne is poured, the top most glass is full.\u00a0 After two cups of champagne are poured, the two glasses on the second row are half full.\u00a0 After three cups of champagne are poured, those two cups become full - there are 3 full glasses total now.\u00a0 After four cups of champagne are poured, the third row has the middle glass half full, and the two outside glasses are a quarter full, as pictured below.\n\nNow after pouring some non-negative integer cups of champagne, return how full the j^th glass in the i^th row is (both i and j are 0-indexed.)", + "examples": [ + "Example 1:\nInput: poured = 1, query_row = 1, query_glass = 1\r\nOutput: 0.00000\r\nExplanation: We poured 1 cup of champange to the top glass of the tower (which is indexed as (0, 0)). There will be no excess liquid so all the glasses under the top glass will remain empty.", + "Example 2:\nInput: poured = 2, query_row = 1, query_glass = 1\r\nOutput: 0.50000\r\nExplanation: We poured 2 cups of champange to the top glass of the tower (which is indexed as (0, 0)). There is one cup of excess liquid. The glass indexed as (1, 0) and the glass indexed as (1, 1) will share the excess liquid equally, and each will get half cup of champange.", + "Example 3:\nInput: poured = 100000009, query_row = 33, query_glass = 17\r\nOutput: 1.00000" + ], + "constraints": "Constraints:\n\n0 <=\u00a0poured <= 10^9\n0 <= query_glass <= query_row\u00a0< 100", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "champagne-tower" + }, + { + "leetcode-id": 801, + "title": "Minimum Swaps To Make Sequences Increasing", + "difficulty": 3, + "description": "You are given two integer arrays of the same length nums1 and nums2. In one operation, you are allowed to swap nums1[i] with nums2[i].\n\nFor example, if nums1 = [1,2,3,8], and nums2 = [5,6,7,4], you can swap the element at i = 3 to obtain nums1 = [1,2,3,4] and nums2 = [5,6,7,8].\n\nReturn the minimum number of needed operations to make nums1 and nums2 strictly increasing. The test cases are generated so that the given input always makes it possible.\nAn array arr is strictly increasing if and only if arr[0] < arr[1] < arr[2] < ... < arr[arr.length - 1].", + "examples": [ + "Example 1:\nInput: nums1 = [1,3,5,4], nums2 = [1,2,3,7]\nOutput: 1\nExplanation: \nSwap nums1[3] and nums2[3]. Then the sequences are:\nnums1 = [1, 3, 5, 7] and nums2 = [1, 2, 3, 4]\nwhich are both strictly increasing.", + "Example 2:\nInput: nums1 = [0,3,5,8,9], nums2 = [2,1,4,6,9]\nOutput: 1" + ], + "constraints": "Constraints:\n\n2 <= nums1.length <= 10^5\nnums2.length == nums1.length\n0 <= nums1[i], nums2[i] <= 2 * 10^5", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "minimum-swaps-to-make-sequences-increasing" + }, + { + "leetcode-id": 802, + "title": "Find Eventual Safe States", + "difficulty": 2, + "description": "There is a directed graph of n nodes with each node labeled from 0 to n - 1. The graph is represented by a 0-indexed 2D integer array graph where graph[i] is an integer array of nodes adjacent to node i, meaning there is an edge from node i to each node in graph[i].\nA node is a terminal node if there are no outgoing edges. A node is a safe node if every possible path starting from that node leads to a terminal node (or another safe node).\nReturn an array containing all the safe nodes of the graph. The answer should be sorted in ascending order.", + "examples": [ + "Example 1:\nInput: graph = [[1,2],[2,3],[5],[0],[5],[],[]]\nOutput: [2,4,5,6]\nExplanation: The given graph is shown above.\nNodes 5 and 6 are terminal nodes as there are no outgoing edges from either of them.\nEvery path starting at nodes 2, 4, 5, and 6 all lead to either node 5 or 6.", + "Example 2:\nInput: graph = [[1,2,3,4],[1,2],[3,4],[0,4],[]]\nOutput: [4]\nExplanation:\nOnly node 4 is a terminal node, and every path starting at node 4 leads to node 4." + ], + "constraints": "Constraints:\n\nn == graph.length\n1 <= n <= 10^4\n0 <= graph[i].length <= n\n0 <= graph[i][j] <= n - 1\ngraph[i] is sorted in a strictly increasing order.\nThe graph may contain self-loops.\nThe number of edges in the graph will be in the range [1, 4 * 10^4].", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Graph", + "Topological Sort" + ], + "title-slug": "find-eventual-safe-states" + }, + { + "leetcode-id": 803, + "title": "Bricks Falling When Hit", + "difficulty": 3, + "description": "You are given an m x n binary grid, where each 1 represents a brick and 0 represents an empty space. A brick is stable if:\n\nIt is directly connected to the top of the grid, or\nAt least one other brick in its four adjacent cells is stable.\n\nYou are also given an array hits, which is a sequence of erasures we want to apply. Each time we want to erase the brick at the location hits[i] = (rowi, coli). The brick on that location\u00a0(if it exists) will disappear. Some other bricks may no longer be stable because of that erasure and will fall. Once a brick falls, it is immediately erased from the grid (i.e., it does not land on other stable bricks).\nReturn an array result, where each result[i] is the number of bricks that will fall after the i^th erasure is applied.\nNote that an erasure may refer to a location with no brick, and if it does, no bricks drop.", + "examples": [ + "Example 1:\nInput: grid = [[1,0,0,0],[1,1,1,0]], hits = [[1,0]]\nOutput: [2]\nExplanation: Starting with the grid:\n[[1,0,0,0],\n [1,1,1,0]]\nWe erase the underlined brick at (1,0), resulting in the grid:\n[[1,0,0,0],\n [0,1,1,0]]\nThe two underlined bricks are no longer stable as they are no longer connected to the top nor adjacent to another stable brick, so they will fall. The resulting grid is:\n[[1,0,0,0],\n [0,0,0,0]]\nHence the result is [2].", + "Example 2:\nInput: grid = [[1,0,0,0],[1,1,0,0]], hits = [[1,1],[1,0]]\nOutput: [0,0]\nExplanation: Starting with the grid:\n[[1,0,0,0],\n [1,1,0,0]]\nWe erase the underlined brick at (1,1), resulting in the grid:\n[[1,0,0,0],\n [1,0,0,0]]\nAll remaining bricks are still stable, so no bricks fall. The grid remains the same:\n[[1,0,0,0],\n [1,0,0,0]]\nNext, we erase the underlined brick at (1,0), resulting in the grid:\n[[1,0,0,0],\n [0,0,0,0]]\nOnce again, all remaining bricks are still stable, so no bricks fall.\nHence the result is [0,0]." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 200\ngrid[i][j] is 0 or 1.\n1 <= hits.length <= 4 * 10^4\nhits[i].length == 2\n0 <= xi\u00a0<= m - 1\n0 <=\u00a0yi <= n - 1\nAll (xi, yi) are unique.", + "tags": [ + "Array", + "Union Find", + "Matrix" + ], + "title-slug": "bricks-falling-when-hit" + }, + { + "leetcode-id": 804, + "title": "Unique Morse Code Words", + "difficulty": 1, + "description": "International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows:\n\n'a' maps to \".-\",\n'b' maps to \"-...\",\n'c' maps to \"-.-.\", and so on.\n\nFor convenience, the full table for the 26 letters of the English alphabet is given below:\n\n[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]\nGiven an array of strings words where each word can be written as a concatenation of the Morse code of each letter.\n\nFor example, \"cab\" can be written as \"-.-..--...\", which is the concatenation of \"-.-.\", \".-\", and \"-...\". We will call such a concatenation the transformation of a word.\n\nReturn the number of different transformations among all words we have.", + "examples": [ + "Example 1:\nInput: words = [\"gin\",\"zen\",\"gig\",\"msg\"]\nOutput: 2\nExplanation: The transformation of each word is:\n\"gin\" -> \"--...-.\"\n\"zen\" -> \"--...-.\"\n\"gig\" -> \"--...--.\"\n\"msg\" -> \"--...--.\"\nThere are 2 different transformations: \"--...-.\" and \"--...--.\".", + "Example 2:\nInput: words = [\"a\"]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= words.length <= 100\n1 <= words[i].length <= 12\nwords[i] consists of lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "unique-morse-code-words" + }, + { + "leetcode-id": 805, + "title": "Split Array With Same Average", + "difficulty": 3, + "description": "You are given an integer array nums.\nYou should move each element of nums into one of the two arrays A and B such that A and B are non-empty, and average(A) == average(B).\nReturn true if it is possible to achieve that and false otherwise.\nNote that for an array arr, average(arr) is the sum of all the elements of arr over the length of arr.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4,5,6,7,8]\nOutput: true\nExplanation: We can split the array into [1,4,5,8] and [2,3,6,7], and both of them have an average of 4.5.", + "Example 2:\nInput: nums = [3,1]\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 30\n0 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "split-array-with-same-average" + }, + { + "leetcode-id": 806, + "title": "Number of Lines To Write String", + "difficulty": 1, + "description": "You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Specifically, widths[0] is the width of 'a', widths[1] is the width of 'b', and so on.\nYou are trying to write s across several lines, where each line is no longer than 100 pixels. Starting at the beginning of s, write as many letters on the first line such that the total width does not exceed 100 pixels. Then, from where you stopped in s, continue writing as many letters as you can on the second line. Continue this process until you have written all of s.\nReturn an array result of length 2 where:\n\nresult[0] is the total number of lines.\nresult[1] is the width of the last line in pixels.", + "examples": [ + "Example 1:\nInput: widths = [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = \"abcdefghijklmnopqrstuvwxyz\"\nOutput: [3,60]\nExplanation: You can write s as follows:\nabcdefghij // 100 pixels wide\nklmnopqrst // 100 pixels wide\nuvwxyz // 60 pixels wide\nThere are a total of 3 lines, and the last line is 60 pixels wide.", + "Example 2:\nInput: widths = [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = \"bbbcccdddaaa\"\nOutput: [2,4]\nExplanation: You can write s as follows:\nbbbcccdddaa // 98 pixels wide\na // 4 pixels wide\nThere are a total of 2 lines, and the last line is 4 pixels wide." + ], + "constraints": "Constraints:\n\nwidths.length == 26\n2 <= widths[i] <= 10\n1 <= s.length <= 1000\ns contains only lowercase English letters.", + "tags": [ + "Array", + "String" + ], + "title-slug": "number-of-lines-to-write-string" + }, + { + "leetcode-id": 807, + "title": "Max Increase to Keep City Skyline", + "difficulty": 2, + "description": "There is a city composed of n x n blocks, where each block contains a single building shaped like a vertical square prism. You are given a 0-indexed n x n integer matrix grid where grid[r][c] represents the height of the building located in the block at row r and column c.\nA city's skyline is the\u00a0outer contour formed by all the building when viewing the side of the city from a distance. The skyline from each cardinal direction north, east, south, and west may be different.\nWe are allowed to increase the height of any number of buildings by any amount (the amount can be different per building). The height of a 0-height building can also be increased. However, increasing the height of a building should not affect the city's skyline from any cardinal direction.\nReturn the maximum total sum that the height of the buildings can be increased by without changing the city's skyline from any cardinal direction.", + "examples": [ + "Example 1:\nInput: grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]\nOutput: 35\nExplanation: The building heights are shown in the center of the above image.\nThe skylines when viewed from each cardinal direction are drawn in red.\nThe grid after increasing the height of buildings without affecting skylines is:\ngridNew = [ [8, 4, 8, 7],\n [7, 4, 7, 7],\n [9, 4, 8, 7],\n [3, 3, 3, 3] ]", + "Example 2:\nInput: grid = [[0,0,0],[0,0,0],[0,0,0]]\nOutput: 0\nExplanation: Increasing the height of any building will result in the skyline changing." + ], + "constraints": "Constraints:\n\nn == grid.length\nn == grid[r].length\n2 <= n <= 50\n0 <= grid[r][c] <= 100", + "tags": [ + "Array", + "Greedy", + "Matrix" + ], + "title-slug": "max-increase-to-keep-city-skyline" + }, + { + "leetcode-id": 808, + "title": "Soup Servings", + "difficulty": 2, + "description": "There are two types of soup: type A and type B. Initially, we have n ml of each type of soup. There are four kinds of operations:\n\nServe 100 ml of soup A and 0 ml of soup B,\nServe 75 ml of soup A and 25 ml of soup B,\nServe 50 ml of soup A and 50 ml of soup B, and\nServe 25 ml of soup A and 75 ml of soup B.\n\nWhen we serve some soup, we give it to someone, and we no longer have it. Each turn, we will choose from the four operations with an equal probability 0.25. If the remaining volume of soup is not enough to complete the operation, we will serve as much as possible. We stop once we no longer have some quantity of both types of soup.\nNote that we do not have an operation where all 100 ml's of soup B are used first.\nReturn the probability that soup A will be empty first, plus half the probability that A and B become empty at the same time. Answers within 10^-5 of the actual answer will be accepted.", + "examples": [ + "Example 1:\nInput: n = 50\nOutput: 0.62500\nExplanation: If we choose the first two operations, A will become empty first.\nFor the third operation, A and B will become empty at the same time.\nFor the fourth operation, B will become empty first.\nSo the total probability of A becoming empty first plus half the probability that A and B become empty at the same time, is 0.25 * (1 + 1 + 0.5 + 0) = 0.625.", + "Example 2:\nInput: n = 100\nOutput: 0.71875" + ], + "constraints": "Constraints:\n\n0 <= n <= 10^9", + "tags": [ + "Math", + "Dynamic Programming", + "Probability and Statistics" + ], + "title-slug": "soup-servings" + }, + { + "leetcode-id": 809, + "title": "Expressive Words", + "difficulty": 2, + "description": "Sometimes people repeat letters to represent extra feeling. For example:\n\n\"hello\" -> \"heeellooo\"\n\"hi\" -> \"hiiii\"\n\nIn these strings like \"heeellooo\", we have groups of adjacent letters that are all the same: \"h\", \"eee\", \"ll\", \"ooo\".\nYou are given a string s and an array of query strings words. A query word is stretchy if it can be made to be equal to s by any number of applications of the following extension operation: choose a group consisting of characters c, and add some number of characters c to the group so that the size of the group is three or more.\n\nFor example, starting with \"hello\", we could do an extension on the group \"o\" to get \"hellooo\", but we cannot get \"helloo\" since the group \"oo\" has a size less than three. Also, we could do another extension like \"ll\" -> \"lllll\" to get \"helllllooo\". If s = \"helllllooo\", then the query word \"hello\" would be stretchy because of these two extension operations: query = \"hello\" -> \"hellooo\" -> \"helllllooo\" = s.\n\nReturn the number of query strings that are stretchy.", + "examples": [ + "Example 1:\nInput: s = \"heeellooo\", words = [\"hello\", \"hi\", \"helo\"]\nOutput: 1\nExplanation: \nWe can extend \"e\" and \"o\" in the word \"hello\" to get \"heeellooo\".\nWe can't extend \"helo\" to get \"heeellooo\" because the group \"ll\" is not size 3 or more.", + "Example 2:\nInput: s = \"zzzzzyyyyy\", words = [\"zzyy\",\"zy\",\"zyy\"]\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= s.length, words.length <= 100\n1 <= words[i].length <= 100\ns and words[i] consist of lowercase letters.", + "tags": [ + "Array", + "Two Pointers", + "String" + ], + "title-slug": "expressive-words" + }, + { + "leetcode-id": 810, + "title": "Chalkboard XOR Game", + "difficulty": 3, + "description": "You are given an array of integers nums represents the numbers written on a chalkboard.\nAlice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become 0, then that player loses. The bitwise XOR of one element is that element itself, and the bitwise XOR of no elements is 0.\nAlso, if any player starts their turn with the bitwise XOR of all the elements of the chalkboard equal to 0, then that player wins.\nReturn true if and only if Alice wins the game, assuming both players play optimally.", + "examples": [ + "Example 1:\nInput: nums = [1,1,2]\nOutput: false\nExplanation: \nAlice has two choices: erase 1 or erase 2. \nIf she erases 1, the nums array becomes [1, 2]. The bitwise XOR of all the elements of the chalkboard is 1 XOR 2 = 3. Now Bob can remove any element he wants, because Alice will be the one to erase the last element and she will lose. \nIf Alice erases 2 first, now nums become [1, 1]. The bitwise XOR of all the elements of the chalkboard is 1 XOR 1 = 0. Alice will lose.", + "Example 2:\nInput: nums = [0,1]\nOutput: true", + "Example 3:\nInput: nums = [1,2,3]\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n0 <= nums[i] < 2^16", + "tags": [ + "Array", + "Math", + "Bit Manipulation", + "Brainteaser", + "Game Theory" + ], + "title-slug": "chalkboard-xor-game" + }, + { + "leetcode-id": 811, + "title": "Subdomain Visit Count", + "difficulty": 2, + "description": "A website domain \"discuss.leetcode.com\" consists of various subdomains. At the top level, we have \"com\", at the next level, we have \"leetcode.com\"\u00a0and at the lowest level, \"discuss.leetcode.com\". When we visit a domain like \"discuss.leetcode.com\", we will also visit the parent domains \"leetcode.com\" and \"com\" implicitly.\nA count-paired domain is a domain that has one of the two formats \"rep d1.d2.d3\" or \"rep d1.d2\" where rep is the number of visits to the domain and d1.d2.d3 is the domain itself.\n\nFor example, \"9001 discuss.leetcode.com\" is a count-paired domain that indicates that discuss.leetcode.com was visited 9001 times.\n\nGiven an array of count-paired domains cpdomains, return an array of the count-paired domains of each subdomain in the input. You may return the answer in any order.", + "examples": [ + "Example 1:\nInput: cpdomains = [\"9001 discuss.leetcode.com\"]\nOutput: [\"9001 leetcode.com\",\"9001 discuss.leetcode.com\",\"9001 com\"]\nExplanation: We only have one website domain: \"discuss.leetcode.com\".\nAs discussed above, the subdomain \"leetcode.com\" and \"com\" will also be visited. So they will all be visited 9001 times.", + "Example 2:\nInput: cpdomains = [\"900 google.mail.com\", \"50 yahoo.com\", \"1 intel.mail.com\", \"5 wiki.org\"]\nOutput: [\"901 mail.com\",\"50 yahoo.com\",\"900 google.mail.com\",\"5 wiki.org\",\"5 org\",\"1 intel.mail.com\",\"951 com\"]\nExplanation: We will visit \"google.mail.com\" 900 times, \"yahoo.com\" 50 times, \"intel.mail.com\" once and \"wiki.org\" 5 times.\nFor the subdomains, we will visit \"mail.com\" 900 + 1 = 901 times, \"com\" 900 + 50 + 1 = 951 times, and \"org\" 5 times." + ], + "constraints": "Constraints:\n\n1 <= cpdomain.length <= 100\n1 <= cpdomain[i].length <= 100\ncpdomain[i] follows either the \"repi d1i.d2i.d3i\" format or the \"repi d1i.d2i\" format.\nrepi is an integer in the range [1, 10^4].\nd1i, d2i, and d3i consist of lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Counting" + ], + "title-slug": "subdomain-visit-count" + }, + { + "leetcode-id": 812, + "title": "Largest Triangle Area", + "difficulty": 1, + "description": "Given an array of points on the X-Y plane points where points[i] = [xi, yi], return the area of the largest triangle that can be formed by any three different points. Answers within 10^-5 of the actual answer will be accepted.", + "examples": [ + "Example 1:\nInput: points = [[0,0],[0,1],[1,0],[0,2],[2,0]]\nOutput: 2.00000\nExplanation: The five points are shown in the above figure. The red triangle is the largest.", + "Example 2:\nInput: points = [[1,0],[0,0],[0,1]]\nOutput: 0.50000" + ], + "constraints": "Constraints:\n\n3 <= points.length <= 50\n-50 <= xi, yi <= 50\nAll the given points are unique.", + "tags": [ + "Array", + "Math", + "Geometry" + ], + "title-slug": "largest-triangle-area" + }, + { + "leetcode-id": 813, + "title": "Largest Sum of Averages", + "difficulty": 2, + "description": "You are given an integer array nums and an integer k. You can partition the array into at most k non-empty adjacent subarrays. The score of a partition is the sum of the averages of each subarray.\nNote that the partition must use every integer in nums, and that the score is not necessarily an integer.\nReturn the maximum score you can achieve of all the possible partitions. Answers within 10^-6 of the actual answer will be accepted.", + "examples": [ + "Example 1:\nInput: nums = [9,1,2,3,9], k = 3\nOutput: 20.00000\nExplanation: \nThe best choice is to partition nums into [9], [1, 2, 3], [9]. The answer is 9 + (1 + 2 + 3) / 3 + 9 = 20.\nWe could have also partitioned nums into [9, 1], [2], [3, 9], for example.\nThat partition would lead to a score of 5 + 2 + 6 = 13, which is worse.", + "Example 2:\nInput: nums = [1,2,3,4,5,6,7], k = 4\nOutput: 20.50000" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 10^4\n1 <= k <= nums.length", + "tags": [ + "Array", + "Dynamic Programming", + "Prefix Sum" + ], + "title-slug": "largest-sum-of-averages" + }, + { + "leetcode-id": 814, + "title": "Binary Tree Pruning", + "difficulty": 2, + "description": "Given the root of a binary tree, return the same tree where every subtree (of the given tree) not containing a 1 has been removed.\nA subtree of a node node is node plus every node that is a descendant of node.", + "examples": [ + "Example 1:\nInput: root = [1,null,0,0,1]\nOutput: [1,null,0,null,1]\nExplanation: \nOnly the red nodes satisfy the property \"every subtree not containing a 1\".\nThe diagram on the right represents the answer.", + "Example 2:\nInput: root = [1,0,1,0,0,0,1]\nOutput: [1,null,1,null,1]", + "Example 3:\nInput: root = [1,1,0,1,1,0,1,0]\nOutput: [1,1,0,1,1,null,1]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 200].\nNode.val is either 0 or 1.", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "binary-tree-pruning" + }, + { + "leetcode-id": 815, + "title": "Bus Routes", + "difficulty": 3, + "description": "You are given an array routes representing bus routes where routes[i] is a bus route that the i^th bus repeats forever.\n\nFor example, if routes[0] = [1, 5, 7], this means that the 0^th bus travels in the sequence 1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ... forever.\n\nYou will start at the bus stop source (You are not on any bus initially), and you want to go to the bus stop target. You can travel between bus stops by buses only.\nReturn the least number of buses you must take to travel from source to target. Return -1 if it is not possible.", + "examples": [ + "Example 1:\nInput: routes = [[1,2,7],[3,6,7]], source = 1, target = 6\nOutput: 2\nExplanation: The best strategy is take the first bus to the bus stop 7, then take the second bus to the bus stop 6.", + "Example 2:\nInput: routes = [[7,12],[4,5,15],[6],[15,19],[9,12,13]], source = 15, target = 12\nOutput: -1" + ], + "constraints": "Constraints:\n\n1 <= routes.length <= 500.\n1 <= routes[i].length <= 10^5\nAll the values of routes[i] are unique.\nsum(routes[i].length) <= 10^5\n0 <= routes[i][j] < 10^6\n0 <= source, target < 10^6", + "tags": [ + "Array", + "Hash Table", + "Breadth-First Search" + ], + "title-slug": "bus-routes" + }, + { + "leetcode-id": 816, + "title": "Ambiguous Coordinates", + "difficulty": 2, + "description": "We had some 2-dimensional coordinates, like \"(1, 3)\" or \"(2, 0.5)\". Then, we removed all commas, decimal points, and spaces and ended up with the string s.\n\nFor example, \"(1, 3)\" becomes s = \"(13)\" and \"(2, 0.5)\" becomes s = \"(205)\".\n\nReturn a list of strings representing all possibilities for what our original coordinates could have been.\nOur original representation never had extraneous zeroes, so we never started with numbers like \"00\", \"0.0\", \"0.00\", \"1.0\", \"001\", \"00.01\", or any other number that can be represented with fewer digits. Also, a decimal point within a number never occurs without at least one digit occurring before it, so we never started with numbers like \".1\".\nThe final answer list can be returned in any order. All coordinates in the final answer have exactly one space between them (occurring after the comma.)", + "examples": [ + "Example 1:\nInput: s = \"(123)\"\nOutput: [\"(1, 2.3)\",\"(1, 23)\",\"(1.2, 3)\",\"(12, 3)\"]", + "Example 2:\nInput: s = \"(0123)\"\nOutput: [\"(0, 1.23)\",\"(0, 12.3)\",\"(0, 123)\",\"(0.1, 2.3)\",\"(0.1, 23)\",\"(0.12, 3)\"]\nExplanation: 0.0, 00, 0001 or 00.01 are not allowed.", + "Example 3:\nInput: s = \"(00011)\"\nOutput: [\"(0, 0.011)\",\"(0.001, 1)\"]" + ], + "constraints": "Constraints:\n\n4 <= s.length <= 12\ns[0] == '(' and s[s.length - 1] == ')'.\nThe rest of s are digits.", + "tags": [ + "String", + "Backtracking" + ], + "title-slug": "ambiguous-coordinates" + }, + { + "leetcode-id": 817, + "title": "Linked List Components", + "difficulty": 2, + "description": "You are given the head of a linked list containing unique integer values and an integer array nums that is a subset of the linked list values.\nReturn the number of connected components in nums where two values are connected if they appear consecutively in the linked list.", + "examples": [ + "Example 1:\nInput: head = [0,1,2,3], nums = [0,1,3]\nOutput: 2\nExplanation: 0 and 1 are connected, so [0, 1] and [3] are the two connected components.", + "Example 2:\nInput: head = [0,1,2,3,4], nums = [0,3,1,4]\nOutput: 2\nExplanation: 0 and 1 are connected, 3 and 4 are connected, so [0, 1] and [3, 4] are the two connected components." + ], + "constraints": "Constraints:\n\nThe number of nodes in the linked list is n.\n1 <= n <= 10^4\n0 <= Node.val < n\nAll the values Node.val are unique.\n1 <= nums.length <= n\n0 <= nums[i] < n\nAll the values of nums are unique.", + "tags": [ + "Array", + "Hash Table", + "Linked List" + ], + "title-slug": "linked-list-components" + }, + { + "leetcode-id": 818, + "title": "Race Car", + "difficulty": 3, + "description": "Your car starts at position 0 and speed +1 on an infinite number line. Your car can go into negative positions. Your car drives automatically according to a sequence of instructions 'A' (accelerate) and 'R' (reverse):\n\nWhen you get an instruction 'A', your car does the following:\n\n\t\nposition += speed\nspeed *= 2\n\n\nWhen you get an instruction 'R', your car does the following:\n\t\nIf your speed is positive then speed = -1\notherwise speed = 1\n\n\tYour position stays the same.\n\nFor example, after commands \"AAR\", your car goes to positions 0 --> 1 --> 3 --> 3, and your speed goes to 1 --> 2 --> 4 --> -1.\nGiven a target position target, return the length of the shortest sequence of instructions to get there.", + "examples": [ + "Example 1:\nInput: target = 3\nOutput: 2\nExplanation: \nThe shortest instruction sequence is \"AA\".\nYour position goes from 0 --> 1 --> 3.", + "Example 2:\nInput: target = 6\nOutput: 5\nExplanation: \nThe shortest instruction sequence is \"AAARA\".\nYour position goes from 0 --> 1 --> 3 --> 7 --> 7 --> 6." + ], + "constraints": "Constraints:\n\n1 <= target <= 10^4", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "race-car" + }, + { + "leetcode-id": 819, + "title": "Most Common Word", + "difficulty": 1, + "description": "Given a string paragraph and a string array of the banned words banned, return the most frequent word that is not banned. It is guaranteed there is at least one word that is not banned, and that the answer is unique.\nThe words in paragraph are case-insensitive and the answer should be returned in lowercase.", + "examples": [ + "Example 1:\nInput: paragraph = \"Bob hit a ball, the hit BALL flew far after it was hit.\", banned = [\"hit\"]\nOutput: \"ball\"\nExplanation: \n\"hit\" occurs 3 times, but it is a banned word.\n\"ball\" occurs twice (and no other word does), so it is the most frequent non-banned word in the paragraph. \nNote that words in the paragraph are not case sensitive,\nthat punctuation is ignored (even if adjacent to words, such as \"ball,\"), \nand that \"hit\" isn't the answer even though it occurs more because it is banned.", + "Example 2:\nInput: paragraph = \"a.\", banned = []\nOutput: \"a\"" + ], + "constraints": "Constraints:\n\n1 <= paragraph.length <= 1000\nparagraph consists of English letters, space ' ', or one of the symbols: \"!?',;.\".\n0 <= banned.length <= 100\n1 <= banned[i].length <= 10\nbanned[i] consists of only lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Counting" + ], + "title-slug": "most-common-word" + }, + { + "leetcode-id": 820, + "title": "Short Encoding of Words", + "difficulty": 2, + "description": "A valid encoding of an array of words is any reference string s and array of indices indices such that:\n\nwords.length == indices.length\nThe reference string s ends with the '#' character.\nFor each index indices[i], the substring of s starting from indices[i] and up to (but not including) the next '#' character is equal to words[i].\n\nGiven an array of words, return the length of the shortest reference string s possible of any valid encoding of words.", + "examples": [ + "Example 1:\nInput: words = [\"time\", \"me\", \"bell\"]\nOutput: 10\nExplanation: A valid encoding would be s = \"time#bell#\" and indices = [0, 2, 5].\nwords[0] = \"time\", the substring of s starting from indices[0] = 0 to the next '#' is underlined in \"time#bell#\"\nwords[1] = \"me\", the substring of s starting from indices[1] = 2 to the next '#' is underlined in \"time#bell#\"\nwords[2] = \"bell\", the substring of s starting from indices[2] = 5 to the next '#' is underlined in \"time#bell#\"", + "Example 2:\nInput: words = [\"t\"]\nOutput: 2\nExplanation: A valid encoding would be s = \"t#\" and indices = [0]." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 2000\n1 <= words[i].length <= 7\nwords[i] consists of only lowercase letters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Trie" + ], + "title-slug": "short-encoding-of-words" + }, + { + "leetcode-id": 821, + "title": "Shortest Distance to a Character", + "difficulty": 1, + "description": "Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s.\nThe distance between two indices i and j is abs(i - j), where abs is the absolute value function.", + "examples": [ + "Example 1:\nInput: s = \"loveleetcode\", c = \"e\"\nOutput: [3,2,1,0,1,0,0,1,2,2,1,0]\nExplanation: The character 'e' appears at indices 3, 5, 6, and 11 (0-indexed).\nThe closest occurrence of 'e' for index 0 is at index 3, so the distance is abs(0 - 3) = 3.\nThe closest occurrence of 'e' for index 1 is at index 3, so the distance is abs(1 - 3) = 2.\nFor index 4, there is a tie between the 'e' at index 3 and the 'e' at index 5, but the distance is still the same: abs(4 - 3) == abs(4 - 5) = 1.\nThe closest occurrence of 'e' for index 8 is at index 6, so the distance is abs(8 - 6) = 2.", + "Example 2:\nInput: s = \"aaab\", c = \"b\"\nOutput: [3,2,1,0]" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^4\ns[i] and c are lowercase English letters.\nIt is guaranteed that c occurs at least once in s.", + "tags": [ + "Array", + "Two Pointers", + "String" + ], + "title-slug": "shortest-distance-to-a-character" + }, + { + "leetcode-id": 822, + "title": "Card Flipping Game", + "difficulty": 2, + "description": "You are given two 0-indexed integer arrays fronts and backs of length n, where the i^th card has the positive integer fronts[i] printed on the front and backs[i] printed on the back. Initially, each card is placed on a table such that the front number is facing up and the other is facing down. You may flip over any number of cards (possibly zero).\nAfter flipping the cards, an integer is considered good if it is facing down on some card and not facing up on any card.\nReturn the minimum possible good integer after flipping the cards. If there are no good integers, return 0.", + "examples": [ + "Example 1:\nInput: fronts = [1,2,4,4,7], backs = [1,3,4,1,3]\nOutput: 2\nExplanation:\nIf we flip the second card, the face up numbers are [1,3,4,4,7] and the face down are [1,2,4,1,3].\n2 is the minimum good integer as it appears facing down but not facing up.\nIt can be shown that 2 is the minimum possible good integer obtainable after flipping some cards.", + "Example 2:\nInput: fronts = [1], backs = [1]\nOutput: 0\nExplanation:\nThere are no good integers no matter how we flip the cards, so we return 0." + ], + "constraints": "Constraints:\n\nn == fronts.length == backs.length\n1 <= n <= 1000\n1 <= fronts[i], backs[i] <= 2000", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "card-flipping-game" + }, + { + "leetcode-id": 823, + "title": "Binary Trees With Factors", + "difficulty": 2, + "description": "Given an array of unique integers, arr, where each integer arr[i] is strictly greater than 1.\nWe make a binary tree using these integers, and each number may be used for any number of times. Each non-leaf node's value should be equal to the product of the values of its children.\nReturn the number of binary trees we can make. The answer may be too large so return the answer modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: arr = [2,4]\nOutput: 3\nExplanation: We can make these trees: [2], [4], [4, 2, 2]", + "Example 2:\nInput: arr = [2,4,5,10]\nOutput: 7\nExplanation: We can make these trees: [2], [4], [5], [10], [4, 2, 2], [10, 2, 5], [10, 5, 2]." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 1000\n2 <= arr[i] <= 10^9\nAll the values of arr are unique.", + "tags": [ + "Array", + "Hash Table", + "Dynamic Programming", + "Sorting" + ], + "title-slug": "binary-trees-with-factors" + }, + { + "leetcode-id": 824, + "title": "Goat Latin", + "difficulty": 1, + "description": "You are given a string sentence that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only.\nWe would like to convert the sentence to \"Goat Latin\" (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows:\n\nIf a word begins with a vowel ('a', 'e', 'i', 'o', or 'u'), append \"ma\" to the end of the word.\n\n\t\nFor example, the word \"apple\" becomes \"applema\".\n\n\nIf a word begins with a consonant (i.e., not a vowel), remove the first letter and append it to the end, then add \"ma\".\n\t\nFor example, the word \"goat\" becomes \"oatgma\".\n\n\nAdd one letter 'a' to the end of each word per its word index in the sentence, starting with 1.\n\t\nFor example, the first word gets \"a\" added to the end, the second word gets \"aa\" added to the end, and so on.\n\n\n\nReturn the final sentence representing the conversion from sentence to Goat Latin.", + "examples": [ + "Example 1:\nInput: sentence = \"I speak Goat Latin\"\nOutput: \"Imaa peaksmaaa oatGmaaaa atinLmaaaaa\"", + "Example 2:\nInput: sentence = \"The quick brown fox jumped over the lazy dog\"\nOutput: \"heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa\"" + ], + "constraints": "Constraints:\n\n1 <= sentence.length <= 150\nsentence consists of English letters and spaces.\nsentence has no leading or trailing spaces.\nAll the words in sentence are separated by a single space.", + "tags": [ + "String" + ], + "title-slug": "goat-latin" + }, + { + "leetcode-id": 825, + "title": "Friends Of Appropriate Ages", + "difficulty": 2, + "description": "There are n persons on a social media website. You are given an integer array ages where ages[i] is the age of the i^th person.\nA Person x will not send a friend request to a person y (x != y) if any of the following conditions is true:\n\nage[y] <= 0.5 * age[x] + 7\nage[y] > age[x]\nage[y] > 100 && age[x] < 100\n\nOtherwise, x will send a friend request to y.\nNote that if x sends a request to y, y will not necessarily send a request to x. Also, a person will not send a friend request to themself.\nReturn the total number of friend requests made.", + "examples": [ + "Example 1:\nInput: ages = [16,16]\nOutput: 2\nExplanation: 2 people friend request each other.", + "Example 2:\nInput: ages = [16,17,18]\nOutput: 2\nExplanation: Friend requests are made 17 -> 16, 18 -> 17.", + "Example 3:\nInput: ages = [20,30,100,110,120]\nOutput: 3\nExplanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100." + ], + "constraints": "Constraints:\n\nn == ages.length\n1 <= n <= 2 * 10^4\n1 <= ages[i] <= 120", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Sorting" + ], + "title-slug": "friends-of-appropriate-ages" + }, + { + "leetcode-id": 826, + "title": "Most Profit Assigning Work", + "difficulty": 2, + "description": "You have n jobs and m workers. You are given three arrays: difficulty, profit, and worker where:\n\ndifficulty[i] and profit[i] are the difficulty and the profit of the i^th job, and\nworker[j] is the ability of j^th worker (i.e., the j^th worker can only complete a job with difficulty at most worker[j]).\n\nEvery worker can be assigned at most one job, but one job can be completed multiple times.\n\nFor example, if three workers attempt the same job that pays $1, then the total profit will be $3. If a worker cannot complete any job, their profit is $0.\n\nReturn the maximum profit we can achieve after assigning the workers to the jobs.", + "examples": [ + "Example 1:\nInput: difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7]\nOutput: 100\nExplanation: Workers are assigned jobs of difficulty [4,4,6,6] and they get a profit of [20,20,30,30] separately.", + "Example 2:\nInput: difficulty = [85,47,57], profit = [24,66,99], worker = [40,25,25]\nOutput: 0" + ], + "constraints": "Constraints:\n\nn == difficulty.length\nn == profit.length\nm == worker.length\n1 <= n, m <= 10^4\n1 <= difficulty[i], profit[i], worker[i] <= 10^5", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Greedy", + "Sorting" + ], + "title-slug": "most-profit-assigning-work" + }, + { + "leetcode-id": 827, + "title": "Making A Large Island", + "difficulty": 3, + "description": "You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1.\nReturn the size of the largest island in grid after applying this operation.\nAn island is a 4-directionally connected group of 1s.", + "examples": [ + "Example 1:\nInput: grid = [[1,0],[0,1]]\r\nOutput: 3\r\nExplanation: Change one 0 to 1 and connect two 1s, then we get an island with area = 3.", + "Example 2:\nInput: grid = [[1,1],[1,0]]\r\nOutput: 4\r\nExplanation: Change the 0 to 1 and make the island bigger, only one island with area = 4.", + "Example 3:\nInput: grid = [[1,1],[1,1]]\r\nOutput: 4\r\nExplanation: Can't change any 0 to 1, only one island with area = 4." + ], + "constraints": "Constraints:\n\nn == grid.length\nn == grid[i].length\n1 <= n <= 500\ngrid[i][j] is either 0 or 1.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Matrix" + ], + "title-slug": "making-a-large-island" + }, + { + "leetcode-id": 828, + "title": "Count Unique Characters of All Substrings of a Given String", + "difficulty": 3, + "description": "Let's define a function countUniqueChars(s) that returns the number of unique characters in\u00a0s.\n\nFor example, calling countUniqueChars(s) if s = \"LEETCODE\" then \"L\", \"T\", \"C\", \"O\", \"D\" are the unique characters since they appear only once in s, therefore countUniqueChars(s) = 5.\n\nGiven a string s, return the sum of countUniqueChars(t) where t is a substring of s. The test cases are generated such that the answer fits in a 32-bit integer.\nNotice that some substrings can be repeated so in this case you have to count the repeated ones too.", + "examples": [ + "Example 1:\nInput: s = \"ABC\"\nOutput: 10\nExplanation: All possible substrings are: \"A\",\"B\",\"C\",\"AB\",\"BC\" and \"ABC\".\nEvery substring is composed with only unique letters.\nSum of lengths of all substring is 1 + 1 + 1 + 2 + 2 + 3 = 10", + "Example 2:\nInput: s = \"ABA\"\nOutput: 8\nExplanation: The same as example 1, except countUniqueChars(\"ABA\") = 1.", + "Example 3:\nInput: s = \"LEETCODE\"\nOutput: 92" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of uppercase English letters only.", + "tags": [ + "Hash Table", + "String", + "Dynamic Programming" + ], + "title-slug": "count-unique-characters-of-all-substrings-of-a-given-string" + }, + { + "leetcode-id": 829, + "title": "Consecutive Numbers Sum", + "difficulty": 3, + "description": "Given an integer n, return the number of ways you can write n as the sum of consecutive positive integers.", + "examples": [ + "Example 1:\nInput: n = 5\nOutput: 2\nExplanation: 5 = 2 + 3", + "Example 2:\nInput: n = 9\nOutput: 3\nExplanation: 9 = 4 + 5 = 2 + 3 + 4", + "Example 3:\nInput: n = 15\nOutput: 4\nExplanation: 15 = 8 + 7 = 4 + 5 + 6 = 1 + 2 + 3 + 4 + 5" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^9", + "tags": [ + "Math", + "Enumeration" + ], + "title-slug": "consecutive-numbers-sum" + }, + { + "leetcode-id": 830, + "title": "Positions of Large Groups", + "difficulty": 1, + "description": "In a string s\u00a0of lowercase letters, these letters form consecutive groups of the same character.\nFor example, a string like s = \"abbxxxxzyy\" has the groups \"a\", \"bb\", \"xxxx\", \"z\", and\u00a0\"yy\".\nA group is identified by an interval\u00a0[start, end], where\u00a0start\u00a0and\u00a0end\u00a0denote the start and end\u00a0indices (inclusive) of the group. In the above example,\u00a0\"xxxx\"\u00a0has the interval\u00a0[3,6].\nA group is considered\u00a0large\u00a0if it has 3 or more characters.\nReturn\u00a0the intervals of every large group sorted in\u00a0increasing order by start index.", + "examples": [ + "Example 1:\nInput: s = \"abbxxxxzzy\"\nOutput: [[3,6]]\nExplanation: \"xxxx\" is the only large group with start index 3 and end index 6.", + "Example 2:\nInput: s = \"abc\"\nOutput: []\nExplanation: We have groups \"a\", \"b\", and \"c\", none of which are large groups.", + "Example 3:\nInput: s = \"abcdddeeeeaabbbcd\"\nOutput: [[3,5],[6,9],[12,14]]\nExplanation: The large groups are \"ddd\", \"eeee\", and \"bbb\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns contains lowercase English letters only.", + "tags": [ + "String" + ], + "title-slug": "positions-of-large-groups" + }, + { + "leetcode-id": 831, + "title": "Masking Personal Information", + "difficulty": 2, + "description": "You are given a personal information string s, representing either an email address or a phone number. Return the masked personal information using the below rules.\nEmail address:\nAn email address is:\n\nA name consisting of uppercase and lowercase English letters, followed by\nThe '@' symbol, followed by\nThe domain consisting of uppercase and lowercase English letters with a dot '.' somewhere in the middle (not the first or last character).\n\nTo mask an email:\n\nThe uppercase letters in the name and domain must be converted to lowercase letters.\nThe middle letters of the name (i.e., all but the first and last letters) must be replaced by 5 asterisks \"*****\".\n\nPhone number:\nA phone number is formatted as follows:\n\nThe phone number contains 10-13 digits.\nThe last 10 digits make up the local number.\nThe remaining 0-3 digits, in the beginning, make up the country code.\nSeparation characters from the set {'+', '-', '(', ')', ' '} separate the above digits in some way.\n\nTo mask a phone number:\n\nRemove all separation characters.\nThe masked phone number should have the form:\n\t\n\"***-***-XXXX\" if the country code has 0 digits.\n\"+*-***-***-XXXX\" if the country code has 1 digit.\n\"+**-***-***-XXXX\" if the country code has 2 digits.\n\"+***-***-***-XXXX\" if the country code has 3 digits.\n\n\n\"XXXX\" is the last 4 digits of the local number.", + "examples": [ + "Example 1:\nInput: s = \"LeetCode@LeetCode.com\"\nOutput: \"l*****e@leetcode.com\"\nExplanation: s is an email address.\nThe name and domain are converted to lowercase, and the middle of the name is replaced by 5 asterisks.", + "Example 2:\nInput: s = \"AB@qq.com\"\nOutput: \"a*****b@qq.com\"\nExplanation: s is an email address.\nThe name and domain are converted to lowercase, and the middle of the name is replaced by 5 asterisks.\nNote that even though \"ab\" is 2 characters, it still must have 5 asterisks in the middle.", + "Example 3:\nInput: s = \"1(234)567-890\"\nOutput: \"***-***-7890\"\nExplanation: s is a phone number.\nThere are 10 digits, so the local number is 10 digits and the country code is 0 digits.\nThus, the resulting masked number is \"***-***-7890\"." + ], + "constraints": "Constraints:\n\ns is either a valid email or a phone number.\nIf s is an email:\n\t\n8 <= s.length <= 40\ns consists of uppercase and lowercase English letters and exactly one '@' symbol and '.' symbol.\n\n\nIf s is a phone number:\n\t\n10 <= s.length <= 20\ns consists of digits, spaces, and the symbols '(', ')', '-', and '+'.", + "tags": [ + "String" + ], + "title-slug": "masking-personal-information" + }, + { + "leetcode-id": 832, + "title": "Flipping an Image", + "difficulty": 1, + "description": "Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image.\nTo flip an image horizontally means that each row of the image is reversed.\n\nFor example, flipping [1,1,0] horizontally results in [0,1,1].\n\nTo invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0.\n\nFor example, inverting [0,1,1] results in [1,0,0].", + "examples": [ + "Example 1:\nInput: image = [[1,1,0],[1,0,1],[0,0,0]]\nOutput: [[1,0,0],[0,1,0],[1,1,1]]\nExplanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].\nThen, invert the image: [[1,0,0],[0,1,0],[1,1,1]]", + "Example 2:\nInput: image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]\nOutput: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\nExplanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]].\nThen invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]" + ], + "constraints": "Constraints:\n\nn == image.length\nn == image[i].length\n1 <= n <= 20\nimages[i][j] is either 0 or 1.", + "tags": [ + "Array", + "Two Pointers", + "Matrix", + "Simulation" + ], + "title-slug": "flipping-an-image" + }, + { + "leetcode-id": 833, + "title": "Find And Replace in String", + "difficulty": 2, + "description": "You are given a 0-indexed string s that you must perform k replacement operations on. The replacement operations are given as three 0-indexed parallel arrays, indices, sources, and targets, all of length k.\nTo complete the i^th replacement operation:\n\nCheck if the substring sources[i] occurs at index indices[i] in the original string s.\nIf it does not occur, do nothing.\nOtherwise if it does occur, replace that substring with targets[i].\n\nFor example, if s = \"abcd\", indices[i] = 0, sources[i] = \"ab\", and targets[i] = \"eee\", then the result of this replacement will be \"eeecd\".\nAll replacement operations must occur simultaneously, meaning the replacement operations should not affect the indexing of each other. The testcases will be generated such that the replacements will not overlap.\n\nFor example, a testcase with s = \"abc\", indices = [0, 1], and sources = [\"ab\",\"bc\"] will not be generated because the \"ab\" and \"bc\" replacements overlap.\n\nReturn the resulting string after performing all replacement operations on s.\nA substring is a contiguous sequence of characters in a string.", + "examples": [ + "Example 1:\nInput: s = \"abcd\", indices = [0, 2], sources = [\"a\", \"cd\"], targets = [\"eee\", \"ffff\"]\nOutput: \"eeebffff\"\nExplanation:\n\"a\" occurs at index 0 in s, so we replace it with \"eee\".\n\"cd\" occurs at index 2 in s, so we replace it with \"ffff\".", + "Example 2:\nInput: s = \"abcd\", indices = [0, 2], sources = [\"ab\",\"ec\"], targets = [\"eee\",\"ffff\"]\nOutput: \"eeecd\"\nExplanation:\n\"ab\" occurs at index 0 in s, so we replace it with \"eee\".\n\"ec\" does not occur at index 2 in s, so we do nothing." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\nk == indices.length == sources.length == targets.length\n1 <= k <= 100\n0 <= indexes[i] < s.length\n1 <= sources[i].length, targets[i].length <= 50\ns consists of only lowercase English letters.\nsources[i] and targets[i] consist of only lowercase English letters.", + "tags": [ + "Array", + "String", + "Sorting" + ], + "title-slug": "find-and-replace-in-string" + }, + { + "leetcode-id": 834, + "title": "Sum of Distances in Tree", + "difficulty": 3, + "description": "There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.\nYou are given the integer n and the array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\nReturn an array answer of length n where answer[i] is the sum of the distances between the i^th node in the tree and all other nodes.", + "examples": [ + "Example 1:\nInput: n = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]\nOutput: [8,12,6,10,10,10]\nExplanation: The tree is shown above.\nWe can see that dist(0,1) + dist(0,2) + dist(0,3) + dist(0,4) + dist(0,5)\nequals 1 + 1 + 2 + 2 + 2 = 8.\nHence, answer[0] = 8, and so on.", + "Example 2:\nInput: n = 1, edges = []\nOutput: [0]", + "Example 3:\nInput: n = 2, edges = [[1,0]]\nOutput: [1,1]" + ], + "constraints": "Constraints:\n\n1 <= n <= 3 * 10^4\nedges.length == n - 1\nedges[i].length == 2\n0 <= ai, bi < n\nai != bi\nThe given input represents a valid tree.", + "tags": [ + "Dynamic Programming", + "Tree", + "Depth-First Search", + "Graph" + ], + "title-slug": "sum-of-distances-in-tree" + }, + { + "leetcode-id": 835, + "title": "Image Overlap", + "difficulty": 2, + "description": "You are given two images, img1 and img2, represented as binary, square matrices of size n x n. A binary matrix has only 0s and 1s as values.\nWe translate one image however we choose by sliding all the 1 bits left, right, up, and/or down any number of units. We then place it on top of the other image. We can then calculate the overlap by counting the number of positions that have a 1 in both images.\nNote also that a translation does not include any kind of rotation. Any 1 bits that are translated outside of the matrix borders are erased.\nReturn the largest possible overlap.", + "examples": [ + "Example 1:\nInput: img1 = [[1,1,0],[0,1,0],[0,1,0]], img2 = [[0,0,0],[0,1,1],[0,0,1]]\nOutput: 3\nExplanation: We translate img1 to right by 1 unit and down by 1 unit.\n\nThe number of positions that have a 1 in both images is 3 (shown in red).", + "Example 2:\nInput: img1 = [[1]], img2 = [[1]]\nOutput: 1", + "Example 3:\nInput: img1 = [[0]], img2 = [[0]]\nOutput: 0" + ], + "constraints": "Constraints:\n\nn == img1.length == img1[i].length\nn == img2.length == img2[i].length\n1 <= n <= 30\nimg1[i][j] is either 0 or 1.\nimg2[i][j] is either 0 or 1.", + "tags": [ + "Array", + "Matrix" + ], + "title-slug": "image-overlap" + }, + { + "leetcode-id": 836, + "title": "Rectangle Overlap", + "difficulty": 1, + "description": "An axis-aligned rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) is the coordinate of its bottom-left corner, and (x2, y2) is the coordinate of its top-right corner. Its top and bottom edges are parallel to the X-axis, and its left and right edges are parallel to the Y-axis.\nTwo rectangles overlap if the area of their intersection is positive. To be clear, two rectangles that only touch at the corner or edges do not overlap.\nGiven two axis-aligned rectangles rec1 and rec2, return true if they overlap, otherwise return false.", + "examples": [ + "Example 1:\nInput: rec1 = [0,0,2,2], rec2 = [1,1,3,3]\nOutput: true", + "Example 2:\nInput: rec1 = [0,0,1,1], rec2 = [1,0,2,1]\nOutput: false", + "Example 3:\nInput: rec1 = [0,0,1,1], rec2 = [2,2,3,3]\nOutput: false" + ], + "constraints": "Constraints:\n\nrec1.length == 4\nrec2.length == 4\n-10^9 <= rec1[i], rec2[i] <= 10^9\nrec1 and rec2 represent a valid rectangle with a non-zero area.", + "tags": [ + "Math", + "Geometry" + ], + "title-slug": "rectangle-overlap" + }, + { + "leetcode-id": 837, + "title": "New 21 Game", + "difficulty": 2, + "description": "Alice plays the following game, loosely based on the card game \"21\".\nAlice starts with 0 points and draws numbers while she has less than k points. During each draw, she gains an integer number of points randomly from the range [1, maxPts], where maxPts is an integer. Each draw is independent and the outcomes have equal probabilities.\nAlice stops drawing numbers when she gets k or more points.\nReturn the probability that Alice has n or fewer points.\nAnswers within 10^-5 of the actual answer are considered accepted.", + "examples": [ + "Example 1:\nInput: n = 10, k = 1, maxPts = 10\nOutput: 1.00000\nExplanation: Alice gets a single card, then stops.", + "Example 2:\nInput: n = 6, k = 1, maxPts = 10\nOutput: 0.60000\nExplanation: Alice gets a single card, then stops.\nIn 6 out of 10 possibilities, she is at or below 6 points.", + "Example 3:\nInput: n = 21, k = 17, maxPts = 10\nOutput: 0.73278" + ], + "constraints": "Constraints:\n\n0 <= k <= n <= 10^4\n1 <= maxPts <= 10^4", + "tags": [ + "Math", + "Dynamic Programming", + "Sliding Window", + "Probability and Statistics" + ], + "title-slug": "new-21-game" + }, + { + "leetcode-id": 838, + "title": "Push Dominoes", + "difficulty": 2, + "description": "There are n dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to the left or to the right.\nAfter each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right.\nWhen a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces.\nFor the purposes of this question, we will consider that a falling domino expends no additional force to a falling or already fallen domino.\nYou are given a string dominoes representing the initial state where:\n\ndominoes[i] = 'L', if the i^th domino has been pushed to the left,\ndominoes[i] = 'R', if the i^th domino has been pushed to the right, and\ndominoes[i] = '.', if the i^th domino has not been pushed.\n\nReturn a string representing the final state.", + "examples": [ + "Example 1:\nInput: dominoes = \"RR.L\"\nOutput: \"RR.L\"\nExplanation: The first domino expends no additional force on the second domino.", + "Example 2:\nInput: dominoes = \".L.R...LR..L..\"\nOutput: \"LL.RR.LLRRLL..\"" + ], + "constraints": "Constraints:\n\nn == dominoes.length\n1 <= n <= 10^5\ndominoes[i] is either 'L', 'R', or '.'.", + "tags": [ + "Two Pointers", + "String", + "Dynamic Programming" + ], + "title-slug": "push-dominoes" + }, + { + "leetcode-id": 839, + "title": "Similar String Groups", + "difficulty": 3, + "description": "Two strings, X and Y, are considered similar if either they are identical or we can make them equivalent by swapping at most two letters (in distinct positions) within the string X.\nFor example, \"tars\"\u00a0and \"rats\"\u00a0are similar (swapping at positions 0 and 2), and \"rats\" and \"arts\" are similar, but \"star\" is not similar to \"tars\", \"rats\", or \"arts\".\nTogether, these form two connected groups by similarity: {\"tars\", \"rats\", \"arts\"} and {\"star\"}.\u00a0 Notice that \"tars\" and \"arts\" are in the same group even though they are not similar.\u00a0 Formally, each group is such that a word is in the group if and only if it is similar to at least one other word in the group.\nWe are given a list strs of strings where every string in strs is an anagram of every other string in strs. How many groups are there?", + "examples": [ + "Example 1:\nInput: strs = [\"tars\",\"rats\",\"arts\",\"star\"]\nOutput: 2", + "Example 2:\nInput: strs = [\"omv\",\"ovm\"]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= strs.length <= 300\n1 <= strs[i].length <= 300\nstrs[i] consists of lowercase letters only.\nAll words in strs have the same length and are anagrams of each other.", + "tags": [ + "Array", + "Hash Table", + "String", + "Depth-First Search", + "Breadth-First Search", + "Union Find" + ], + "title-slug": "similar-string-groups" + }, + { + "leetcode-id": 840, + "title": "Magic Squares In Grid", + "difficulty": 2, + "description": "A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum.\nGiven a row x col\u00a0grid\u00a0of integers, how many 3 x 3 \"magic square\" subgrids are there?\u00a0 (Each subgrid is contiguous).", + "examples": [ + "Example 1:\nInput: grid = [[4,3,8,4],[9,5,1,9],[2,7,6,2]]\nOutput: 1\nExplanation: \nThe following subgrid is a 3 x 3 magic square:\n\nwhile this one is not:\n\nIn total, there is only one magic square inside the given grid.", + "Example 2:\nInput: grid = [[8]]\nOutput: 0" + ], + "constraints": "Constraints:\n\nrow == grid.length\ncol == grid[i].length\n1 <= row, col <= 10\n0 <= grid[i][j] <= 15", + "tags": [ + "Array", + "Math", + "Matrix" + ], + "title-slug": "magic-squares-in-grid" + }, + { + "leetcode-id": 841, + "title": "Keys and Rooms", + "difficulty": 2, + "description": "There are n rooms labeled from 0 to n - 1\u00a0and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key.\nWhen you visit a room, you may find a set of distinct keys in it. Each key has a number on it, denoting which room it unlocks, and you can take all of them with you to unlock the other rooms.\nGiven an array rooms where rooms[i] is the set of keys that you can obtain if you visited room i, return true if you can visit all the rooms, or false otherwise.", + "examples": [ + "Example 1:\nInput: rooms = [[1],[2],[3],[]]\nOutput: true\nExplanation: \nWe visit room 0 and pick up key 1.\nWe then visit room 1 and pick up key 2.\nWe then visit room 2 and pick up key 3.\nWe then visit room 3.\nSince we were able to visit every room, we return true.", + "Example 2:\nInput: rooms = [[1,3],[3,0,1],[2],[0]]\nOutput: false\nExplanation: We can not enter room number 2 since the only key that unlocks it is in that room." + ], + "constraints": "Constraints:\n\nn == rooms.length\n2 <= n <= 1000\n0 <= rooms[i].length <= 1000\n1 <= sum(rooms[i].length) <= 3000\n0 <= rooms[i][j] < n\nAll the values of rooms[i] are unique.", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Graph" + ], + "title-slug": "keys-and-rooms" + }, + { + "leetcode-id": 842, + "title": "Split Array into Fibonacci Sequence", + "difficulty": 2, + "description": "You are given a string of digits num, such as \"123456579\". We can split it into a Fibonacci-like sequence [123, 456, 579].\nFormally, a Fibonacci-like sequence is a list f of non-negative integers such that:\n\n0 <= f[i] < 2^31, (that is, each integer fits in a 32-bit signed integer type),\nf.length >= 3, and\nf[i] + f[i + 1] == f[i + 2] for all 0 <= i < f.length - 2.\n\nNote that when splitting the string into pieces, each piece must not have extra leading zeroes, except if the piece is the number 0 itself.\nReturn any Fibonacci-like sequence split from num, or return [] if it cannot be done.", + "examples": [ + "Example 1:\nInput: num = \"1101111\"\nOutput: [11,0,11,11]\nExplanation: The output [110, 1, 111] would also be accepted.", + "Example 2:\nInput: num = \"112358130\"\nOutput: []\nExplanation: The task is impossible.", + "Example 3:\nInput: num = \"0123\"\nOutput: []\nExplanation: Leading zeroes are not allowed, so \"01\", \"2\", \"3\" is not valid." + ], + "constraints": "Constraints:\n\n1 <= num.length <= 200\nnum contains only digits.", + "tags": [ + "String", + "Backtracking" + ], + "title-slug": "split-array-into-fibonacci-sequence" + }, + { + "leetcode-id": 843, + "title": "Guess the Word", + "difficulty": 3, + "description": "You are given an array of unique strings words where words[i] is six letters long. One word of words was chosen as a secret word.\nYou are also given the helper object Master. You may call Master.guess(word) where word is a six-letter-long string, and it must be from words. Master.guess(word) returns:\n\n-1 if word is not from words, or\nan integer representing the number of exact matches (value and position) of your guess to the secret word.\n\nThere is a parameter allowedGuesses for each test case where allowedGuesses is the maximum number of times you can call Master.guess(word).\nFor each test case, you should call Master.guess with the secret word without exceeding the maximum number of allowed guesses. You will get:\n\n\"Either you took too many guesses, or you did not find the secret word.\" if you called Master.guess more than allowedGuesses times or if you did not call Master.guess with the secret word, or\n\"You guessed the secret word correctly.\" if you called Master.guess with the secret word with the number of calls to Master.guess less than or equal to allowedGuesses.\n\nThe test cases are generated such that you can guess the secret word with a reasonable strategy (other than using the bruteforce method).", + "examples": [ + "Example 1:\nInput: secret = \"acckzz\", words = [\"acckzz\",\"ccbazz\",\"eiowzz\",\"abcczz\"], allowedGuesses = 10\nOutput: You guessed the secret word correctly.\nExplanation:\nmaster.guess(\"aaaaaa\") returns -1, because \"aaaaaa\" is not in wordlist.\nmaster.guess(\"acckzz\") returns 6, because \"acckzz\" is secret and has all 6 matches.\nmaster.guess(\"ccbazz\") returns 3, because \"ccbazz\" has 3 matches.\nmaster.guess(\"eiowzz\") returns 2, because \"eiowzz\" has 2 matches.\nmaster.guess(\"abcczz\") returns 4, because \"abcczz\" has 4 matches.\nWe made 5 calls to master.guess, and one of them was the secret, so we pass the test case.", + "Example 2:\nInput: secret = \"hamada\", words = [\"hamada\",\"khaled\"], allowedGuesses = 10\nOutput: You guessed the secret word correctly.\nExplanation: Since there are two words, you can guess both." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 100\nwords[i].length == 6\nwords[i] consist of lowercase English letters.\nAll the strings of wordlist are unique.\nsecret exists in words.\n10 <= allowedGuesses <= 30", + "tags": [ + "Array", + "Math", + "String", + "Interactive", + "Game Theory" + ], + "title-slug": "guess-the-word" + }, + { + "leetcode-id": 844, + "title": "Backspace String Compare", + "difficulty": 1, + "description": "Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character.\nNote that after backspacing an empty text, the text will continue empty.", + "examples": [ + "Example 1:\nInput: s = \"ab#c\", t = \"ad#c\"\nOutput: true\nExplanation: Both s and t become \"ac\".", + "Example 2:\nInput: s = \"ab##\", t = \"c#d#\"\nOutput: true\nExplanation: Both s and t become \"\".", + "Example 3:\nInput: s = \"a#c\", t = \"b\"\nOutput: false\nExplanation: s becomes \"c\" while t becomes \"b\"." + ], + "constraints": "Constraints:\n\n1 <= s.length, t.length <= 200\ns and t only contain lowercase letters and '#' characters.\n\n\u00a0\nFollow up: Can you solve it in O(n) time and O(1) space?", + "tags": [ + "Two Pointers", + "String", + "Stack", + "Simulation" + ], + "title-slug": "backspace-string-compare" + }, + { + "leetcode-id": 845, + "title": "Longest Mountain in Array", + "difficulty": 2, + "description": "You may recall that an array arr is a mountain array if and only if:\n\narr.length >= 3\nThere exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:\n\t\narr[0] < arr[1] < ... < arr[i - 1] < arr[i]\narr[i] > arr[i + 1] > ... > arr[arr.length - 1]\n\n\n\nGiven an integer array arr, return the length of the longest subarray, which is a mountain. Return 0 if there is no mountain subarray.", + "examples": [ + "Example 1:\nInput: arr = [2,1,4,7,3,2,5]\nOutput: 5\nExplanation: The largest mountain is [1,4,7,3,2] which has length 5.", + "Example 2:\nInput: arr = [2,2,2]\nOutput: 0\nExplanation: There is no mountain." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^4\n0 <= arr[i] <= 10^4\n\n\u00a0\nFollow up:\n\nCan you solve it using only one pass?\nCan you solve it in O(1) space?", + "tags": [ + "Array", + "Two Pointers", + "Dynamic Programming", + "Enumeration" + ], + "title-slug": "longest-mountain-in-array" + }, + { + "leetcode-id": 846, + "title": "Hand of Straights", + "difficulty": 2, + "description": "Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size groupSize, and consists of groupSize consecutive cards.\nGiven an integer array hand where hand[i] is the value written on the i^th card and an integer groupSize, return true if she can rearrange the cards, or false otherwise.", + "examples": [ + "Example 1:\nInput: hand = [1,2,3,6,2,3,4,7,8], groupSize = 3\nOutput: true\nExplanation: Alice's hand can be rearranged as [1,2,3],[2,3,4],[6,7,8]", + "Example 2:\nInput: hand = [1,2,3,4,5], groupSize = 4\nOutput: false\nExplanation: Alice's hand can not be rearranged into groups of 4." + ], + "constraints": "Constraints:\n\n1 <= hand.length <= 10^4\n0 <= hand[i] <= 10^9\n1 <= groupSize <= hand.length\n\n\u00a0\nNote: This question is the same as 1296: https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Sorting" + ], + "title-slug": "hand-of-straights" + }, + { + "leetcode-id": 847, + "title": "Shortest Path Visiting All Nodes", + "difficulty": 3, + "description": "You have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an edge.\nReturn the length of the shortest path that visits every node. You may start and stop at any node, you may revisit nodes multiple times, and you may reuse edges.", + "examples": [ + "Example 1:\nInput: graph = [[1,2,3],[0],[0],[0]]\nOutput: 4\nExplanation: One possible path is [1,0,2,0,3]", + "Example 2:\nInput: graph = [[1],[0,2,4],[1,3,4],[2],[1,2]]\nOutput: 4\nExplanation: One possible path is [0,1,4,2,3]" + ], + "constraints": "Constraints:\n\nn == graph.length\n1 <= n <= 12\n0 <= graph[i].length <\u00a0n\ngraph[i] does not contain i.\nIf graph[a] contains b, then graph[b] contains a.\nThe input graph is always connected.", + "tags": [ + "Dynamic Programming", + "Bit Manipulation", + "Breadth-First Search", + "Graph", + "Bitmask" + ], + "title-slug": "shortest-path-visiting-all-nodes" + }, + { + "leetcode-id": 848, + "title": "Shifting Letters", + "difficulty": 2, + "description": "You are given a string s of lowercase English letters and an integer array shifts of the same length.\nCall the shift() of a letter, the next letter in the alphabet, (wrapping around so that 'z' becomes 'a').\n\nFor example, shift('a') = 'b', shift('t') = 'u', and shift('z') = 'a'.\n\nNow for each shifts[i] = x, we want to shift the first i + 1 letters of s, x times.\nReturn the final string after all such shifts to s are applied.", + "examples": [ + "Example 1:\nInput: s = \"abc\", shifts = [3,5,9]\nOutput: \"rpl\"\nExplanation: We start with \"abc\".\nAfter shifting the first 1 letters of s by 3, we have \"dbc\".\nAfter shifting the first 2 letters of s by 5, we have \"igc\".\nAfter shifting the first 3 letters of s by 9, we have \"rpl\", the answer.", + "Example 2:\nInput: s = \"aaa\", shifts = [1,2,3]\nOutput: \"gfd\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of lowercase English letters.\nshifts.length == s.length\n0 <= shifts[i] <= 10^9", + "tags": [ + "Array", + "String" + ], + "title-slug": "shifting-letters" + }, + { + "leetcode-id": 849, + "title": "Maximize Distance to Closest Person", + "difficulty": 2, + "description": "You are given an array representing a row of seats where seats[i] = 1 represents a person sitting in the i^th seat, and seats[i] = 0 represents that the i^th seat is empty (0-indexed).\nThere is at least one empty seat, and at least one person sitting.\nAlex wants to sit in the seat such that the distance between him and the closest person to him is maximized.\u00a0\nReturn that maximum distance to the closest person.", + "examples": [ + "Example 1:\nInput: seats = [1,0,0,0,1,0,1]\nOutput: 2\nExplanation: \nIf Alex sits in the second open seat (i.e. seats[2]), then the closest person has distance 2.\nIf Alex sits in any other open seat, the closest person has distance 1.\nThus, the maximum distance to the closest person is 2.", + "Example 2:\nInput: seats = [1,0,0,0]\nOutput: 3\nExplanation: \nIf Alex sits in the last seat (i.e. seats[3]), the closest person is 3 seats away.\nThis is the maximum distance possible, so the answer is 3.", + "Example 3:\nInput: seats = [0,1]\nOutput: 1" + ], + "constraints": "Constraints:\n\n2 <= seats.length <= 2 * 10^4\nseats[i]\u00a0is 0 or\u00a01.\nAt least one seat is empty.\nAt least one seat is occupied.", + "tags": [ + "Array" + ], + "title-slug": "maximize-distance-to-closest-person" + }, + { + "leetcode-id": 850, + "title": "Rectangle Area II", + "difficulty": 3, + "description": "You are given a 2D array of axis-aligned rectangles. Each rectangle[i] = [xi1, yi1, xi2, yi2] denotes the i^th rectangle where (xi1, yi1) are the coordinates of the bottom-left corner, and (xi2, yi2) are the coordinates of the top-right corner.\nCalculate the total area covered by all rectangles in the plane. Any area covered by two or more rectangles should only be counted once.\nReturn the total area. Since the answer may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: rectangles = [[0,0,2,2],[1,0,2,3],[1,0,3,1]]\nOutput: 6\nExplanation: A total area of 6 is covered by all three rectangles, as illustrated in the picture.\nFrom (1,1) to (2,2), the green and red rectangles overlap.\nFrom (1,0) to (2,3), all three rectangles overlap.", + "Example 2:\nInput: rectangles = [[0,0,1000000000,1000000000]]\nOutput: 49\nExplanation: The answer is 10^18 modulo (10^9 + 7), which is 49." + ], + "constraints": "Constraints:\n\n1 <= rectangles.length <= 200\nrectanges[i].length == 4\n0 <= xi1, yi1, xi2, yi2 <= 10^9\nxi1 <= xi2\nyi1 <= yi2", + "tags": [ + "Array", + "Segment Tree", + "Line Sweep", + "Ordered Set" + ], + "title-slug": "rectangle-area-ii" + }, + { + "leetcode-id": 851, + "title": "Loud and Rich", + "difficulty": 2, + "description": "There is a group of n people labeled from 0 to n - 1 where each person has a different amount of money and a different level of quietness.\nYou are given an array richer where richer[i] = [ai, bi] indicates that ai has more money than bi and an integer array quiet where quiet[i] is the quietness of the i^th person. All the given data in richer are logically correct (i.e., the data will not lead you to a situation where x is richer than y and y is richer than x at the same time).\nReturn an integer array answer where answer[x] = y if y is the least quiet person (that is, the person y with the smallest value of quiet[y]) among all people who definitely have equal to or more money than the person x.", + "examples": [ + "Example 1:\nInput: richer = [[1,0],[2,1],[3,1],[3,7],[4,3],[5,3],[6,3]], quiet = [3,2,5,4,6,1,7,0]\nOutput: [5,5,2,5,4,5,6,7]\nExplanation: \nanswer[0] = 5.\nPerson 5 has more money than 3, which has more money than 1, which has more money than 0.\nThe only person who is quieter (has lower quiet[x]) is person 7, but it is not clear if they have more money than person 0.\nanswer[7] = 7.\nAmong all people that definitely have equal to or more money than person 7 (which could be persons 3, 4, 5, 6, or 7), the person who is the quietest (has lower quiet[x]) is person 7.\nThe other answers can be filled out with similar reasoning.", + "Example 2:\nInput: richer = [], quiet = [0]\nOutput: [0]" + ], + "constraints": "Constraints:\n\nn == quiet.length\n1 <= n <= 500\n0 <= quiet[i] < n\nAll the values of quiet are unique.\n0 <= richer.length <= n * (n - 1) / 2\n0 <= ai, bi < n\nai != bi\nAll the pairs of richer are unique.\nThe observations in richer are all logically consistent.", + "tags": [ + "Array", + "Depth-First Search", + "Graph", + "Topological Sort" + ], + "title-slug": "loud-and-rich" + }, + { + "leetcode-id": 852, + "title": "Peak Index in a Mountain Array", + "difficulty": 2, + "description": "An array arr is a mountain if the following properties hold:\n\narr.length >= 3\nThere exists some i with 0 < i < arr.length - 1 such that:\n\t\narr[0] < arr[1] < ... < arr[i - 1] < arr[i] \narr[i] > arr[i + 1] > ... > arr[arr.length - 1]\n\n\n\nGiven a mountain array arr, return the index i such that arr[0] < arr[1] < ... < arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1].\nYou must solve it in O(log(arr.length)) time complexity.", + "examples": [ + "Example 1:\nInput: arr = [0,1,0]\nOutput: 1", + "Example 2:\nInput: arr = [0,2,1,0]\nOutput: 1", + "Example 3:\nInput: arr = [0,10,5,2]\nOutput: 1" + ], + "constraints": "Constraints:\n\n3 <= arr.length <= 10^5\n0 <= arr[i] <= 10^6\narr is guaranteed to be a mountain array.", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "peak-index-in-a-mountain-array" + }, + { + "leetcode-id": 853, + "title": "Car Fleet", + "difficulty": 2, + "description": "There are n cars going to the same destination along a one-lane road. The destination is target miles away.\nYou are given two integer array position and speed, both of length n, where position[i] is the position of the i^th car and speed[i] is the speed of the i^th car (in miles per hour).\nA car can never pass another car ahead of it, but it can catch up to it\u00a0and drive bumper to bumper at the same speed. The faster car will slow down to match the slower car's speed. The distance between these two cars is ignored (i.e., they are assumed to have the same position).\nA car fleet is some non-empty set of cars driving at the same position and same speed. Note that a single car is also a car fleet.\nIf a car catches up to a car fleet right at the destination point, it will still be considered as one car fleet.\nReturn the number of car fleets that will arrive at the destination.", + "examples": [ + "Example 1:\nInput: target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3]\nOutput: 3\nExplanation:\nThe cars starting at 10 (speed 2) and 8 (speed 4) become a fleet, meeting each other at 12.\nThe car starting at 0 does not catch up to any other car, so it is a fleet by itself.\nThe cars starting at 5 (speed 1) and 3 (speed 3) become a fleet, meeting each other at 6. The fleet moves at speed 1 until it reaches target.\nNote that no other cars meet these fleets before the destination, so the answer is 3.", + "Example 2:\nInput: target = 10, position = [3], speed = [3]\nOutput: 1\nExplanation: There is only one car, hence there is only one fleet.", + "Example 3:\nInput: target = 100, position = [0,2,4], speed = [4,2,1]\nOutput: 1\nExplanation:\nThe cars starting at 0 (speed 4) and 2 (speed 2) become a fleet, meeting each other at 4. The fleet moves at speed 2.\nThen, the fleet (speed 2) and the car starting at 4 (speed 1) become one fleet, meeting each other at 6. The fleet moves at speed 1 until it reaches target." + ], + "constraints": "Constraints:\n\nn == position.length == speed.length\n1 <= n <= 10^5\n0 < target <= 10^6\n0 <= position[i] < target\nAll the values of position are unique.\n0 < speed[i] <= 10^6", + "tags": [ + "Array", + "Stack", + "Sorting", + "Monotonic Stack" + ], + "title-slug": "car-fleet" + }, + { + "leetcode-id": 854, + "title": "K-Similar Strings", + "difficulty": 3, + "description": "Strings s1 and s2 are k-similar (for some non-negative integer k) if we can swap the positions of two letters in s1 exactly k times so that the resulting string equals s2.\nGiven two anagrams s1 and s2, return the smallest k for which s1 and s2 are k-similar.", + "examples": [ + "Example 1:\nInput: s1 = \"ab\", s2 = \"ba\"\nOutput: 1\nExplanation: The two string are 1-similar because we can use one swap to change s1 to s2: \"ab\" --> \"ba\".", + "Example 2:\nInput: s1 = \"abc\", s2 = \"bca\"\nOutput: 2\nExplanation: The two strings are 2-similar because we can use two swaps to change s1 to s2: \"abc\" --> \"bac\" --> \"bca\"." + ], + "constraints": "Constraints:\n\n1 <= s1.length <= 20\ns2.length == s1.length\ns1 and s2 contain only lowercase letters from the set {'a', 'b', 'c', 'd', 'e', 'f'}.\ns2 is an anagram of s1.", + "tags": [ + "String", + "Breadth-First Search" + ], + "title-slug": "k-similar-strings" + }, + { + "leetcode-id": 855, + "title": "Exam Room", + "difficulty": 2, + "description": "There is an exam room with n seats in a single row labeled from 0 to n - 1.\nWhen a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are multiple such seats, they sit in the seat with the lowest number. If no one is in the room, then the student sits at seat number 0.\nDesign a class that simulates the mentioned exam room.\nImplement the ExamRoom class:\n\nExamRoom(int n) Initializes the object of the exam room with the number of the seats n.\nint seat() Returns the label of the seat at which the next student will set.\nvoid leave(int p) Indicates that the student sitting at seat p will leave the room. It is guaranteed that there will be a student sitting at seat p.", + "examples": [ + "Example 1:\nInput\n[\"ExamRoom\", \"seat\", \"seat\", \"seat\", \"seat\", \"leave\", \"seat\"]\n[[10], [], [], [], [], [4], []]\nOutput\n[null, 0, 9, 4, 2, null, 5]\n\nExplanation\nExamRoom examRoom = new ExamRoom(10);\nexamRoom.seat(); // return 0, no one is in the room, then the student sits at seat number 0.\nexamRoom.seat(); // return 9, the student sits at the last seat number 9.\nexamRoom.seat(); // return 4, the student sits at the last seat number 4.\nexamRoom.seat(); // return 2, the student sits at the last seat number 2.\nexamRoom.leave(4);\nexamRoom.seat(); // return 5, the student sits at the last seat number 5." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^9\nIt is guaranteed that there is a student sitting at seat p.\nAt most 10^4 calls will be made to seat and leave.", + "tags": [ + "Design", + "Heap (Priority Queue)", + "Ordered Set" + ], + "title-slug": "exam-room" + }, + { + "leetcode-id": 856, + "title": "Score of Parentheses", + "difficulty": 2, + "description": "Given a balanced parentheses string s, return the score of the string.\nThe score of a balanced parentheses string is based on the following rule:\n\n\"()\" has score 1.\nAB has score A + B, where A and B are balanced parentheses strings.\n(A) has score 2 * A, where A is a balanced parentheses string.", + "examples": [ + "Example 1:\nInput: s = \"()\"\nOutput: 1", + "Example 2:\nInput: s = \"(())\"\nOutput: 2", + "Example 3:\nInput: s = \"()()\"\nOutput: 2" + ], + "constraints": "Constraints:\n\n2 <= s.length <= 50\ns consists of only '(' and ')'.\ns is a balanced parentheses string.", + "tags": [ + "String", + "Stack" + ], + "title-slug": "score-of-parentheses" + }, + { + "leetcode-id": 857, + "title": "Minimum Cost to Hire K Workers", + "difficulty": 3, + "description": "There are n workers. You are given two integer arrays quality and wage where quality[i] is the quality of the i^th worker and wage[i] is the minimum wage expectation for the i^th worker.\nWe want to hire exactly k workers to form a paid group. To hire a group of k workers, we must pay them according to the following rules:\n\nEvery worker in the paid group should be paid in the ratio of their quality compared to other workers in the paid group.\nEvery worker in the paid group must be paid at least their minimum wage expectation.\n\nGiven the integer k, return the least amount of money needed to form a paid group satisfying the above conditions. Answers within 10^-5 of the actual answer will be accepted.", + "examples": [ + "Example 1:\nInput: quality = [10,20,5], wage = [70,50,30], k = 2\nOutput: 105.00000\nExplanation: We pay 70 to 0^th worker and 35 to 2^nd worker.", + "Example 2:\nInput: quality = [3,1,10,10,1], wage = [4,8,2,2,7], k = 3\nOutput: 30.66667\nExplanation: We pay 4 to 0^th worker, 13.33333 to 2^nd and 3^rd workers separately." + ], + "constraints": "Constraints:\n\nn == quality.length == wage.length\n1 <= k <= n <= 10^4\n1 <= quality[i], wage[i] <= 10^4", + "tags": [ + "Array", + "Greedy", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "minimum-cost-to-hire-k-workers" + }, + { + "leetcode-id": 858, + "title": "Mirror Reflection", + "difficulty": 2, + "description": "There is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining corners, numbered 0, 1, and 2.\nThe square room has walls of length p\u00a0and a laser ray from the southwest corner first meets the east wall at a distance q from the 0^th receptor.\nGiven the two integers p and q, return the number of the receptor that the ray meets first.\nThe test cases are guaranteed so that the ray will meet a receptor eventually.", + "examples": [ + "Example 1:\nInput: p = 2, q = 1\nOutput: 2\nExplanation: The ray meets receptor 2 the first time it gets reflected back to the left wall.", + "Example 2:\nInput: p = 3, q = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= q <= p <= 1000", + "tags": [ + "Math", + "Geometry", + "Number Theory" + ], + "title-slug": "mirror-reflection" + }, + { + "leetcode-id": 859, + "title": "Buddy Strings", + "difficulty": 1, + "description": "Given two strings s and goal, return true if you can swap two letters in s so the result is equal to goal, otherwise, return false.\nSwapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at s[i] and s[j].\n\nFor example, swapping at indices 0 and 2 in \"abcd\" results in \"cbad\".", + "examples": [ + "Example 1:\nInput: s = \"ab\", goal = \"ba\"\nOutput: true\nExplanation: You can swap s[0] = 'a' and s[1] = 'b' to get \"ba\", which is equal to goal.", + "Example 2:\nInput: s = \"ab\", goal = \"ab\"\nOutput: false\nExplanation: The only letters you can swap are s[0] = 'a' and s[1] = 'b', which results in \"ba\" != goal.", + "Example 3:\nInput: s = \"aa\", goal = \"aa\"\nOutput: true\nExplanation: You can swap s[0] = 'a' and s[1] = 'a' to get \"aa\", which is equal to goal." + ], + "constraints": "Constraints:\n\n1 <= s.length, goal.length <= 2 * 10^4\ns and goal consist of lowercase letters.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "buddy-strings" + }, + { + "leetcode-id": 860, + "title": "Lemonade Change", + "difficulty": 1, + "description": "At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you and order one at a time (in the order specified by bills). Each customer will only buy one lemonade and pay with either a $5, $10, or $20 bill. You must provide the correct change to each customer so that the net transaction is that the customer pays $5.\nNote that you do not have any change in hand at first.\nGiven an integer array bills where bills[i] is the bill the i^th customer pays, return true if you can provide every customer with the correct change, or false otherwise.", + "examples": [ + "Example 1:\nInput: bills = [5,5,5,10,20]\nOutput: true\nExplanation: \nFrom the first 3 customers, we collect three $5 bills in order.\nFrom the fourth customer, we collect a $10 bill and give back a $5.\nFrom the fifth customer, we give a $10 bill and a $5 bill.\nSince all customers got correct change, we output true.", + "Example 2:\nInput: bills = [5,5,10,10,20]\nOutput: false\nExplanation: \nFrom the first two customers in order, we collect two $5 bills.\nFor the next two customers in order, we collect a $10 bill and give back a $5 bill.\nFor the last customer, we can not give the change of $15 back because we only have two $10 bills.\nSince not every customer received the correct change, the answer is false." + ], + "constraints": "Constraints:\n\n1 <= bills.length <= 10^5\nbills[i] is either 5, 10, or 20.", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "lemonade-change" + }, + { + "leetcode-id": 861, + "title": "Score After Flipping Matrix", + "difficulty": 2, + "description": "You are given an m x n binary matrix grid.\nA move consists of choosing any row or column and toggling each value in that row or column (i.e., changing all 0's to 1's, and all 1's to 0's).\nEvery row of the matrix is interpreted as a binary number, and the score of the matrix is the sum of these numbers.\nReturn the highest possible score after making any number of moves (including zero moves).", + "examples": [ + "Example 1:\nInput: grid = [[0,0,1,1],[1,0,1,0],[1,1,0,0]]\nOutput: 39\nExplanation: 0b1111 + 0b1001 + 0b1111 = 15 + 9 + 15 = 39", + "Example 2:\nInput: grid = [[0]]\nOutput: 1" + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 20\ngrid[i][j] is either 0 or 1.", + "tags": [ + "Array", + "Greedy", + "Bit Manipulation", + "Matrix" + ], + "title-slug": "score-after-flipping-matrix" + }, + { + "leetcode-id": 862, + "title": "Shortest Subarray with Sum at Least K", + "difficulty": 3, + "description": "Given an integer array nums and an integer k, return the length of the shortest non-empty subarray of nums with a sum of at least k. If there is no such subarray, return -1.\nA subarray is a contiguous part of an array.", + "examples": [ + "Example 1:\nInput: nums = [1], k = 1\nOutput: 1", + "Example 2:\nInput: nums = [1,2], k = 4\nOutput: -1", + "Example 3:\nInput: nums = [2,-1,2], k = 3\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^5 <= nums[i] <= 10^5\n1 <= k <= 10^9", + "tags": [ + "Array", + "Binary Search", + "Queue", + "Sliding Window", + "Heap (Priority Queue)", + "Prefix Sum", + "Monotonic Queue" + ], + "title-slug": "shortest-subarray-with-sum-at-least-k" + }, + { + "leetcode-id": 863, + "title": "All Nodes Distance K in Binary Tree", + "difficulty": 2, + "description": "Given the root of a binary tree, the value of a target node target, and an integer k, return an array of the values of all nodes that have a distance k from the target node.\nYou can return the answer in any order.", + "examples": [ + "Example 1:\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, k = 2\nOutput: [7,4,1]\nExplanation: The nodes that are a distance 2 from the target node (with value 5) have values 7, 4, and 1.", + "Example 2:\nInput: root = [1], target = 1, k = 3\nOutput: []" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 500].\n0 <= Node.val <= 500\nAll the values Node.val are unique.\ntarget is the value of one of the nodes in the tree.\n0 <= k <= 1000", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "all-nodes-distance-k-in-binary-tree" + }, + { + "leetcode-id": 864, + "title": "Shortest Path to Get All Keys", + "difficulty": 3, + "description": "You are given an m x n grid grid where:\n\n'.' is an empty cell.\n'#' is a wall.\n'@' is the starting point.\nLowercase letters represent keys.\nUppercase letters represent locks.\n\nYou start at the starting point and one move consists of walking one space in one of the four cardinal directions. You cannot walk outside the grid, or walk into a wall.\nIf you walk over a key, you can pick it up and you cannot walk over a lock unless you have its corresponding key.\nFor some 1 <= k <= 6, there is exactly one lowercase and one uppercase letter of the first k letters of the English alphabet in the grid. This means that there is exactly one key for each lock, and one lock for each key; and also that the letters used to represent the keys and locks were chosen in the same order as the English alphabet.\nReturn the lowest number of moves to acquire all keys. If it is impossible, return -1.", + "examples": [ + "Example 1:\nInput: grid = [\"@.a..\",\"###.#\",\"b.A.B\"]\nOutput: 8\nExplanation: Note that the goal is to obtain all the keys not to open all the locks.", + "Example 2:\nInput: grid = [\"@..aA\",\"..B#.\",\"....b\"]\nOutput: 6", + "Example 3:\nInput: grid = [\"@Aa\"]\nOutput: -1" + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 30\ngrid[i][j] is either an English letter, '.', '#', or '@'.\u00a0\nThere is exactly one\u00a0'@'\u00a0in the grid.\nThe number of keys in the grid is in the range [1, 6].\nEach key in the grid is unique.\nEach key in the grid has a matching lock.", + "tags": [ + "Array", + "Bit Manipulation", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "shortest-path-to-get-all-keys" + }, + { + "leetcode-id": 865, + "title": "Smallest Subtree with all the Deepest Nodes", + "difficulty": 2, + "description": "Given the root of a binary tree, the depth of each node is the shortest distance to the root.\nReturn the smallest subtree such that it contains all the deepest nodes in the original tree.\nA node is called the deepest if it has the largest depth possible among any node in the entire tree.\nThe subtree of a node is a tree consisting of that node, plus the set of all descendants of that node.", + "examples": [ + "Example 1:\nInput: root = [3,5,1,6,2,0,8,null,null,7,4]\nOutput: [2,7,4]\nExplanation: We return the node with value 2, colored in yellow in the diagram.\nThe nodes coloured in blue are the deepest nodes of the tree.\nNotice that nodes 5, 3 and 2 contain the deepest nodes in the tree but node 2 is the smallest subtree among them, so we return it.", + "Example 2:\nInput: root = [1]\nOutput: [1]\nExplanation: The root is the deepest node in the tree.", + "Example 3:\nInput: root = [0,1,3,null,2]\nOutput: [2]\nExplanation: The deepest node in the tree is 2, the valid subtrees are the subtrees of nodes 2, 1 and 0 but the subtree of node 2 is the smallest." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree will be in the range [1, 500].\n0 <= Node.val <= 500\nThe values of the nodes in the tree are unique.\n\n\u00a0\nNote: This question is the same as 1123: https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves/", + "tags": [ + "Hash Table", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "smallest-subtree-with-all-the-deepest-nodes" + }, + { + "leetcode-id": 866, + "title": "Prime Palindrome", + "difficulty": 2, + "description": "Given an integer n, return the smallest prime palindrome greater than or equal to n.\nAn integer is prime if it has exactly two divisors: 1 and itself. Note that 1 is not a prime number.\n\nFor example, 2, 3, 5, 7, 11, and 13 are all primes.\n\nAn integer is a palindrome if it reads the same from left to right as it does from right to left.\n\nFor example, 101 and 12321 are palindromes.\n\nThe test cases are generated so that the answer always exists and is in the range [2, 2 * 10^8].", + "examples": [ + "Example 1:\nInput: n = 6\nOutput: 7", + "Example 2:\nInput: n = 8\nOutput: 11", + "Example 3:\nInput: n = 13\nOutput: 101" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^8", + "tags": [ + "Math" + ], + "title-slug": "prime-palindrome" + }, + { + "leetcode-id": 867, + "title": "Transpose Matrix", + "difficulty": 1, + "description": "Given a 2D integer array matrix, return the transpose of matrix.\nThe transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices.", + "examples": [ + "Example 1:\nInput: matrix = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [[1,4,7],[2,5,8],[3,6,9]]", + "Example 2:\nInput: matrix = [[1,2,3],[4,5,6]]\nOutput: [[1,4],[2,5],[3,6]]" + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= m, n <= 1000\n1 <= m * n <= 10^5\n-10^9 <= matrix[i][j] <= 10^9", + "tags": [ + "Array", + "Matrix", + "Simulation" + ], + "title-slug": "transpose-matrix" + }, + { + "leetcode-id": 868, + "title": "Binary Gap", + "difficulty": 1, + "description": "Given a positive integer n, find and return the longest distance between any two adjacent 1's in the binary representation of n. If there are no two adjacent 1's, return 0.\nTwo 1's are adjacent if there are only 0's separating them (possibly no 0's). The distance between two 1's is the absolute difference between their bit positions. For example, the two 1's in \"1001\" have a distance of 3.", + "examples": [ + "Example 1:\nInput: n = 22\nOutput: 2\nExplanation: 22 in binary is \"10110\".\nThe first adjacent pair of 1's is \"10110\" with a distance of 2.\nThe second adjacent pair of 1's is \"10110\" with a distance of 1.\nThe answer is the largest of these two distances, which is 2.\nNote that \"10110\" is not a valid pair since there is a 1 separating the two 1's underlined.", + "Example 2:\nInput: n = 8\nOutput: 0\nExplanation: 8 in binary is \"1000\".\nThere are not any adjacent pairs of 1's in the binary representation of 8, so we return 0.", + "Example 3:\nInput: n = 5\nOutput: 2\nExplanation: 5 in binary is \"101\"." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^9", + "tags": [ + "Bit Manipulation" + ], + "title-slug": "binary-gap" + }, + { + "leetcode-id": 869, + "title": "Reordered Power of 2", + "difficulty": 2, + "description": "You are given an integer n. We reorder the digits in any order (including the original order) such that the leading digit is not zero.\nReturn true if and only if we can do this so that the resulting number is a power of two.", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: true", + "Example 2:\nInput: n = 10\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^9", + "tags": [ + "Math", + "Sorting", + "Counting", + "Enumeration" + ], + "title-slug": "reordered-power-of-2" + }, + { + "leetcode-id": 870, + "title": "Advantage Shuffle", + "difficulty": 2, + "description": "You are given two integer arrays nums1 and nums2 both of the same length. The advantage of nums1 with respect to nums2 is the number of indices i for which nums1[i] > nums2[i].\nReturn any permutation of nums1 that maximizes its advantage with respect to nums2.", + "examples": [ + "Example 1:\nInput: nums1 = [2,7,11,15], nums2 = [1,10,4,11]\nOutput: [2,11,7,15]", + "Example 2:\nInput: nums1 = [12,24,8,32], nums2 = [13,25,32,11]\nOutput: [24,32,8,12]" + ], + "constraints": "Constraints:\n\n1 <= nums1.length <= 10^5\nnums2.length == nums1.length\n0 <= nums1[i], nums2[i] <= 10^9", + "tags": [ + "Array", + "Two Pointers", + "Greedy", + "Sorting" + ], + "title-slug": "advantage-shuffle" + }, + { + "leetcode-id": 871, + "title": "Minimum Number of Refueling Stops", + "difficulty": 3, + "description": "A car travels from a starting position to a destination which is target miles east of the starting position.\nThere are gas stations along the way. The gas stations are represented as an array stations where stations[i] = [positioni, fueli] indicates that the i^th gas station is positioni miles east of the starting position and has fueli liters of gas.\nThe car starts with an infinite tank of gas, which initially has startFuel liters of fuel in it. It uses one liter of gas per one mile that it drives. When the car reaches a gas station, it may stop and refuel, transferring all the gas from the station into the car.\nReturn the minimum number of refueling stops the car must make in order to reach its destination. If it cannot reach the destination, return -1.\nNote that if the car reaches a gas station with 0 fuel left, the car can still refuel there. If the car reaches the destination with 0 fuel left, it is still considered to have arrived.", + "examples": [ + "Example 1:\nInput: target = 1, startFuel = 1, stations = []\nOutput: 0\nExplanation: We can reach the target without refueling.", + "Example 2:\nInput: target = 100, startFuel = 1, stations = [[10,100]]\nOutput: -1\nExplanation: We can not reach the target (or even the first gas station).", + "Example 3:\nInput: target = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]]\nOutput: 2\nExplanation: We start with 10 liters of fuel.\nWe drive to position 10, expending 10 liters of fuel. We refuel from 0 liters to 60 liters of gas.\nThen, we drive from position 10 to position 60 (expending 50 liters of fuel),\nand refuel from 10 liters to 50 liters of gas. We then drive to and reach the target.\nWe made 2 refueling stops along the way, so we return 2." + ], + "constraints": "Constraints:\n\n1 <= target, startFuel <= 10^9\n0 <= stations.length <= 500\n1 <= positioni < positioni+1 < target\n1 <= fueli < 10^9", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy", + "Heap (Priority Queue)" + ], + "title-slug": "minimum-number-of-refueling-stops" + }, + { + "leetcode-id": 872, + "title": "Leaf-Similar Trees", + "difficulty": 1, + "description": "Consider all the leaves of a binary tree, from\u00a0left to right order, the values of those\u00a0leaves form a leaf value sequence.\n\nFor example, in the given tree above, the leaf value sequence is (6, 7, 4, 9, 8).\nTwo binary trees are considered leaf-similar\u00a0if their leaf value sequence is the same.\nReturn true if and only if the two given trees with head nodes root1 and root2 are leaf-similar.", + "examples": [ + "Example 1:\nInput: root1 = [3,5,1,6,2,9,8,null,null,7,4], root2 = [3,5,1,6,7,4,2,null,null,null,null,null,null,9,8]\nOutput: true", + "Example 2:\nInput: root1 = [1,2,3], root2 = [1,3,2]\nOutput: false" + ], + "constraints": "Constraints:\n\nThe number of nodes in each tree will be in the range [1, 200].\nBoth of the given trees will have values in the range [0, 200].", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "leaf-similar-trees" + }, + { + "leetcode-id": 873, + "title": "Length of Longest Fibonacci Subsequence", + "difficulty": 2, + "description": "A sequence x1, x2, ..., xn is Fibonacci-like if:\n\nn >= 3\nxi + xi+1 == xi+2 for all i + 2 <= n\n\nGiven a strictly increasing array arr of positive integers forming a sequence, return the length of the longest Fibonacci-like subsequence of arr. If one does not exist, return 0.\nA subsequence is derived from another sequence arr by deleting any number of elements (including none) from arr, without changing the order of the remaining elements. For example, [3, 5, 8] is a subsequence of [3, 4, 5, 6, 7, 8].", + "examples": [ + "Example 1:\nInput: arr = [1,2,3,4,5,6,7,8]\nOutput: 5\nExplanation: The longest subsequence that is fibonacci-like: [1,2,3,5,8].", + "Example 2:\nInput: arr = [1,3,7,11,12,14,18]\nOutput: 3\nExplanation: The longest subsequence that is fibonacci-like: [1,11,12], [3,11,14] or [7,11,18]." + ], + "constraints": "Constraints:\n\n3 <= arr.length <= 1000\n1 <= arr[i] < arr[i + 1] <= 10^9", + "tags": [ + "Array", + "Hash Table", + "Dynamic Programming" + ], + "title-slug": "length-of-longest-fibonacci-subsequence" + }, + { + "leetcode-id": 874, + "title": "Walking Robot Simulation", + "difficulty": 2, + "description": "A robot on an infinite XY-plane starts at point (0, 0) facing north. The robot can receive a sequence of these three possible types of commands:\n\n-2: Turn left 90 degrees.\n-1: Turn right 90 degrees.\n1 <= k <= 9: Move forward k units, one unit at a time.\n\nSome of the grid squares are obstacles. The i^th obstacle is at grid point obstacles[i] = (xi, yi). If the robot runs into an obstacle, then it will instead stay in its current location and move on to the next command.\nReturn the maximum Euclidean distance that the robot ever gets from the origin squared (i.e. if the distance is 5, return 25).\nNote:\n\nNorth means +Y direction.\nEast means +X direction.\nSouth means -Y direction.\nWest means -X direction.\nThere can be obstacle in\u00a0[0,0].", + "examples": [ + "Example 1:\nInput: commands = [4,-1,3], obstacles = []\nOutput: 25\nExplanation: The robot starts at (0, 0):\n1. Move north 4 units to (0, 4).\n2. Turn right.\n3. Move east 3 units to (3, 4).\nThe furthest point the robot ever gets from the origin is (3, 4), which squared is 3^2 + 4^2 = 25 units away.", + "Example 2:\nInput: commands = [4,-1,4,-2,4], obstacles = [[2,4]]\nOutput: 65\nExplanation: The robot starts at (0, 0):\n1. Move north 4 units to (0, 4).\n2. Turn right.\n3. Move east 1 unit and get blocked by the obstacle at (2, 4), robot is at (1, 4).\n4. Turn left.\n5. Move north 4 units to (1, 8).\nThe furthest point the robot ever gets from the origin is (1, 8), which squared is 1^2 + 8^2 = 65 units away.", + "Example 3:\nInput: commands = [6,-1,-1,6], obstacles = []\nOutput: 36\nExplanation: The robot starts at (0, 0):\n1. Move north 6 units to (0, 6).\n2. Turn right.\n3. Turn right.\n4. Move south 6 units to (0, 0).\nThe furthest point the robot ever gets from the origin is (0, 6), which squared is 6^2 = 36 units away." + ], + "constraints": "Constraints:\n\n1 <= commands.length <= 10^4\ncommands[i] is either -2, -1, or an integer in the range [1, 9].\n0 <= obstacles.length <= 10^4\n-3 * 10^4 <= xi, yi <= 3 * 10^4\nThe answer is guaranteed to be less than 2^31.", + "tags": [ + "Array", + "Simulation" + ], + "title-slug": "walking-robot-simulation" + }, + { + "leetcode-id": 875, + "title": "Koko Eating Bananas", + "difficulty": 2, + "description": "Koko loves to eat bananas. There are n piles of bananas, the i^th pile has piles[i] bananas. The guards have gone and will come back in h hours.\nKoko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour.\nKoko likes to eat slowly but still wants to finish eating all the bananas before the guards return.\nReturn the minimum integer k such that she can eat all the bananas within h hours.", + "examples": [ + "Example 1:\nInput: piles = [3,6,7,11], h = 8\nOutput: 4", + "Example 2:\nInput: piles = [30,11,23,4,20], h = 5\nOutput: 30", + "Example 3:\nInput: piles = [30,11,23,4,20], h = 6\nOutput: 23" + ], + "constraints": "Constraints:\n\n1 <= piles.length <= 10^4\npiles.length <= h <= 10^9\n1 <= piles[i] <= 10^9", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "koko-eating-bananas" + }, + { + "leetcode-id": 876, + "title": "Middle of the Linked List", + "difficulty": 1, + "description": "Given the head of a singly linked list, return the middle node of the linked list.\nIf there are two middle nodes, return the second middle node.", + "examples": [ + "Example 1:\nInput: head = [1,2,3,4,5]\nOutput: [3,4,5]\nExplanation: The middle node of the list is node 3.", + "Example 2:\nInput: head = [1,2,3,4,5,6]\nOutput: [4,5,6]\nExplanation: Since the list has two middle nodes with values 3 and 4, we return the second one." + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [1, 100].\n1 <= Node.val <= 100", + "tags": [ + "Linked List", + "Two Pointers" + ], + "title-slug": "middle-of-the-linked-list" + }, + { + "leetcode-id": 877, + "title": "Stone Game", + "difficulty": 2, + "description": "Alice and Bob play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].\nThe objective of the game is to end with the most stones. The total number of stones across all the piles is odd, so there are no ties.\nAlice and Bob take turns, with Alice starting first. Each turn, a player takes the entire pile of stones either from the beginning or from the end of the row. This continues until there are no more piles left, at which point the person with the most stones wins.\nAssuming Alice and Bob play optimally, return true if Alice wins the game, or false if Bob wins.", + "examples": [ + "Example 1:\nInput: piles = [5,3,4,5]\nOutput: true\nExplanation: \nAlice starts first, and can only take the first 5 or the last 5.\nSay she takes the first 5, so that the row becomes [3, 4, 5].\nIf Bob takes 3, then the board is [4, 5], and Alice takes 5 to win with 10 points.\nIf Bob takes the last 5, then the board is [3, 4], and Alice takes 4 to win with 9 points.\nThis demonstrated that taking the first 5 was a winning move for Alice, so we return true.", + "Example 2:\nInput: piles = [3,7,2,3]\nOutput: true" + ], + "constraints": "Constraints:\n\n2 <= piles.length <= 500\npiles.length is even.\n1 <= piles[i] <= 500\nsum(piles[i]) is odd.", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Game Theory" + ], + "title-slug": "stone-game" + }, + { + "leetcode-id": 878, + "title": "Nth Magical Number", + "difficulty": 3, + "description": "A positive integer is magical if it is divisible by either a or b.\nGiven the three integers n, a, and b, return the n^th magical number. Since the answer may be very large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 1, a = 2, b = 3\nOutput: 2", + "Example 2:\nInput: n = 4, a = 2, b = 3\nOutput: 6" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^9\n2 <= a, b <= 4 * 10^4", + "tags": [ + "Math", + "Binary Search" + ], + "title-slug": "nth-magical-number" + }, + { + "leetcode-id": 879, + "title": "Profitable Schemes", + "difficulty": 3, + "description": "There is a group of n members, and a list of various crimes they could commit. The i^th crime generates a profit[i] and requires group[i] members to participate in it. If a member participates in one crime, that member can't participate in another crime.\nLet's call a profitable scheme any subset of these crimes that generates at least minProfit profit, and the total number of members participating in that subset of crimes is at most n.\nReturn the number of schemes that can be chosen. Since the answer may be very large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 5, minProfit = 3, group = [2,2], profit = [2,3]\nOutput: 2\nExplanation: To make a profit of at least 3, the group could either commit crimes 0 and 1, or just crime 1.\nIn total, there are 2 schemes.", + "Example 2:\nInput: n = 10, minProfit = 5, group = [2,3,5], profit = [6,7,8]\nOutput: 7\nExplanation: To make a profit of at least 5, the group could commit any crimes, as long as they commit one.\nThere are 7 possible schemes: (0), (1), (2), (0,1), (0,2), (1,2), and (0,1,2)." + ], + "constraints": "Constraints:\n\n1 <= n <= 100\n0 <= minProfit <= 100\n1 <= group.length <= 100\n1 <= group[i] <= 100\nprofit.length == group.length\n0 <= profit[i] <= 100", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "profitable-schemes" + }, + { + "leetcode-id": 880, + "title": "Decoded String at Index", + "difficulty": 2, + "description": "You are given an encoded string s. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:\n\nIf the character read is a letter, that letter is written onto the tape.\nIf the character read is a digit d, the entire current tape is repeatedly written d - 1 more times in total.\n\nGiven an integer k, return the k^th letter (1-indexed) in the decoded string.", + "examples": [ + "Example 1:\nInput: s = \"leet2code3\", k = 10\nOutput: \"o\"\nExplanation: The decoded string is \"leetleetcodeleetleetcodeleetleetcode\".\nThe 10^th letter in the string is \"o\".", + "Example 2:\nInput: s = \"ha22\", k = 5\nOutput: \"h\"\nExplanation: The decoded string is \"hahahaha\".\nThe 5^th letter is \"h\".", + "Example 3:\nInput: s = \"a2345678999999999999999\", k = 1\nOutput: \"a\"\nExplanation: The decoded string is \"a\" repeated 8301530446056247680 times.\nThe 1^st letter is \"a\"." + ], + "constraints": "Constraints:\n\n2 <= s.length <= 100\ns consists of lowercase English letters and digits 2 through 9.\ns starts with a letter.\n1 <= k <= 10^9\nIt is guaranteed that k is less than or equal to the length of the decoded string.\nThe decoded string is guaranteed to have less than 2^63 letters.", + "tags": [ + "String", + "Stack" + ], + "title-slug": "decoded-string-at-index" + }, + { + "leetcode-id": 881, + "title": "Boats to Save People", + "difficulty": 2, + "description": "You are given an array people where people[i] is the weight of the i^th person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most limit.\nReturn the minimum number of boats to carry every given person.", + "examples": [ + "Example 1:\nInput: people = [1,2], limit = 3\nOutput: 1\nExplanation: 1 boat (1, 2)", + "Example 2:\nInput: people = [3,2,2,1], limit = 3\nOutput: 3\nExplanation: 3 boats (1, 2), (2) and (3)", + "Example 3:\nInput: people = [3,5,3,4], limit = 5\nOutput: 4\nExplanation: 4 boats (3), (3), (4), (5)" + ], + "constraints": "Constraints:\n\n1 <= people.length <= 5 * 10^4\n1 <= people[i] <= limit <= 3 * 10^4", + "tags": [ + "Array", + "Two Pointers", + "Greedy", + "Sorting" + ], + "title-slug": "boats-to-save-people" + }, + { + "leetcode-id": 882, + "title": "Reachable Nodes In Subdivided Graph", + "difficulty": 3, + "description": "You are given an undirected graph (the \"original graph\") with n nodes labeled from 0 to n - 1. You decide to subdivide each edge in the graph into a chain of nodes, with the number of new nodes varying between each edge.\nThe graph is given as a 2D array of edges where edges[i] = [ui, vi, cnti] indicates that there is an edge between nodes ui and vi in the original graph, and cnti is the total number of new nodes that you will subdivide the edge into. Note that cnti == 0 means you will not subdivide the edge.\nTo subdivide the edge [ui, vi], replace it with (cnti + 1) new edges and cnti new nodes. The new nodes are x1, x2, ..., xcnti, and the new edges are [ui, x1], [x1, x2], [x2, x3], ..., [xcnti-1, xcnti], [xcnti, vi].\nIn this new graph, you want to know how many nodes are reachable from the node 0, where a node is reachable if the distance is maxMoves or less.\nGiven the original graph and maxMoves, return the number of nodes that are reachable from node 0 in the new graph.", + "examples": [ + "Example 1:\nInput: edges = [[0,1,10],[0,2,1],[1,2,2]], maxMoves = 6, n = 3\nOutput: 13\nExplanation: The edge subdivisions are shown in the image above.\nThe nodes that are reachable are highlighted in yellow.", + "Example 2:\nInput: edges = [[0,1,4],[1,2,6],[0,2,8],[1,3,1]], maxMoves = 10, n = 4\nOutput: 23", + "Example 3:\nInput: edges = [[1,2,4],[1,4,5],[1,3,1],[2,3,4],[3,4,5]], maxMoves = 17, n = 5\nOutput: 1\nExplanation: Node 0 is disconnected from the rest of the graph, so only node 0 is reachable." + ], + "constraints": "Constraints:\n\n0 <= edges.length <= min(n * (n - 1) / 2, 10^4)\nedges[i].length == 3\n0 <= ui < vi < n\nThere are no multiple edges in the graph.\n0 <= cnti <= 10^4\n0 <= maxMoves <= 10^9\n1 <= n <= 3000", + "tags": [ + "Graph", + "Heap (Priority Queue)", + "Shortest Path" + ], + "title-slug": "reachable-nodes-in-subdivided-graph" + }, + { + "leetcode-id": 883, + "title": "Projection Area of 3D Shapes", + "difficulty": 1, + "description": "You are given an n x n grid where we place some 1 x 1 x 1 cubes that are axis-aligned with the x, y, and z axes.\nEach value v = grid[i][j] represents a tower of v cubes placed on top of the cell (i, j).\nWe view the projection of these cubes onto the xy, yz, and zx planes.\nA projection is like a shadow, that maps our 3-dimensional figure to a 2-dimensional plane. We are viewing the \"shadow\" when looking at the cubes from the top, the front, and the side.\nReturn the total area of all three projections.", + "examples": [ + "Example 1:\nInput: grid = [[1,2],[3,4]]\nOutput: 17\nExplanation: Here are the three projections (\"shadows\") of the shape made with each axis-aligned plane.", + "Example 2:\nInput: grid = [[2]]\nOutput: 5", + "Example 3:\nInput: grid = [[1,0],[0,2]]\nOutput: 8" + ], + "constraints": "Constraints:\n\nn == grid.length == grid[i].length\n1 <= n <= 50\n0 <= grid[i][j] <= 50", + "tags": [ + "Array", + "Math", + "Geometry", + "Matrix" + ], + "title-slug": "projection-area-of-3d-shapes" + }, + { + "leetcode-id": 884, + "title": "Uncommon Words from Two Sentences", + "difficulty": 1, + "description": "A sentence is a string of single-space separated words where each word consists only of lowercase letters.\nA word is uncommon if it appears exactly once in one of the sentences, and does not appear in the other sentence.\nGiven two sentences s1 and s2, return a list of all the uncommon words. You may return the answer in any order.", + "examples": [ + "Example 1:\nInput: s1 = \"this apple is sweet\", s2 = \"this apple is sour\"\nOutput: [\"sweet\",\"sour\"]", + "Example 2:\nInput: s1 = \"apple apple\", s2 = \"banana\"\nOutput: [\"banana\"]" + ], + "constraints": "Constraints:\n\n1 <= s1.length, s2.length <= 200\ns1 and s2 consist of lowercase English letters and spaces.\ns1 and s2 do not have leading or trailing spaces.\nAll the words in s1 and s2 are separated by a single space.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "uncommon-words-from-two-sentences" + }, + { + "leetcode-id": 885, + "title": "Spiral Matrix III", + "difficulty": 2, + "description": "You start at the cell (rStart, cStart) of an rows x cols grid facing east. The northwest corner is at the first row and column in the grid, and the southeast corner is at the last row and column.\nYou will walk in a clockwise spiral shape to visit every position in this grid. Whenever you move outside the grid's boundary, we continue our walk outside the grid (but may return to the grid boundary later.). Eventually, we reach all rows * cols spaces of the grid.\nReturn an array of coordinates representing the positions of the grid in the order you visited them.", + "examples": [ + "Example 1:\nInput: rows = 1, cols = 4, rStart = 0, cStart = 0\nOutput: [[0,0],[0,1],[0,2],[0,3]]", + "Example 2:\nInput: rows = 5, cols = 6, rStart = 1, cStart = 4\nOutput: [[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],[3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,2],[4,1],[3,1],[2,1],[1,1],[0,1],[4,0],[3,0],[2,0],[1,0],[0,0]]" + ], + "constraints": "Constraints:\n\n1 <= rows, cols <= 100\n0 <= rStart < rows\n0 <= cStart < cols", + "tags": [ + "Array", + "Matrix", + "Simulation" + ], + "title-slug": "spiral-matrix-iii" + }, + { + "leetcode-id": 886, + "title": "Possible Bipartition", + "difficulty": 2, + "description": "We want to split a group of n people (labeled from 1 to n) into two groups of any size. Each person may dislike some other people, and they should not go into the same group.\nGiven the integer n and the array dislikes where dislikes[i] = [ai, bi] indicates that the person labeled ai does not like the person labeled bi, return true if it is possible to split everyone into two groups in this way.", + "examples": [ + "Example 1:\nInput: n = 4, dislikes = [[1,2],[1,3],[2,4]]\nOutput: true\nExplanation: The first group has [1,4], and the second group has [2,3].", + "Example 2:\nInput: n = 3, dislikes = [[1,2],[1,3],[2,3]]\nOutput: false\nExplanation: We need at least 3 groups to divide them. We cannot put them in two groups." + ], + "constraints": "Constraints:\n\n1 <= n <= 2000\n0 <= dislikes.length <= 10^4\ndislikes[i].length == 2\n1 <= ai < bi <= n\nAll the pairs of dislikes are unique.", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Graph" + ], + "title-slug": "possible-bipartition" + }, + { + "leetcode-id": 887, + "title": "Super Egg Drop", + "difficulty": 3, + "description": "You are given k identical eggs and you have access to a building with n floors labeled from 1 to n.\nYou know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.\nEach move, you may take an unbroken egg and drop it from any floor x (where 1 <= x <= n). If the egg breaks, you can no longer use it. However, if the egg does not break, you may reuse it in future moves.\nReturn the minimum number of moves that you need to determine with certainty what the value of f is.", + "examples": [ + "Example 1:\nInput: k = 1, n = 2\nOutput: 2\nExplanation: \nDrop the egg from floor 1. If it breaks, we know that f = 0.\nOtherwise, drop the egg from floor 2. If it breaks, we know that f = 1.\nIf it does not break, then we know f = 2.\nHence, we need at minimum 2 moves to determine with certainty what the value of f is.", + "Example 2:\nInput: k = 2, n = 6\nOutput: 3", + "Example 3:\nInput: k = 3, n = 14\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= k <= 100\n1 <= n <= 10^4", + "tags": [ + "Math", + "Binary Search", + "Dynamic Programming" + ], + "title-slug": "super-egg-drop" + }, + { + "leetcode-id": 888, + "title": "Fair Candy Swap", + "difficulty": 1, + "description": "Alice and Bob have a different total number of candies. You are given two integer arrays aliceSizes and bobSizes where aliceSizes[i] is the number of candies of the i^th box of candy that Alice has and bobSizes[j] is the number of candies of the j^th box of candy that Bob has.\nSince they are friends, they would like to exchange one candy box each so that after the exchange, they both have the same total amount of candy. The total amount of candy a person has is the sum of the number of candies in each box they have.\nReturn an integer array answer where answer[0] is the number of candies in the box that Alice must exchange, and answer[1] is the number of candies in the box that Bob must exchange. If there are multiple answers, you may return any one of them. It is guaranteed that at least one answer exists.", + "examples": [ + "Example 1:\nInput: aliceSizes = [1,1], bobSizes = [2,2]\nOutput: [1,2]", + "Example 2:\nInput: aliceSizes = [1,2], bobSizes = [2,3]\nOutput: [1,2]", + "Example 3:\nInput: aliceSizes = [2], bobSizes = [1,3]\nOutput: [2,3]" + ], + "constraints": "Constraints:\n\n1 <= aliceSizes.length, bobSizes.length <= 10^4\n1 <= aliceSizes[i], bobSizes[j] <= 10^5\nAlice and Bob have a different total number of candies.\nThere will be at least one valid answer for the given input.", + "tags": [ + "Array", + "Hash Table", + "Binary Search", + "Sorting" + ], + "title-slug": "fair-candy-swap" + }, + { + "leetcode-id": 889, + "title": "Construct Binary Tree from Preorder and Postorder Traversal", + "difficulty": 2, + "description": "Given two integer arrays, preorder and postorder where preorder is the preorder traversal of a binary tree of distinct values and postorder is the postorder traversal of the same tree, reconstruct and return the binary tree.\nIf there exist multiple answers, you can return any of them.", + "examples": [ + "Example 1:\nInput: preorder = [1,2,4,5,3,6,7], postorder = [4,5,2,6,7,3,1]\nOutput: [1,2,3,4,5,6,7]", + "Example 2:\nInput: preorder = [1], postorder = [1]\nOutput: [1]" + ], + "constraints": "Constraints:\n\n1 <= preorder.length <= 30\n1 <= preorder[i] <= preorder.length\nAll the values of preorder are unique.\npostorder.length == preorder.length\n1 <= postorder[i] <= postorder.length\nAll the values of postorder are unique.\nIt is guaranteed that preorder and postorder are the preorder traversal and postorder traversal of the same binary tree.", + "tags": [ + "Array", + "Hash Table", + "Divide and Conquer", + "Tree", + "Binary Tree" + ], + "title-slug": "construct-binary-tree-from-preorder-and-postorder-traversal" + }, + { + "leetcode-id": 890, + "title": "Find and Replace Pattern", + "difficulty": 2, + "description": "Given a list of strings words and a string pattern, return a list of words[i] that match pattern. You may return the answer in any order.\nA word matches the pattern if there exists a permutation of letters p so that after replacing every letter x in the pattern with p(x), we get the desired word.\nRecall that a permutation of letters is a bijection from letters to letters: every letter maps to another letter, and no two letters map to the same letter.", + "examples": [ + "Example 1:\nInput: words = [\"abc\",\"deq\",\"mee\",\"aqq\",\"dkd\",\"ccc\"], pattern = \"abb\"\nOutput: [\"mee\",\"aqq\"]\nExplanation: \"mee\" matches the pattern because there is a permutation {a -> m, b -> e, ...}. \n\"ccc\" does not match the pattern because {a -> c, b -> c, ...} is not a permutation, since a and b map to the same letter.", + "Example 2:\nInput: words = [\"a\",\"b\",\"c\"], pattern = \"a\"\nOutput: [\"a\",\"b\",\"c\"]" + ], + "constraints": "Constraints:\n\n1 <= pattern.length <= 20\n1 <= words.length <= 50\nwords[i].length == pattern.length\npattern and words[i] are lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "find-and-replace-pattern" + }, + { + "leetcode-id": 891, + "title": "Sum of Subsequence Widths", + "difficulty": 3, + "description": "The width of a sequence is the difference between the maximum and minimum elements in the sequence.\nGiven an array of integers nums, return the sum of the widths of all the non-empty subsequences of nums. Since the answer may be very large, return it modulo 10^9 + 7.\nA subsequence is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements. For example, [3,6,2,7] is a subsequence of the array [0,3,1,6,2,2,7].", + "examples": [ + "Example 1:\nInput: nums = [2,1,3]\nOutput: 6\nExplanation: The subsequences are [1], [2], [3], [2,1], [2,3], [1,3], [2,1,3].\nThe corresponding widths are 0, 0, 0, 1, 1, 2, 2.\nThe sum of these widths is 6.", + "Example 2:\nInput: nums = [2]\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Math", + "Sorting" + ], + "title-slug": "sum-of-subsequence-widths" + }, + { + "leetcode-id": 892, + "title": "Surface Area of 3D Shapes", + "difficulty": 1, + "description": "You are given an n x n grid where you have placed some 1 x 1 x 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of cell (i, j).\nAfter placing these cubes, you have decided to glue any directly adjacent cubes to each other, forming several irregular 3D shapes.\nReturn the total surface area of the resulting shapes.\nNote: The bottom face of each shape counts toward its surface area.", + "examples": [ + "Example 1:\nInput: grid = [[1,2],[3,4]]\nOutput: 34", + "Example 2:\nInput: grid = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: 32", + "Example 3:\nInput: grid = [[2,2,2],[2,1,2],[2,2,2]]\nOutput: 46" + ], + "constraints": "Constraints:\n\nn == grid.length == grid[i].length\n1 <= n <= 50\n0 <= grid[i][j] <= 50", + "tags": [ + "Array", + "Math", + "Geometry", + "Matrix" + ], + "title-slug": "surface-area-of-3d-shapes" + }, + { + "leetcode-id": 893, + "title": "Groups of Special-Equivalent Strings", + "difficulty": 2, + "description": "You are given an array of strings of the same length words.\nIn one move, you can swap any two even indexed characters or any two odd indexed characters of a string words[i].\nTwo strings words[i] and words[j] are special-equivalent if after any number of moves, words[i] == words[j].\n\nFor example, words[i] = \"zzxy\" and words[j] = \"xyzz\" are special-equivalent because we may make the moves \"zzxy\" -> \"xzzy\" -> \"xyzz\".\n\nA group of special-equivalent strings from words is a non-empty subset of words such that:\n\nEvery pair of strings in the group are special equivalent, and\nThe group is the largest size possible (i.e., there is not a string words[i] not in the group such that words[i] is special-equivalent to every string in the group).\n\nReturn the number of groups of special-equivalent strings from words.", + "examples": [ + "Example 1:\nInput: words = [\"abcd\",\"cdab\",\"cbad\",\"xyzz\",\"zzxy\",\"zzyx\"]\nOutput: 3\nExplanation: \nOne group is [\"abcd\", \"cdab\", \"cbad\"], since they are all pairwise special equivalent, and none of the other strings is all pairwise special equivalent to these.\nThe other two groups are [\"xyzz\", \"zzxy\"] and [\"zzyx\"].\nNote that in particular, \"zzxy\" is not special equivalent to \"zzyx\".", + "Example 2:\nInput: words = [\"abc\",\"acb\",\"bac\",\"bca\",\"cab\",\"cba\"]\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= words.length <= 1000\n1 <= words[i].length <= 20\nwords[i] consist of lowercase English letters.\nAll the strings are of the same length.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "groups-of-special-equivalent-strings" + }, + { + "leetcode-id": 894, + "title": "All Possible Full Binary Trees", + "difficulty": 2, + "description": "Given an integer n, return a list of all possible full binary trees with n nodes. Each node of each tree in the answer must have Node.val == 0.\nEach element of the answer is the root node of one possible tree. You may return the final list of trees in any order.\nA full binary tree is a binary tree where each node has exactly 0 or 2 children.", + "examples": [ + "Example 1:\nInput: n = 7\nOutput: [[0,0,0,null,null,0,0,null,null,0,0],[0,0,0,null,null,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,null,null,null,null,0,0],[0,0,0,0,0,null,null,0,0]]", + "Example 2:\nInput: n = 3\nOutput: [[0,0,0]]" + ], + "constraints": "Constraints:\n\n1 <= n <= 20", + "tags": [ + "Dynamic Programming", + "Tree", + "Recursion", + "Memoization", + "Binary Tree" + ], + "title-slug": "all-possible-full-binary-trees" + }, + { + "leetcode-id": 895, + "title": "Maximum Frequency Stack", + "difficulty": 3, + "description": "Design a stack-like data structure to push elements to the stack and pop the most frequent element from the stack.\nImplement the FreqStack class:\n\nFreqStack() constructs an empty frequency stack.\nvoid push(int val) pushes an integer val onto the top of the stack.\nint pop() removes and returns the most frequent element in the stack.\n\t\nIf there is a tie for the most frequent element, the element closest to the stack's top is removed and returned.", + "examples": [ + "Example 1:\nInput\n[\"FreqStack\", \"push\", \"push\", \"push\", \"push\", \"push\", \"push\", \"pop\", \"pop\", \"pop\", \"pop\"]\n[[], [5], [7], [5], [7], [4], [5], [], [], [], []]\nOutput\n[null, null, null, null, null, null, null, 5, 7, 5, 4]\n\nExplanation\nFreqStack freqStack = new FreqStack();\nfreqStack.push(5); // The stack is [5]\nfreqStack.push(7); // The stack is [5,7]\nfreqStack.push(5); // The stack is [5,7,5]\nfreqStack.push(7); // The stack is [5,7,5,7]\nfreqStack.push(4); // The stack is [5,7,5,7,4]\nfreqStack.push(5); // The stack is [5,7,5,7,4,5]\nfreqStack.pop(); // return 5, as 5 is the most frequent. The stack becomes [5,7,5,7,4].\nfreqStack.pop(); // return 7, as 5 and 7 is the most frequent, but 7 is closest to the top. The stack becomes [5,7,5,4].\nfreqStack.pop(); // return 5, as 5 is the most frequent. The stack becomes [5,7,4].\nfreqStack.pop(); // return 4, as 4, 5 and 7 is the most frequent, but 4 is closest to the top. The stack becomes [5,7]." + ], + "constraints": "Constraints:\n\n0 <= val <= 10^9\nAt most 2 * 10^4 calls will be made to push and pop.\nIt is guaranteed that there will be at least one element in the stack before calling pop.", + "tags": [ + "Hash Table", + "Stack", + "Design", + "Ordered Set" + ], + "title-slug": "maximum-frequency-stack" + }, + { + "leetcode-id": 896, + "title": "Monotonic Array", + "difficulty": 1, + "description": "An array is monotonic if it is either monotone increasing or monotone decreasing.\nAn array nums is monotone increasing if for all i <= j, nums[i] <= nums[j]. An array nums is monotone decreasing if for all i <= j, nums[i] >= nums[j].\nGiven an integer array nums, return true if the given array is monotonic, or false otherwise.", + "examples": [ + "Example 1:\nInput: nums = [1,2,2,3]\nOutput: true", + "Example 2:\nInput: nums = [6,5,4,4]\nOutput: true", + "Example 3:\nInput: nums = [1,3,2]\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^5 <= nums[i] <= 10^5", + "tags": [ + "Array" + ], + "title-slug": "monotonic-array" + }, + { + "leetcode-id": 897, + "title": "Increasing Order Search Tree", + "difficulty": 1, + "description": "Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child.", + "examples": [ + "Example 1:\nInput: root = [5,3,6,2,4,null,8,1,null,null,null,7,9]\nOutput: [1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9]", + "Example 2:\nInput: root = [5,1,7]\nOutput: [1,null,5,null,7]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the given tree will be in the range [1, 100].\n0 <= Node.val <= 1000", + "tags": [ + "Stack", + "Tree", + "Depth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "increasing-order-search-tree" + }, + { + "leetcode-id": 898, + "title": "Bitwise ORs of Subarrays", + "difficulty": 2, + "description": "Given an integer array arr, return the number of distinct bitwise ORs of all the non-empty subarrays of arr.\nThe bitwise OR of a subarray is the bitwise OR of each integer in the subarray. The bitwise OR of a subarray of one integer is that integer.\nA subarray is a contiguous non-empty sequence of elements within an array.", + "examples": [ + "Example 1:\nInput: arr = [0]\nOutput: 1\nExplanation: There is only one possible result: 0.", + "Example 2:\nInput: arr = [1,1,2]\nOutput: 3\nExplanation: The possible subarrays are [1], [1], [2], [1, 1], [1, 2], [1, 1, 2].\nThese yield the results 1, 1, 2, 1, 3, 3.\nThere are 3 unique values, so the answer is 3.", + "Example 3:\nInput: arr = [1,2,4]\nOutput: 6\nExplanation: The possible results are 1, 2, 3, 4, 6, and 7." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 5 * 10^4\n0 <= arr[i] <= 10^9", + "tags": [ + "Array", + "Dynamic Programming", + "Bit Manipulation" + ], + "title-slug": "bitwise-ors-of-subarrays" + }, + { + "leetcode-id": 899, + "title": "Orderly Queue", + "difficulty": 3, + "description": "You are given a string s and an integer k. You can choose one of the first k letters of s and append it at the end of the string.\nReturn the lexicographically smallest string you could have after applying the mentioned step any number of moves.", + "examples": [ + "Example 1:\nInput: s = \"cba\", k = 1\nOutput: \"acb\"\nExplanation: \nIn the first move, we move the 1^st character 'c' to the end, obtaining the string \"bac\".\nIn the second move, we move the 1^st character 'b' to the end, obtaining the final result \"acb\".", + "Example 2:\nInput: s = \"baaca\", k = 3\nOutput: \"aaabc\"\nExplanation: \nIn the first move, we move the 1^st character 'b' to the end, obtaining the string \"aacab\".\nIn the second move, we move the 3^rd character 'c' to the end, obtaining the final result \"aaabc\"." + ], + "constraints": "Constraints:\n\n1 <= k <= s.length <= 1000\ns consist of lowercase English letters.", + "tags": [ + "Math", + "String", + "Sorting" + ], + "title-slug": "orderly-queue" + }, + { + "leetcode-id": 900, + "title": "RLE Iterator", + "difficulty": 2, + "description": "We can use run-length encoding (i.e., RLE) to encode a sequence of integers. In a run-length encoded array of even length encoding (0-indexed), for all even i, encoding[i] tells us the number of times that the non-negative integer value encoding[i + 1] is repeated in the sequence.\n\nFor example, the sequence arr = [8,8,8,5,5] can be encoded to be encoding = [3,8,2,5]. encoding = [3,8,0,9,2,5] and encoding = [2,8,1,8,2,5] are also valid RLE of arr.\n\nGiven a run-length encoded array, design an iterator that iterates through it.\nImplement the RLEIterator class:\n\nRLEIterator(int[] encoded) Initializes the object with the encoded array encoded.\nint next(int n) Exhausts the next n elements and returns the last element exhausted in this way. If there is no element left to exhaust, return -1 instead.", + "examples": [ + "Example 1:\nInput\n[\"RLEIterator\", \"next\", \"next\", \"next\", \"next\"]\n[[[3, 8, 0, 9, 2, 5]], [2], [1], [1], [2]]\nOutput\n[null, 8, 8, 5, -1]\n\nExplanation\nRLEIterator rLEIterator = new RLEIterator([3, 8, 0, 9, 2, 5]); // This maps to the sequence [8,8,8,5,5].\nrLEIterator.next(2); // exhausts 2 terms of the sequence, returning 8. The remaining sequence is now [8, 5, 5].\nrLEIterator.next(1); // exhausts 1 term of the sequence, returning 8. The remaining sequence is now [5, 5].\nrLEIterator.next(1); // exhausts 1 term of the sequence, returning 5. The remaining sequence is now [5].\nrLEIterator.next(2); // exhausts 2 terms, returning -1. This is because the first term exhausted was 5,\nbut the second term did not exist. Since the last term exhausted does not exist, we return -1." + ], + "constraints": "Constraints:\n\n2 <= encoding.length <= 1000\nencoding.length is even.\n0 <= encoding[i] <= 10^9\n1 <= n <= 10^9\nAt most 1000 calls will be made to next.", + "tags": [ + "Array", + "Design", + "Counting", + "Iterator" + ], + "title-slug": "rle-iterator" + }, + { + "leetcode-id": 901, + "title": "Online Stock Span", + "difficulty": 2, + "description": "Design an algorithm that collects daily price quotes for some stock and returns the span of that stock's price for the current day.\nThe span of the stock's price in one day is the maximum number of consecutive days (starting from that day and going backward) for which the stock price was less than or equal to the price of that day.\n\nFor example, if the prices of the stock in the last four days is [7,2,1,2] and the price of the stock today is 2, then the span of today is 4 because starting from today, the price of the stock was less than or equal 2 for 4 consecutive days.\nAlso, if the prices of the stock in the last four days is [7,34,1,2] and the price of the stock today is 8, then the span of today is 3 because starting from today, the price of the stock was less than or equal 8 for 3 consecutive days.\n\nImplement the StockSpanner class:\n\nStockSpanner() Initializes the object of the class.\nint next(int price) Returns the span of the stock's price given that today's price is price.", + "examples": [ + "Example 1:\nInput\n[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]\n[[], [100], [80], [60], [70], [60], [75], [85]]\nOutput\n[null, 1, 1, 1, 2, 1, 4, 6]\n\nExplanation\nStockSpanner stockSpanner = new StockSpanner();\nstockSpanner.next(100); // return 1\nstockSpanner.next(80); // return 1\nstockSpanner.next(60); // return 1\nstockSpanner.next(70); // return 2\nstockSpanner.next(60); // return 1\nstockSpanner.next(75); // return 4, because the last 4 prices (including today's price of 75) were less than or equal to today's price.\nstockSpanner.next(85); // return 6" + ], + "constraints": "Constraints:\n\n1 <= price <= 10^5\nAt most 10^4 calls will be made to next.", + "tags": [ + "Stack", + "Design", + "Monotonic Stack", + "Data Stream" + ], + "title-slug": "online-stock-span" + }, + { + "leetcode-id": 902, + "title": "Numbers At Most N Given Digit Set", + "difficulty": 3, + "description": "Given an array of digits which is sorted in non-decreasing order. You can write numbers using each digits[i] as many times as we want. For example, if digits = ['1','3','5'], we may write numbers such as '13', '551', and '1351315'.\nReturn the number of positive integers that can be generated that are less than or equal to a given integer n.", + "examples": [ + "Example 1:\nInput: digits = [\"1\",\"3\",\"5\",\"7\"], n = 100\nOutput: 20\nExplanation: \nThe 20 numbers that can be written are:\n1, 3, 5, 7, 11, 13, 15, 17, 31, 33, 35, 37, 51, 53, 55, 57, 71, 73, 75, 77.", + "Example 2:\nInput: digits = [\"1\",\"4\",\"9\"], n = 1000000000\nOutput: 29523\nExplanation: \nWe can write 3 one digit numbers, 9 two digit numbers, 27 three digit numbers,\n81 four digit numbers, 243 five digit numbers, 729 six digit numbers,\n2187 seven digit numbers, 6561 eight digit numbers, and 19683 nine digit numbers.\nIn total, this is 29523 integers that can be written using the digits array.", + "Example 3:\nInput: digits = [\"7\"], n = 8\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= digits.length <= 9\ndigits[i].length == 1\ndigits[i] is a digit from\u00a0'1'\u00a0to '9'.\nAll the values in\u00a0digits are unique.\ndigits is sorted in\u00a0non-decreasing order.\n1 <= n <= 10^9", + "tags": [ + "Array", + "Math", + "String", + "Binary Search", + "Dynamic Programming" + ], + "title-slug": "numbers-at-most-n-given-digit-set" + }, + { + "leetcode-id": 903, + "title": "Valid Permutations for DI Sequence", + "difficulty": 3, + "description": "You are given a string s of length n where s[i] is either:\n\n'D' means decreasing, or\n'I' means increasing.\n\nA permutation perm of n + 1 integers of all the integers in the range [0, n] is called a valid permutation if for all valid i:\n\nIf s[i] == 'D', then perm[i] > perm[i + 1], and\nIf s[i] == 'I', then perm[i] < perm[i + 1].\n\nReturn the number of valid permutations perm. Since the answer may be large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: s = \"DID\"\nOutput: 5\nExplanation: The 5 valid permutations of (0, 1, 2, 3) are:\n(1, 0, 3, 2)\n(2, 0, 3, 1)\n(2, 1, 3, 0)\n(3, 0, 2, 1)\n(3, 1, 2, 0)", + "Example 2:\nInput: s = \"D\"\nOutput: 1" + ], + "constraints": "Constraints:\n\nn == s.length\n1 <= n <= 200\ns[i] is either 'I' or 'D'.", + "tags": [ + "String", + "Dynamic Programming", + "Prefix Sum" + ], + "title-slug": "valid-permutations-for-di-sequence" + }, + { + "leetcode-id": 904, + "title": "Fruit Into Baskets", + "difficulty": 2, + "description": "You are visiting a farm that has a single row of fruit trees arranged from left to right. The trees are represented by an integer array fruits where fruits[i] is the type of fruit the i^th tree produces.\nYou want to collect as much fruit as possible. However, the owner has some strict rules that you must follow:\n\nYou only have two baskets, and each basket can only hold a single type of fruit. There is no limit on the amount of fruit each basket can hold.\nStarting from any tree of your choice, you must pick exactly one fruit from every tree (including the start tree) while moving to the right. The picked fruits must fit in one of your baskets.\nOnce you reach a tree with fruit that cannot fit in your baskets, you must stop.\n\nGiven the integer array fruits, return the maximum number of fruits you can pick.", + "examples": [ + "Example 1:\nInput: fruits = [1,2,1]\nOutput: 3\nExplanation: We can pick from all 3 trees.", + "Example 2:\nInput: fruits = [0,1,2,2]\nOutput: 3\nExplanation: We can pick from trees [1,2,2].\nIf we had started at the first tree, we would only pick from trees [0,1].", + "Example 3:\nInput: fruits = [1,2,3,2,2]\nOutput: 4\nExplanation: We can pick from trees [2,3,2,2].\nIf we had started at the first tree, we would only pick from trees [1,2]." + ], + "constraints": "Constraints:\n\n1 <= fruits.length <= 10^5\n0 <= fruits[i] < fruits.length", + "tags": [ + "Array", + "Hash Table", + "Sliding Window" + ], + "title-slug": "fruit-into-baskets" + }, + { + "leetcode-id": 905, + "title": "Sort Array By Parity", + "difficulty": 1, + "description": "Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers.\nReturn any array that satisfies this condition.", + "examples": [ + "Example 1:\nInput: nums = [3,1,2,4]\nOutput: [2,4,3,1]\nExplanation: The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.", + "Example 2:\nInput: nums = [0]\nOutput: [0]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 5000\n0 <= nums[i] <= 5000", + "tags": [ + "Array", + "Two Pointers", + "Sorting" + ], + "title-slug": "sort-array-by-parity" + }, + { + "leetcode-id": 906, + "title": "Super Palindromes", + "difficulty": 3, + "description": "Let's say a positive integer is a super-palindrome if it is a palindrome, and it is also the square of a palindrome.\nGiven two positive integers left and right represented as strings, return the number of super-palindromes integers in the inclusive range [left, right].", + "examples": [ + "Example 1:\nInput: left = \"4\", right = \"1000\"\nOutput: 4\nExplanation: 4, 9, 121, and 484 are superpalindromes.\nNote that 676 is not a superpalindrome: 26 * 26 = 676, but 26 is not a palindrome.", + "Example 2:\nInput: left = \"1\", right = \"2\"\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= left.length, right.length <= 18\nleft and right consist of only digits.\nleft and right cannot have leading zeros.\nleft and right represent integers in the range [1, 10^18 - 1].\nleft is less than or equal to right.", + "tags": [ + "Math", + "Enumeration" + ], + "title-slug": "super-palindromes" + }, + { + "leetcode-id": 907, + "title": "Sum of Subarray Minimums", + "difficulty": 2, + "description": "Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: arr = [3,1,2,4]\nOutput: 17\nExplanation: \nSubarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,2,4], [3,1,2,4]. \nMinimums are 3, 1, 2, 4, 1, 1, 2, 1, 1, 1.\nSum is 17.", + "Example 2:\nInput: arr = [11,81,94,43,3]\nOutput: 444" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 3 * 10^4\n1 <= arr[i] <= 3 * 10^4", + "tags": [ + "Array", + "Dynamic Programming", + "Stack", + "Monotonic Stack" + ], + "title-slug": "sum-of-subarray-minimums" + }, + { + "leetcode-id": 908, + "title": "Smallest Range I", + "difficulty": 1, + "description": "You are given an integer array nums and an integer k.\nIn one operation, you can choose any index i where 0 <= i < nums.length and change nums[i] to nums[i] + x where x is an integer from the range [-k, k]. You can apply this operation at most once for each index i.\nThe score of nums is the difference between the maximum and minimum elements in nums.\nReturn the minimum score of nums after applying the mentioned operation at most once for each index in it.", + "examples": [ + "Example 1:\nInput: nums = [1], k = 0\nOutput: 0\nExplanation: The score is max(nums) - min(nums) = 1 - 1 = 0.", + "Example 2:\nInput: nums = [0,10], k = 2\nOutput: 6\nExplanation: Change nums to be [2, 8]. The score is max(nums) - min(nums) = 8 - 2 = 6.", + "Example 3:\nInput: nums = [1,3,6], k = 3\nOutput: 0\nExplanation: Change nums to be [4, 4, 4]. The score is max(nums) - min(nums) = 4 - 4 = 0." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n0 <= nums[i] <= 10^4\n0 <= k <= 10^4", + "tags": [ + "Array", + "Math" + ], + "title-slug": "smallest-range-i" + }, + { + "leetcode-id": 909, + "title": "Snakes and Ladders", + "difficulty": 2, + "description": "You are given an n x n integer matrix board where the cells are labeled from 1 to n^2 in a Boustrophedon style starting from the bottom left of the board (i.e. board[n - 1][0]) and alternating direction each row.\nYou start on square 1 of the board. In each move, starting from square curr, do the following:\n\nChoose a destination square next with a label in the range [curr + 1, min(curr + 6, n^2)].\n\n\t\nThis choice simulates the result of a standard 6-sided die roll: i.e., there are always at most 6 destinations, regardless of the size of the board.\n\n\nIf next has a snake or ladder, you must move to the destination of that snake or ladder. Otherwise, you move to next.\nThe game ends when you reach the square n^2.\n\nA board square on row r and column c has a snake or ladder if board[r][c] != -1. The destination of that snake or ladder is board[r][c]. Squares 1 and n^2 do not have a snake or ladder.\nNote that you only take a snake or ladder at most once per move. If the destination to a snake or ladder is the start of another snake or ladder, you do not follow the subsequent\u00a0snake or ladder.\n\nFor example, suppose the board is [[-1,4],[-1,3]], and on the first move, your destination square is 2. You follow the ladder to square 3, but do not follow the subsequent ladder to 4.\n\nReturn the least number of moves required to reach the square n^2. If it is not possible to reach the square, return -1.", + "examples": [ + "Example 1:\nInput: board = [[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,35,-1,-1,13,-1],[-1,-1,-1,-1,-1,-1],[-1,15,-1,-1,-1,-1]]\nOutput: 4\nExplanation: \nIn the beginning, you start at square 1 (at row 5, column 0).\nYou decide to move to square 2 and must take the ladder to square 15.\nYou then decide to move to square 17 and must take the snake to square 13.\nYou then decide to move to square 14 and must take the ladder to square 35.\nYou then decide to move to square 36, ending the game.\nThis is the lowest possible number of moves to reach the last square, so return 4.", + "Example 2:\nInput: board = [[-1,-1],[-1,3]]\nOutput: 1" + ], + "constraints": "Constraints:\n\nn == board.length == board[i].length\n2 <= n <= 20\nboard[i][j] is either -1 or in the range [1, n^2].\nThe squares labeled 1 and n^2 do not have any ladders or snakes.", + "tags": [ + "Array", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "snakes-and-ladders" + }, + { + "leetcode-id": 910, + "title": "Smallest Range II", + "difficulty": 2, + "description": "You are given an integer array nums and an integer k.\nFor each index i where 0 <= i < nums.length, change nums[i] to be either nums[i] + k or nums[i] - k.\nThe score of nums is the difference between the maximum and minimum elements in nums.\nReturn the minimum score of nums after changing the values at each index.", + "examples": [ + "Example 1:\nInput: nums = [1], k = 0\nOutput: 0\nExplanation: The score is max(nums) - min(nums) = 1 - 1 = 0.", + "Example 2:\nInput: nums = [0,10], k = 2\nOutput: 6\nExplanation: Change nums to be [2, 8]. The score is max(nums) - min(nums) = 8 - 2 = 6.", + "Example 3:\nInput: nums = [1,3,6], k = 3\nOutput: 3\nExplanation: Change nums to be [4, 6, 3]. The score is max(nums) - min(nums) = 6 - 3 = 3." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n0 <= nums[i] <= 10^4\n0 <= k <= 10^4", + "tags": [ + "Array", + "Math", + "Greedy", + "Sorting" + ], + "title-slug": "smallest-range-ii" + }, + { + "leetcode-id": 911, + "title": "Online Election", + "difficulty": 2, + "description": "You are given two integer arrays persons and times. In an election, the i^th vote was cast for persons[i] at time times[i].\nFor each query at a time t, find the person that was leading the election at time t. Votes cast at time t will count towards our query. In the case of a tie, the most recent vote (among tied candidates) wins.\nImplement the TopVotedCandidate class:\n\nTopVotedCandidate(int[] persons, int[] times) Initializes the object with the persons and times arrays.\nint q(int t) Returns the number of the person that was leading the election at time t according to the mentioned rules.", + "examples": [ + "Example 1:\nInput\n[\"TopVotedCandidate\", \"q\", \"q\", \"q\", \"q\", \"q\", \"q\"]\n[[[0, 1, 1, 0, 0, 1, 0], [0, 5, 10, 15, 20, 25, 30]], [3], [12], [25], [15], [24], [8]]\nOutput\n[null, 0, 1, 1, 0, 0, 1]\n\nExplanation\nTopVotedCandidate topVotedCandidate = new TopVotedCandidate([0, 1, 1, 0, 0, 1, 0], [0, 5, 10, 15, 20, 25, 30]);\ntopVotedCandidate.q(3); // return 0, At time 3, the votes are [0], and 0 is leading.\ntopVotedCandidate.q(12); // return 1, At time 12, the votes are [0,1,1], and 1 is leading.\ntopVotedCandidate.q(25); // return 1, At time 25, the votes are [0,1,1,0,0,1], and 1 is leading (as ties go to the most recent vote.)\ntopVotedCandidate.q(15); // return 0\ntopVotedCandidate.q(24); // return 0\ntopVotedCandidate.q(8); // return 1" + ], + "constraints": "Constraints:\n\n1 <= persons.length <= 5000\ntimes.length == persons.length\n0 <= persons[i] < persons.length\n0 <= times[i] <= 10^9\ntimes is sorted in a strictly increasing order.\ntimes[0] <= t <= 10^9\nAt most 10^4 calls will be made to q.", + "tags": [ + "Array", + "Hash Table", + "Binary Search", + "Design" + ], + "title-slug": "online-election" + }, + { + "leetcode-id": 912, + "title": "Sort an Array", + "difficulty": 2, + "description": "Given an array of integers nums, sort the array in ascending order and return it.\nYou must solve the problem without using any built-in functions in O(nlog(n)) time complexity and with the smallest space complexity possible.", + "examples": [ + "Example 1:\nInput: nums = [5,2,3,1]\nOutput: [1,2,3,5]\nExplanation: After sorting the array, the positions of some numbers are not changed (for example, 2 and 3), while the positions of other numbers are changed (for example, 1 and 5).", + "Example 2:\nInput: nums = [5,1,1,2,0,0]\nOutput: [0,0,1,1,2,5]\nExplanation: Note that the values of nums are not necessairly unique." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 5 * 10^4\n-5 * 10^4 <= nums[i] <= 5 * 10^4", + "tags": [ + "Array", + "Divide and Conquer", + "Sorting", + "Heap (Priority Queue)", + "Merge Sort", + "Bucket Sort", + "Radix Sort", + "Counting Sort" + ], + "title-slug": "sort-an-array" + }, + { + "leetcode-id": 913, + "title": "Cat and Mouse", + "difficulty": 3, + "description": "A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns.\nThe graph is given as follows: graph[a] is a list of all nodes b such that ab is an edge of the graph.\nThe mouse starts at node 1 and goes first, the cat starts at node 2 and goes second, and there is a hole at node 0.\nDuring each player's turn, they must travel along one\u00a0edge of the graph that meets where they are.\u00a0 For example, if the Mouse is at node 1, it must travel to any node in graph[1].\nAdditionally, it is not allowed for the Cat to travel to the Hole (node 0.)\nThen, the game can end in three\u00a0ways:\n\nIf ever the Cat occupies the same node as the Mouse, the Cat wins.\nIf ever the Mouse reaches the Hole, the Mouse wins.\nIf ever a position is repeated (i.e., the players are in the same position as a previous turn, and\u00a0it is the same player's turn to move), the game is a draw.\n\nGiven a graph, and assuming both players play optimally, return\n\n1\u00a0if the mouse wins the game,\n2\u00a0if the cat wins the game, or\n0\u00a0if the game is a draw.", + "examples": [ + "Example 1:\nInput: graph = [[2,5],[3],[0,4,5],[1,4,5],[2,3],[0,2,3]]\nOutput: 0", + "Example 2:\nInput: graph = [[1,3],[0],[3],[0,2]]\nOutput: 1" + ], + "constraints": "Constraints:\n\n3 <= graph.length <= 50\n1\u00a0<= graph[i].length < graph.length\n0 <= graph[i][j] < graph.length\ngraph[i][j] != i\ngraph[i] is unique.\nThe mouse and the cat can always move.", + "tags": [ + "Math", + "Dynamic Programming", + "Graph", + "Topological Sort", + "Memoization", + "Game Theory" + ], + "title-slug": "cat-and-mouse" + }, + { + "leetcode-id": 914, + "title": "X of a Kind in a Deck of Cards", + "difficulty": 1, + "description": "You are given an integer array deck where deck[i] represents the number written on the i^th card.\nPartition the cards into one or more groups such that:\n\nEach group has exactly x cards where x > 1, and\nAll the cards in one group have the same integer written on them.\n\nReturn true if such partition is possible, or false otherwise.", + "examples": [ + "Example 1:\nInput: deck = [1,2,3,4,4,3,2,1]\nOutput: true\nExplanation: Possible partition [1,1],[2,2],[3,3],[4,4].", + "Example 2:\nInput: deck = [1,1,1,2,2,2,3,3]\nOutput: false\nExplanation: No possible partition." + ], + "constraints": "Constraints:\n\n1 <= deck.length <= 10^4\n0 <= deck[i] < 10^4", + "tags": [ + "Array", + "Hash Table", + "Math", + "Counting", + "Number Theory" + ], + "title-slug": "x-of-a-kind-in-a-deck-of-cards" + }, + { + "leetcode-id": 915, + "title": "Partition Array into Disjoint Intervals", + "difficulty": 2, + "description": "Given an integer array nums, partition it into two (contiguous) subarrays left and right so that:\n\nEvery element in left is less than or equal to every element in right.\nleft and right are non-empty.\nleft has the smallest possible size.\n\nReturn the length of left after such a partitioning.\nTest cases are generated such that partitioning exists.", + "examples": [ + "Example 1:\nInput: nums = [5,0,3,8,6]\nOutput: 3\nExplanation: left = [5,0,3], right = [8,6]", + "Example 2:\nInput: nums = [1,1,1,0,6,12]\nOutput: 4\nExplanation: left = [1,1,1,0], right = [6,12]" + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 10^5\n0 <= nums[i] <= 10^6\nThere is at least one valid answer for the given input.", + "tags": [ + "Array" + ], + "title-slug": "partition-array-into-disjoint-intervals" + }, + { + "leetcode-id": 916, + "title": "Word Subsets", + "difficulty": 2, + "description": "You are given two string arrays words1 and words2.\nA string b is a subset of string a if every letter in b occurs in a including multiplicity.\n\nFor example, \"wrr\" is a subset of \"warrior\" but is not a subset of \"world\".\n\nA string a from words1 is universal if for every string b in words2, b is a subset of a.\nReturn an array of all the universal strings in words1. You may return the answer in any order.", + "examples": [ + "Example 1:\nInput: words1 = [\"amazon\",\"apple\",\"facebook\",\"google\",\"leetcode\"], words2 = [\"e\",\"o\"]\nOutput: [\"facebook\",\"google\",\"leetcode\"]", + "Example 2:\nInput: words1 = [\"amazon\",\"apple\",\"facebook\",\"google\",\"leetcode\"], words2 = [\"l\",\"e\"]\nOutput: [\"apple\",\"google\",\"leetcode\"]" + ], + "constraints": "Constraints:\n\n1 <= words1.length, words2.length <= 10^4\n1 <= words1[i].length, words2[i].length <= 10\nwords1[i] and words2[i] consist only of lowercase English letters.\nAll the strings of words1 are unique.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "word-subsets" + }, + { + "leetcode-id": 917, + "title": "Reverse Only Letters", + "difficulty": 1, + "description": "Given a string s, reverse the string according to the following rules:\n\nAll the characters that are not English letters remain in the same position.\nAll the English letters (lowercase or uppercase) should be reversed.\n\nReturn s after reversing it.", + "examples": [ + "Example 1:\nInput: s = \"ab-cd\"\nOutput: \"dc-ba\"", + "Example 2:\nInput: s = \"a-bC-dEf-ghIj\"\nOutput: \"j-Ih-gfE-dCba\"", + "Example 3:\nInput: s = \"Test1ng-Leet=code-Q!\"\nOutput: \"Qedo1ct-eeLg=ntse-T!\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\ns consists of characters with ASCII values in the range [33, 122].\ns does not contain '\\\"' or '\\\\'.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "reverse-only-letters" + }, + { + "leetcode-id": 918, + "title": "Maximum Sum Circular Subarray", + "difficulty": 2, + "description": "Given a circular integer array nums of length n, return the maximum possible sum of a non-empty subarray of nums.\nA circular array means the end of the array connects to the beginning of the array. Formally, the next element of nums[i] is nums[(i + 1) % n] and the previous element of nums[i] is nums[(i - 1 + n) % n].\nA subarray may only include each element of the fixed buffer nums at most once. Formally, for a subarray nums[i], nums[i + 1], ..., nums[j], there does not exist i <= k1, k2 <= j with k1 % n == k2 % n.", + "examples": [ + "Example 1:\nInput: nums = [1,-2,3,-2]\nOutput: 3\nExplanation: Subarray [3] has maximum sum 3.", + "Example 2:\nInput: nums = [5,-3,5]\nOutput: 10\nExplanation: Subarray [5,5] has maximum sum 5 + 5 = 10.", + "Example 3:\nInput: nums = [-3,-2,-3]\nOutput: -2\nExplanation: Subarray [-2] has maximum sum -2." + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 3 * 10^4\n-3 * 10^4 <= nums[i] <= 3 * 10^4", + "tags": [ + "Array", + "Divide and Conquer", + "Dynamic Programming", + "Queue", + "Monotonic Queue" + ], + "title-slug": "maximum-sum-circular-subarray" + }, + { + "leetcode-id": 919, + "title": "Complete Binary Tree Inserter", + "difficulty": 2, + "description": "A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.\nDesign an algorithm to insert a new node to a complete binary tree keeping it complete after the insertion.\nImplement the CBTInserter class:\n\nCBTInserter(TreeNode root) Initializes the data structure with the root of the complete binary tree.\nint insert(int v) Inserts a TreeNode into the tree with value Node.val == val so that the tree remains complete, and returns the value of the parent of the inserted TreeNode.\nTreeNode get_root() Returns the root node of the tree.", + "examples": [ + "Example 1:\nInput\n[\"CBTInserter\", \"insert\", \"insert\", \"get_root\"]\n[[[1, 2]], [3], [4], []]\nOutput\n[null, 1, 2, [1, 2, 3, 4]]\n\nExplanation\nCBTInserter cBTInserter = new CBTInserter([1, 2]);\ncBTInserter.insert(3); // return 1\ncBTInserter.insert(4); // return 2\ncBTInserter.get_root(); // return [1, 2, 3, 4]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree will be in the range [1, 1000].\n0 <= Node.val <= 5000\nroot is a complete binary tree.\n0 <= val <= 5000\nAt most 10^4 calls will be made to insert and get_root.", + "tags": [ + "Tree", + "Breadth-First Search", + "Design", + "Binary Tree" + ], + "title-slug": "complete-binary-tree-inserter" + }, + { + "leetcode-id": 920, + "title": "Number of Music Playlists", + "difficulty": 3, + "description": "Your music player contains n different songs. You want to listen to goal songs (not necessarily different) during your trip. To avoid boredom, you will create a playlist so that:\n\nEvery song is played at least once.\nA song can only be played again only if k other songs have been played.\n\nGiven n, goal, and k, return the number of possible playlists that you can create. Since the answer can be very large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 3, goal = 3, k = 1\nOutput: 6\nExplanation: There are 6 possible playlists: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], and [3, 2, 1].", + "Example 2:\nInput: n = 2, goal = 3, k = 0\nOutput: 6\nExplanation: There are 6 possible playlists: [1, 1, 2], [1, 2, 1], [2, 1, 1], [2, 2, 1], [2, 1, 2], and [1, 2, 2].", + "Example 3:\nInput: n = 2, goal = 3, k = 1\nOutput: 2\nExplanation: There are 2 possible playlists: [1, 2, 1] and [2, 1, 2]." + ], + "constraints": "Constraints:\n\n0 <= k < n <= goal <= 100", + "tags": [ + "Math", + "Dynamic Programming", + "Combinatorics" + ], + "title-slug": "number-of-music-playlists" + }, + { + "leetcode-id": 921, + "title": "Minimum Add to Make Parentheses Valid", + "difficulty": 2, + "description": "A parentheses string is valid if and only if:\n\nIt is the empty string,\nIt can be written as AB (A concatenated with B), where A and B are valid strings, or\nIt can be written as (A), where A is a valid string.\n\nYou are given a parentheses string s. In one move, you can insert a parenthesis at any position of the string.\n\nFor example, if s = \"()))\", you can insert an opening parenthesis to be \"(()))\" or a closing parenthesis to be \"())))\".\n\nReturn the minimum number of moves required to make s valid.", + "examples": [ + "Example 1:\nInput: s = \"())\"\nOutput: 1", + "Example 2:\nInput: s = \"(((\"\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns[i] is either '(' or ')'.", + "tags": [ + "String", + "Stack", + "Greedy" + ], + "title-slug": "minimum-add-to-make-parentheses-valid" + }, + { + "leetcode-id": 922, + "title": "Sort Array By Parity II", + "difficulty": 1, + "description": "Given an array of integers nums, half of the integers in nums are odd, and the other half are even.\nSort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.\nReturn any answer array that satisfies this condition.", + "examples": [ + "Example 1:\nInput: nums = [4,2,5,7]\nOutput: [4,5,2,7]\nExplanation: [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have been accepted.", + "Example 2:\nInput: nums = [2,3]\nOutput: [2,3]" + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 2 * 10^4\nnums.length is even.\nHalf of the integers in nums are even.\n0 <= nums[i] <= 1000\n\n\u00a0\nFollow Up: Could you solve it in-place?", + "tags": [ + "Array", + "Two Pointers", + "Sorting" + ], + "title-slug": "sort-array-by-parity-ii" + }, + { + "leetcode-id": 923, + "title": "3Sum With Multiplicity", + "difficulty": 2, + "description": "Given an integer array arr, and an integer target, return the number of tuples i, j, k such that i < j < k and arr[i] + arr[j] + arr[k] == target.\nAs the answer can be very large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: arr = [1,1,2,2,3,3,4,4,5,5], target = 8\nOutput: 20\nExplanation: \nEnumerating by the values (arr[i], arr[j], arr[k]):\n(1, 2, 5) occurs 8 times;\n(1, 3, 4) occurs 8 times;\n(2, 2, 4) occurs 2 times;\n(2, 3, 3) occurs 2 times.", + "Example 2:\nInput: arr = [1,1,2,2,2,2], target = 5\nOutput: 12\nExplanation: \narr[i] = 1, arr[j] = arr[k] = 2 occurs 12 times:\nWe choose one 1 from [1,1] in 2 ways,\nand two 2s from [2,2,2,2] in 6 ways.", + "Example 3:\nInput: arr = [2,1,3], target = 6\nOutput: 1\nExplanation: (1, 2, 3) occured one time in the array so we return 1." + ], + "constraints": "Constraints:\n\n3 <= arr.length <= 3000\n0 <= arr[i] <= 100\n0 <= target <= 300", + "tags": [ + "Array", + "Hash Table", + "Two Pointers", + "Sorting", + "Counting" + ], + "title-slug": "3sum-with-multiplicity" + }, + { + "leetcode-id": 924, + "title": "Minimize Malware Spread", + "difficulty": 3, + "description": "You are given a network of n nodes represented as an n x n adjacency matrix graph, where the i^th node is directly connected to the j^th node if graph[i][j] == 1.\nSome nodes initial are initially infected by malware. Whenever two nodes are directly connected, and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.\nSuppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops. We will remove exactly one node from initial.\nReturn the node that, if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.\nNote that if a node was removed from the initial list of infected nodes, it might still be infected later due to the malware spread.", + "examples": [ + "Example 1:\nInput: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]\nOutput: 0", + "Example 2:\nInput: graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2]\nOutput: 0", + "Example 3:\nInput: graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2]\nOutput: 1" + ], + "constraints": "Constraints:\n\nn == graph.length\nn == graph[i].length\n2 <= n <= 300\ngraph[i][j] is 0 or 1.\ngraph[i][j] == graph[j][i]\ngraph[i][i] == 1\n1 <= initial.length <= n\n0 <= initial[i] <= n - 1\nAll the integers in initial are unique.", + "tags": [ + "Hash Table", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Graph" + ], + "title-slug": "minimize-malware-spread" + }, + { + "leetcode-id": 925, + "title": "Long Pressed Name", + "difficulty": 1, + "description": "Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.\nYou examine the typed characters of the keyboard. Return True if it is possible that it was your friends name, with some characters (possibly none) being long pressed.", + "examples": [ + "Example 1:\nInput: name = \"alex\", typed = \"aaleex\"\nOutput: true\nExplanation: 'a' and 'e' in 'alex' were long pressed.", + "Example 2:\nInput: name = \"saeed\", typed = \"ssaaedd\"\nOutput: false\nExplanation: 'e' must have been pressed twice, but it was not in the typed output." + ], + "constraints": "Constraints:\n\n1 <= name.length, typed.length <= 1000\nname and typed consist of only lowercase English letters.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "long-pressed-name" + }, + { + "leetcode-id": 926, + "title": "Flip String to Monotone Increasing", + "difficulty": 2, + "description": "A binary string is monotone increasing if it consists of some number of 0's (possibly none), followed by some number of 1's (also possibly none).\nYou are given a binary string s. You can flip s[i] changing it from 0 to 1 or from 1 to 0.\nReturn the minimum number of flips to make s monotone increasing.", + "examples": [ + "Example 1:\nInput: s = \"00110\"\nOutput: 1\nExplanation: We flip the last digit to get 00111.", + "Example 2:\nInput: s = \"010110\"\nOutput: 2\nExplanation: We flip to get 011111, or alternatively 000111.", + "Example 3:\nInput: s = \"00011000\"\nOutput: 2\nExplanation: We flip to get 00000000." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns[i] is either '0' or '1'.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "flip-string-to-monotone-increasing" + }, + { + "leetcode-id": 927, + "title": "Three Equal Parts", + "difficulty": 3, + "description": "You are given an array arr which consists of only zeros and ones, divide the array into three non-empty parts such that all of these parts represent the same binary value.\nIf it is possible, return any [i, j] with i + 1 < j, such that:\n\narr[0], arr[1], ..., arr[i] is the first part,\narr[i + 1], arr[i + 2], ..., arr[j - 1] is the second part, and\narr[j], arr[j + 1], ..., arr[arr.length - 1] is the third part.\nAll three parts have equal binary values.\n\nIf it is not possible, return [-1, -1].\nNote that the entire part is used when considering what binary value it represents. For example, [1,1,0] represents 6 in decimal, not 3. Also, leading zeros are allowed, so [0,1,1] and [1,1] represent the same value.", + "examples": [ + "Example 1:\nInput: arr = [1,0,1,0,1]\nOutput: [0,3]", + "Example 2:\nInput: arr = [1,1,0,1,1]\nOutput: [-1,-1]", + "Example 3:\nInput: arr = [1,1,0,0,1]\nOutput: [0,2]" + ], + "constraints": "Constraints:\n\n3 <= arr.length <= 3 * 10^4\narr[i] is 0 or 1", + "tags": [ + "Array", + "Math" + ], + "title-slug": "three-equal-parts" + }, + { + "leetcode-id": 928, + "title": "Minimize Malware Spread II", + "difficulty": 3, + "description": "You are given a network of n nodes represented as an n x n adjacency matrix graph, where the i^th node is directly connected to the j^th node if graph[i][j] == 1.\nSome nodes initial are initially infected by malware. Whenever two nodes are directly connected, and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.\nSuppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops.\nWe will remove exactly one node from initial, completely removing it and any connections from this node to any other node.\nReturn the node that, if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.", + "examples": [ + "Example 1:\nInput: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]\nOutput: 0", + "Example 2:\nInput: graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]\nOutput: 1", + "Example 3:\nInput: graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]\nOutput: 1" + ], + "constraints": "Constraints:\n\nn == graph.length\nn == graph[i].length\n2 <= n <= 300\ngraph[i][j] is 0 or 1.\ngraph[i][j] == graph[j][i]\ngraph[i][i] == 1\n1 <= initial.length <\u00a0n\n0 <= initial[i] <= n - 1\nAll the integers in initial are unique.", + "tags": [ + "Hash Table", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Graph" + ], + "title-slug": "minimize-malware-spread-ii" + }, + { + "leetcode-id": 929, + "title": "Unique Email Addresses", + "difficulty": 1, + "description": "Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase letters, the email may contain one or more '.' or '+'.\n\nFor example, in \"alice@leetcode.com\", \"alice\" is the local name, and \"leetcode.com\" is the domain name.\n\nIf you add periods '.' between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name. Note that this rule does not apply to domain names.\n\nFor example, \"alice.z@leetcode.com\" and \"alicez@leetcode.com\" forward to the same email address.\n\nIf you add a plus '+' in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered. Note that this rule does not apply to domain names.\n\nFor example, \"m.y+name@email.com\" will be forwarded to \"my@email.com\".\n\nIt is possible to use both of these rules at the same time.\nGiven an array of strings emails where we send one email to each emails[i], return the number of different addresses that actually receive mails.", + "examples": [ + "Example 1:\nInput: emails = [\"test.email+alex@leetcode.com\",\"test.e.mail+bob.cathy@leetcode.com\",\"testemail+david@lee.tcode.com\"]\nOutput: 2\nExplanation: \"testemail@leetcode.com\" and \"testemail@lee.tcode.com\" actually receive mails.", + "Example 2:\nInput: emails = [\"a@leetcode.com\",\"b@leetcode.com\",\"c@leetcode.com\"]\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= emails.length <= 100\n1 <= emails[i].length <= 100\nemails[i] consist of lowercase English letters, '+', '.' and '@'.\nEach emails[i] contains exactly one '@' character.\nAll local and domain names are non-empty.\nLocal names do not start with a '+' character.\nDomain names end with the \".com\" suffix.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "unique-email-addresses" + }, + { + "leetcode-id": 930, + "title": "Binary Subarrays With Sum", + "difficulty": 2, + "description": "Given a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal.\nA subarray is a contiguous part of the array.", + "examples": [ + "Example 1:\nInput: nums = [1,0,1,0,1], goal = 2\r\nOutput: 4\r\nExplanation: The 4 subarrays are bolded and underlined below:\r\n[1,0,1,0,1]\r\n[1,0,1,0,1]\r\n[1,0,1,0,1]\r\n[1,0,1,0,1]", + "Example 2:\nInput: nums = [0,0,0,0,0], goal = 0\r\nOutput: 15" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 3 * 10^4\nnums[i] is either 0 or 1.\n0 <= goal <= nums.length", + "tags": [ + "Array", + "Hash Table", + "Sliding Window", + "Prefix Sum" + ], + "title-slug": "binary-subarrays-with-sum" + }, + { + "leetcode-id": 931, + "title": "Minimum Falling Path Sum", + "difficulty": 2, + "description": "Given an n x n array of integers matrix, return the minimum sum of any falling path through matrix.\nA falling path starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position (row, col) will be (row + 1, col - 1), (row + 1, col), or (row + 1, col + 1).", + "examples": [ + "Example 1:\nInput: matrix = [[2,1,3],[6,5,4],[7,8,9]]\nOutput: 13\nExplanation: There are two falling paths with a minimum sum as shown.", + "Example 2:\nInput: matrix = [[-19,57],[-40,-5]]\nOutput: -59\nExplanation: The falling path with a minimum sum is shown." + ], + "constraints": "Constraints:\n\nn == matrix.length == matrix[i].length\n1 <= n <= 100\n-100 <= matrix[i][j] <= 100", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "minimum-falling-path-sum" + }, + { + "leetcode-id": 932, + "title": "Beautiful Array", + "difficulty": 2, + "description": "An array nums of length n is beautiful if:\n\nnums is a permutation of the integers in the range [1, n].\nFor every 0 <= i < j < n, there is no index k with i < k < j where 2 * nums[k] == nums[i] + nums[j].\n\nGiven the integer n, return any beautiful array nums of length n. There will be at least one valid answer for the given n.", + "examples": [ + "Example 1:\nInput: n = 4\nOutput: [2,1,4,3]", + "Example 2:\nInput: n = 5\nOutput: [3,1,2,5,4]" + ], + "constraints": "Constraints:\n\n1 <= n <= 1000", + "tags": [ + "Array", + "Math", + "Divide and Conquer" + ], + "title-slug": "beautiful-array" + }, + { + "leetcode-id": 933, + "title": "Number of Recent Calls", + "difficulty": 1, + "description": "You have a RecentCounter class which counts the number of recent requests within a certain time frame.\nImplement the RecentCounter class:\n\nRecentCounter() Initializes the counter with zero recent requests.\nint ping(int t) Adds a new request at time t, where t represents some time in milliseconds, and returns the number of requests that has happened in the past 3000 milliseconds (including the new request). Specifically, return the number of requests that have happened in the inclusive range [t - 3000, t].\n\nIt is guaranteed that every call to ping uses a strictly larger value of t than the previous call.", + "examples": [ + "Example 1:\nInput\n[\"RecentCounter\", \"ping\", \"ping\", \"ping\", \"ping\"]\n[[], [1], [100], [3001], [3002]]\nOutput\n[null, 1, 2, 3, 3]\n\nExplanation\nRecentCounter recentCounter = new RecentCounter();\nrecentCounter.ping(1); // requests = [1], range is [-2999,1], return 1\nrecentCounter.ping(100); // requests = [1, 100], range is [-2900,100], return 2\nrecentCounter.ping(3001); // requests = [1, 100, 3001], range is [1,3001], return 3\nrecentCounter.ping(3002); // requests = [1, 100, 3001, 3002], range is [2,3002], return 3" + ], + "constraints": "Constraints:\n\n1 <= t <= 10^9\nEach test case will call ping with strictly increasing values of t.\nAt most 10^4 calls will be made to ping.", + "tags": [ + "Design", + "Queue", + "Data Stream" + ], + "title-slug": "number-of-recent-calls" + }, + { + "leetcode-id": 934, + "title": "Shortest Bridge", + "difficulty": 2, + "description": "You are given an n x n binary matrix grid where 1 represents land and 0 represents water.\nAn island is a 4-directionally connected group of 1's not connected to any other 1's. There are exactly two islands in grid.\nYou may change 0's to 1's to connect the two islands to form one island.\nReturn the smallest number of 0's you must flip to connect the two islands.", + "examples": [ + "Example 1:\nInput: grid = [[0,1],[1,0]]\nOutput: 1", + "Example 2:\nInput: grid = [[0,1,0],[0,0,0],[0,0,1]]\nOutput: 2", + "Example 3:\nInput: grid = [[1,1,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,1],[1,1,1,1,1]]\nOutput: 1" + ], + "constraints": "Constraints:\n\nn == grid.length == grid[i].length\n2 <= n <= 100\ngrid[i][j] is either 0 or 1.\nThere are exactly two islands in grid.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "shortest-bridge" + }, + { + "leetcode-id": 935, + "title": "Knight Dialer", + "difficulty": 2, + "description": "The chess knight has a unique movement,\u00a0it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L). The possible movements of chess knight are shown in this diagaram:\nA chess knight can move as indicated in the chess diagram below:\n\nWe have a chess knight and a phone pad as shown below, the knight can only stand on a numeric cell\u00a0(i.e. blue cell).\n\nGiven an integer n, return how many distinct phone numbers of length n we can dial.\nYou are allowed to place the knight on any numeric cell initially and then you should perform n - 1 jumps to dial a number of length n. All jumps should be valid knight jumps.\nAs the answer may be very large, return the answer modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: 10\nExplanation: We need to dial a number of length 1, so placing the knight over any numeric cell of the 10 cells is sufficient.", + "Example 2:\nInput: n = 2\nOutput: 20\nExplanation: All the valid number we can dial are [04, 06, 16, 18, 27, 29, 34, 38, 40, 43, 49, 60, 61, 67, 72, 76, 81, 83, 92, 94]", + "Example 3:\nInput: n = 3131\nOutput: 136006598\nExplanation: Please take care of the mod." + ], + "constraints": "Constraints:\n\n1 <= n <= 5000", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "knight-dialer" + }, + { + "leetcode-id": 936, + "title": "Stamping The Sequence", + "difficulty": 3, + "description": "You are given two strings stamp and target. Initially, there is a string s of length target.length with all s[i] == '?'.\nIn one turn, you can place stamp over s and replace every letter in the s with the corresponding letter from stamp.\n\nFor example, if stamp = \"abc\" and target = \"abcba\", then s is \"?????\" initially. In one turn you can:\n\n\t\nplace stamp at index 0 of s to obtain \"abc??\",\nplace stamp at index 1 of s to obtain \"?abc?\", or\nplace stamp at index 2 of s to obtain \"??abc\".\n\n\tNote that stamp must be fully contained in the boundaries of s in order to stamp (i.e., you cannot place stamp at index 3 of s).\n\nWe want to convert s to target using at most 10 * target.length turns.\nReturn an array of the index of the left-most letter being stamped at each turn. If we cannot obtain target from s within 10 * target.length turns, return an empty array.", + "examples": [ + "Example 1:\nInput: stamp = \"abc\", target = \"ababc\"\nOutput: [0,2]\nExplanation: Initially s = \"?????\".\n- Place stamp at index 0 to get \"abc??\".\n- Place stamp at index 2 to get \"ababc\".\n[1,0,2] would also be accepted as an answer, as well as some other answers.", + "Example 2:\nInput: stamp = \"abca\", target = \"aabcaca\"\nOutput: [3,0,1]\nExplanation: Initially s = \"???????\".\n- Place stamp at index 3 to get \"???abca\".\n- Place stamp at index 0 to get \"abcabca\".\n- Place stamp at index 1 to get \"aabcaca\"." + ], + "constraints": "Constraints:\n\n1 <= stamp.length <= target.length <= 1000\nstamp and target consist of lowercase English letters.", + "tags": [ + "String", + "Stack", + "Greedy", + "Queue" + ], + "title-slug": "stamping-the-sequence" + }, + { + "leetcode-id": 937, + "title": "Reorder Data in Log Files", + "difficulty": 2, + "description": "You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier.\nThere are two types of logs:\n\nLetter-logs: All words (except the identifier) consist of lowercase English letters.\nDigit-logs: All words (except the identifier) consist of digits.\n\nReorder these logs so that:\n\nThe letter-logs come before all digit-logs.\nThe letter-logs are sorted lexicographically by their contents. If their contents are the same, then sort them lexicographically by their identifiers.\nThe digit-logs maintain their relative ordering.\n\nReturn the final order of the logs.", + "examples": [ + "Example 1:\nInput: logs = [\"dig1 8 1 5 1\",\"let1 art can\",\"dig2 3 6\",\"let2 own kit dig\",\"let3 art zero\"]\nOutput: [\"let1 art can\",\"let3 art zero\",\"let2 own kit dig\",\"dig1 8 1 5 1\",\"dig2 3 6\"]\nExplanation:\nThe letter-log contents are all different, so their ordering is \"art can\", \"art zero\", \"own kit dig\".\nThe digit-logs have a relative order of \"dig1 8 1 5 1\", \"dig2 3 6\".", + "Example 2:\nInput: logs = [\"a1 9 2 3 1\",\"g1 act car\",\"zo4 4 7\",\"ab1 off key dog\",\"a8 act zoo\"]\nOutput: [\"g1 act car\",\"a8 act zoo\",\"ab1 off key dog\",\"a1 9 2 3 1\",\"zo4 4 7\"]" + ], + "constraints": "Constraints:\n\n1 <= logs.length <= 100\n3 <= logs[i].length <= 100\nAll the tokens of logs[i] are separated by a single space.\nlogs[i] is guaranteed to have an identifier and at least one word after the identifier.", + "tags": [ + "Array", + "String", + "Sorting" + ], + "title-slug": "reorder-data-in-log-files" + }, + { + "leetcode-id": 938, + "title": "Range Sum of BST", + "difficulty": 1, + "description": "Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].", + "examples": [ + "Example 1:\nInput: root = [10,5,15,3,7,null,18], low = 7, high = 15\nOutput: 32\nExplanation: Nodes 7, 10, and 15 are in the range [7, 15]. 7 + 10 + 15 = 32.", + "Example 2:\nInput: root = [10,5,15,3,7,13,18,1,null,6], low = 6, high = 10\nOutput: 23\nExplanation: Nodes 6, 7, and 10 are in the range [6, 10]. 6 + 7 + 10 = 23." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 2 * 10^4].\n1 <= Node.val <= 10^5\n1 <= low <= high <= 10^5\nAll Node.val are unique.", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "range-sum-of-bst" + }, + { + "leetcode-id": 939, + "title": "Minimum Area Rectangle", + "difficulty": 2, + "description": "You are given an array of points in the X-Y plane points where points[i] = [xi, yi].\nReturn the minimum area of a rectangle formed from these points, with sides parallel to the X and Y axes. If there is not any such rectangle, return 0.", + "examples": [ + "Example 1:\nInput: points = [[1,1],[1,3],[3,1],[3,3],[2,2]]\nOutput: 4", + "Example 2:\nInput: points = [[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]\nOutput: 2" + ], + "constraints": "Constraints:\n\n1 <= points.length <= 500\npoints[i].length == 2\n0 <= xi, yi <= 4 * 10^4\nAll the given points are unique.", + "tags": [ + "Array", + "Hash Table", + "Math", + "Geometry", + "Sorting" + ], + "title-slug": "minimum-area-rectangle" + }, + { + "leetcode-id": 940, + "title": "Distinct Subsequences II", + "difficulty": 3, + "description": "Given a string s, return the number of distinct non-empty subsequences of s. Since the answer may be very large, return it modulo 10^9 + 7.\nA subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., \"ace\" is a subsequence of \"abcde\" while \"aec\" is not.", + "examples": [ + "Example 1:\nInput: s = \"abc\"\nOutput: 7\nExplanation: The 7 distinct subsequences are \"a\", \"b\", \"c\", \"ab\", \"ac\", \"bc\", and \"abc\".", + "Example 2:\nInput: s = \"aba\"\nOutput: 6\nExplanation: The 6 distinct subsequences are \"a\", \"b\", \"ab\", \"aa\", \"ba\", and \"aba\".", + "Example 3:\nInput: s = \"aaa\"\nOutput: 3\nExplanation: The 3 distinct subsequences are \"a\", \"aa\" and \"aaa\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 2000\ns consists of lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "distinct-subsequences-ii" + }, + { + "leetcode-id": 941, + "title": "Valid Mountain Array", + "difficulty": 1, + "description": "Given an array of integers arr, return true if and only if it is a valid mountain array.\nRecall that arr is a mountain array if and only if:\n\narr.length >= 3\nThere exists some i with 0 < i < arr.length - 1 such that:\n\t\narr[0] < arr[1] < ... < arr[i - 1] < arr[i] \narr[i] > arr[i + 1] > ... > arr[arr.length - 1]", + "examples": [ + "Example 1:\nInput: arr = [2,1]\nOutput: false", + "Example 2:\nInput: arr = [3,5,5]\nOutput: false", + "Example 3:\nInput: arr = [0,3,2,1]\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^4\n0 <= arr[i] <= 10^4", + "tags": [ + "Array" + ], + "title-slug": "valid-mountain-array" + }, + { + "leetcode-id": 942, + "title": "DI String Match", + "difficulty": 1, + "description": "A permutation perm of n + 1 integers of all the integers in the range [0, n] can be represented as a string s of length n where:\n\ns[i] == 'I' if perm[i] < perm[i + 1], and\ns[i] == 'D' if perm[i] > perm[i + 1].\n\nGiven a string s, reconstruct the permutation perm and return it. If there are multiple valid permutations perm, return any of them.", + "examples": [ + "Example 1:\nInput: s = \"IDID\"\nOutput: [0,4,1,3,2]", + "Example 2:\nInput: s = \"III\"\nOutput: [0,1,2,3]", + "Example 3:\nInput: s = \"DDI\"\nOutput: [3,2,0,1]" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns[i] is either 'I' or 'D'.", + "tags": [ + "Array", + "Two Pointers", + "String", + "Greedy" + ], + "title-slug": "di-string-match" + }, + { + "leetcode-id": 943, + "title": "Find the Shortest Superstring", + "difficulty": 3, + "description": "Given an array of strings words, return the smallest string that contains each string in words as a substring. If there are multiple valid strings of the smallest length, return any of them.\nYou may assume that no string in words is a substring of another string in words.", + "examples": [ + "Example 1:\nInput: words = [\"alex\",\"loves\",\"leetcode\"]\nOutput: \"alexlovesleetcode\"\nExplanation: All permutations of \"alex\",\"loves\",\"leetcode\" would also be accepted.", + "Example 2:\nInput: words = [\"catg\",\"ctaagt\",\"gcta\",\"ttca\",\"atgcatc\"]\nOutput: \"gctaagttcatgcatc\"" + ], + "constraints": "Constraints:\n\n1 <= words.length <= 12\n1 <= words[i].length <= 20\nwords[i] consists of lowercase English letters.\nAll the strings of words are unique.", + "tags": [ + "Array", + "String", + "Dynamic Programming", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "find-the-shortest-superstring" + }, + { + "leetcode-id": 944, + "title": "Delete Columns to Make Sorted", + "difficulty": 1, + "description": "You are given an array of n strings strs, all of the same length.\nThe strings can be arranged such that there is one on each line, making a grid.\n\nFor example, strs = [\"abc\", \"bce\", \"cae\"] can be arranged as follows:\n\n\nabc\nbce\ncae\n\nYou want to delete the columns that are not sorted lexicographically. In the above example (0-indexed), columns 0 ('a', 'b', 'c') and 2 ('c', 'e', 'e') are sorted, while column 1 ('b', 'c', 'a') is not, so you would delete column 1.\nReturn the number of columns that you will delete.", + "examples": [ + "Example 1:\nInput: strs = [\"cba\",\"daf\",\"ghi\"]\nOutput: 1\nExplanation: The grid looks as follows:\n cba\n daf\n ghi\nColumns 0 and 2 are sorted, but column 1 is not, so you only need to delete 1 column.", + "Example 2:\nInput: strs = [\"a\",\"b\"]\nOutput: 0\nExplanation: The grid looks as follows:\n a\n b\nColumn 0 is the only column and is sorted, so you will not delete any columns.", + "Example 3:\nInput: strs = [\"zyx\",\"wvu\",\"tsr\"]\nOutput: 3\nExplanation: The grid looks as follows:\n zyx\n wvu\n tsr\nAll 3 columns are not sorted, so you will delete all 3." + ], + "constraints": "Constraints:\n\nn == strs.length\n1 <= n <= 100\n1 <= strs[i].length <= 1000\nstrs[i] consists of lowercase English letters.", + "tags": [ + "Array", + "String" + ], + "title-slug": "delete-columns-to-make-sorted" + }, + { + "leetcode-id": 945, + "title": "Minimum Increment to Make Array Unique", + "difficulty": 2, + "description": "You are given an integer array nums. In one move, you can pick an index i where 0 <= i < nums.length and increment nums[i] by 1.\nReturn the minimum number of moves to make every value in nums unique.\nThe test cases are generated so that the answer fits in a 32-bit integer.", + "examples": [ + "Example 1:\nInput: nums = [1,2,2]\nOutput: 1\nExplanation: After 1 move, the array could be [1, 2, 3].", + "Example 2:\nInput: nums = [3,2,1,2,1,7]\nOutput: 6\nExplanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].\nIt can be shown with 5 or less moves that it is impossible for the array to have all unique values." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Greedy", + "Sorting", + "Counting" + ], + "title-slug": "minimum-increment-to-make-array-unique" + }, + { + "leetcode-id": 946, + "title": "Validate Stack Sequences", + "difficulty": 2, + "description": "Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push and pop operations on an initially empty stack, or false otherwise.", + "examples": [ + "Example 1:\nInput: pushed = [1,2,3,4,5], popped = [4,5,3,2,1]\nOutput: true\nExplanation: We might do the following sequence:\npush(1), push(2), push(3), push(4),\npop() -> 4,\npush(5),\npop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1", + "Example 2:\nInput: pushed = [1,2,3,4,5], popped = [4,3,5,1,2]\nOutput: false\nExplanation: 1 cannot be popped before 2." + ], + "constraints": "Constraints:\n\n1 <= pushed.length <= 1000\n0 <= pushed[i] <= 1000\nAll the elements of pushed are unique.\npopped.length == pushed.length\npopped is a permutation of pushed.", + "tags": [ + "Array", + "Stack", + "Simulation" + ], + "title-slug": "validate-stack-sequences" + }, + { + "leetcode-id": 947, + "title": "Most Stones Removed with Same Row or Column", + "difficulty": 2, + "description": "On a 2D plane, we place n stones at some integer coordinate points. Each coordinate point may have at most one stone.\nA stone can be removed if it shares either the same row or the same column as another stone that has not been removed.\nGiven an array stones of length n where stones[i] = [xi, yi] represents the location of the i^th stone, return the largest possible number of stones that can be removed.", + "examples": [ + "Example 1:\nInput: stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]\nOutput: 5\nExplanation: One way to remove 5 stones is as follows:\n1. Remove stone [2,2] because it shares the same row as [2,1].\n2. Remove stone [2,1] because it shares the same column as [0,1].\n3. Remove stone [1,2] because it shares the same row as [1,0].\n4. Remove stone [1,0] because it shares the same column as [0,0].\n5. Remove stone [0,1] because it shares the same row as [0,0].\nStone [0,0] cannot be removed since it does not share a row/column with another stone still on the plane.", + "Example 2:\nInput: stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]\nOutput: 3\nExplanation: One way to make 3 moves is as follows:\n1. Remove stone [2,2] because it shares the same row as [2,0].\n2. Remove stone [2,0] because it shares the same column as [0,0].\n3. Remove stone [0,2] because it shares the same row as [0,0].\nStones [0,0] and [1,1] cannot be removed since they do not share a row/column with another stone still on the plane.", + "Example 3:\nInput: stones = [[0,0]]\nOutput: 0\nExplanation: [0,0] is the only stone on the plane, so you cannot remove it." + ], + "constraints": "Constraints:\n\n1 <= stones.length <= 1000\n0 <= xi, yi <= 10^4\nNo two stones are at the same coordinate point.", + "tags": [ + "Hash Table", + "Depth-First Search", + "Union Find", + "Graph" + ], + "title-slug": "most-stones-removed-with-same-row-or-column" + }, + { + "leetcode-id": 948, + "title": "Bag of Tokens", + "difficulty": 2, + "description": "You have an initial power of power, an initial score of 0, and a bag of tokens where tokens[i] is the value of the i^th token (0-indexed).\nYour goal is to maximize your total score by potentially playing each token in one of two ways:\n\nIf your current power is at least tokens[i], you may play the i^th token face up, losing tokens[i] power and gaining 1 score.\nIf your current score is at least 1, you may play the i^th token face down, gaining tokens[i] power and losing 1 score.\n\nEach token may be played at most once and in any order. You do not have to play all the tokens.\nReturn the largest possible score you can achieve after playing any number of tokens.", + "examples": [ + "Example 1:\nInput: tokens = [100], power = 50\nOutput: 0\nExplanation: Playing the only token in the bag is impossible because you either have too little power or too little score.", + "Example 2:\nInput: tokens = [100,200], power = 150\nOutput: 1\nExplanation: Play the 0^th token (100) face up, your power becomes 50 and score becomes 1.\nThere is no need to play the 1^st token since you cannot play it face up to add to your score.", + "Example 3:\nInput: tokens = [100,200,300,400], power = 200\nOutput: 2\nExplanation: Play the tokens in this order to get a score of 2:\n1. Play the 0^th token (100) face up, your power becomes 100 and score becomes 1.\n2. Play the 3^rd token (400) face down, your power becomes 500 and score becomes 0.\n3. Play the 1^st token (200) face up, your power becomes 300 and score becomes 1.\n4. Play the 2^nd token (300) face up, your power becomes 0 and score becomes 2." + ], + "constraints": "Constraints:\n\n0 <= tokens.length <= 1000\n0 <= tokens[i],\u00a0power < 10^4", + "tags": [ + "Array", + "Two Pointers", + "Greedy", + "Sorting" + ], + "title-slug": "bag-of-tokens" + }, + { + "leetcode-id": 949, + "title": "Largest Time for Given Digits", + "difficulty": 2, + "description": "Given an array arr of 4 digits, find the latest 24-hour time that can be made using each digit exactly once.\n24-hour times are formatted as \"HH:MM\", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59.\nReturn the latest 24-hour time in \"HH:MM\" format. If no valid time can be made, return an empty string.", + "examples": [ + "Example 1:\nInput: arr = [1,2,3,4]\nOutput: \"23:41\"\nExplanation: The valid 24-hour times are \"12:34\", \"12:43\", \"13:24\", \"13:42\", \"14:23\", \"14:32\", \"21:34\", \"21:43\", \"23:14\", and \"23:41\". Of these times, \"23:41\" is the latest.", + "Example 2:\nInput: arr = [5,5,5,5]\nOutput: \"\"\nExplanation: There are no valid 24-hour times as \"55:55\" is not valid." + ], + "constraints": "Constraints:\n\narr.length == 4\n0 <= arr[i] <= 9", + "tags": [ + "String", + "Enumeration" + ], + "title-slug": "largest-time-for-given-digits" + }, + { + "leetcode-id": 950, + "title": "Reveal Cards In Increasing Order", + "difficulty": 2, + "description": "You are given an integer array deck. There is a deck of cards where every card has a unique integer. The integer on the i^th card is deck[i].\nYou can order the deck in any order you want. Initially, all the cards start face down (unrevealed) in one deck.\nYou will do the following steps repeatedly until all cards are revealed:\n\nTake the top card of the deck, reveal it, and take it out of the deck.\nIf there are still cards in the deck then put the next top card of the deck at the bottom of the deck.\nIf there are still unrevealed cards, go back to step 1. Otherwise, stop.\n\nReturn an ordering of the deck that would reveal the cards in increasing order.\nNote that the first entry in the answer is considered to be the top of the deck.", + "examples": [ + "Example 1:\nInput: deck = [17,13,11,2,3,5,7]\nOutput: [2,13,3,11,5,17,7]\nExplanation: \nWe get the deck in the order [17,13,11,2,3,5,7] (this order does not matter), and reorder it.\nAfter reordering, the deck starts as [2,13,3,11,5,17,7], where 2 is the top of the deck.\nWe reveal 2, and move 13 to the bottom. The deck is now [3,11,5,17,7,13].\nWe reveal 3, and move 11 to the bottom. The deck is now [5,17,7,13,11].\nWe reveal 5, and move 17 to the bottom. The deck is now [7,13,11,17].\nWe reveal 7, and move 13 to the bottom. The deck is now [11,17,13].\nWe reveal 11, and move 17 to the bottom. The deck is now [13,17].\nWe reveal 13, and move 17 to the bottom. The deck is now [17].\nWe reveal 17.\nSince all the cards revealed are in increasing order, the answer is correct.", + "Example 2:\nInput: deck = [1,1000]\nOutput: [1,1000]" + ], + "constraints": "Constraints:\n\n1 <= deck.length <= 1000\n1 <= deck[i] <= 10^6\nAll the values of deck are unique.", + "tags": [ + "Array", + "Queue", + "Sorting", + "Simulation" + ], + "title-slug": "reveal-cards-in-increasing-order" + }, + { + "leetcode-id": 951, + "title": "Flip Equivalent Binary Trees", + "difficulty": 2, + "description": "For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees.\nA binary tree X\u00a0is flip equivalent to a binary tree Y if and only if we can make X equal to Y after some number of flip operations.\nGiven the roots of two binary trees root1 and root2, return true if the two trees are flip equivalent or false otherwise.", + "examples": [ + "Example 1:\nInput: root1 = [1,2,3,4,5,6,null,null,null,7,8], root2 = [1,3,2,null,6,4,5,null,null,null,null,8,7]\nOutput: true\nExplanation: We flipped at nodes with values 1, 3, and 5.", + "Example 2:\nInput: root1 = [], root2 = []\nOutput: true", + "Example 3:\nInput: root1 = [], root2 = [1]\nOutput: false" + ], + "constraints": "Constraints:\n\nThe number of nodes in each tree is in the range [0, 100].\nEach tree will have unique node values in the range [0, 99].", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "flip-equivalent-binary-trees" + }, + { + "leetcode-id": 952, + "title": "Largest Component Size by Common Factor", + "difficulty": 3, + "description": "You are given an integer array of unique positive integers nums. Consider the following graph:\n\nThere are nums.length nodes, labeled nums[0] to nums[nums.length - 1],\nThere is an undirected edge between nums[i] and nums[j] if nums[i] and nums[j] share a common factor greater than 1.\n\nReturn the size of the largest connected component in the graph.", + "examples": [ + "Example 1:\nInput: nums = [4,6,15,35]\nOutput: 4", + "Example 2:\nInput: nums = [20,50,9,63]\nOutput: 2", + "Example 3:\nInput: nums = [2,3,6,7,4,12,21,39]\nOutput: 8" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 2 * 10^4\n1 <= nums[i] <= 10^5\nAll the values of nums are unique.", + "tags": [ + "Array", + "Hash Table", + "Math", + "Union Find", + "Number Theory" + ], + "title-slug": "largest-component-size-by-common-factor" + }, + { + "leetcode-id": 953, + "title": "Verifying an Alien Dictionary", + "difficulty": 1, + "description": "In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.\nGiven a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographically in this alien language.", + "examples": [ + "Example 1:\nInput: words = [\"hello\",\"leetcode\"], order = \"hlabcdefgijkmnopqrstuvwxyz\"\nOutput: true\nExplanation: As 'h' comes before 'l' in this language, then the sequence is sorted.", + "Example 2:\nInput: words = [\"word\",\"world\",\"row\"], order = \"worldabcefghijkmnpqstuvxyz\"\nOutput: false\nExplanation: As 'd' comes after 'l' in this language, then words[0] > words[1], hence the sequence is unsorted.", + "Example 3:\nInput: words = [\"apple\",\"app\"], order = \"abcdefghijklmnopqrstuvwxyz\"\nOutput: false\nExplanation: The first three characters \"app\" match, and the second string is shorter (in size.) According to lexicographical rules \"apple\" > \"app\", because 'l' > '\u2205', where '\u2205' is defined as the blank character which is less than any other character (More info)." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 100\n1 <= words[i].length <= 20\norder.length == 26\nAll characters in words[i] and order are English lowercase letters.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "verifying-an-alien-dictionary" + }, + { + "leetcode-id": 954, + "title": "Array of Doubled Pairs", + "difficulty": 2, + "description": "Given an integer array of even length arr, return true if it is possible to reorder arr such that arr[2 * i + 1] = 2 * arr[2 * i] for every 0 <= i < len(arr) / 2, or false otherwise.", + "examples": [ + "Example 1:\nInput: arr = [3,1,3,6]\nOutput: false", + "Example 2:\nInput: arr = [2,1,2,6]\nOutput: false", + "Example 3:\nInput: arr = [4,-2,2,-4]\nOutput: true\nExplanation: We can take two groups, [-2,-4] and [2,4] to form [-2,-4,2,4] or [2,4,-2,-4]." + ], + "constraints": "Constraints:\n\n2 <= arr.length <= 3 * 10^4\narr.length is even.\n-10^5 <= arr[i] <= 10^5", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Sorting" + ], + "title-slug": "array-of-doubled-pairs" + }, + { + "leetcode-id": 955, + "title": "Delete Columns to Make Sorted II", + "difficulty": 2, + "description": "You are given an array of n strings strs, all of the same length.\nWe may choose any deletion indices, and we delete all the characters in those indices for each string.\nFor example, if we have strs = [\"abcdef\",\"uvwxyz\"] and deletion indices {0, 2, 3}, then the final array after deletions is [\"bef\", \"vyz\"].\nSuppose we chose a set of deletion indices answer such that after deletions, the final array has its elements in lexicographic order (i.e., strs[0] <= strs[1] <= strs[2] <= ... <= strs[n - 1]). Return the minimum possible value of answer.length.", + "examples": [ + "Example 1:\nInput: strs = [\"ca\",\"bb\",\"ac\"]\nOutput: 1\nExplanation: \nAfter deleting the first column, strs = [\"a\", \"b\", \"c\"].\nNow strs is in lexicographic order (ie. strs[0] <= strs[1] <= strs[2]).\nWe require at least 1 deletion since initially strs was not in lexicographic order, so the answer is 1.", + "Example 2:\nInput: strs = [\"xc\",\"yb\",\"za\"]\nOutput: 0\nExplanation: \nstrs is already in lexicographic order, so we do not need to delete anything.\nNote that the rows of strs are not necessarily in lexicographic order:\ni.e., it is NOT necessarily true that (strs[0][0] <= strs[0][1] <= ...)", + "Example 3:\nInput: strs = [\"zyx\",\"wvu\",\"tsr\"]\nOutput: 3\nExplanation: We have to delete every column." + ], + "constraints": "Constraints:\n\nn == strs.length\n1 <= n <= 100\n1 <= strs[i].length <= 100\nstrs[i] consists of lowercase English letters.", + "tags": [ + "Array", + "String", + "Greedy" + ], + "title-slug": "delete-columns-to-make-sorted-ii" + }, + { + "leetcode-id": 956, + "title": "Tallest Billboard", + "difficulty": 3, + "description": "You are installing a billboard and want it to have the largest height. The billboard will have two steel supports, one on each side. Each steel support must be an equal height.\nYou are given a collection of rods that can be welded together. For example, if you have rods of lengths 1, 2, and 3, you can weld them together to make a support of length 6.\nReturn the largest possible height of your billboard installation. If you cannot support the billboard, return 0.", + "examples": [ + "Example 1:\nInput: rods = [1,2,3,6]\nOutput: 6\nExplanation: We have two disjoint subsets {1,2,3} and {6}, which have the same sum = 6.", + "Example 2:\nInput: rods = [1,2,3,4,5,6]\nOutput: 10\nExplanation: We have two disjoint subsets {2,3,5} and {4,6}, which have the same sum = 10.", + "Example 3:\nInput: rods = [1,2]\nOutput: 0\nExplanation: The billboard cannot be supported, so we return 0." + ], + "constraints": "Constraints:\n\n1 <= rods.length <= 20\n1 <= rods[i] <= 1000\nsum(rods[i]) <= 5000", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "tallest-billboard" + }, + { + "leetcode-id": 957, + "title": "Prison Cells After N Days", + "difficulty": 2, + "description": "There are 8 prison cells in a row and each cell is either occupied or vacant.\nEach day, whether the cell is occupied or vacant changes according to the following rules:\n\nIf a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.\nOtherwise, it becomes vacant.\n\nNote that because the prison is a row, the first and the last cells in the row can't have two adjacent neighbors.\nYou are given an integer array cells where cells[i] == 1 if the i^th cell is occupied and cells[i] == 0 if the i^th cell is vacant, and you are given an integer n.\nReturn the state of the prison after n days (i.e., n such changes described above).", + "examples": [ + "Example 1:\nInput: cells = [0,1,0,1,1,0,0,1], n = 7\nOutput: [0,0,1,1,0,0,0,0]\nExplanation: The following table summarizes the state of the prison on each day:\nDay 0: [0, 1, 0, 1, 1, 0, 0, 1]\nDay 1: [0, 1, 1, 0, 0, 0, 0, 0]\nDay 2: [0, 0, 0, 0, 1, 1, 1, 0]\nDay 3: [0, 1, 1, 0, 0, 1, 0, 0]\nDay 4: [0, 0, 0, 0, 0, 1, 0, 0]\nDay 5: [0, 1, 1, 1, 0, 1, 0, 0]\nDay 6: [0, 0, 1, 0, 1, 1, 0, 0]\nDay 7: [0, 0, 1, 1, 0, 0, 0, 0]", + "Example 2:\nInput: cells = [1,0,0,1,0,0,1,0], n = 1000000000\nOutput: [0,0,1,1,1,1,1,0]" + ], + "constraints": "Constraints:\n\ncells.length == 8\ncells[i]\u00a0is either 0 or 1.\n1 <= n <= 10^9", + "tags": [ + "Array", + "Hash Table", + "Math", + "Bit Manipulation" + ], + "title-slug": "prison-cells-after-n-days" + }, + { + "leetcode-id": 958, + "title": "Check Completeness of a Binary Tree", + "difficulty": 2, + "description": "Given the root of a binary tree, determine if it is a complete binary tree.\nIn a complete binary tree, every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2^h nodes inclusive at the last level h.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,4,5,6]\nOutput: true\nExplanation: Every level before the last is full (ie. levels with node-values {1} and {2, 3}), and all nodes in the last level ({4, 5, 6}) are as far left as possible.", + "Example 2:\nInput: root = [1,2,3,4,5,null,7]\nOutput: false\nExplanation: The node with value 7 isn't as far left as possible." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 100].\n1 <= Node.val <= 1000", + "tags": [ + "Tree", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "check-completeness-of-a-binary-tree" + }, + { + "leetcode-id": 959, + "title": "Regions Cut By Slashes", + "difficulty": 2, + "description": "An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\\', or blank space ' '. These characters divide the square into contiguous regions.\nGiven the grid grid represented as a string array, return the number of regions.\nNote that backslash characters are escaped, so a '\\' is represented as '\\\\'.", + "examples": [ + "Example 1:\nInput: grid = [\" /\",\"/ \"]\nOutput: 2", + "Example 2:\nInput: grid = [\" /\",\" \"]\nOutput: 1", + "Example 3:\nInput: grid = [\"/\\\\\",\"\\\\/\"]\nOutput: 5\nExplanation: Recall that because \\ characters are escaped, \"\\\\/\" refers to \\/, and \"/\\\\\" refers to /\\." + ], + "constraints": "Constraints:\n\nn == grid.length == grid[i].length\n1 <= n <= 30\ngrid[i][j] is either '/', '\\', or ' '.", + "tags": [ + "Array", + "Hash Table", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Matrix" + ], + "title-slug": "regions-cut-by-slashes" + }, + { + "leetcode-id": 960, + "title": "Delete Columns to Make Sorted III", + "difficulty": 3, + "description": "You are given an array of n strings strs, all of the same length.\nWe may choose any deletion indices, and we delete all the characters in those indices for each string.\nFor example, if we have strs = [\"abcdef\",\"uvwxyz\"] and deletion indices {0, 2, 3}, then the final array after deletions is [\"bef\", \"vyz\"].\nSuppose we chose a set of deletion indices answer such that after deletions, the final array has every string (row) in lexicographic order. (i.e., (strs[0][0] <= strs[0][1] <= ... <= strs[0][strs[0].length - 1]), and (strs[1][0] <= strs[1][1] <= ... <= strs[1][strs[1].length - 1]), and so on). Return the minimum possible value of answer.length.", + "examples": [ + "Example 1:\nInput: strs = [\"babca\",\"bbazb\"]\nOutput: 3\nExplanation: After deleting columns 0, 1, and 4, the final array is strs = [\"bc\", \"az\"].\nBoth these rows are individually in lexicographic order (ie. strs[0][0] <= strs[0][1] and strs[1][0] <= strs[1][1]).\nNote that strs[0] > strs[1] - the array strs is not necessarily in lexicographic order.", + "Example 2:\nInput: strs = [\"edcba\"]\nOutput: 4\nExplanation: If we delete less than 4 columns, the only row will not be lexicographically sorted.", + "Example 3:\nInput: strs = [\"ghi\",\"def\",\"abc\"]\nOutput: 0\nExplanation: All rows are already lexicographically sorted." + ], + "constraints": "Constraints:\n\nn == strs.length\n1 <= n <= 100\n1 <= strs[i].length <= 100\nstrs[i] consists of lowercase English letters.", + "tags": [ + "Array", + "String", + "Dynamic Programming" + ], + "title-slug": "delete-columns-to-make-sorted-iii" + }, + { + "leetcode-id": 961, + "title": "N-Repeated Element in Size 2N Array", + "difficulty": 1, + "description": "You are given an integer array nums with the following properties:\n\nnums.length == 2 * n.\nnums contains n + 1 unique elements.\nExactly one element of nums is repeated n times.\n\nReturn the element that is repeated n times.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,3]\nOutput: 3", + "Example 2:\nInput: nums = [2,1,2,5,3,2]\nOutput: 2", + "Example 3:\nInput: nums = [5,1,5,2,5,3,5,4]\nOutput: 5" + ], + "constraints": "Constraints:\n\n2 <= n <= 5000\nnums.length == 2 * n\n0 <= nums[i] <= 10^4\nnums contains n + 1 unique elements and one of them is repeated exactly n times.", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "n-repeated-element-in-size-2n-array" + }, + { + "leetcode-id": 962, + "title": "Maximum Width Ramp", + "difficulty": 2, + "description": "A ramp in an integer array nums is a pair (i, j) for which i < j and nums[i] <= nums[j]. The width of such a ramp is j - i.\nGiven an integer array nums, return the maximum width of a ramp in nums. If there is no ramp in nums, return 0.", + "examples": [ + "Example 1:\nInput: nums = [6,0,8,2,1,5]\nOutput: 4\nExplanation: The maximum width ramp is achieved at (i, j) = (1, 5): nums[1] = 0 and nums[5] = 5.", + "Example 2:\nInput: nums = [9,8,1,0,1,9,4,0,4,1]\nOutput: 7\nExplanation: The maximum width ramp is achieved at (i, j) = (2, 9): nums[2] = 1 and nums[9] = 1." + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 5 * 10^4\n0 <= nums[i] <= 5 * 10^4", + "tags": [ + "Array", + "Stack", + "Monotonic Stack" + ], + "title-slug": "maximum-width-ramp" + }, + { + "leetcode-id": 963, + "title": "Minimum Area Rectangle II", + "difficulty": 2, + "description": "You are given an array of points in the X-Y plane points where points[i] = [xi, yi].\nReturn the minimum area of any rectangle formed from these points, with sides not necessarily parallel to the X and Y axes. If there is not any such rectangle, return 0.\nAnswers within 10^-5 of the actual answer will be accepted.", + "examples": [ + "Example 1:\nInput: points = [[1,2],[2,1],[1,0],[0,1]]\nOutput: 2.00000\nExplanation: The minimum area rectangle occurs at [1,2],[2,1],[1,0],[0,1], with an area of 2.", + "Example 2:\nInput: points = [[0,1],[2,1],[1,1],[1,0],[2,0]]\nOutput: 1.00000\nExplanation: The minimum area rectangle occurs at [1,0],[1,1],[2,1],[2,0], with an area of 1.", + "Example 3:\nInput: points = [[0,3],[1,2],[3,1],[1,3],[2,1]]\nOutput: 0\nExplanation: There is no possible rectangle to form from these points." + ], + "constraints": "Constraints:\n\n1 <= points.length <= 50\npoints[i].length == 2\n0 <= xi, yi <= 4 * 10^4\nAll the given points are unique.", + "tags": [ + "Array", + "Math", + "Geometry" + ], + "title-slug": "minimum-area-rectangle-ii" + }, + { + "leetcode-id": 964, + "title": "Least Operators to Express Number", + "difficulty": 3, + "description": "Given a single positive integer x, we will write an expression of the form x (op1) x (op2) x (op3) x ... where each operator op1, op2, etc. is either addition, subtraction, multiplication, or division (+, -, *, or /). For example, with x = 3, we might write 3 * 3 / 3 + 3 - 3 which is a value of 3.\nWhen writing such an expression, we adhere to the following conventions:\n\nThe division operator (/) returns rational numbers.\nThere are no parentheses placed anywhere.\nWe use the usual order of operations: multiplication and division happen before addition and subtraction.\nIt is not allowed to use the unary negation operator (-). For example, \"x - x\" is a valid expression as it only uses subtraction, but \"-x + x\" is not because it uses negation.\n\nWe would like to write an expression with the least number of operators such that the expression equals the given target. Return the least number of operators used.", + "examples": [ + "Example 1:\nInput: x = 3, target = 19\nOutput: 5\nExplanation: 3 * 3 + 3 * 3 + 3 / 3.\nThe expression contains 5 operations.", + "Example 2:\nInput: x = 5, target = 501\nOutput: 8\nExplanation: 5 * 5 * 5 * 5 - 5 * 5 * 5 + 5 / 5.\nThe expression contains 8 operations.", + "Example 3:\nInput: x = 100, target = 100000000\nOutput: 3\nExplanation: 100 * 100 * 100 * 100.\nThe expression contains 3 operations." + ], + "constraints": "Constraints:\n\n2 <= x <= 100\n1 <= target <= 2 * 10^8", + "tags": [ + "Math", + "Dynamic Programming", + "Memoization" + ], + "title-slug": "least-operators-to-express-number" + }, + { + "leetcode-id": 965, + "title": "Univalued Binary Tree", + "difficulty": 1, + "description": "A binary tree is uni-valued if every node in the tree has the same value.\nGiven the root of a binary tree, return true if the given tree is uni-valued, or false otherwise.", + "examples": [ + "Example 1:\nInput: root = [1,1,1,1,1,null,1]\nOutput: true", + "Example 2:\nInput: root = [2,2,2,5,2]\nOutput: false" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 100].\n0 <= Node.val < 100", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "univalued-binary-tree" + }, + { + "leetcode-id": 966, + "title": "Vowel Spellchecker", + "difficulty": 2, + "description": "Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word.\nFor a given query word, the spell checker handles two categories of spelling mistakes:\n\nCapitalization: If the query matches a word in the wordlist (case-insensitive), then the query word is returned with the same case as the case in the wordlist.\n\n\t\nExample: wordlist = [\"yellow\"], query = \"YellOw\": correct = \"yellow\"\nExample: wordlist = [\"Yellow\"], query = \"yellow\": correct = \"Yellow\"\nExample: wordlist = [\"yellow\"], query = \"yellow\": correct = \"yellow\"\n\n\nVowel Errors: If after replacing the vowels ('a', 'e', 'i', 'o', 'u') of the query word with any vowel individually, it matches a word in the wordlist (case-insensitive), then the query word is returned with the same case as the match in the wordlist.\n\t\nExample: wordlist = [\"YellOw\"], query = \"yollow\": correct = \"YellOw\"\nExample: wordlist = [\"YellOw\"], query = \"yeellow\": correct = \"\" (no match)\nExample: wordlist = [\"YellOw\"], query = \"yllw\": correct = \"\" (no match)\n\n\n\nIn addition, the spell checker operates under the following precedence rules:\n\nWhen the query exactly matches a word in the wordlist (case-sensitive), you should return the same word back.\nWhen the query matches a word up to capitlization, you should return the first such match in the wordlist.\nWhen the query matches a word up to vowel errors, you should return the first such match in the wordlist.\nIf the query has no matches in the wordlist, you should return the empty string.\n\nGiven some queries, return a list of words answer, where answer[i] is the correct word for query = queries[i].", + "examples": [ + "Example 1:\nInput: wordlist = [\"KiTe\",\"kite\",\"hare\",\"Hare\"], queries = [\"kite\",\"Kite\",\"KiTe\",\"Hare\",\"HARE\",\"Hear\",\"hear\",\"keti\",\"keet\",\"keto\"]\nOutput: [\"kite\",\"KiTe\",\"KiTe\",\"Hare\",\"hare\",\"\",\"\",\"KiTe\",\"\",\"KiTe\"]", + "Example 2:\nInput: wordlist = [\"yellow\"], queries = [\"YellOw\"]\nOutput: [\"yellow\"]" + ], + "constraints": "Constraints:\n\n1 <= wordlist.length, queries.length <= 5000\n1 <= wordlist[i].length, queries[i].length <= 7\nwordlist[i] and queries[i] consist only of only English letters.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "vowel-spellchecker" + }, + { + "leetcode-id": 967, + "title": "Numbers With Same Consecutive Differences", + "difficulty": 2, + "description": "Given two integers n and k, return an array of all the integers of length n where the difference between every two consecutive digits is k. You may return the answer in any order.\nNote that the integers should not have leading zeros. Integers as 02 and 043 are not allowed.", + "examples": [ + "Example 1:\nInput: n = 3, k = 7\nOutput: [181,292,707,818,929]\nExplanation: Note that 070 is not a valid number, because it has leading zeroes.", + "Example 2:\nInput: n = 2, k = 1\nOutput: [10,12,21,23,32,34,43,45,54,56,65,67,76,78,87,89,98]" + ], + "constraints": "Constraints:\n\n2 <= n <= 9\n0 <= k <= 9", + "tags": [ + "Backtracking", + "Breadth-First Search" + ], + "title-slug": "numbers-with-same-consecutive-differences" + }, + { + "leetcode-id": 968, + "title": "Binary Tree Cameras", + "difficulty": 3, + "description": "You are given the root of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.\nReturn the minimum number of cameras needed to monitor all nodes of the tree.", + "examples": [ + "Example 1:\nInput: root = [0,0,null,0,0]\nOutput: 1\nExplanation: One camera is enough to monitor all nodes if placed as shown.", + "Example 2:\nInput: root = [0,0,null,0,null,0,null,null,0]\nOutput: 2\nExplanation: At least two cameras are needed to monitor all nodes of the tree. The above image shows one of the valid configurations of camera placement." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 1000].\nNode.val == 0", + "tags": [ + "Dynamic Programming", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "binary-tree-cameras" + }, + { + "leetcode-id": 969, + "title": "Pancake Sorting", + "difficulty": 2, + "description": "Given an array of integers arr, sort the array by performing a series of pancake flips.\nIn one pancake flip we do the following steps:\n\nChoose an integer k where 1 <= k <= arr.length.\nReverse the sub-array arr[0...k-1] (0-indexed).\n\nFor example, if arr = [3,2,1,4] and we performed a pancake flip choosing k = 3, we reverse the sub-array [3,2,1], so arr = [1,2,3,4] after the pancake flip at k = 3.\nReturn an array of the k-values corresponding to a sequence of pancake flips that sort arr. Any valid answer that sorts the array within 10 * arr.length flips will be judged as correct.", + "examples": [ + "Example 1:\nInput: arr = [3,2,4,1]\nOutput: [4,2,4,3]\nExplanation: \nWe perform 4 pancake flips, with k values 4, 2, 4, and 3.\nStarting state: arr = [3, 2, 4, 1]\nAfter 1st flip (k = 4): arr = [1, 4, 2, 3]\nAfter 2nd flip (k = 2): arr = [4, 1, 2, 3]\nAfter 3rd flip (k = 4): arr = [3, 2, 1, 4]\nAfter 4th flip (k = 3): arr = [1, 2, 3, 4], which is sorted.", + "Example 2:\nInput: arr = [1,2,3]\nOutput: []\nExplanation: The input is already sorted, so there is no need to flip anything.\nNote that other answers, such as [3, 3], would also be accepted." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 100\n1 <= arr[i] <= arr.length\nAll integers in arr are unique (i.e. arr is a permutation of the integers from 1 to arr.length).", + "tags": [ + "Array", + "Two Pointers", + "Greedy", + "Sorting" + ], + "title-slug": "pancake-sorting" + }, + { + "leetcode-id": 970, + "title": "Powerful Integers", + "difficulty": 2, + "description": "Given three integers x, y, and bound, return a list of all the powerful integers that have a value less than or equal to bound.\nAn integer is powerful if it can be represented as x^i + y^j for some integers i >= 0 and j >= 0.\nYou may return the answer in any order. In your answer, each value should occur at most once.", + "examples": [ + "Example 1:\nInput: x = 2, y = 3, bound = 10\nOutput: [2,3,4,5,7,9,10]\nExplanation:\n2 = 2^0 + 3^0\n3 = 2^1 + 3^0\n4 = 2^0 + 3^1\n5 = 2^1 + 3^1\n7 = 2^2 + 3^1\n9 = 2^3 + 3^0\n10 = 2^0 + 3^2", + "Example 2:\nInput: x = 3, y = 5, bound = 15\nOutput: [2,4,6,8,10,14]" + ], + "constraints": "Constraints:\n\n1 <= x, y <= 100\n0 <= bound <= 10^6", + "tags": [ + "Hash Table", + "Math" + ], + "title-slug": "powerful-integers" + }, + { + "leetcode-id": 971, + "title": "Flip Binary Tree To Match Preorder Traversal", + "difficulty": 2, + "description": "You are given the root of a binary tree with n nodes, where each node is uniquely assigned a value from 1 to n. You are also given a sequence of n values voyage, which is the desired pre-order traversal of the binary tree.\nAny node in the binary tree can be flipped by swapping its left and right subtrees. For example, flipping node 1 will have the following effect:\n\nFlip the smallest number of nodes so that the pre-order traversal of the tree matches voyage.\nReturn a list of the values of all flipped nodes. You may return the answer in any order. If it is impossible to flip the nodes in the tree to make the pre-order traversal match voyage, return the list [-1].", + "examples": [ + "Example 1:\nInput: root = [1,2], voyage = [2,1]\nOutput: [-1]\nExplanation: It is impossible to flip the nodes such that the pre-order traversal matches voyage.", + "Example 2:\nInput: root = [1,2,3], voyage = [1,3,2]\nOutput: [1]\nExplanation: Flipping node 1 swaps nodes 2 and 3, so the pre-order traversal matches voyage.", + "Example 3:\nInput: root = [1,2,3], voyage = [1,2,3]\nOutput: []\nExplanation: The tree's pre-order traversal already matches voyage, so no nodes need to be flipped." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is n.\nn == voyage.length\n1 <= n <= 100\n1 <= Node.val, voyage[i] <= n\nAll the values in the tree are unique.\nAll the values in voyage are unique.", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "flip-binary-tree-to-match-preorder-traversal" + }, + { + "leetcode-id": 972, + "title": "Equal Rational Numbers", + "difficulty": 3, + "description": "Given two strings s and t, each of which represents a non-negative rational number, return true if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number.\nA rational number can be represented using up to three parts: , , and a . The number will be represented in one of the following three ways:\n\n\n\nFor example, 12, 0, and 123.\n\n\n<.>\n\nFor example, 0.5, 1., 2.12, and 123.0001.\n\n\n<.><(><)>\n\nFor example, 0.1(6), 1.(9), 123.00(1212).\n\n\n\nThe repeating portion of a decimal expansion is conventionally denoted within a pair of round brackets. For example:\n\n1/6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66).", + "examples": [ + "Example 1:\nInput: s = \"0.(52)\", t = \"0.5(25)\"\nOutput: true\nExplanation: Because \"0.(52)\" represents 0.52525252..., and \"0.5(25)\" represents 0.52525252525..... , the strings represent the same number.", + "Example 2:\nInput: s = \"0.1666(6)\", t = \"0.166(66)\"\nOutput: true", + "Example 3:\nInput: s = \"0.9(9)\", t = \"1.\"\nOutput: true\nExplanation: \"0.9(9)\" represents 0.999999999... repeated forever, which equals 1. [See this link for an explanation.]\n\"1.\" represents the number 1, which is formed correctly: (IntegerPart) = \"1\" and (NonRepeatingPart) = \"\"." + ], + "constraints": "Constraints:\n\nEach part consists only of digits.\nThe does not have leading zeros (except for the zero itself).\n1 <= .length <= 4\n0 <= .length <= 4\n1 <= .length <= 4", + "tags": [ + "Math", + "String" + ], + "title-slug": "equal-rational-numbers" + }, + { + "leetcode-id": 973, + "title": "K Closest Points to Origin", + "difficulty": 2, + "description": "Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).\nThe distance between two points on the X-Y plane is the Euclidean distance (i.e., \u221a(x1 - x2)^2 + (y1 - y2)^2).\nYou may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in).", + "examples": [ + "Example 1:\nInput: points = [[1,3],[-2,2]], k = 1\nOutput: [[-2,2]]\nExplanation:\nThe distance between (1, 3) and the origin is sqrt(10).\nThe distance between (-2, 2) and the origin is sqrt(8).\nSince sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.\nWe only want the closest k = 1 points from the origin, so the answer is just [[-2,2]].", + "Example 2:\nInput: points = [[3,3],[5,-1],[-2,4]], k = 2\nOutput: [[3,3],[-2,4]]\nExplanation: The answer [[-2,4],[3,3]] would also be accepted." + ], + "constraints": "Constraints:\n\n1 <= k <= points.length <= 10^4\n-10^4 <= xi, yi <= 10^4", + "tags": [ + "Array", + "Math", + "Divide and Conquer", + "Geometry", + "Sorting", + "Heap (Priority Queue)", + "Quickselect" + ], + "title-slug": "k-closest-points-to-origin" + }, + { + "leetcode-id": 974, + "title": "Subarray Sums Divisible by K", + "difficulty": 2, + "description": "Given an integer array nums and an integer k, return the number of non-empty subarrays that have a sum divisible by k.\nA subarray is a contiguous part of an array.", + "examples": [ + "Example 1:\nInput: nums = [4,5,0,-2,-3,1], k = 5\nOutput: 7\nExplanation: There are 7 subarrays with a sum divisible by k = 5:\n[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]", + "Example 2:\nInput: nums = [5], k = 9\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 3 * 10^4\n-10^4 <= nums[i] <= 10^4\n2 <= k <= 10^4", + "tags": [ + "Array", + "Hash Table", + "Prefix Sum" + ], + "title-slug": "subarray-sums-divisible-by-k" + }, + { + "leetcode-id": 975, + "title": "Odd Even Jump", + "difficulty": 3, + "description": "You are given an integer array arr. From some starting index, you can make a series of jumps. The (1^st, 3^rd, 5^th, ...) jumps in the series are called odd-numbered jumps, and the (2^nd, 4^th, 6^th, ...) jumps in the series are called even-numbered jumps. Note that the jumps are numbered, not the indices.\nYou may jump forward from index i to index j (with i < j) in the following way:\n\nDuring odd-numbered jumps (i.e., jumps 1, 3, 5, ...), you jump to the index j such that arr[i] <= arr[j] and arr[j] is the smallest possible value. If there are multiple such indices j, you can only jump to the smallest such index j.\nDuring even-numbered jumps (i.e., jumps 2, 4, 6, ...), you jump to the index j such that arr[i] >= arr[j] and arr[j] is the largest possible value. If there are multiple such indices j, you can only jump to the smallest such index j.\nIt may be the case that for some index i, there are no legal jumps.\n\nA starting index is good if, starting from that index, you can reach the end of the array (index arr.length - 1) by jumping some number of times (possibly 0 or more than once).\nReturn the number of good starting indices.", + "examples": [ + "Example 1:\nInput: arr = [10,13,12,14,15]\nOutput: 2\nExplanation: \nFrom starting index i = 0, we can make our 1st jump to i = 2 (since arr[2] is the smallest among arr[1], arr[2], arr[3], arr[4] that is greater or equal to arr[0]), then we cannot jump any more.\nFrom starting index i = 1 and i = 2, we can make our 1st jump to i = 3, then we cannot jump any more.\nFrom starting index i = 3, we can make our 1st jump to i = 4, so we have reached the end.\nFrom starting index i = 4, we have reached the end already.\nIn total, there are 2 different starting indices i = 3 and i = 4, where we can reach the end with some number of\njumps.", + "Example 2:\nInput: arr = [2,3,1,1,4]\nOutput: 3\nExplanation: \nFrom starting index i = 0, we make jumps to i = 1, i = 2, i = 3:\nDuring our 1st jump (odd-numbered), we first jump to i = 1 because arr[1] is the smallest value in [arr[1], arr[2], arr[3], arr[4]] that is greater than or equal to arr[0].\nDuring our 2nd jump (even-numbered), we jump from i = 1 to i = 2 because arr[2] is the largest value in [arr[2], arr[3], arr[4]] that is less than or equal to arr[1]. arr[3] is also the largest value, but 2 is a smaller index, so we can only jump to i = 2 and not i = 3\nDuring our 3rd jump (odd-numbered), we jump from i = 2 to i = 3 because arr[3] is the smallest value in [arr[3], arr[4]] that is greater than or equal to arr[2].\nWe can't jump from i = 3 to i = 4, so the starting index i = 0 is not good.\nIn a similar manner, we can deduce that:\nFrom starting index i = 1, we jump to i = 4, so we reach the end.\nFrom starting index i = 2, we jump to i = 3, and then we can't jump anymore.\nFrom starting index i = 3, we jump to i = 4, so we reach the end.\nFrom starting index i = 4, we are already at the end.\nIn total, there are 3 different starting indices i = 1, i = 3, and i = 4, where we can reach the end with some\nnumber of jumps.", + "Example 3:\nInput: arr = [5,1,3,4,2]\nOutput: 3\nExplanation: We can reach the end from starting indices 1, 2, and 4." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 2 * 10^4\n0 <= arr[i] < 10^5", + "tags": [ + "Array", + "Dynamic Programming", + "Stack", + "Monotonic Stack", + "Ordered Set" + ], + "title-slug": "odd-even-jump" + }, + { + "leetcode-id": 976, + "title": "Largest Perimeter Triangle", + "difficulty": 1, + "description": "Given an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible to form any triangle of a non-zero area, return 0.", + "examples": [ + "Example 1:\nInput: nums = [2,1,2]\nOutput: 5\nExplanation: You can form a triangle with three side lengths: 1, 2, and 2.", + "Example 2:\nInput: nums = [1,2,1,10]\nOutput: 0\nExplanation: \nYou cannot use the side lengths 1, 1, and 2 to form a triangle.\nYou cannot use the side lengths 1, 1, and 10 to form a triangle.\nYou cannot use the side lengths 1, 2, and 10 to form a triangle.\nAs we cannot use any three side lengths to form a triangle of non-zero area, we return 0." + ], + "constraints": "Constraints:\n\n3 <= nums.length <= 10^4\n1 <= nums[i] <= 10^6", + "tags": [ + "Array", + "Math", + "Greedy", + "Sorting" + ], + "title-slug": "largest-perimeter-triangle" + }, + { + "leetcode-id": 977, + "title": "Squares of a Sorted Array", + "difficulty": 1, + "description": "Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.", + "examples": [ + "Example 1:\nInput: nums = [-4,-1,0,3,10]\nOutput: [0,1,9,16,100]\nExplanation: After squaring, the array becomes [16,1,0,9,100].\nAfter sorting, it becomes [0,1,9,16,100].", + "Example 2:\nInput: nums = [-7,-3,2,3,11]\nOutput: [4,9,9,49,121]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-10^4 <= nums[i] <= 10^4\nnums is sorted in non-decreasing order.\n\n\u00a0\nFollow up: Squaring each element and sorting the new array is very trivial, could you find an O(n) solution using a different approach?", + "tags": [ + "Array", + "Two Pointers", + "Sorting" + ], + "title-slug": "squares-of-a-sorted-array" + }, + { + "leetcode-id": 978, + "title": "Longest Turbulent Subarray", + "difficulty": 2, + "description": "Given an integer array arr, return the length of a maximum size turbulent subarray of arr.\nA subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray.\nMore formally, a subarray [arr[i], arr[i + 1], ..., arr[j]] of arr is said to be turbulent if and only if:\n\nFor i <= k < j:\n\n\t\narr[k] > arr[k + 1] when k is odd, and\narr[k] < arr[k + 1] when k is even.\n\n\nOr, for i <= k < j:\n\t\narr[k] > arr[k + 1] when k is even, and\narr[k] < arr[k + 1] when k is odd.", + "examples": [ + "Example 1:\nInput: arr = [9,4,2,10,7,8,8,1,9]\nOutput: 5\nExplanation: arr[1] > arr[2] < arr[3] > arr[4] < arr[5]", + "Example 2:\nInput: arr = [4,8,12,16]\nOutput: 2", + "Example 3:\nInput: arr = [100]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 4 * 10^4\n0 <= arr[i] <= 10^9", + "tags": [ + "Array", + "Dynamic Programming", + "Sliding Window" + ], + "title-slug": "longest-turbulent-subarray" + }, + { + "leetcode-id": 979, + "title": "Distribute Coins in Binary Tree", + "difficulty": 2, + "description": "You are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole tree.\nIn one move, we may choose two adjacent nodes and move one coin from one node to another. A move may be from parent to child, or from child to parent.\nReturn the minimum number of moves required to make every node have exactly one coin.", + "examples": [ + "Example 1:\nInput: root = [3,0,0]\nOutput: 2\nExplanation: From the root of the tree, we move one coin to its left child, and one coin to its right child.", + "Example 2:\nInput: root = [0,3,0]\nOutput: 3\nExplanation: From the left child of the root, we move two coins to the root [taking two moves]. Then, we move one coin from the root of the tree to the right child." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is n.\n1 <= n <= 100\n0 <= Node.val <= n\nThe sum of all Node.val is n.", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "distribute-coins-in-binary-tree" + }, + { + "leetcode-id": 980, + "title": "Unique Paths III", + "difficulty": 3, + "description": "You are given an m x n integer array grid where grid[i][j] could be:\n\n1 representing the starting square. There is exactly one starting square.\n2 representing the ending square. There is exactly one ending square.\n0 representing empty squares we can walk over.\n-1 representing obstacles that we cannot walk over.\n\nReturn the number of 4-directional walks from the starting square to the ending square, that walk over every non-obstacle square exactly once.", + "examples": [ + "Example 1:\nInput: grid = [[1,0,0,0],[0,0,0,0],[0,0,2,-1]]\nOutput: 2\nExplanation: We have the following two paths: \n1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2)\n2. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2)", + "Example 2:\nInput: grid = [[1,0,0,0],[0,0,0,0],[0,0,0,2]]\nOutput: 4\nExplanation: We have the following four paths: \n1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2),(2,3)\n2. (0,0),(0,1),(1,1),(1,0),(2,0),(2,1),(2,2),(1,2),(0,2),(0,3),(1,3),(2,3)\n3. (0,0),(1,0),(2,0),(2,1),(2,2),(1,2),(1,1),(0,1),(0,2),(0,3),(1,3),(2,3)\n4. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2),(2,3)", + "Example 3:\nInput: grid = [[0,1],[2,0]]\nOutput: 0\nExplanation: There is no path that walks over every empty square exactly once.\nNote that the starting and ending square can be anywhere in the grid." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 20\n1 <= m * n <= 20\n-1 <= grid[i][j] <= 2\nThere is exactly one starting cell and one ending cell.", + "tags": [ + "Array", + "Backtracking", + "Bit Manipulation", + "Matrix" + ], + "title-slug": "unique-paths-iii" + }, + { + "leetcode-id": 981, + "title": "Time Based Key-Value Store", + "difficulty": 2, + "description": "Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key's value at a certain timestamp.\nImplement the TimeMap class:\n\nTimeMap() Initializes the object of the data structure.\nvoid set(String key, String value, int timestamp) Stores the key key with the value value at the given time timestamp.\nString get(String key, int timestamp) Returns a value such that set was called previously, with timestamp_prev <= timestamp. If there are multiple such values, it returns the value associated with the largest timestamp_prev. If there are no values, it returns \"\".", + "examples": [ + "Example 1:\nInput\n[\"TimeMap\", \"set\", \"get\", \"get\", \"set\", \"get\", \"get\"]\n[[], [\"foo\", \"bar\", 1], [\"foo\", 1], [\"foo\", 3], [\"foo\", \"bar2\", 4], [\"foo\", 4], [\"foo\", 5]]\nOutput\n[null, null, \"bar\", \"bar\", null, \"bar2\", \"bar2\"]\n\nExplanation\nTimeMap timeMap = new TimeMap();\ntimeMap.set(\"foo\", \"bar\", 1); // store the key \"foo\" and value \"bar\" along with timestamp = 1.\ntimeMap.get(\"foo\", 1); // return \"bar\"\ntimeMap.get(\"foo\", 3); // return \"bar\", since there is no value corresponding to foo at timestamp 3 and timestamp 2, then the only value is at timestamp 1 is \"bar\".\ntimeMap.set(\"foo\", \"bar2\", 4); // store the key \"foo\" and value \"bar2\" along with timestamp = 4.\ntimeMap.get(\"foo\", 4); // return \"bar2\"\ntimeMap.get(\"foo\", 5); // return \"bar2\"" + ], + "constraints": "Constraints:\n\n1 <= key.length, value.length <= 100\nkey and value consist of lowercase English letters and digits.\n1 <= timestamp <= 10^7\nAll the timestamps timestamp of set are strictly increasing.\nAt most 2 * 10^5 calls will be made to set and get.", + "tags": [ + "Hash Table", + "String", + "Binary Search", + "Design" + ], + "title-slug": "time-based-key-value-store" + }, + { + "leetcode-id": 982, + "title": "Triples with Bitwise AND Equal To Zero", + "difficulty": 3, + "description": "Given an integer array nums, return the number of AND triples.\nAn AND triple is a triple of indices (i, j, k) such that:\n\n0 <= i < nums.length\n0 <= j < nums.length\n0 <= k < nums.length\nnums[i] & nums[j] & nums[k] == 0, where & represents the bitwise-AND operator.", + "examples": [ + "Example 1:\nInput: nums = [2,1,3]\nOutput: 12\nExplanation: We could choose the following i, j, k triples:\n(i=0, j=0, k=1) : 2 & 2 & 1\n(i=0, j=1, k=0) : 2 & 1 & 2\n(i=0, j=1, k=1) : 2 & 1 & 1\n(i=0, j=1, k=2) : 2 & 1 & 3\n(i=0, j=2, k=1) : 2 & 3 & 1\n(i=1, j=0, k=0) : 1 & 2 & 2\n(i=1, j=0, k=1) : 1 & 2 & 1\n(i=1, j=0, k=2) : 1 & 2 & 3\n(i=1, j=1, k=0) : 1 & 1 & 2\n(i=1, j=2, k=0) : 1 & 3 & 2\n(i=2, j=0, k=1) : 3 & 2 & 1\n(i=2, j=1, k=0) : 3 & 1 & 2", + "Example 2:\nInput: nums = [0,0,0]\nOutput: 27" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n0 <= nums[i] < 2^16", + "tags": [ + "Array", + "Hash Table", + "Bit Manipulation" + ], + "title-slug": "triples-with-bitwise-and-equal-to-zero" + }, + { + "leetcode-id": 983, + "title": "Minimum Cost For Tickets", + "difficulty": 2, + "description": "You have planned some train traveling one year in advance. The days of the year in which you will travel are given as an integer array days. Each day is an integer from 1 to 365.\nTrain tickets are sold in three different ways:\n\na 1-day pass is sold for costs[0] dollars,\na 7-day pass is sold for costs[1] dollars, and\na 30-day pass is sold for costs[2] dollars.\n\nThe passes allow that many days of consecutive travel.\n\nFor example, if we get a 7-day pass on day 2, then we can travel for 7 days: 2, 3, 4, 5, 6, 7, and 8.\n\nReturn the minimum number of dollars you need to travel every day in the given list of days.", + "examples": [ + "Example 1:\nInput: days = [1,4,6,7,8,20], costs = [2,7,15]\nOutput: 11\nExplanation: For example, here is one way to buy passes that lets you travel your travel plan:\nOn day 1, you bought a 1-day pass for costs[0] = $2, which covered day 1.\nOn day 3, you bought a 7-day pass for costs[1] = $7, which covered days 3, 4, ..., 9.\nOn day 20, you bought a 1-day pass for costs[0] = $2, which covered day 20.\nIn total, you spent $11 and covered all the days of your travel.", + "Example 2:\nInput: days = [1,2,3,4,5,6,7,8,9,10,30,31], costs = [2,7,15]\nOutput: 17\nExplanation: For example, here is one way to buy passes that lets you travel your travel plan:\nOn day 1, you bought a 30-day pass for costs[2] = $15 which covered days 1, 2, ..., 30.\nOn day 31, you bought a 1-day pass for costs[0] = $2 which covered day 31.\nIn total, you spent $17 and covered all the days of your travel." + ], + "constraints": "Constraints:\n\n1 <= days.length <= 365\n1 <= days[i] <= 365\ndays is in strictly increasing order.\ncosts.length == 3\n1 <= costs[i] <= 1000", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "minimum-cost-for-tickets" + }, + { + "leetcode-id": 984, + "title": "String Without AAA or BBB", + "difficulty": 2, + "description": "Given two integers a and b, return any string s such that:\n\ns has length a + b and contains exactly a 'a' letters, and exactly b 'b' letters,\nThe substring 'aaa' does not occur in s, and\nThe substring 'bbb' does not occur in s.", + "examples": [ + "Example 1:\nInput: a = 1, b = 2\nOutput: \"abb\"\nExplanation: \"abb\", \"bab\" and \"bba\" are all correct answers.", + "Example 2:\nInput: a = 4, b = 1\nOutput: \"aabaa\"" + ], + "constraints": "Constraints:\n\n0 <= a, b <= 100\nIt is guaranteed such an s exists for the given a and b.", + "tags": [ + "String", + "Greedy" + ], + "title-slug": "string-without-aaa-or-bbb" + }, + { + "leetcode-id": 985, + "title": "Sum of Even Numbers After Queries", + "difficulty": 2, + "description": "You are given an integer array nums and an array queries where queries[i] = [vali, indexi].\nFor each query i, first, apply nums[indexi] = nums[indexi] + vali, then print the sum of the even values of nums.\nReturn an integer array answer where answer[i] is the answer to the i^th query.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]]\nOutput: [8,6,2,4]\nExplanation: At the beginning, the array is [1,2,3,4].\nAfter adding 1 to nums[0], the array is [2,2,3,4], and the sum of even values is 2 + 2 + 4 = 8.\nAfter adding -3 to nums[1], the array is [2,-1,3,4], and the sum of even values is 2 + 4 = 6.\nAfter adding -4 to nums[0], the array is [-2,-1,3,4], and the sum of even values is -2 + 4 = 2.\nAfter adding 2 to nums[3], the array is [-2,-1,3,6], and the sum of even values is -2 + 6 = 4.", + "Example 2:\nInput: nums = [1], queries = [[4,0]]\nOutput: [0]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-10^4 <= nums[i] <= 10^4\n1 <= queries.length <= 10^4\n-10^4 <= vali <= 10^4\n0 <= indexi < nums.length", + "tags": [ + "Array", + "Simulation" + ], + "title-slug": "sum-of-even-numbers-after-queries" + }, + { + "leetcode-id": 986, + "title": "Interval List Intersections", + "difficulty": 2, + "description": "You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each list of intervals is pairwise disjoint and in sorted order.\nReturn the intersection of these two interval lists.\nA closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b.\nThe intersection of two closed intervals is a set of real numbers that are either empty or represented as a closed interval. For example, the intersection of [1, 3] and [2, 4] is [2, 3].", + "examples": [ + "Example 1:\nInput: firstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]]\nOutput: [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]", + "Example 2:\nInput: firstList = [[1,3],[5,9]], secondList = []\nOutput: []" + ], + "constraints": "Constraints:\n\n0 <= firstList.length, secondList.length <= 1000\nfirstList.length + secondList.length >= 1\n0 <= starti < endi <= 10^9\nendi < starti+1\n0 <= startj < endj <= 10^9 \nendj < startj+1", + "tags": [ + "Array", + "Two Pointers" + ], + "title-slug": "interval-list-intersections" + }, + { + "leetcode-id": 987, + "title": "Vertical Order Traversal of a Binary Tree", + "difficulty": 3, + "description": "Given the root of a binary tree, calculate the vertical order traversal of the binary tree.\nFor each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0).\nThe vertical order traversal of a binary tree is a list of top-to-bottom orderings for each column index starting from the leftmost column and ending on the rightmost column. There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values.\nReturn the vertical order traversal of the binary tree.", + "examples": [ + "Example 1:\nInput: root = [3,9,20,null,null,15,7]\nOutput: [[9],[3,15],[20],[7]]\nExplanation:\nColumn -1: Only node 9 is in this column.\nColumn 0: Nodes 3 and 15 are in this column in that order from top to bottom.\nColumn 1: Only node 20 is in this column.\nColumn 2: Only node 7 is in this column.", + "Example 2:\nInput: root = [1,2,3,4,5,6,7]\nOutput: [[4],[2],[1,5,6],[3],[7]]\nExplanation:\nColumn -2: Only node 4 is in this column.\nColumn -1: Only node 2 is in this column.\nColumn 0: Nodes 1, 5, and 6 are in this column.\n 1 is at the top, so it comes first.\n 5 and 6 are at the same position (2, 0), so we order them by their value, 5 before 6.\nColumn 1: Only node 3 is in this column.\nColumn 2: Only node 7 is in this column.", + "Example 3:\nInput: root = [1,2,3,4,6,5,7]\nOutput: [[4],[2],[1,5,6],[3],[7]]\nExplanation:\nThis case is the exact same as example 2, but with nodes 5 and 6 swapped.\nNote that the solution remains the same since 5 and 6 are in the same location and should be ordered by their values." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 1000].\n0 <= Node.val <= 1000", + "tags": [ + "Hash Table", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "vertical-order-traversal-of-a-binary-tree" + }, + { + "leetcode-id": 988, + "title": "Smallest String Starting From Leaf", + "difficulty": 2, + "description": "You are given the root of a binary tree where each node has a value in the range [0, 25] representing the letters 'a' to 'z'.\nReturn the lexicographically smallest string that starts at a leaf of this tree and ends at the root.\nAs a reminder, any shorter prefix of a string is lexicographically smaller.\n\nFor example, \"ab\" is lexicographically smaller than \"aba\".\n\nA leaf of a node is a node that has no children.", + "examples": [ + "Example 1:\nInput: root = [0,1,2,3,4,3,4]\nOutput: \"dba\"", + "Example 2:\nInput: root = [25,1,3,1,3,0,2]\nOutput: \"adz\"", + "Example 3:\nInput: root = [2,2,1,null,1,0,null,0]\nOutput: \"abc\"" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 8500].\n0 <= Node.val <= 25", + "tags": [ + "String", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "smallest-string-starting-from-leaf" + }, + { + "leetcode-id": 989, + "title": "Add to Array-Form of Integer", + "difficulty": 1, + "description": "The array-form of an integer num is an array representing its digits in left to right order.\n\nFor example, for num = 1321, the array form is [1,3,2,1].\n\nGiven num, the array-form of an integer, and an integer k, return the array-form of the integer num + k.", + "examples": [ + "Example 1:\nInput: num = [1,2,0,0], k = 34\nOutput: [1,2,3,4]\nExplanation: 1200 + 34 = 1234", + "Example 2:\nInput: num = [2,7,4], k = 181\nOutput: [4,5,5]\nExplanation: 274 + 181 = 455", + "Example 3:\nInput: num = [2,1,5], k = 806\nOutput: [1,0,2,1]\nExplanation: 215 + 806 = 1021" + ], + "constraints": "Constraints:\n\n1 <= num.length <= 10^4\n0 <= num[i] <= 9\nnum does not contain any leading zeros except for the zero itself.\n1 <= k <= 10^4", + "tags": [ + "Array", + "Math" + ], + "title-slug": "add-to-array-form-of-integer" + }, + { + "leetcode-id": 990, + "title": "Satisfiability of Equality Equations", + "difficulty": 2, + "description": "You are given an array of strings equations that represent relationships between variables where each string equations[i] is of length 4 and takes one of two different forms: \"xi==yi\" or \"xi!=yi\".Here, xi and yi are lowercase letters (not necessarily different) that represent one-letter variable names.\nReturn true if it is possible to assign integers to variable names so as to satisfy all the given equations, or false otherwise.", + "examples": [ + "Example 1:\nInput: equations = [\"a==b\",\"b!=a\"]\nOutput: false\nExplanation: If we assign say, a = 1 and b = 1, then the first equation is satisfied, but not the second.\nThere is no way to assign the variables to satisfy both equations.", + "Example 2:\nInput: equations = [\"b==a\",\"a==b\"]\nOutput: true\nExplanation: We could assign a = 1 and b = 1 to satisfy both equations." + ], + "constraints": "Constraints:\n\n1 <= equations.length <= 500\nequations[i].length == 4\nequations[i][0] is a lowercase letter.\nequations[i][1] is either '=' or '!'.\nequations[i][2] is '='.\nequations[i][3] is a lowercase letter.", + "tags": [ + "Array", + "String", + "Union Find", + "Graph" + ], + "title-slug": "satisfiability-of-equality-equations" + }, + { + "leetcode-id": 991, + "title": "Broken Calculator", + "difficulty": 2, + "description": "There is a broken calculator that has the integer startValue on its display initially. In one operation, you can:\n\nmultiply the number on display by 2, or\nsubtract 1 from the number on display.\n\nGiven two integers startValue and target, return the minimum number of operations needed to display target on the calculator.", + "examples": [ + "Example 1:\nInput: startValue = 2, target = 3\nOutput: 2\nExplanation: Use double operation and then decrement operation {2 -> 4 -> 3}.", + "Example 2:\nInput: startValue = 5, target = 8\nOutput: 2\nExplanation: Use decrement and then double {5 -> 4 -> 8}.", + "Example 3:\nInput: startValue = 3, target = 10\nOutput: 3\nExplanation: Use double, decrement and double {3 -> 6 -> 5 -> 10}." + ], + "constraints": "Constraints:\n\n1 <= startValue, target <= 10^9", + "tags": [ + "Math", + "Greedy" + ], + "title-slug": "broken-calculator" + }, + { + "leetcode-id": 992, + "title": "Subarrays with K Different Integers", + "difficulty": 3, + "description": "Given an integer array nums and an integer k, return the number of good subarrays of nums.\nA good array is an array where the number of different integers in that array is exactly k.\n\nFor example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.\n\nA subarray is a contiguous part of an array.", + "examples": [ + "Example 1:\nInput: nums = [1,2,1,2,3], k = 2\nOutput: 7\nExplanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2]", + "Example 2:\nInput: nums = [1,2,1,3,4], k = 3\nOutput: 3\nExplanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4]." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 2 * 10^4\n1 <= nums[i], k <= nums.length", + "tags": [ + "Array", + "Hash Table", + "Sliding Window", + "Counting" + ], + "title-slug": "subarrays-with-k-different-integers" + }, + { + "leetcode-id": 993, + "title": "Cousins in Binary Tree", + "difficulty": 1, + "description": "Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y, return true if the nodes corresponding to the values x and y in the tree are cousins, or false otherwise.\nTwo nodes of a binary tree are cousins if they have the same depth with different parents.\nNote that in a binary tree, the root node is at the depth 0, and children of each depth k node are at the depth k + 1.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,4], x = 4, y = 3\nOutput: false", + "Example 2:\nInput: root = [1,2,3,null,4,null,5], x = 5, y = 4\nOutput: true", + "Example 3:\nInput: root = [1,2,3,null,4], x = 2, y = 3\nOutput: false" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [2, 100].\n1 <= Node.val <= 100\nEach node has a unique value.\nx != y\nx and y are exist in the tree.", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "cousins-in-binary-tree" + }, + { + "leetcode-id": 994, + "title": "Rotting Oranges", + "difficulty": 2, + "description": "You are given an m x n grid where each cell can have one of three values:\n\n0 representing an empty cell,\n1 representing a fresh orange, or\n2 representing a rotten orange.\n\nEvery minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten.\nReturn the minimum number of minutes that must elapse until no cell has a fresh orange. If this is impossible, return -1.", + "examples": [ + "Example 1:\nInput: grid = [[2,1,1],[1,1,0],[0,1,1]]\nOutput: 4", + "Example 2:\nInput: grid = [[2,1,1],[0,1,1],[1,0,1]]\nOutput: -1\nExplanation: The orange in the bottom left corner (row 2, column 0) is never rotten, because rotting only happens 4-directionally.", + "Example 3:\nInput: grid = [[0,2]]\nOutput: 0\nExplanation: Since there are already no fresh oranges at minute 0, the answer is just 0." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 10\ngrid[i][j] is 0, 1, or 2.", + "tags": [ + "Array", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "rotting-oranges" + }, + { + "leetcode-id": 995, + "title": "Minimum Number of K Consecutive Bit Flips", + "difficulty": 3, + "description": "You are given a binary array nums and an integer k.\nA k-bit flip is choosing a subarray of length k from nums and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.\nReturn the minimum number of k-bit flips required so that there is no 0 in the array. If it is not possible, return -1.\nA subarray is a contiguous part of an array.", + "examples": [ + "Example 1:\nInput: nums = [0,1,0], k = 1\nOutput: 2\nExplanation: Flip nums[0], then flip nums[2].", + "Example 2:\nInput: nums = [1,1,0], k = 2\nOutput: -1\nExplanation: No matter how we flip subarrays of size 2, we cannot make the array become [1,1,1].", + "Example 3:\nInput: nums = [0,0,0,1,0,1,1,0], k = 3\nOutput: 3\nExplanation: \nFlip nums[0],nums[1],nums[2]: nums becomes [1,1,1,1,0,1,1,0]\nFlip nums[4],nums[5],nums[6]: nums becomes [1,1,1,1,1,0,0,0]\nFlip nums[5],nums[6],nums[7]: nums becomes [1,1,1,1,1,1,1,1]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= k <= nums.length", + "tags": [ + "Array", + "Bit Manipulation", + "Queue", + "Sliding Window", + "Prefix Sum" + ], + "title-slug": "minimum-number-of-k-consecutive-bit-flips" + }, + { + "leetcode-id": 996, + "title": "Number of Squareful Arrays", + "difficulty": 3, + "description": "An array is squareful if the sum of every pair of adjacent elements is a perfect square.\nGiven an integer array nums, return the number of permutations of nums that are squareful.\nTwo permutations perm1 and perm2 are different if there is some index i such that perm1[i] != perm2[i].", + "examples": [ + "Example 1:\nInput: nums = [1,17,8]\nOutput: 2\nExplanation: [1,8,17] and [17,8,1] are the valid permutations.", + "Example 2:\nInput: nums = [2,2,2]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 12\n0 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Backtracking", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "number-of-squareful-arrays" + }, + { + "leetcode-id": 997, + "title": "Find the Town Judge", + "difficulty": 1, + "description": "In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge.\nIf the town judge exists, then:\n\nThe town judge trusts nobody.\nEverybody (except for the town judge) trusts the town judge.\nThere is exactly one person that satisfies properties 1 and 2.\n\nYou are given an array trust where trust[i] = [ai, bi] representing that the person labeled ai trusts the person labeled bi. If a trust relationship does not exist in trust array, then such a trust relationship does not exist.\nReturn the label of the town judge if the town judge exists and can be identified, or return -1 otherwise.", + "examples": [ + "Example 1:\nInput: n = 2, trust = [[1,2]]\nOutput: 2", + "Example 2:\nInput: n = 3, trust = [[1,3],[2,3]]\nOutput: 3", + "Example 3:\nInput: n = 3, trust = [[1,3],[2,3],[3,1]]\nOutput: -1" + ], + "constraints": "Constraints:\n\n1 <= n <= 1000\n0 <= trust.length <= 10^4\ntrust[i].length == 2\nAll the pairs of trust are unique.\nai != bi\n1 <= ai, bi <= n", + "tags": [ + "Array", + "Hash Table", + "Graph" + ], + "title-slug": "find-the-town-judge" + }, + { + "leetcode-id": 998, + "title": "Maximum Binary Tree II", + "difficulty": 2, + "description": "A maximum tree is a tree where every node has a value greater than any other value in its subtree.\nYou are given the root of a maximum binary tree and an integer val.\nJust as in the previous problem, the given tree was constructed from a list a (root = Construct(a)) recursively with the following Construct(a) routine:\n\nIf a is empty, return null.\nOtherwise, let a[i] be the largest element of a. Create a root node with the value a[i].\nThe left child of root will be Construct([a[0], a[1], ..., a[i - 1]]).\nThe right child of root will be Construct([a[i + 1], a[i + 2], ..., a[a.length - 1]]).\nReturn root.\n\nNote that we were not given a directly, only a root node root = Construct(a).\nSuppose b is a copy of a with the value val appended to it. It is guaranteed that b has unique values.\nReturn Construct(b).", + "examples": [ + "Example 1:\nInput: root = [4,1,3,null,null,2], val = 5\nOutput: [5,4,null,1,3,null,null,2]\nExplanation: a = [1,4,2,3], b = [1,4,2,3,5]", + "Example 2:\nInput: root = [5,2,4,null,1], val = 3\nOutput: [5,2,4,null,1,null,3]\nExplanation: a = [2,1,5,4], b = [2,1,5,4,3]", + "Example 3:\nInput: root = [5,2,3,null,1], val = 4\nOutput: [5,2,4,null,1,3]\nExplanation: a = [2,1,5,3], b = [2,1,5,3,4]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 100].\n1 <= Node.val <= 100\nAll the values of the tree are unique.\n1 <= val <= 100", + "tags": [ + "Tree", + "Binary Tree" + ], + "title-slug": "maximum-binary-tree-ii" + }, + { + "leetcode-id": 999, + "title": "Available Captures for Rook", + "difficulty": 1, + "description": "On an 8 x 8 chessboard, there is exactly one white rook 'R' and some number of white bishops 'B', black pawns 'p', and empty squares '.'.\nWhen the rook moves, it chooses one of four cardinal directions (north, east, south, or west), then moves in that direction until it chooses to stop, reaches the edge of the board, captures a black pawn, or is blocked by a white bishop. A rook is considered attacking a pawn if the rook can capture the pawn on the rook's turn. The number of available captures for the white rook is the number of pawns that the rook is attacking.\nReturn the number of available captures for the white rook.", + "examples": [ + "Example 1:\nInput: board = [[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"R\",\".\",\".\",\".\",\"p\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"]]\nOutput: 3\nExplanation: In this example, the rook is attacking all the pawns.", + "Example 2:\nInput: board = [[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\"p\",\"p\",\"p\",\"p\",\"p\",\".\",\".\"],[\".\",\"p\",\"p\",\"B\",\"p\",\"p\",\".\",\".\"],[\".\",\"p\",\"B\",\"R\",\"B\",\"p\",\".\",\".\"],[\".\",\"p\",\"p\",\"B\",\"p\",\"p\",\".\",\".\"],[\".\",\"p\",\"p\",\"p\",\"p\",\"p\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"]]\nOutput: 0\nExplanation: The bishops are blocking the rook from attacking any of the pawns.", + "Example 3:\nInput: board = [[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\"p\",\"p\",\".\",\"R\",\".\",\"p\",\"B\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"B\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"p\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"]]\nOutput: 3\nExplanation: The rook is attacking the pawns at positions b5, d6, and f5." + ], + "constraints": "Constraints:\n\nboard.length == 8\nboard[i].length == 8\nboard[i][j] is either 'R', '.', 'B', or 'p'\nThere is exactly one cell with board[i][j] == 'R'", + "tags": [ + "Array", + "Matrix", + "Simulation" + ], + "title-slug": "available-captures-for-rook" + }, + { + "leetcode-id": 1000, + "title": "Minimum Cost to Merge Stones", + "difficulty": 3, + "description": "There are n piles of stones arranged in a row. The i^th pile has stones[i] stones.\nA move consists of merging exactly k consecutive piles into one pile, and the cost of this move is equal to the total number of stones in these k piles.\nReturn the minimum cost to merge all piles of stones into one pile. If it is impossible, return -1.", + "examples": [ + "Example 1:\nInput: stones = [3,2,4,1], k = 2\nOutput: 20\nExplanation: We start with [3, 2, 4, 1].\nWe merge [3, 2] for a cost of 5, and we are left with [5, 4, 1].\nWe merge [4, 1] for a cost of 5, and we are left with [5, 5].\nWe merge [5, 5] for a cost of 10, and we are left with [10].\nThe total cost was 20, and this is the minimum possible.", + "Example 2:\nInput: stones = [3,2,4,1], k = 3\nOutput: -1\nExplanation: After any merge operation, there are 2 piles left, and we can't merge anymore. So the task is impossible.", + "Example 3:\nInput: stones = [3,5,1,2,6], k = 3\nOutput: 25\nExplanation: We start with [3, 5, 1, 2, 6].\nWe merge [5, 1, 2] for a cost of 8, and we are left with [3, 8, 6].\nWe merge [3, 8, 6] for a cost of 17, and we are left with [17].\nThe total cost was 25, and this is the minimum possible." + ], + "constraints": "Constraints:\n\nn == stones.length\n1 <= n <= 30\n1 <= stones[i] <= 100\n2 <= k <= 30", + "tags": [ + "Array", + "Dynamic Programming", + "Prefix Sum" + ], + "title-slug": "minimum-cost-to-merge-stones" + }, + { + "leetcode-id": 1001, + "title": "Grid Illumination", + "difficulty": 3, + "description": "There is a 2D grid of size n x n where each cell of this grid has a lamp that is initially turned off.\nYou are given a 2D array of lamp positions lamps, where lamps[i] = [rowi, coli] indicates that the lamp at grid[rowi][coli] is turned on. Even if the same lamp is listed more than once, it is turned on.\nWhen a lamp is turned on, it illuminates its cell and all other cells in the same row, column, or diagonal.\nYou are also given another 2D array queries, where queries[j] = [rowj, colj]. For the j^th query, determine whether grid[rowj][colj] is illuminated or not. After answering the j^th query, turn off the lamp at grid[rowj][colj] and its 8 adjacent lamps if they exist. A lamp is adjacent if its cell shares either a side or corner with grid[rowj][colj].\nReturn an array of integers ans, where ans[j] should be 1 if the cell in the j^th query was illuminated, or 0 if the lamp was not.", + "examples": [ + "Example 1:\nInput: n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,0]]\nOutput: [1,0]\nExplanation: We have the initial grid with all lamps turned off. In the above picture we see the grid after turning on the lamp at grid[0][0] then turning on the lamp at grid[4][4].\nThe 0^th\u00a0query asks if the lamp at grid[1][1] is illuminated or not (the blue square). It is illuminated, so set ans[0] = 1. Then, we turn off all lamps in the red square.\n\nThe 1^st\u00a0query asks if the lamp at grid[1][0] is illuminated or not (the blue square). It is not illuminated, so set ans[1] = 0. Then, we turn off all lamps in the red rectangle.", + "Example 2:\nInput: n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,1]]\nOutput: [1,1]", + "Example 3:\nInput: n = 5, lamps = [[0,0],[0,4]], queries = [[0,4],[0,1],[1,4]]\nOutput: [1,1,0]" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^9\n0 <= lamps.length <= 20000\n0 <= queries.length <= 20000\nlamps[i].length == 2\n0 <= rowi, coli < n\nqueries[j].length == 2\n0 <= rowj, colj < n", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "grid-illumination" + }, + { + "leetcode-id": 1002, + "title": "Find Common Characters", + "difficulty": 1, + "description": "Given a string array words, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order.", + "examples": [ + "Example 1:\nInput: words = [\"bella\",\"label\",\"roller\"]\nOutput: [\"e\",\"l\",\"l\"]", + "Example 2:\nInput: words = [\"cool\",\"lock\",\"cook\"]\nOutput: [\"c\",\"o\"]" + ], + "constraints": "Constraints:\n\n1 <= words.length <= 100\n1 <= words[i].length <= 100\nwords[i] consists of lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "find-common-characters" + }, + { + "leetcode-id": 1003, + "title": "Check If Word Is Valid After Substitutions", + "difficulty": 2, + "description": "Given a string s, determine if it is valid.\nA string s is valid if, starting with an empty string t = \"\", you can transform t into s after performing the following operation any number of times:\n\nInsert string \"abc\" into any position in t. More formally, t becomes tleft + \"abc\" + tright, where t == tleft + tright. Note that tleft and tright may be empty.\n\nReturn true if s is a valid string, otherwise, return false.", + "examples": [ + "Example 1:\nInput: s = \"aabcbc\"\nOutput: true\nExplanation:\n\"\" -> \"abc\" -> \"aabcbc\"\nThus, \"aabcbc\" is valid.", + "Example 2:\nInput: s = \"abcabcababcc\"\nOutput: true\nExplanation:\n\"\" -> \"abc\" -> \"abcabc\" -> \"abcabcabc\" -> \"abcabcababcc\"\nThus, \"abcabcababcc\" is valid.", + "Example 3:\nInput: s = \"abccba\"\nOutput: false\nExplanation: It is impossible to get \"abccba\" using the operation." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 2 * 10^4\ns consists of letters 'a', 'b', and 'c'", + "tags": [ + "String", + "Stack" + ], + "title-slug": "check-if-word-is-valid-after-substitutions" + }, + { + "leetcode-id": 1004, + "title": "Max Consecutive Ones III", + "difficulty": 2, + "description": "Given a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.", + "examples": [ + "Example 1:\nInput: nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2\nOutput: 6\nExplanation: [1,1,1,0,0,1,1,1,1,1,1]\nBolded numbers were flipped from 0 to 1. The longest subarray is underlined.", + "Example 2:\nInput: nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3\nOutput: 10\nExplanation: [0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]\nBolded numbers were flipped from 0 to 1. The longest subarray is underlined." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\nnums[i] is either 0 or 1.\n0 <= k <= nums.length", + "tags": [ + "Array", + "Binary Search", + "Sliding Window", + "Prefix Sum" + ], + "title-slug": "max-consecutive-ones-iii" + }, + { + "leetcode-id": 1005, + "title": "Maximize Sum Of Array After K Negations", + "difficulty": 1, + "description": "Given an integer array nums and an integer k, modify the array in the following way:\n\nchoose an index i and replace nums[i] with -nums[i].\n\nYou should apply this process exactly k times. You may choose the same index i multiple times.\nReturn the largest possible sum of the array after modifying it in this way.", + "examples": [ + "Example 1:\nInput: nums = [4,2,3], k = 1\nOutput: 5\nExplanation: Choose index 1 and nums becomes [4,-2,3].", + "Example 2:\nInput: nums = [3,-1,0,2], k = 3\nOutput: 6\nExplanation: Choose indices (1, 2, 2) and nums becomes [3,1,0,2].", + "Example 3:\nInput: nums = [2,-3,-1,5,-4], k = 2\nOutput: 13\nExplanation: Choose indices (1, 4) and nums becomes [2,3,-1,5,4]." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n-100 <= nums[i] <= 100\n1 <= k <= 10^4", + "tags": [ + "Array", + "Greedy", + "Sorting" + ], + "title-slug": "maximize-sum-of-array-after-k-negations" + }, + { + "leetcode-id": 1006, + "title": "Clumsy Factorial", + "difficulty": 2, + "description": "The factorial of a positive integer n is the product of all positive integers less than or equal to n.\n\nFor example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1.\n\nWe make a clumsy factorial using the integers in decreasing order by swapping out the multiply operations for a fixed rotation of operations with multiply '*', divide '/', add '+', and subtract '-' in this order.\n\nFor example, clumsy(10) = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1.\n\nHowever, these operations are still applied using the usual order of operations of arithmetic. We do all multiplication and division steps before any addition or subtraction steps, and multiplication and division steps are processed left to right.\nAdditionally, the division that we use is floor division such that 10 * 9 / 8 = 90 / 8 = 11.\nGiven an integer n, return the clumsy factorial of n.", + "examples": [ + "Example 1:\nInput: n = 4\nOutput: 7\nExplanation: 7 = 4 * 3 / 2 + 1", + "Example 2:\nInput: n = 10\nOutput: 12\nExplanation: 12 = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^4", + "tags": [ + "Math", + "Stack", + "Simulation" + ], + "title-slug": "clumsy-factorial" + }, + { + "leetcode-id": 1007, + "title": "Minimum Domino Rotations For Equal Row", + "difficulty": 2, + "description": "In a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the i^th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)\nWe may rotate the i^th domino, so that tops[i] and bottoms[i] swap values.\nReturn the minimum number of rotations so that all the values in tops are the same, or all the values in bottoms are the same.\nIf it cannot be done, return -1.", + "examples": [ + "Example 1:\nInput: tops = [2,1,2,4,2,2], bottoms = [5,2,6,2,3,2]\nOutput: 2\nExplanation: \nThe first figure represents the dominoes as given by tops and bottoms: before we do any rotations.\nIf we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.", + "Example 2:\nInput: tops = [3,5,1,2,3], bottoms = [3,6,3,3,4]\nOutput: -1\nExplanation: \nIn this case, it is not possible to rotate the dominoes to make one row of values equal." + ], + "constraints": "Constraints:\n\n2 <= tops.length <= 2 * 10^4\nbottoms.length == tops.length\n1 <= tops[i], bottoms[i] <= 6", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "minimum-domino-rotations-for-equal-row" + }, + { + "leetcode-id": 1008, + "title": "Construct Binary Search Tree from Preorder Traversal", + "difficulty": 2, + "description": "Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its root.\nIt is guaranteed that there is always possible to find a binary search tree with the given requirements for the given test cases.\nA binary search tree is a binary tree where for every node, any descendant of Node.left has a value strictly less than Node.val, and any descendant of Node.right has a value strictly greater than Node.val.\nA preorder traversal of a binary tree displays the value of the node first, then traverses Node.left, then traverses Node.right.", + "examples": [ + "Example 1:\nInput: preorder = [8,5,1,7,10,12]\nOutput: [8,5,10,1,7,null,12]", + "Example 2:\nInput: preorder = [1,3]\nOutput: [1,null,3]" + ], + "constraints": "Constraints:\n\n1 <= preorder.length <= 100\n1 <= preorder[i] <= 1000\nAll the values of preorder are unique.", + "tags": [ + "Array", + "Stack", + "Tree", + "Binary Search Tree", + "Monotonic Stack", + "Binary Tree" + ], + "title-slug": "construct-binary-search-tree-from-preorder-traversal" + }, + { + "leetcode-id": 1009, + "title": "Complement of Base 10 Integer", + "difficulty": 1, + "description": "The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.\n\nFor example, The integer 5 is \"101\" in binary and its complement is \"010\" which is the integer 2.\n\nGiven an integer n, return its complement.", + "examples": [ + "Example 1:\nInput: n = 5\nOutput: 2\nExplanation: 5 is \"101\" in binary, with complement \"010\" in binary, which is 2 in base-10.", + "Example 2:\nInput: n = 7\nOutput: 0\nExplanation: 7 is \"111\" in binary, with complement \"000\" in binary, which is 0 in base-10.", + "Example 3:\nInput: n = 10\nOutput: 5\nExplanation: 10 is \"1010\" in binary, with complement \"0101\" in binary, which is 5 in base-10." + ], + "constraints": "Constraints:\n\n0 <= n < 10^9\n\n\u00a0\nNote: This question is the same as 476: https://leetcode.com/problems/number-complement/", + "tags": [ + "Bit Manipulation" + ], + "title-slug": "complement-of-base-10-integer" + }, + { + "leetcode-id": 1010, + "title": "Pairs of Songs With Total Durations Divisible by 60", + "difficulty": 2, + "description": "You are given a list of songs where the i^th song has a duration of time[i] seconds.\nReturn the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0.", + "examples": [ + "Example 1:\nInput: time = [30,20,150,100,40]\nOutput: 3\nExplanation: Three pairs have a total duration divisible by 60:\n(time[0] = 30, time[2] = 150): total duration 180\n(time[1] = 20, time[3] = 100): total duration 120\n(time[1] = 20, time[4] = 40): total duration 60", + "Example 2:\nInput: time = [60,60,60]\nOutput: 3\nExplanation: All three pairs have a total duration of 120, which is divisible by 60." + ], + "constraints": "Constraints:\n\n1 <= time.length <= 6 * 10^4\n1 <= time[i] <= 500", + "tags": [ + "Array", + "Hash Table", + "Counting" + ], + "title-slug": "pairs-of-songs-with-total-durations-divisible-by-60" + }, + { + "leetcode-id": 1011, + "title": "Capacity To Ship Packages Within D Days", + "difficulty": 2, + "description": "A conveyor belt has packages that must be shipped from one port to another within days days.\nThe i^th package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship.\nReturn the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within days days.", + "examples": [ + "Example 1:\nInput: weights = [1,2,3,4,5,6,7,8,9,10], days = 5\nOutput: 15\nExplanation: A ship capacity of 15 is the minimum to ship all the packages in 5 days like this:\n1st day: 1, 2, 3, 4, 5\n2nd day: 6, 7\n3rd day: 8\n4th day: 9\n5th day: 10\n\nNote that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the packages into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed.", + "Example 2:\nInput: weights = [3,2,2,4,1,4], days = 3\nOutput: 6\nExplanation: A ship capacity of 6 is the minimum to ship all the packages in 3 days like this:\n1st day: 3, 2\n2nd day: 2, 4\n3rd day: 1, 4", + "Example 3:\nInput: weights = [1,2,3,1,1], days = 4\nOutput: 3\nExplanation:\n1st day: 1\n2nd day: 2\n3rd day: 3\n4th day: 1, 1" + ], + "constraints": "Constraints:\n\n1 <= days <= weights.length <= 5 * 10^4\n1 <= weights[i] <= 500", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "capacity-to-ship-packages-within-d-days" + }, + { + "leetcode-id": 1012, + "title": "Numbers With Repeated Digits", + "difficulty": 3, + "description": "Given an integer n, return the number of positive integers in the range [1, n] that have at least one repeated digit.", + "examples": [ + "Example 1:\nInput: n = 20\nOutput: 1\nExplanation: The only positive number (<= 20) with at least 1 repeated digit is 11.", + "Example 2:\nInput: n = 100\nOutput: 10\nExplanation: The positive numbers (<= 100) with atleast 1 repeated digit are 11, 22, 33, 44, 55, 66, 77, 88, 99, and 100.", + "Example 3:\nInput: n = 1000\nOutput: 262" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^9", + "tags": [ + "Math", + "Dynamic Programming" + ], + "title-slug": "numbers-with-repeated-digits" + }, + { + "leetcode-id": 1013, + "title": "Partition Array Into Three Parts With Equal Sum", + "difficulty": 1, + "description": "Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.\nFormally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[arr.length - 1])", + "examples": [ + "Example 1:\nInput: arr = [0,2,1,-6,6,-7,9,1,2,0,1]\nOutput: true\nExplanation: 0 + 2 + 1 = -6 + 6 - 7 + 9 + 1 = 2 + 0 + 1", + "Example 2:\nInput: arr = [0,2,1,-6,6,7,9,-1,2,0,1]\nOutput: false", + "Example 3:\nInput: arr = [3,3,6,5,-2,2,5,1,-9,4]\nOutput: true\nExplanation: 3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4" + ], + "constraints": "Constraints:\n\n3 <= arr.length <= 5 * 10^4\n-10^4 <= arr[i] <= 10^4", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "partition-array-into-three-parts-with-equal-sum" + }, + { + "leetcode-id": 1014, + "title": "Best Sightseeing Pair", + "difficulty": 2, + "description": "You are given an integer array values where values[i] represents the value of the i^th sightseeing spot. Two sightseeing spots i and j have a distance j - i between them.\nThe score of a pair (i < j) of sightseeing spots is values[i] + values[j] + i - j: the sum of the values of the sightseeing spots, minus the distance between them.\nReturn the maximum score of a pair of sightseeing spots.", + "examples": [ + "Example 1:\nInput: values = [8,1,5,2,6]\nOutput: 11\nExplanation: i = 0, j = 2, values[i] + values[j] + i - j = 8 + 5 + 0 - 2 = 11", + "Example 2:\nInput: values = [1,2]\nOutput: 2" + ], + "constraints": "Constraints:\n\n2 <= values.length <= 5 * 10^4\n1 <= values[i] <= 1000", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "best-sightseeing-pair" + }, + { + "leetcode-id": 1015, + "title": "Smallest Integer Divisible by K", + "difficulty": 2, + "description": "Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1.\nReturn the length of n. If there is no such n, return -1.\nNote: n may not fit in a 64-bit signed integer.", + "examples": [ + "Example 1:\nInput: k = 1\nOutput: 1\nExplanation: The smallest answer is n = 1, which has length 1.", + "Example 2:\nInput: k = 2\nOutput: -1\nExplanation: There is no such positive integer n divisible by 2.", + "Example 3:\nInput: k = 3\nOutput: 3\nExplanation: The smallest answer is n = 111, which has length 3." + ], + "constraints": "Constraints:\n\n1 <= k <= 10^5", + "tags": [ + "Hash Table", + "Math" + ], + "title-slug": "smallest-integer-divisible-by-k" + }, + { + "leetcode-id": 1016, + "title": "Binary String With Substrings Representing 1 To N", + "difficulty": 2, + "description": "Given a binary string s and a positive integer n, return true if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise.\nA substring is a contiguous sequence of characters within a string.", + "examples": [ + "Example 1:\nInput: s = \"0110\", n = 3\nOutput: true", + "Example 2:\nInput: s = \"0110\", n = 4\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns[i] is either '0' or '1'.\n1 <= n <= 10^9", + "tags": [ + "String" + ], + "title-slug": "binary-string-with-substrings-representing-1-to-n" + }, + { + "leetcode-id": 1017, + "title": "Convert to Base -2", + "difficulty": 2, + "description": "Given an integer n, return a binary string representing its representation in base -2.\nNote that the returned string should not have leading zeros unless the string is \"0\".", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: \"110\"\nExplantion: (-2)^2 + (-2)^1 = 2", + "Example 2:\nInput: n = 3\nOutput: \"111\"\nExplantion: (-2)^2 + (-2)^1 + (-2)^0 = 3", + "Example 3:\nInput: n = 4\nOutput: \"100\"\nExplantion: (-2)^2 = 4" + ], + "constraints": "Constraints:\n\n0 <= n <= 10^9", + "tags": [ + "Math" + ], + "title-slug": "convert-to-base-2" + }, + { + "leetcode-id": 1018, + "title": "Binary Prefix Divisible By 5", + "difficulty": 1, + "description": "You are given a binary array nums (0-indexed).\nWe define xi as the number whose binary representation is the subarray nums[0..i] (from most-significant-bit to least-significant-bit).\n\nFor example, if nums = [1,0,1], then x0 = 1, x1 = 2, and x2 = 5.\n\nReturn an array of booleans answer where answer[i] is true if xi is divisible by 5.", + "examples": [ + "Example 1:\nInput: nums = [0,1,1]\nOutput: [true,false,false]\nExplanation: The input numbers in binary are 0, 01, 011; which are 0, 1, and 3 in base-10.\nOnly the first number is divisible by 5, so answer[0] is true.", + "Example 2:\nInput: nums = [1,1,1]\nOutput: [false,false,false]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\nnums[i] is either 0 or 1.", + "tags": [ + "Array" + ], + "title-slug": "binary-prefix-divisible-by-5" + }, + { + "leetcode-id": 1019, + "title": "Next Greater Node In Linked List", + "difficulty": 2, + "description": "You are given the head of a linked list with n nodes.\nFor each node in the list, find the value of the next greater node. That is, for each node, find the value of the first node that is next to it and has a strictly larger value than it.\nReturn an integer array answer where answer[i] is the value of the next greater node of the i^th node (1-indexed). If the i^th node does not have a next greater node, set answer[i] = 0.", + "examples": [ + "Example 1:\nInput: head = [2,1,5]\nOutput: [5,5,0]", + "Example 2:\nInput: head = [2,7,4,3,5]\nOutput: [7,0,5,5,0]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is n.\n1 <= n <= 10^4\n1 <= Node.val <= 10^9", + "tags": [ + "Array", + "Linked List", + "Stack", + "Monotonic Stack" + ], + "title-slug": "next-greater-node-in-linked-list" + }, + { + "leetcode-id": 1020, + "title": "Number of Enclaves", + "difficulty": 2, + "description": "You are given an m x n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell.\nA move consists of walking from one land cell to another adjacent (4-directionally) land cell or walking off the boundary of the grid.\nReturn the number of land cells in grid for which we cannot walk off the boundary of the grid in any number of moves.", + "examples": [ + "Example 1:\nInput: grid = [[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]]\nOutput: 3\nExplanation: There are three 1s that are enclosed by 0s, and one 1 that is not enclosed because its on the boundary.", + "Example 2:\nInput: grid = [[0,1,1,0],[0,0,1,0],[0,0,1,0],[0,0,0,0]]\nOutput: 0\nExplanation: All 1s are either on the boundary or can reach the boundary." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 500\ngrid[i][j] is either 0 or 1.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Matrix" + ], + "title-slug": "number-of-enclaves" + }, + { + "leetcode-id": 1021, + "title": "Remove Outermost Parentheses", + "difficulty": 1, + "description": "A valid parentheses string is either empty \"\", \"(\" + A + \")\", or A + B, where A and B are valid parentheses strings, and + represents string concatenation.\n\nFor example, \"\", \"()\", \"(())()\", and \"(()(()))\" are all valid parentheses strings.\n\nA valid parentheses string s is primitive if it is nonempty, and there does not exist a way to split it into s = A + B, with A and B nonempty valid parentheses strings.\nGiven a valid parentheses string s, consider its primitive decomposition: s = P1 + P2 + ... + Pk, where Pi are primitive valid parentheses strings.\nReturn s after removing the outermost parentheses of every primitive string in the primitive decomposition of s.", + "examples": [ + "Example 1:\nInput: s = \"(()())(())\"\nOutput: \"()()()\"\nExplanation: \nThe input string is \"(()())(())\", with primitive decomposition \"(()())\" + \"(())\".\nAfter removing outer parentheses of each part, this is \"()()\" + \"()\" = \"()()()\".", + "Example 2:\nInput: s = \"(()())(())(()(()))\"\nOutput: \"()()()()(())\"\nExplanation: \nThe input string is \"(()())(())(()(()))\", with primitive decomposition \"(()())\" + \"(())\" + \"(()(()))\".\nAfter removing outer parentheses of each part, this is \"()()\" + \"()\" + \"()(())\" = \"()()()()(())\".", + "Example 3:\nInput: s = \"()()\"\nOutput: \"\"\nExplanation: \nThe input string is \"()()\", with primitive decomposition \"()\" + \"()\".\nAfter removing outer parentheses of each part, this is \"\" + \"\" = \"\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns[i] is either '(' or ')'.\ns is a valid parentheses string.", + "tags": [ + "String", + "Stack" + ], + "title-slug": "remove-outermost-parentheses" + }, + { + "leetcode-id": 1022, + "title": "Sum of Root To Leaf Binary Numbers", + "difficulty": 1, + "description": "You are given the root of a binary tree where each node has a value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit.\n\nFor example, if the path is 0 -> 1 -> 1 -> 0 -> 1, then this could represent 01101 in binary, which is 13.\n\nFor all leaves in the tree, consider the numbers represented by the path from the root to that leaf. Return the sum of these numbers.\nThe test cases are generated so that the answer fits in a 32-bits integer.", + "examples": [ + "Example 1:\nInput: root = [1,0,1,0,1,0,1]\nOutput: 22\nExplanation: (100) + (101) + (110) + (111) = 4 + 5 + 6 + 7 = 22", + "Example 2:\nInput: root = [0]\nOutput: 0" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 1000].\nNode.val is 0 or 1.", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "sum-of-root-to-leaf-binary-numbers" + }, + { + "leetcode-id": 1023, + "title": "Camelcase Matching", + "difficulty": 2, + "description": "Given an array of strings queries and a string pattern, return a boolean array answer where answer[i] is true if queries[i] matches pattern, and false otherwise.\nA query word queries[i] matches pattern if you can insert lowercase English letters pattern so that it equals the query. You may insert each character at any position and you may not insert any characters.", + "examples": [ + "Example 1:\nInput: queries = [\"FooBar\",\"FooBarTest\",\"FootBall\",\"FrameBuffer\",\"ForceFeedBack\"], pattern = \"FB\"\nOutput: [true,false,true,true,false]\nExplanation: \"FooBar\" can be generated like this \"F\" + \"oo\" + \"B\" + \"ar\".\n\"FootBall\" can be generated like this \"F\" + \"oot\" + \"B\" + \"all\".\n\"FrameBuffer\" can be generated like this \"F\" + \"rame\" + \"B\" + \"uffer\".", + "Example 2:\nInput: queries = [\"FooBar\",\"FooBarTest\",\"FootBall\",\"FrameBuffer\",\"ForceFeedBack\"], pattern = \"FoBa\"\nOutput: [true,false,true,false,false]\nExplanation: \"FooBar\" can be generated like this \"Fo\" + \"o\" + \"Ba\" + \"r\".\n\"FootBall\" can be generated like this \"Fo\" + \"ot\" + \"Ba\" + \"ll\".", + "Example 3:\nInput: queries = [\"FooBar\",\"FooBarTest\",\"FootBall\",\"FrameBuffer\",\"ForceFeedBack\"], pattern = \"FoBaT\"\nOutput: [false,true,false,false,false]\nExplanation: \"FooBarTest\" can be generated like this \"Fo\" + \"o\" + \"Ba\" + \"r\" + \"T\" + \"est\"." + ], + "constraints": "Constraints:\n\n1 <= pattern.length, queries.length <= 100\n1 <= queries[i].length <= 100\nqueries[i] and pattern consist of English letters.", + "tags": [ + "Two Pointers", + "String", + "Trie", + "String Matching" + ], + "title-slug": "camelcase-matching" + }, + { + "leetcode-id": 1024, + "title": "Video Stitching", + "difficulty": 2, + "description": "You are given a series of video clips from a sporting event that lasted time seconds. These video clips can be overlapping with each other and have varying lengths.\nEach video clip is described by an array clips where clips[i] = [starti, endi] indicates that the ith clip started at starti and ended at endi.\nWe can cut these clips into segments freely.\n\nFor example, a clip [0, 7] can be cut into segments [0, 1] + [1, 3] + [3, 7].\n\nReturn the minimum number of clips needed so that we can cut the clips into segments that cover the entire sporting event [0, time]. If the task is impossible, return -1.", + "examples": [ + "Example 1:\nInput: clips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], time = 10\nOutput: 3\nExplanation: We take the clips [0,2], [8,10], [1,9]; a total of 3 clips.\nThen, we can reconstruct the sporting event as follows:\nWe cut [1,9] into segments [1,2] + [2,8] + [8,9].\nNow we have segments [0,2] + [2,8] + [8,10] which cover the sporting event [0, 10].", + "Example 2:\nInput: clips = [[0,1],[1,2]], time = 5\nOutput: -1\nExplanation: We cannot cover [0,5] with only [0,1] and [1,2].", + "Example 3:\nInput: clips = [[0,1],[6,8],[0,2],[5,6],[0,4],[0,3],[6,7],[1,3],[4,7],[1,4],[2,5],[2,6],[3,4],[4,5],[5,7],[6,9]], time = 9\nOutput: 3\nExplanation: We can take clips [0,4], [4,7], and [6,9]." + ], + "constraints": "Constraints:\n\n1 <= clips.length <= 100\n0 <= starti <= endi <= 100\n1 <= time <= 100", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "video-stitching" + }, + { + "leetcode-id": 1025, + "title": "Divisor Game", + "difficulty": 1, + "description": "Alice and Bob take turns playing a game, with Alice starting first.\nInitially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of:\n\nChoosing any x with 0 < x < n and n % x == 0.\nReplacing the number n on the chalkboard with n - x.\n\nAlso, if a player cannot make a move, they lose the game.\nReturn true if and only if Alice wins the game, assuming both players play optimally.", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: true\nExplanation: Alice chooses 1, and Bob has no more moves.", + "Example 2:\nInput: n = 3\nOutput: false\nExplanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves." + ], + "constraints": "Constraints:\n\n1 <= n <= 1000", + "tags": [ + "Math", + "Dynamic Programming", + "Brainteaser", + "Game Theory" + ], + "title-slug": "divisor-game" + }, + { + "leetcode-id": 1026, + "title": "Maximum Difference Between Node and Ancestor", + "difficulty": 2, + "description": "Given the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor of b.\nA node a is an ancestor of b if either: any child of a is equal to b\u00a0or any child of a is an ancestor of b.", + "examples": [ + "Example 1:\nInput: root = [8,3,10,1,6,null,14,null,null,4,7,13]\nOutput: 7\nExplanation: We have various ancestor-node differences, some of which are given below :\n|8 - 3| = 5\n|3 - 7| = 4\n|8 - 1| = 7\n|10 - 13| = 3\nAmong all possible differences, the maximum value of 7 is obtained by |8 - 1| = 7.", + "Example 2:\nInput: root = [1,null,2,null,0,3]\nOutput: 3" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [2, 5000].\n0 <= Node.val <= 10^5", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "maximum-difference-between-node-and-ancestor" + }, + { + "leetcode-id": 1027, + "title": "Longest Arithmetic Subsequence", + "difficulty": 2, + "description": "Given an array nums of integers, return the length of the longest arithmetic subsequence in nums.\nNote that:\n\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.\nA sequence seq is arithmetic if seq[i + 1] - seq[i] are all the same value (for 0 <= i < seq.length - 1).", + "examples": [ + "Example 1:\nInput: nums = [3,6,9,12]\nOutput: 4\nExplanation: The whole array is an arithmetic sequence with steps of length = 3.", + "Example 2:\nInput: nums = [9,4,7,2,10]\nOutput: 3\nExplanation: The longest arithmetic subsequence is [4,7,10].", + "Example 3:\nInput: nums = [20,1,15,3,10,5,8]\nOutput: 4\nExplanation: The longest arithmetic subsequence is [20,15,10,5]." + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 1000\n0 <= nums[i] <= 500", + "tags": [ + "Array", + "Hash Table", + "Binary Search", + "Dynamic Programming" + ], + "title-slug": "longest-arithmetic-subsequence" + }, + { + "leetcode-id": 1028, + "title": "Recover a Tree From Preorder Traversal", + "difficulty": 3, + "description": "We run a\u00a0preorder\u00a0depth-first search (DFS) on the root of a binary tree.\nAt each node in this traversal, we output D dashes (where D is the depth of this node), then we output the value of this node.\u00a0 If the depth of a node is D, the depth of its immediate child is D + 1.\u00a0 The depth of the root node is 0.\nIf a node has only one child, that child is guaranteed to be the left child.\nGiven the output traversal of this traversal, recover the tree and return its root.", + "examples": [ + "Example 1:\nInput: traversal = \"1-2--3--4-5--6--7\"\nOutput: [1,2,5,3,4,6,7]", + "Example 2:\nInput: traversal = \"1-2--3---4-5--6---7\"\nOutput: [1,2,5,3,null,6,null,4,null,7]", + "Example 3:\nInput: traversal = \"1-401--349---90--88\"\nOutput: [1,401,null,349,88,90]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the original tree is in the range [1, 1000].\n1 <= Node.val <= 10^9", + "tags": [ + "String", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "recover-a-tree-from-preorder-traversal" + }, + { + "leetcode-id": 1029, + "title": "Two City Scheduling", + "difficulty": 2, + "description": "A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti],\u00a0the cost of flying the i^th person to city a is aCosti, and the cost of flying the i^th person to city b is bCosti.\nReturn the minimum cost to fly every person to a city such that exactly n people arrive in each city.", + "examples": [ + "Example 1:\nInput: costs = [[10,20],[30,200],[400,50],[30,20]]\nOutput: 110\nExplanation: \nThe first person goes to city A for a cost of 10.\nThe second person goes to city A for a cost of 30.\nThe third person goes to city B for a cost of 50.\nThe fourth person goes to city B for a cost of 20.\n\nThe total minimum cost is 10 + 30 + 50 + 20 = 110 to have half the people interviewing in each city.", + "Example 2:\nInput: costs = [[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]]\nOutput: 1859", + "Example 3:\nInput: costs = [[515,563],[451,713],[537,709],[343,819],[855,779],[457,60],[650,359],[631,42]]\nOutput: 3086" + ], + "constraints": "Constraints:\n\n2 * n == costs.length\n2 <= costs.length <= 100\ncosts.length is even.\n1 <= aCosti, bCosti <= 1000", + "tags": [ + "Array", + "Greedy", + "Sorting" + ], + "title-slug": "two-city-scheduling" + }, + { + "leetcode-id": 1030, + "title": "Matrix Cells in Distance Order", + "difficulty": 1, + "description": "You are given four integers row, cols, rCenter, and cCenter. There is a rows x cols matrix and you are on the cell with the coordinates (rCenter, cCenter).\nReturn the coordinates of all cells in the matrix, sorted by their distance from (rCenter, cCenter) from the smallest distance to the largest distance. You may return the answer in any order that satisfies this condition.\nThe distance between two cells (r1, c1) and (r2, c2) is |r1 - r2| + |c1 - c2|.", + "examples": [ + "Example 1:\nInput: rows = 1, cols = 2, rCenter = 0, cCenter = 0\nOutput: [[0,0],[0,1]]\nExplanation: The distances from (0, 0) to other cells are: [0,1]", + "Example 2:\nInput: rows = 2, cols = 2, rCenter = 0, cCenter = 1\nOutput: [[0,1],[0,0],[1,1],[1,0]]\nExplanation: The distances from (0, 1) to other cells are: [0,1,1,2]\nThe answer [[0,1],[1,1],[0,0],[1,0]] would also be accepted as correct.", + "Example 3:\nInput: rows = 2, cols = 3, rCenter = 1, cCenter = 2\nOutput: [[1,2],[0,2],[1,1],[0,1],[1,0],[0,0]]\nExplanation: The distances from (1, 2) to other cells are: [0,1,1,2,2,3]\nThere are other answers that would also be accepted as correct, such as [[1,2],[1,1],[0,2],[1,0],[0,1],[0,0]]." + ], + "constraints": "Constraints:\n\n1 <= rows, cols <= 100\n0 <= rCenter < rows\n0 <= cCenter < cols", + "tags": [ + "Array", + "Math", + "Geometry", + "Sorting", + "Matrix" + ], + "title-slug": "matrix-cells-in-distance-order" + }, + { + "leetcode-id": 1031, + "title": "Maximum Sum of Two Non-Overlapping Subarrays", + "difficulty": 2, + "description": "Given an integer array nums and two integers firstLen and secondLen, return the maximum sum of elements in two non-overlapping subarrays with lengths firstLen and secondLen.\nThe array with length firstLen could occur before or after the array with length secondLen, but they have to be non-overlapping.\nA subarray is a contiguous part of an array.", + "examples": [ + "Example 1:\nInput: nums = [0,6,5,2,2,5,1,9,4], firstLen = 1, secondLen = 2\nOutput: 20\nExplanation: One choice of subarrays is [9] with length 1, and [6,5] with length 2.", + "Example 2:\nInput: nums = [3,8,1,3,2,1,8,9,0], firstLen = 3, secondLen = 2\nOutput: 29\nExplanation: One choice of subarrays is [3,8,1] with length 3, and [8,9] with length 2.", + "Example 3:\nInput: nums = [2,1,5,6,0,9,5,0,3,8], firstLen = 4, secondLen = 3\nOutput: 31\nExplanation: One choice of subarrays is [5,6,0,9] with length 4, and [0,3,8] with length 3." + ], + "constraints": "Constraints:\n\n1 <= firstLen, secondLen <= 1000\n2 <= firstLen + secondLen <= 1000\nfirstLen + secondLen <= nums.length <= 1000\n0 <= nums[i] <= 1000", + "tags": [ + "Array", + "Dynamic Programming", + "Sliding Window" + ], + "title-slug": "maximum-sum-of-two-non-overlapping-subarrays" + }, + { + "leetcode-id": 1032, + "title": "Stream of Characters", + "difficulty": 3, + "description": "Design an algorithm that accepts a stream of characters and checks if a suffix of these characters is a string of a given array of strings words.\nFor example, if words = [\"abc\", \"xyz\"]\u00a0and the stream added the four characters (one by one) 'a', 'x', 'y', and 'z', your algorithm should detect that the suffix \"xyz\" of the characters \"axyz\" matches \"xyz\" from words.\nImplement the StreamChecker class:\n\nStreamChecker(String[] words) Initializes the object with the strings array words.\nboolean query(char letter) Accepts a new character from the stream and returns true if any non-empty suffix from the stream forms a word that is in words.", + "examples": [ + "Example 1:\nInput\n[\"StreamChecker\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\", \"query\"]\n[[[\"cd\", \"f\", \"kl\"]], [\"a\"], [\"b\"], [\"c\"], [\"d\"], [\"e\"], [\"f\"], [\"g\"], [\"h\"], [\"i\"], [\"j\"], [\"k\"], [\"l\"]]\nOutput\n[null, false, false, false, true, false, true, false, false, false, false, false, true]\n\nExplanation\nStreamChecker streamChecker = new StreamChecker([\"cd\", \"f\", \"kl\"]);\nstreamChecker.query(\"a\"); // return False\nstreamChecker.query(\"b\"); // return False\nstreamChecker.query(\"c\"); // return False\nstreamChecker.query(\"d\"); // return True, because 'cd' is in the wordlist\nstreamChecker.query(\"e\"); // return False\nstreamChecker.query(\"f\"); // return True, because 'f' is in the wordlist\nstreamChecker.query(\"g\"); // return False\nstreamChecker.query(\"h\"); // return False\nstreamChecker.query(\"i\"); // return False\nstreamChecker.query(\"j\"); // return False\nstreamChecker.query(\"k\"); // return False\nstreamChecker.query(\"l\"); // return True, because 'kl' is in the wordlist" + ], + "constraints": "Constraints:\n\n1 <= words.length <= 2000\n1 <= words[i].length <= 200\nwords[i] consists of lowercase English letters.\nletter is a lowercase English letter.\nAt most 4 * 10^4 calls will be made to query.", + "tags": [ + "Array", + "String", + "Design", + "Trie", + "Data Stream" + ], + "title-slug": "stream-of-characters" + }, + { + "leetcode-id": 1033, + "title": "Moving Stones Until Consecutive", + "difficulty": 2, + "description": "There are three stones in different positions on the X-axis. You are given three integers a, b, and c, the positions of the stones.\nIn one move, you pick up a stone at an endpoint (i.e., either the lowest or highest position stone), and move it to an unoccupied position between those endpoints. Formally, let's say the stones are currently at positions x, y, and z with x < y < z. You pick up the stone at either position x or position z, and move that stone to an integer position k, with x < k < z and k != y.\nThe game ends when you cannot make any more moves (i.e., the stones are in three consecutive positions).\nReturn an integer array answer of length 2 where:\n\nanswer[0] is the minimum number of moves you can play, and\nanswer[1] is the maximum number of moves you can play.", + "examples": [ + "Example 1:\nInput: a = 1, b = 2, c = 5\nOutput: [1,2]\nExplanation: Move the stone from 5 to 3, or move the stone from 5 to 4 to 3.", + "Example 2:\nInput: a = 4, b = 3, c = 2\nOutput: [0,0]\nExplanation: We cannot make any moves.", + "Example 3:\nInput: a = 3, b = 5, c = 1\nOutput: [1,2]\nExplanation: Move the stone from 1 to 4; or move the stone from 1 to 2 to 4." + ], + "constraints": "Constraints:\n\n1 <= a, b, c <= 100\na, b, and c have different values.", + "tags": [ + "Math", + "Brainteaser" + ], + "title-slug": "moving-stones-until-consecutive" + }, + { + "leetcode-id": 1034, + "title": "Coloring A Border", + "difficulty": 2, + "description": "You are given an m x n integer matrix grid, and three integers row, col, and color. Each value in the grid represents the color of the grid square at that location.\nTwo squares are called adjacent if they are next to each other in any of the 4 directions.\nTwo squares belong to the same connected component if they have the same color and they are adjacent.\nThe border of a connected component is all the squares in the connected component that are either adjacent to (at least) a square not in the component, or on the boundary of the grid (the first or last row or column).\nYou should color the border of the connected component that contains the square grid[row][col] with color.\nReturn the final grid.", + "examples": [ + "Example 1:\nInput: grid = [[1,1],[1,2]], row = 0, col = 0, color = 3\nOutput: [[3,3],[3,2]]", + "Example 2:\nInput: grid = [[1,2,2],[2,3,2]], row = 0, col = 1, color = 3\nOutput: [[1,3,3],[2,3,3]]", + "Example 3:\nInput: grid = [[1,1,1],[1,1,1],[1,1,1]], row = 1, col = 1, color = 2\nOutput: [[2,2,2],[2,1,2],[2,2,2]]" + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 50\n1 <= grid[i][j], color <= 1000\n0 <= row < m\n0 <= col < n", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "coloring-a-border" + }, + { + "leetcode-id": 1035, + "title": "Uncrossed Lines", + "difficulty": 2, + "description": "You are given two integer arrays nums1 and nums2. We write the integers of nums1 and nums2 (in the order they are given) on two separate horizontal lines.\nWe may draw connecting lines: a straight line connecting two numbers nums1[i] and nums2[j] such that:\n\nnums1[i] == nums2[j], and\nthe line we draw does not intersect any other connecting (non-horizontal) line.\n\nNote that a connecting line cannot intersect even at the endpoints (i.e., each number can only belong to one connecting line).\nReturn the maximum number of connecting lines we can draw in this way.", + "examples": [ + "Example 1:\nInput: nums1 = [1,4,2], nums2 = [1,2,4]\nOutput: 2\nExplanation: We can draw 2 uncrossed lines as in the diagram.\nWe cannot draw 3 uncrossed lines, because the line from nums1[1] = 4 to nums2[2] = 4 will intersect the line from nums1[2]=2 to nums2[1]=2.", + "Example 2:\nInput: nums1 = [2,5,1,2,5], nums2 = [10,5,2,1,5,2]\nOutput: 3", + "Example 3:\nInput: nums1 = [1,3,7,1,7,5], nums2 = [1,9,2,5,1]\nOutput: 2" + ], + "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 500\n1 <= nums1[i], nums2[j] <= 2000", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "uncrossed-lines" + }, + { + "leetcode-id": 1036, + "title": "Escape a Large Maze", + "difficulty": 3, + "description": "There is a 1 million by 1 million grid on an XY-plane, and the coordinates of each grid square are (x, y).\nWe start at the source = [sx, sy] square and want to reach the target = [tx, ty] square. There is also an array of blocked squares, where each blocked[i] = [xi, yi] represents a blocked square with coordinates (xi, yi).\nEach move, we can walk one square north, east, south, or west if the square is not in the array of blocked squares. We are also not allowed to walk outside of the grid.\nReturn true if and only if it is possible to reach the target square from the source square through a sequence of valid moves.", + "examples": [ + "Example 1:\nInput: blocked = [[0,1],[1,0]], source = [0,0], target = [0,2]\nOutput: false\nExplanation: The target square is inaccessible starting from the source square because we cannot move.\nWe cannot move north or east because those squares are blocked.\nWe cannot move south or west because we cannot go outside of the grid.", + "Example 2:\nInput: blocked = [], source = [0,0], target = [999999,999999]\nOutput: true\nExplanation: Because there are no blocked cells, it is possible to reach the target square." + ], + "constraints": "Constraints:\n\n0 <= blocked.length <= 200\nblocked[i].length == 2\n0 <= xi, yi < 10^6\nsource.length == target.length == 2\n0 <= sx, sy, tx, ty < 10^6\nsource != target\nIt is guaranteed that source and target are not blocked.", + "tags": [ + "Array", + "Hash Table", + "Depth-First Search", + "Breadth-First Search" + ], + "title-slug": "escape-a-large-maze" + }, + { + "leetcode-id": 1037, + "title": "Valid Boomerang", + "difficulty": 1, + "description": "Given an array points where points[i] = [xi, yi] represents a point on the X-Y plane, return true if these points are a boomerang.\nA boomerang is a set of three points that are all distinct and not in a straight line.", + "examples": [ + "Example 1:\nInput: points = [[1,1],[2,3],[3,2]]\nOutput: true", + "Example 2:\nInput: points = [[1,1],[2,2],[3,3]]\nOutput: false" + ], + "constraints": "Constraints:\n\npoints.length == 3\npoints[i].length == 2\n0 <= xi, yi <= 100", + "tags": [ + "Array", + "Math", + "Geometry" + ], + "title-slug": "valid-boomerang" + }, + { + "leetcode-id": 1038, + "title": "Binary Search Tree to Greater Sum Tree", + "difficulty": 2, + "description": "Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.\nAs a reminder, a binary search tree is a tree that satisfies these constraints:\n\nThe left subtree of a node contains only nodes with keys less than the node's key.\nThe right subtree of a node contains only nodes with keys greater than the node's key.\nBoth the left and right subtrees must also be binary search trees.", + "examples": [ + "Example 1:\nInput: root = [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]\nOutput: [30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]", + "Example 2:\nInput: root = [0,null,1]\nOutput: [1,null,1]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 100].\n0 <= Node.val <= 100\nAll the values in the tree are unique.\n\n\u00a0\nNote: This question is the same as 538: https://leetcode.com/problems/convert-bst-to-greater-tree/", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "binary-search-tree-to-greater-sum-tree" + }, + { + "leetcode-id": 1039, + "title": "Minimum Score Triangulation of Polygon", + "difficulty": 2, + "description": "You have a convex n-sided polygon where each vertex has an integer value. You are given an integer array values where values[i] is the value of the i^th vertex (i.e., clockwise order).\nYou will triangulate the polygon into n - 2 triangles. For each triangle, the value of that triangle is the product of the values of its vertices, and the total score of the triangulation is the sum of these values over all n - 2 triangles in the triangulation.\nReturn the smallest possible total score that you can achieve with some triangulation of the polygon.", + "examples": [ + "Example 1:\nInput: values = [1,2,3]\nOutput: 6\nExplanation: The polygon is already triangulated, and the score of the only triangle is 6.", + "Example 2:\nInput: values = [3,7,4,5]\nOutput: 144\nExplanation: There are two triangulations, with possible scores: 3*7*5 + 4*5*7 = 245, or 3*4*5 + 3*4*7 = 144.\nThe minimum score is 144.", + "Example 3:\nInput: values = [1,3,1,4,1,5]\nOutput: 13\nExplanation: The minimum score triangulation has score 1*1*3 + 1*1*4 + 1*1*5 + 1*1*1 = 13." + ], + "constraints": "Constraints:\n\nn == values.length\n3 <= n <= 50\n1 <= values[i] <= 100", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "minimum-score-triangulation-of-polygon" + }, + { + "leetcode-id": 1040, + "title": "Moving Stones Until Consecutive II", + "difficulty": 2, + "description": "There are some stones in different positions on the X-axis. You are given an integer array stones, the positions of the stones.\nCall a stone an endpoint stone if it has the smallest or largest position. In one move, you pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.\n\nIn particular, if the stones are at say, stones = [1,2,5], you cannot move the endpoint stone at position 5, since moving it to any position (such as 0, or 3) will still keep that stone as an endpoint stone.\n\nThe game ends when you cannot make any more moves (i.e., the stones are in three consecutive positions).\nReturn an integer array answer of length 2 where:\n\nanswer[0] is the minimum number of moves you can play, and\nanswer[1] is the maximum number of moves you can play.", + "examples": [ + "Example 1:\nInput: stones = [7,4,9]\nOutput: [1,2]\nExplanation: We can move 4 -> 8 for one move to finish the game.\nOr, we can move 9 -> 5, 4 -> 6 for two moves to finish the game.", + "Example 2:\nInput: stones = [6,5,4,3,10]\nOutput: [2,3]\nExplanation: We can move 3 -> 8 then 10 -> 7 to finish the game.\nOr, we can move 3 -> 7, 4 -> 8, 5 -> 9 to finish the game.\nNotice we cannot move 10 -> 2 to finish the game, because that would be an illegal move." + ], + "constraints": "Constraints:\n\n3 <= stones.length <= 10^4\n1 <= stones[i] <= 10^9\nAll the values of stones are unique.", + "tags": [ + "Array", + "Math", + "Two Pointers", + "Sorting" + ], + "title-slug": "moving-stones-until-consecutive-ii" + }, + { + "leetcode-id": 1041, + "title": "Robot Bounded In Circle", + "difficulty": 2, + "description": "On an infinite plane, a robot initially stands at (0, 0) and faces north. Note that:\n\nThe north direction is the positive direction of the y-axis.\nThe south direction is the negative direction of the y-axis.\nThe east direction is the positive direction of the x-axis.\nThe west direction is the negative direction of the x-axis.\n\nThe robot can receive one of three instructions:\n\n\"G\": go straight 1 unit.\n\"L\": turn 90 degrees to the left (i.e., anti-clockwise direction).\n\"R\": turn 90 degrees to the right (i.e., clockwise direction).\n\nThe robot performs the instructions given in order, and repeats them forever.\nReturn true if and only if there exists a circle in the plane such that the robot never leaves the circle.", + "examples": [ + "Example 1:\nInput: instructions = \"GGLLGG\"\nOutput: true\nExplanation: The robot is initially at (0, 0) facing the north direction.\n\"G\": move one step. Position: (0, 1). Direction: North.\n\"G\": move one step. Position: (0, 2). Direction: North.\n\"L\": turn 90 degrees anti-clockwise. Position: (0, 2). Direction: West.\n\"L\": turn 90 degrees anti-clockwise. Position: (0, 2). Direction: South.\n\"G\": move one step. Position: (0, 1). Direction: South.\n\"G\": move one step. Position: (0, 0). Direction: South.\nRepeating the instructions, the robot goes into the cycle: (0, 0) --> (0, 1) --> (0, 2) --> (0, 1) --> (0, 0).\nBased on that, we return true.", + "Example 2:\nInput: instructions = \"GG\"\nOutput: false\nExplanation: The robot is initially at (0, 0) facing the north direction.\n\"G\": move one step. Position: (0, 1). Direction: North.\n\"G\": move one step. Position: (0, 2). Direction: North.\nRepeating the instructions, keeps advancing in the north direction and does not go into cycles.\nBased on that, we return false.", + "Example 3:\nInput: instructions = \"GL\"\nOutput: true\nExplanation: The robot is initially at (0, 0) facing the north direction.\n\"G\": move one step. Position: (0, 1). Direction: North.\n\"L\": turn 90 degrees anti-clockwise. Position: (0, 1). Direction: West.\n\"G\": move one step. Position: (-1, 1). Direction: West.\n\"L\": turn 90 degrees anti-clockwise. Position: (-1, 1). Direction: South.\n\"G\": move one step. Position: (-1, 0). Direction: South.\n\"L\": turn 90 degrees anti-clockwise. Position: (-1, 0). Direction: East.\n\"G\": move one step. Position: (0, 0). Direction: East.\n\"L\": turn 90 degrees anti-clockwise. Position: (0, 0). Direction: North.\nRepeating the instructions, the robot goes into the cycle: (0, 0) --> (0, 1) --> (-1, 1) --> (-1, 0) --> (0, 0).\nBased on that, we return true." + ], + "constraints": "Constraints:\n\n1 <= instructions.length <= 100\ninstructions[i] is 'G', 'L' or, 'R'.", + "tags": [ + "Math", + "String", + "Simulation" + ], + "title-slug": "robot-bounded-in-circle" + }, + { + "leetcode-id": 1042, + "title": "Flower Planting With No Adjacent", + "difficulty": 2, + "description": "You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. In each garden, you want to plant one of 4 types of flowers.\nAll gardens have at most 3 paths coming into or leaving it.\nYour task is to choose a flower type for each garden such that, for any two gardens connected by a path, they have different types of flowers.\nReturn any such a choice as an array answer, where answer[i] is the type of flower planted in the (i+1)^th garden. The flower types are denoted 1, 2, 3, or 4. It is guaranteed an answer exists.", + "examples": [ + "Example 1:\nInput: n = 3, paths = [[1,2],[2,3],[3,1]]\nOutput: [1,2,3]\nExplanation:\nGardens 1 and 2 have different types.\nGardens 2 and 3 have different types.\nGardens 3 and 1 have different types.\nHence, [1,2,3] is a valid answer. Other valid answers include [1,2,4], [1,4,2], and [3,2,1].", + "Example 2:\nInput: n = 4, paths = [[1,2],[3,4]]\nOutput: [1,2,1,2]", + "Example 3:\nInput: n = 4, paths = [[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]]\nOutput: [1,2,3,4]" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^4\n0 <= paths.length <= 2 * 10^4\npaths[i].length == 2\n1 <= xi, yi <= n\nxi != yi\nEvery garden has at most 3 paths coming into or leaving it.", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Graph" + ], + "title-slug": "flower-planting-with-no-adjacent" + }, + { + "leetcode-id": 1043, + "title": "Partition Array for Maximum Sum", + "difficulty": 2, + "description": "Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray.\nReturn the largest sum of the given array after partitioning. Test cases are generated so that the answer fits in a 32-bit integer.", + "examples": [ + "Example 1:\nInput: arr = [1,15,7,9,2,5,10], k = 3\nOutput: 84\nExplanation: arr becomes [15,15,15,9,10,10,10]", + "Example 2:\nInput: arr = [1,4,1,5,7,3,6,1,9,9,3], k = 4\nOutput: 83", + "Example 3:\nInput: arr = [1], k = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 500\n0 <= arr[i] <= 10^9\n1 <= k <= arr.length", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "partition-array-for-maximum-sum" + }, + { + "leetcode-id": 1044, + "title": "Longest Duplicate Substring", + "difficulty": 3, + "description": "Given a string s, consider all duplicated substrings: (contiguous) substrings of s that occur 2 or more times.\u00a0The occurrences\u00a0may overlap.\nReturn any duplicated\u00a0substring that has the longest possible length.\u00a0If s does not have a duplicated substring, the answer is \"\".", + "examples": [ + "Example 1:\nInput: s = \"banana\"\nOutput: \"ana\"", + "Example 2:\nInput: s = \"abcd\"\nOutput: \"\"" + ], + "constraints": "Constraints:\n\n2 <= s.length <= 3 * 10^4\ns consists of lowercase English letters.", + "tags": [ + "String", + "Binary Search", + "Sliding Window", + "Rolling Hash", + "Suffix Array", + "Hash Function" + ], + "title-slug": "longest-duplicate-substring" + }, + { + "leetcode-id": 1046, + "title": "Last Stone Weight", + "difficulty": 1, + "description": "You are given an array of integers stones where stones[i] is the weight of the i^th stone.\nWe are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have weights x and y with x <= y. The result of this smash is:\n\nIf x == y, both stones are destroyed, and\nIf x != y, the stone of weight x is destroyed, and the stone of weight y has new weight y - x.\n\nAt the end of the game, there is at most one stone left.\nReturn the weight of the last remaining stone. If there are no stones left, return 0.", + "examples": [ + "Example 1:\nInput: stones = [2,7,4,1,8,1]\nOutput: 1\nExplanation: \nWe combine 7 and 8 to get 1 so the array converts to [2,4,1,1,1] then,\nwe combine 2 and 4 to get 2 so the array converts to [2,1,1,1] then,\nwe combine 2 and 1 to get 1 so the array converts to [1,1,1] then,\nwe combine 1 and 1 to get 0 so the array converts to [1] then that's the value of the last stone.", + "Example 2:\nInput: stones = [1]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= stones.length <= 30\n1 <= stones[i] <= 1000", + "tags": [ + "Array", + "Heap (Priority Queue)" + ], + "title-slug": "last-stone-weight" + }, + { + "leetcode-id": 1047, + "title": "Remove All Adjacent Duplicates In String", + "difficulty": 1, + "description": "You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them.\nWe repeatedly make duplicate removals on s until we no longer can.\nReturn the final string after all such duplicate removals have been made. It can be proven that the answer is unique.", + "examples": [ + "Example 1:\nInput: s = \"abbaca\"\nOutput: \"ca\"\nExplanation: \nFor example, in \"abbaca\" we could remove \"bb\" since the letters are adjacent and equal, and this is the only possible move. The result of this move is that the string is \"aaca\", of which only \"aa\" is possible, so the final string is \"ca\".", + "Example 2:\nInput: s = \"azxxzy\"\nOutput: \"ay\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of lowercase English letters.", + "tags": [ + "String", + "Stack" + ], + "title-slug": "remove-all-adjacent-duplicates-in-string" + }, + { + "leetcode-id": 1048, + "title": "Longest String Chain", + "difficulty": 2, + "description": "You are given an array of words where each word consists of lowercase English letters.\nwordA is a predecessor of wordB if and only if we can insert exactly one letter anywhere in wordA without changing the order of the other characters to make it equal to wordB.\n\nFor example, \"abc\" is a predecessor of \"abac\", while \"cba\" is not a predecessor of \"bcad\".\n\nA word chain is a sequence of words [word1, word2, ..., wordk] with k >= 1, where word1 is a predecessor of word2, word2 is a predecessor of word3, and so on. A single word is trivially a word chain with k == 1.\nReturn the length of the longest possible word chain with words chosen from the given list of words.", + "examples": [ + "Example 1:\nInput: words = [\"a\",\"b\",\"ba\",\"bca\",\"bda\",\"bdca\"]\nOutput: 4\nExplanation: One of the longest word chains is [\"a\",\"ba\",\"bda\",\"bdca\"].", + "Example 2:\nInput: words = [\"xbc\",\"pcxbcf\",\"xb\",\"cxbc\",\"pcxbc\"]\nOutput: 5\nExplanation: All the words can be put in a word chain [\"xb\", \"xbc\", \"cxbc\", \"pcxbc\", \"pcxbcf\"].", + "Example 3:\nInput: words = [\"abcd\",\"dbqca\"]\nOutput: 1\nExplanation: The trivial word chain [\"abcd\"] is one of the longest word chains.\n[\"abcd\",\"dbqca\"] is not a valid word chain because the ordering of the letters is changed." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 1000\n1 <= words[i].length <= 16\nwords[i] only consists of lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "Two Pointers", + "String", + "Dynamic Programming" + ], + "title-slug": "longest-string-chain" + }, + { + "leetcode-id": 1049, + "title": "Last Stone Weight II", + "difficulty": 2, + "description": "You are given an array of integers stones where stones[i] is the weight of the i^th stone.\nWe are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:\n\nIf x == y, both stones are destroyed, and\nIf x != y, the stone of weight x is destroyed, and the stone of weight y has new weight y - x.\n\nAt the end of the game, there is at most one stone left.\nReturn the smallest possible weight of the left stone. If there are no stones left, return 0.", + "examples": [ + "Example 1:\nInput: stones = [2,7,4,1,8,1]\nOutput: 1\nExplanation:\nWe can combine 2 and 4 to get 2, so the array converts to [2,7,1,8,1] then,\nwe can combine 7 and 8 to get 1, so the array converts to [2,1,1,1] then,\nwe can combine 2 and 1 to get 1, so the array converts to [1,1,1] then,\nwe can combine 1 and 1 to get 0, so the array converts to [1], then that's the optimal value.", + "Example 2:\nInput: stones = [31,26,33,21,40]\nOutput: 5" + ], + "constraints": "Constraints:\n\n1 <= stones.length <= 30\n1 <= stones[i] <= 100", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "last-stone-weight-ii" + }, + { + "leetcode-id": 1051, + "title": "Height Checker", + "difficulty": 1, + "description": "A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the i^th student in line.\nYou are given an integer array heights representing the current order that the students are standing in. Each heights[i] is the height of the i^th student in line (0-indexed).\nReturn the number of indices where heights[i] != expected[i].", + "examples": [ + "Example 1:\nInput: heights = [1,1,4,2,1,3]\nOutput: 3\nExplanation: \nheights: [1,1,4,2,1,3]\nexpected: [1,1,1,2,3,4]\nIndices 2, 4, and 5 do not match.", + "Example 2:\nInput: heights = [5,1,2,3,4]\nOutput: 5\nExplanation:\nheights: [5,1,2,3,4]\nexpected: [1,2,3,4,5]\nAll indices do not match.", + "Example 3:\nInput: heights = [1,2,3,4,5]\nOutput: 0\nExplanation:\nheights: [1,2,3,4,5]\nexpected: [1,2,3,4,5]\nAll indices match." + ], + "constraints": "Constraints:\n\n1 <= heights.length <= 100\n1 <= heights[i] <= 100", + "tags": [ + "Array", + "Sorting", + "Counting Sort" + ], + "title-slug": "height-checker" + }, + { + "leetcode-id": 1052, + "title": "Grumpy Bookstore Owner", + "difficulty": 2, + "description": "There is a bookstore owner that has a store open for n minutes. Every minute, some number of customers enter the store. You are given an integer array customers of length n where customers[i] is the number of the customer that enters the store at the start of the i^th minute and all those customers leave after the end of that minute.\nOn some minutes, the bookstore owner is grumpy. You are given a binary array grumpy where grumpy[i] is 1 if the bookstore owner is grumpy during the i^th minute, and is 0 otherwise.\nWhen the bookstore owner is grumpy, the customers of that minute are not satisfied, otherwise, they are satisfied.\nThe bookstore owner knows a secret technique to keep themselves not grumpy for minutes consecutive minutes, but can only use it once.\nReturn the maximum number of customers that can be satisfied throughout the day.", + "examples": [ + "Example 1:\nInput: customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3\nOutput: 16\nExplanation: The bookstore owner keeps themselves not grumpy for the last 3 minutes. \nThe maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.", + "Example 2:\nInput: customers = [1], grumpy = [0], minutes = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\nn == customers.length == grumpy.length\n1 <= minutes <= n <= 2 * 10^4\n0 <= customers[i] <= 1000\ngrumpy[i] is either 0 or 1.", + "tags": [ + "Array", + "Sliding Window" + ], + "title-slug": "grumpy-bookstore-owner" + }, + { + "leetcode-id": 1053, + "title": "Previous Permutation With One Swap", + "difficulty": 2, + "description": "Given an array of positive integers arr (not necessarily distinct), return the lexicographically largest permutation that is smaller than arr, that can be made with exactly one swap. If it cannot be done, then return the same array.\nNote that a swap exchanges the positions of two numbers arr[i] and arr[j]", + "examples": [ + "Example 1:\nInput: arr = [3,2,1]\nOutput: [3,1,2]\nExplanation: Swapping 2 and 1.", + "Example 2:\nInput: arr = [1,1,5]\nOutput: [1,1,5]\nExplanation: This is already the smallest permutation.", + "Example 3:\nInput: arr = [1,9,4,6,7]\nOutput: [1,7,4,6,9]\nExplanation: Swapping 9 and 7." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^4\n1 <= arr[i] <= 10^4", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "previous-permutation-with-one-swap" + }, + { + "leetcode-id": 1054, + "title": "Distant Barcodes", + "difficulty": 2, + "description": "In a warehouse, there is a row of barcodes, where the i^th barcode is barcodes[i].\nRearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists.", + "examples": [ + "Example 1:\nInput: barcodes = [1,1,1,2,2,2]\nOutput: [2,1,2,1,2,1]", + "Example 2:\nInput: barcodes = [1,1,1,1,2,2,3,3]\nOutput: [1,3,1,3,1,2,1,2]" + ], + "constraints": "Constraints:\n\n1 <= barcodes.length <= 10000\n1 <= barcodes[i] <= 10000", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Sorting", + "Heap (Priority Queue)", + "Counting" + ], + "title-slug": "distant-barcodes" + }, + { + "leetcode-id": 1061, + "title": "Lexicographically Smallest Equivalent String", + "difficulty": 2, + "description": "You are given two strings of the same length s1 and s2 and a string baseStr.\nWe say s1[i] and s2[i] are equivalent characters.\n\nFor example, if s1 = \"abc\" and s2 = \"cde\", then we have 'a' == 'c', 'b' == 'd', and 'c' == 'e'.\n\nEquivalent characters follow the usual rules of any equivalence relation:\n\nReflexivity: 'a' == 'a'.\nSymmetry: 'a' == 'b' implies 'b' == 'a'.\nTransitivity: 'a' == 'b' and 'b' == 'c' implies 'a' == 'c'.\n\nFor example, given the equivalency information from s1 = \"abc\" and s2 = \"cde\", \"acd\" and \"aab\" are equivalent strings of baseStr = \"eed\", and \"aab\" is the lexicographically smallest equivalent string of baseStr.\nReturn the lexicographically smallest equivalent string of baseStr by using the equivalency information from s1 and s2.", + "examples": [ + "Example 1:\nInput: s1 = \"parker\", s2 = \"morris\", baseStr = \"parser\"\nOutput: \"makkek\"\nExplanation: Based on the equivalency information in s1 and s2, we can group their characters as [m,p], [a,o], [k,r,s], [e,i].\nThe characters in each group are equivalent and sorted in lexicographical order.\nSo the answer is \"makkek\".", + "Example 2:\nInput: s1 = \"hello\", s2 = \"world\", baseStr = \"hold\"\nOutput: \"hdld\"\nExplanation: Based on the equivalency information in s1 and s2, we can group their characters as [h,w], [d,e,o], [l,r].\nSo only the second letter 'o' in baseStr is changed to 'd', the answer is \"hdld\".", + "Example 3:\nInput: s1 = \"leetcode\", s2 = \"programs\", baseStr = \"sourcecode\"\nOutput: \"aauaaaaada\"\nExplanation: We group the equivalent characters in s1 and s2 as [a,o,e,r,s,c], [l,p], [g,t] and [d,m], thus all letters in baseStr except 'u' and 'd' are transformed to 'a', the answer is \"aauaaaaada\"." + ], + "constraints": "Constraints:\n\n1 <= s1.length, s2.length, baseStr <= 1000\ns1.length == s2.length\ns1, s2, and baseStr consist of lowercase English letters.", + "tags": [ + "String", + "Union Find" + ], + "title-slug": "lexicographically-smallest-equivalent-string" + }, + { + "leetcode-id": 1071, + "title": "Greatest Common Divisor of Strings", + "difficulty": 1, + "description": "For two strings s and t, we say \"t divides s\" if and only if s = t + ... + t (i.e., t is concatenated with itself one or more times).\nGiven two strings str1 and str2, return the largest string x such that x divides both str1 and str2.", + "examples": [ + "Example 1:\nInput: str1 = \"ABCABC\", str2 = \"ABC\"\nOutput: \"ABC\"", + "Example 2:\nInput: str1 = \"ABABAB\", str2 = \"ABAB\"\nOutput: \"AB\"", + "Example 3:\nInput: str1 = \"LEET\", str2 = \"CODE\"\nOutput: \"\"" + ], + "constraints": "Constraints:\n\n1 <= str1.length, str2.length <= 1000\nstr1 and str2 consist of English uppercase letters.", + "tags": [ + "Math", + "String" + ], + "title-slug": "greatest-common-divisor-of-strings" + }, + { + "leetcode-id": 1072, + "title": "Flip Columns For Maximum Number of Equal Rows", + "difficulty": 2, + "description": "You are given an m x n binary matrix matrix.\nYou can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from 0 to 1 or vice versa).\nReturn the maximum number of rows that have all values equal after some number of flips.", + "examples": [ + "Example 1:\nInput: matrix = [[0,1],[1,1]]\nOutput: 1\nExplanation: After flipping no values, 1 row has all values equal.", + "Example 2:\nInput: matrix = [[0,1],[1,0]]\nOutput: 2\nExplanation: After flipping values in the first column, both rows have equal values.", + "Example 3:\nInput: matrix = [[0,0,0],[0,0,1],[1,1,0]]\nOutput: 2\nExplanation: After flipping values in the first two columns, the last two rows have equal values." + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= m, n <= 300\nmatrix[i][j] is either\u00a00 or 1.", + "tags": [ + "Array", + "Hash Table", + "Matrix" + ], + "title-slug": "flip-columns-for-maximum-number-of-equal-rows" + }, + { + "leetcode-id": 1073, + "title": "Adding Two Negabinary Numbers", + "difficulty": 2, + "description": "Given two numbers arr1 and arr2 in base -2, return the result of adding them together.\nEach number is given in array format:\u00a0 as an array of 0s and 1s, from most significant bit to least significant bit.\u00a0 For example, arr = [1,1,0,1] represents the number (-2)^3\u00a0+ (-2)^2 + (-2)^0 = -3.\u00a0 A number arr in array, format is also guaranteed to have no leading zeros: either\u00a0arr == [0] or arr[0] == 1.\nReturn the result of adding arr1 and arr2 in the same format: as an array of 0s and 1s with no leading zeros.", + "examples": [ + "Example 1:\nInput: arr1 = [1,1,1,1,1], arr2 = [1,0,1]\nOutput: [1,0,0,0,0]\nExplanation: arr1 represents 11, arr2 represents 5, the output represents 16.", + "Example 2:\nInput: arr1 = [0], arr2 = [0]\nOutput: [0]", + "Example 3:\nInput: arr1 = [0], arr2 = [1]\nOutput: [1]" + ], + "constraints": "Constraints:\n\n1 <= arr1.length,\u00a0arr2.length <= 1000\narr1[i]\u00a0and arr2[i] are\u00a00 or 1\narr1 and arr2 have no leading zeros", + "tags": [ + "Array", + "Math" + ], + "title-slug": "adding-two-negabinary-numbers" + }, + { + "leetcode-id": 1074, + "title": "Number of Submatrices That Sum to Target", + "difficulty": 3, + "description": "Given a matrix\u00a0and a target, return the number of non-empty submatrices that sum to target.\nA submatrix x1, y1, x2, y2 is the set of all cells matrix[x][y] with x1 <= x <= x2 and y1 <= y <= y2.\nTwo submatrices (x1, y1, x2, y2) and (x1', y1', x2', y2') are different if they have some coordinate\u00a0that is different: for example, if x1 != x1'.", + "examples": [ + "Example 1:\nInput: matrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0\nOutput: 4\nExplanation: The four 1x1 submatrices that only contain 0.", + "Example 2:\nInput: matrix = [[1,-1],[-1,1]], target = 0\nOutput: 5\nExplanation: The two 1x2 submatrices, plus the two 2x1 submatrices, plus the 2x2 submatrix.", + "Example 3:\nInput: matrix = [[904]], target = 0\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= matrix.length <= 100\n1 <= matrix[0].length <= 100\n-1000 <= matrix[i] <= 1000\n-10^8 <= target <= 10^8", + "tags": [ + "Array", + "Hash Table", + "Matrix", + "Prefix Sum" + ], + "title-slug": "number-of-submatrices-that-sum-to-target" + }, + { + "leetcode-id": 1078, + "title": "Occurrences After Bigram", + "difficulty": 1, + "description": "Given two strings first and second, consider occurrences in some text of the form \"first second third\", where second comes immediately after first, and third comes immediately after second.\nReturn an array of all the words third for each occurrence of \"first second third\".", + "examples": [ + "Example 1:\nInput: text = \"alice is a good girl she is a good student\", first = \"a\", second = \"good\"\nOutput: [\"girl\",\"student\"]", + "Example 2:\nInput: text = \"we will we will rock you\", first = \"we\", second = \"will\"\nOutput: [\"we\",\"rock\"]" + ], + "constraints": "Constraints:\n\n1 <= text.length <= 1000\ntext consists of lowercase English letters and spaces.\nAll the words in text a separated by a single space.\n1 <= first.length, second.length <= 10\nfirst and second consist of lowercase English letters.", + "tags": [ + "String" + ], + "title-slug": "occurrences-after-bigram" + }, + { + "leetcode-id": 1079, + "title": "Letter Tile Possibilities", + "difficulty": 2, + "description": "You have n\u00a0\u00a0tiles, where each tile has one letter tiles[i] printed on it.\nReturn the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.", + "examples": [ + "Example 1:\nInput: tiles = \"AAB\"\nOutput: 8\nExplanation: The possible sequences are \"A\", \"B\", \"AA\", \"AB\", \"BA\", \"AAB\", \"ABA\", \"BAA\".", + "Example 2:\nInput: tiles = \"AAABBC\"\nOutput: 188", + "Example 3:\nInput: tiles = \"V\"\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= tiles.length <= 7\ntiles consists of uppercase English letters.", + "tags": [ + "Hash Table", + "String", + "Backtracking", + "Counting" + ], + "title-slug": "letter-tile-possibilities" + }, + { + "leetcode-id": 1080, + "title": "Insufficient Nodes in Root to Leaf Paths", + "difficulty": 2, + "description": "Given the root of a binary tree and an integer limit, delete all insufficient nodes in the tree simultaneously, and return the root of the resulting binary tree.\nA node is insufficient if every root to leaf path intersecting this node has a sum strictly less than limit.\nA leaf is a node with no children.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1\nOutput: [1,2,3,4,null,null,7,8,9,null,14]", + "Example 2:\nInput: root = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22\nOutput: [5,4,8,11,null,17,4,7,null,null,null,5]", + "Example 3:\nInput: root = [1,2,-3,-5,null,4,null], limit = -1\nOutput: [1,null,-3,4]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 5000].\n-10^5 <= Node.val <= 10^5\n-10^9 <= limit <= 10^9", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "insufficient-nodes-in-root-to-leaf-paths" + }, + { + "leetcode-id": 1081, + "title": "Smallest Subsequence of Distinct Characters", + "difficulty": 2, + "description": "Given a string s, return the lexicographically smallest subsequence of s that contains all the distinct characters of s exactly once.", + "examples": [ + "Example 1:\nInput: s = \"bcabc\"\nOutput: \"abc\"", + "Example 2:\nInput: s = \"cbacdcbc\"\nOutput: \"acdb\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns consists of lowercase English letters.\n\n\u00a0\nNote: This question is the same as 316: https://leetcode.com/problems/remove-duplicate-letters/", + "tags": [ + "String", + "Stack", + "Greedy", + "Monotonic Stack" + ], + "title-slug": "smallest-subsequence-of-distinct-characters" + }, + { + "leetcode-id": 1089, + "title": "Duplicate Zeros", + "difficulty": 1, + "description": "Given a fixed-length integer array arr, duplicate each occurrence of zero, shifting the remaining elements to the right.\nNote that elements beyond the length of the original array are not written. Do the above modifications to the input array in place and do not return anything.", + "examples": [ + "Example 1:\nInput: arr = [1,0,2,3,0,4,5,0]\nOutput: [1,0,0,2,3,0,0,4]\nExplanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]", + "Example 2:\nInput: arr = [1,2,3]\nOutput: [1,2,3]\nExplanation: After calling your function, the input array is modified to: [1,2,3]" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^4\n0 <= arr[i] <= 9", + "tags": [ + "Array", + "Two Pointers" + ], + "title-slug": "duplicate-zeros" + }, + { + "leetcode-id": 1090, + "title": "Largest Values From Labels", + "difficulty": 2, + "description": "There is a set of n items. You are given two integer arrays values and labels where the value and the label of the i^th element are values[i] and labels[i] respectively. You are also given two integers numWanted and useLimit.\nChoose a subset s of the n elements such that:\n\nThe size of the subset s is less than or equal to numWanted.\nThere are at most useLimit items with the same label in s.\n\nThe score of a subset is the sum of the values in the subset.\nReturn the maximum score of a subset s.", + "examples": [ + "Example 1:\nInput: values = [5,4,3,2,1], labels = [1,1,2,2,3], numWanted = 3, useLimit = 1\nOutput: 9\nExplanation: The subset chosen is the first, third, and fifth items.", + "Example 2:\nInput: values = [5,4,3,2,1], labels = [1,3,3,3,2], numWanted = 3, useLimit = 2\nOutput: 12\nExplanation: The subset chosen is the first, second, and third items.", + "Example 3:\nInput: values = [9,8,8,7,6], labels = [0,0,0,1,1], numWanted = 3, useLimit = 1\nOutput: 16\nExplanation: The subset chosen is the first and fourth items." + ], + "constraints": "Constraints:\n\nn == values.length == labels.length\n1 <= n <= 2 * 10^4\n0 <= values[i], labels[i] <= 2 * 10^4\n1 <= numWanted, useLimit <= n", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Sorting", + "Counting" + ], + "title-slug": "largest-values-from-labels" + }, + { + "leetcode-id": 1091, + "title": "Shortest Path in Binary Matrix", + "difficulty": 2, + "description": "Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1.\nA clear path in a binary matrix is a path from the top-left cell (i.e., (0, 0)) to the bottom-right cell (i.e., (n - 1, n - 1)) such that:\n\nAll the visited cells of the path are 0.\nAll the adjacent cells of the path are 8-directionally connected (i.e., they are different and they share an edge or a corner).\n\nThe length of a clear path is the number of visited cells of this path.", + "examples": [ + "Example 1:\nInput: grid = [[0,1],[1,0]]\nOutput: 2", + "Example 2:\nInput: grid = [[0,0,0],[1,1,0],[1,1,0]]\nOutput: 4", + "Example 3:\nInput: grid = [[1,0,0],[1,1,0],[1,1,0]]\nOutput: -1" + ], + "constraints": "Constraints:\n\nn == grid.length\nn == grid[i].length\n1 <= n <= 100\ngrid[i][j] is 0 or 1", + "tags": [ + "Array", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "shortest-path-in-binary-matrix" + }, + { + "leetcode-id": 1092, + "title": "Shortest Common Supersequence ", + "difficulty": 3, + "description": "Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them.\nA string s is a subsequence of string t if deleting some number of characters from t (possibly 0) results in the string s.", + "examples": [ + "Example 1:\nInput: str1 = \"abac\", str2 = \"cab\"\nOutput: \"cabac\"\nExplanation: \nstr1 = \"abac\" is a subsequence of \"cabac\" because we can delete the first \"c\".\nstr2 = \"cab\" is a subsequence of \"cabac\" because we can delete the last \"ac\".\nThe answer provided is the shortest such string that satisfies these properties.", + "Example 2:\nInput: str1 = \"aaaaaaaa\", str2 = \"aaaaaaaa\"\nOutput: \"aaaaaaaa\"" + ], + "constraints": "Constraints:\n\n1 <= str1.length, str2.length <= 1000\nstr1 and str2 consist of lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "shortest-common-supersequence" + }, + { + "leetcode-id": 1093, + "title": "Statistics from a Large Sample", + "difficulty": 2, + "description": "You are given a large sample of integers in the range [0, 255]. Since the sample is so large, it is represented by an array count\u00a0where count[k] is the number of times that k appears in the sample.\nCalculate the following statistics:\n\nminimum: The minimum element in the sample.\nmaximum: The maximum element in the sample.\nmean: The average of the sample, calculated as the total sum of all elements divided by the total number of elements.\nmedian:\n\t\nIf the sample has an odd number of elements, then the median is the middle element once the sample is sorted.\nIf the sample has an even number of elements, then the median is the average of the two middle elements once the sample is sorted.\n\n\nmode: The number that appears the most in the sample. It is guaranteed to be unique.\n\nReturn the statistics of the sample as an array of floating-point numbers [minimum, maximum, mean, median, mode]. Answers within 10^-5 of the actual answer will be accepted.", + "examples": [ + "Example 1:\nInput: count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\nOutput: [1.00000,3.00000,2.37500,2.50000,3.00000]\nExplanation: The sample represented by count is [1,2,2,2,3,3,3,3].\nThe minimum and maximum are 1 and 3 respectively.\nThe mean is (1+2+2+2+3+3+3+3) / 8 = 19 / 8 = 2.375.\nSince the size of the sample is even, the median is the average of the two middle elements 2 and 3, which is 2.5.\nThe mode is 3 as it appears the most in the sample.", + "Example 2:\nInput: count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\nOutput: [1.00000,4.00000,2.18182,2.00000,1.00000]\nExplanation: The sample represented by count is [1,1,1,1,2,2,2,3,3,4,4].\nThe minimum and maximum are 1 and 4 respectively.\nThe mean is (1+1+1+1+2+2+2+3+3+4+4) / 11 = 24 / 11 = 2.18181818... (for display purposes, the output shows the rounded number 2.18182).\nSince the size of the sample is odd, the median is the middle element 2.\nThe mode is 1 as it appears the most in the sample." + ], + "constraints": "Constraints:\n\ncount.length == 256\n0 <= count[i] <= 10^9\n1 <= sum(count) <= 10^9\nThe mode of the sample that count represents is unique.", + "tags": [ + "Array", + "Math", + "Probability and Statistics" + ], + "title-slug": "statistics-from-a-large-sample" + }, + { + "leetcode-id": 1094, + "title": "Car Pooling", + "difficulty": 2, + "description": "There is a car with capacity empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).\nYou are given the integer capacity and an array trips where trips[i] = [numPassengersi, fromi, toi] indicates that the i^th trip has numPassengersi passengers and the locations to pick them up and drop them off are fromi and toi respectively. The locations are given as the number of kilometers due east from the car's initial location.\nReturn true if it is possible to pick up and drop off all passengers for all the given trips, or false otherwise.", + "examples": [ + "Example 1:\nInput: trips = [[2,1,5],[3,3,7]], capacity = 4\nOutput: false", + "Example 2:\nInput: trips = [[2,1,5],[3,3,7]], capacity = 5\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= trips.length <= 1000\ntrips[i].length == 3\n1 <= numPassengersi <= 100\n0 <= fromi < toi <= 1000\n1 <= capacity <= 10^5", + "tags": [ + "Array", + "Sorting", + "Heap (Priority Queue)", + "Simulation", + "Prefix Sum" + ], + "title-slug": "car-pooling" + }, + { + "leetcode-id": 1095, + "title": "Find in Mountain Array", + "difficulty": 3, + "description": "(This problem is an interactive problem.)\nYou may recall that an array arr is a mountain array if and only if:\n\narr.length >= 3\nThere exists some i with 0 < i < arr.length - 1 such that:\n\t\narr[0] < arr[1] < ... < arr[i - 1] < arr[i]\narr[i] > arr[i + 1] > ... > arr[arr.length - 1]\n\n\n\nGiven a mountain array mountainArr, return the minimum index such that mountainArr.get(index) == target. If such an index does not exist, return -1.\nYou cannot access the mountain array directly. You may only access the array using a MountainArray interface:\n\nMountainArray.get(k) returns the element of the array at index k (0-indexed).\nMountainArray.length() returns the length of the array.\n\nSubmissions making more than 100 calls to MountainArray.get will be judged Wrong Answer. Also, any solutions that attempt to circumvent the judge will result in disqualification.", + "examples": [ + "Example 1:\nInput: array = [1,2,3,4,5,3,1], target = 3\nOutput: 2\nExplanation: 3 exists in the array, at index=2 and index=5. Return the minimum index, which is 2.", + "Example 2:\nInput: array = [0,1,2,4,2,1], target = 3\nOutput: -1\nExplanation: 3 does not exist in the array, so we return -1." + ], + "constraints": "Constraints:\n\n3 <= mountain_arr.length() <= 10^4\n0 <= target <= 10^9\n0 <= mountain_arr.get(index) <= 10^9", + "tags": [ + "Array", + "Binary Search", + "Interactive" + ], + "title-slug": "find-in-mountain-array" + }, + { + "leetcode-id": 1096, + "title": "Brace Expansion II", + "difficulty": 3, + "description": "Under the grammar given below, strings can represent a set of lowercase words. Let\u00a0R(expr)\u00a0denote the set of words the expression represents.\nThe grammar can best be understood through simple examples:\n\nSingle letters represent a singleton set containing that word.\n\t\nR(\"a\") = {\"a\"}\nR(\"w\") = {\"w\"}\n\n\nWhen we take a comma-delimited list of two or more expressions, we take the union of possibilities.\n\t\nR(\"{a,b,c}\") = {\"a\",\"b\",\"c\"}\nR(\"{{a,b},{b,c}}\") = {\"a\",\"b\",\"c\"} (notice the final set only contains each word at most once)\n\n\nWhen we concatenate two expressions, we take the set of possible concatenations between two words where the first word comes from the first expression and the second word comes from the second expression.\n\t\nR(\"{a,b}{c,d}\") = {\"ac\",\"ad\",\"bc\",\"bd\"}\nR(\"a{b,c}{d,e}f{g,h}\") = {\"abdfg\", \"abdfh\", \"abefg\", \"abefh\", \"acdfg\", \"acdfh\", \"acefg\", \"acefh\"}\n\n\n\nFormally, the three rules for our grammar:\n\nFor every lowercase letter x, we have R(x) = {x}.\nFor expressions e1, e2, ... , ek with k >= 2, we have R({e1, e2, ...}) = R(e1) \u222a R(e2) \u222a ...\nFor expressions e1 and e2, we have R(e1 + e2) = {a + b for (a, b) in R(e1) \u00d7 R(e2)}, where + denotes concatenation, and \u00d7 denotes the cartesian product.\n\nGiven an expression representing a set of words under the given grammar, return the sorted list of words that the expression represents.", + "examples": [ + "Example 1:\nInput: expression = \"{a,b}{c,{d,e}}\"\nOutput: [\"ac\",\"ad\",\"ae\",\"bc\",\"bd\",\"be\"]", + "Example 2:\nInput: expression = \"{{a,z},a{b,c},{ab,z}}\"\nOutput: [\"a\",\"ab\",\"ac\",\"z\"]\nExplanation: Each distinct word is written only once in the final answer." + ], + "constraints": "Constraints:\n\n1 <= expression.length <= 60\nexpression[i] consists of '{', '}', ','or lowercase English letters.\nThe given\u00a0expression\u00a0represents a set of words based on the grammar given in the description.", + "tags": [ + "String", + "Backtracking", + "Stack", + "Breadth-First Search" + ], + "title-slug": "brace-expansion-ii" + }, + { + "leetcode-id": 1103, + "title": "Distribute Candies to People", + "difficulty": 1, + "description": "We distribute some\u00a0number of candies, to a row of n =\u00a0num_people\u00a0people in the following way:\nWe then give 1 candy to the first person, 2 candies to the second person, and so on until we give n\u00a0candies to the last person.\nThen, we go back to the start of the row, giving n\u00a0+ 1 candies to the first person, n\u00a0+ 2 candies to the second person, and so on until we give 2 * n\u00a0candies to the last person.\nThis process repeats (with us giving one more candy each time, and moving to the start of the row after we reach the end) until we run out of candies.\u00a0 The last person will receive all of our remaining candies (not necessarily one more than the previous gift).\nReturn an array (of length num_people\u00a0and sum candies) that represents the final distribution of candies.", + "examples": [ + "Example 1:\nInput: candies = 7, num_people = 4\nOutput: [1,2,3,1]\nExplanation:\nOn the first turn, ans[0] += 1, and the array is [1,0,0,0].\nOn the second turn, ans[1] += 2, and the array is [1,2,0,0].\nOn the third turn, ans[2] += 3, and the array is [1,2,3,0].\nOn the fourth turn, ans[3] += 1 (because there is only one candy left), and the final array is [1,2,3,1].", + "Example 2:\nInput: candies = 10, num_people = 3\nOutput: [5,2,3]\nExplanation: \nOn the first turn, ans[0] += 1, and the array is [1,0,0].\nOn the second turn, ans[1] += 2, and the array is [1,2,0].\nOn the third turn, ans[2] += 3, and the array is [1,2,3].\nOn the fourth turn, ans[0] += 4, and the final array is [5,2,3]." + ], + "constraints": "Constraints:\n\n1 <= candies <= 10^9\n1 <= num_people <= 1000", + "tags": [ + "Math", + "Simulation" + ], + "title-slug": "distribute-candies-to-people" + }, + { + "leetcode-id": 1104, + "title": "Path In Zigzag Labelled Binary Tree", + "difficulty": 2, + "description": "In an infinite binary tree where every node has two children, the nodes are labelled in row order.\nIn the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, while in the even numbered rows (second, fourth, sixth,...), the labelling is right to left.\n\nGiven the label of a node in this tree, return the labels in the path from the root of the tree to the\u00a0node with that label.", + "examples": [ + "Example 1:\nInput: label = 14\nOutput: [1,3,4,14]", + "Example 2:\nInput: label = 26\nOutput: [1,2,6,10,26]" + ], + "constraints": "Constraints:\n\n1 <= label <= 10^6", + "tags": [ + "Math", + "Tree", + "Binary Tree" + ], + "title-slug": "path-in-zigzag-labelled-binary-tree" + }, + { + "leetcode-id": 1105, + "title": "Filling Bookcase Shelves", + "difficulty": 2, + "description": "You are given an array books where books[i] = [thicknessi, heighti] indicates the thickness and height of the i^th book. You are also given an integer shelfWidth.\nWe want to place these books in order onto bookcase shelves that have a total width shelfWidth.\nWe choose some of the books to place on this shelf such that the sum of their thickness is less than or equal to shelfWidth, then build another level of the shelf of the bookcase so that the total height of the bookcase has increased by the maximum height of the books we just put down. We repeat this process until there are no more books to place.\nNote that at each step of the above process, the order of the books we place is the same order as the given sequence of books.\n\nFor example, if we have an ordered list of 5 books, we might place the first and second book onto the first shelf, the third book on the second shelf, and the fourth and fifth book on the last shelf.\n\nReturn the minimum possible height that the total bookshelf can be after placing shelves in this manner.", + "examples": [ + "Example 1:\nInput: books = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelfWidth = 4\nOutput: 6\nExplanation:\nThe sum of the heights of the 3 shelves is 1 + 3 + 2 = 6.\nNotice that book number 2 does not have to be on the first shelf.", + "Example 2:\nInput: books = [[1,3],[2,4],[3,2]], shelfWidth = 6\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= books.length <= 1000\n1 <= thicknessi <= shelfWidth <= 1000\n1 <= heighti <= 1000", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "filling-bookcase-shelves" + }, + { + "leetcode-id": 1106, + "title": "Parsing A Boolean Expression", + "difficulty": 3, + "description": "A boolean expression is an expression that evaluates to either true or false. It can be in one of the following shapes:\n\n't' that evaluates to true.\n'f' that evaluates to false.\n'!(subExpr)' that evaluates to the logical NOT of the inner expression subExpr.\n'&(subExpr1, subExpr2, ..., subExprn)' that evaluates to the logical AND of the inner expressions subExpr1, subExpr2, ..., subExprn where n >= 1.\n'|(subExpr1, subExpr2, ..., subExprn)' that evaluates to the logical OR of the inner expressions subExpr1, subExpr2, ..., subExprn where n >= 1.\n\nGiven a string expression that represents a boolean expression, return the evaluation of that expression.\nIt is guaranteed that the given expression is valid and follows the given rules.", + "examples": [ + "Example 1:\nInput: expression = \"&(|(f))\"\nOutput: false\nExplanation: \nFirst, evaluate |(f) --> f. The expression is now \"&(f)\".\nThen, evaluate &(f) --> f. The expression is now \"f\".\nFinally, return false.", + "Example 2:\nInput: expression = \"|(f,f,f,t)\"\nOutput: true\nExplanation: The evaluation of (false OR false OR false OR true) is true.", + "Example 3:\nInput: expression = \"!(&(f,t))\"\nOutput: true\nExplanation: \nFirst, evaluate &(f,t) --> (false AND true) --> false --> f. The expression is now \"!(f)\".\nThen, evaluate !(f) --> NOT false --> true. We return true." + ], + "constraints": "Constraints:\n\n1 <= expression.length <= 2 * 10^4\nexpression[i] is one following characters: '(', ')', '&', '|', '!', 't', 'f', and ','.", + "tags": [ + "String", + "Stack", + "Recursion" + ], + "title-slug": "parsing-a-boolean-expression" + }, + { + "leetcode-id": 1108, + "title": "Defanging an IP Address", + "difficulty": 1, + "description": "Given a valid (IPv4) IP address, return a defanged version of that IP address.\nA defanged\u00a0IP address\u00a0replaces every period \".\" with \"[.]\".", + "examples": [ + "Example 1:\nInput: address = \"1.1.1.1\"\r\nOutput: \"1[.]1[.]1[.]1\"", + "Example 2:\nInput: address = \"255.100.50.0\"\r\nOutput: \"255[.]100[.]50[.]0\"" + ], + "constraints": "Constraints:\n\nThe given address is a valid IPv4 address.", + "tags": [ + "String" + ], + "title-slug": "defanging-an-ip-address" + }, + { + "leetcode-id": 1109, + "title": "Corporate Flight Bookings", + "difficulty": 2, + "description": "There are n flights that are labeled from 1 to n.\nYou are given an array of flight bookings bookings, where bookings[i] = [firsti, lasti, seatsi] represents a booking for flights firsti through lasti (inclusive) with seatsi seats reserved for each flight in the range.\nReturn an array answer of length n, where answer[i] is the total number of seats reserved for flight i.", + "examples": [ + "Example 1:\nInput: bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5\nOutput: [10,55,45,25,25]\nExplanation:\nFlight labels: 1 2 3 4 5\nBooking 1 reserved: 10 10\nBooking 2 reserved: 20 20\nBooking 3 reserved: 25 25 25 25\nTotal seats: 10 55 45 25 25\nHence, answer = [10,55,45,25,25]", + "Example 2:\nInput: bookings = [[1,2,10],[2,2,15]], n = 2\nOutput: [10,25]\nExplanation:\nFlight labels: 1 2\nBooking 1 reserved: 10 10\nBooking 2 reserved: 15\nTotal seats: 10 25\nHence, answer = [10,25]" + ], + "constraints": "Constraints:\n\n1 <= n <= 2 * 10^4\n1 <= bookings.length <= 2 * 10^4\nbookings[i].length == 3\n1 <= firsti <= lasti <= n\n1 <= seatsi <= 10^4", + "tags": [ + "Array", + "Prefix Sum" + ], + "title-slug": "corporate-flight-bookings" + }, + { + "leetcode-id": 1110, + "title": "Delete Nodes And Return Forest", + "difficulty": 2, + "description": "Given the root of a binary tree, each node in the tree has a distinct value.\nAfter deleting all nodes with a value in to_delete, we are left with a forest (a disjoint union of trees).\nReturn the roots of the trees in the remaining forest. You may return the result in any order.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,4,5,6,7], to_delete = [3,5]\nOutput: [[1,2,null,4],[6],[7]]", + "Example 2:\nInput: root = [1,2,4,null,3], to_delete = [3]\nOutput: [[1,2,4]]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the given tree is at most 1000.\nEach node has a distinct value between 1 and 1000.\nto_delete.length <= 1000\nto_delete contains distinct values between 1 and 1000.", + "tags": [ + "Array", + "Hash Table", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "delete-nodes-and-return-forest" + }, + { + "leetcode-id": 1111, + "title": "Maximum Nesting Depth of Two Valid Parentheses Strings", + "difficulty": 2, + "description": "A string is a valid parentheses string\u00a0(denoted VPS) if and only if it consists of \"(\" and \")\" characters only, and:\n\nIt is the empty string, or\nIt can be written as\u00a0AB\u00a0(A\u00a0concatenated with\u00a0B), where\u00a0A\u00a0and\u00a0B\u00a0are VPS's, or\nIt can be written as\u00a0(A), where\u00a0A\u00a0is a VPS.\n\nWe can\u00a0similarly define the nesting depth depth(S) of any VPS S as follows:\n\ndepth(\"\") = 0\ndepth(A + B) = max(depth(A), depth(B)), where A and B are VPS's\ndepth(\"(\" + A + \")\") = 1 + depth(A), where A is a VPS.\n\nFor example,\u00a0 \"\",\u00a0\"()()\", and\u00a0\"()(()())\"\u00a0are VPS's (with nesting depths 0, 1, and 2), and \")(\" and \"(()\" are not VPS's.\n\u00a0\nGiven a VPS seq, split it into two disjoint subsequences A and B, such that\u00a0A and B are VPS's (and\u00a0A.length + B.length = seq.length).\nNow choose any such A and B such that\u00a0max(depth(A), depth(B)) is the minimum possible value.\nReturn an answer array (of length seq.length) that encodes such a\u00a0choice of A and B:\u00a0 answer[i] = 0 if seq[i] is part of A, else answer[i] = 1.\u00a0 Note that even though multiple answers may exist, you may return any of them.", + "examples": [ + "Example 1:\nInput: seq = \"(()())\"\nOutput: [0,1,1,1,1,0]", + "Example 2:\nInput: seq = \"()(())()\"\nOutput: [0,0,0,1,1,0,1,1]" + ], + "constraints": "Constraints:\n\n1 <= seq.size <= 10000", + "tags": [ + "String", + "Stack" + ], + "title-slug": "maximum-nesting-depth-of-two-valid-parentheses-strings" + }, + { + "leetcode-id": 1122, + "title": "Relative Sort Array", + "difficulty": 1, + "description": "Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1.\nSort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Elements that do not appear in arr2 should be placed at the end of arr1 in ascending order.", + "examples": [ + "Example 1:\nInput: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]\nOutput: [2,2,2,1,4,3,3,9,6,7,19]", + "Example 2:\nInput: arr1 = [28,6,22,8,44,17], arr2 = [22,28,8,6]\nOutput: [22,28,8,6,17,44]" + ], + "constraints": "Constraints:\n\n1 <= arr1.length, arr2.length <= 1000\n0 <= arr1[i], arr2[i] <= 1000\nAll the elements of arr2 are distinct.\nEach\u00a0arr2[i] is in arr1.", + "tags": [ + "Array", + "Hash Table", + "Sorting", + "Counting Sort" + ], + "title-slug": "relative-sort-array" + }, + { + "leetcode-id": 1123, + "title": "Lowest Common Ancestor of Deepest Leaves", + "difficulty": 2, + "description": "Given the root of a binary tree, return the lowest common ancestor of its deepest leaves.\nRecall that:\n\nThe node of a binary tree is a leaf if and only if it has no children\nThe depth of the root of the tree is 0. if the depth of a node is d, the depth of each of its children is d + 1.\nThe lowest common ancestor of a set S of nodes, is the node A with the largest depth such that every node in S is in the subtree with root A.", + "examples": [ + "Example 1:\nInput: root = [3,5,1,6,2,0,8,null,null,7,4]\nOutput: [2,7,4]\nExplanation: We return the node with value 2, colored in yellow in the diagram.\nThe nodes coloured in blue are the deepest leaf-nodes of the tree.\nNote that nodes 6, 0, and 8 are also leaf nodes, but the depth of them is 2, but the depth of nodes 7 and 4 is 3.", + "Example 2:\nInput: root = [1]\nOutput: [1]\nExplanation: The root is the deepest node in the tree, and it's the lca of itself.", + "Example 3:\nInput: root = [0,1,3,null,2]\nOutput: [2]\nExplanation: The deepest leaf node in the tree is 2, the lca of one node is itself." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree will be in the range [1, 1000].\n0 <= Node.val <= 1000\nThe values of the nodes in the tree are unique.\n\n\u00a0\nNote: This question is the same as 865: https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/", + "tags": [ + "Hash Table", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "lowest-common-ancestor-of-deepest-leaves" + }, + { + "leetcode-id": 1124, + "title": "Longest Well-Performing Interval", + "difficulty": 2, + "description": "We are given hours, a list of the number of hours worked per day for a given employee.\nA day is considered to be a tiring day if and only if the number of hours worked is (strictly) greater than 8.\nA well-performing interval is an interval of days for which the number of tiring days is strictly larger than the number of non-tiring days.\nReturn the length of the longest well-performing interval.", + "examples": [ + "Example 1:\nInput: hours = [9,9,6,0,6,6,9]\nOutput: 3\nExplanation: The longest well-performing interval is [9,9,6].", + "Example 2:\nInput: hours = [6,6,6]\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= hours.length <= 10^4\n0 <= hours[i] <= 16", + "tags": [ + "Array", + "Hash Table", + "Stack", + "Monotonic Stack", + "Prefix Sum" + ], + "title-slug": "longest-well-performing-interval" + }, + { + "leetcode-id": 1125, + "title": "Smallest Sufficient Team", + "difficulty": 3, + "description": "In a project, you have a list of required skills req_skills, and a list of people. The i^th person people[i] contains a list of skills that the person has.\nConsider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can represent these teams by the index of each person.\n\nFor example, team = [0, 1, 3] represents the people with skills people[0], people[1], and people[3].\n\nReturn any sufficient team of the smallest possible size, represented by the index of each person. You may return the answer in any order.\nIt is guaranteed an answer exists.", + "examples": [ + "Example 1:\nInput: req_skills = [\"java\",\"nodejs\",\"reactjs\"], people = [[\"java\"],[\"nodejs\"],[\"nodejs\",\"reactjs\"]]\nOutput: [0,2]", + "Example 2:\nInput: req_skills = [\"algorithms\",\"math\",\"java\",\"reactjs\",\"csharp\",\"aws\"], people = [[\"algorithms\",\"math\",\"java\"],[\"algorithms\",\"math\",\"reactjs\"],[\"java\",\"csharp\",\"aws\"],[\"reactjs\",\"csharp\"],[\"csharp\",\"math\"],[\"aws\",\"java\"]]\nOutput: [1,2]" + ], + "constraints": "Constraints:\n\n1 <= req_skills.length <= 16\n1 <= req_skills[i].length <= 16\nreq_skills[i] consists of lowercase English letters.\nAll the strings of req_skills are unique.\n1 <= people.length <= 60\n0 <= people[i].length <= 16\n1 <= people[i][j].length <= 16\npeople[i][j] consists of lowercase English letters.\nAll the strings of people[i] are unique.\nEvery skill in people[i] is a skill in req_skills.\nIt is guaranteed a sufficient team exists.", + "tags": [ + "Array", + "Dynamic Programming", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "smallest-sufficient-team" + }, + { + "leetcode-id": 1128, + "title": "Number of Equivalent Domino Pairs", + "difficulty": 1, + "description": "Given a list of dominoes, dominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a == c and b == d), or (a == d and b == c) - that is, one domino can be rotated to be equal to another domino.\nReturn the number of pairs (i, j) for which 0 <= i < j < dominoes.length, and dominoes[i] is equivalent to dominoes[j].", + "examples": [ + "Example 1:\nInput: dominoes = [[1,2],[2,1],[3,4],[5,6]]\nOutput: 1", + "Example 2:\nInput: dominoes = [[1,2],[1,2],[1,1],[1,2],[2,2]]\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= dominoes.length <= 4 * 10^4\ndominoes[i].length == 2\n1 <= dominoes[i][j] <= 9", + "tags": [ + "Array", + "Hash Table", + "Counting" + ], + "title-slug": "number-of-equivalent-domino-pairs" + }, + { + "leetcode-id": 1129, + "title": "Shortest Path with Alternating Colors", + "difficulty": 2, + "description": "You are given an integer n, the number of nodes in a directed graph where the nodes are labeled from 0 to n - 1. Each edge is red or blue in this graph, and there could be self-edges and parallel edges.\nYou are given two arrays redEdges and blueEdges where:\n\nredEdges[i] = [ai, bi] indicates that there is a directed red edge from node ai to node bi in the graph, and\nblueEdges[j] = [uj, vj] indicates that there is a directed blue edge from node uj to node vj in the graph.\n\nReturn an array answer of length n, where each answer[x] is the length of the shortest path from node 0 to node x such that the edge colors alternate along the path, or -1 if such a path does not exist.", + "examples": [ + "Example 1:\nInput: n = 3, redEdges = [[0,1],[1,2]], blueEdges = []\nOutput: [0,1,-1]", + "Example 2:\nInput: n = 3, redEdges = [[0,1]], blueEdges = [[2,1]]\nOutput: [0,1,-1]" + ], + "constraints": "Constraints:\n\n1 <= n <= 100\n0 <= redEdges.length,\u00a0blueEdges.length <= 400\nredEdges[i].length == blueEdges[j].length == 2\n0 <= ai, bi, uj, vj < n", + "tags": [ + "Breadth-First Search", + "Graph" + ], + "title-slug": "shortest-path-with-alternating-colors" + }, + { + "leetcode-id": 1130, + "title": "Minimum Cost Tree From Leaf Values", + "difficulty": 2, + "description": "Given an array arr of positive integers, consider all binary trees such that:\n\nEach node has either 0 or 2 children;\nThe values of arr correspond to the values of each leaf in an in-order traversal of the tree.\nThe value of each non-leaf node is equal to the product of the largest leaf value in its left and right subtree, respectively.\n\nAmong all possible binary trees considered, return the smallest possible sum of the values of each non-leaf node. It is guaranteed this sum fits into a 32-bit integer.\nA node is a leaf if and only if it has zero children.", + "examples": [ + "Example 1:\nInput: arr = [6,2,4]\nOutput: 32\nExplanation: There are two possible trees shown.\nThe first has a non-leaf node sum 36, and the second has non-leaf node sum 32.", + "Example 2:\nInput: arr = [4,11]\nOutput: 44" + ], + "constraints": "Constraints:\n\n2 <= arr.length <= 40\n1 <= arr[i] <= 15\nIt is guaranteed that the answer fits into a 32-bit signed integer (i.e., it is less than 2^31).", + "tags": [ + "Array", + "Dynamic Programming", + "Stack", + "Greedy", + "Monotonic Stack" + ], + "title-slug": "minimum-cost-tree-from-leaf-values" + }, + { + "leetcode-id": 1131, + "title": "Maximum of Absolute Value Expression", + "difficulty": 2, + "description": "Given two arrays of integers with equal lengths, return the maximum value of:\n|arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|\nwhere the maximum is taken over all 0 <= i, j < arr1.length.", + "examples": [ + "Example 1:\nInput: arr1 = [1,2,3,4], arr2 = [-1,4,5,6]\nOutput: 13", + "Example 2:\nInput: arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]\nOutput: 20" + ], + "constraints": "Constraints:\n\n2 <= arr1.length == arr2.length <= 40000\n-10^6 <= arr1[i], arr2[i] <= 10^6", + "tags": [ + "Array", + "Math" + ], + "title-slug": "maximum-of-absolute-value-expression" + }, + { + "leetcode-id": 1137, + "title": "N-th Tribonacci Number", + "difficulty": 1, + "description": "The Tribonacci sequence Tn is defined as follows:\u00a0\nT0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.\nGiven n, return the value of Tn.", + "examples": [ + "Example 1:\nInput: n = 4\r\nOutput: 4\r\nExplanation:\r\nT_3 = 0 + 1 + 1 = 2\r\nT_4 = 1 + 1 + 2 = 4", + "Example 2:\nInput: n = 25\r\nOutput: 1389537" + ], + "constraints": "Constraints:\n\n0 <= n <= 37\nThe answer is guaranteed to fit within a 32-bit integer, ie. answer <= 2^31 - 1.", + "tags": [ + "Math", + "Dynamic Programming", + "Memoization" + ], + "title-slug": "n-th-tribonacci-number" + }, + { + "leetcode-id": 1138, + "title": "Alphabet Board Path", + "difficulty": 2, + "description": "On an alphabet board, we start at position (0, 0), corresponding to character\u00a0board[0][0].\nHere, board = [\"abcde\", \"fghij\", \"klmno\", \"pqrst\", \"uvwxy\", \"z\"], as shown in the diagram below.\n\nWe may make the following moves:\n\n'U' moves our position up one row, if the position exists on the board;\n'D' moves our position down one row, if the position exists on the board;\n'L' moves our position left one column, if the position exists on the board;\n'R' moves our position right one column, if the position exists on the board;\n'!'\u00a0adds the character board[r][c] at our current position (r, c)\u00a0to the\u00a0answer.\n\n(Here, the only positions that exist on the board are positions with letters on them.)\nReturn a sequence of moves that makes our answer equal to target\u00a0in the minimum number of moves.\u00a0 You may return any path that does so.", + "examples": [ + "Example 1:\nInput: target = \"leet\"\r\nOutput: \"DDR!UURRR!!DDD!\"", + "Example 2:\nInput: target = \"code\"\r\nOutput: \"RR!DDRR!UUL!R!\"" + ], + "constraints": "Constraints:\n\n1 <= target.length <= 100\ntarget consists only of English lowercase letters.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "alphabet-board-path" + }, + { + "leetcode-id": 1139, + "title": "Largest 1-Bordered Square", + "difficulty": 2, + "description": "Given a 2D grid of 0s and 1s, return the number of elements in\u00a0the largest square\u00a0subgrid that has all 1s on its border, or 0 if such a subgrid\u00a0doesn't exist in the grid.", + "examples": [ + "Example 1:\nInput: grid = [[1,1,1],[1,0,1],[1,1,1]]\r\nOutput: 9", + "Example 2:\nInput: grid = [[1,1,0,0]]\r\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= grid.length <= 100\n1 <= grid[0].length <= 100\ngrid[i][j] is 0 or 1", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "largest-1-bordered-square" + }, + { + "leetcode-id": 1140, + "title": "Stone Game II", + "difficulty": 2, + "description": "Alice and Bob continue their\u00a0games with piles of stones.\u00a0 There are a number of\u00a0piles\u00a0arranged in a row, and each pile has a positive integer number of stones\u00a0piles[i].\u00a0 The objective of the game is to end with the most\u00a0stones.\u00a0\nAlice\u00a0and Bob take turns, with Alice starting first.\u00a0 Initially, M = 1.\nOn each player's turn, that player\u00a0can take all the stones in the first X remaining piles, where 1 <= X <= 2M.\u00a0 Then, we set\u00a0M = max(M, X).\nThe game continues until all the stones have been taken.\nAssuming Alice and Bob play optimally, return the maximum number of stones Alice\u00a0can get.", + "examples": [ + "Example 1:\nInput: piles = [2,7,9,4,4]\nOutput: 10\nExplanation: If Alice takes one pile at the beginning, Bob takes two piles, then Alice takes 2 piles again. Alice can get 2 + 4 + 4 = 10 piles in total. If Alice takes two piles at the beginning, then Bob can take all three piles left. In this case, Alice get 2 + 7 = 9 piles in total. So we return 10 since it's larger.", + "Example 2:\nInput: piles = [1,2,3,4,5,100]\nOutput: 104" + ], + "constraints": "Constraints:\n\n1 <= piles.length <= 100\n1 <= piles[i]\u00a0<= 10^4", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Prefix Sum", + "Game Theory" + ], + "title-slug": "stone-game-ii" + }, + { + "leetcode-id": 1143, + "title": "Longest Common Subsequence", + "difficulty": 2, + "description": "Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.\nA subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.\n\nFor example, \"ace\" is a subsequence of \"abcde\".\n\nA common subsequence of two strings is a subsequence that is common to both strings.", + "examples": [ + "Example 1:\nInput: text1 = \"abcde\", text2 = \"ace\" \nOutput: 3 \nExplanation: The longest common subsequence is \"ace\" and its length is 3.", + "Example 2:\nInput: text1 = \"abc\", text2 = \"abc\"\nOutput: 3\nExplanation: The longest common subsequence is \"abc\" and its length is 3.", + "Example 3:\nInput: text1 = \"abc\", text2 = \"def\"\nOutput: 0\nExplanation: There is no such common subsequence, so the result is 0." + ], + "constraints": "Constraints:\n\n1 <= text1.length, text2.length <= 1000\ntext1 and text2 consist of only lowercase English characters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "longest-common-subsequence" + }, + { + "leetcode-id": 1144, + "title": "Decrease Elements To Make Array Zigzag", + "difficulty": 2, + "description": "Given an array nums of integers, a move\u00a0consists of choosing any element and decreasing it by 1.\nAn array A is a\u00a0zigzag array\u00a0if either:\n\nEvery even-indexed element is greater than adjacent elements, ie.\u00a0A[0] > A[1] < A[2] > A[3] < A[4] > ...\nOR, every odd-indexed element is greater than adjacent elements, ie.\u00a0A[0] < A[1] > A[2] < A[3] > A[4] < ...\n\nReturn the minimum number of moves to transform the given array nums into a zigzag array.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3]\nOutput: 2\nExplanation: We can decrease 2 to 0 or 3 to 1.", + "Example 2:\nInput: nums = [9,6,1,6,2]\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 1000", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "decrease-elements-to-make-array-zigzag" + }, + { + "leetcode-id": 1145, + "title": "Binary Tree Coloring Game", + "difficulty": 2, + "description": "Two players play a turn based game on a binary tree. We are given the root of this binary tree, and the number of nodes n in the tree. n is odd, and each node has a distinct value from 1 to n.\nInitially, the first player names a value x with 1 <= x <= n, and the second player names a value y with 1 <= y <= n and y != x. The first player colors the node with value x red, and the second player colors the node with value y blue.\nThen, the players take turns starting with the first player. In each turn, that player chooses a node of their color (red if player 1, blue if player 2) and colors an uncolored neighbor of the chosen node (either the left child, right child, or parent of the chosen node.)\nIf (and only if) a player cannot choose such a node in this way, they must pass their turn. If both players pass their turn, the game ends, and the winner is the player that colored more nodes.\nYou are the second player. If it is possible to choose such a y to ensure you win the game, return true. If it is not possible, return false.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,4,5,6,7,8,9,10,11], n = 11, x = 3\nOutput: true\nExplanation: The second player can choose the node with value 2.", + "Example 2:\nInput: root = [1,2,3], n = 3, x = 1\nOutput: false" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is n.\n1 <= x <= n <= 100\nn is odd.\n1 <= Node.val <= n\nAll the values of the tree are unique.", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "binary-tree-coloring-game" + }, + { + "leetcode-id": 1146, + "title": "Snapshot Array", + "difficulty": 2, + "description": "Implement a SnapshotArray that supports the following interface:\n\nSnapshotArray(int length) initializes an array-like data structure with the given length. Initially, each element equals 0.\nvoid set(index, val) sets the element at the given index to be equal to val.\nint snap() takes a snapshot of the array and returns the snap_id: the total number of times we called snap() minus 1.\nint get(index, snap_id) returns the value at the given index, at the time we took the snapshot with the given snap_id", + "examples": [ + "Example 1:\nInput: [\"SnapshotArray\",\"set\",\"snap\",\"set\",\"get\"]\n[[3],[0,5],[],[0,6],[0,0]]\nOutput: [null,null,0,null,5]\nExplanation: \nSnapshotArray snapshotArr = new SnapshotArray(3); // set the length to be 3\nsnapshotArr.set(0,5); // Set array[0] = 5\nsnapshotArr.snap(); // Take a snapshot, return snap_id = 0\nsnapshotArr.set(0,6);\nsnapshotArr.get(0,0); // Get the value of array[0] with snap_id = 0, return 5" + ], + "constraints": "Constraints:\n\n1 <= length <= 5 * 10^4\n0 <= index < length\n0 <= val <= 10^9\n0 <= snap_id < (the total number of times we call snap())\nAt most 5 * 10^4 calls will be made to set, snap, and get.", + "tags": [ + "Array", + "Hash Table", + "Binary Search", + "Design" + ], + "title-slug": "snapshot-array" + }, + { + "leetcode-id": 1147, + "title": "Longest Chunked Palindrome Decomposition", + "difficulty": 3, + "description": "You are given a string text. You should split it to k substrings (subtext1, subtext2, ..., subtextk) such that:\n\nsubtexti is a non-empty string.\nThe concatenation of all the substrings is equal to text (i.e., subtext1 + subtext2 + ... + subtextk == text).\nsubtexti == subtextk - i + 1 for all valid values of i (i.e., 1 <= i <= k).\n\nReturn the largest possible value of k.", + "examples": [ + "Example 1:\nInput: text = \"ghiabcdefhelloadamhelloabcdefghi\"\nOutput: 7\nExplanation: We can split the string on \"(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)\".", + "Example 2:\nInput: text = \"merchant\"\nOutput: 1\nExplanation: We can split the string on \"(merchant)\".", + "Example 3:\nInput: text = \"antaprezatepzapreanta\"\nOutput: 11\nExplanation: We can split the string on \"(a)(nt)(a)(pre)(za)(tep)(za)(pre)(a)(nt)(a)\"." + ], + "constraints": "Constraints:\n\n1 <= text.length <= 1000\ntext consists only of lowercase English characters.", + "tags": [ + "Two Pointers", + "String", + "Dynamic Programming", + "Greedy", + "Rolling Hash", + "Hash Function" + ], + "title-slug": "longest-chunked-palindrome-decomposition" + }, + { + "leetcode-id": 1154, + "title": "Day of the Year", + "difficulty": 1, + "description": "Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.", + "examples": [ + "Example 1:\nInput: date = \"2019-01-09\"\nOutput: 9\nExplanation: Given date is the 9th day of the year in 2019.", + "Example 2:\nInput: date = \"2019-02-10\"\nOutput: 41" + ], + "constraints": "Constraints:\n\ndate.length == 10\ndate[4] == date[7] == '-', and all other date[i]'s are digits\ndate represents a calendar date between Jan 1^st, 1900 and Dec 31^th, 2019.", + "tags": [ + "Math", + "String" + ], + "title-slug": "day-of-the-year" + }, + { + "leetcode-id": 1155, + "title": "Number of Dice Rolls With Target Sum", + "difficulty": 2, + "description": "You have n dice, and each die has k faces numbered from 1 to k.\nGiven three integers n, k, and target, return the number of possible ways (out of the k^n total ways) to roll the dice, so the sum of the face-up numbers equals target. Since the answer may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 1, k = 6, target = 3\nOutput: 1\nExplanation: You throw one die with 6 faces.\nThere is only one way to get a sum of 3.", + "Example 2:\nInput: n = 2, k = 6, target = 7\nOutput: 6\nExplanation: You throw two dice, each with 6 faces.\nThere are 6 ways to get a sum of 7: 1+6, 2+5, 3+4, 4+3, 5+2, 6+1.", + "Example 3:\nInput: n = 30, k = 30, target = 500\nOutput: 222616187\nExplanation: The answer must be returned modulo 10^9 + 7." + ], + "constraints": "Constraints:\n\n1 <= n, k <= 30\n1 <= target <= 1000", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "number-of-dice-rolls-with-target-sum" + }, + { + "leetcode-id": 1156, + "title": "Swap For Longest Repeated Character Substring", + "difficulty": 2, + "description": "You are given a string text. You can swap two of the characters in the text.\nReturn the length of the longest substring with repeated characters.", + "examples": [ + "Example 1:\nInput: text = \"ababa\"\nOutput: 3\nExplanation: We can swap the first 'b' with the last 'a', or the last 'b' with the first 'a'. Then, the longest repeated character substring is \"aaa\" with length 3.", + "Example 2:\nInput: text = \"aaabaaa\"\nOutput: 6\nExplanation: Swap 'b' with the last 'a' (or the first 'a'), and we get longest repeated character substring \"aaaaaa\" with length 6.", + "Example 3:\nInput: text = \"aaaaa\"\nOutput: 5\nExplanation: No need to swap, longest repeated character substring is \"aaaaa\" with length is 5." + ], + "constraints": "Constraints:\n\n1 <= text.length <= 2 * 10^4\ntext consist of lowercase English characters only.", + "tags": [ + "Hash Table", + "String", + "Sliding Window" + ], + "title-slug": "swap-for-longest-repeated-character-substring" + }, + { + "leetcode-id": 1157, + "title": "Online Majority Element In Subarray", + "difficulty": 3, + "description": "Design a data structure that efficiently finds the majority element of a given subarray.\nThe majority element of a subarray is an element that occurs threshold times or more in the subarray.\nImplementing the MajorityChecker class:\n\nMajorityChecker(int[] arr) Initializes the instance of the class with the given array arr.\nint query(int left, int right, int threshold) returns the element in the subarray arr[left...right] that occurs at least threshold times, or -1 if no such element exists.", + "examples": [ + "Example 1:\nInput\n[\"MajorityChecker\", \"query\", \"query\", \"query\"]\n[[[1, 1, 2, 2, 1, 1]], [0, 5, 4], [0, 3, 3], [2, 3, 2]]\nOutput\n[null, 1, -1, 2]\n\nExplanation\nMajorityChecker majorityChecker = new MajorityChecker([1, 1, 2, 2, 1, 1]);\nmajorityChecker.query(0, 5, 4); // return 1\nmajorityChecker.query(0, 3, 3); // return -1\nmajorityChecker.query(2, 3, 2); // return 2" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 2 * 10^4\n1 <= arr[i] <= 2 * 10^4\n0 <= left <= right < arr.length\nthreshold <= right - left + 1\n2 * threshold > right - left + 1\nAt most 10^4 calls will be made to query.", + "tags": [ + "Array", + "Binary Search", + "Design", + "Binary Indexed Tree", + "Segment Tree" + ], + "title-slug": "online-majority-element-in-subarray" + }, + { + "leetcode-id": 1160, + "title": "Find Words That Can Be Formed by Characters", + "difficulty": 1, + "description": "You are given an array of strings words and a string chars.\nA string is good if it can be formed by characters from chars (each character can only be used once).\nReturn the sum of lengths of all good strings in words.", + "examples": [ + "Example 1:\nInput: words = [\"cat\",\"bt\",\"hat\",\"tree\"], chars = \"atach\"\nOutput: 6\nExplanation: The strings that can be formed are \"cat\" and \"hat\" so the answer is 3 + 3 = 6.", + "Example 2:\nInput: words = [\"hello\",\"world\",\"leetcode\"], chars = \"welldonehoneyr\"\nOutput: 10\nExplanation: The strings that can be formed are \"hello\" and \"world\" so the answer is 5 + 5 = 10." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 1000\n1 <= words[i].length, chars.length <= 100\nwords[i] and chars consist of lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "find-words-that-can-be-formed-by-characters" + }, + { + "leetcode-id": 1161, + "title": "Maximum Level Sum of a Binary Tree", + "difficulty": 2, + "description": "Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.\nReturn the smallest level x such that the sum of all the values of nodes at level x is maximal.", + "examples": [ + "Example 1:\nInput: root = [1,7,0,7,-8,null,null]\nOutput: 2\nExplanation: \nLevel 1 sum = 1.\nLevel 2 sum = 7 + 0 = 7.\nLevel 3 sum = 7 + -8 = -1.\nSo we return the level with the maximum sum which is level 2.", + "Example 2:\nInput: root = [989,null,10250,98693,-89388,null,null,null,-32127]\nOutput: 2" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n-10^5 <= Node.val <= 10^5", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "maximum-level-sum-of-a-binary-tree" + }, + { + "leetcode-id": 1162, + "title": "As Far from Land as Possible", + "difficulty": 2, + "description": "Given an n x n grid\u00a0containing only values 0 and 1, where\u00a00 represents water\u00a0and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance.\u00a0If no land or water exists in the grid, return -1.\nThe distance used in this problem is the Manhattan distance:\u00a0the distance between two cells (x0, y0) and (x1, y1) is |x0 - x1| + |y0 - y1|.", + "examples": [ + "Example 1:\nInput: grid = [[1,0,1],[0,0,0],[1,0,1]]\nOutput: 2\nExplanation: The cell (1, 1) is as far as possible from all the land with distance 2.", + "Example 2:\nInput: grid = [[1,0,0],[0,0,0],[0,0,0]]\nOutput: 4\nExplanation: The cell (2, 2) is as far as possible from all the land with distance 4." + ], + "constraints": "Constraints:\n\nn == grid.length\nn == grid[i].length\n1 <= n\u00a0<= 100\ngrid[i][j]\u00a0is 0 or 1", + "tags": [ + "Array", + "Dynamic Programming", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "as-far-from-land-as-possible" + }, + { + "leetcode-id": 1163, + "title": "Last Substring in Lexicographical Order", + "difficulty": 3, + "description": "Given a string s, return the last substring of s in lexicographical order.", + "examples": [ + "Example 1:\nInput: s = \"abab\"\nOutput: \"bab\"\nExplanation: The substrings are [\"a\", \"ab\", \"aba\", \"abab\", \"b\", \"ba\", \"bab\"]. The lexicographically maximum substring is \"bab\".", + "Example 2:\nInput: s = \"leetcode\"\nOutput: \"tcode\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 4 * 10^5\ns contains only lowercase English letters.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "last-substring-in-lexicographical-order" + }, + { + "leetcode-id": 1169, + "title": "Invalid Transactions", + "difficulty": 2, + "description": "A transaction is possibly invalid if:\n\nthe amount exceeds $1000, or;\nif it occurs within (and including) 60 minutes of another transaction with the same name in a different city.\n\nYou are given an array of strings transaction where transactions[i] consists of comma-separated values representing the name, time (in minutes), amount, and city of the transaction.\nReturn a list of transactions that are possibly invalid. You may return the answer in any order.", + "examples": [ + "Example 1:\nInput: transactions = [\"alice,20,800,mtv\",\"alice,50,100,beijing\"]\nOutput: [\"alice,20,800,mtv\",\"alice,50,100,beijing\"]\nExplanation: The first transaction is invalid because the second transaction occurs within a difference of 60 minutes, have the same name and is in a different city. Similarly the second one is invalid too.", + "Example 2:\nInput: transactions = [\"alice,20,800,mtv\",\"alice,50,1200,mtv\"]\nOutput: [\"alice,50,1200,mtv\"]", + "Example 3:\nInput: transactions = [\"alice,20,800,mtv\",\"bob,50,1200,mtv\"]\nOutput: [\"bob,50,1200,mtv\"]" + ], + "constraints": "Constraints:\n\ntransactions.length <= 1000\nEach transactions[i] takes the form \"{name},{time},{amount},{city}\"\nEach {name} and {city} consist of lowercase English letters, and have lengths between 1 and 10.\nEach {time} consist of digits, and represent an integer between 0 and 1000.\nEach {amount} consist of digits, and represent an integer between 0 and 2000.", + "tags": [ + "Array", + "Hash Table", + "String", + "Sorting" + ], + "title-slug": "invalid-transactions" + }, + { + "leetcode-id": 1170, + "title": "Compare Strings by Frequency of the Smallest Character", + "difficulty": 2, + "description": "Let the function f(s) be the frequency of the lexicographically smallest character in a non-empty string s. For example, if s = \"dcce\" then f(s) = 2 because the lexicographically smallest character is 'c', which has a frequency of 2.\nYou are given an array of strings words and another array of query strings queries. For each query queries[i], count the number of words in words such that f(queries[i]) < f(W) for each W in words.\nReturn an integer array answer, where each answer[i] is the answer to the i^th query.", + "examples": [ + "Example 1:\nInput: queries = [\"cbd\"], words = [\"zaaaz\"]\nOutput: [1]\nExplanation: On the first query we have f(\"cbd\") = 1, f(\"zaaaz\") = 3 so f(\"cbd\") < f(\"zaaaz\").", + "Example 2:\nInput: queries = [\"bbb\",\"cc\"], words = [\"a\",\"aa\",\"aaa\",\"aaaa\"]\nOutput: [1,2]\nExplanation: On the first query only f(\"bbb\") < f(\"aaaa\"). On the second query both f(\"aaa\") and f(\"aaaa\") are both > f(\"cc\")." + ], + "constraints": "Constraints:\n\n1 <= queries.length <= 2000\n1 <= words.length <= 2000\n1 <= queries[i].length, words[i].length <= 10\nqueries[i][j], words[i][j] consist of lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Binary Search", + "Sorting" + ], + "title-slug": "compare-strings-by-frequency-of-the-smallest-character" + }, + { + "leetcode-id": 1171, + "title": "Remove Zero Sum Consecutive Nodes from Linked List", + "difficulty": 2, + "description": "Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences.\nAfter doing so, return the head of the final linked list.\u00a0 You may return any such answer.\n\u00a0\n(Note that in the examples below, all sequences are serializations of ListNode objects.)", + "examples": [ + "Example 1:\nInput: head = [1,2,-3,3,1]\nOutput: [3,1]\nNote: The answer [1,2,1] would also be accepted.", + "Example 2:\nInput: head = [1,2,3,-3,4]\nOutput: [1,2,4]", + "Example 3:\nInput: head = [1,2,3,-3,-2]\nOutput: [1]" + ], + "constraints": "Constraints:\n\nThe given linked list will contain between 1 and 1000 nodes.\nEach node in the linked list has -1000 <= node.val <= 1000.", + "tags": [ + "Hash Table", + "Linked List" + ], + "title-slug": "remove-zero-sum-consecutive-nodes-from-linked-list" + }, + { + "leetcode-id": 1172, + "title": "Dinner Plate Stacks", + "difficulty": 3, + "description": "You have an infinite number of stacks arranged in a row and numbered (left to right) from 0, each of the stacks has the same maximum capacity.\nImplement the DinnerPlates class:\n\nDinnerPlates(int capacity) Initializes the object with the maximum capacity of the stacks capacity.\nvoid push(int val) Pushes the given integer val into the leftmost stack with a size less than capacity.\nint pop() Returns the value at the top of the rightmost non-empty stack and removes it from that stack, and returns -1 if all the stacks are empty.\nint popAtStack(int index) Returns the value at the top of the stack with the given index index and removes it from that stack or returns -1 if the stack with that given index is empty.", + "examples": [ + "Example 1:\nInput\n[\"DinnerPlates\", \"push\", \"push\", \"push\", \"push\", \"push\", \"popAtStack\", \"push\", \"push\", \"popAtStack\", \"popAtStack\", \"pop\", \"pop\", \"pop\", \"pop\", \"pop\"]\n[[2], [1], [2], [3], [4], [5], [0], [20], [21], [0], [2], [], [], [], [], []]\nOutput\n[null, null, null, null, null, null, 2, null, null, 20, 21, 5, 4, 3, 1, -1]\n\nExplanation: \nDinnerPlates D = DinnerPlates(2); // Initialize with capacity = 2\nD.push(1);\nD.push(2);\nD.push(3);\nD.push(4);\nD.push(5); // The stacks are now: 2 4\n 1 3 5\n \ufe48 \ufe48 \ufe48\nD.popAtStack(0); // Returns 2. The stacks are now: 4\n 1 3 5\n \ufe48 \ufe48 \ufe48\nD.push(20); // The stacks are now: 20 4\n 1 3 5\n \ufe48 \ufe48 \ufe48\nD.push(21); // The stacks are now: 20 4 21\n 1 3 5\n \ufe48 \ufe48 \ufe48\nD.popAtStack(0); // Returns 20. The stacks are now: 4 21\n 1 3 5\n \ufe48 \ufe48 \ufe48\nD.popAtStack(2); // Returns 21. The stacks are now: 4\n 1 3 5\n \ufe48 \ufe48 \ufe48 \nD.pop() // Returns 5. The stacks are now: 4\n 1 3 \n \ufe48 \ufe48 \nD.pop() // Returns 4. The stacks are now: 1 3 \n \ufe48 \ufe48 \nD.pop() // Returns 3. The stacks are now: 1 \n \ufe48 \nD.pop() // Returns 1. There are no stacks.\nD.pop() // Returns -1. There are still no stacks." + ], + "constraints": "Constraints:\n\n1 <= capacity <= 2 * 10^4\n1 <= val <= 2 * 10^4\n0 <= index <= 10^5\nAt most 2 * 10^5 calls will be made to push, pop, and popAtStack.", + "tags": [ + "Hash Table", + "Stack", + "Design", + "Heap (Priority Queue)" + ], + "title-slug": "dinner-plate-stacks" + }, + { + "leetcode-id": 1175, + "title": "Prime Arrangements", + "difficulty": 1, + "description": "Return the number of permutations of 1 to n so that prime numbers are at prime indices (1-indexed.)\n(Recall that an integer\u00a0is prime if and only if it is greater than 1, and cannot be written as a product of two positive integers\u00a0both smaller than it.)\nSince the answer may be large, return the answer modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 5\nOutput: 12\nExplanation: For example [1,2,5,4,3] is a valid permutation, but [5,2,3,4,1] is not because the prime number 5 is at index 1.", + "Example 2:\nInput: n = 100\nOutput: 682289015" + ], + "constraints": "Constraints:\n\n1 <= n <= 100", + "tags": [ + "Math" + ], + "title-slug": "prime-arrangements" + }, + { + "leetcode-id": 1177, + "title": "Can Make Palindrome from Substring", + "difficulty": 2, + "description": "You are given a string s and array queries where queries[i] = [lefti, righti, ki]. We may rearrange the substring s[lefti...righti] for each query and then choose up to ki of them to replace with any lowercase English letter.\nIf the substring is possible to be a palindrome string after the operations above, the result of the query is true. Otherwise, the result is false.\nReturn a boolean array answer where answer[i] is the result of the i^th query queries[i].\nNote that each letter is counted individually for replacement, so if, for example s[lefti...righti] = \"aaa\", and ki = 2, we can only replace two of the letters. Also, note that no query modifies the initial string s.", + "examples": [ + "Example :\nInput: s = \"abcda\", queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]\nOutput: [true,false,false,true,true]\nExplanation:\nqueries[0]: substring = \"d\", is palidrome.\nqueries[1]: substring = \"bc\", is not palidrome.\nqueries[2]: substring = \"abcd\", is not palidrome after replacing only 1 character.\nqueries[3]: substring = \"abcd\", could be changed to \"abba\" which is palidrome. Also this can be changed to \"baab\" first rearrange it \"bacd\" then replace \"cd\" with \"ab\".\nqueries[4]: substring = \"abcda\", could be changed to \"abcba\" which is palidrome.", + "Example 2:\nInput: s = \"lyb\", queries = [[0,1,0],[2,2,1]]\nOutput: [false,true]" + ], + "constraints": "Constraints:\n\n1 <= s.length, queries.length <= 10^5\n0 <= lefti <= righti < s.length\n0 <= ki <= s.length\ns consists of lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Bit Manipulation", + "Prefix Sum" + ], + "title-slug": "can-make-palindrome-from-substring" + }, + { + "leetcode-id": 1178, + "title": "Number of Valid Words for Each Puzzle", + "difficulty": 3, + "description": "With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:\n\nword contains the first letter of puzzle.\nFor each letter in word, that letter is in puzzle.\n\t\nFor example, if the puzzle is \"abcdefg\", then valid words are \"faced\", \"cabbage\", and \"baggage\", while\ninvalid words are \"beefed\" (does not include 'a') and \"based\" (includes 's' which is not in the puzzle).\n\n\n\nReturn an array answer, where answer[i] is the number of words in the given word list words that is valid with respect to the puzzle puzzles[i].", + "examples": [ + "Example 1:\nInput: words = [\"aaaa\",\"asas\",\"able\",\"ability\",\"actt\",\"actor\",\"access\"], puzzles = [\"aboveyz\",\"abrodyz\",\"abslute\",\"absoryz\",\"actresz\",\"gaswxyz\"]\nOutput: [1,1,3,2,4,0]\nExplanation: \n1 valid word for \"aboveyz\" : \"aaaa\" \n1 valid word for \"abrodyz\" : \"aaaa\"\n3 valid words for \"abslute\" : \"aaaa\", \"asas\", \"able\"\n2 valid words for \"absoryz\" : \"aaaa\", \"asas\"\n4 valid words for \"actresz\" : \"aaaa\", \"asas\", \"actt\", \"access\"\nThere are no valid words for \"gaswxyz\" cause none of the words in the list contains letter 'g'.", + "Example 2:\nInput: words = [\"apple\",\"pleas\",\"please\"], puzzles = [\"aelwxyz\",\"aelpxyz\",\"aelpsxy\",\"saelpxy\",\"xaelpsy\"]\nOutput: [0,1,3,2,0]" + ], + "constraints": "Constraints:\n\n1 <= words.length <= 10^5\n4 <= words[i].length <= 50\n1 <= puzzles.length <= 10^4\npuzzles[i].length == 7\nwords[i] and puzzles[i] consist of lowercase English letters.\nEach puzzles[i] does not contain repeated characters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Bit Manipulation", + "Trie" + ], + "title-slug": "number-of-valid-words-for-each-puzzle" + }, + { + "leetcode-id": 1184, + "title": "Distance Between Bus Stops", + "difficulty": 1, + "description": "A bus\u00a0has n stops numbered from 0 to n - 1 that form\u00a0a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number\u00a0i and (i + 1) % n.\nThe bus goes along both directions\u00a0i.e. clockwise and counterclockwise.\nReturn the shortest distance between the given\u00a0start\u00a0and destination\u00a0stops.", + "examples": [ + "Example 1:\nInput: distance = [1,2,3,4], start = 0, destination = 1\r\nOutput: 1\r\nExplanation: Distance between 0 and 1 is 1 or 9, minimum is 1.", + "Example 2:\nInput: distance = [1,2,3,4], start = 0, destination = 2\r\nOutput: 3\r\nExplanation: Distance between 0 and 2 is 3 or 7, minimum is 3.", + "Example 3:\nInput: distance = [1,2,3,4], start = 0, destination = 3\r\nOutput: 4\r\nExplanation: Distance between 0 and 3 is 6 or 4, minimum is 4." + ], + "constraints": "Constraints:\n\n1 <= n\u00a0<= 10^4\ndistance.length == n\n0 <= start, destination < n\n0 <= distance[i] <= 10^4", + "tags": [ + "Array" + ], + "title-slug": "distance-between-bus-stops" + }, + { + "leetcode-id": 1185, + "title": "Day of the Week", + "difficulty": 1, + "description": "Given a date, return the corresponding day of the week for that date.\nThe input is given as three integers representing the day, month and year respectively.\nReturn the answer as one of the following values\u00a0{\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"}.", + "examples": [ + "Example 1:\nInput: day = 31, month = 8, year = 2019\nOutput: \"Saturday\"", + "Example 2:\nInput: day = 18, month = 7, year = 1999\nOutput: \"Sunday\"", + "Example 3:\nInput: day = 15, month = 8, year = 1993\nOutput: \"Sunday\"" + ], + "constraints": "Constraints:\n\nThe given dates are valid dates between the years 1971 and 2100.", + "tags": [ + "Math" + ], + "title-slug": "day-of-the-week" + }, + { + "leetcode-id": 1186, + "title": "Maximum Subarray Sum with One Deletion", + "difficulty": 2, + "description": "Given an array of integers, return the maximum sum for a non-empty\u00a0subarray (contiguous elements) with at most one element deletion.\u00a0In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the\u00a0sum of the remaining elements is maximum possible.\nNote that the subarray needs to be non-empty after deleting one element.", + "examples": [ + "Example 1:\nInput: arr = [1,-2,0,3]\nOutput: 4\nExplanation: Because we can choose [1, -2, 0, 3] and drop -2, thus the subarray [1, 0, 3] becomes the maximum value.", + "Example 2:\nInput: arr = [1,-2,-2,3]\nOutput: 3\nExplanation: We just choose [3] and it's the maximum sum.", + "Example 3:\nInput: arr = [-1,-1,-1,-1]\nOutput: -1\nExplanation:\u00a0The final subarray needs to be non-empty. You can't choose [-1] and delete -1 from it, then get an empty subarray to make the sum equals to 0." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^5\n-10^4 <= arr[i] <= 10^4", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "maximum-subarray-sum-with-one-deletion" + }, + { + "leetcode-id": 1187, + "title": "Make Array Strictly Increasing", + "difficulty": 3, + "description": "Given two integer arrays\u00a0arr1 and arr2, return the minimum number of operations (possibly zero) needed\u00a0to make arr1 strictly increasing.\nIn one operation, you can choose two indices\u00a00 <=\u00a0i < arr1.length\u00a0and\u00a00 <= j < arr2.length\u00a0and do the assignment\u00a0arr1[i] = arr2[j].\nIf there is no way to make\u00a0arr1\u00a0strictly increasing,\u00a0return\u00a0-1.", + "examples": [ + "Example 1:\nInput: arr1 = [1,5,3,6,7], arr2 = [1,3,2,4]\nOutput: 1\nExplanation: Replace 5 with 2, then arr1 = [1, 2, 3, 6, 7].", + "Example 2:\nInput: arr1 = [1,5,3,6,7], arr2 = [4,3,1]\nOutput: 2\nExplanation: Replace 5 with 3 and then replace 3 with 4. arr1 = [1, 3, 4, 6, 7].", + "Example 3:\nInput: arr1 = [1,5,3,6,7], arr2 = [1,6,3,3]\nOutput: -1\nExplanation: You can't make arr1 strictly increasing." + ], + "constraints": "Constraints:\n\n1 <= arr1.length, arr2.length <= 2000\n0 <= arr1[i], arr2[i] <= 10^9", + "tags": [ + "Array", + "Binary Search", + "Dynamic Programming", + "Sorting" + ], + "title-slug": "make-array-strictly-increasing" + }, + { + "leetcode-id": 1189, + "title": "Maximum Number of Balloons", + "difficulty": 1, + "description": "Given a string text, you want to use the characters of text to form as many instances of the word \"balloon\" as possible.\nYou can use each character in text at most once. Return the maximum number of instances that can be formed.", + "examples": [ + "Example 1:\nInput: text = \"nlaebolko\"\nOutput: 1", + "Example 2:\nInput: text = \"loonbalxballpoon\"\nOutput: 2", + "Example 3:\nInput: text = \"leetcode\"\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= text.length <= 10^4\ntext consists of lower case English letters only.", + "tags": [ + "Hash Table", + "String", + "Counting" + ], + "title-slug": "maximum-number-of-balloons" + }, + { + "leetcode-id": 1190, + "title": "Reverse Substrings Between Each Pair of Parentheses", + "difficulty": 2, + "description": "You are given a string s that consists of lower case English letters and brackets.\nReverse the strings in each pair of matching parentheses, starting from the innermost one.\nYour result should not contain any brackets.", + "examples": [ + "Example 1:\nInput: s = \"(abcd)\"\nOutput: \"dcba\"", + "Example 2:\nInput: s = \"(u(love)i)\"\nOutput: \"iloveu\"\nExplanation: The substring \"love\" is reversed first, then the whole string is reversed.", + "Example 3:\nInput: s = \"(ed(et(oc))el)\"\nOutput: \"leetcode\"\nExplanation: First, we reverse the substring \"oc\", then \"etco\", and finally, the whole string." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 2000\ns only contains lower case English characters and parentheses.\nIt is guaranteed that all parentheses are balanced.", + "tags": [ + "String", + "Stack" + ], + "title-slug": "reverse-substrings-between-each-pair-of-parentheses" + }, + { + "leetcode-id": 1191, + "title": "K-Concatenation Maximum Sum", + "difficulty": 2, + "description": "Given an integer array arr and an integer k, modify the array by repeating it k times.\nFor example, if arr = [1, 2] and k = 3 then the modified array will be [1, 2, 1, 2, 1, 2].\nReturn the maximum sub-array sum in the modified array. Note that the length of the sub-array can be 0 and its sum in that case is 0.\nAs the answer can be very large, return the answer modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: arr = [1,2], k = 3\nOutput: 9", + "Example 2:\nInput: arr = [1,-2,1], k = 5\nOutput: 2", + "Example 3:\nInput: arr = [-1,-2], k = 7\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^5\n1 <= k <= 10^5\n-10^4 <= arr[i] <= 10^4", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "k-concatenation-maximum-sum" + }, + { + "leetcode-id": 1192, + "title": "Critical Connections in a Network", + "difficulty": 3, + "description": "There are n servers numbered from 0 to n - 1 connected by undirected server-to-server connections forming a network where connections[i] = [ai, bi] represents a connection between servers ai and bi. Any server can reach other servers directly or indirectly through the network.\nA critical connection is a connection that, if removed, will make some servers unable to reach some other server.\nReturn all critical connections in the network in any order.", + "examples": [ + "Example 1:\nInput: n = 4, connections = [[0,1],[1,2],[2,0],[1,3]]\nOutput: [[1,3]]\nExplanation: [[3,1]] is also accepted.", + "Example 2:\nInput: n = 2, connections = [[0,1]]\nOutput: [[0,1]]" + ], + "constraints": "Constraints:\n\n2 <= n <= 10^5\nn - 1 <= connections.length <= 10^5\n0 <= ai, bi <= n - 1\nai != bi\nThere are no repeated connections.", + "tags": [ + "Depth-First Search", + "Graph", + "Biconnected Component" + ], + "title-slug": "critical-connections-in-a-network" + }, + { + "leetcode-id": 1200, + "title": "Minimum Absolute Difference", + "difficulty": 1, + "description": "Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements.\nReturn a list of pairs in ascending order(with respect to pairs), each pair [a, b] follows\n\na, b are from arr\na < b\nb - a equals to the minimum absolute difference of any two elements in arr", + "examples": [ + "Example 1:\nInput: arr = [4,2,1,3]\nOutput: [[1,2],[2,3],[3,4]]\nExplanation: The minimum absolute difference is 1. List all pairs with difference equal to 1 in ascending order.", + "Example 2:\nInput: arr = [1,3,6,10,15]\nOutput: [[1,3]]", + "Example 3:\nInput: arr = [3,8,-10,23,19,-4,-14,27]\nOutput: [[-14,-10],[19,23],[23,27]]" + ], + "constraints": "Constraints:\n\n2 <= arr.length <= 10^5\n-10^6 <= arr[i] <= 10^6", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "minimum-absolute-difference" + }, + { + "leetcode-id": 1201, + "title": "Ugly Number III", + "difficulty": 2, + "description": "An ugly number is a positive integer that is divisible by a, b, or c.\nGiven four integers n, a, b, and c, return the n^th ugly number.", + "examples": [ + "Example 1:\nInput: n = 3, a = 2, b = 3, c = 5\nOutput: 4\nExplanation: The ugly numbers are 2, 3, 4, 5, 6, 8, 9, 10... The 3^rd is 4.", + "Example 2:\nInput: n = 4, a = 2, b = 3, c = 4\nOutput: 6\nExplanation: The ugly numbers are 2, 3, 4, 6, 8, 9, 10, 12... The 4^th is 6.", + "Example 3:\nInput: n = 5, a = 2, b = 11, c = 13\nOutput: 10\nExplanation: The ugly numbers are 2, 4, 6, 8, 10, 11, 12, 13... The 5^th is 10." + ], + "constraints": "Constraints:\n\n1 <= n, a, b, c <= 10^9\n1 <= a * b * c <= 10^18\nIt is guaranteed that the result will be in range [1, 2 * 10^9].", + "tags": [ + "Math", + "Binary Search", + "Number Theory" + ], + "title-slug": "ugly-number-iii" + }, + { + "leetcode-id": 1202, + "title": "Smallest String With Swaps", + "difficulty": 2, + "description": "You are given a string s, and an array of pairs of indices in the string\u00a0pairs\u00a0where\u00a0pairs[i] =\u00a0[a, b]\u00a0indicates 2 indices(0-indexed) of the string.\nYou can\u00a0swap the characters at any pair of indices in the given\u00a0pairs\u00a0any number of times.\nReturn the\u00a0lexicographically smallest string that s\u00a0can be changed to after using the swaps.", + "examples": [ + "Example 1:\nInput: s = \"dcab\", pairs = [[0,3],[1,2]]\nOutput: \"bacd\"\nExplaination: \nSwap s[0] and s[3], s = \"bcad\"\nSwap s[1] and s[2], s = \"bacd\"", + "Example 2:\nInput: s = \"dcab\", pairs = [[0,3],[1,2],[0,2]]\nOutput: \"abcd\"\nExplaination: \nSwap s[0] and s[3], s = \"bcad\"\nSwap s[0] and s[2], s = \"acbd\"\nSwap s[1] and s[2], s = \"abcd\"", + "Example 3:\nInput: s = \"cba\", pairs = [[0,1],[1,2]]\nOutput: \"abc\"\nExplaination: \nSwap s[0] and s[1], s = \"bca\"\nSwap s[1] and s[2], s = \"bac\"\nSwap s[0] and s[1], s = \"abc\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\n0 <= pairs.length <= 10^5\n0 <= pairs[i][0], pairs[i][1] <\u00a0s.length\ns\u00a0only contains lower case English letters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Sorting" + ], + "title-slug": "smallest-string-with-swaps" + }, + { + "leetcode-id": 1203, + "title": "Sort Items by Groups Respecting Dependencies", + "difficulty": 3, + "description": "There are\u00a0n\u00a0items each\u00a0belonging to zero or one of\u00a0m\u00a0groups where group[i]\u00a0is the group that the i-th item belongs to and it's equal to -1\u00a0if the i-th item belongs to no group. The items and the groups are zero indexed. A group can have no item belonging to it.\nReturn a sorted list of the items such that:\n\nThe items that belong to the same group are next to each other in the sorted list.\nThere are some\u00a0relations\u00a0between these items where\u00a0beforeItems[i]\u00a0is a list containing all the items that should come before the\u00a0i-th item in the sorted array (to the left of the\u00a0i-th item).\n\nReturn any solution if there is more than one solution and return an empty list\u00a0if there is no solution.", + "examples": [ + "Example 1:\nInput: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3,6],[],[],[]]\nOutput: [6,3,4,1,5,2,0,7]", + "Example 2:\nInput: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]]\nOutput: []\nExplanation:\u00a0This is the same as example 1 except that 4 needs to be before 6 in the sorted list." + ], + "constraints": "Constraints:\n\n1 <= m <= n <= 3 * 10^4\ngroup.length == beforeItems.length == n\n-1 <= group[i] <= m - 1\n0 <= beforeItems[i].length <= n - 1\n0 <= beforeItems[i][j] <= n - 1\ni != beforeItems[i][j]\nbeforeItems[i]\u00a0does not contain\u00a0duplicates elements.", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Graph", + "Topological Sort" + ], + "title-slug": "sort-items-by-groups-respecting-dependencies" + }, + { + "leetcode-id": 1206, + "title": "Design Skiplist", + "difficulty": 3, + "description": "Design a Skiplist without using any built-in libraries.\nA skiplist is a data structure that takes O(log(n)) time to add, erase and search. Comparing with treap and red-black tree which has the same function and performance, the code length of Skiplist can be comparatively short and the idea behind Skiplists is just simple linked lists.\nFor example, we have a Skiplist containing [30,40,50,60,70,90] and we want to add 80 and 45 into it. The Skiplist works this way:\n\nArtyom Kalinin [CC BY-SA 3.0], via Wikimedia Commons\nYou can see there are many layers in the Skiplist. Each layer is a sorted linked list. With the help of the top layers, add, erase and search can be faster than O(n). It can be proven that the average time complexity for each operation is O(log(n)) and space complexity is O(n).\nSee more about Skiplist: https://en.wikipedia.org/wiki/Skip_list\nImplement the Skiplist class:\n\nSkiplist() Initializes the object of the skiplist.\nbool search(int target) Returns true if the integer target exists in the Skiplist or false otherwise.\nvoid add(int num) Inserts the value num into the SkipList.\nbool erase(int num) Removes the value num from the Skiplist and returns true. If num does not exist in the Skiplist, do nothing and return false. If there exist multiple num values, removing any one of them is fine.\n\nNote that duplicates may exist in the Skiplist, your code needs to handle this situation.", + "examples": [ + "Example 1:\nInput\n[\"Skiplist\", \"add\", \"add\", \"add\", \"search\", \"add\", \"search\", \"erase\", \"erase\", \"search\"]\n[[], [1], [2], [3], [0], [4], [1], [0], [1], [1]]\nOutput\n[null, null, null, null, false, null, true, false, true, false]\n\nExplanation\nSkiplist skiplist = new Skiplist();\nskiplist.add(1);\nskiplist.add(2);\nskiplist.add(3);\nskiplist.search(0); // return False\nskiplist.add(4);\nskiplist.search(1); // return True\nskiplist.erase(0); // return False, 0 is not in skiplist.\nskiplist.erase(1); // return True\nskiplist.search(1); // return False, 1 has already been erased." + ], + "constraints": "Constraints:\n\n0 <= num, target <= 2 * 10^4\nAt most 5 * 10^4 calls will be made to search, add, and erase.", + "tags": [ + "Linked List", + "Design" + ], + "title-slug": "design-skiplist" + }, + { + "leetcode-id": 1207, + "title": "Unique Number of Occurrences", + "difficulty": 1, + "description": "Given an array of integers arr, return true if the number of occurrences of each value in the array is unique or false otherwise.", + "examples": [ + "Example 1:\nInput: arr = [1,2,2,1,1,3]\nOutput: true\nExplanation:\u00a0The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.", + "Example 2:\nInput: arr = [1,2]\nOutput: false", + "Example 3:\nInput: arr = [-3,0,1,-3,1,1,1,-3,10,0]\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 1000\n-1000 <= arr[i] <= 1000", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "unique-number-of-occurrences" + }, + { + "leetcode-id": 1208, + "title": "Get Equal Substrings Within Budget", + "difficulty": 2, + "description": "You are given two strings s and t of the same length and an integer maxCost.\nYou want to change s to t. Changing the i^th character of s to i^th character of t costs |s[i] - t[i]| (i.e., the absolute difference between the ASCII values of the characters).\nReturn the maximum length of a substring of s that can be changed to be the same as the corresponding substring of t with a cost less than or equal to maxCost. If there is no substring from s that can be changed to its corresponding substring from t, return 0.", + "examples": [ + "Example 1:\nInput: s = \"abcd\", t = \"bcdf\", maxCost = 3\nOutput: 3\nExplanation: \"abc\" of s can change to \"bcd\".\nThat costs 3, so the maximum length is 3.", + "Example 2:\nInput: s = \"abcd\", t = \"cdef\", maxCost = 3\nOutput: 1\nExplanation: Each character in s costs 2 to change to character in t, so the maximum length is 1.", + "Example 3:\nInput: s = \"abcd\", t = \"acde\", maxCost = 0\nOutput: 1\nExplanation: You cannot make any change, so the maximum length is 1." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\nt.length == s.length\n0 <= maxCost <= 10^6\ns and t consist of only lowercase English letters.", + "tags": [ + "String", + "Binary Search", + "Sliding Window", + "Prefix Sum" + ], + "title-slug": "get-equal-substrings-within-budget" + }, + { + "leetcode-id": 1209, + "title": "Remove All Adjacent Duplicates in String II", + "difficulty": 2, + "description": "You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate together.\nWe repeatedly make k duplicate removals on s until we no longer can.\nReturn the final string after all such duplicate removals have been made. It is guaranteed that the answer is unique.", + "examples": [ + "Example 1:\nInput: s = \"abcd\", k = 2\nOutput: \"abcd\"\nExplanation: There's nothing to delete.", + "Example 2:\nInput: s = \"deeedbbcccbdaa\", k = 3\nOutput: \"aa\"\nExplanation: \nFirst delete \"eee\" and \"ccc\", get \"ddbbbdaa\"\nThen delete \"bbb\", get \"dddaa\"\nFinally delete \"ddd\", get \"aa\"", + "Example 3:\nInput: s = \"pbbcggttciiippooaais\", k = 2\nOutput: \"ps\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\n2 <= k <= 10^4\ns only contains lowercase English letters.", + "tags": [ + "String", + "Stack" + ], + "title-slug": "remove-all-adjacent-duplicates-in-string-ii" + }, + { + "leetcode-id": 1210, + "title": "Minimum Moves to Reach Target with Rotations", + "difficulty": 3, + "description": "In an\u00a0n*n\u00a0grid, there is a snake that spans 2 cells and starts moving from the top left corner at (0, 0) and (0, 1). The grid has empty cells represented by zeros and blocked cells represented by ones. The snake wants to reach the lower right corner at\u00a0(n-1, n-2)\u00a0and\u00a0(n-1, n-1).\nIn one move the snake can:\n\nMove one cell to the right\u00a0if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is.\nMove down one cell\u00a0if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is.\nRotate clockwise if it's in a horizontal position and the two cells under it are both empty. In that case the snake moves from\u00a0(r, c)\u00a0and\u00a0(r, c+1)\u00a0to\u00a0(r, c)\u00a0and\u00a0(r+1, c).\n\nRotate counterclockwise\u00a0if it's in a vertical position and the two cells to its right are both empty. In that case the snake moves from\u00a0(r, c)\u00a0and\u00a0(r+1, c)\u00a0to\u00a0(r, c)\u00a0and\u00a0(r, c+1).\n\n\nReturn the minimum number of moves to reach the target.\nIf there is no way to reach the target, return\u00a0-1.", + "examples": [ + "Example 1:\nInput: grid = [[0,0,0,0,0,1],\n [1,1,0,0,1,0],\n\u00a0 [0,0,0,0,1,1],\n\u00a0 [0,0,1,0,1,0],\n\u00a0 [0,1,1,0,0,0],\n\u00a0 [0,1,1,0,0,0]]\nOutput: 11\nExplanation:\nOne possible solution is [right, right, rotate clockwise, right, down, down, down, down, rotate counterclockwise, right, down].", + "Example 2:\nInput: grid = [[0,0,1,1,1,1],\n\u00a0 [0,0,0,0,1,1],\n\u00a0 [1,1,0,0,0,1],\n\u00a0 [1,1,1,0,0,1],\n\u00a0 [1,1,1,0,0,1],\n\u00a0 [1,1,1,0,0,0]]\nOutput: 9" + ], + "constraints": "Constraints:\n\n2 <= n <= 100\n0 <= grid[i][j] <= 1\nIt is guaranteed that the snake starts at empty cells.", + "tags": [ + "Array", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "minimum-moves-to-reach-target-with-rotations" + }, + { + "leetcode-id": 1217, + "title": "Minimum Cost to Move Chips to The Same Position", + "difficulty": 1, + "description": "We have n chips, where the position of the i^th chip is position[i].\nWe need to move all the chips to the same position. In one step, we can change the position of the i^th chip from position[i] to:\n\nposition[i] + 2 or position[i] - 2 with cost = 0.\nposition[i] + 1 or position[i] - 1 with cost = 1.\n\nReturn the minimum cost needed to move all the chips to the same position.", + "examples": [ + "Example 1:\nInput: position = [1,2,3]\nOutput: 1\nExplanation: First step: Move the chip at position 3 to position 1 with cost = 0.\nSecond step: Move the chip at position 2 to position 1 with cost = 1.\nTotal cost is 1.", + "Example 2:\nInput: position = [2,2,2,3,3]\nOutput: 2\nExplanation: We can move the two chips at position 3 to position 2. Each move has cost = 1. The total cost = 2.", + "Example 3:\nInput: position = [1,1000000000]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= position.length <= 100\n1 <= position[i] <= 10^9", + "tags": [ + "Array", + "Math", + "Greedy" + ], + "title-slug": "minimum-cost-to-move-chips-to-the-same-position" + }, + { + "leetcode-id": 1218, + "title": "Longest Arithmetic Subsequence of Given Difference", + "difficulty": 2, + "description": "Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals difference.\nA subsequence is a sequence that can be derived from arr by deleting some or no elements without changing the order of the remaining elements.", + "examples": [ + "Example 1:\nInput: arr = [1,2,3,4], difference = 1\nOutput: 4\nExplanation: The longest arithmetic subsequence is [1,2,3,4].", + "Example 2:\nInput: arr = [1,3,5,7], difference = 1\nOutput: 1\nExplanation: The longest arithmetic subsequence is any single element.", + "Example 3:\nInput: arr = [1,5,7,8,5,3,4,2,1], difference = -2\nOutput: 4\nExplanation: The longest arithmetic subsequence is [7,5,3,1]." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^5\n-10^4 <= arr[i], difference <= 10^4", + "tags": [ + "Array", + "Hash Table", + "Dynamic Programming" + ], + "title-slug": "longest-arithmetic-subsequence-of-given-difference" + }, + { + "leetcode-id": 1219, + "title": "Path with Maximum Gold", + "difficulty": 2, + "description": "In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.\nReturn the maximum amount of gold you can collect under the conditions:\n\nEvery time you are located in a cell you will collect all the gold in that cell.\nFrom your position, you can walk one step to the left, right, up, or down.\nYou can't visit the same cell more than once.\nNever visit a cell with 0 gold.\nYou can start and stop collecting gold from any position in the grid that has some gold.", + "examples": [ + "Example 1:\nInput: grid = [[0,6,0],[5,8,7],[0,9,0]]\nOutput: 24\nExplanation:\n[[0,6,0],\n [5,8,7],\n [0,9,0]]\nPath to get the maximum gold, 9 -> 8 -> 7.", + "Example 2:\nInput: grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]\nOutput: 28\nExplanation:\n[[1,0,7],\n [2,0,6],\n [3,4,5],\n [0,3,0],\n [9,0,20]]\nPath to get the maximum gold, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 15\n0 <= grid[i][j] <= 100\nThere are at most 25 cells containing gold.", + "tags": [ + "Array", + "Backtracking", + "Matrix" + ], + "title-slug": "path-with-maximum-gold" + }, + { + "leetcode-id": 1220, + "title": "Count Vowels Permutation", + "difficulty": 3, + "description": "Given an integer n, your task is to count how many strings of length n can be formed under the following rules:\n\nEach character is a lower case vowel\u00a0('a', 'e', 'i', 'o', 'u')\nEach vowel\u00a0'a' may only be followed by an 'e'.\nEach vowel\u00a0'e' may only be followed by an 'a'\u00a0or an 'i'.\nEach vowel\u00a0'i' may not be followed by another 'i'.\nEach vowel\u00a0'o' may only be followed by an 'i' or a\u00a0'u'.\nEach vowel\u00a0'u' may only be followed by an 'a'.\n\nSince the answer\u00a0may be too large,\u00a0return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: 5\nExplanation: All possible strings are: \"a\", \"e\", \"i\" , \"o\" and \"u\".", + "Example 2:\nInput: n = 2\nOutput: 10\nExplanation: All possible strings are: \"ae\", \"ea\", \"ei\", \"ia\", \"ie\", \"io\", \"iu\", \"oi\", \"ou\" and \"ua\".", + "Example 3:\nInput: n = 5\nOutput: 68" + ], + "constraints": "Constraints:\n\n1 <= n <= 2 * 10^4", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "count-vowels-permutation" + }, + { + "leetcode-id": 1221, + "title": "Split a String in Balanced Strings", + "difficulty": 1, + "description": "Balanced strings are those that have an equal quantity of 'L' and 'R' characters.\nGiven a balanced string s, split it into some number of substrings such that:\n\nEach substring is balanced.\n\nReturn the maximum number of balanced strings you can obtain.", + "examples": [ + "Example 1:\nInput: s = \"RLRRLLRLRL\"\nOutput: 4\nExplanation: s can be split into \"RL\", \"RRLL\", \"RL\", \"RL\", each substring contains same number of 'L' and 'R'.", + "Example 2:\nInput: s = \"RLRRRLLRLL\"\nOutput: 2\nExplanation: s can be split into \"RL\", \"RRRLLRLL\", each substring contains same number of 'L' and 'R'.\nNote that s cannot be split into \"RL\", \"RR\", \"RL\", \"LR\", \"LL\", because the 2^nd and 5^th substrings are not balanced.", + "Example 3:\nInput: s = \"LLLLRRRR\"\nOutput: 1\nExplanation: s can be split into \"LLLLRRRR\"." + ], + "constraints": "Constraints:\n\n2 <= s.length <= 1000\ns[i] is either 'L' or 'R'.\ns is a balanced string.", + "tags": [ + "String", + "Greedy", + "Counting" + ], + "title-slug": "split-a-string-in-balanced-strings" + }, + { + "leetcode-id": 1222, + "title": "Queens That Can Attack the King", + "difficulty": 2, + "description": "On a 0-indexed 8 x 8 chessboard, there can be multiple black queens ad one white king.\nYou are given a 2D integer array queens where queens[i] = [xQueeni, yQueeni] represents the position of the i^th black queen on the chessboard. You are also given an integer array king of length 2 where king = [xKing, yKing] represents the position of the white king.\nReturn the coordinates of the black queens that can directly attack the king. You may return the answer in any order.", + "examples": [ + "Example 1:\nInput: queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0]\nOutput: [[0,1],[1,0],[3,3]]\nExplanation: The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes).", + "Example 2:\nInput: queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3]\nOutput: [[2,2],[3,4],[4,4]]\nExplanation: The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes)." + ], + "constraints": "Constraints:\n\n1 <= queens.length < 64\nqueens[i].length == king.length == 2\n0 <= xQueeni, yQueeni, xKing, yKing < 8\nAll the given positions are unique.", + "tags": [ + "Array", + "Matrix", + "Simulation" + ], + "title-slug": "queens-that-can-attack-the-king" + }, + { + "leetcode-id": 1223, + "title": "Dice Roll Simulation", + "difficulty": 3, + "description": "A die simulator generates a random number from 1 to 6 for each roll. You introduced a constraint to the generator such that it cannot roll the number i more than rollMax[i] (1-indexed) consecutive times.\nGiven an array of integers rollMax and an integer n, return the number of distinct sequences that can be obtained with exact n rolls. Since the answer may be too large, return it modulo 10^9 + 7.\nTwo sequences are considered different if at least one element differs from each other.", + "examples": [ + "Example 1:\nInput: n = 2, rollMax = [1,1,2,2,2,3]\nOutput: 34\nExplanation: There will be 2 rolls of die, if there are no constraints on the die, there are 6 * 6 = 36 possible combinations. In this case, looking at rollMax array, the numbers 1 and 2 appear at most once consecutively, therefore sequences (1,1) and (2,2) cannot occur, so the final answer is 36-2 = 34.", + "Example 2:\nInput: n = 2, rollMax = [1,1,1,1,1,1]\nOutput: 30", + "Example 3:\nInput: n = 3, rollMax = [1,1,1,2,2,3]\nOutput: 181" + ], + "constraints": "Constraints:\n\n1 <= n <= 5000\nrollMax.length == 6\n1 <= rollMax[i] <= 15", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "dice-roll-simulation" + }, + { + "leetcode-id": 1224, + "title": "Maximum Equal Frequency", + "difficulty": 3, + "description": "Given an array nums of positive integers, return the longest possible length of an array prefix of nums, such that it is possible to remove exactly one element from this prefix so that every number that has appeared in it will have the same number of occurrences.\nIf after removing one element there are no remaining elements, it's still considered that every appeared number has the same number of ocurrences (0).", + "examples": [ + "Example 1:\nInput: nums = [2,2,1,1,5,3,3,5]\nOutput: 7\nExplanation: For the subarray [2,2,1,1,5,3,3] of length 7, if we remove nums[4] = 5, we will get [2,2,1,1,3,3], so that each number will appear exactly twice.", + "Example 2:\nInput: nums = [1,1,1,2,2,2,3,3,3,4,4,4,5]\nOutput: 13" + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 10^5\n1 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "maximum-equal-frequency" + }, + { + "leetcode-id": 1227, + "title": "Airplane Seat Assignment Probability", + "difficulty": 2, + "description": "n passengers board an airplane with exactly n seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of the passengers will:\n\nTake their own seat if it is still available, and\nPick other seats randomly when they find their seat occupied\n\nReturn the probability that the n^th person gets his own seat.", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: 1.00000\nExplanation: The first person can only get the first seat.", + "Example 2:\nInput: n = 2\nOutput: 0.50000\nExplanation: The second person has a probability of 0.5 to get the second seat (when first person gets the first seat)." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5", + "tags": [ + "Math", + "Dynamic Programming", + "Brainteaser", + "Probability and Statistics" + ], + "title-slug": "airplane-seat-assignment-probability" + }, + { + "leetcode-id": 1232, + "title": "Check If It Is a Straight Line", + "difficulty": 1, + "description": "You are given an array\u00a0coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points\u00a0make a straight line in the XY plane.", + "examples": [ + "Example 1:\nInput: coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]\nOutput: true", + "Example 2:\nInput: coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]\nOutput: false" + ], + "constraints": "Constraints:\n\n2 <=\u00a0coordinates.length <= 1000\ncoordinates[i].length == 2\n-10^4 <=\u00a0coordinates[i][0],\u00a0coordinates[i][1] <= 10^4\ncoordinates\u00a0contains no duplicate point.", + "tags": [ + "Array", + "Math", + "Geometry" + ], + "title-slug": "check-if-it-is-a-straight-line" + }, + { + "leetcode-id": 1233, + "title": "Remove Sub-Folders from the Filesystem", + "difficulty": 2, + "description": "Given a list of folders folder, return the folders after removing all sub-folders in those folders. You may return the answer in any order.\nIf a folder[i] is located within another folder[j], it is called a sub-folder of it.\nThe format of a path is one or more concatenated strings of the form: '/' followed by one or more lowercase English letters.\n\nFor example, \"/leetcode\" and \"/leetcode/problems\" are valid paths while an empty string and \"/\" are not.", + "examples": [ + "Example 1:\nInput: folder = [\"/a\",\"/a/b\",\"/c/d\",\"/c/d/e\",\"/c/f\"]\nOutput: [\"/a\",\"/c/d\",\"/c/f\"]\nExplanation: Folders \"/a/b\" is a subfolder of \"/a\" and \"/c/d/e\" is inside of folder \"/c/d\" in our filesystem.", + "Example 2:\nInput: folder = [\"/a\",\"/a/b/c\",\"/a/b/d\"]\nOutput: [\"/a\"]\nExplanation: Folders \"/a/b/c\" and \"/a/b/d\" will be removed because they are subfolders of \"/a\".", + "Example 3:\nInput: folder = [\"/a/b/c\",\"/a/b/ca\",\"/a/b/d\"]\nOutput: [\"/a/b/c\",\"/a/b/ca\",\"/a/b/d\"]" + ], + "constraints": "Constraints:\n\n1 <= folder.length <= 4 * 10^4\n2 <= folder[i].length <= 100\nfolder[i] contains only lowercase letters and '/'.\nfolder[i] always starts with the character '/'.\nEach folder name is unique.", + "tags": [ + "Array", + "String", + "Depth-First Search", + "Trie" + ], + "title-slug": "remove-sub-folders-from-the-filesystem" + }, + { + "leetcode-id": 1234, + "title": "Replace the Substring for Balanced String", + "difficulty": 2, + "description": "You are given a string s of length n containing only four kinds of characters: 'Q', 'W', 'E', and 'R'.\nA string is said to be balanced if each of its characters appears n / 4 times where n is the length of the string.\nReturn the minimum length of the substring that can be replaced with any other string of the same length to make s balanced. If s is already balanced, return 0.", + "examples": [ + "Example 1:\nInput: s = \"QWER\"\nOutput: 0\nExplanation: s is already balanced.", + "Example 2:\nInput: s = \"QQWE\"\nOutput: 1\nExplanation: We need to replace a 'Q' to 'R', so that \"RQWE\" (or \"QRWE\") is balanced.", + "Example 3:\nInput: s = \"QQQW\"\nOutput: 2\nExplanation: We can replace the first \"QQ\" to \"ER\"." + ], + "constraints": "Constraints:\n\nn == s.length\n4 <= n <= 10^5\nn is a multiple of 4.\ns contains only 'Q', 'W', 'E', and 'R'.", + "tags": [ + "String", + "Sliding Window" + ], + "title-slug": "replace-the-substring-for-balanced-string" + }, + { + "leetcode-id": 1235, + "title": "Maximum Profit in Job Scheduling", + "difficulty": 3, + "description": "We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i].\nYou're given the startTime, endTime and profit arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range.\nIf you choose a job that ends at time X you will be able to start another job that starts at time X.", + "examples": [ + "Example 1:\nInput: startTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70]\nOutput: 120\nExplanation: The subset chosen is the first and fourth job. \nTime range [1-3]+[3-6] , we get profit of 120 = 50 + 70.", + "Example 2:\nInput: startTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60]\nOutput: 150\nExplanation: The subset chosen is the first, fourth and fifth job. \nProfit obtained 150 = 20 + 70 + 60.", + "Example 3:\nInput: startTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4]\nOutput: 6" + ], + "constraints": "Constraints:\n\n1 <= startTime.length == endTime.length == profit.length <= 5 * 10^4\n1 <= startTime[i] < endTime[i] <= 10^9\n1 <= profit[i] <= 10^4", + "tags": [ + "Array", + "Binary Search", + "Dynamic Programming", + "Sorting" + ], + "title-slug": "maximum-profit-in-job-scheduling" + }, + { + "leetcode-id": 1237, + "title": "Find Positive Integer Solution for a Given Equation", + "difficulty": 2, + "description": "Given a callable function f(x, y) with a hidden formula and a value z, reverse engineer the formula and return all positive integer pairs x and y where f(x,y) == z. You may return the pairs in any order.\nWhile the exact formula is hidden, the function is monotonically increasing, i.e.:\n\nf(x, y) < f(x + 1, y)\nf(x, y) < f(x, y + 1)\n\nThe function interface is defined like this:\n\ninterface CustomFunction {\npublic:\n // Returns some positive integer f(x, y) for two positive integers x and y based on a formula.\n int f(int x, int y);\n};\n\nWe will judge your solution as follows:\n\nThe judge has a list of 9 hidden implementations of CustomFunction, along with a way to generate an answer key of all valid pairs for a specific z.\nThe judge will receive two inputs: a function_id (to determine which implementation to test your code with), and the target z.\nThe judge will call your findSolution and compare your results with the answer key.\nIf your results match the answer key, your solution will be Accepted.", + "examples": [ + "Example 1:\nInput: function_id = 1, z = 5\nOutput: [[1,4],[2,3],[3,2],[4,1]]\nExplanation: The hidden formula for function_id = 1 is f(x, y) = x + y.\nThe following positive integer values of x and y make f(x, y) equal to 5:\nx=1, y=4 -> f(1, 4) = 1 + 4 = 5.\nx=2, y=3 -> f(2, 3) = 2 + 3 = 5.\nx=3, y=2 -> f(3, 2) = 3 + 2 = 5.\nx=4, y=1 -> f(4, 1) = 4 + 1 = 5.", + "Example 2:\nInput: function_id = 2, z = 5\nOutput: [[1,5],[5,1]]\nExplanation: The hidden formula for function_id = 2 is f(x, y) = x * y.\nThe following positive integer values of x and y make f(x, y) equal to 5:\nx=1, y=5 -> f(1, 5) = 1 * 5 = 5.\nx=5, y=1 -> f(5, 1) = 5 * 1 = 5." + ], + "constraints": "Constraints:\n\n1 <= function_id <= 9\n1 <= z <= 100\nIt is guaranteed that the solutions of f(x, y) == z will be in the range 1 <= x, y <= 1000.\nIt is also guaranteed that f(x, y) will fit in 32 bit signed integer if 1 <= x, y <= 1000.", + "tags": [ + "Math", + "Two Pointers", + "Binary Search", + "Interactive" + ], + "title-slug": "find-positive-integer-solution-for-a-given-equation" + }, + { + "leetcode-id": 1238, + "title": "Circular Permutation in Binary Representation", + "difficulty": 2, + "description": "Given 2 integers n and start. Your task is return any permutation p\u00a0of (0,1,2.....,2^n -1) such that :\n\np[0] = start\np[i] and p[i+1]\u00a0differ by only one bit in their binary representation.\np[0] and p[2^n -1]\u00a0must also differ by only one bit in their binary representation.", + "examples": [ + "Example 1:\nInput: n = 2, start = 3\r\nOutput: [3,2,0,1]\r\nExplanation: The binary representation of the permutation is (11,10,00,01). \r\nAll the adjacent element differ by one bit. Another valid permutation is [3,1,0,2]", + "Example 2:\nInput: n = 3, start = 2\r\nOutput: [2,6,7,5,4,0,1,3]\r\nExplanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011)." + ], + "constraints": "Constraints:\n\n1 <= n <= 16\n0 <= start\u00a0<\u00a02 ^ n", + "tags": [ + "Math", + "Backtracking", + "Bit Manipulation" + ], + "title-slug": "circular-permutation-in-binary-representation" + }, + { + "leetcode-id": 1239, + "title": "Maximum Length of a Concatenated String with Unique Characters", + "difficulty": 2, + "description": "You are given an array of strings arr. A string s is formed by the concatenation of a subsequence of arr that has unique characters.\nReturn the maximum possible length of s.\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.", + "examples": [ + "Example 1:\nInput: arr = [\"un\",\"iq\",\"ue\"]\nOutput: 4\nExplanation: All the valid concatenations are:\n- \"\"\n- \"un\"\n- \"iq\"\n- \"ue\"\n- \"uniq\" (\"un\" + \"iq\")\n- \"ique\" (\"iq\" + \"ue\")\nMaximum length is 4.", + "Example 2:\nInput: arr = [\"cha\",\"r\",\"act\",\"ers\"]\nOutput: 6\nExplanation: Possible longest valid concatenations are \"chaers\" (\"cha\" + \"ers\") and \"acters\" (\"act\" + \"ers\").", + "Example 3:\nInput: arr = [\"abcdefghijklmnopqrstuvwxyz\"]\nOutput: 26\nExplanation: The only string in arr has all 26 characters." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 16\n1 <= arr[i].length <= 26\narr[i] contains only lowercase English letters.", + "tags": [ + "Array", + "String", + "Backtracking", + "Bit Manipulation" + ], + "title-slug": "maximum-length-of-a-concatenated-string-with-unique-characters" + }, + { + "leetcode-id": 1240, + "title": "Tiling a Rectangle with the Fewest Squares", + "difficulty": 3, + "description": "Given a rectangle of size n x m, return the minimum number of integer-sided squares that tile the rectangle.", + "examples": [ + "Example 1:\nInput: n = 2, m = 3\nOutput: 3\nExplanation: 3 squares are necessary to cover the rectangle.\n2 (squares of 1x1)\n1 (square of 2x2)", + "Example 2:\nInput: n = 5, m = 8\nOutput: 5", + "Example 3:\nInput: n = 11, m = 13\nOutput: 6" + ], + "constraints": "Constraints:\n\n1 <= n, m <= 13", + "tags": [ + "Backtracking" + ], + "title-slug": "tiling-a-rectangle-with-the-fewest-squares" + }, + { + "leetcode-id": 1247, + "title": "Minimum Swaps to Make Strings Equal", + "difficulty": 2, + "description": "You are given two strings s1 and s2 of equal length consisting of letters \"x\" and \"y\" only. Your task is to make these two strings equal to each other. You can swap any two characters that belong to different strings, which means: swap s1[i] and s2[j].\nReturn the minimum number of swaps required to make s1 and s2 equal, or return -1 if it is impossible to do so.", + "examples": [ + "Example 1:\nInput: s1 = \"xx\", s2 = \"yy\"\nOutput: 1\nExplanation: Swap s1[0] and s2[1], s1 = \"yx\", s2 = \"yx\".", + "Example 2:\nInput: s1 = \"xy\", s2 = \"yx\"\nOutput: 2\nExplanation: Swap s1[0] and s2[0], s1 = \"yy\", s2 = \"xx\".\nSwap s1[0] and s2[1], s1 = \"xy\", s2 = \"xy\".\nNote that you cannot swap s1[0] and s1[1] to make s1 equal to \"yx\", cause we can only swap chars in different strings.", + "Example 3:\nInput: s1 = \"xx\", s2 = \"xy\"\nOutput: -1" + ], + "constraints": "Constraints:\n\n1 <= s1.length, s2.length <= 1000\ns1.length == s2.length\ns1, s2 only contain 'x' or 'y'.", + "tags": [ + "Math", + "String", + "Greedy" + ], + "title-slug": "minimum-swaps-to-make-strings-equal" + }, + { + "leetcode-id": 1248, + "title": "Count Number of Nice Subarrays", + "difficulty": 2, + "description": "Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.\nReturn the number of nice sub-arrays.", + "examples": [ + "Example 1:\nInput: nums = [1,1,2,1,1], k = 3\r\nOutput: 2\r\nExplanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].", + "Example 2:\nInput: nums = [2,4,6], k = 1\r\nOutput: 0\r\nExplanation: There is no odd numbers in the array.", + "Example 3:\nInput: nums = [2,2,2,1,2,2,1,2,2,2], k = 2\r\nOutput: 16" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 50000\n1 <= nums[i] <= 10^5\n1 <= k <= nums.length", + "tags": [ + "Array", + "Hash Table", + "Math", + "Sliding Window" + ], + "title-slug": "count-number-of-nice-subarrays" + }, + { + "leetcode-id": 1249, + "title": "Minimum Remove to Make Valid Parentheses", + "difficulty": 2, + "description": "Given a string s of '(' , ')' and lowercase English characters.\nYour task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string.\nFormally, a parentheses string is valid if and only if:\n\nIt is the empty string, contains only lowercase characters, or\nIt can be written as AB (A concatenated with B), where A and B are valid strings, or\nIt can be written as (A), where A is a valid string.", + "examples": [ + "Example 1:\nInput: s = \"lee(t(c)o)de)\"\nOutput: \"lee(t(c)o)de\"\nExplanation: \"lee(t(co)de)\" , \"lee(t(c)ode)\" would also be accepted.", + "Example 2:\nInput: s = \"a)b(c)d\"\nOutput: \"ab(c)d\"", + "Example 3:\nInput: s = \"))((\"\nOutput: \"\"\nExplanation: An empty string is also valid." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns[i] is either'(' , ')', or lowercase English letter.", + "tags": [ + "String", + "Stack" + ], + "title-slug": "minimum-remove-to-make-valid-parentheses" + }, + { + "leetcode-id": 1250, + "title": "Check If It Is a Good Array", + "difficulty": 3, + "description": "Given an array nums of\u00a0positive integers. Your task is to select some subset of nums, multiply each element by an integer and add all these numbers.\u00a0The array is said to be\u00a0good\u00a0if you can obtain a sum of\u00a01\u00a0from the array by any possible subset and multiplicand.\nReturn\u00a0True\u00a0if the array is good\u00a0otherwise\u00a0return\u00a0False.", + "examples": [ + "Example 1:\nInput: nums = [12,5,7,23]\nOutput: true\nExplanation: Pick numbers 5 and 7.\n5*3 + 7*(-2) = 1", + "Example 2:\nInput: nums = [29,6,10]\nOutput: true\nExplanation: Pick numbers 29, 6 and 10.\n29*1 + 6*(-3) + 10*(-1) = 1", + "Example 3:\nInput: nums = [3,6]\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Math", + "Number Theory" + ], + "title-slug": "check-if-it-is-a-good-array" + }, + { + "leetcode-id": 1252, + "title": "Cells with Odd Values in a Matrix", + "difficulty": 1, + "description": "There is an m x n matrix that is initialized to all 0's. There is also a 2D array indices where each indices[i] = [ri, ci] represents a 0-indexed location to perform some increment operations on the matrix.\nFor each location indices[i], do both of the following:\n\nIncrement all the cells on row ri.\nIncrement all the cells on column ci.\n\nGiven m, n, and indices, return the number of odd-valued cells in the matrix after applying the increment to all locations in indices.", + "examples": [ + "Example 1:\nInput: m = 2, n = 3, indices = [[0,1],[1,1]]\nOutput: 6\nExplanation: Initial matrix = [[0,0,0],[0,0,0]].\nAfter applying first increment it becomes [[1,2,1],[0,1,0]].\nThe final matrix is [[1,3,1],[1,3,1]], which contains 6 odd numbers.", + "Example 2:\nInput: m = 2, n = 2, indices = [[1,1],[0,0]]\nOutput: 0\nExplanation: Final matrix = [[2,2],[2,2]]. There are no odd numbers in the final matrix." + ], + "constraints": "Constraints:\n\n1 <= m, n <= 50\n1 <= indices.length <= 100\n0 <= ri < m\n0 <= ci < n\n\n\u00a0\nFollow up: Could you solve this in O(n + m + indices.length) time with only O(n + m) extra space?", + "tags": [ + "Array", + "Math", + "Simulation" + ], + "title-slug": "cells-with-odd-values-in-a-matrix" + }, + { + "leetcode-id": 1253, + "title": "Reconstruct a 2-Row Binary Matrix", + "difficulty": 2, + "description": "Given the following details of a matrix with n columns and 2 rows :\n\nThe matrix is a binary matrix, which means each element in the matrix can be 0 or 1.\nThe sum of elements of the 0-th(upper) row is given as upper.\nThe sum of elements of the 1-st(lower) row is given as lower.\nThe sum of elements in the i-th column(0-indexed) is colsum[i], where colsum is given as an integer array with length n.\n\nYour task is to reconstruct the matrix with upper, lower and colsum.\nReturn it as a 2-D integer array.\nIf there are more than one valid solution, any of them will be accepted.\nIf no valid solution exists, return an empty 2-D array.", + "examples": [ + "Example 1:\nInput: upper = 2, lower = 1, colsum = [1,1,1]\nOutput: [[1,1,0],[0,0,1]]\nExplanation: [[1,0,1],[0,1,0]], and [[0,1,1],[1,0,0]] are also correct answers.", + "Example 2:\nInput: upper = 2, lower = 3, colsum = [2,2,1,1]\nOutput: []", + "Example 3:\nInput: upper = 5, lower = 5, colsum = [2,1,2,0,1,0,1,2,0,1]\nOutput: [[1,1,1,0,1,0,0,1,0,0],[1,0,1,0,0,0,1,1,0,1]]" + ], + "constraints": "Constraints:\n\n1 <= colsum.length <= 10^5\n0 <= upper, lower <= colsum.length\n0 <= colsum[i] <= 2", + "tags": [ + "Array", + "Greedy", + "Matrix" + ], + "title-slug": "reconstruct-a-2-row-binary-matrix" + }, + { + "leetcode-id": 1254, + "title": "Number of Closed Islands", + "difficulty": 2, + "description": "Given a 2D\u00a0grid consists of 0s (land)\u00a0and 1s (water).\u00a0 An island is a maximal 4-directionally connected group of 0s and a closed island\u00a0is an island totally\u00a0(all left, top, right, bottom) surrounded by 1s.\nReturn the number of closed islands.", + "examples": [ + "Example 1:\nInput: grid = [[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,1,0],[1,0,0,0,0,1,0,1],[1,1,1,1,1,1,1,0]]\nOutput: 2\nExplanation: \nIslands in gray are closed because they are completely surrounded by water (group of 1s).", + "Example 2:\nInput: grid = [[0,0,1,0,0],[0,1,0,1,0],[0,1,1,1,0]]\nOutput: 1", + "Example 3:\nInput: grid = [[1,1,1,1,1,1,1],\n\u00a0 [1,0,0,0,0,0,1],\n\u00a0 [1,0,1,1,1,0,1],\n\u00a0 [1,0,1,0,1,0,1],\n\u00a0 [1,0,1,1,1,0,1],\n\u00a0 [1,0,0,0,0,0,1],\n [1,1,1,1,1,1,1]]\nOutput: 2" + ], + "constraints": "Constraints:\n\n1 <= grid.length, grid[0].length <= 100\n0 <= grid[i][j] <=1", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Matrix" + ], + "title-slug": "number-of-closed-islands" + }, + { + "leetcode-id": 1255, + "title": "Maximum Score Words Formed by Letters", + "difficulty": 3, + "description": "Given a list of words, list of\u00a0 single\u00a0letters (might be repeating)\u00a0and score\u00a0of every character.\nReturn the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two\u00a0or more times).\nIt is not necessary to use all characters in letters and each letter can only be used once. Score of letters\u00a0'a', 'b', 'c', ... ,'z' is given by\u00a0score[0], score[1], ... , score[25] respectively.", + "examples": [ + "Example 1:\nInput: words = [\"dog\",\"cat\",\"dad\",\"good\"], letters = [\"a\",\"a\",\"c\",\"d\",\"d\",\"d\",\"g\",\"o\",\"o\"], score = [1,0,9,5,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0]\nOutput: 23\nExplanation:\nScore a=1, c=9, d=5, g=3, o=2\nGiven letters, we can form the words \"dad\" (5+1+5) and \"good\" (3+2+2+5) with a score of 23.\nWords \"dad\" and \"dog\" only get a score of 21.", + "Example 2:\nInput: words = [\"xxxz\",\"ax\",\"bx\",\"cx\"], letters = [\"z\",\"a\",\"b\",\"c\",\"x\",\"x\",\"x\"], score = [4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,10]\nOutput: 27\nExplanation:\nScore a=4, b=4, c=4, x=5, z=10\nGiven letters, we can form the words \"ax\" (4+5), \"bx\" (4+5) and \"cx\" (4+5) with a score of 27.\nWord \"xxxz\" only get a score of 25.", + "Example 3:\nInput: words = [\"leetcode\"], letters = [\"l\",\"e\",\"t\",\"c\",\"o\",\"d\"], score = [0,0,1,1,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0]\nOutput: 0\nExplanation:\nLetter \"e\" can only be used once." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 14\n1 <= words[i].length <= 15\n1 <= letters.length <= 100\nletters[i].length == 1\nscore.length ==\u00a026\n0 <= score[i] <= 10\nwords[i], letters[i]\u00a0contains only lower case English letters.", + "tags": [ + "Array", + "String", + "Dynamic Programming", + "Backtracking", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "maximum-score-words-formed-by-letters" + }, + { + "leetcode-id": 1260, + "title": "Shift 2D Grid", + "difficulty": 1, + "description": "Given a 2D grid of size m x n\u00a0and an integer k. You need to shift the grid\u00a0k times.\nIn one shift operation:\n\nElement at grid[i][j] moves to grid[i][j + 1].\nElement at grid[i][n - 1] moves to grid[i + 1][0].\nElement at grid[m\u00a0- 1][n - 1] moves to grid[0][0].\n\nReturn the 2D grid after applying shift operation k times.", + "examples": [ + "Example 1:\nInput: grid = [[1,2,3],[4,5,6],[7,8,9]], k = 1\nOutput: [[9,1,2],[3,4,5],[6,7,8]]", + "Example 2:\nInput: grid = [[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]], k = 4\nOutput: [[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]]", + "Example 3:\nInput: grid = [[1,2,3],[4,5,6],[7,8,9]], k = 9\nOutput: [[1,2,3],[4,5,6],[7,8,9]]" + ], + "constraints": "Constraints:\n\nm ==\u00a0grid.length\nn ==\u00a0grid[i].length\n1 <= m <= 50\n1 <= n <= 50\n-1000 <= grid[i][j] <= 1000\n0 <= k <= 100", + "tags": [ + "Array", + "Matrix", + "Simulation" + ], + "title-slug": "shift-2d-grid" + }, + { + "leetcode-id": 1261, + "title": "Find Elements in a Contaminated Binary Tree", + "difficulty": 2, + "description": "Given a binary tree with the following rules:\n\nroot.val == 0\nIf treeNode.val == x and treeNode.left != null, then treeNode.left.val == 2 * x + 1\nIf treeNode.val == x and treeNode.right != null, then treeNode.right.val == 2 * x + 2\n\nNow the binary tree is contaminated, which means all treeNode.val have been changed to -1.\nImplement the FindElements class:\n\nFindElements(TreeNode* root) Initializes the object with a contaminated binary tree and recovers it.\nbool find(int target) Returns true if the target value exists in the recovered binary tree.", + "examples": [ + "Example 1:\nInput\n[\"FindElements\",\"find\",\"find\"]\n[[[-1,null,-1]],[1],[2]]\nOutput\n[null,false,true]\nExplanation\nFindElements findElements = new FindElements([-1,null,-1]); \nfindElements.find(1); // return False \nfindElements.find(2); // return True", + "Example 2:\nInput\n[\"FindElements\",\"find\",\"find\",\"find\"]\n[[[-1,-1,-1,-1,-1]],[1],[3],[5]]\nOutput\n[null,true,true,false]\nExplanation\nFindElements findElements = new FindElements([-1,-1,-1,-1,-1]);\nfindElements.find(1); // return True\nfindElements.find(3); // return True\nfindElements.find(5); // return False", + "Example 3:\nInput\n[\"FindElements\",\"find\",\"find\",\"find\",\"find\"]\n[[[-1,null,-1,-1,null,-1]],[2],[3],[4],[5]]\nOutput\n[null,true,false,false,true]\nExplanation\nFindElements findElements = new FindElements([-1,null,-1,-1,null,-1]);\nfindElements.find(2); // return True\nfindElements.find(3); // return False\nfindElements.find(4); // return False\nfindElements.find(5); // return True" + ], + "constraints": "Constraints:\n\nTreeNode.val == -1\nThe height of the binary tree is less than or equal to 20\nThe total number of nodes is between [1, 10^4]\nTotal calls of find() is between [1, 10^4]\n0 <= target <= 10^6", + "tags": [ + "Hash Table", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Design", + "Binary Tree" + ], + "title-slug": "find-elements-in-a-contaminated-binary-tree" + }, + { + "leetcode-id": 1262, + "title": "Greatest Sum Divisible by Three", + "difficulty": 2, + "description": "Given an integer array nums, return the maximum possible sum of elements of the array such that it is divisible by three.", + "examples": [ + "Example 1:\nInput: nums = [3,6,5,1,8]\nOutput: 18\nExplanation: Pick numbers 3, 6, 1 and 8 their sum is 18 (maximum sum divisible by 3).", + "Example 2:\nInput: nums = [4]\nOutput: 0\nExplanation: Since 4 is not divisible by 3, do not pick any number.", + "Example 3:\nInput: nums = [1,2,3,4,4]\nOutput: 12\nExplanation: Pick numbers 1, 3, 4 and 4 their sum is 12 (maximum sum divisible by 3)." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 4 * 10^4\n1 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy", + "Sorting" + ], + "title-slug": "greatest-sum-divisible-by-three" + }, + { + "leetcode-id": 1263, + "title": "Minimum Moves to Move a Box to Their Target Location", + "difficulty": 3, + "description": "A storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations.\nThe game is represented by an m x n grid of characters grid where each element is a wall, floor, or box.\nYour task is to move the box 'B' to the target position 'T' under the following rules:\n\nThe character 'S' represents the player. The player can move up, down, left, right in grid if it is a floor (empty cell).\nThe character '.' represents the floor which means a free cell to walk.\nThe character\u00a0'#'\u00a0represents the wall which means an obstacle (impossible to walk there).\nThere is only one box 'B' and one target cell 'T' in the grid.\nThe box can be moved to an adjacent free cell by standing next to the box and then moving in the direction of the box. This is a push.\nThe player cannot walk through the box.\n\nReturn the minimum number of pushes to move the box to the target. If there is no way to reach the target, return -1.", + "examples": [ + "Example 1:\nInput: grid = [[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],\n [\"#\",\"T\",\"#\",\"#\",\"#\",\"#\"],\n [\"#\",\".\",\".\",\"B\",\".\",\"#\"],\n [\"#\",\".\",\"#\",\"#\",\".\",\"#\"],\n [\"#\",\".\",\".\",\".\",\"S\",\"#\"],\n [\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"]]\nOutput: 3\nExplanation: We return only the number of times the box is pushed.", + "Example 2:\nInput: grid = [[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],\n [\"#\",\"T\",\"#\",\"#\",\"#\",\"#\"],\n [\"#\",\".\",\".\",\"B\",\".\",\"#\"],\n [\"#\",\"#\",\"#\",\"#\",\".\",\"#\"],\n [\"#\",\".\",\".\",\".\",\"S\",\"#\"],\n [\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"]]\nOutput: -1", + "Example 3:\nInput: grid = [[\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"],\n [\"#\",\"T\",\".\",\".\",\"#\",\"#\"],\n [\"#\",\".\",\"#\",\"B\",\".\",\"#\"],\n [\"#\",\".\",\".\",\".\",\".\",\"#\"],\n [\"#\",\".\",\".\",\".\",\"S\",\"#\"],\n [\"#\",\"#\",\"#\",\"#\",\"#\",\"#\"]]\nOutput: 5\nExplanation: push the box down, left, left, up and up." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 20\ngrid contains only characters '.', '#', 'S', 'T', or 'B'.\nThere is only one character 'S', 'B', and 'T' in the grid.", + "tags": [ + "Array", + "Breadth-First Search", + "Heap (Priority Queue)", + "Matrix" + ], + "title-slug": "minimum-moves-to-move-a-box-to-their-target-location" + }, + { + "leetcode-id": 1266, + "title": "Minimum Time Visiting All Points", + "difficulty": 1, + "description": "On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points.\nYou can move according to these rules:\n\nIn 1 second, you can either:\n\n\t\nmove vertically by one\u00a0unit,\nmove horizontally by one unit, or\nmove diagonally sqrt(2) units (in other words, move one unit vertically then one unit horizontally in 1 second).\n\n\nYou have to visit the points in the same order as they appear in the array.\nYou are allowed to pass through points that appear later in the order, but these do not count as visits.", + "examples": [ + "Example 1:\nInput: points = [[1,1],[3,4],[-1,0]]\nOutput: 7\nExplanation: One optimal path is [1,1] -> [2,2] -> [3,3] -> [3,4] -> [2,3] -> [1,2] -> [0,1] -> [-1,0] \nTime from [1,1] to [3,4] = 3 seconds \nTime from [3,4] to [-1,0] = 4 seconds\nTotal time = 7 seconds", + "Example 2:\nInput: points = [[3,2],[-2,2]]\nOutput: 5" + ], + "constraints": "Constraints:\n\npoints.length == n\n1 <= n\u00a0<= 100\npoints[i].length == 2\n-1000\u00a0<= points[i][0], points[i][1]\u00a0<= 1000", + "tags": [ + "Array", + "Math", + "Geometry" + ], + "title-slug": "minimum-time-visiting-all-points" + }, + { + "leetcode-id": 1267, + "title": "Count Servers that Communicate", + "difficulty": 2, + "description": "You are given a map of a server center, represented as a m * n integer matrix\u00a0grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communicate if they are on the same row or on the same column.\n\nReturn the number of servers\u00a0that communicate with any other server.", + "examples": [ + "Example 1:\nInput: grid = [[1,0],[0,1]]\nOutput: 0\nExplanation:\u00a0No servers can communicate with others.", + "Example 2:\nInput: grid = [[1,0],[1,1]]\nOutput: 3\nExplanation:\u00a0All three servers can communicate with at least one other server.", + "Example 3:\nInput: grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]\nOutput: 4\nExplanation:\u00a0The two servers in the first row can communicate with each other. The two servers in the third column can communicate with each other. The server at right bottom corner can't communicate with any other server." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m <= 250\n1 <= n <= 250\ngrid[i][j] == 0 or 1", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Matrix", + "Counting" + ], + "title-slug": "count-servers-that-communicate" + }, + { + "leetcode-id": 1268, + "title": "Search Suggestions System", + "difficulty": 2, + "description": "You are given an array of strings products and a string searchWord.\nDesign a system that suggests at most three product names from products after each character of searchWord is typed. Suggested products should have common prefix with searchWord. If there are more than three products with a common prefix return the three lexicographically minimums products.\nReturn a list of lists of the suggested products after each character of searchWord is typed.", + "examples": [ + "Example 1:\nInput: products = [\"mobile\",\"mouse\",\"moneypot\",\"monitor\",\"mousepad\"], searchWord = \"mouse\"\nOutput: [[\"mobile\",\"moneypot\",\"monitor\"],[\"mobile\",\"moneypot\",\"monitor\"],[\"mouse\",\"mousepad\"],[\"mouse\",\"mousepad\"],[\"mouse\",\"mousepad\"]]\nExplanation: products sorted lexicographically = [\"mobile\",\"moneypot\",\"monitor\",\"mouse\",\"mousepad\"].\nAfter typing m and mo all products match and we show user [\"mobile\",\"moneypot\",\"monitor\"].\nAfter typing mou, mous and mouse the system suggests [\"mouse\",\"mousepad\"].", + "Example 2:\nInput: products = [\"havana\"], searchWord = \"havana\"\nOutput: [[\"havana\"],[\"havana\"],[\"havana\"],[\"havana\"],[\"havana\"],[\"havana\"]]\nExplanation: The only word \"havana\" will be always suggested while typing the search word." + ], + "constraints": "Constraints:\n\n1 <= products.length <= 1000\n1 <= products[i].length <= 3000\n1 <= sum(products[i].length) <= 2 * 10^4\nAll the strings of products are unique.\nproducts[i] consists of lowercase English letters.\n1 <= searchWord.length <= 1000\nsearchWord consists of lowercase English letters.", + "tags": [ + "Array", + "String", + "Binary Search", + "Trie", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "search-suggestions-system" + }, + { + "leetcode-id": 1269, + "title": "Number of Ways to Stay in the Same Place After Some Steps", + "difficulty": 3, + "description": "You have a pointer at index 0 in an array of size arrLen. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).\nGiven two integers steps and arrLen, return the number of ways such that your pointer is still at index 0 after exactly steps steps. Since the answer may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: steps = 3, arrLen = 2\nOutput: 4\nExplanation: There are 4 differents ways to stay at index 0 after 3 steps.\nRight, Left, Stay\nStay, Right, Left\nRight, Stay, Left\nStay, Stay, Stay", + "Example 2:\nInput: steps = 2, arrLen = 4\nOutput: 2\nExplanation: There are 2 differents ways to stay at index 0 after 2 steps\nRight, Left\nStay, Stay", + "Example 3:\nInput: steps = 4, arrLen = 2\nOutput: 8" + ], + "constraints": "Constraints:\n\n1 <= steps <= 500\n1 <= arrLen <= 10^6", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "number-of-ways-to-stay-in-the-same-place-after-some-steps" + }, + { + "leetcode-id": 1275, + "title": "Find Winner on a Tic Tac Toe Game", + "difficulty": 1, + "description": "Tic-tac-toe is played by two players A and B on a 3 x 3 grid. The rules of Tic-Tac-Toe are:\n\nPlayers take turns placing characters into empty squares ' '.\nThe first player A always places 'X' characters, while the second player B always places 'O' characters.\n'X' and 'O' characters are always placed into empty squares, never on filled ones.\nThe game ends when there are three of the same (non-empty) character filling any row, column, or diagonal.\nThe game also ends if all squares are non-empty.\nNo more moves can be played if the game is over.\n\nGiven a 2D integer array moves where moves[i] = [rowi, coli] indicates that the i^th move will be played on grid[rowi][coli]. return the winner of the game if it exists (A or B). In case the game ends in a draw return \"Draw\". If there are still movements to play return \"Pending\".\nYou can assume that moves is valid (i.e., it follows the rules of Tic-Tac-Toe), the grid is initially empty, and A will play first.", + "examples": [ + "Example 1:\nInput: moves = [[0,0],[2,0],[1,1],[2,1],[2,2]]\nOutput: \"A\"\nExplanation: A wins, they always play first.", + "Example 2:\nInput: moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]\nOutput: \"B\"\nExplanation: B wins.", + "Example 3:\nInput: moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]\nOutput: \"Draw\"\nExplanation: The game ends in a draw since there are no moves to make." + ], + "constraints": "Constraints:\n\n1 <= moves.length <= 9\nmoves[i].length == 2\n0 <= rowi, coli <= 2\nThere are no repeated elements on moves.\nmoves follow the rules of tic tac toe.", + "tags": [ + "Array", + "Hash Table", + "Matrix", + "Simulation" + ], + "title-slug": "find-winner-on-a-tic-tac-toe-game" + }, + { + "leetcode-id": 1276, + "title": "Number of Burgers with No Waste of Ingredients", + "difficulty": 2, + "description": "Given two integers tomatoSlices and cheeseSlices. The ingredients of different burgers are as follows:\n\nJumbo Burger: 4 tomato slices and 1 cheese slice.\nSmall Burger: 2 Tomato slices and 1 cheese slice.\n\nReturn [total_jumbo, total_small] so that the number of remaining tomatoSlices equal to 0 and the number of remaining cheeseSlices equal to 0. If it is not possible to make the remaining tomatoSlices and cheeseSlices equal to 0 return [].", + "examples": [ + "Example 1:\nInput: tomatoSlices = 16, cheeseSlices = 7\nOutput: [1,6]\nExplantion: To make one jumbo burger and 6 small burgers we need 4*1 + 2*6 = 16 tomato and 1 + 6 = 7 cheese.\nThere will be no remaining ingredients.", + "Example 2:\nInput: tomatoSlices = 17, cheeseSlices = 4\nOutput: []\nExplantion: There will be no way to use all ingredients to make small and jumbo burgers.", + "Example 3:\nInput: tomatoSlices = 4, cheeseSlices = 17\nOutput: []\nExplantion: Making 1 jumbo burger there will be 16 cheese remaining and making 2 small burgers there will be 15 cheese remaining." + ], + "constraints": "Constraints:\n\n0 <= tomatoSlices, cheeseSlices <= 10^7", + "tags": [ + "Math" + ], + "title-slug": "number-of-burgers-with-no-waste-of-ingredients" + }, + { + "leetcode-id": 1277, + "title": "Count Square Submatrices with All Ones", + "difficulty": 2, + "description": "Given a m * n matrix of ones and zeros, return how many square submatrices have all ones.", + "examples": [ + "Example 1:\nInput: matrix =\n[\n\u00a0 [0,1,1,1],\n\u00a0 [1,1,1,1],\n\u00a0 [0,1,1,1]\n]\nOutput: 15\nExplanation: \nThere are 10 squares of side 1.\nThere are 4 squares of side 2.\nThere is 1 square of side 3.\nTotal number of squares = 10 + 4 + 1 = 15.", + "Example 2:\nInput: matrix = \n[\n [1,0,1],\n [1,1,0],\n [1,1,0]\n]\nOutput: 7\nExplanation: \nThere are 6 squares of side 1. \nThere is 1 square of side 2. \nTotal number of squares = 6 + 1 = 7." + ], + "constraints": "Constraints:\n\n1 <= arr.length\u00a0<= 300\n1 <= arr[0].length\u00a0<= 300\n0 <= arr[i][j] <= 1", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "count-square-submatrices-with-all-ones" + }, + { + "leetcode-id": 1278, + "title": "Palindrome Partitioning III", + "difficulty": 3, + "description": "You are given a string s containing lowercase letters and an integer k. You need to :\n\nFirst, change some characters of s to other lowercase English letters.\nThen divide s into k non-empty disjoint substrings such that each substring is a palindrome.\n\nReturn the minimal number of characters that you need to change to divide the string.", + "examples": [ + "Example 1:\nInput: s = \"abc\", k = 2\nOutput: 1\nExplanation:\u00a0You can split the string into \"ab\" and \"c\", and change 1 character in \"ab\" to make it palindrome.", + "Example 2:\nInput: s = \"aabbc\", k = 3\nOutput: 0\nExplanation:\u00a0You can split the string into \"aa\", \"bb\" and \"c\", all of them are palindrome.", + "Example 3:\nInput: s = \"leetcode\", k = 8\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= k <= s.length <= 100.\ns only contains lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "palindrome-partitioning-iii" + }, + { + "leetcode-id": 1281, + "title": "Subtract the Product and Sum of Digits of an Integer", + "difficulty": 1, + "description": "Given an integer number n, return the difference between the product of its digits and the sum of its digits.", + "examples": [ + "Example 1:\nInput: n = 234\nOutput: 15 \nExplanation: \nProduct of digits = 2 * 3 * 4 = 24 \nSum of digits = 2 + 3 + 4 = 9 \nResult = 24 - 9 = 15", + "Example 2:\nInput: n = 4421\nOutput: 21\nExplanation: \nProduct of digits = 4 * 4 * 2 * 1 = 32 \nSum of digits = 4 + 4 + 2 + 1 = 11 \nResult = 32 - 11 = 21" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5", + "tags": [ + "Math" + ], + "title-slug": "subtract-the-product-and-sum-of-digits-of-an-integer" + }, + { + "leetcode-id": 1282, + "title": "Group the People Given the Group Size They Belong To", + "difficulty": 2, + "description": "There are n people\u00a0that are split into some unknown number of groups. Each person is labeled with a\u00a0unique ID\u00a0from\u00a00\u00a0to\u00a0n - 1.\nYou are given an integer array\u00a0groupSizes, where groupSizes[i]\u00a0is the size of the group that person\u00a0i\u00a0is in. For example, if\u00a0groupSizes[1] = 3, then\u00a0person\u00a01\u00a0must be in a\u00a0group of size\u00a03.\nReturn\u00a0a list of groups\u00a0such that\u00a0each person\u00a0i\u00a0is in a group of size\u00a0groupSizes[i].\nEach person should\u00a0appear in\u00a0exactly one group,\u00a0and every person must be in a group. If there are\u00a0multiple answers, return any of them. It is guaranteed that there will be at least one valid solution for the given input.", + "examples": [ + "Example 1:\nInput: groupSizes = [3,3,3,3,3,1,3]\nOutput: [[5],[0,1,2],[3,4,6]]\nExplanation: \nThe first group is [5]. The size is 1, and groupSizes[5] = 1.\nThe second group is [0,1,2]. The size is 3, and groupSizes[0] = groupSizes[1] = groupSizes[2] = 3.\nThe third group is [3,4,6]. The size is 3, and groupSizes[3] = groupSizes[4] = groupSizes[6] = 3.\nOther possible solutions are [[2,1,6],[5],[0,4,3]] and [[5],[0,6,2],[4,3,1]].", + "Example 2:\nInput: groupSizes = [2,1,3,3,3,2]\nOutput: [[1],[0,5],[2,3,4]]" + ], + "constraints": "Constraints:\n\ngroupSizes.length == n\n1 <= n\u00a0<= 500\n1 <=\u00a0groupSizes[i] <= n", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "group-the-people-given-the-group-size-they-belong-to" + }, + { + "leetcode-id": 1283, + "title": "Find the Smallest Divisor Given a Threshold", + "difficulty": 2, + "description": "Given an array of integers nums and an integer threshold, we will choose a positive integer divisor, divide all the array by it, and sum the division's result. Find the smallest divisor such that the result mentioned above is less than or equal to threshold.\nEach result of the division is rounded to the nearest integer greater than or equal to that element. (For example: 7/3 = 3 and 10/2 = 5).\nThe test cases are generated so\u00a0that there will be an answer.", + "examples": [ + "Example 1:\nInput: nums = [1,2,5,9], threshold = 6\nOutput: 5\nExplanation: We can get a sum to 17 (1+2+5+9) if the divisor is 1. \nIf the divisor is 4 we can get a sum of 7 (1+1+2+3) and if the divisor is 5 the sum will be 5 (1+1+1+2).", + "Example 2:\nInput: nums = [44,22,33,11,1], threshold = 5\nOutput: 44" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 5 * 10^4\n1 <= nums[i] <= 10^6\nnums.length <= threshold <= 10^6", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "find-the-smallest-divisor-given-a-threshold" + }, + { + "leetcode-id": 1284, + "title": "Minimum Number of Flips to Convert Binary Matrix to Zero Matrix", + "difficulty": 3, + "description": "Given a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing 1 to 0 and 0 to 1). A pair of cells are called neighbors if they share one edge.\nReturn the minimum number of steps required to convert mat to a zero matrix or -1 if you cannot.\nA binary matrix is a matrix with all cells equal to 0 or 1 only.\nA zero matrix is a matrix with all cells equal to 0.", + "examples": [ + "Example 1:\nInput: mat = [[0,0],[0,1]]\nOutput: 3\nExplanation: One possible solution is to flip (1, 0) then (0, 1) and finally (1, 1) as shown.", + "Example 2:\nInput: mat = [[0]]\nOutput: 0\nExplanation: Given matrix is a zero matrix. We do not need to change it.", + "Example 3:\nInput: mat = [[1,0,0],[1,0,0]]\nOutput: -1\nExplanation: Given matrix cannot be a zero matrix." + ], + "constraints": "Constraints:\n\nm == mat.length\nn == mat[i].length\n1 <= m, n <= 3\nmat[i][j] is either 0 or 1.", + "tags": [ + "Array", + "Bit Manipulation", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix" + }, + { + "leetcode-id": 1286, + "title": "Iterator for Combination", + "difficulty": 2, + "description": "Design the CombinationIterator class:\n\nCombinationIterator(string characters, int combinationLength) Initializes the object with a string characters of sorted distinct lowercase English letters and a number combinationLength as arguments.\nnext() Returns the next combination of length combinationLength in lexicographical order.\nhasNext() Returns true if and only if there exists a next combination.", + "examples": [ + "Example 1:\nInput\n[\"CombinationIterator\", \"next\", \"hasNext\", \"next\", \"hasNext\", \"next\", \"hasNext\"]\n[[\"abc\", 2], [], [], [], [], [], []]\nOutput\n[null, \"ab\", true, \"ac\", true, \"bc\", false]\n\nExplanation\nCombinationIterator itr = new CombinationIterator(\"abc\", 2);\nitr.next(); // return \"ab\"\nitr.hasNext(); // return True\nitr.next(); // return \"ac\"\nitr.hasNext(); // return True\nitr.next(); // return \"bc\"\nitr.hasNext(); // return False" + ], + "constraints": "Constraints:\n\n1 <= combinationLength <= characters.length <= 15\nAll the characters of characters are unique.\nAt most 10^4 calls will be made to next and hasNext.\nIt is guaranteed that all calls of the function next are valid.", + "tags": [ + "String", + "Backtracking", + "Design", + "Iterator" + ], + "title-slug": "iterator-for-combination" + }, + { + "leetcode-id": 1287, + "title": "Element Appearing More Than 25% In Sorted Array", + "difficulty": 1, + "description": "Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.", + "examples": [ + "Example 1:\nInput: arr = [1,2,2,6,6,6,6,7,10]\nOutput: 6", + "Example 2:\nInput: arr = [1,1]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^4\n0 <= arr[i] <= 10^5", + "tags": [ + "Array" + ], + "title-slug": "element-appearing-more-than-25-in-sorted-array" + }, + { + "leetcode-id": 1288, + "title": "Remove Covered Intervals", + "difficulty": 2, + "description": "Given an array intervals where intervals[i] = [li, ri] represent the interval [li, ri), remove all intervals that are covered by another interval in the list.\nThe interval [a, b) is covered by the interval [c, d) if and only if c <= a and b <= d.\nReturn the number of remaining intervals.", + "examples": [ + "Example 1:\nInput: intervals = [[1,4],[3,6],[2,8]]\nOutput: 2\nExplanation: Interval [3,6] is covered by [2,8], therefore it is removed.", + "Example 2:\nInput: intervals = [[1,4],[2,3]]\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= intervals.length <= 1000\nintervals[i].length == 2\n0 <= li < ri <= 10^5\nAll the given intervals are unique.", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "remove-covered-intervals" + }, + { + "leetcode-id": 1289, + "title": "Minimum Falling Path Sum II", + "difficulty": 3, + "description": "Given an n x n integer matrix grid, return the minimum sum of a falling path with non-zero shifts.\nA falling path with non-zero shifts is a choice of exactly one element from each row of grid such that no two elements chosen in adjacent rows are in the same column.", + "examples": [ + "Example 1:\nInput: grid = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: 13\nExplanation: \nThe possible falling paths are:\n[1,5,9], [1,5,7], [1,6,7], [1,6,8],\n[2,4,8], [2,4,9], [2,6,7], [2,6,8],\n[3,4,8], [3,4,9], [3,5,7], [3,5,9]\nThe falling path with the smallest sum is\u00a0[1,5,7], so the answer is\u00a013.", + "Example 2:\nInput: grid = [[7]]\nOutput: 7" + ], + "constraints": "Constraints:\n\nn == grid.length == grid[i].length\n1 <= n <= 200\n-99 <= grid[i][j] <= 99", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "minimum-falling-path-sum-ii" + }, + { + "leetcode-id": 1290, + "title": "Convert Binary Number in a Linked List to Integer", + "difficulty": 1, + "description": "Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number.\nReturn the decimal value of the number in the linked list.\nThe most significant bit is at the head of the linked list.", + "examples": [ + "Example 1:\nInput: head = [1,0,1]\nOutput: 5\nExplanation: (101) in base 2 = (5) in base 10", + "Example 2:\nInput: head = [0]\nOutput: 0" + ], + "constraints": "Constraints:\n\nThe Linked List is not empty.\nNumber of nodes will not exceed 30.\nEach node's value is either 0 or 1.", + "tags": [ + "Linked List", + "Math" + ], + "title-slug": "convert-binary-number-in-a-linked-list-to-integer" + }, + { + "leetcode-id": 1291, + "title": "Sequential Digits", + "difficulty": 2, + "description": "An\u00a0integer has sequential digits if and only if each digit in the number is one more than the previous digit.\nReturn a sorted list of all the integers\u00a0in the range [low, high]\u00a0inclusive that have sequential digits.", + "examples": [ + "Example 1:\nInput: low = 100, high = 300\nOutput: [123,234]", + "Example 2:\nInput: low = 1000, high = 13000\nOutput: [1234,2345,3456,4567,5678,6789,12345]" + ], + "constraints": "Constraints:\n\n10 <= low <= high <= 10^9", + "tags": [ + "Enumeration" + ], + "title-slug": "sequential-digits" + }, + { + "leetcode-id": 1292, + "title": "Maximum Side Length of a Square with Sum Less than or Equal to Threshold", + "difficulty": 2, + "description": "Given a m x n matrix mat and an integer threshold, return the maximum side-length of a square with a sum less than or equal to threshold or return 0 if there is no such square.", + "examples": [ + "Example 1:\nInput: mat = [[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]], threshold = 4\nOutput: 2\nExplanation: The maximum side length of square with sum less than 4 is 2 as shown.", + "Example 2:\nInput: mat = [[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2]], threshold = 1\nOutput: 0" + ], + "constraints": "Constraints:\n\nm == mat.length\nn == mat[i].length\n1 <= m, n <= 300\n0 <= mat[i][j] <= 10^4\n0 <= threshold <= 10^5", + "tags": [ + "Array", + "Binary Search", + "Matrix", + "Prefix Sum" + ], + "title-slug": "maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold" + }, + { + "leetcode-id": 1293, + "title": "Shortest Path in a Grid with Obstacles Elimination", + "difficulty": 3, + "description": "You are given an m x n integer matrix grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an empty cell in one step.\nReturn the minimum number of steps to walk from the upper left corner (0, 0) to the lower right corner (m - 1, n - 1) given that you can eliminate at most k obstacles. If it is not possible to find such walk return -1.", + "examples": [ + "Example 1:\nInput: grid = [[0,0,0],[1,1,0],[0,0,0],[0,1,1],[0,0,0]], k = 1\nOutput: 6\nExplanation: \nThe shortest path without eliminating any obstacle is 10.\nThe shortest path with one obstacle elimination at position (3,2) is 6. Such path is (0,0) -> (0,1) -> (0,2) -> (1,2) -> (2,2) -> (3,2) -> (4,2).", + "Example 2:\nInput: grid = [[0,1,1],[1,1,1],[1,0,0]], k = 1\nOutput: -1\nExplanation: We need to eliminate at least two obstacles to find such a walk." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 40\n1 <= k <= m * n\ngrid[i][j] is either 0 or 1.\ngrid[0][0] == grid[m - 1][n - 1] == 0", + "tags": [ + "Array", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "shortest-path-in-a-grid-with-obstacles-elimination" + }, + { + "leetcode-id": 1295, + "title": "Find Numbers with Even Number of Digits", + "difficulty": 1, + "description": "Given an array nums of integers, return how many of them contain an even number of digits.", + "examples": [ + "Example 1:\nInput: nums = [12,345,2,6,7896]\nOutput: 2\nExplanation: \n12 contains 2 digits (even number of digits).\u00a0\n345 contains 3 digits (odd number of digits).\u00a0\n2 contains 1 digit (odd number of digits).\u00a0\n6 contains 1 digit (odd number of digits).\u00a0\n7896 contains 4 digits (even number of digits).\u00a0\nTherefore only 12 and 7896 contain an even number of digits.", + "Example 2:\nInput: nums = [555,901,482,1771]\nOutput: 1 \nExplanation: \nOnly 1771 contains an even number of digits." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 500\n1 <= nums[i] <= 10^5", + "tags": [ + "Array" + ], + "title-slug": "find-numbers-with-even-number-of-digits" + }, + { + "leetcode-id": 1296, + "title": "Divide Array in Sets of K Consecutive Numbers", + "difficulty": 2, + "description": "Given an array of integers nums and a positive integer k, check whether it is possible to divide this array into sets of k consecutive numbers.\nReturn true if it is possible. Otherwise, return false.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,3,4,4,5,6], k = 4\nOutput: true\nExplanation: Array can be divided into [1,2,3,4] and [3,4,5,6].", + "Example 2:\nInput: nums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3\nOutput: true\nExplanation: Array can be divided into [1,2,3] , [2,3,4] , [3,4,5] and [9,10,11].", + "Example 3:\nInput: nums = [1,2,3,4], k = 3\nOutput: false\nExplanation: Each array should be divided in subarrays of size 3." + ], + "constraints": "Constraints:\n\n1 <= k <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\n\n\u00a0\nNote: This question is the same as\u00a0846:\u00a0https://leetcode.com/problems/hand-of-straights/", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Sorting" + ], + "title-slug": "divide-array-in-sets-of-k-consecutive-numbers" + }, + { + "leetcode-id": 1297, + "title": "Maximum Number of Occurrences of a Substring", + "difficulty": 2, + "description": "Given a string s, return the maximum number of occurrences of any substring under the following rules:\n\nThe number of unique characters in the substring must be less than or equal to maxLetters.\nThe substring size must be between minSize and maxSize inclusive.", + "examples": [ + "Example 1:\nInput: s = \"aababcaab\", maxLetters = 2, minSize = 3, maxSize = 4\nOutput: 2\nExplanation: Substring \"aab\" has 2 occurrences in the original string.\nIt satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize).", + "Example 2:\nInput: s = \"aaaa\", maxLetters = 1, minSize = 3, maxSize = 3\nOutput: 2\nExplanation: Substring \"aaa\" occur 2 times in the string. It can overlap." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\n1 <= maxLetters <= 26\n1 <= minSize <= maxSize <= min(26, s.length)\ns consists of only lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Sliding Window" + ], + "title-slug": "maximum-number-of-occurrences-of-a-substring" + }, + { + "leetcode-id": 1298, + "title": "Maximum Candies You Can Get from Boxes", + "difficulty": 3, + "description": "You have n boxes labeled from 0 to n - 1. You are given four arrays: status, candies, keys, and containedBoxes where:\n\nstatus[i] is 1 if the i^th box is open and 0 if the i^th box is closed,\ncandies[i] is the number of candies in the i^th box,\nkeys[i] is a list of the labels of the boxes you can open after opening the i^th box.\ncontainedBoxes[i] is a list of the boxes you found inside the i^th box.\n\nYou are given an integer array initialBoxes that contains the labels of the boxes you initially have. You can take all the candies in any open box and you can use the keys in it to open new boxes and you also can use the boxes you find in it.\nReturn the maximum number of candies you can get following the rules above.", + "examples": [ + "Example 1:\nInput: status = [1,0,1,0], candies = [7,5,4,100], keys = [[],[],[1],[]], containedBoxes = [[1,2],[3],[],[]], initialBoxes = [0]\nOutput: 16\nExplanation: You will be initially given box 0. You will find 7 candies in it and boxes 1 and 2.\nBox 1 is closed and you do not have a key for it so you will open box 2. You will find 4 candies and a key to box 1 in box 2.\nIn box 1, you will find 5 candies and box 3 but you will not find a key to box 3 so box 3 will remain closed.\nTotal number of candies collected = 7 + 4 + 5 = 16 candy.", + "Example 2:\nInput: status = [1,0,0,0,0,0], candies = [1,1,1,1,1,1], keys = [[1,2,3,4,5],[],[],[],[],[]], containedBoxes = [[1,2,3,4,5],[],[],[],[],[]], initialBoxes = [0]\nOutput: 6\nExplanation: You have initially box 0. Opening it you can find boxes 1,2,3,4 and 5 and their keys.\nThe total number of candies will be 6." + ], + "constraints": "Constraints:\n\nn == status.length == candies.length == keys.length == containedBoxes.length\n1 <= n <= 1000\nstatus[i] is either 0 or 1.\n1 <= candies[i] <= 1000\n0 <= keys[i].length <= n\n0 <= keys[i][j] < n\nAll values of keys[i] are unique.\n0 <= containedBoxes[i].length <= n\n0 <= containedBoxes[i][j] < n\nAll values of containedBoxes[i] are unique.\nEach box is contained in one box at most.\n0 <= initialBoxes.length <= n\n0 <= initialBoxes[i] < n", + "tags": [ + "Array", + "Breadth-First Search", + "Graph" + ], + "title-slug": "maximum-candies-you-can-get-from-boxes" + }, + { + "leetcode-id": 1299, + "title": "Replace Elements with Greatest Element on Right Side", + "difficulty": 1, + "description": "Given an array arr,\u00a0replace every element in that array with the greatest element among the elements to its\u00a0right, and replace the last element with -1.\nAfter doing so, return the array.", + "examples": [ + "Example 1:\nInput: arr = [17,18,5,4,6,1]\nOutput: [18,6,6,6,1,-1]\nExplanation: \n- index 0 --> the greatest element to the right of index 0 is index 1 (18).\n- index 1 --> the greatest element to the right of index 1 is index 4 (6).\n- index 2 --> the greatest element to the right of index 2 is index 4 (6).\n- index 3 --> the greatest element to the right of index 3 is index 4 (6).\n- index 4 --> the greatest element to the right of index 4 is index 5 (1).\n- index 5 --> there are no elements to the right of index 5, so we put -1.", + "Example 2:\nInput: arr = [400]\nOutput: [-1]\nExplanation: There are no elements to the right of index 0." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^4\n1 <= arr[i] <= 10^5", + "tags": [ + "Array" + ], + "title-slug": "replace-elements-with-greatest-element-on-right-side" + }, + { + "leetcode-id": 1300, + "title": "Sum of Mutated Array Closest to Target", + "difficulty": 2, + "description": "Given an integer array arr and a target value target, return the integer value such that when we change all the integers larger than value in the given array to be equal to value, the sum of the array gets as close as possible (in absolute difference) to target.\nIn case of a tie, return the minimum such integer.\nNotice that the answer is not neccesarilly a number from arr.", + "examples": [ + "Example 1:\nInput: arr = [4,9,3], target = 10\nOutput: 3\nExplanation: When using 3 arr converts to [3, 3, 3] which sums 9 and that's the optimal answer.", + "Example 2:\nInput: arr = [2,3,5], target = 10\nOutput: 5", + "Example 3:\nInput: arr = [60864,25176,27249,21296,20204], target = 56803\nOutput: 11361" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^4\n1 <= arr[i], target <= 10^5", + "tags": [ + "Array", + "Binary Search", + "Sorting" + ], + "title-slug": "sum-of-mutated-array-closest-to-target" + }, + { + "leetcode-id": 1301, + "title": "Number of Paths with Max Score", + "difficulty": 3, + "description": "You are given a square board\u00a0of characters. You can move on the board starting at the bottom right square marked with the character\u00a0'S'.\nYou need\u00a0to reach the top left square marked with the character 'E'. The rest of the squares are labeled either with a numeric character\u00a01, 2, ..., 9 or with an obstacle 'X'. In one move you can go up, left or up-left (diagonally) only if there is no obstacle there.\nReturn a list of two integers: the first integer is the maximum sum of numeric characters you can collect, and the second is the number of such paths that you can take to get that maximum sum, taken modulo 10^9 + 7.\nIn case there is no path, return\u00a0[0, 0].", + "examples": [ + "Example 1:\nInput: board = [\"E23\",\"2X2\",\"12S\"]\r\nOutput: [7,1]", + "Example 2:\nInput: board = [\"E12\",\"1X1\",\"21S\"]\r\nOutput: [4,2]", + "Example 3:\nInput: board = [\"E11\",\"XXX\",\"11S\"]\r\nOutput: [0,0]" + ], + "constraints": "Constraints:\n\n2 <= board.length == board[i].length <= 100", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "number-of-paths-with-max-score" + }, + { + "leetcode-id": 1302, + "title": "Deepest Leaves Sum", + "difficulty": 2, + "description": "Given the root of a binary tree, return the sum of values of its deepest leaves.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,4,5,null,6,7,null,null,null,null,8]\nOutput: 15", + "Example 2:\nInput: root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]\nOutput: 19" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n1 <= Node.val <= 100", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "deepest-leaves-sum" + }, + { + "leetcode-id": 1304, + "title": "Find N Unique Integers Sum up to Zero", + "difficulty": 1, + "description": "Given an integer n, return any array containing n unique integers such that they add up to 0.", + "examples": [ + "Example 1:\nInput: n = 5\nOutput: [-7,-1,1,3,4]\nExplanation: These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4].", + "Example 2:\nInput: n = 3\nOutput: [-1,0,1]", + "Example 3:\nInput: n = 1\nOutput: [0]" + ], + "constraints": "Constraints:\n\n1 <= n <= 1000", + "tags": [ + "Array", + "Math" + ], + "title-slug": "find-n-unique-integers-sum-up-to-zero" + }, + { + "leetcode-id": 1305, + "title": "All Elements in Two Binary Search Trees", + "difficulty": 2, + "description": "Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order.", + "examples": [ + "Example 1:\nInput: root1 = [2,1,4], root2 = [1,0,3]\nOutput: [0,1,1,2,3,4]", + "Example 2:\nInput: root1 = [1,null,8], root2 = [8,1]\nOutput: [1,1,8,8]" + ], + "constraints": "Constraints:\n\nThe number of nodes in each tree is in the range [0, 5000].\n-10^5 <= Node.val <= 10^5", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Search Tree", + "Sorting", + "Binary Tree" + ], + "title-slug": "all-elements-in-two-binary-search-trees" + }, + { + "leetcode-id": 1306, + "title": "Jump Game III", + "difficulty": 2, + "description": "Given an array of non-negative integers arr, you are initially positioned at start\u00a0index of the array. When you are at index i, you can jump\u00a0to i + arr[i] or i - arr[i], check if you can reach\u00a0any index with value 0.\nNotice that you can not jump outside of the array at any time.", + "examples": [ + "Example 1:\nInput: arr = [4,2,3,0,3,1,2], start = 5\nOutput: true\nExplanation: \nAll possible ways to reach at index 3 with value 0 are: \nindex 5 -> index 4 -> index 1 -> index 3 \nindex 5 -> index 6 -> index 4 -> index 1 -> index 3", + "Example 2:\nInput: arr = [4,2,3,0,3,1,2], start = 0\nOutput: true \nExplanation: \nOne possible way to reach at index 3 with value 0 is: \nindex 0 -> index 4 -> index 1 -> index 3", + "Example 3:\nInput: arr = [3,0,2,1,2], start = 2\nOutput: false\nExplanation: There is no way to reach at index 1 with value 0." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 5 * 10^4\n0 <= arr[i] <\u00a0arr.length\n0 <= start < arr.length", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search" + ], + "title-slug": "jump-game-iii" + }, + { + "leetcode-id": 1307, + "title": "Verbal Arithmetic Puzzle", + "difficulty": 3, + "description": "Given an equation, represented by words on the left side and the result on the right side.\nYou need to check if the equation is solvable under the following rules:\n\nEach character is decoded as one digit (0 - 9).\nNo two characters can map to the same digit.\nEach words[i] and result are decoded as one number without leading zeros.\nSum of numbers on the left side (words) will equal to the number on the right side (result).\n\nReturn true if the equation is solvable, otherwise return false.", + "examples": [ + "Example 1:\nInput: words = [\"SEND\",\"MORE\"], result = \"MONEY\"\nOutput: true\nExplanation: Map 'S'-> 9, 'E'->5, 'N'->6, 'D'->7, 'M'->1, 'O'->0, 'R'->8, 'Y'->'2'\nSuch that: \"SEND\" + \"MORE\" = \"MONEY\" , 9567 + 1085 = 10652", + "Example 2:\nInput: words = [\"SIX\",\"SEVEN\",\"SEVEN\"], result = \"TWENTY\"\nOutput: true\nExplanation: Map 'S'-> 6, 'I'->5, 'X'->0, 'E'->8, 'V'->7, 'N'->2, 'T'->1, 'W'->'3', 'Y'->4\nSuch that: \"SIX\" + \"SEVEN\" + \"SEVEN\" = \"TWENTY\" , 650 + 68782 + 68782 = 138214", + "Example 3:\nInput: words = [\"LEET\",\"CODE\"], result = \"POINT\"\nOutput: false\nExplanation: There is no possible mapping to satisfy the equation, so we return false.\nNote that two different characters cannot map to the same digit." + ], + "constraints": "Constraints:\n\n2 <= words.length <= 5\n1 <= words[i].length, result.length <= 7\nwords[i], result contain only uppercase English letters.\nThe number of different characters used in the expression is at most 10.", + "tags": [ + "Array", + "Math", + "String", + "Backtracking" + ], + "title-slug": "verbal-arithmetic-puzzle" + }, + { + "leetcode-id": 1309, + "title": "Decrypt String from Alphabet to Integer Mapping", + "difficulty": 1, + "description": "You are given a string s formed by digits and '#'. We want to map s to English lowercase characters as follows:\n\nCharacters ('a' to 'i') are represented by ('1' to '9') respectively.\nCharacters ('j' to 'z') are represented by ('10#' to '26#') respectively.\n\nReturn the string formed after mapping.\nThe test cases are generated so that a unique mapping will always exist.", + "examples": [ + "Example 1:\nInput: s = \"10#11#12\"\nOutput: \"jkab\"\nExplanation: \"j\" -> \"10#\" , \"k\" -> \"11#\" , \"a\" -> \"1\" , \"b\" -> \"2\".", + "Example 2:\nInput: s = \"1326#\"\nOutput: \"acz\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns consists of digits and the '#' letter.\ns will be a valid string such that mapping is always possible.", + "tags": [ + "String" + ], + "title-slug": "decrypt-string-from-alphabet-to-integer-mapping" + }, + { + "leetcode-id": 1310, + "title": "XOR Queries of a Subarray", + "difficulty": 2, + "description": "You are given an array arr of positive integers. You are also given the array queries where queries[i] = [lefti, righti].\nFor each query i compute the XOR of elements from lefti to righti (that is, arr[lefti] XOR arr[lefti + 1] XOR ... XOR arr[righti] ).\nReturn an array answer where answer[i] is the answer to the i^th query.", + "examples": [ + "Example 1:\nInput: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]]\nOutput: [2,7,14,8] \nExplanation: \nThe binary representation of the elements in the array are:\n1 = 0001 \n3 = 0011 \n4 = 0100 \n8 = 1000 \nThe XOR values for queries are:\n[0,1] = 1 xor 3 = 2 \n[1,2] = 3 xor 4 = 7 \n[0,3] = 1 xor 3 xor 4 xor 8 = 14 \n[3,3] = 8", + "Example 2:\nInput: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]]\nOutput: [8,0,4,4]" + ], + "constraints": "Constraints:\n\n1 <= arr.length, queries.length <= 3 * 10^4\n1 <= arr[i] <= 10^9\nqueries[i].length == 2\n0 <= lefti <= righti < arr.length", + "tags": [ + "Array", + "Bit Manipulation", + "Prefix Sum" + ], + "title-slug": "xor-queries-of-a-subarray" + }, + { + "leetcode-id": 1311, + "title": "Get Watched Videos by Your Friends", + "difficulty": 2, + "description": "There are n people, each person has a unique id between 0 and n-1. Given the arrays watchedVideos and friends, where watchedVideos[i] and friends[i] contain the list of watched videos and the list of friends respectively for the person with id = i.\nLevel 1 of videos are all watched videos by your\u00a0friends, level 2 of videos are all watched videos by the friends of your\u00a0friends and so on. In general, the level k of videos are all\u00a0watched videos by people\u00a0with the shortest path exactly equal\u00a0to\u00a0k with you. Given your\u00a0id and the level of videos, return the list of videos ordered by their frequencies (increasing). For videos with the same frequency order them alphabetically from least to greatest.", + "examples": [ + "Example 1:\nInput: watchedVideos = [[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 1\nOutput: [\"B\",\"C\"] \nExplanation: \nYou have id = 0 (green color in the figure) and your friends are (yellow color in the figure):\nPerson with id = 1 -> watchedVideos = [\"C\"]\u00a0\nPerson with id = 2 -> watchedVideos = [\"B\",\"C\"]\u00a0\nThe frequencies of watchedVideos by your friends are:\u00a0\nB -> 1\u00a0\nC -> 2", + "Example 2:\nInput: watchedVideos = [[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 2\nOutput: [\"D\"]\nExplanation: \nYou have id = 0 (green color in the figure) and the only friend of your friends is the person with id = 3 (yellow color in the figure)." + ], + "constraints": "Constraints:\n\nn == watchedVideos.length ==\u00a0friends.length\n2 <= n\u00a0<= 100\n1 <=\u00a0watchedVideos[i].length <= 100\n1 <=\u00a0watchedVideos[i][j].length <= 8\n0 <= friends[i].length < n\n0 <= friends[i][j]\u00a0< n\n0 <= id < n\n1 <= level < n\nif\u00a0friends[i] contains j, then friends[j] contains i", + "tags": [ + "Array", + "Hash Table", + "Breadth-First Search", + "Graph", + "Sorting" + ], + "title-slug": "get-watched-videos-by-your-friends" + }, + { + "leetcode-id": 1312, + "title": "Minimum Insertion Steps to Make a String Palindrome", + "difficulty": 3, + "description": "Given a string s. In one step you can insert any character at any index of the string.\nReturn the minimum number of steps to make s\u00a0palindrome.\nA\u00a0Palindrome String\u00a0is one that reads the same backward as well as forward.", + "examples": [ + "Example 1:\nInput: s = \"zzazz\"\nOutput: 0\nExplanation: The string \"zzazz\" is already palindrome we do not need any insertions.", + "Example 2:\nInput: s = \"mbadm\"\nOutput: 2\nExplanation: String can be \"mbdadbm\" or \"mdbabdm\".", + "Example 3:\nInput: s = \"leetcode\"\nOutput: 5\nExplanation: Inserting 5 characters the string becomes \"leetcodocteel\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 500\ns consists of lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "minimum-insertion-steps-to-make-a-string-palindrome" + }, + { + "leetcode-id": 1313, + "title": "Decompress Run-Length Encoded List", + "difficulty": 1, + "description": "We are given a list nums of integers representing a list compressed with run-length encoding.\nConsider each adjacent pair\u00a0of elements [freq, val] = [nums[2*i], nums[2*i+1]]\u00a0(with i >= 0).\u00a0 For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list.\nReturn the decompressed list.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4]\nOutput: [2,4,4,4]\nExplanation: The first pair [1,2] means we have freq = 1 and val = 2 so we generate the array [2].\nThe second pair [3,4] means we have freq = 3 and val = 4 so we generate [4,4,4].\nAt the end the concatenation [2] + [4,4,4] is [2,4,4,4].", + "Example 2:\nInput: nums = [1,1,2,3]\nOutput: [1,3,3]" + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 100\nnums.length % 2 == 0\n1 <= nums[i] <= 100", + "tags": [ + "Array" + ], + "title-slug": "decompress-run-length-encoded-list" + }, + { + "leetcode-id": 1314, + "title": "Matrix Block Sum", + "difficulty": 2, + "description": "Given a m x n matrix mat and an integer k, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for:\n\ni - k <= r <= i + k,\nj - k <= c <= j + k, and\n(r, c) is a valid position in the matrix.", + "examples": [ + "Example 1:\nInput: mat = [[1,2,3],[4,5,6],[7,8,9]], k = 1\nOutput: [[12,21,16],[27,45,33],[24,39,28]]", + "Example 2:\nInput: mat = [[1,2,3],[4,5,6],[7,8,9]], k = 2\nOutput: [[45,45,45],[45,45,45],[45,45,45]]" + ], + "constraints": "Constraints:\n\nm ==\u00a0mat.length\nn ==\u00a0mat[i].length\n1 <= m, n, k <= 100\n1 <= mat[i][j] <= 100", + "tags": [ + "Array", + "Matrix", + "Prefix Sum" + ], + "title-slug": "matrix-block-sum" + }, + { + "leetcode-id": 1315, + "title": "Sum of Nodes with Even-Valued Grandparent", + "difficulty": 2, + "description": "Given the root of a binary tree, return the sum of values of nodes with an even-valued grandparent. If there are no nodes with an even-valued grandparent, return 0.\nA grandparent of a node is the parent of its parent if it exists.", + "examples": [ + "Example 1:\nInput: root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]\nOutput: 18\nExplanation: The red nodes are the nodes with even-value grandparent while the blue nodes are the even-value grandparents.", + "Example 2:\nInput: root = [1]\nOutput: 0" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n1 <= Node.val <= 100", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "sum-of-nodes-with-even-valued-grandparent" + }, + { + "leetcode-id": 1316, + "title": "Distinct Echo Substrings", + "difficulty": 3, + "description": "Return the number of distinct non-empty substrings of text\u00a0that can be written as the concatenation of some string with itself (i.e. it can be written as a + a\u00a0where a is some string).", + "examples": [ + "Example 1:\nInput: text = \"abcabcabc\"\nOutput: 3\nExplanation: The 3 substrings are \"abcabc\", \"bcabca\" and \"cabcab\".", + "Example 2:\nInput: text = \"leetcodeleetcode\"\nOutput: 2\nExplanation: The 2 substrings are \"ee\" and \"leetcodeleetcode\"." + ], + "constraints": "Constraints:\n\n1 <= text.length <= 2000\ntext\u00a0has only lowercase English letters.", + "tags": [ + "String", + "Trie", + "Rolling Hash", + "Hash Function" + ], + "title-slug": "distinct-echo-substrings" + }, + { + "leetcode-id": 1317, + "title": "Convert Integer to the Sum of Two No-Zero Integers", + "difficulty": 1, + "description": "No-Zero integer is a positive integer that does not contain any 0 in its decimal representation.\nGiven an integer n, return a list of two integers [a, b] where:\n\na and b are No-Zero integers.\na + b = n\n\nThe test cases are generated so that there is at least one valid solution. If there are many valid solutions, you can return any of them.", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: [1,1]\nExplanation: Let a = 1 and b = 1.\nBoth a and b are no-zero integers, and a + b = 2 = n.", + "Example 2:\nInput: n = 11\nOutput: [2,9]\nExplanation: Let a = 2 and b = 9.\nBoth a and b are no-zero integers, and a + b = 9 = n.\nNote that there are other valid answers as [8, 3] that can be accepted." + ], + "constraints": "Constraints:\n\n2 <= n <= 10^4", + "tags": [ + "Math" + ], + "title-slug": "convert-integer-to-the-sum-of-two-no-zero-integers" + }, + { + "leetcode-id": 1318, + "title": "Minimum Flips to Make a OR b Equal to c", + "difficulty": 2, + "description": "Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make (\u00a0a OR b == c\u00a0). (bitwise OR operation).\r\nFlip operation\u00a0consists of change\u00a0any\u00a0single bit 1 to 0 or change the bit 0 to 1\u00a0in their binary representation.", + "examples": [ + "Example 1:\nInput: a = 2, b = 6, c = 5\r\nOutput: 3\r\nExplanation: After flips a = 1 , b = 4 , c = 5 such that (a OR b == c)", + "Example 2:\nInput: a = 4, b = 2, c = 7\r\nOutput: 1", + "Example 3:\nInput: a = 1, b = 2, c = 3\r\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= a <= 10^9\n1 <= b\u00a0<= 10^9\n1 <= c\u00a0<= 10^9", + "tags": [ + "Bit Manipulation" + ], + "title-slug": "minimum-flips-to-make-a-or-b-equal-to-c" + }, + { + "leetcode-id": 1319, + "title": "Number of Operations to Make Network Connected", + "difficulty": 2, + "description": "There are n computers numbered from 0 to n - 1 connected by ethernet cables connections forming a network where connections[i] = [ai, bi] represents a connection between computers ai and bi. Any computer can reach any other computer directly or indirectly through the network.\nYou are given an initial computer network connections. You can extract certain cables between two directly connected computers, and place them between any pair of disconnected computers to make them directly connected.\nReturn the minimum number of times you need to do this in order to make all the computers connected. If it is not possible, return -1.", + "examples": [ + "Example 1:\nInput: n = 4, connections = [[0,1],[0,2],[1,2]]\nOutput: 1\nExplanation: Remove cable between computer 1 and 2 and place between computers 1 and 3.", + "Example 2:\nInput: n = 6, connections = [[0,1],[0,2],[0,3],[1,2],[1,3]]\nOutput: 2", + "Example 3:\nInput: n = 6, connections = [[0,1],[0,2],[0,3],[1,2]]\nOutput: -1\nExplanation: There are not enough cables." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5\n1 <= connections.length <= min(n * (n - 1) / 2, 10^5)\nconnections[i].length == 2\n0 <= ai, bi < n\nai != bi\nThere are no repeated connections.\nNo two computers are connected by more than one cable.", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Graph" + ], + "title-slug": "number-of-operations-to-make-network-connected" + }, + { + "leetcode-id": 1320, + "title": "Minimum Distance to Type a Word Using Two Fingers", + "difficulty": 3, + "description": "You have a keyboard layout as shown above in the X-Y plane, where each English uppercase letter is located at some coordinate.\n\nFor example, the letter 'A' is located at coordinate (0, 0), the letter 'B' is located at coordinate (0, 1), the letter 'P' is located at coordinate (2, 3) and the letter 'Z' is located at coordinate (4, 1).\n\nGiven the string word, return the minimum total distance to type such string using only two fingers.\nThe distance between coordinates (x1, y1) and (x2, y2) is |x1 - x2| + |y1 - y2|.\nNote that the initial positions of your two fingers are considered free so do not count towards your total distance, also your two fingers do not have to start at the first letter or the first two letters.", + "examples": [ + "Example 1:\nInput: word = \"CAKE\"\nOutput: 3\nExplanation: Using two fingers, one optimal way to type \"CAKE\" is: \nFinger 1 on letter 'C' -> cost = 0 \nFinger 1 on letter 'A' -> cost = Distance from letter 'C' to letter 'A' = 2 \nFinger 2 on letter 'K' -> cost = 0 \nFinger 2 on letter 'E' -> cost = Distance from letter 'K' to letter 'E' = 1 \nTotal distance = 3", + "Example 2:\nInput: word = \"HAPPY\"\nOutput: 6\nExplanation: Using two fingers, one optimal way to type \"HAPPY\" is:\nFinger 1 on letter 'H' -> cost = 0\nFinger 1 on letter 'A' -> cost = Distance from letter 'H' to letter 'A' = 2\nFinger 2 on letter 'P' -> cost = 0\nFinger 2 on letter 'P' -> cost = Distance from letter 'P' to letter 'P' = 0\nFinger 1 on letter 'Y' -> cost = Distance from letter 'A' to letter 'Y' = 4\nTotal distance = 6" + ], + "constraints": "Constraints:\n\n2 <= word.length <= 300\nword consists of uppercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "minimum-distance-to-type-a-word-using-two-fingers" + }, + { + "leetcode-id": 1323, + "title": "Maximum 69 Number", + "difficulty": 1, + "description": "You are given a positive integer num consisting only of digits 6 and 9.\nReturn the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).", + "examples": [ + "Example 1:\nInput: num = 9669\nOutput: 9969\nExplanation: \nChanging the first digit results in 6669.\nChanging the second digit results in 9969.\nChanging the third digit results in 9699.\nChanging the fourth digit results in 9666.\nThe maximum number is 9969.", + "Example 2:\nInput: num = 9996\nOutput: 9999\nExplanation: Changing the last digit 6 to 9 results in the maximum number.", + "Example 3:\nInput: num = 9999\nOutput: 9999\nExplanation: It is better not to apply any change." + ], + "constraints": "Constraints:\n\n1 <= num <= 10^4\nnum\u00a0consists of only 6 and 9 digits.", + "tags": [ + "Math", + "Greedy" + ], + "title-slug": "maximum-69-number" + }, + { + "leetcode-id": 1324, + "title": "Print Words Vertically", + "difficulty": 2, + "description": "Given a string s.\u00a0Return\u00a0all the words vertically in the same order in which they appear in s.\r\nWords are returned as a list of strings, complete with\u00a0spaces when is necessary. (Trailing spaces are not allowed).\r\nEach word would be put on only one column and that in one column there will be only one word.", + "examples": [ + "Example 1:\nInput: s = \"HOW ARE YOU\"\r\nOutput: [\"HAY\",\"ORO\",\"WEU\"]\r\nExplanation: Each word is printed vertically. \r\n \"HAY\"\r\n\u00a0\"ORO\"\r\n\u00a0\"WEU\"", + "Example 2:\nInput: s = \"TO BE OR NOT TO BE\"\r\nOutput: [\"TBONTB\",\"OEROOE\",\" T\"]\r\nExplanation: Trailing spaces is not allowed. \r\n\"TBONTB\"\r\n\"OEROOE\"\r\n\" T\"", + "Example 3:\nInput: s = \"CONTEST IS COMING\"\r\nOutput: [\"CIC\",\"OSO\",\"N M\",\"T I\",\"E N\",\"S G\",\"T\"]" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 200\ns\u00a0contains only upper case English letters.\nIt's guaranteed that there is only one\u00a0space between 2 words.", + "tags": [ + "Array", + "String", + "Simulation" + ], + "title-slug": "print-words-vertically" + }, + { + "leetcode-id": 1325, + "title": "Delete Leaves With a Given Value", + "difficulty": 2, + "description": "Given a binary tree root and an integer target, delete all the leaf nodes with value target.\nNote that once you delete a leaf node with value target, if its parent node becomes a leaf node and has the value target, it should also be deleted (you need to continue doing that until you cannot).", + "examples": [ + "Example 1:\nInput: root = [1,2,3,2,null,2,4], target = 2\nOutput: [1,null,3,null,4]\nExplanation: Leaf nodes in green with value (target = 2) are removed (Picture in left). \nAfter removing, new nodes become leaf nodes with value (target = 2) (Picture in center).", + "Example 2:\nInput: root = [1,3,3,3,2], target = 3\nOutput: [1,3,null,null,2]", + "Example 3:\nInput: root = [1,2,null,2,null,2], target = 2\nOutput: [1]\nExplanation: Leaf nodes in green with value (target = 2) are removed at each step." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 3000].\n1 <= Node.val, target <= 1000", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "delete-leaves-with-a-given-value" + }, + { + "leetcode-id": 1326, + "title": "Minimum Number of Taps to Open to Water a Garden", + "difficulty": 3, + "description": "There is a one-dimensional garden on the x-axis. The garden starts at the point 0 and ends at the point n. (i.e., the\u00a0length of the garden is n).\nThere are n + 1 taps located at points [0, 1, ..., n] in the garden.\nGiven an integer n and an integer array ranges of length n + 1 where ranges[i] (0-indexed) means the i-th tap can water the area [i - ranges[i], i + ranges[i]] if it was open.\nReturn the minimum number of taps that should be open to water the whole garden, If the garden cannot be watered return -1.", + "examples": [ + "Example 1:\nInput: n = 5, ranges = [3,4,1,1,0,0]\nOutput: 1\nExplanation: The tap at point 0 can cover the interval [-3,3]\nThe tap at point 1 can cover the interval [-3,5]\nThe tap at point 2 can cover the interval [1,3]\nThe tap at point 3 can cover the interval [2,4]\nThe tap at point 4 can cover the interval [4,4]\nThe tap at point 5 can cover the interval [5,5]\nOpening Only the second tap will water the whole garden [0,5]", + "Example 2:\nInput: n = 3, ranges = [0,0,0,0]\nOutput: -1\nExplanation: Even if you activate all the four taps you cannot water the whole garden." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^4\nranges.length == n + 1\n0 <= ranges[i] <= 100", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "minimum-number-of-taps-to-open-to-water-a-garden" + }, + { + "leetcode-id": 1328, + "title": "Break a Palindrome", + "difficulty": 2, + "description": "Given a palindromic string of lowercase English letters palindrome, replace exactly one character with any lowercase English letter so that the resulting string is not a palindrome and that it is the lexicographically smallest one possible.\nReturn the resulting string. If there is no way to replace a character to make it not a palindrome, return an empty string.\nA string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, a has a character strictly smaller than the corresponding character in b. For example, \"abcc\" is lexicographically smaller than \"abcd\" because the first position they differ is at the fourth character, and 'c' is smaller than 'd'.", + "examples": [ + "Example 1:\nInput: palindrome = \"abccba\"\nOutput: \"aaccba\"\nExplanation: There are many ways to make \"abccba\" not a palindrome, such as \"zbccba\", \"aaccba\", and \"abacba\".\nOf all the ways, \"aaccba\" is the lexicographically smallest.", + "Example 2:\nInput: palindrome = \"a\"\nOutput: \"\"\nExplanation: There is no way to replace a single character to make \"a\" not a palindrome, so return an empty string." + ], + "constraints": "Constraints:\n\n1 <= palindrome.length <= 1000\npalindrome consists of only lowercase English letters.", + "tags": [ + "String", + "Greedy" + ], + "title-slug": "break-a-palindrome" + }, + { + "leetcode-id": 1329, + "title": "Sort the Matrix Diagonally", + "difficulty": 2, + "description": "A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix's end. For example, the matrix diagonal starting from mat[2][0], where mat is a 6 x 3 matrix, includes cells mat[2][0], mat[3][1], and mat[4][2].\nGiven an m x n matrix mat of integers, sort each matrix diagonal in ascending order and return the resulting matrix.", + "examples": [ + "Example 1:\nInput: mat = [[3,3,1,1],[2,2,1,2],[1,1,1,2]]\nOutput: [[1,1,1,1],[1,2,2,2],[1,2,3,3]]", + "Example 2:\nInput: mat = [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]]\nOutput: [[5,17,4,1,52,7],[11,11,25,45,8,69],[14,23,25,44,58,15],[22,27,31,36,50,66],[84,28,75,33,55,68]]" + ], + "constraints": "Constraints:\n\nm == mat.length\nn == mat[i].length\n1 <= m, n <= 100\n1 <= mat[i][j] <= 100", + "tags": [ + "Array", + "Sorting", + "Matrix" + ], + "title-slug": "sort-the-matrix-diagonally" + }, + { + "leetcode-id": 1330, + "title": "Reverse Subarray To Maximize Array Value", + "difficulty": 3, + "description": "You are given an integer array nums. The value of this array is defined as the sum of |nums[i] - nums[i + 1]| for all 0 <= i < nums.length - 1.\nYou are allowed to select any subarray of the given array and reverse it. You can perform this operation only once.\nFind maximum possible value of the final array.", + "examples": [ + "Example 1:\nInput: nums = [2,3,1,5,4]\nOutput: 10\nExplanation: By reversing the subarray [3,1,5] the array becomes [2,5,1,3,4] whose value is 10.", + "Example 2:\nInput: nums = [2,4,9,24,2,1,10]\nOutput: 68" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 3 * 10^4\n-10^5 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Math", + "Greedy" + ], + "title-slug": "reverse-subarray-to-maximize-array-value" + }, + { + "leetcode-id": 1331, + "title": "Rank Transform of an Array", + "difficulty": 1, + "description": "Given an array of integers\u00a0arr, replace each element with its rank.\nThe rank represents how large the element is. The rank has the following rules:\n\nRank is an integer starting from 1.\nThe larger the element, the larger the rank. If two elements are equal, their rank must be the same.\nRank should be as small as possible.", + "examples": [ + "Example 1:\nInput: arr = [40,10,20,30]\nOutput: [4,1,2,3]\nExplanation: 40 is the largest element. 10 is the smallest. 20 is the second smallest. 30 is the third smallest.", + "Example 2:\nInput: arr = [100,100,100]\nOutput: [1,1,1]\nExplanation: Same elements share the same rank.", + "Example 3:\nInput: arr = [37,12,28,9,100,56,80,5,12]\nOutput: [5,3,4,2,8,6,7,1,3]" + ], + "constraints": "Constraints:\n\n0 <= arr.length <= 10^5\n-10^9\u00a0<= arr[i] <= 10^9", + "tags": [ + "Array", + "Hash Table", + "Sorting" + ], + "title-slug": "rank-transform-of-an-array" + }, + { + "leetcode-id": 1332, + "title": "Remove Palindromic Subsequences", + "difficulty": 1, + "description": "You are given a string s consisting only of letters 'a' and 'b'. In a single step you can remove one palindromic subsequence from s.\nReturn the minimum number of steps to make the given string empty.\nA string is a subsequence of a given string if it is generated by deleting some characters of a given string without changing its order. Note that a subsequence does not necessarily need to be contiguous.\nA string is called palindrome if is one that reads the same backward as well as forward.", + "examples": [ + "Example 1:\nInput: s = \"ababa\"\nOutput: 1\nExplanation: s is already a palindrome, so its entirety can be removed in a single step.", + "Example 2:\nInput: s = \"abb\"\nOutput: 2\nExplanation: \"abb\" -> \"bb\" -> \"\". \nRemove palindromic subsequence \"a\" then \"bb\".", + "Example 3:\nInput: s = \"baabb\"\nOutput: 2\nExplanation: \"baabb\" -> \"b\" -> \"\". \nRemove palindromic subsequence \"baab\" then \"b\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns[i] is either 'a' or 'b'.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "remove-palindromic-subsequences" + }, + { + "leetcode-id": 1333, + "title": "Filter Restaurants by Vegan-Friendly, Price and Distance", + "difficulty": 2, + "description": "Given the array restaurants where \u00a0restaurants[i] = [idi, ratingi, veganFriendlyi, pricei, distancei]. You have to filter the restaurants using three filters.\nThe veganFriendly filter will be either true (meaning you should only include restaurants with veganFriendlyi set to true)\u00a0or false\u00a0(meaning you can include any restaurant). In addition, you have the filters\u00a0maxPrice and maxDistance\u00a0which\u00a0are the maximum value for price and distance of restaurants you should consider respectively.\nReturn the array of restaurant IDs after filtering, ordered by rating from highest to lowest. For restaurants with the same rating, order them by id from highest to lowest. For simplicity veganFriendlyi and veganFriendly take value 1 when it is true, and 0 when it is false.", + "examples": [ + "Example 1:\nInput: restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 1, maxPrice = 50, maxDistance = 10\nOutput: [3,1,5] \nExplanation: \nThe restaurants are:\nRestaurant 1 [id=1, rating=4, veganFriendly=1, price=40, distance=10]\nRestaurant 2 [id=2, rating=8, veganFriendly=0, price=50, distance=5]\nRestaurant 3 [id=3, rating=8, veganFriendly=1, price=30, distance=4]\nRestaurant 4 [id=4, rating=10, veganFriendly=0, price=10, distance=3]\nRestaurant 5 [id=5, rating=1, veganFriendly=1, price=15, distance=1] \nAfter filter restaurants with veganFriendly = 1, maxPrice = 50 and maxDistance = 10 we have restaurant 3, restaurant 1 and restaurant 5 (ordered by rating from highest to lowest).", + "Example 2:\nInput: restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 50, maxDistance = 10\nOutput: [4,3,2,1,5]\nExplanation: The restaurants are the same as in example 1, but in this case the filter veganFriendly = 0, therefore all restaurants are considered.", + "Example 3:\nInput: restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 30, maxDistance = 3\nOutput: [4,5]" + ], + "constraints": "Constraints:\n\n1 <=\u00a0restaurants.length <= 10^4\nrestaurants[i].length == 5\n1 <=\u00a0idi, ratingi, pricei, distancei <= 10^5\n1 <=\u00a0maxPrice,\u00a0maxDistance <= 10^5\nveganFriendlyi and\u00a0veganFriendly\u00a0are\u00a00 or 1.\nAll idi are distinct.", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "filter-restaurants-by-vegan-friendly-price-and-distance" + }, + { + "leetcode-id": 1334, + "title": "Find the City With the Smallest Number of Neighbors at a Threshold Distance", + "difficulty": 2, + "description": "There are n cities numbered from 0 to n-1. Given the array edges where edges[i] = [fromi, toi, weighti] represents a bidirectional and weighted edge between cities fromi and toi, and given the integer distanceThreshold.\nReturn the city with the smallest number of cities that are reachable through some path and whose distance is at most distanceThreshold, If there are multiple such cities, return the city with the greatest number.\nNotice that the distance of a path connecting cities i and j is equal to the sum of the edges' weights along that path.", + "examples": [ + "Example 1:\nInput: n = 4, edges = [[0,1,3],[1,2,1],[1,3,4],[2,3,1]], distanceThreshold = 4\nOutput: 3\nExplanation: The figure above describes the graph.\u00a0\nThe neighboring cities at a distanceThreshold = 4 for each city are:\nCity 0 -> [City 1, City 2]\u00a0\nCity 1 -> [City 0, City 2, City 3]\u00a0\nCity 2 -> [City 0, City 1, City 3]\u00a0\nCity 3 -> [City 1, City 2]\u00a0\nCities 0 and 3 have 2 neighboring cities at a distanceThreshold = 4, but we have to return city 3 since it has the greatest number.", + "Example 2:\nInput: n = 5, edges = [[0,1,2],[0,4,8],[1,2,3],[1,4,2],[2,3,1],[3,4,1]], distanceThreshold = 2\nOutput: 0\nExplanation: The figure above describes the graph.\u00a0\nThe neighboring cities at a distanceThreshold = 2 for each city are:\nCity 0 -> [City 1]\u00a0\nCity 1 -> [City 0, City 4]\u00a0\nCity 2 -> [City 3, City 4]\u00a0\nCity 3 -> [City 2, City 4]\nCity 4 -> [City 1, City 2, City 3]\u00a0\nThe city 0 has 1 neighboring city at a distanceThreshold = 2." + ], + "constraints": "Constraints:\n\n2 <= n <= 100\n1 <= edges.length <= n * (n - 1) / 2\nedges[i].length == 3\n0 <= fromi < toi < n\n1 <= weighti,\u00a0distanceThreshold <= 10^4\nAll pairs (fromi, toi) are distinct.", + "tags": [ + "Dynamic Programming", + "Graph", + "Shortest Path" + ], + "title-slug": "find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance" + }, + { + "leetcode-id": 1335, + "title": "Minimum Difficulty of a Job Schedule", + "difficulty": 3, + "description": "You want to schedule a list of jobs in d days. Jobs are dependent (i.e To work on the i^th job, you have to finish all the jobs j where 0 <= j < i).\nYou have to finish at least one task every day. The difficulty of a job schedule is the sum of difficulties of each day of the d days. The difficulty of a day is the maximum difficulty of a job done on that day.\nYou are given an integer array jobDifficulty and an integer d. The difficulty of the i^th job is jobDifficulty[i].\nReturn the minimum difficulty of a job schedule. If you cannot find a schedule for the jobs return -1.", + "examples": [ + "Example 1:\nInput: jobDifficulty = [6,5,4,3,2,1], d = 2\nOutput: 7\nExplanation: First day you can finish the first 5 jobs, total difficulty = 6.\nSecond day you can finish the last job, total difficulty = 1.\nThe difficulty of the schedule = 6 + 1 = 7", + "Example 2:\nInput: jobDifficulty = [9,9,9], d = 4\nOutput: -1\nExplanation: If you finish a job per day you will still have a free day. you cannot find a schedule for the given jobs.", + "Example 3:\nInput: jobDifficulty = [1,1,1], d = 3\nOutput: 3\nExplanation: The schedule is one job per day. total difficulty will be 3." + ], + "constraints": "Constraints:\n\n1 <= jobDifficulty.length <= 300\n0 <= jobDifficulty[i] <= 1000\n1 <= d <= 10", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "minimum-difficulty-of-a-job-schedule" + }, + { + "leetcode-id": 1337, + "title": "The K Weakest Rows in a Matrix", + "difficulty": 1, + "description": "You are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1's will appear to the left of all the 0's in each row.\nA row i is weaker than a row j if one of the following is true:\n\nThe number of soldiers in row i is less than the number of soldiers in row j.\nBoth rows have the same number of soldiers and i < j.\n\nReturn the indices of the k weakest rows in the matrix ordered from weakest to strongest.", + "examples": [ + "Example 1:\nInput: mat = \n[[1,1,0,0,0],\n [1,1,1,1,0],\n [1,0,0,0,0],\n [1,1,0,0,0],\n [1,1,1,1,1]], \nk = 3\nOutput: [2,0,3]\nExplanation: \nThe number of soldiers in each row is: \n- Row 0: 2 \n- Row 1: 4 \n- Row 2: 1 \n- Row 3: 2 \n- Row 4: 5 \nThe rows ordered from weakest to strongest are [2,0,3,1,4].", + "Example 2:\nInput: mat = \n[[1,0,0,0],\n [1,1,1,1],\n [1,0,0,0],\n [1,0,0,0]], \nk = 2\nOutput: [0,2]\nExplanation: \nThe number of soldiers in each row is: \n- Row 0: 1 \n- Row 1: 4 \n- Row 2: 1 \n- Row 3: 1 \nThe rows ordered from weakest to strongest are [0,2,3,1]." + ], + "constraints": "Constraints:\n\nm == mat.length\nn == mat[i].length\n2 <= n, m <= 100\n1 <= k <= m\nmatrix[i][j] is either 0 or 1.", + "tags": [ + "Array", + "Binary Search", + "Sorting", + "Heap (Priority Queue)", + "Matrix" + ], + "title-slug": "the-k-weakest-rows-in-a-matrix" + }, + { + "leetcode-id": 1338, + "title": "Reduce Array Size to The Half", + "difficulty": 2, + "description": "You are given an integer array arr. You can choose a set of integers and remove all the occurrences of these integers in the array.\nReturn the minimum size of the set so that at least half of the integers of the array are removed.", + "examples": [ + "Example 1:\nInput: arr = [3,3,3,3,5,5,5,2,2,7]\nOutput: 2\nExplanation: Choosing {3,7} will make the new array [5,5,5,2,2] which has size 5 (i.e equal to half of the size of the old array).\nPossible sets of size 2 are {3,5},{3,2},{5,2}.\nChoosing set {2,7} is not possible as it will make the new array [3,3,3,3,5,5,5] which has a size greater than half of the size of the old array.", + "Example 2:\nInput: arr = [7,7,7,7,7,7]\nOutput: 1\nExplanation: The only possible set you can choose is {7}. This will make the new array empty." + ], + "constraints": "Constraints:\n\n2 <= arr.length <= 10^5\narr.length is even.\n1 <= arr[i] <= 10^5", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "reduce-array-size-to-the-half" + }, + { + "leetcode-id": 1339, + "title": "Maximum Product of Splitted Binary Tree", + "difficulty": 2, + "description": "Given the root of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.\nReturn the maximum product of the sums of the two subtrees. Since the answer may be too large, return it modulo 10^9 + 7.\nNote that you need to maximize the answer before taking the mod and not after taking it.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,4,5,6]\nOutput: 110\nExplanation: Remove the red edge and get 2 binary trees with sum 11 and 10. Their product is 110 (11*10)", + "Example 2:\nInput: root = [1,null,2,3,4,null,null,5,6]\nOutput: 90\nExplanation: Remove the red edge and get 2 binary trees with sum 15 and 6.Their product is 90 (15*6)" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [2, 5 * 10^4].\n1 <= Node.val <= 10^4", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "maximum-product-of-splitted-binary-tree" + }, + { + "leetcode-id": 1340, + "title": "Jump Game V", + "difficulty": 3, + "description": "Given an array of\u00a0integers arr and an integer d. In one step you can jump from index i to index:\n\ni + x where:\u00a0i + x < arr.length and 0 <\u00a0x <= d.\ni - x where:\u00a0i - x >= 0 and 0 <\u00a0x <= d.\n\nIn addition, you can only jump from index i to index j\u00a0if arr[i] > arr[j] and arr[i] > arr[k] for all indices k between i and j (More formally min(i,\u00a0j) < k < max(i, j)).\nYou can choose any index of the array and start jumping. Return the maximum number of indices\u00a0you can visit.\nNotice that you can not jump outside of the array at any time.", + "examples": [ + "Example 1:\nInput: arr = [6,4,14,6,8,13,9,7,10,6,12], d = 2\nOutput: 4\nExplanation: You can start at index 10. You can jump 10 --> 8 --> 6 --> 7 as shown.\nNote that if you start at index 6 you can only jump to index 7. You cannot jump to index 5 because 13 > 9. You cannot jump to index 4 because index 5 is between index 4 and 6 and 13 > 9.\nSimilarly You cannot jump from index 3 to index 2 or index 1.", + "Example 2:\nInput: arr = [3,3,3,3,3], d = 3\nOutput: 1\nExplanation: You can start at any index. You always cannot jump to any index.", + "Example 3:\nInput: arr = [7,6,5,4,3,2,1], d = 1\nOutput: 7\nExplanation: Start at index 0. You can visit all the indicies." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 1000\n1 <= arr[i] <= 10^5\n1 <= d <= arr.length", + "tags": [ + "Array", + "Dynamic Programming", + "Sorting" + ], + "title-slug": "jump-game-v" + }, + { + "leetcode-id": 1342, + "title": "Number of Steps to Reduce a Number to Zero", + "difficulty": 1, + "description": "Given an integer num, return the number of steps to reduce it to zero.\nIn one step, if the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.", + "examples": [ + "Example 1:\nInput: num = 14\nOutput: 6\nExplanation:\u00a0\nStep 1) 14 is even; divide by 2 and obtain 7.\u00a0\nStep 2) 7 is odd; subtract 1 and obtain 6.\nStep 3) 6 is even; divide by 2 and obtain 3.\u00a0\nStep 4) 3 is odd; subtract 1 and obtain 2.\u00a0\nStep 5) 2 is even; divide by 2 and obtain 1.\u00a0\nStep 6) 1 is odd; subtract 1 and obtain 0.", + "Example 2:\nInput: num = 8\nOutput: 4\nExplanation:\u00a0\nStep 1) 8 is even; divide by 2 and obtain 4.\u00a0\nStep 2) 4 is even; divide by 2 and obtain 2.\u00a0\nStep 3) 2 is even; divide by 2 and obtain 1.\u00a0\nStep 4) 1 is odd; subtract 1 and obtain 0.", + "Example 3:\nInput: num = 123\nOutput: 12" + ], + "constraints": "Constraints:\n\n0 <= num <= 10^6", + "tags": [ + "Math", + "Bit Manipulation" + ], + "title-slug": "number-of-steps-to-reduce-a-number-to-zero" + }, + { + "leetcode-id": 1343, + "title": "Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold", + "difficulty": 2, + "description": "Given an array of integers arr and two integers k and threshold, return the number of sub-arrays of size k and average greater than or equal to threshold.", + "examples": [ + "Example 1:\nInput: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4\nOutput: 3\nExplanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively. All other sub-arrays of size 3 have averages less than 4 (the threshold).", + "Example 2:\nInput: arr = [11,13,17,23,29,31,7,5,2,3], k = 3, threshold = 5\nOutput: 6\nExplanation: The first 6 sub-arrays of size 3 have averages greater than 5. Note that averages are not integers." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^5\n1 <= arr[i] <= 10^4\n1 <= k <= arr.length\n0 <= threshold <= 10^4", + "tags": [ + "Array", + "Sliding Window" + ], + "title-slug": "number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold" + }, + { + "leetcode-id": 1344, + "title": "Angle Between Hands of a Clock", + "difficulty": 2, + "description": "Given two numbers, hour and minutes, return the smaller angle (in degrees) formed between the hour and the minute hand.\nAnswers within 10^-5 of the actual value will be accepted as correct.", + "examples": [ + "Example 1:\nInput: hour = 12, minutes = 30\nOutput: 165", + "Example 2:\nInput: hour = 3, minutes = 30\nOutput: 75", + "Example 3:\nInput: hour = 3, minutes = 15\nOutput: 7.5" + ], + "constraints": "Constraints:\n\n1 <= hour <= 12\n0 <= minutes <= 59", + "tags": [ + "Math" + ], + "title-slug": "angle-between-hands-of-a-clock" + }, + { + "leetcode-id": 1345, + "title": "Jump Game IV", + "difficulty": 3, + "description": "Given an array of\u00a0integers arr, you are initially positioned at the first index of the array.\nIn one step you can jump from index i to index:\n\ni + 1 where:\u00a0i + 1 < arr.length.\ni - 1 where:\u00a0i - 1 >= 0.\nj where: arr[i] == arr[j] and i != j.\n\nReturn the minimum number of steps to reach the last index of the array.\nNotice that you can not jump outside of the array at any time.", + "examples": [ + "Example 1:\nInput: arr = [100,-23,-23,404,100,23,23,23,3,404]\nOutput: 3\nExplanation: You need three jumps from index 0 --> 4 --> 3 --> 9. Note that index 9 is the last index of the array.", + "Example 2:\nInput: arr = [7]\nOutput: 0\nExplanation: Start index is the last index. You do not need to jump.", + "Example 3:\nInput: arr = [7,6,9,6,9,6,9,7]\nOutput: 1\nExplanation: You can jump directly from index 0 to index 7 which is last index of the array." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 5 * 10^4\n-10^8 <= arr[i] <= 10^8", + "tags": [ + "Array", + "Hash Table", + "Breadth-First Search" + ], + "title-slug": "jump-game-iv" + }, + { + "leetcode-id": 1346, + "title": "Check If N and Its Double Exist", + "difficulty": 1, + "description": "Given an array arr of integers, check if there exist two indices i and j such that :\n\ni != j\n0 <= i, j < arr.length\narr[i] == 2 * arr[j]", + "examples": [ + "Example 1:\nInput: arr = [10,2,5,3]\nOutput: true\nExplanation: For i = 0 and j = 2, arr[i] == 10 == 2 * 5 == 2 * arr[j]", + "Example 2:\nInput: arr = [3,1,7,11]\nOutput: false\nExplanation: There is no i and j that satisfy the conditions." + ], + "constraints": "Constraints:\n\n2 <= arr.length <= 500\n-10^3 <= arr[i] <= 10^3", + "tags": [ + "Array", + "Hash Table", + "Two Pointers", + "Binary Search", + "Sorting" + ], + "title-slug": "check-if-n-and-its-double-exist" + }, + { + "leetcode-id": 1347, + "title": "Minimum Number of Steps to Make Two Strings Anagram", + "difficulty": 2, + "description": "You are given two strings of the same length s and t. In one step you can choose any character of t and replace it with another character.\nReturn the minimum number of steps to make t an anagram of s.\nAn Anagram of a string is a string that contains the same characters with a different (or the same) ordering.", + "examples": [ + "Example 1:\nInput: s = \"bab\", t = \"aba\"\nOutput: 1\nExplanation: Replace the first 'a' in t with b, t = \"bba\" which is anagram of s.", + "Example 2:\nInput: s = \"leetcode\", t = \"practice\"\nOutput: 5\nExplanation: Replace 'p', 'r', 'a', 'i' and 'c' from t with proper characters to make t anagram of s.", + "Example 3:\nInput: s = \"anagram\", t = \"mangaar\"\nOutput: 0\nExplanation: \"anagram\" and \"mangaar\" are anagrams." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 5 * 10^4\ns.length == t.length\ns and t consist of lowercase English letters only.", + "tags": [ + "Hash Table", + "String", + "Counting" + ], + "title-slug": "minimum-number-of-steps-to-make-two-strings-anagram" + }, + { + "leetcode-id": 1348, + "title": "Tweet Counts Per Frequency", + "difficulty": 2, + "description": "A social media company is trying to monitor activity on their site by analyzing the number of tweets that occur in select periods of time. These periods can be partitioned into smaller time chunks based on a certain frequency (every minute, hour, or day).\nFor example, the period [10, 10000] (in seconds) would be partitioned into the following time chunks with these frequencies:\n\nEvery minute (60-second chunks): [10,69], [70,129], [130,189], ..., [9970,10000]\nEvery hour (3600-second chunks): [10,3609], [3610,7209], [7210,10000]\nEvery day (86400-second chunks): [10,10000]\n\nNotice that the last chunk may be shorter than the specified frequency's chunk size and will always end with the end time of the period (10000 in the above example).\nDesign and implement an API to help the company with their analysis.\nImplement the TweetCounts class:\n\nTweetCounts() Initializes the TweetCounts object.\nvoid recordTweet(String tweetName, int time) Stores the tweetName at the recorded time (in seconds).\nList getTweetCountsPerFrequency(String freq, String tweetName, int startTime, int endTime) Returns a list of integers representing the number of tweets with tweetName in each time chunk for the given period of time [startTime, endTime] (in seconds) and frequency freq.\n\t\nfreq is one of \"minute\", \"hour\", or \"day\" representing a frequency of every minute, hour, or day respectively.\n\n\n\n\u00a0\nExample:\n\nInput\n[\"TweetCounts\",\"recordTweet\",\"recordTweet\",\"recordTweet\",\"getTweetCountsPerFrequency\",\"getTweetCountsPerFrequency\",\"recordTweet\",\"getTweetCountsPerFrequency\"]\n[[],[\"tweet3\",0],[\"tweet3\",60],[\"tweet3\",10],[\"minute\",\"tweet3\",0,59],[\"minute\",\"tweet3\",0,60],[\"tweet3\",120],[\"hour\",\"tweet3\",0,210]]\n\nOutput\n[null,null,null,null,[2],[2,1],null,[4]]\n\nExplanation\nTweetCounts tweetCounts = new TweetCounts();\ntweetCounts.recordTweet(\"tweet3\", 0); // New tweet \"tweet3\" at time 0\ntweetCounts.recordTweet(\"tweet3\", 60); // New tweet \"tweet3\" at time 60\ntweetCounts.recordTweet(\"tweet3\", 10); // New tweet \"tweet3\" at time 10\ntweetCounts.getTweetCountsPerFrequency(\"minute\", \"tweet3\", 0, 59); // return [2]; chunk [0,59] had 2 tweets\ntweetCounts.getTweetCountsPerFrequency(\"minute\", \"tweet3\", 0, 60); // return [2,1]; chunk [0,59] had 2 tweets, chunk [60,60] had 1 tweet\ntweetCounts.recordTweet(\"tweet3\", 120); // New tweet \"tweet3\" at time 120\ntweetCounts.getTweetCountsPerFrequency(\"hour\", \"tweet3\", 0, 210); // return [4]; chunk [0,210] had 4 tweets\n\n\u00a0\nConstraints:\n\n0 <= time, startTime, endTime <= 10^9\n0 <= endTime - startTime <= 10^4\nThere will be at most 10^4 calls in total to recordTweet and getTweetCountsPerFrequency.", + "examples": [], + "constraints": "Constraints:\n\n0 <= time, startTime, endTime <= 10^9\n0 <= endTime - startTime <= 10^4\nThere will be at most 10^4 calls in total to recordTweet and getTweetCountsPerFrequency.", + "tags": [ + "Hash Table", + "Binary Search", + "Design", + "Sorting", + "Ordered Set" + ], + "title-slug": "tweet-counts-per-frequency" + }, + { + "leetcode-id": 1349, + "title": "Maximum Students Taking Exam", + "difficulty": 3, + "description": "Given a m\u00a0* n\u00a0matrix seats\u00a0\u00a0that represent seats distributions\u00a0in a classroom.\u00a0If a seat\u00a0is\u00a0broken, it is denoted by '#' character otherwise it is denoted by a '.' character.\nStudents can see the answers of those sitting next to the left, right, upper left and upper right, but he cannot see the answers of the student sitting\u00a0directly in front or behind him. Return the maximum number of students that can take the exam together\u00a0without any cheating being possible..\nStudents must be placed in seats in good condition.", + "examples": [ + "Example 1:\nInput: seats = [[\"#\",\".\",\"#\",\"#\",\".\",\"#\"],\n\u00a0 [\".\",\"#\",\"#\",\"#\",\"#\",\".\"],\n\u00a0 [\"#\",\".\",\"#\",\"#\",\".\",\"#\"]]\nOutput: 4\nExplanation: Teacher can place 4 students in available seats so they don't cheat on the exam.", + "Example 2:\nInput: seats = [[\".\",\"#\"],\n\u00a0 [\"#\",\"#\"],\n\u00a0 [\"#\",\".\"],\n\u00a0 [\"#\",\"#\"],\n\u00a0 [\".\",\"#\"]]\nOutput: 3\nExplanation: Place all students in available seats.", + "Example 3:\nInput: seats = [[\"#\",\".\",\".\",\".\",\"#\"],\n\u00a0 [\".\",\"#\",\".\",\"#\",\".\"],\n\u00a0 [\".\",\".\",\"#\",\".\",\".\"],\n\u00a0 [\".\",\"#\",\".\",\"#\",\".\"],\n\u00a0 [\"#\",\".\",\".\",\".\",\"#\"]]\nOutput: 10\nExplanation: Place students in available seats in column 1, 3 and 5." + ], + "constraints": "Constraints:\n\nseats\u00a0contains only characters\u00a0'.'\u00a0and'#'.\nm ==\u00a0seats.length\nn ==\u00a0seats[i].length\n1 <= m <= 8\n1 <= n <= 8", + "tags": [ + "Array", + "Dynamic Programming", + "Bit Manipulation", + "Matrix", + "Bitmask" + ], + "title-slug": "maximum-students-taking-exam" + }, + { + "leetcode-id": 1351, + "title": "Count Negative Numbers in a Sorted Matrix", + "difficulty": 1, + "description": "Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.", + "examples": [ + "Example 1:\nInput: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]\nOutput: 8\nExplanation: There are 8 negatives number in the matrix.", + "Example 2:\nInput: grid = [[3,2],[1,0]]\nOutput: 0" + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 100\n-100 <= grid[i][j] <= 100\n\n\u00a0\nFollow up: Could you find an O(n + m) solution?", + "tags": [ + "Array", + "Binary Search", + "Matrix" + ], + "title-slug": "count-negative-numbers-in-a-sorted-matrix" + }, + { + "leetcode-id": 1352, + "title": "Product of the Last K Numbers", + "difficulty": 2, + "description": "Design an algorithm that accepts a stream of integers and retrieves the product of the last k integers of the stream.\nImplement the ProductOfNumbers class:\n\nProductOfNumbers() Initializes the object with an empty stream.\nvoid add(int num) Appends the integer num to the stream.\nint getProduct(int k) Returns the product of the last k numbers in the current list. You can assume that always the current list has at least k numbers.\n\nThe test cases are generated so that, at any time, the product of any contiguous sequence of numbers will fit into a single 32-bit integer without overflowing.\n\u00a0\nExample:\n\nInput\n[\"ProductOfNumbers\",\"add\",\"add\",\"add\",\"add\",\"add\",\"getProduct\",\"getProduct\",\"getProduct\",\"add\",\"getProduct\"]\n[[],[3],[0],[2],[5],[4],[2],[3],[4],[8],[2]]\n\nOutput\n[null,null,null,null,null,null,20,40,0,null,32]\n\nExplanation\nProductOfNumbers productOfNumbers = new ProductOfNumbers();\nproductOfNumbers.add(3); // [3]\nproductOfNumbers.add(0); // [3,0]\nproductOfNumbers.add(2); // [3,0,2]\nproductOfNumbers.add(5); // [3,0,2,5]\nproductOfNumbers.add(4); // [3,0,2,5,4]\nproductOfNumbers.getProduct(2); // return 20. The product of the last 2 numbers is 5 * 4 = 20\nproductOfNumbers.getProduct(3); // return 40. The product of the last 3 numbers is 2 * 5 * 4 = 40\nproductOfNumbers.getProduct(4); // return 0. The product of the last 4 numbers is 0 * 2 * 5 * 4 = 0\nproductOfNumbers.add(8); // [3,0,2,5,4,8]\nproductOfNumbers.getProduct(2); // return 32. The product of the last 2 numbers is 4 * 8 = 32 \n\n\u00a0\nConstraints:\n\n0 <= num <= 100\n1 <= k <= 4 * 10^4\nAt most 4 * 10^4 calls will be made to add and getProduct.\nThe product of the stream at any point in time will fit in a 32-bit integer.", + "examples": [], + "constraints": "Constraints:\n\n0 <= num <= 100\n1 <= k <= 4 * 10^4\nAt most 4 * 10^4 calls will be made to add and getProduct.\nThe product of the stream at any point in time will fit in a 32-bit integer.", + "tags": [ + "Array", + "Math", + "Design", + "Queue", + "Data Stream" + ], + "title-slug": "product-of-the-last-k-numbers" + }, + { + "leetcode-id": 1353, + "title": "Maximum Number of Events That Can Be Attended", + "difficulty": 2, + "description": "You are given an array of events where events[i] = [startDayi, endDayi]. Every event i starts at startDayi and ends at endDayi.\nYou can attend an event i at any day d where startTimei <= d <= endTimei. You can only attend one event at any time d.\nReturn the maximum number of events you can attend.", + "examples": [ + "Example 1:\nInput: events = [[1,2],[2,3],[3,4]]\nOutput: 3\nExplanation: You can attend all the three events.\nOne way to attend them all is as shown.\nAttend the first event on day 1.\nAttend the second event on day 2.\nAttend the third event on day 3.", + "Example 2:\nInput: events= [[1,2],[2,3],[3,4],[1,2]]\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= events.length <= 10^5\nevents[i].length == 2\n1 <= startDayi <= endDayi <= 10^5", + "tags": [ + "Array", + "Greedy", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "maximum-number-of-events-that-can-be-attended" + }, + { + "leetcode-id": 1354, + "title": "Construct Target Array With Multiple Sums", + "difficulty": 3, + "description": "You are given an array target of n integers. From a starting array arr consisting of n 1's, you may perform the following procedure :\n\nlet x be the sum of all elements currently in your array.\nchoose index i, such that 0 <= i < n and set the value of arr at index i to x.\nYou may repeat this procedure as many times as needed.\n\nReturn true if it is possible to construct the target array from arr, otherwise, return false.", + "examples": [ + "Example 1:\nInput: target = [9,3,5]\nOutput: true\nExplanation: Start with arr = [1, 1, 1] \n[1, 1, 1], sum = 3 choose index 1\n[1, 3, 1], sum = 5 choose index 2\n[1, 3, 5], sum = 9 choose index 0\n[9, 3, 5] Done", + "Example 2:\nInput: target = [1,1,1,2]\nOutput: false\nExplanation: Impossible to create target array from [1,1,1,1].", + "Example 3:\nInput: target = [8,5]\nOutput: true" + ], + "constraints": "Constraints:\n\nn == target.length\n1 <= n <= 5 * 10^4\n1 <= target[i] <= 10^9", + "tags": [ + "Array", + "Heap (Priority Queue)" + ], + "title-slug": "construct-target-array-with-multiple-sums" + }, + { + "leetcode-id": 1356, + "title": "Sort Integers by The Number of 1 Bits", + "difficulty": 1, + "description": "You are given an integer array arr. Sort the integers in the array\u00a0in ascending order by the number of 1's\u00a0in their binary representation and in case of two or more integers have the same number of 1's you have to sort them in ascending order.\nReturn the array after sorting it.", + "examples": [ + "Example 1:\nInput: arr = [0,1,2,3,4,5,6,7,8]\nOutput: [0,1,2,4,8,3,5,6,7]\nExplantion: [0] is the only integer with 0 bits.\n[1,2,4,8] all have 1 bit.\n[3,5,6] have 2 bits.\n[7] has 3 bits.\nThe sorted array by bits is [0,1,2,4,8,3,5,6,7]", + "Example 2:\nInput: arr = [1024,512,256,128,64,32,16,8,4,2,1]\nOutput: [1,2,4,8,16,32,64,128,256,512,1024]\nExplantion: All integers have 1 bit in the binary representation, you should just sort them in ascending order." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 500\n0 <= arr[i] <= 10^4", + "tags": [ + "Array", + "Bit Manipulation", + "Sorting", + "Counting" + ], + "title-slug": "sort-integers-by-the-number-of-1-bits" + }, + { + "leetcode-id": 1357, + "title": "Apply Discount Every n Orders", + "difficulty": 2, + "description": "There is a supermarket that is frequented by many customers. The products sold at the supermarket are represented as two parallel integer arrays products and prices, where the i^th product has an ID of products[i] and a price of prices[i].\nWhen a customer is paying, their bill is represented as two parallel integer arrays product and amount, where the j^th product they purchased has an ID of product[j], and amount[j] is how much of the product they bought. Their subtotal is calculated as the sum of each amount[j] * (price of the j^th product).\nThe supermarket decided to have a sale. Every n^th customer paying for their groceries will be given a percentage discount. The discount amount is given by discount, where they will be given discount percent off their subtotal. More formally, if their subtotal is bill, then they would actually pay bill * ((100 - discount) / 100).\nImplement the Cashier class:\n\nCashier(int n, int discount, int[] products, int[] prices) Initializes the object with n, the discount, and the products and their prices.\ndouble getBill(int[] product, int[] amount) Returns the final total of the bill with the discount applied (if any). Answers within 10^-5 of the actual value will be accepted.", + "examples": [ + "Example 1:\nInput\n[\"Cashier\",\"getBill\",\"getBill\",\"getBill\",\"getBill\",\"getBill\",\"getBill\",\"getBill\"]\n[[3,50,[1,2,3,4,5,6,7],[100,200,300,400,300,200,100]],[[1,2],[1,2]],[[3,7],[10,10]],[[1,2,3,4,5,6,7],[1,1,1,1,1,1,1]],[[4],[10]],[[7,3],[10,10]],[[7,5,3,1,6,4,2],[10,10,10,9,9,9,7]],[[2,3,5],[5,3,2]]]\nOutput\n[null,500.0,4000.0,800.0,4000.0,4000.0,7350.0,2500.0]\nExplanation\nCashier cashier = new Cashier(3,50,[1,2,3,4,5,6,7],[100,200,300,400,300,200,100]);\ncashier.getBill([1,2],[1,2]); // return 500.0. 1^st customer, no discount.\n // bill = 1 * 100 + 2 * 200 = 500.\ncashier.getBill([3,7],[10,10]); // return 4000.0. 2^nd customer, no discount.\n // bill = 10 * 300 + 10 * 100 = 4000.\ncashier.getBill([1,2,3,4,5,6,7],[1,1,1,1,1,1,1]); // return 800.0. 3^rd customer, 50% discount.\n // Original bill = 1600\n // Actual bill = 1600 * ((100 - 50) / 100) = 800.\ncashier.getBill([4],[10]); // return 4000.0. 4^th customer, no discount.\ncashier.getBill([7,3],[10,10]); // return 4000.0. 5^th customer, no discount.\ncashier.getBill([7,5,3,1,6,4,2],[10,10,10,9,9,9,7]); // return 7350.0. 6^th customer, 50% discount.\n // Original bill = 14700, but with\n // Actual bill = 14700 * ((100 - 50) / 100) = 7350.\ncashier.getBill([2,3,5],[5,3,2]); // return 2500.0. 7^th customer, no discount." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^4\n0 <= discount <= 100\n1 <= products.length <= 200\nprices.length == products.length\n1 <= products[i] <= 200\n1 <= prices[i] <= 1000\nThe elements in products are unique.\n1 <= product.length <= products.length\namount.length == product.length\nproduct[j] exists in products.\n1 <= amount[j] <= 1000\nThe elements of product are unique.\nAt most 1000 calls will be made to getBill.\nAnswers within 10^-5 of the actual value will be accepted.", + "tags": [ + "Array", + "Hash Table", + "Design" + ], + "title-slug": "apply-discount-every-n-orders" + }, + { + "leetcode-id": 1358, + "title": "Number of Substrings Containing All Three Characters", + "difficulty": 2, + "description": "Given a string s\u00a0consisting only of characters a, b and c.\nReturn the number of substrings containing at least\u00a0one occurrence of all these characters a, b and c.", + "examples": [ + "Example 1:\nInput: s = \"abcabc\"\nOutput: 10\nExplanation: The substrings containing\u00a0at least\u00a0one occurrence of the characters\u00a0a,\u00a0b\u00a0and\u00a0c are \"abc\", \"abca\", \"abcab\", \"abcabc\", \"bca\", \"bcab\", \"bcabc\", \"cab\", \"cabc\" and \"abc\" (again).", + "Example 2:\nInput: s = \"aaacb\"\nOutput: 3\nExplanation: The substrings containing\u00a0at least\u00a0one occurrence of the characters\u00a0a,\u00a0b\u00a0and\u00a0c are \"aaacb\", \"aacb\" and \"acb\".", + "Example 3:\nInput: s = \"abc\"\nOutput: 1" + ], + "constraints": "Constraints:\n\n3 <= s.length <= 5 x 10^4\ns\u00a0only consists of\u00a0a, b or c\u00a0characters.", + "tags": [ + "Hash Table", + "String", + "Sliding Window" + ], + "title-slug": "number-of-substrings-containing-all-three-characters" + }, + { + "leetcode-id": 1359, + "title": "Count All Valid Pickup and Delivery Options", + "difficulty": 3, + "description": "Given n orders,each order consists of a pickup and a delivery service.\nCount all valid pickup/delivery possible sequences such that delivery(i) is always after of\u00a0pickup(i).\u00a0\nSince the answer\u00a0may be too large,\u00a0return it modulo\u00a010^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: 1\nExplanation: Unique order (P1, D1), Delivery 1 always is after of Pickup 1.", + "Example 2:\nInput: n = 2\nOutput: 6\nExplanation: All possible orders: \n(P1,P2,D1,D2), (P1,P2,D2,D1), (P1,D1,P2,D2), (P2,P1,D1,D2), (P2,P1,D2,D1) and (P2,D2,P1,D1).\nThis is an invalid order (P1,D2,P2,D1) because Pickup 2 is after of Delivery 2.", + "Example 3:\nInput: n = 3\nOutput: 90" + ], + "constraints": "Constraints:\n\n1 <= n <= 500", + "tags": [ + "Math", + "Dynamic Programming", + "Combinatorics" + ], + "title-slug": "count-all-valid-pickup-and-delivery-options" + }, + { + "leetcode-id": 1360, + "title": "Number of Days Between Two Dates", + "difficulty": 1, + "description": "Write a program to count the number of days between two dates.\nThe two dates are given as strings, their format is YYYY-MM-DD\u00a0as shown in the examples.", + "examples": [ + "Example 1:\nInput: date1 = \"2019-06-29\", date2 = \"2019-06-30\"\nOutput: 1", + "Example 2:\nInput: date1 = \"2020-01-15\", date2 = \"2019-12-31\"\nOutput: 15" + ], + "constraints": "Constraints:\n\nThe given dates are valid\u00a0dates between the years 1971 and 2100.", + "tags": [ + "Math", + "String" + ], + "title-slug": "number-of-days-between-two-dates" + }, + { + "leetcode-id": 1361, + "title": "Validate Binary Tree Nodes", + "difficulty": 2, + "description": "You have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the given nodes form exactly one valid binary tree.\nIf node i has no left child then leftChild[i] will equal -1, similarly for the right child.\nNote that the nodes have no values and that we only use the node numbers in this problem.", + "examples": [ + "Example 1:\nInput: n = 4, leftChild = [1,-1,3,-1], rightChild = [2,-1,-1,-1]\nOutput: true", + "Example 2:\nInput: n = 4, leftChild = [1,-1,3,-1], rightChild = [2,3,-1,-1]\nOutput: false", + "Example 3:\nInput: n = 2, leftChild = [1,0], rightChild = [-1,-1]\nOutput: false" + ], + "constraints": "Constraints:\n\nn == leftChild.length == rightChild.length\n1 <= n <= 10^4\n-1 <= leftChild[i], rightChild[i] <= n - 1", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Graph", + "Binary Tree" + ], + "title-slug": "validate-binary-tree-nodes" + }, + { + "leetcode-id": 1362, + "title": "Closest Divisors", + "difficulty": 2, + "description": "Given an integer num, find the closest two integers in absolute difference whose product equals\u00a0num + 1\u00a0or num + 2.\nReturn the two integers in any order.", + "examples": [ + "Example 1:\nInput: num = 8\nOutput: [3,3]\nExplanation: For num + 1 = 9, the closest divisors are 3 & 3, for num + 2 = 10, the closest divisors are 2 & 5, hence 3 & 3 is chosen.", + "Example 2:\nInput: num = 123\nOutput: [5,25]", + "Example 3:\nInput: num = 999\nOutput: [40,25]" + ], + "constraints": "Constraints:\n\n1 <= num <= 10^9", + "tags": [ + "Math" + ], + "title-slug": "closest-divisors" + }, + { + "leetcode-id": 1363, + "title": "Largest Multiple of Three", + "difficulty": 3, + "description": "Given an array of digits digits, return the largest multiple of three that can be formed by concatenating some of the given digits in any order. If there is no answer return an empty string.\nSince the answer may not fit in an integer data type, return the answer as a string. Note that the returning answer must not contain unnecessary leading zeros.", + "examples": [ + "Example 1:\nInput: digits = [8,1,9]\nOutput: \"981\"", + "Example 2:\nInput: digits = [8,6,7,1,0]\nOutput: \"8760\"", + "Example 3:\nInput: digits = [1]\nOutput: \"\"" + ], + "constraints": "Constraints:\n\n1 <= digits.length <= 10^4\n0 <= digits[i] <= 9", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "largest-multiple-of-three" + }, + { + "leetcode-id": 1365, + "title": "How Many Numbers Are Smaller Than the Current Number", + "difficulty": 1, + "description": "Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's\u00a0such that\u00a0j != i and nums[j] < nums[i].\nReturn the answer in an array.", + "examples": [ + "Example 1:\nInput: nums = [8,1,2,2,3]\nOutput: [4,0,1,1,3]\nExplanation: \nFor nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3). \nFor nums[1]=1 does not exist any smaller number than it.\nFor nums[2]=2 there exist one smaller number than it (1). \nFor nums[3]=2 there exist one smaller number than it (1). \nFor nums[4]=3 there exist three smaller numbers than it (1, 2 and 2).", + "Example 2:\nInput: nums = [6,5,4,8]\nOutput: [2,1,0,3]", + "Example 3:\nInput: nums = [7,7,7,7]\nOutput: [0,0,0,0]" + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 500\n0 <= nums[i] <= 100", + "tags": [ + "Array", + "Hash Table", + "Sorting", + "Counting" + ], + "title-slug": "how-many-numbers-are-smaller-than-the-current-number" + }, + { + "leetcode-id": 1366, + "title": "Rank Teams by Votes", + "difficulty": 2, + "description": "In a special ranking system, each voter gives a rank from highest to lowest to all teams participating in the competition.\nThe ordering of teams is decided by who received the most position-one votes. If two or more teams tie in the first position, we consider the second position to resolve the conflict, if they tie again, we continue this process until the ties are resolved. If two or more teams are still tied after considering all positions, we rank them alphabetically based on their team letter.\nYou are given an array of strings votes which is the votes of all voters in the ranking systems. Sort all teams according to the ranking system described above.\nReturn a string of all teams sorted by the ranking system.", + "examples": [ + "Example 1:\nInput: votes = [\"ABC\",\"ACB\",\"ABC\",\"ACB\",\"ACB\"]\nOutput: \"ACB\"\nExplanation: \nTeam A was ranked first place by 5 voters. No other team was voted as first place, so team A is the first team.\nTeam B was ranked second by 2 voters and ranked third by 3 voters.\nTeam C was ranked second by 3 voters and ranked third by 2 voters.\nAs most of the voters ranked C second, team C is the second team, and team B is the third.", + "Example 2:\nInput: votes = [\"WXYZ\",\"XYZW\"]\nOutput: \"XWYZ\"\nExplanation:\nX is the winner due to the tie-breaking rule. X has the same votes as W for the first position, but X has one vote in the second position, while W does not have any votes in the second position.", + "Example 3:\nInput: votes = [\"ZMNAGUEDSJYLBOPHRQICWFXTVK\"]\nOutput: \"ZMNAGUEDSJYLBOPHRQICWFXTVK\"\nExplanation: Only one voter, so their votes are used for the ranking." + ], + "constraints": "Constraints:\n\n1 <= votes.length <= 1000\n1 <= votes[i].length <= 26\nvotes[i].length == votes[j].length for 0 <= i, j < votes.length.\nvotes[i][j] is an English uppercase letter.\nAll characters of votes[i] are unique.\nAll the characters that occur in votes[0] also occur in votes[j] where 1 <= j < votes.length.", + "tags": [ + "Array", + "Hash Table", + "String", + "Sorting", + "Counting" + ], + "title-slug": "rank-teams-by-votes" + }, + { + "leetcode-id": 1367, + "title": "Linked List in Binary Tree", + "difficulty": 2, + "description": "Given a binary tree root and a\u00a0linked list with\u00a0head\u00a0as the first node.\u00a0\nReturn True if all the elements in the linked list starting from the head correspond to some downward path connected in the binary tree\u00a0otherwise return False.\nIn this context downward path means a path that starts at some node and goes downwards.", + "examples": [ + "Example 1:\nInput: head = [4,2,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\nOutput: true\nExplanation: Nodes in blue form a subpath in the binary Tree.", + "Example 2:\nInput: head = [1,4,2,6], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\nOutput: true", + "Example 3:\nInput: head = [1,4,2,6,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\nOutput: false\nExplanation: There is no path in the binary tree that contains all the elements of the linked list from head." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree will be in the range [1, 2500].\nThe number of nodes in the list will be in the range [1, 100].\n1 <= Node.val\u00a0<= 100\u00a0for each node in the linked list and binary tree.", + "tags": [ + "Linked List", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "linked-list-in-binary-tree" + }, + { + "leetcode-id": 1368, + "title": "Minimum Cost to Make at Least One Valid Path in a Grid", + "difficulty": 3, + "description": "Given an m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j] can be:\n\n1 which means go to the cell to the right. (i.e go from grid[i][j] to grid[i][j + 1])\n2 which means go to the cell to the left. (i.e go from grid[i][j] to grid[i][j - 1])\n3 which means go to the lower cell. (i.e go from grid[i][j] to grid[i + 1][j])\n4 which means go to the upper cell. (i.e go from grid[i][j] to grid[i - 1][j])\n\nNotice that there could be some signs on the cells of the grid that point outside the grid.\nYou will initially start at the upper left cell (0, 0). A valid path in the grid is a path that starts from the upper left cell (0, 0) and ends at the bottom-right cell (m - 1, n - 1) following the signs on the grid. The valid path does not have to be the shortest.\nYou can modify the sign on a cell with cost = 1. You can modify the sign on a cell one time only.\nReturn the minimum cost to make the grid have at least one valid path.", + "examples": [ + "Example 1:\nInput: grid = [[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]]\nOutput: 3\nExplanation: You will start at point (0, 0).\nThe path to (3, 3) is as follows. (0, 0) --> (0, 1) --> (0, 2) --> (0, 3) change the arrow to down with cost = 1 --> (1, 3) --> (1, 2) --> (1, 1) --> (1, 0) change the arrow to down with cost = 1 --> (2, 0) --> (2, 1) --> (2, 2) --> (2, 3) change the arrow to down with cost = 1 --> (3, 3)\nThe total cost = 3.", + "Example 2:\nInput: grid = [[1,1,3],[3,2,2],[1,1,4]]\nOutput: 0\nExplanation: You can follow the path from (0, 0) to (2, 2).", + "Example 3:\nInput: grid = [[1,2],[4,3]]\nOutput: 1" + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 100\n1 <= grid[i][j] <= 4", + "tags": [ + "Array", + "Breadth-First Search", + "Graph", + "Heap (Priority Queue)", + "Matrix", + "Shortest Path" + ], + "title-slug": "minimum-cost-to-make-at-least-one-valid-path-in-a-grid" + }, + { + "leetcode-id": 1370, + "title": "Increasing Decreasing String", + "difficulty": 1, + "description": "You are given a string s. Reorder the string using the following algorithm:\n\nPick the smallest character from s and append it to the result.\nPick the smallest character from s which is greater than the last appended character to the result and append it.\nRepeat step 2 until you cannot pick more characters.\nPick the largest character from s and append it to the result.\nPick the largest character from s which is smaller than the last appended character to the result and append it.\nRepeat step 5 until you cannot pick more characters.\nRepeat the steps from 1 to 6 until you pick all characters from s.\n\nIn each step, If the smallest or the largest character appears more than once you can choose any occurrence and append it to the result.\nReturn the result string after sorting s with this algorithm.", + "examples": [ + "Example 1:\nInput: s = \"aaaabbbbcccc\"\nOutput: \"abccbaabccba\"\nExplanation: After steps 1, 2 and 3 of the first iteration, result = \"abc\"\nAfter steps 4, 5 and 6 of the first iteration, result = \"abccba\"\nFirst iteration is done. Now s = \"aabbcc\" and we go back to step 1\nAfter steps 1, 2 and 3 of the second iteration, result = \"abccbaabc\"\nAfter steps 4, 5 and 6 of the second iteration, result = \"abccbaabccba\"", + "Example 2:\nInput: s = \"rat\"\nOutput: \"art\"\nExplanation: The word \"rat\" becomes \"art\" after re-ordering it with the mentioned algorithm." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 500\ns consists of only lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Counting" + ], + "title-slug": "increasing-decreasing-string" + }, + { + "leetcode-id": 1371, + "title": "Find the Longest Substring Containing Vowels in Even Counts", + "difficulty": 2, + "description": "Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.", + "examples": [ + "Example 1:\nInput: s = \"eleetminicoworoep\"\nOutput: 13\nExplanation: The longest substring is \"leetminicowor\" which contains two each of the vowels: e, i and o and zero of the vowels: a and u.", + "Example 2:\nInput: s = \"leetcodeisgreat\"\nOutput: 5\nExplanation: The longest substring is \"leetc\" which contains two e's.", + "Example 3:\nInput: s = \"bcbcbc\"\nOutput: 6\nExplanation: In this case, the given string \"bcbcbc\" is the longest because all vowels: a, e, i, o and u appear zero times." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 5 x 10^5\ns\u00a0contains only lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Bit Manipulation", + "Prefix Sum" + ], + "title-slug": "find-the-longest-substring-containing-vowels-in-even-counts" + }, + { + "leetcode-id": 1372, + "title": "Longest ZigZag Path in a Binary Tree", + "difficulty": 2, + "description": "You are given the root of a binary tree.\nA ZigZag path for a binary tree is defined as follow:\n\nChoose any node in the binary tree and a direction (right or left).\nIf the current direction is right, move to the right child of the current node; otherwise, move to the left child.\nChange the direction from right to left or from left to right.\nRepeat the second and third steps until you can't move in the tree.\n\nZigzag length is defined as the number of nodes visited - 1. (A single node has a length of 0).\nReturn the longest ZigZag path contained in that tree.", + "examples": [ + "Example 1:\nInput: root = [1,null,1,1,1,null,null,1,1,null,1,null,null,null,1]\nOutput: 3\nExplanation: Longest ZigZag path in blue nodes (right -> left -> right).", + "Example 2:\nInput: root = [1,1,1,null,1,null,null,1,1,null,1]\nOutput: 4\nExplanation: Longest ZigZag path in blue nodes (left -> right -> left -> right).", + "Example 3:\nInput: root = [1]\nOutput: 0" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 5 * 10^4].\n1 <= Node.val <= 100", + "tags": [ + "Dynamic Programming", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "longest-zigzag-path-in-a-binary-tree" + }, + { + "leetcode-id": 1373, + "title": "Maximum Sum BST in Binary Tree", + "difficulty": 3, + "description": "Given a binary tree root, return the maximum sum of all keys of any sub-tree which is also a Binary Search Tree (BST).\nAssume a BST is defined as follows:\n\nThe left subtree of a node contains only nodes with keys less than the node's key.\nThe right subtree of a node contains only nodes with keys greater than the node's key.\nBoth the left and right subtrees must also be binary search trees.", + "examples": [ + "Example 1:\nInput: root = [1,4,3,2,4,2,5,null,null,null,null,null,null,4,6]\nOutput: 20\nExplanation: Maximum sum in a valid Binary search tree is obtained in root node with key equal to 3.", + "Example 2:\nInput: root = [4,3,null,1,2]\nOutput: 2\nExplanation: Maximum sum in a valid Binary search tree is obtained in a single root node with key equal to 2.", + "Example 3:\nInput: root = [-4,-2,-5]\nOutput: 0\nExplanation: All values are negatives. Return an empty BST." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 4 * 10^4].\n-4 * 10^4 <= Node.val <= 4 * 10^4", + "tags": [ + "Dynamic Programming", + "Tree", + "Depth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "maximum-sum-bst-in-binary-tree" + }, + { + "leetcode-id": 1374, + "title": "Generate a String With Characters That Have Odd Counts", + "difficulty": 1, + "description": "Given an\u00a0integer n, return a string with n\u00a0characters such that each character in such string occurs an odd number of times.\nThe returned string must contain only lowercase English letters. If there are multiples valid strings, return any of them.", + "examples": [ + "Example 1:\nInput: n = 4\nOutput: \"pppz\"\nExplanation: \"pppz\" is a valid string since the character 'p' occurs three times and the character 'z' occurs once. Note that there are many other valid strings such as \"ohhh\" and \"love\".", + "Example 2:\nInput: n = 2\nOutput: \"xy\"\nExplanation: \"xy\" is a valid string since the characters 'x' and 'y' occur once. Note that there are many other valid strings such as \"ag\" and \"ur\".", + "Example 3:\nInput: n = 7\nOutput: \"holasss\"" + ], + "constraints": "Constraints:\n\n1 <= n <= 500", + "tags": [ + "String" + ], + "title-slug": "generate-a-string-with-characters-that-have-odd-counts" + }, + { + "leetcode-id": 1375, + "title": "Number of Times Binary String Is Prefix-Aligned", + "difficulty": 2, + "description": "You have a 1-indexed binary string of length n where all the bits are 0 initially. We will flip all the bits of this binary string (i.e., change them from 0 to 1) one by one. You are given a 1-indexed integer array flips where flips[i] indicates that the bit at index i will be flipped in the i^th step.\nA binary string is prefix-aligned if, after the i^th step, all the bits in the inclusive range [1, i] are ones and all the other bits are zeros.\nReturn the number of times the binary string is prefix-aligned during the flipping process.", + "examples": [ + "Example 1:\nInput: flips = [3,2,4,1,5]\nOutput: 2\nExplanation: The binary string is initially \"00000\".\nAfter applying step 1: The string becomes \"00100\", which is not prefix-aligned.\nAfter applying step 2: The string becomes \"01100\", which is not prefix-aligned.\nAfter applying step 3: The string becomes \"01110\", which is not prefix-aligned.\nAfter applying step 4: The string becomes \"11110\", which is prefix-aligned.\nAfter applying step 5: The string becomes \"11111\", which is prefix-aligned.\nWe can see that the string was prefix-aligned 2 times, so we return 2.", + "Example 2:\nInput: flips = [4,1,2,3]\nOutput: 1\nExplanation: The binary string is initially \"0000\".\nAfter applying step 1: The string becomes \"0001\", which is not prefix-aligned.\nAfter applying step 2: The string becomes \"1001\", which is not prefix-aligned.\nAfter applying step 3: The string becomes \"1101\", which is not prefix-aligned.\nAfter applying step 4: The string becomes \"1111\", which is prefix-aligned.\nWe can see that the string was prefix-aligned 1 time, so we return 1." + ], + "constraints": "Constraints:\n\nn == flips.length\n1 <= n <= 5 * 10^4\nflips is a permutation of the integers in the range [1, n].", + "tags": [ + "Array" + ], + "title-slug": "number-of-times-binary-string-is-prefix-aligned" + }, + { + "leetcode-id": 1376, + "title": "Time Needed to Inform All Employees", + "difficulty": 2, + "description": "A company has n employees with a unique ID for each employee from 0 to n - 1. The head of the company is the one with headID.\nEach employee has one direct manager given in the manager array where manager[i] is the direct manager of the i-th employee, manager[headID] = -1. Also, it is guaranteed that the subordination relationships have a tree structure.\nThe head of the company wants to inform all the company employees of an urgent piece of news. He will inform his direct subordinates, and they will inform their subordinates, and so on until all employees know about the urgent news.\nThe i-th employee needs informTime[i] minutes to inform all of his direct subordinates (i.e., After informTime[i] minutes, all his direct subordinates can start spreading the news).\nReturn the number of minutes needed to inform all the employees about the urgent news.", + "examples": [ + "Example 1:\nInput: n = 1, headID = 0, manager = [-1], informTime = [0]\nOutput: 0\nExplanation: The head of the company is the only employee in the company.", + "Example 2:\nInput: n = 6, headID = 2, manager = [2,2,-1,2,2,2], informTime = [0,0,1,0,0,0]\nOutput: 1\nExplanation: The head of the company with id = 2 is the direct manager of all the employees in the company and needs 1 minute to inform them all.\nThe tree structure of the employees in the company is shown." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5\n0 <= headID < n\nmanager.length == n\n0 <= manager[i] < n\nmanager[headID] == -1\ninformTime.length == n\n0 <= informTime[i] <= 1000\ninformTime[i] == 0 if employee i has no subordinates.\nIt is guaranteed that all the employees can be informed.", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search" + ], + "title-slug": "time-needed-to-inform-all-employees" + }, + { + "leetcode-id": 1377, + "title": "Frog Position After T Seconds", + "difficulty": 3, + "description": "Given an undirected tree consisting of n vertices numbered from 1 to n. A frog starts jumping from vertex 1. In one second, the frog jumps from its current vertex to another unvisited vertex if they are directly connected. The frog can not jump back to a visited vertex. In case the frog can jump to several vertices, it jumps randomly to one of them with the same probability. Otherwise, when the frog can not jump to any unvisited vertex, it jumps forever on the same vertex.\nThe edges of the undirected tree are given in the array edges, where edges[i] = [ai, bi] means that exists an edge connecting the vertices ai and bi.\nReturn the probability that after t seconds the frog is on the vertex target. Answers within 10^-5 of the actual answer will be accepted.", + "examples": [ + "Example 1:\nInput: n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4\nOutput: 0.16666666666666666 \nExplanation: The figure above shows the given graph. The frog starts at vertex 1, jumping with 1/3 probability to the vertex 2 after second 1 and then jumping with 1/2 probability to vertex 4 after second 2. Thus the probability for the frog is on the vertex 4 after 2 seconds is 1/3 * 1/2 = 1/6 = 0.16666666666666666.", + "Example 2:\nInput: n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7\nOutput: 0.3333333333333333\nExplanation: The figure above shows the given graph. The frog starts at vertex 1, jumping with 1/3 = 0.3333333333333333 probability to the vertex 7 after second 1." + ], + "constraints": "Constraints:\n\n1 <= n <= 100\nedges.length == n - 1\nedges[i].length == 2\n1 <= ai, bi <= n\n1 <= t <= 50\n1 <= target <= n", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Graph" + ], + "title-slug": "frog-position-after-t-seconds" + }, + { + "leetcode-id": 1379, + "title": "Find a Corresponding Node of a Binary Tree in a Clone of That Tree", + "difficulty": 1, + "description": "Given two binary trees original and cloned and given a reference to a node target in the original tree.\nThe cloned tree is a copy of the original tree.\nReturn a reference to the same node in the cloned tree.\nNote that you are not allowed to change any of the two trees or the target node and the answer must be a reference to a node in the cloned tree.", + "examples": [ + "Example 1:\nInput: tree = [7,4,3,null,null,6,19], target = 3\nOutput: 3\nExplanation: In all examples the original and cloned trees are shown. The target node is a green node from the original tree. The answer is the yellow node from the cloned tree.", + "Example 2:\nInput: tree = [7], target = 7\nOutput: 7", + "Example 3:\nInput: tree = [8,null,6,null,5,null,4,null,3,null,2,null,1], target = 4\nOutput: 4" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\nThe values of the nodes of the tree are unique.\ntarget node is a node from the original tree and is not null.\n\n\u00a0\nFollow up: Could you solve the problem if repeated values on the tree are allowed?", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree" + }, + { + "leetcode-id": 1380, + "title": "Lucky Numbers in a Matrix", + "difficulty": 1, + "description": "Given an m x n matrix of distinct numbers, return all lucky numbers in the matrix in any order.\nA lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.", + "examples": [ + "Example 1:\nInput: matrix = [[3,7,8],[9,11,13],[15,16,17]]\nOutput: [15]\nExplanation: 15 is the only lucky number since it is the minimum in its row and the maximum in its column.", + "Example 2:\nInput: matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]\nOutput: [12]\nExplanation: 12 is the only lucky number since it is the minimum in its row and the maximum in its column.", + "Example 3:\nInput: matrix = [[7,8],[1,2]]\nOutput: [7]\nExplanation: 7 is the only lucky number since it is the minimum in its row and the maximum in its column." + ], + "constraints": "Constraints:\n\nm == mat.length\nn == mat[i].length\n1 <= n, m <= 50\n1 <= matrix[i][j] <= 10^5.\nAll elements in the matrix are distinct.", + "tags": [ + "Array", + "Matrix" + ], + "title-slug": "lucky-numbers-in-a-matrix" + }, + { + "leetcode-id": 1381, + "title": "Design a Stack With Increment Operation", + "difficulty": 2, + "description": "Design a stack that supports increment operations on its elements.\nImplement the CustomStack class:\n\nCustomStack(int maxSize) Initializes the object with maxSize which is the maximum number of elements in the stack.\nvoid push(int x) Adds x to the top of the stack if the stack has not reached the maxSize.\nint pop() Pops and returns the top of the stack or -1 if the stack is empty.\nvoid inc(int k, int val) Increments the bottom k elements of the stack by val. If there are less than k elements in the stack, increment all the elements in the stack.", + "examples": [ + "Example 1:\nInput\n[\"CustomStack\",\"push\",\"push\",\"pop\",\"push\",\"push\",\"push\",\"increment\",\"increment\",\"pop\",\"pop\",\"pop\",\"pop\"]\n[[3],[1],[2],[],[2],[3],[4],[5,100],[2,100],[],[],[],[]]\nOutput\n[null,null,null,2,null,null,null,null,null,103,202,201,-1]\nExplanation\nCustomStack stk = new CustomStack(3); // Stack is Empty []\nstk.push(1); // stack becomes [1]\nstk.push(2); // stack becomes [1, 2]\nstk.pop(); // return 2 --> Return top of the stack 2, stack becomes [1]\nstk.push(2); // stack becomes [1, 2]\nstk.push(3); // stack becomes [1, 2, 3]\nstk.push(4); // stack still [1, 2, 3], Do not add another elements as size is 4\nstk.increment(5, 100); // stack becomes [101, 102, 103]\nstk.increment(2, 100); // stack becomes [201, 202, 103]\nstk.pop(); // return 103 --> Return top of the stack 103, stack becomes [201, 202]\nstk.pop(); // return 202 --> Return top of the stack 202, stack becomes [201]\nstk.pop(); // return 201 --> Return top of the stack 201, stack becomes []\nstk.pop(); // return -1 --> Stack is empty return -1." + ], + "constraints": "Constraints:\n\n1 <= maxSize, x, k <= 1000\n0 <= val <= 100\nAt most 1000 calls will be made to each method of increment, push and pop each separately.", + "tags": [ + "Array", + "Stack", + "Design" + ], + "title-slug": "design-a-stack-with-increment-operation" + }, + { + "leetcode-id": 1382, + "title": "Balance a Binary Search Tree", + "difficulty": 2, + "description": "Given the root of a binary search tree, return a balanced binary search tree with the same node values. If there is more than one answer, return any of them.\nA binary search tree is balanced if the depth of the two subtrees of every node never differs by more than 1.", + "examples": [ + "Example 1:\nInput: root = [1,null,2,null,3,null,4,null,null]\nOutput: [2,1,3,null,null,null,4]\nExplanation: This is not the only correct answer, [3,1,4,null,2] is also correct.", + "Example 2:\nInput: root = [2,1,3]\nOutput: [2,1,3]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^4].\n1 <= Node.val <= 10^5", + "tags": [ + "Divide and Conquer", + "Greedy", + "Tree", + "Depth-First Search", + "Binary Search Tree", + "Binary Tree" + ], + "title-slug": "balance-a-binary-search-tree" + }, + { + "leetcode-id": 1383, + "title": "Maximum Performance of a Team", + "difficulty": 3, + "description": "You are given two integers n and k and two integer arrays speed and efficiency both of length n. There are n engineers numbered from 1 to n. speed[i] and efficiency[i] represent the speed and efficiency of the i^th engineer respectively.\nChoose at most k different engineers out of the n engineers to form a team with the maximum performance.\nThe performance of a team is the sum of its engineers' speeds multiplied by the minimum efficiency among its engineers.\nReturn the maximum performance of this team. Since the answer can be a huge number, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2\nOutput: 60\nExplanation: \nWe have the maximum performance of the team by selecting engineer 2 (with speed=10 and efficiency=4) and engineer 5 (with speed=5 and efficiency=7). That is, performance = (10 + 5) * min(4, 7) = 60.", + "Example 2:\nInput: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 3\nOutput: 68\nExplanation:\nThis is the same example as the first but k = 3. We can select engineer 1, engineer 2 and engineer 5 to get the maximum performance of the team. That is, performance = (2 + 10 + 5) * min(5, 4, 7) = 68.", + "Example 3:\nInput: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 4\nOutput: 72" + ], + "constraints": "Constraints:\n\n1 <= k <= n <= 10^5\nspeed.length == n\nefficiency.length == n\n1 <= speed[i] <= 10^5\n1 <= efficiency[i] <= 10^8", + "tags": [ + "Array", + "Greedy", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "maximum-performance-of-a-team" + }, + { + "leetcode-id": 1385, + "title": "Find the Distance Value Between Two Arrays", + "difficulty": 1, + "description": "Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays.\nThe distance value is defined as the number of elements arr1[i] such that there is not any element arr2[j] where |arr1[i]-arr2[j]| <= d.", + "examples": [ + "Example 1:\nInput: arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2\nOutput: 2\nExplanation: \nFor arr1[0]=4 we have: \n|4-10|=6 > d=2 \n|4-9|=5 > d=2 \n|4-1|=3 > d=2 \n|4-8|=4 > d=2 \nFor arr1[1]=5 we have: \n|5-10|=5 > d=2 \n|5-9|=4 > d=2 \n|5-1|=4 > d=2 \n|5-8|=3 > d=2\nFor arr1[2]=8 we have:\n|8-10|=2 <= d=2\n|8-9|=1 <= d=2\n|8-1|=7 > d=2\n|8-8|=0 <= d=2", + "Example 2:\nInput: arr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3\nOutput: 2", + "Example 3:\nInput: arr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= arr1.length, arr2.length <= 500\n-1000 <= arr1[i], arr2[j] <= 1000\n0 <= d <= 100", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Sorting" + ], + "title-slug": "find-the-distance-value-between-two-arrays" + }, + { + "leetcode-id": 1386, + "title": "Cinema Seat Allocation", + "difficulty": 2, + "description": "A cinema\u00a0has n\u00a0rows of seats, numbered from 1 to n\u00a0and there are ten\u00a0seats in each row, labelled from 1\u00a0to 10\u00a0as shown in the figure above.\nGiven the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8]\u00a0means the seat located in row 3 and labelled with 8\u00a0is already reserved.\nReturn the maximum number of four-person groups\u00a0you can assign on the cinema\u00a0seats. A four-person group\u00a0occupies four\u00a0adjacent seats in one single row. Seats across an aisle (such as [3,3]\u00a0and [3,4]) are not considered to be adjacent, but there is an exceptional case\u00a0on which an aisle split\u00a0a four-person group, in that case, the aisle split\u00a0a four-person group in the middle,\u00a0which means to have two people on each side.", + "examples": [ + "Example 1:\nInput: n = 3, reservedSeats = [[1,2],[1,3],[1,8],[2,6],[3,1],[3,10]]\nOutput: 4\nExplanation: The figure above shows the optimal allocation for four groups, where seats mark with blue are already reserved and contiguous seats mark with orange are for one group.", + "Example 2:\nInput: n = 2, reservedSeats = [[2,1],[1,8],[2,6]]\nOutput: 2", + "Example 3:\nInput: n = 4, reservedSeats = [[4,3],[1,4],[4,6],[1,7]]\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^9\n1 <=\u00a0reservedSeats.length <= min(10*n, 10^4)\nreservedSeats[i].length == 2\n1\u00a0<=\u00a0reservedSeats[i][0] <= n\n1 <=\u00a0reservedSeats[i][1] <= 10\nAll reservedSeats[i] are distinct.", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Bit Manipulation" + ], + "title-slug": "cinema-seat-allocation" + }, + { + "leetcode-id": 1387, + "title": "Sort Integers by The Power Value", + "difficulty": 2, + "description": "The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:\n\nif x is even then x = x / 2\nif x is odd then x = 3 * x + 1\n\nFor example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).\nGiven three integers lo, hi and k. The task is to sort all integers in the interval [lo, hi] by the power value in ascending order, if two or more integers have the same power value sort them by ascending order.\nReturn the k^th integer in the range [lo, hi] sorted by the power value.\nNotice that for any integer x (lo <= x <= hi) it is guaranteed that x will transform into 1 using these steps and that the power of x is will fit in a 32-bit signed integer.", + "examples": [ + "Example 1:\nInput: lo = 12, hi = 15, k = 2\nOutput: 13\nExplanation: The power of 12 is 9 (12 --> 6 --> 3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1)\nThe power of 13 is 9\nThe power of 14 is 17\nThe power of 15 is 17\nThe interval sorted by the power value [12,13,14,15]. For k = 2 answer is the second element which is 13.\nNotice that 12 and 13 have the same power value and we sorted them in ascending order. Same for 14 and 15.", + "Example 2:\nInput: lo = 7, hi = 11, k = 4\nOutput: 7\nExplanation: The power array corresponding to the interval [7, 8, 9, 10, 11] is [16, 3, 19, 6, 14].\nThe interval sorted by power is [8, 10, 11, 7, 9].\nThe fourth number in the sorted array is 7." + ], + "constraints": "Constraints:\n\n1 <= lo <= hi <= 1000\n1 <= k <= hi - lo + 1", + "tags": [ + "Dynamic Programming", + "Memoization", + "Sorting" + ], + "title-slug": "sort-integers-by-the-power-value" + }, + { + "leetcode-id": 1388, + "title": "Pizza With 3n Slices", + "difficulty": 3, + "description": "There is a pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows:\n\nYou will pick any pizza slice.\nYour friend Alice will pick the next slice in the anti-clockwise direction of your pick.\nYour friend Bob will pick the next slice in the clockwise direction of your pick.\nRepeat until there are no more slices of pizzas.\n\nGiven an integer array slices that represent the sizes of the pizza slices in a clockwise direction, return the maximum possible sum of slice sizes that you can pick.", + "examples": [ + "Example 1:\nInput: slices = [1,2,3,4,5,6]\nOutput: 10\nExplanation: Pick pizza slice of size 4, Alice and Bob will pick slices with size 3 and 5 respectively. Then Pick slices with size 6, finally Alice and Bob will pick slice of size 2 and 1 respectively. Total = 4 + 6.", + "Example 2:\nInput: slices = [8,9,8,6,1,1]\nOutput: 16\nExplanation: Pick pizza slice of size 8 in each turn. If you pick slice with size 9 your partners will pick slices of size 8." + ], + "constraints": "Constraints:\n\n3 * n == slices.length\n1 <= slices.length <= 500\n1 <= slices[i] <= 1000", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy", + "Heap (Priority Queue)" + ], + "title-slug": "pizza-with-3n-slices" + }, + { + "leetcode-id": 1389, + "title": "Create Target Array in the Given Order", + "difficulty": 1, + "description": "Given two arrays of integers\u00a0nums and index. Your task is to create target array under the following rules:\n\nInitially target array is empty.\nFrom left to right read nums[i] and index[i], insert at index index[i]\u00a0the value nums[i]\u00a0in\u00a0target array.\nRepeat the previous step until there are no elements to read in nums and index.\n\nReturn the target array.\nIt is guaranteed that the insertion operations will be valid.", + "examples": [ + "Example 1:\nInput: nums = [0,1,2,3,4], index = [0,1,2,2,1]\nOutput: [0,4,1,3,2]\nExplanation:\nnums index target\n0 0 [0]\n1 1 [0,1]\n2 2 [0,1,2]\n3 2 [0,1,3,2]\n4 1 [0,4,1,3,2]", + "Example 2:\nInput: nums = [1,2,3,4,0], index = [0,1,2,3,0]\nOutput: [0,1,2,3,4]\nExplanation:\nnums index target\n1 0 [1]\n2 1 [1,2]\n3 2 [1,2,3]\n4 3 [1,2,3,4]\n0 0 [0,1,2,3,4]", + "Example 3:\nInput: nums = [1], index = [0]\nOutput: [1]" + ], + "constraints": "Constraints:\n\n1 <= nums.length, index.length <= 100\nnums.length == index.length\n0 <= nums[i] <= 100\n0 <= index[i] <= i", + "tags": [ + "Array", + "Simulation" + ], + "title-slug": "create-target-array-in-the-given-order" + }, + { + "leetcode-id": 1390, + "title": "Four Divisors", + "difficulty": 2, + "description": "Given an integer array nums, return the sum of divisors of the integers in that array that have exactly four divisors. If there is no such integer in the array, return 0.", + "examples": [ + "Example 1:\nInput: nums = [21,4,7]\nOutput: 32\nExplanation: \n21 has 4 divisors: 1, 3, 7, 21\n4 has 3 divisors: 1, 2, 4\n7 has 2 divisors: 1, 7\nThe answer is the sum of divisors of 21 only.", + "Example 2:\nInput: nums = [21,21]\nOutput: 64", + "Example 3:\nInput: nums = [1,2,3,4,5]\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n1 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Math" + ], + "title-slug": "four-divisors" + }, + { + "leetcode-id": 1391, + "title": "Check if There is a Valid Path in a Grid", + "difficulty": 2, + "description": "You are given an m x n grid. Each cell of grid represents a street. The street of grid[i][j] can be:\n\n1 which means a street connecting the left cell and the right cell.\n2 which means a street connecting the upper cell and the lower cell.\n3 which means a street connecting the left cell and the lower cell.\n4 which means a street connecting the right cell and the lower cell.\n5 which means a street connecting the left cell and the upper cell.\n6 which means a street connecting the right cell and the upper cell.\n\n\nYou will initially start at the street of the upper-left cell (0, 0). A valid path in the grid is a path that starts from the upper left cell (0, 0) and ends at the bottom-right cell (m - 1, n - 1). The path should only follow the streets.\nNotice that you are not allowed to change any street.\nReturn true if there is a valid path in the grid or false otherwise.", + "examples": [ + "Example 1:\nInput: grid = [[2,4,3],[6,5,2]]\nOutput: true\nExplanation: As shown you can start at cell (0, 0) and visit all the cells of the grid to reach (m - 1, n - 1).", + "Example 2:\nInput: grid = [[1,2,1],[1,2,1]]\nOutput: false\nExplanation: As shown you the street at cell (0, 0) is not connected with any street of any other cell and you will get stuck at cell (0, 0)", + "Example 3:\nInput: grid = [[1,1,2]]\nOutput: false\nExplanation: You will get stuck at cell (0, 1) and you cannot reach cell (0, 2)." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 300\n1 <= grid[i][j] <= 6", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Matrix" + ], + "title-slug": "check-if-there-is-a-valid-path-in-a-grid" + }, + { + "leetcode-id": 1392, + "title": "Longest Happy Prefix", + "difficulty": 3, + "description": "A string is called a happy prefix if is a non-empty prefix which is also a suffix (excluding itself).\nGiven a string s, return the longest happy prefix of s. Return an empty string \"\" if no such prefix exists.", + "examples": [ + "Example 1:\nInput: s = \"level\"\nOutput: \"l\"\nExplanation: s contains 4 prefix excluding itself (\"l\", \"le\", \"lev\", \"leve\"), and suffix (\"l\", \"el\", \"vel\", \"evel\"). The largest prefix which is also suffix is given by \"l\".", + "Example 2:\nInput: s = \"ababab\"\nOutput: \"abab\"\nExplanation: \"abab\" is the largest prefix which is also suffix. They can overlap in the original string." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns contains only lowercase English letters.", + "tags": [ + "String", + "Rolling Hash", + "String Matching", + "Hash Function" + ], + "title-slug": "longest-happy-prefix" + }, + { + "leetcode-id": 1394, + "title": "Find Lucky Integer in an Array", + "difficulty": 1, + "description": "Given an array of integers arr, a lucky integer is an integer that has a frequency in the array equal to its value.\nReturn the largest lucky integer in the array. If there is no lucky integer return -1.", + "examples": [ + "Example 1:\nInput: arr = [2,2,3,4]\nOutput: 2\nExplanation: The only lucky number in the array is 2 because frequency[2] == 2.", + "Example 2:\nInput: arr = [1,2,2,3,3,3]\nOutput: 3\nExplanation: 1, 2 and 3 are all lucky numbers, return the largest of them.", + "Example 3:\nInput: arr = [2,2,2,3,3]\nOutput: -1\nExplanation: There are no lucky numbers in the array." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 500\n1 <= arr[i] <= 500", + "tags": [ + "Array", + "Hash Table", + "Counting" + ], + "title-slug": "find-lucky-integer-in-an-array" + }, + { + "leetcode-id": 1395, + "title": "Count Number of Teams", + "difficulty": 2, + "description": "There are n soldiers standing in a line. Each soldier is assigned a unique rating value.\nYou have to form a team of 3 soldiers amongst them under the following rules:\n\nChoose 3 soldiers with index (i, j, k) with rating (rating[i], rating[j], rating[k]).\nA team is valid if: (rating[i] < rating[j] < rating[k]) or (rating[i] > rating[j] > rating[k]) where (0 <= i < j < k < n).\n\nReturn the number of teams you can form given the conditions. (soldiers can be part of multiple teams).", + "examples": [ + "Example 1:\nInput: rating = [2,5,3,4,1]\nOutput: 3\nExplanation: We can form three teams given the conditions. (2,3,4), (5,4,1), (5,3,1).", + "Example 2:\nInput: rating = [2,1,3]\nOutput: 0\nExplanation: We can't form any team given the conditions.", + "Example 3:\nInput: rating = [1,2,3,4]\nOutput: 4" + ], + "constraints": "Constraints:\n\nn == rating.length\n3 <= n <= 1000\n1 <= rating[i] <= 10^5\nAll the integers in rating are unique.", + "tags": [ + "Array", + "Dynamic Programming", + "Binary Indexed Tree" + ], + "title-slug": "count-number-of-teams" + }, + { + "leetcode-id": 1396, + "title": "Design Underground System", + "difficulty": 2, + "description": "An underground railway system is keeping track of customer travel times between different stations. They are using this data to calculate the average time it takes to travel from one station to another.\nImplement the UndergroundSystem class:\n\nvoid checkIn(int id, string stationName, int t)\n\nA customer with a card ID equal to id, checks in at the station stationName at time t.\nA customer can only be checked into one place at a time.\n\n\nvoid checkOut(int id, string stationName, int t)\n\nA customer with a card ID equal to id, checks out from the station stationName at time t.\n\n\ndouble getAverageTime(string startStation, string endStation)\n\nReturns the average time it takes to travel from startStation to endStation.\nThe average time is computed from all the previous traveling times from startStation to endStation that happened directly, meaning a check in at startStation followed by a check out from endStation.\nThe time it takes to travel from startStation to endStation may be different from the time it takes to travel from endStation to startStation.\nThere will be at least one customer that has traveled from startStation to endStation before getAverageTime is called.\n\n\n\nYou may assume all calls to the checkIn and checkOut methods are consistent. If a customer checks in at time t1 then checks out at time t2, then t1 < t2. All events happen in chronological order.", + "examples": [ + "Example 1:\nInput\n[\"UndergroundSystem\",\"checkIn\",\"checkIn\",\"checkIn\",\"checkOut\",\"checkOut\",\"checkOut\",\"getAverageTime\",\"getAverageTime\",\"checkIn\",\"getAverageTime\",\"checkOut\",\"getAverageTime\"]\n[[],[45,\"Leyton\",3],[32,\"Paradise\",8],[27,\"Leyton\",10],[45,\"Waterloo\",15],[27,\"Waterloo\",20],[32,\"Cambridge\",22],[\"Paradise\",\"Cambridge\"],[\"Leyton\",\"Waterloo\"],[10,\"Leyton\",24],[\"Leyton\",\"Waterloo\"],[10,\"Waterloo\",38],[\"Leyton\",\"Waterloo\"]]\n\nOutput\n[null,null,null,null,null,null,null,14.00000,11.00000,null,11.00000,null,12.00000]\n\nExplanation\nUndergroundSystem undergroundSystem = new UndergroundSystem();\nundergroundSystem.checkIn(45, \"Leyton\", 3);\nundergroundSystem.checkIn(32, \"Paradise\", 8);\nundergroundSystem.checkIn(27, \"Leyton\", 10);\nundergroundSystem.checkOut(45, \"Waterloo\", 15); // Customer 45 \"Leyton\" -> \"Waterloo\" in 15-3 = 12\nundergroundSystem.checkOut(27, \"Waterloo\", 20); // Customer 27 \"Leyton\" -> \"Waterloo\" in 20-10 = 10\nundergroundSystem.checkOut(32, \"Cambridge\", 22); // Customer 32 \"Paradise\" -> \"Cambridge\" in 22-8 = 14\nundergroundSystem.getAverageTime(\"Paradise\", \"Cambridge\"); // return 14.00000. One trip \"Paradise\" -> \"Cambridge\", (14) / 1 = 14\nundergroundSystem.getAverageTime(\"Leyton\", \"Waterloo\"); // return 11.00000. Two trips \"Leyton\" -> \"Waterloo\", (10 + 12) / 2 = 11\nundergroundSystem.checkIn(10, \"Leyton\", 24);\nundergroundSystem.getAverageTime(\"Leyton\", \"Waterloo\"); // return 11.00000\nundergroundSystem.checkOut(10, \"Waterloo\", 38); // Customer 10 \"Leyton\" -> \"Waterloo\" in 38-24 = 14\nundergroundSystem.getAverageTime(\"Leyton\", \"Waterloo\"); // return 12.00000. Three trips \"Leyton\" -> \"Waterloo\", (10 + 12 + 14) / 3 = 12", + "Example 2:\nInput\n[\"UndergroundSystem\",\"checkIn\",\"checkOut\",\"getAverageTime\",\"checkIn\",\"checkOut\",\"getAverageTime\",\"checkIn\",\"checkOut\",\"getAverageTime\"]\n[[],[10,\"Leyton\",3],[10,\"Paradise\",8],[\"Leyton\",\"Paradise\"],[5,\"Leyton\",10],[5,\"Paradise\",16],[\"Leyton\",\"Paradise\"],[2,\"Leyton\",21],[2,\"Paradise\",30],[\"Leyton\",\"Paradise\"]]\n\nOutput\n[null,null,null,5.00000,null,null,5.50000,null,null,6.66667]\n\nExplanation\nUndergroundSystem undergroundSystem = new UndergroundSystem();\nundergroundSystem.checkIn(10, \"Leyton\", 3);\nundergroundSystem.checkOut(10, \"Paradise\", 8); // Customer 10 \"Leyton\" -> \"Paradise\" in 8-3 = 5\nundergroundSystem.getAverageTime(\"Leyton\", \"Paradise\"); // return 5.00000, (5) / 1 = 5\nundergroundSystem.checkIn(5, \"Leyton\", 10);\nundergroundSystem.checkOut(5, \"Paradise\", 16); // Customer 5 \"Leyton\" -> \"Paradise\" in 16-10 = 6\nundergroundSystem.getAverageTime(\"Leyton\", \"Paradise\"); // return 5.50000, (5 + 6) / 2 = 5.5\nundergroundSystem.checkIn(2, \"Leyton\", 21);\nundergroundSystem.checkOut(2, \"Paradise\", 30); // Customer 2 \"Leyton\" -> \"Paradise\" in 30-21 = 9\nundergroundSystem.getAverageTime(\"Leyton\", \"Paradise\"); // return 6.66667, (5 + 6 + 9) / 3 = 6.66667" + ], + "constraints": "Constraints:\n\n1 <= id, t <= 10^6\n1 <= stationName.length, startStation.length, endStation.length <= 10\nAll strings consist of uppercase and lowercase English letters and digits.\nThere will be at most 2 * 10^4 calls in total to checkIn, checkOut, and getAverageTime.\nAnswers within 10^-5 of the actual value will be accepted.", + "tags": [ + "Hash Table", + "String", + "Design" + ], + "title-slug": "design-underground-system" + }, + { + "leetcode-id": 1397, + "title": "Find All Good Strings", + "difficulty": 3, + "description": "Given the strings s1 and s2 of size n and the string evil, return the number of good strings.\nA good string has size n, it is alphabetically greater than or equal to s1, it is alphabetically smaller than or equal to s2, and it does not contain the string evil as a substring. Since the answer can be a huge number, return this modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 2, s1 = \"aa\", s2 = \"da\", evil = \"b\"\nOutput: 51 \nExplanation: There are 25 good strings starting with 'a': \"aa\",\"ac\",\"ad\",...,\"az\". Then there are 25 good strings starting with 'c': \"ca\",\"cc\",\"cd\",...,\"cz\" and finally there is one good string starting with 'd': \"da\".", + "Example 2:\nInput: n = 8, s1 = \"leetcode\", s2 = \"leetgoes\", evil = \"leet\"\nOutput: 0 \nExplanation: All strings greater than or equal to s1 and smaller than or equal to s2 start with the prefix \"leet\", therefore, there is not any good string.", + "Example 3:\nInput: n = 2, s1 = \"gx\", s2 = \"gz\", evil = \"x\"\nOutput: 2" + ], + "constraints": "Constraints:\n\ns1.length == n\ns2.length == n\ns1 <= s2\n1 <= n <= 500\n1 <= evil.length <= 50\nAll strings consist of lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming", + "String Matching" + ], + "title-slug": "find-all-good-strings" + }, + { + "leetcode-id": 1399, + "title": "Count Largest Group", + "difficulty": 1, + "description": "You are given an integer n.\nEach number from 1 to n is grouped according to the sum of its digits.\nReturn the number of groups that have the largest size.", + "examples": [ + "Example 1:\nInput: n = 13\nOutput: 4\nExplanation: There are 9 groups in total, they are grouped according sum of its digits of numbers from 1 to 13:\n[1,10], [2,11], [3,12], [4,13], [5], [6], [7], [8], [9].\nThere are 4 groups with largest size.", + "Example 2:\nInput: n = 2\nOutput: 2\nExplanation: There are 2 groups [1], [2] of size 1." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^4", + "tags": [ + "Hash Table", + "Math" + ], + "title-slug": "count-largest-group" + }, + { + "leetcode-id": 1400, + "title": "Construct K Palindrome Strings", + "difficulty": 2, + "description": "Given a string s and an integer k, return true if you can use all the characters in s to construct k palindrome strings or false otherwise.", + "examples": [ + "Example 1:\nInput: s = \"annabelle\", k = 2\nOutput: true\nExplanation: You can construct two palindromes using all characters in s.\nSome possible constructions \"anna\" + \"elble\", \"anbna\" + \"elle\", \"anellena\" + \"b\"", + "Example 2:\nInput: s = \"leetcode\", k = 3\nOutput: false\nExplanation: It is impossible to construct 3 palindromes using all the characters of s.", + "Example 3:\nInput: s = \"true\", k = 4\nOutput: true\nExplanation: The only possible solution is to put each character in a separate string." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of lowercase English letters.\n1 <= k <= 10^5", + "tags": [ + "Hash Table", + "String", + "Greedy", + "Counting" + ], + "title-slug": "construct-k-palindrome-strings" + }, + { + "leetcode-id": 1401, + "title": "Circle and Rectangle Overlapping", + "difficulty": 2, + "description": "You are given a circle represented as (radius, xCenter, yCenter) and an axis-aligned rectangle represented as (x1, y1, x2, y2), where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-right corner of the rectangle.\nReturn true if the circle and rectangle are overlapped otherwise return false. In other words, check if there is any point (xi, yi) that belongs to the circle and the rectangle at the same time.", + "examples": [ + "Example 1:\nInput: radius = 1, xCenter = 0, yCenter = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1\nOutput: true\nExplanation: Circle and rectangle share the point (1,0).", + "Example 2:\nInput: radius = 1, xCenter = 1, yCenter = 1, x1 = 1, y1 = -3, x2 = 2, y2 = -1\nOutput: false", + "Example 3:\nInput: radius = 1, xCenter = 0, yCenter = 0, x1 = -1, y1 = 0, x2 = 0, y2 = 1\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= radius <= 2000\n-10^4 <= xCenter, yCenter <= 10^4\n-10^4 <= x1 < x2 <= 10^4\n-10^4 <= y1 < y2 <= 10^4", + "tags": [ + "Math", + "Geometry" + ], + "title-slug": "circle-and-rectangle-overlapping" + }, + { + "leetcode-id": 1402, + "title": "Reducing Dishes", + "difficulty": 3, + "description": "A chef has collected data on the satisfaction level of his n dishes. Chef can cook any dish in 1 unit of time.\nLike-time coefficient of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. time[i] * satisfaction[i].\nReturn the maximum sum of like-time coefficient that the chef can obtain after dishes preparation.\nDishes can be prepared in any order and the chef can discard some dishes to get this maximum value.", + "examples": [ + "Example 1:\nInput: satisfaction = [-1,-8,0,5,-9]\nOutput: 14\nExplanation: After Removing the second and last dish, the maximum total like-time coefficient will be equal to (-1*1 + 0*2 + 5*3 = 14).\nEach dish is prepared in one unit of time.", + "Example 2:\nInput: satisfaction = [4,3,2]\nOutput: 20\nExplanation: Dishes can be prepared in any order, (2*1 + 3*2 + 4*3 = 20)", + "Example 3:\nInput: satisfaction = [-1,-4,-5]\nOutput: 0\nExplanation: People do not like the dishes. No dish is prepared." + ], + "constraints": "Constraints:\n\nn == satisfaction.length\n1 <= n <= 500\n-1000 <= satisfaction[i] <= 1000", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy", + "Sorting" + ], + "title-slug": "reducing-dishes" + }, + { + "leetcode-id": 1403, + "title": "Minimum Subsequence in Non-Increasing Order", + "difficulty": 1, + "description": "Given the array nums, obtain a subsequence of the array whose sum of elements is strictly greater than the sum of the non\u00a0included elements in such subsequence.\u00a0\nIf there are multiple solutions, return the subsequence with minimum size and if there still exist multiple solutions, return the subsequence with the maximum total sum of all its elements. A subsequence of an array can be obtained by erasing some (possibly zero) elements from the array.\u00a0\nNote that the solution with the given constraints is guaranteed to be\u00a0unique. Also return the answer sorted in non-increasing order.", + "examples": [ + "Example 1:\nInput: nums = [4,3,10,9,8]\nOutput: [10,9] \nExplanation: The subsequences [10,9] and [10,8] are minimal such that the sum of their elements is strictly greater than the sum of elements not included. However, the subsequence [10,9] has the maximum total sum of its elements.", + "Example 2:\nInput: nums = [4,4,7,6,7]\nOutput: [7,7,6] \nExplanation: The subsequence [7,7] has the sum of its elements equal to 14 which is not strictly greater than the sum of elements not included (14 = 4 + 4 + 6). Therefore, the subsequence [7,6,7] is the minimal satisfying the conditions. Note the subsequence has to be returned in non-decreasing order." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 500\n1 <= nums[i] <= 100", + "tags": [ + "Array", + "Greedy", + "Sorting" + ], + "title-slug": "minimum-subsequence-in-non-increasing-order" + }, + { + "leetcode-id": 1404, + "title": "Number of Steps to Reduce a Number in Binary Representation to One", + "difficulty": 2, + "description": "Given the binary representation of an integer as a string s, return the number of steps to reduce it to 1 under the following rules:\n\n\nIf the current number is even, you have to divide it by 2.\n\n\nIf the current number is odd, you have to add 1 to it.\n\n\nIt is guaranteed that you can always reach one for all test cases.", + "examples": [ + "Example 1:\nInput: s = \"1101\"\nOutput: 6\nExplanation: \"1101\" corressponds to number 13 in their decimal representation.\nStep 1) 13 is odd, add 1 and obtain 14.\u00a0\nStep 2) 14 is even, divide by 2 and obtain 7.\nStep 3) 7 is odd, add 1 and obtain 8.\nStep 4) 8 is even, divide by 2 and obtain 4.\u00a0 \nStep 5) 4 is even, divide by 2 and obtain 2.\u00a0\nStep 6) 2 is even, divide by 2 and obtain 1.", + "Example 2:\nInput: s = \"10\"\nOutput: 1\nExplanation: \"10\" corressponds to number 2 in their decimal representation.\nStep 1) 2 is even, divide by 2 and obtain 1.", + "Example 3:\nInput: s = \"1\"\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= s.length\u00a0<= 500\ns consists of characters '0' or '1'\ns[0] == '1'", + "tags": [ + "String", + "Bit Manipulation" + ], + "title-slug": "number-of-steps-to-reduce-a-number-in-binary-representation-to-one" + }, + { + "leetcode-id": 1405, + "title": "Longest Happy String", + "difficulty": 2, + "description": "A string s is called happy if it satisfies the following conditions:\n\ns only contains the letters 'a', 'b', and 'c'.\ns does not contain any of \"aaa\", \"bbb\", or \"ccc\" as a substring.\ns contains at most a occurrences of the letter 'a'.\ns contains at most b occurrences of the letter 'b'.\ns contains at most c occurrences of the letter 'c'.\n\nGiven three integers a, b, and c, return the longest possible happy string. If there are multiple longest happy strings, return any of them. If there is no such string, return the empty string \"\".\nA substring is a contiguous sequence of characters within a string.", + "examples": [ + "Example 1:\nInput: a = 1, b = 1, c = 7\nOutput: \"ccaccbcc\"\nExplanation: \"ccbccacc\" would also be a correct answer.", + "Example 2:\nInput: a = 7, b = 1, c = 0\nOutput: \"aabaa\"\nExplanation: It is the only correct answer in this case." + ], + "constraints": "Constraints:\n\n0 <= a, b, c <= 100\na + b + c > 0", + "tags": [ + "String", + "Greedy", + "Heap (Priority Queue)" + ], + "title-slug": "longest-happy-string" + }, + { + "leetcode-id": 1406, + "title": "Stone Game III", + "difficulty": 3, + "description": "Alice and Bob continue their games with piles of stones. There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue.\nAlice and Bob take turns, with Alice starting first. On each player's turn, that player can take 1, 2, or 3 stones from the first remaining stones in the row.\nThe score of each player is the sum of the values of the stones taken. The score of each player is 0 initially.\nThe objective of the game is to end with the highest score, and the winner is the player with the highest score and there could be a tie. The game continues until all the stones have been taken.\nAssume Alice and Bob play optimally.\nReturn \"Alice\" if Alice will win, \"Bob\" if Bob will win, or \"Tie\" if they will end the game with the same score.", + "examples": [ + "Example 1:\nInput: stoneValue = [1,2,3,7]\nOutput: \"Bob\"\nExplanation: Alice will always lose. Her best move will be to take three piles and the score become 6. Now the score of Bob is 7 and Bob wins.", + "Example 2:\nInput: stoneValue = [1,2,3,-9]\nOutput: \"Alice\"\nExplanation: Alice must choose all the three piles at the first move to win and leave Bob with negative score.\nIf Alice chooses one pile her score will be 1 and the next move Bob's score becomes 5. In the next move, Alice will take the pile with value = -9 and lose.\nIf Alice chooses two piles her score will be 3 and the next move Bob's score becomes 3. In the next move, Alice will take the pile with value = -9 and also lose.\nRemember that both play optimally so here Alice will choose the scenario that makes her win.", + "Example 3:\nInput: stoneValue = [1,2,3,6]\nOutput: \"Tie\"\nExplanation: Alice cannot win this game. She can end the game in a draw if she decided to choose all the first three piles, otherwise she will lose." + ], + "constraints": "Constraints:\n\n1 <= stoneValue.length <= 5 * 10^4\n-1000 <= stoneValue[i] <= 1000", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Game Theory" + ], + "title-slug": "stone-game-iii" + }, + { + "leetcode-id": 1408, + "title": "String Matching in an Array", + "difficulty": 1, + "description": "Given an array of string words, return all strings in words that is a substring of another word. You can return the answer in any order.\nA substring is a contiguous sequence of characters within a string", + "examples": [ + "Example 1:\nInput: words = [\"mass\",\"as\",\"hero\",\"superhero\"]\nOutput: [\"as\",\"hero\"]\nExplanation: \"as\" is substring of \"mass\" and \"hero\" is substring of \"superhero\".\n[\"hero\",\"as\"] is also a valid answer.", + "Example 2:\nInput: words = [\"leetcode\",\"et\",\"code\"]\nOutput: [\"et\",\"code\"]\nExplanation: \"et\", \"code\" are substring of \"leetcode\".", + "Example 3:\nInput: words = [\"blue\",\"green\",\"bu\"]\nOutput: []\nExplanation: No string of words is substring of another string." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 100\n1 <= words[i].length <= 30\nwords[i] contains only lowercase English letters.\nAll the strings of words are unique.", + "tags": [ + "Array", + "String", + "String Matching" + ], + "title-slug": "string-matching-in-an-array" + }, + { + "leetcode-id": 1409, + "title": "Queries on a Permutation With Key", + "difficulty": 2, + "description": "Given the array queries of positive integers between 1 and m, you have to process all queries[i] (from i=0 to i=queries.length-1) according to the following rules:\n\nIn the beginning, you have the permutation P=[1,2,3,...,m].\nFor the current i, find the position of queries[i] in the permutation P (indexing from 0) and then move this at the beginning of the permutation P.\u00a0Notice that the position of queries[i] in P is the result for queries[i].\n\nReturn an array containing the result for the given queries.", + "examples": [ + "Example 1:\nInput: queries = [3,1,2,1], m = 5\r\nOutput: [2,1,2,1] \r\nExplanation: The queries are processed as follow: \r\nFor i=0: queries[i]=3, P=[1,2,3,4,5], position of 3 in P is 2, then we move 3 to the beginning of P resulting in P=[3,1,2,4,5]. \r\nFor i=1: queries[i]=1, P=[3,1,2,4,5], position of 1 in P is 1, then we move 1 to the beginning of P resulting in P=[1,3,2,4,5]. \r\nFor i=2: queries[i]=2, P=[1,3,2,4,5], position of 2 in P is 2, then we move 2 to the beginning of P resulting in P=[2,1,3,4,5]. \r\nFor i=3: queries[i]=1, P=[2,1,3,4,5], position of 1 in P is 1, then we move 1 to the beginning of P resulting in P=[1,2,3,4,5]. \r\nTherefore, the array containing the result is [2,1,2,1].", + "Example 2:\nInput: queries = [4,1,2,2], m = 4\r\nOutput: [3,1,2,0]", + "Example 3:\nInput: queries = [7,5,5,8,3], m = 8\r\nOutput: [6,5,0,7,5]" + ], + "constraints": "Constraints:\n\n1 <= m <= 10^3\n1 <= queries.length <= m\n1 <= queries[i] <= m", + "tags": [ + "Array", + "Binary Indexed Tree", + "Simulation" + ], + "title-slug": "queries-on-a-permutation-with-key" + }, + { + "leetcode-id": 1410, + "title": "HTML Entity Parser", + "difficulty": 2, + "description": "HTML entity parser is the parser that takes HTML code as input and replace all the entities of the special characters by the characters itself.\nThe special characters and their entities for HTML are:\n\nQuotation Mark: the entity is " and symbol character is \".\nSingle Quote Mark: the entity is ' and symbol character is '.\nAmpersand: the entity is & and symbol character is &.\nGreater Than Sign: the entity is > and symbol character is >.\nLess Than Sign: the entity is < and symbol character is <.\nSlash: the entity is ⁄ and symbol character is /.\n\nGiven the input text string to the HTML parser, you have to implement the entity parser.\nReturn the text after replacing the entities by the special characters.", + "examples": [ + "Example 1:\nInput: text = \"& is an HTML entity but &ambassador; is not.\"\nOutput: \"& is an HTML entity but &ambassador; is not.\"\nExplanation: The parser will replace the & entity by &", + "Example 2:\nInput: text = \"and I quote: "..."\"\nOutput: \"and I quote: \\\"...\\\"\"" + ], + "constraints": "Constraints:\n\n1 <= text.length <= 10^5\nThe string may contain any possible characters out of all the 256 ASCII characters.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "html-entity-parser" + }, + { + "leetcode-id": 1411, + "title": "Number of Ways to Paint N \u00d7 3 Grid", + "difficulty": 3, + "description": "You have a grid of size n x 3 and you want to paint each cell of the grid with exactly one of the three colors: Red, Yellow, or Green while making sure that no two adjacent cells have the same color (i.e., no two cells that share vertical or horizontal sides have the same color).\nGiven n the number of rows of the grid, return the number of ways you can paint this grid. As the answer may grow large, the answer must be computed modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: 12\nExplanation: There are 12 possible way to paint the grid as shown.", + "Example 2:\nInput: n = 5000\nOutput: 30228214" + ], + "constraints": "Constraints:\n\nn == grid.length\n1 <= n <= 5000", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "number-of-ways-to-paint-n-3-grid" + }, + { + "leetcode-id": 1413, + "title": "Minimum Value to Get Positive Step by Step Sum", + "difficulty": 1, + "description": "Given an array of integers\u00a0nums, you start with an initial positive value startValue.\nIn each iteration, you calculate the step by step sum of startValue\u00a0plus\u00a0elements in nums\u00a0(from left to right).\nReturn the minimum positive value of\u00a0startValue such that the step by step sum is never less than 1.", + "examples": [ + "Example 1:\nInput: nums = [-3,2,-3,4,2]\nOutput: 5\nExplanation: If you choose startValue = 4, in the third iteration your step by step sum is less than 1.\nstep by step sum\nstartValue = 4 | startValue = 5 | nums\n (4 -3 ) = 1 | (5 -3 ) = 2 | -3\n (1 +2 ) = 3 | (2 +2 ) = 4 | 2\n (3 -3 ) = 0 | (4 -3 ) = 1 | -3\n (0 +4 ) = 4 | (1 +4 ) = 5 | 4\n (4 +2 ) = 6 | (5 +2 ) = 7 | 2", + "Example 2:\nInput: nums = [1,2]\nOutput: 1\nExplanation: Minimum start value should be positive.", + "Example 3:\nInput: nums = [1,-2,-3]\nOutput: 5" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n-100 <= nums[i] <= 100", + "tags": [ + "Array", + "Prefix Sum" + ], + "title-slug": "minimum-value-to-get-positive-step-by-step-sum" + }, + { + "leetcode-id": 1414, + "title": "Find the Minimum Number of Fibonacci Numbers Whose Sum Is K", + "difficulty": 2, + "description": "Given an integer\u00a0k, return the minimum number of Fibonacci numbers whose sum is equal to k. The same Fibonacci number can be used multiple times.\nThe Fibonacci numbers are defined as:\n\nF1 = 1\nF2 = 1\nFn = Fn-1 + Fn-2 for n > 2.\n\nIt is guaranteed that for the given constraints we can always find such Fibonacci numbers that sum up to k.", + "examples": [ + "Example 1:\nInput: k = 7\nOutput: 2 \nExplanation: The Fibonacci numbers are: 1, 1, 2, 3, 5, 8, 13, ... \nFor k = 7 we can use 2 + 5 = 7.", + "Example 2:\nInput: k = 10\nOutput: 2 \nExplanation: For k = 10 we can use 2 + 8 = 10.", + "Example 3:\nInput: k = 19\nOutput: 3 \nExplanation: For k = 19 we can use 1 + 5 + 13 = 19." + ], + "constraints": "Constraints:\n\n1 <= k <= 10^9", + "tags": [ + "Math", + "Greedy" + ], + "title-slug": "find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k" + }, + { + "leetcode-id": 1415, + "title": "The k-th Lexicographical String of All Happy Strings of Length n", + "difficulty": 2, + "description": "A happy string is a string that:\n\nconsists only of letters of the set ['a', 'b', 'c'].\ns[i] != s[i + 1] for all values of i from 1 to s.length - 1 (string is 1-indexed).\n\nFor example, strings \"abc\", \"ac\", \"b\" and \"abcbabcbcb\" are all happy strings and strings \"aa\", \"baa\" and \"ababbc\" are not happy strings.\nGiven two integers n and k, consider a list of all happy strings of length n sorted in lexicographical order.\nReturn the kth string of this list or return an empty string if there are less than k happy strings of length n.", + "examples": [ + "Example 1:\nInput: n = 1, k = 3\nOutput: \"c\"\nExplanation: The list [\"a\", \"b\", \"c\"] contains all happy strings of length 1. The third string is \"c\".", + "Example 2:\nInput: n = 1, k = 4\nOutput: \"\"\nExplanation: There are only 3 happy strings of length 1.", + "Example 3:\nInput: n = 3, k = 9\nOutput: \"cab\"\nExplanation: There are 12 different happy string of length 3 [\"aba\", \"abc\", \"aca\", \"acb\", \"bab\", \"bac\", \"bca\", \"bcb\", \"cab\", \"cac\", \"cba\", \"cbc\"]. You will find the 9^th string = \"cab\"" + ], + "constraints": "Constraints:\n\n1 <= n <= 10\n1 <= k <= 100", + "tags": [ + "String", + "Backtracking" + ], + "title-slug": "the-k-th-lexicographical-string-of-all-happy-strings-of-length-n" + }, + { + "leetcode-id": 1416, + "title": "Restore The Array", + "difficulty": 3, + "description": "A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits s and all we know is that all integers in the array were in the range [1, k] and there are no leading zeros in the array.\nGiven the string s and the integer k, return the number of the possible arrays that can be printed as s using the mentioned program. Since the answer may be very large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: s = \"1000\", k = 10000\nOutput: 1\nExplanation: The only possible array is [1000]", + "Example 2:\nInput: s = \"1000\", k = 10\nOutput: 0\nExplanation: There cannot be an array that was printed this way and has all integer >= 1 and <= 10.", + "Example 3:\nInput: s = \"1317\", k = 2000\nOutput: 8\nExplanation: Possible arrays are [1317],[131,7],[13,17],[1,317],[13,1,7],[1,31,7],[1,3,17],[1,3,1,7]" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of only digits and does not contain leading zeros.\n1 <= k <= 10^9", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "restore-the-array" + }, + { + "leetcode-id": 1417, + "title": "Reformat The String", + "difficulty": 1, + "description": "You are given an alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits).\nYou have to find a permutation of the string where no letter is followed by another letter and no digit is followed by another digit. That is, no two adjacent characters have the same type.\nReturn the reformatted string or return an empty string if it is impossible to reformat the string.", + "examples": [ + "Example 1:\nInput: s = \"a0b1c2\"\nOutput: \"0a1b2c\"\nExplanation: No two adjacent characters have the same type in \"0a1b2c\". \"a0b1c2\", \"0a1b2c\", \"0c2a1b\" are also valid permutations.", + "Example 2:\nInput: s = \"leetcode\"\nOutput: \"\"\nExplanation: \"leetcode\" has only characters so we cannot separate them by digits.", + "Example 3:\nInput: s = \"1229857369\"\nOutput: \"\"\nExplanation: \"1229857369\" has only digits so we cannot separate them by characters." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 500\ns consists of only lowercase English letters and/or digits.", + "tags": [ + "String" + ], + "title-slug": "reformat-the-string" + }, + { + "leetcode-id": 1418, + "title": "Display Table of Food Orders in a Restaurant", + "difficulty": 2, + "description": "Given\u00a0the array orders, which represents the orders that customers have done in a restaurant. More specifically\u00a0orders[i]=[customerNamei,tableNumberi,foodItemi] where customerNamei is the name of the customer, tableNumberi\u00a0is the table customer sit at, and foodItemi\u00a0is the item customer orders.\nReturn the restaurant's \u201cdisplay table\u201d. The \u201cdisplay table\u201d is a table whose row entries denote how many of each food item each table ordered. The first column is the table number and the remaining columns correspond to each food item in alphabetical order. The first row should be a header whose first column is \u201cTable\u201d, followed by the names of the food items. Note that the customer names are not part of the table. Additionally, the rows should be sorted in numerically increasing order.", + "examples": [ + "Example 1:\nInput: orders = [[\"David\",\"3\",\"Ceviche\"],[\"Corina\",\"10\",\"Beef Burrito\"],[\"David\",\"3\",\"Fried Chicken\"],[\"Carla\",\"5\",\"Water\"],[\"Carla\",\"5\",\"Ceviche\"],[\"Rous\",\"3\",\"Ceviche\"]]\r\nOutput: [[\"Table\",\"Beef Burrito\",\"Ceviche\",\"Fried Chicken\",\"Water\"],[\"3\",\"0\",\"2\",\"1\",\"0\"],[\"5\",\"0\",\"1\",\"0\",\"1\"],[\"10\",\"1\",\"0\",\"0\",\"0\"]] \r\nExplanation:\r\nThe displaying table looks like:\r\nTable,Beef Burrito,Ceviche,Fried Chicken,Water\r\n3 ,0 ,2 ,1 ,0\r\n5 ,0 ,1 ,0 ,1\r\n10 ,1 ,0 ,0 ,0\r\nFor the table 3: David orders \"Ceviche\" and \"Fried Chicken\", and Rous orders \"Ceviche\".\r\nFor the table 5: Carla orders \"Water\" and \"Ceviche\".\r\nFor the table 10: Corina orders \"Beef Burrito\".", + "Example 2:\nInput: orders = [[\"James\",\"12\",\"Fried Chicken\"],[\"Ratesh\",\"12\",\"Fried Chicken\"],[\"Amadeus\",\"12\",\"Fried Chicken\"],[\"Adam\",\"1\",\"Canadian Waffles\"],[\"Brianna\",\"1\",\"Canadian Waffles\"]]\r\nOutput: [[\"Table\",\"Canadian Waffles\",\"Fried Chicken\"],[\"1\",\"2\",\"0\"],[\"12\",\"0\",\"3\"]] \r\nExplanation: \r\nFor the table 1: Adam and Brianna order \"Canadian Waffles\".\r\nFor the table 12: James, Ratesh and Amadeus order \"Fried Chicken\".", + "Example 3:\nInput: orders = [[\"Laura\",\"2\",\"Bean Burrito\"],[\"Jhon\",\"2\",\"Beef Burrito\"],[\"Melissa\",\"2\",\"Soda\"]]\r\nOutput: [[\"Table\",\"Bean Burrito\",\"Beef Burrito\",\"Soda\"],[\"2\",\"1\",\"1\",\"1\"]]" + ], + "constraints": "Constraints:\n\n1 <=\u00a0orders.length <= 5 * 10^4\norders[i].length == 3\n1 <= customerNamei.length, foodItemi.length <= 20\ncustomerNamei and foodItemi consist of lowercase and uppercase English letters and the space character.\ntableNumberi\u00a0is a valid integer between 1 and 500.", + "tags": [ + "Array", + "Hash Table", + "String", + "Sorting", + "Ordered Set" + ], + "title-slug": "display-table-of-food-orders-in-a-restaurant" + }, + { + "leetcode-id": 1419, + "title": "Minimum Number of Frogs Croaking", + "difficulty": 2, + "description": "You are given the string croakOfFrogs, which represents a combination of the string \"croak\" from different frogs, that is, multiple frogs can croak at the same time, so multiple \"croak\" are mixed.\nReturn the minimum number of different frogs to finish all the croaks in the given string.\nA valid \"croak\" means a frog is printing five letters 'c', 'r', 'o', 'a', and 'k' sequentially. The frogs have to print all five letters to finish a croak. If the given string is not a combination of a valid \"croak\" return -1.", + "examples": [ + "Example 1:\nInput: croakOfFrogs = \"croakcroak\"\nOutput: 1 \nExplanation: One frog yelling \"croak\" twice.", + "Example 2:\nInput: croakOfFrogs = \"crcoakroak\"\nOutput: 2 \nExplanation: The minimum number of frogs is two. \nThe first frog could yell \"crcoakroak\".\nThe second frog could yell later \"crcoakroak\".", + "Example 3:\nInput: croakOfFrogs = \"croakcrook\"\nOutput: -1\nExplanation: The given string is an invalid combination of \"croak\" from different frogs." + ], + "constraints": "Constraints:\n\n1 <= croakOfFrogs.length <= 10^5\ncroakOfFrogs is either 'c', 'r', 'o', 'a', or 'k'.", + "tags": [ + "String", + "Counting" + ], + "title-slug": "minimum-number-of-frogs-croaking" + }, + { + "leetcode-id": 1420, + "title": "Build Array Where You Can Find The Maximum Exactly K Comparisons", + "difficulty": 3, + "description": "You are given three integers n, m and k. Consider the following algorithm to find the maximum element of an array of positive integers:\n\nYou should build the array arr which has the following properties:\n\narr has exactly n integers.\n1 <= arr[i] <= m where (0 <= i < n).\nAfter applying the mentioned algorithm to arr, the value search_cost is equal to k.\n\nReturn the number of ways to build the array arr under the mentioned conditions. As the answer may grow large, the answer must be computed modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 2, m = 3, k = 1\nOutput: 6\nExplanation: The possible arrays are [1, 1], [2, 1], [2, 2], [3, 1], [3, 2] [3, 3]", + "Example 2:\nInput: n = 5, m = 2, k = 3\nOutput: 0\nExplanation: There are no possible arrays that satisify the mentioned conditions.", + "Example 3:\nInput: n = 9, m = 1, k = 1\nOutput: 1\nExplanation: The only possible array is [1, 1, 1, 1, 1, 1, 1, 1, 1]" + ], + "constraints": "Constraints:\n\n1 <= n <= 50\n1 <= m <= 100\n0 <= k <= n", + "tags": [ + "Dynamic Programming", + "Prefix Sum" + ], + "title-slug": "build-array-where-you-can-find-the-maximum-exactly-k-comparisons" + }, + { + "leetcode-id": 1422, + "title": "Maximum Score After Splitting a String", + "difficulty": 1, + "description": "Given a\u00a0string s\u00a0of zeros and ones, return the maximum score after splitting the string into two non-empty substrings (i.e. left substring and right substring).\nThe score after splitting a string is the number of zeros in the left substring plus the number of ones in the right substring.", + "examples": [ + "Example 1:\nInput: s = \"011101\"\nOutput: 5 \nExplanation: \nAll possible ways of splitting s into two non-empty substrings are:\nleft = \"0\" and right = \"11101\", score = 1 + 4 = 5 \nleft = \"01\" and right = \"1101\", score = 1 + 3 = 4 \nleft = \"011\" and right = \"101\", score = 1 + 2 = 3 \nleft = \"0111\" and right = \"01\", score = 1 + 1 = 2 \nleft = \"01110\" and right = \"1\", score = 2 + 1 = 3", + "Example 2:\nInput: s = \"00111\"\nOutput: 5\nExplanation: When left = \"00\" and right = \"111\", we get the maximum score = 2 + 3 = 5", + "Example 3:\nInput: s = \"1111\"\nOutput: 3" + ], + "constraints": "Constraints:\n\n2 <= s.length <= 500\nThe string s consists of characters '0' and '1' only.", + "tags": [ + "String" + ], + "title-slug": "maximum-score-after-splitting-a-string" + }, + { + "leetcode-id": 1423, + "title": "Maximum Points You Can Obtain from Cards", + "difficulty": 2, + "description": "There are several cards arranged in a row, and each card has an associated number of points. The points are given in the integer array cardPoints.\nIn one step, you can take one card from the beginning or from the end of the row. You have to take exactly k cards.\nYour score is the sum of the points of the cards you have taken.\nGiven the integer array cardPoints and the integer k, return the maximum score you can obtain.", + "examples": [ + "Example 1:\nInput: cardPoints = [1,2,3,4,5,6,1], k = 3\nOutput: 12\nExplanation: After the first step, your score will always be 1. However, choosing the rightmost card first will maximize your total score. The optimal strategy is to take the three cards on the right, giving a final score of 1 + 6 + 5 = 12.", + "Example 2:\nInput: cardPoints = [2,2,2], k = 2\nOutput: 4\nExplanation: Regardless of which two cards you take, your score will always be 4.", + "Example 3:\nInput: cardPoints = [9,7,7,9,7,7,9], k = 7\nOutput: 55\nExplanation: You have to take all the cards. Your score is the sum of points of all cards." + ], + "constraints": "Constraints:\n\n1 <= cardPoints.length <= 10^5\n1 <= cardPoints[i] <= 10^4\n1 <= k <= cardPoints.length", + "tags": [ + "Array", + "Sliding Window", + "Prefix Sum" + ], + "title-slug": "maximum-points-you-can-obtain-from-cards" + }, + { + "leetcode-id": 1424, + "title": "Diagonal Traverse II", + "difficulty": 2, + "description": "Given a 2D integer array nums, return all elements of nums in diagonal order as shown in the below images.", + "examples": [ + "Example 1:\nInput: nums = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [1,4,2,7,5,3,8,6,9]", + "Example 2:\nInput: nums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]]\nOutput: [1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i].length <= 10^5\n1 <= sum(nums[i].length) <= 10^5\n1 <= nums[i][j] <= 10^5", + "tags": [ + "Array", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "diagonal-traverse-ii" + }, + { + "leetcode-id": 1425, + "title": "Constrained Subsequence Sum", + "difficulty": 3, + "description": "Given an integer array nums and an integer k, return the maximum sum of a non-empty subsequence of that array such that for every two consecutive integers in the subsequence, nums[i] and nums[j], where i < j, the condition j - i <= k is satisfied.\nA subsequence of an array is obtained by deleting some number of elements (can be zero) from the array, leaving the remaining elements in their original order.", + "examples": [ + "Example 1:\nInput: nums = [10,2,-10,5,20], k = 2\nOutput: 37\nExplanation: The subsequence is [10, 2, 5, 20].", + "Example 2:\nInput: nums = [-1,-2,-3], k = 1\nOutput: -1\nExplanation: The subsequence must be non-empty, so we choose the largest number.", + "Example 3:\nInput: nums = [10,-2,-10,-5,20], k = 2\nOutput: 23\nExplanation: The subsequence is [10, -2, -5, 20]." + ], + "constraints": "Constraints:\n\n1 <= k <= nums.length <= 10^5\n-10^4 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Dynamic Programming", + "Queue", + "Sliding Window", + "Heap (Priority Queue)", + "Monotonic Queue" + ], + "title-slug": "constrained-subsequence-sum" + }, + { + "leetcode-id": 1431, + "title": "Kids With the Greatest Number of Candies", + "difficulty": 1, + "description": "There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the i^th kid has, and an integer extraCandies, denoting the number of extra candies that you have.\nReturn a boolean array result of length n, where result[i] is true if, after giving the i^th kid all the extraCandies, they will have the greatest number of candies among all the kids, or false otherwise.\nNote that multiple kids can have the greatest number of candies.", + "examples": [ + "Example 1:\nInput: candies = [2,3,5,1,3], extraCandies = 3\nOutput: [true,true,true,false,true] \nExplanation: If you give all extraCandies to:\n- Kid 1, they will have 2 + 3 = 5 candies, which is the greatest among the kids.\n- Kid 2, they will have 3 + 3 = 6 candies, which is the greatest among the kids.\n- Kid 3, they will have 5 + 3 = 8 candies, which is the greatest among the kids.\n- Kid 4, they will have 1 + 3 = 4 candies, which is not the greatest among the kids.\n- Kid 5, they will have 3 + 3 = 6 candies, which is the greatest among the kids.", + "Example 2:\nInput: candies = [4,2,1,1,2], extraCandies = 1\nOutput: [true,false,false,false,false] \nExplanation: There is only 1 extra candy.\nKid 1 will always have the greatest number of candies, even if a different kid is given the extra candy.", + "Example 3:\nInput: candies = [12,1,12], extraCandies = 10\nOutput: [true,false,true]" + ], + "constraints": "Constraints:\n\nn == candies.length\n2 <= n <= 100\n1 <= candies[i] <= 100\n1 <= extraCandies <= 50", + "tags": [ + "Array" + ], + "title-slug": "kids-with-the-greatest-number-of-candies" + }, + { + "leetcode-id": 1432, + "title": "Max Difference You Can Get From Changing an Integer", + "difficulty": 2, + "description": "You are given an integer num. You will apply the following steps exactly two times:\n\nPick a digit x (0 <= x <= 9).\nPick another digit y (0 <= y <= 9). The digit y can be equal to x.\nReplace all the occurrences of x in the decimal representation of num by y.\nThe new integer cannot have any leading zeros, also the new integer cannot be 0.\n\nLet a and b be the results of applying the operations to num the first and second times, respectively.\nReturn the max difference between a and b.", + "examples": [ + "Example 1:\nInput: num = 555\nOutput: 888\nExplanation: The first time pick x = 5 and y = 9 and store the new integer in a.\nThe second time pick x = 5 and y = 1 and store the new integer in b.\nWe have now a = 999 and b = 111 and max difference = 888", + "Example 2:\nInput: num = 9\nOutput: 8\nExplanation: The first time pick x = 9 and y = 9 and store the new integer in a.\nThe second time pick x = 9 and y = 1 and store the new integer in b.\nWe have now a = 9 and b = 1 and max difference = 8" + ], + "constraints": "Constraints:\n\n1 <= num <= 10^8", + "tags": [ + "Math", + "Greedy" + ], + "title-slug": "max-difference-you-can-get-from-changing-an-integer" + }, + { + "leetcode-id": 1433, + "title": "Check If a String Can Break Another String", + "difficulty": 2, + "description": "Given two strings: s1 and s2 with the same\u00a0size, check if some\u00a0permutation of string s1 can break\u00a0some\u00a0permutation of string s2 or vice-versa. In other words s2 can break s1\u00a0or vice-versa.\nA string x\u00a0can break\u00a0string y\u00a0(both of size n) if x[i] >= y[i]\u00a0(in alphabetical order)\u00a0for all i\u00a0between 0 and n-1.", + "examples": [ + "Example 1:\nInput: s1 = \"abc\", s2 = \"xya\"\nOutput: true\nExplanation: \"ayx\" is a permutation of s2=\"xya\" which can break to string \"abc\" which is a permutation of s1=\"abc\".", + "Example 2:\nInput: s1 = \"abe\", s2 = \"acd\"\nOutput: false \nExplanation: All permutations for s1=\"abe\" are: \"abe\", \"aeb\", \"bae\", \"bea\", \"eab\" and \"eba\" and all permutation for s2=\"acd\" are: \"acd\", \"adc\", \"cad\", \"cda\", \"dac\" and \"dca\". However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.", + "Example 3:\nInput: s1 = \"leetcodee\", s2 = \"interview\"\nOutput: true" + ], + "constraints": "Constraints:\n\ns1.length == n\ns2.length == n\n1 <= n <= 10^5\nAll strings consist of lowercase English letters.", + "tags": [ + "String", + "Greedy", + "Sorting" + ], + "title-slug": "check-if-a-string-can-break-another-string" + }, + { + "leetcode-id": 1434, + "title": "Number of Ways to Wear Different Hats to Each Other", + "difficulty": 3, + "description": "There are n people and 40 types of hats labeled from 1 to 40.\nGiven a 2D integer array hats, where hats[i] is a list of all hats preferred by the i^th person.\nReturn the number of ways that the n people wear different hats to each other.\nSince the answer may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: hats = [[3,4],[4,5],[5]]\nOutput: 1\nExplanation: There is only one way to choose hats given the conditions. \nFirst person choose hat 3, Second person choose hat 4 and last one hat 5.", + "Example 2:\nInput: hats = [[3,5,1],[3,5]]\nOutput: 4\nExplanation: There are 4 ways to choose hats:\n(3,5), (5,3), (1,3) and (1,5)", + "Example 3:\nInput: hats = [[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]\nOutput: 24\nExplanation: Each person can choose hats labeled from 1 to 4.\nNumber of Permutations of (1,2,3,4) = 24." + ], + "constraints": "Constraints:\n\nn == hats.length\n1 <= n <= 10\n1 <= hats[i].length <= 40\n1 <= hats[i][j] <= 40\nhats[i] contains a list of unique integers.", + "tags": [ + "Array", + "Dynamic Programming", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "number-of-ways-to-wear-different-hats-to-each-other" + }, + { + "leetcode-id": 1436, + "title": "Destination City", + "difficulty": 1, + "description": "You are given the array paths, where paths[i] = [cityAi, cityBi] means there exists a direct path going from cityAi to cityBi. Return the destination city, that is, the city without any path outgoing to another city.\nIt is guaranteed that the graph of paths forms a line without any loop, therefore, there will be exactly one destination city.", + "examples": [ + "Example 1:\nInput: paths = [[\"London\",\"New York\"],[\"New York\",\"Lima\"],[\"Lima\",\"Sao Paulo\"]]\nOutput: \"Sao Paulo\" \nExplanation: Starting at \"London\" city you will reach \"Sao Paulo\" city which is the destination city. Your trip consist of: \"London\" -> \"New York\" -> \"Lima\" -> \"Sao Paulo\".", + "Example 2:\nInput: paths = [[\"B\",\"C\"],[\"D\",\"B\"],[\"C\",\"A\"]]\nOutput: \"A\"\nExplanation: All possible trips are:\u00a0\n\"D\" -> \"B\" -> \"C\" -> \"A\".\u00a0\n\"B\" -> \"C\" -> \"A\".\u00a0\n\"C\" -> \"A\".\u00a0\n\"A\".\u00a0\nClearly the destination city is \"A\".", + "Example 3:\nInput: paths = [[\"A\",\"Z\"]]\nOutput: \"Z\"" + ], + "constraints": "Constraints:\n\n1 <= paths.length <= 100\npaths[i].length == 2\n1 <= cityAi.length, cityBi.length <= 10\ncityAi != cityBi\nAll strings consist of lowercase and uppercase English letters and the space character.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "destination-city" + }, + { + "leetcode-id": 1437, + "title": "Check If All 1's Are at Least Length K Places Away", + "difficulty": 1, + "description": "Given an binary array nums and an integer k, return true if all 1's are at least k places away from each other, otherwise return false.", + "examples": [ + "Example 1:\nInput: nums = [1,0,0,0,1,0,0,1], k = 2\nOutput: true\nExplanation: Each of the 1s are at least 2 places away from each other.", + "Example 2:\nInput: nums = [1,0,0,1,0,1], k = 2\nOutput: false\nExplanation: The second 1 and third 1 are only one apart from each other." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= k <= nums.length\nnums[i] is 0 or 1", + "tags": [ + "Array" + ], + "title-slug": "check-if-all-1s-are-at-least-length-k-places-away" + }, + { + "leetcode-id": 1438, + "title": "Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit", + "difficulty": 2, + "description": "Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.", + "examples": [ + "Example 1:\nInput: nums = [8,2,4,7], limit = 4\nOutput: 2 \nExplanation: All subarrays are: \n[8] with maximum absolute diff |8-8| = 0 <= 4.\n[8,2] with maximum absolute diff |8-2| = 6 > 4. \n[8,2,4] with maximum absolute diff |8-2| = 6 > 4.\n[8,2,4,7] with maximum absolute diff |8-2| = 6 > 4.\n[2] with maximum absolute diff |2-2| = 0 <= 4.\n[2,4] with maximum absolute diff |2-4| = 2 <= 4.\n[2,4,7] with maximum absolute diff |2-7| = 5 > 4.\n[4] with maximum absolute diff |4-4| = 0 <= 4.\n[4,7] with maximum absolute diff |4-7| = 3 <= 4.\n[7] with maximum absolute diff |7-7| = 0 <= 4. \nTherefore, the size of the longest subarray is 2.", + "Example 2:\nInput: nums = [10,1,2,4,7,2], limit = 5\nOutput: 4 \nExplanation: The subarray [2,4,7,2] is the longest since the maximum absolute diff is |2-7| = 5 <= 5.", + "Example 3:\nInput: nums = [4,2,2,2,4,4,2,2], limit = 0\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\n0 <= limit <= 10^9", + "tags": [ + "Array", + "Queue", + "Sliding Window", + "Heap (Priority Queue)", + "Ordered Set", + "Monotonic Queue" + ], + "title-slug": "longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit" + }, + { + "leetcode-id": 1439, + "title": "Find the Kth Smallest Sum of a Matrix With Sorted Rows", + "difficulty": 3, + "description": "You are given an m x n matrix mat that has its rows sorted in non-decreasing order and an integer k.\nYou are allowed to choose exactly one element from each row to form an array.\nReturn the k^th smallest array sum among all possible arrays.", + "examples": [ + "Example 1:\nInput: mat = [[1,3,11],[2,4,6]], k = 5\nOutput: 7\nExplanation: Choosing one element from each row, the first k smallest sum are:\n[1,2], [1,4], [3,2], [3,4], [1,6]. Where the 5th sum is 7.", + "Example 2:\nInput: mat = [[1,3,11],[2,4,6]], k = 9\nOutput: 17", + "Example 3:\nInput: mat = [[1,10,10],[1,4,5],[2,3,6]], k = 7\nOutput: 9\nExplanation: Choosing one element from each row, the first k smallest sum are:\n[1,1,2], [1,1,3], [1,4,2], [1,4,3], [1,1,6], [1,5,2], [1,5,3]. Where the 7th sum is 9." + ], + "constraints": "Constraints:\n\nm == mat.length\nn == mat.length[i]\n1 <= m, n <= 40\n1 <= mat[i][j] <= 5000\n1 <= k <= min(200, n^m)\nmat[i] is a non-decreasing array.", + "tags": [ + "Array", + "Binary Search", + "Heap (Priority Queue)", + "Matrix" + ], + "title-slug": "find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows" + }, + { + "leetcode-id": 1441, + "title": "Build an Array With Stack Operations", + "difficulty": 2, + "description": "You are given an integer array target and an integer n.\nYou have an empty stack with the two following operations:\n\n\"Push\": pushes an integer to the top of the stack.\n\"Pop\": removes the integer on the top of the stack.\n\nYou also have a stream of the integers in the range [1, n].\nUse the two stack operations to make the numbers in the stack (from the bottom to the top) equal to target. You should follow the following rules:\n\nIf the stream of the integers is not empty, pick the next integer from the stream and push it to the top of the stack.\nIf the stack is not empty, pop the integer at the top of the stack.\nIf, at any moment, the elements in the stack (from the bottom to the top) are equal to target, do not read new integers from the stream and do not do more operations on the stack.\n\nReturn the stack operations needed to build target following the mentioned rules. If there are multiple valid answers, return any of them.", + "examples": [ + "Example 1:\nInput: target = [1,3], n = 3\nOutput: [\"Push\",\"Push\",\"Pop\",\"Push\"]\nExplanation: Initially the stack s is empty. The last element is the top of the stack.\nRead 1 from the stream and push it to the stack. s = [1].\nRead 2 from the stream and push it to the stack. s = [1,2].\nPop the integer on the top of the stack. s = [1].\nRead 3 from the stream and push it to the stack. s = [1,3].", + "Example 2:\nInput: target = [1,2,3], n = 3\nOutput: [\"Push\",\"Push\",\"Push\"]\nExplanation: Initially the stack s is empty. The last element is the top of the stack.\nRead 1 from the stream and push it to the stack. s = [1].\nRead 2 from the stream and push it to the stack. s = [1,2].\nRead 3 from the stream and push it to the stack. s = [1,2,3].", + "Example 3:\nInput: target = [1,2], n = 4\nOutput: [\"Push\",\"Push\"]\nExplanation: Initially the stack s is empty. The last element is the top of the stack.\nRead 1 from the stream and push it to the stack. s = [1].\nRead 2 from the stream and push it to the stack. s = [1,2].\nSince the stack (from the bottom to the top) is equal to target, we stop the stack operations.\nThe answers that read integer 3 from the stream are not accepted." + ], + "constraints": "Constraints:\n\n1 <= target.length <= 100\n1 <= n <= 100\n1 <= target[i] <= n\ntarget is strictly increasing.", + "tags": [ + "Array", + "Stack", + "Simulation" + ], + "title-slug": "build-an-array-with-stack-operations" + }, + { + "leetcode-id": 1442, + "title": "Count Triplets That Can Form Two Arrays of Equal XOR", + "difficulty": 2, + "description": "Given an array of integers arr.\nWe want to select three indices i, j and k where (0 <= i < j <= k < arr.length).\nLet's define a and b as follows:\n\na = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]\nb = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]\n\nNote that ^ denotes the bitwise-xor operation.\nReturn the number of triplets (i, j and k) Where a == b.", + "examples": [ + "Example 1:\nInput: arr = [2,3,1,6,7]\nOutput: 4\nExplanation: The triplets are (0,1,2), (0,2,2), (2,3,4) and (2,4,4)", + "Example 2:\nInput: arr = [1,1,1,1,1]\nOutput: 10" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 300\n1 <= arr[i] <= 10^8", + "tags": [ + "Array", + "Hash Table", + "Math", + "Bit Manipulation", + "Prefix Sum" + ], + "title-slug": "count-triplets-that-can-form-two-arrays-of-equal-xor" + }, + { + "leetcode-id": 1443, + "title": "Minimum Time to Collect All Apples in a Tree", + "difficulty": 2, + "description": "Given an undirected tree consisting of n vertices numbered from 0 to n-1, which has some apples in their vertices. You spend 1 second to walk over one edge of the tree. Return the minimum time in seconds you have to spend to collect all apples in the tree, starting at vertex 0 and coming back to this vertex.\nThe edges of the undirected tree are given in the array edges, where edges[i] = [ai, bi] means that exists an edge connecting the vertices ai and bi. Additionally, there is a boolean array hasApple, where hasApple[i] = true means that vertex i has an apple; otherwise, it does not have any apple.", + "examples": [ + "Example 1:\nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,true,false,true,true,false]\nOutput: 8 \nExplanation: The figure above represents the given tree where red vertices have an apple. One optimal path to collect all apples is shown by the green arrows.", + "Example 2:\nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,true,false,false,true,false]\nOutput: 6\nExplanation: The figure above represents the given tree where red vertices have an apple. One optimal path to collect all apples is shown by the green arrows.", + "Example 3:\nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,false,false,false,false,false]\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5\nedges.length == n - 1\nedges[i].length == 2\n0 <= ai < bi <= n - 1\nhasApple.length == n", + "tags": [ + "Hash Table", + "Tree", + "Depth-First Search", + "Breadth-First Search" + ], + "title-slug": "minimum-time-to-collect-all-apples-in-a-tree" + }, + { + "leetcode-id": 1444, + "title": "Number of Ways of Cutting a Pizza", + "difficulty": 3, + "description": "Given a rectangular pizza represented as a rows x cols\u00a0matrix containing the following characters: 'A' (an apple) and '.' (empty cell) and given the integer k. You have to cut the pizza into k pieces using k-1 cuts.\u00a0\nFor each cut you choose the direction: vertical or horizontal, then you choose a cut position at the cell boundary and cut the pizza into two pieces. If you cut the pizza vertically, give the left part of the pizza to a person. If you cut the pizza horizontally, give the upper part of the pizza to a person. Give the last piece of pizza to the last person.\nReturn the number of ways of cutting the pizza such that each piece contains at least one apple.\u00a0Since the answer can be a huge number, return this modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: pizza = [\"A..\",\"AAA\",\"...\"], k = 3\nOutput: 3 \nExplanation: The figure above shows the three ways to cut the pizza. Note that pieces must contain at least one apple.", + "Example 2:\nInput: pizza = [\"A..\",\"AA.\",\"...\"], k = 3\nOutput: 1", + "Example 3:\nInput: pizza = [\"A..\",\"A..\",\"...\"], k = 1\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= rows, cols <= 50\nrows ==\u00a0pizza.length\ncols ==\u00a0pizza[i].length\n1 <= k <= 10\npizza consists of characters 'A'\u00a0and '.' only.", + "tags": [ + "Array", + "Dynamic Programming", + "Memoization", + "Matrix" + ], + "title-slug": "number-of-ways-of-cutting-a-pizza" + }, + { + "leetcode-id": 1446, + "title": "Consecutive Characters", + "difficulty": 1, + "description": "The power of the string is the maximum length of a non-empty substring that contains only one unique character.\nGiven a string s, return the power of s.", + "examples": [ + "Example 1:\nInput: s = \"leetcode\"\nOutput: 2\nExplanation: The substring \"ee\" is of length 2 with the character 'e' only.", + "Example 2:\nInput: s = \"abbcccddddeeeeedcba\"\nOutput: 5\nExplanation: The substring \"eeeee\" is of length 5 with the character 'e' only." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 500\ns consists of only lowercase English letters.", + "tags": [ + "String" + ], + "title-slug": "consecutive-characters" + }, + { + "leetcode-id": 1447, + "title": "Simplified Fractions", + "difficulty": 2, + "description": "Given an integer n, return a list of all simplified fractions between 0 and 1 (exclusive) such that the denominator is less-than-or-equal-to n. You can return the answer in any order.", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: [\"1/2\"]\nExplanation: \"1/2\" is the only unique fraction with a denominator less-than-or-equal-to 2.", + "Example 2:\nInput: n = 3\nOutput: [\"1/2\",\"1/3\",\"2/3\"]", + "Example 3:\nInput: n = 4\nOutput: [\"1/2\",\"1/3\",\"1/4\",\"2/3\",\"3/4\"]\nExplanation: \"2/4\" is not a simplified fraction because it can be simplified to \"1/2\"." + ], + "constraints": "Constraints:\n\n1 <= n <= 100", + "tags": [ + "Math", + "String", + "Number Theory" + ], + "title-slug": "simplified-fractions" + }, + { + "leetcode-id": 1448, + "title": "Count Good Nodes in Binary Tree", + "difficulty": 2, + "description": "Given a binary tree root, a node X in the tree is named\u00a0good if in the path from root to X there are no nodes with a value greater than X.\nReturn the number of good nodes in the binary tree.", + "examples": [ + "Example 1:\nInput: root = [3,1,4,3,null,1,5]\r\nOutput: 4\r\nExplanation: Nodes in blue are good.\r\nRoot Node (3) is always a good node.\r\nNode 4 -> (3,4) is the maximum value in the path starting from the root.\r\nNode 5 -> (3,4,5) is the maximum value in the path\r\nNode 3 -> (3,1,3) is the maximum value in the path.", + "Example 2:\nInput: root = [3,3,null,4,2]\r\nOutput: 3\r\nExplanation: Node 2 -> (3, 3, 2) is not good, because \"3\" is higher than it.", + "Example 3:\nInput: root = [1]\r\nOutput: 1\r\nExplanation: Root is considered as good." + ], + "constraints": "Constraints:\n\nThe number of nodes in the binary tree is in the range\u00a0[1, 10^5].\nEach node's value is between [-10^4, 10^4].", + "tags": [ + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "count-good-nodes-in-binary-tree" + }, + { + "leetcode-id": 1449, + "title": "Form Largest Integer With Digits That Add up to Target", + "difficulty": 3, + "description": "Given an array of integers cost and an integer target, return the maximum integer you can paint under the following rules:\n\nThe cost of painting a digit (i + 1) is given by cost[i] (0-indexed).\nThe total cost used must be equal to target.\nThe integer does not have 0 digits.\n\nSince the answer may be very large, return it as a string. If there is no way to paint any integer given the condition, return \"0\".", + "examples": [ + "Example 1:\nInput: cost = [4,3,2,5,6,7,2,5,5], target = 9\nOutput: \"7772\"\nExplanation: The cost to paint the digit '7' is 2, and the digit '2' is 3. Then cost(\"7772\") = 2*3+ 3*1 = 9. You could also paint \"977\", but \"7772\" is the largest number.\nDigit cost\n 1 -> 4\n 2 -> 3\n 3 -> 2\n 4 -> 5\n 5 -> 6\n 6 -> 7\n 7 -> 2\n 8 -> 5\n 9 -> 5", + "Example 2:\nInput: cost = [7,6,5,5,5,6,8,7,8], target = 12\nOutput: \"85\"\nExplanation: The cost to paint the digit '8' is 7, and the digit '5' is 5. Then cost(\"85\") = 7 + 5 = 12.", + "Example 3:\nInput: cost = [2,4,6,2,4,6,4,4,4], target = 5\nOutput: \"0\"\nExplanation: It is impossible to paint any integer with total cost equal to target." + ], + "constraints": "Constraints:\n\ncost.length == 9\n1 <= cost[i], target <= 5000", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "form-largest-integer-with-digits-that-add-up-to-target" + }, + { + "leetcode-id": 1450, + "title": "Number of Students Doing Homework at a Given Time", + "difficulty": 1, + "description": "Given two integer arrays startTime and endTime and given an integer queryTime.\nThe ith student started doing their homework at the time startTime[i] and finished it at time endTime[i].\nReturn the number of students doing their homework at time queryTime. More formally, return the number of students where queryTime lays in the interval [startTime[i], endTime[i]] inclusive.", + "examples": [ + "Example 1:\nInput: startTime = [1,2,3], endTime = [3,2,7], queryTime = 4\nOutput: 1\nExplanation: We have 3 students where:\nThe first student started doing homework at time 1 and finished at time 3 and wasn't doing anything at time 4.\nThe second student started doing homework at time 2 and finished at time 2 and also wasn't doing anything at time 4.\nThe third student started doing homework at time 3 and finished at time 7 and was the only student doing homework at time 4.", + "Example 2:\nInput: startTime = [4], endTime = [4], queryTime = 4\nOutput: 1\nExplanation: The only student was doing their homework at the queryTime." + ], + "constraints": "Constraints:\n\nstartTime.length == endTime.length\n1 <= startTime.length <= 100\n1 <= startTime[i] <= endTime[i] <= 1000\n1 <= queryTime <= 1000", + "tags": [ + "Array" + ], + "title-slug": "number-of-students-doing-homework-at-a-given-time" + }, + { + "leetcode-id": 1451, + "title": "Rearrange Words in a Sentence", + "difficulty": 2, + "description": "Given a sentence\u00a0text (A\u00a0sentence\u00a0is a string of space-separated words) in the following format:\n\nFirst letter is in upper case.\nEach word in text are separated by a single space.\n\nYour task is to rearrange the words in text such that\u00a0all words are rearranged in an increasing order of their lengths. If two words have the same length, arrange them in their original order.\nReturn the new text\u00a0following the format shown above.", + "examples": [ + "Example 1:\nInput: text = \"Leetcode is cool\"\nOutput: \"Is cool leetcode\"\nExplanation: There are 3 words, \"Leetcode\" of length 8, \"is\" of length 2 and \"cool\" of length 4.\nOutput is ordered by length and the new first word starts with capital letter.", + "Example 2:\nInput: text = \"Keep calm and code on\"\nOutput: \"On and keep calm code\"\nExplanation: Output is ordered as follows:\n\"On\" 2 letters.\n\"and\" 3 letters.\n\"keep\" 4 letters in case of tie order by position in original text.\n\"calm\" 4 letters.\n\"code\" 4 letters.", + "Example 3:\nInput: text = \"To be or not to be\"\nOutput: \"To be or to be not\"" + ], + "constraints": "Constraints:\n\ntext begins with a capital letter and then contains lowercase letters and single space between words.\n1 <= text.length <= 10^5", + "tags": [ + "String", + "Sorting" + ], + "title-slug": "rearrange-words-in-a-sentence" + }, + { + "leetcode-id": 1452, + "title": "People Whose List of Favorite Companies Is Not a Subset of Another List", + "difficulty": 2, + "description": "Given the array favoriteCompanies where favoriteCompanies[i] is the list of favorites companies for the ith person (indexed from 0).\nReturn the indices of people whose list of favorite companies is not a subset of any other list of favorites companies. You must return the indices in increasing order.", + "examples": [ + "Example 1:\nInput: favoriteCompanies = [[\"leetcode\",\"google\",\"facebook\"],[\"google\",\"microsoft\"],[\"google\",\"facebook\"],[\"google\"],[\"amazon\"]]\nOutput: [0,1,4] \nExplanation: \nPerson with index=2 has favoriteCompanies[2]=[\"google\",\"facebook\"] which is a subset of favoriteCompanies[0]=[\"leetcode\",\"google\",\"facebook\"] corresponding to the person with index 0. \nPerson with index=3 has favoriteCompanies[3]=[\"google\"] which is a subset of favoriteCompanies[0]=[\"leetcode\",\"google\",\"facebook\"] and favoriteCompanies[1]=[\"google\",\"microsoft\"]. \nOther lists of favorite companies are not a subset of another list, therefore, the answer is [0,1,4].", + "Example 2:\nInput: favoriteCompanies = [[\"leetcode\",\"google\",\"facebook\"],[\"leetcode\",\"amazon\"],[\"facebook\",\"google\"]]\nOutput: [0,1] \nExplanation: In this case favoriteCompanies[2]=[\"facebook\",\"google\"] is a subset of favoriteCompanies[0]=[\"leetcode\",\"google\",\"facebook\"], therefore, the answer is [0,1].", + "Example 3:\nInput: favoriteCompanies = [[\"leetcode\"],[\"google\"],[\"facebook\"],[\"amazon\"]]\nOutput: [0,1,2,3]" + ], + "constraints": "Constraints:\n\n1 <= favoriteCompanies.length <= 100\n1 <= favoriteCompanies[i].length <= 500\n1 <= favoriteCompanies[i][j].length <= 20\nAll strings in favoriteCompanies[i] are distinct.\nAll lists of favorite companies are distinct, that is, If we sort alphabetically each list then favoriteCompanies[i] != favoriteCompanies[j].\nAll strings consist of lowercase English letters only.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list" + }, + { + "leetcode-id": 1453, + "title": "Maximum Number of Darts Inside of a Circular Dartboard", + "difficulty": 3, + "description": "Alice is throwing n darts on a very large wall. You are given an array darts where darts[i] = [xi, yi] is the position of the i^th dart that Alice threw on the wall.\nBob knows the positions of the n darts on the wall. He wants to place a dartboard of radius r on the wall so that the maximum number of darts that Alice throws lie\u00a0on the dartboard.\nGiven the integer r, return the maximum number of darts that can lie on the dartboard.", + "examples": [ + "Example 1:\nInput: darts = [[-2,0],[2,0],[0,2],[0,-2]], r = 2\nOutput: 4\nExplanation: Circle dartboard with center in (0,0) and radius = 2 contain all points.", + "Example 2:\nInput: darts = [[-3,0],[3,0],[2,6],[5,4],[0,9],[7,8]], r = 5\nOutput: 5\nExplanation: Circle dartboard with center in (0,4) and radius = 5 contain all points except the point (7,8)." + ], + "constraints": "Constraints:\n\n1 <= darts.length <= 100\ndarts[i].length == 2\n-10^4 <= xi, yi <= 10^4\nAll the darts\u00a0are unique\n1 <= r <= 5000", + "tags": [ + "Array", + "Math", + "Geometry" + ], + "title-slug": "maximum-number-of-darts-inside-of-a-circular-dartboard" + }, + { + "leetcode-id": 1455, + "title": "Check If a Word Occurs As a Prefix of Any Word in a Sentence", + "difficulty": 1, + "description": "Given a sentence that consists of some words separated by a single space, and a searchWord, check if searchWord is a prefix of any word in sentence.\nReturn the index of the word in sentence (1-indexed) where searchWord is a prefix of this word. If searchWord is a prefix of more than one word, return the index of the first word (minimum index). If there is no such word return -1.\nA prefix of a string s is any leading contiguous substring of s.", + "examples": [ + "Example 1:\nInput: sentence = \"i love eating burger\", searchWord = \"burg\"\nOutput: 4\nExplanation: \"burg\" is prefix of \"burger\" which is the 4th word in the sentence.", + "Example 2:\nInput: sentence = \"this problem is an easy problem\", searchWord = \"pro\"\nOutput: 2\nExplanation: \"pro\" is prefix of \"problem\" which is the 2nd and the 6th word in the sentence, but we return 2 as it's the minimal index.", + "Example 3:\nInput: sentence = \"i am tired\", searchWord = \"you\"\nOutput: -1\nExplanation: \"you\" is not a prefix of any word in the sentence." + ], + "constraints": "Constraints:\n\n1 <= sentence.length <= 100\n1 <= searchWord.length <= 10\nsentence consists of lowercase English letters and spaces.\nsearchWord consists of lowercase English letters.", + "tags": [ + "String", + "String Matching" + ], + "title-slug": "check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence" + }, + { + "leetcode-id": 1456, + "title": "Maximum Number of Vowels in a Substring of Given Length", + "difficulty": 2, + "description": "Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k.\nVowel letters in English are 'a', 'e', 'i', 'o', and 'u'.", + "examples": [ + "Example 1:\nInput: s = \"abciiidef\", k = 3\nOutput: 3\nExplanation: The substring \"iii\" contains 3 vowel letters.", + "Example 2:\nInput: s = \"aeiou\", k = 2\nOutput: 2\nExplanation: Any substring of length 2 contains 2 vowels.", + "Example 3:\nInput: s = \"leetcode\", k = 3\nOutput: 2\nExplanation: \"lee\", \"eet\" and \"ode\" contain 2 vowels." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of lowercase English letters.\n1 <= k <= s.length", + "tags": [ + "String", + "Sliding Window" + ], + "title-slug": "maximum-number-of-vowels-in-a-substring-of-given-length" + }, + { + "leetcode-id": 1457, + "title": "Pseudo-Palindromic Paths in a Binary Tree", + "difficulty": 2, + "description": "Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be pseudo-palindromic if at least one permutation of the node values in the path is a palindrome.\nReturn the number of pseudo-palindromic paths going from the root node to leaf nodes.", + "examples": [ + "Example 1:\nInput: root = [2,3,1,3,1,null,1]\nOutput: 2 \nExplanation: The figure above represents the given binary tree. There are three paths going from the root node to leaf nodes: the red path [2,3,3], the green path [2,1,1], and the path [2,3,1]. Among these paths only red path and green path are pseudo-palindromic paths since the red path [2,3,3] can be rearranged in [3,2,3] (palindrome) and the green path [2,1,1] can be rearranged in [1,2,1] (palindrome).", + "Example 2:\nInput: root = [2,1,1,1,3,null,null,null,null,null,1]\nOutput: 1 \nExplanation: The figure above represents the given binary tree. There are three paths going from the root node to leaf nodes: the green path [2,1,1], the path [2,1,3,1], and the path [2,1]. Among these paths only the green path is pseudo-palindromic since [2,1,1] can be rearranged in [1,2,1] (palindrome).", + "Example 3:\nInput: root = [9]\nOutput: 1" + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^5].\n1 <= Node.val <= 9", + "tags": [ + "Bit Manipulation", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "pseudo-palindromic-paths-in-a-binary-tree" + }, + { + "leetcode-id": 1458, + "title": "Max Dot Product of Two Subsequences", + "difficulty": 3, + "description": "Given two arrays nums1\u00a0and nums2.\nReturn the maximum dot product\u00a0between\u00a0non-empty subsequences of nums1 and nums2 with the same length.\nA subsequence of a array is a new array which is formed from the original array by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie,\u00a0[2,3,5]\u00a0is a subsequence of\u00a0[1,2,3,4,5]\u00a0while [1,5,3]\u00a0is not).", + "examples": [ + "Example 1:\nInput: nums1 = [2,1,-2,5], nums2 = [3,0,-6]\nOutput: 18\nExplanation: Take subsequence [2,-2] from nums1 and subsequence [3,-6] from nums2.\nTheir dot product is (2*3 + (-2)*(-6)) = 18.", + "Example 2:\nInput: nums1 = [3,-2], nums2 = [2,-6,7]\nOutput: 21\nExplanation: Take subsequence [3] from nums1 and subsequence [7] from nums2.\nTheir dot product is (3*7) = 21.", + "Example 3:\nInput: nums1 = [-1,-1], nums2 = [1,1]\nOutput: -1\nExplanation: Take subsequence [-1] from nums1 and subsequence [1] from nums2.\nTheir dot product is -1." + ], + "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 500\n-1000 <= nums1[i], nums2[i] <= 1000", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "max-dot-product-of-two-subsequences" + }, + { + "leetcode-id": 1460, + "title": "Make Two Arrays Equal by Reversing Subarrays", + "difficulty": 1, + "description": "You are given two integer arrays of equal length target and arr. In one step, you can select any non-empty subarray of arr and reverse it. You are allowed to make any number of steps.\nReturn true if you can make arr equal to target\u00a0or false otherwise.", + "examples": [ + "Example 1:\nInput: target = [1,2,3,4], arr = [2,4,1,3]\nOutput: true\nExplanation: You can follow the next steps to convert arr to target:\n1- Reverse subarray [2,4,1], arr becomes [1,4,2,3]\n2- Reverse subarray [4,2], arr becomes [1,2,4,3]\n3- Reverse subarray [4,3], arr becomes [1,2,3,4]\nThere are multiple ways to convert arr to target, this is not the only way to do so.", + "Example 2:\nInput: target = [7], arr = [7]\nOutput: true\nExplanation: arr is equal to target without any reverses.", + "Example 3:\nInput: target = [3,7,9], arr = [3,7,11]\nOutput: false\nExplanation: arr does not have value 9 and it can never be converted to target." + ], + "constraints": "Constraints:\n\ntarget.length == arr.length\n1 <= target.length <= 1000\n1 <= target[i] <= 1000\n1 <= arr[i] <= 1000", + "tags": [ + "Array", + "Hash Table", + "Sorting" + ], + "title-slug": "make-two-arrays-equal-by-reversing-subarrays" + }, + { + "leetcode-id": 1461, + "title": "Check If a String Contains All Binary Codes of Size K", + "difficulty": 2, + "description": "Given a binary string s and an integer k, return true if every binary code of length k is a substring of s. Otherwise, return false.", + "examples": [ + "Example 1:\nInput: s = \"00110110\", k = 2\nOutput: true\nExplanation: The binary codes of length 2 are \"00\", \"01\", \"10\" and \"11\". They can be all found as substrings at indices 0, 1, 3 and 2 respectively.", + "Example 2:\nInput: s = \"0110\", k = 1\nOutput: true\nExplanation: The binary codes of length 1 are \"0\" and \"1\", it is clear that both exist as a substring.", + "Example 3:\nInput: s = \"0110\", k = 2\nOutput: false\nExplanation: The binary code \"00\" is of length 2 and does not exist in the array." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 5 * 10^5\ns[i] is either '0' or '1'.\n1 <= k <= 20", + "tags": [ + "Hash Table", + "String", + "Bit Manipulation", + "Rolling Hash", + "Hash Function" + ], + "title-slug": "check-if-a-string-contains-all-binary-codes-of-size-k" + }, + { + "leetcode-id": 1462, + "title": "Course Schedule IV", + "difficulty": 2, + "description": "There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course ai first if you want to take course bi.\n\nFor example, the pair [0, 1] indicates that you have to take course 0 before you can take course 1.\n\nPrerequisites can also be indirect. If course a is a prerequisite of course b, and course b is a prerequisite of course c, then course a is a prerequisite of course c.\nYou are also given an array queries where queries[j] = [uj, vj]. For the j^th query, you should answer whether course uj is a prerequisite of course vj or not.\nReturn a boolean array answer, where answer[j] is the answer to the j^th query.", + "examples": [ + "Example 1:\nInput: numCourses = 2, prerequisites = [[1,0]], queries = [[0,1],[1,0]]\nOutput: [false,true]\nExplanation: The pair [1, 0] indicates that you have to take course 1 before you can take course 0.\nCourse 0 is not a prerequisite of course 1, but the opposite is true.", + "Example 2:\nInput: numCourses = 2, prerequisites = [], queries = [[1,0],[0,1]]\nOutput: [false,false]\nExplanation: There are no prerequisites, and each course is independent.", + "Example 3:\nInput: numCourses = 3, prerequisites = [[1,2],[1,0],[2,0]], queries = [[1,0],[1,2]]\nOutput: [true,true]" + ], + "constraints": "Constraints:\n\n2 <= numCourses <= 100\n0 <= prerequisites.length <= (numCourses * (numCourses - 1) / 2)\nprerequisites[i].length == 2\n0 <= ai, bi <= n - 1\nai != bi\nAll the pairs [ai, bi] are unique.\nThe prerequisites graph has no cycles.\n1 <= queries.length <= 10^4\n0 <= ui, vi <= n - 1\nui != vi", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Graph", + "Topological Sort" + ], + "title-slug": "course-schedule-iv" + }, + { + "leetcode-id": 1463, + "title": "Cherry Pickup II", + "difficulty": 3, + "description": "You are given a rows x cols matrix grid representing a field of cherries where grid[i][j] represents the number of cherries that you can collect from the (i, j) cell.\nYou have two robots that can collect cherries for you:\n\nRobot #1 is located at the top-left corner (0, 0), and\nRobot #2 is located at the top-right corner (0, cols - 1).\n\nReturn the maximum number of cherries collection using both robots by following the rules below:\n\nFrom a cell (i, j), robots can move to cell (i + 1, j - 1), (i + 1, j), or (i + 1, j + 1).\nWhen any robot passes through a cell, It picks up all cherries, and the cell becomes an empty cell.\nWhen both robots stay in the same cell, only one takes the cherries.\nBoth robots cannot move outside of the grid at any moment.\nBoth robots should reach the bottom row in grid.", + "examples": [ + "Example 1:\nInput: grid = [[3,1,1],[2,5,1],[1,5,5],[2,1,1]]\nOutput: 24\nExplanation: Path of robot #1 and #2 are described in color green and blue respectively.\nCherries taken by Robot #1, (3 + 2 + 5 + 2) = 12.\nCherries taken by Robot #2, (1 + 5 + 5 + 1) = 12.\nTotal of cherries: 12 + 12 = 24.", + "Example 2:\nInput: grid = [[1,0,0,0,0,0,1],[2,0,0,0,0,3,0],[2,0,9,0,0,0,0],[0,3,0,5,4,0,0],[1,0,2,3,0,0,6]]\nOutput: 28\nExplanation: Path of robot #1 and #2 are described in color green and blue respectively.\nCherries taken by Robot #1, (1 + 9 + 5 + 2) = 17.\nCherries taken by Robot #2, (1 + 3 + 4 + 3) = 11.\nTotal of cherries: 17 + 11 = 28." + ], + "constraints": "Constraints:\n\nrows == grid.length\ncols == grid[i].length\n2 <= rows, cols <= 70\n0 <= grid[i][j] <= 100", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "cherry-pickup-ii" + }, + { + "leetcode-id": 1464, + "title": "Maximum Product of Two Elements in an Array", + "difficulty": 1, + "description": "Given the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)*(nums[j]-1).", + "examples": [ + "Example 1:\nInput: nums = [3,4,5,2]\nOutput: 12 \nExplanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]-1)*(nums[2]-1) = (4-1)*(5-1) = 3*4 = 12.", + "Example 2:\nInput: nums = [1,5,4,5]\nOutput: 16\nExplanation: Choosing the indices i=1 and j=3 (indexed from 0), you will get the maximum value of (5-1)*(5-1) = 16.", + "Example 3:\nInput: nums = [3,7]\nOutput: 12" + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 500\n1 <= nums[i] <= 10^3", + "tags": [ + "Array", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "maximum-product-of-two-elements-in-an-array" + }, + { + "leetcode-id": 1465, + "title": "Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts", + "difficulty": 2, + "description": "You are given a rectangular cake of size h x w and two arrays of integers horizontalCuts and verticalCuts where:\n\nhorizontalCuts[i] is the distance from the top of the rectangular cake to the i^th horizontal cut and similarly, and\nverticalCuts[j] is the distance from the left of the rectangular cake to the j^th vertical cut.\n\nReturn the maximum area of a piece of cake after you cut at each horizontal and vertical position provided in the arrays horizontalCuts and verticalCuts. Since the answer can be a large number, return this modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: h = 5, w = 4, horizontalCuts = [1,2,4], verticalCuts = [1,3]\nOutput: 4 \nExplanation: The figure above represents the given rectangular cake. Red lines are the horizontal and vertical cuts. After you cut the cake, the green piece of cake has the maximum area.", + "Example 2:\nInput: h = 5, w = 4, horizontalCuts = [3,1], verticalCuts = [1]\nOutput: 6\nExplanation: The figure above represents the given rectangular cake. Red lines are the horizontal and vertical cuts. After you cut the cake, the green and yellow pieces of cake have the maximum area.", + "Example 3:\nInput: h = 5, w = 4, horizontalCuts = [3], verticalCuts = [3]\nOutput: 9" + ], + "constraints": "Constraints:\n\n2 <= h, w <= 10^9\n1 <= horizontalCuts.length <= min(h - 1, 10^5)\n1 <= verticalCuts.length <= min(w - 1, 10^5)\n1 <= horizontalCuts[i] < h\n1 <= verticalCuts[i] < w\nAll the elements in horizontalCuts are distinct.\nAll the elements in verticalCuts are distinct.", + "tags": [ + "Array", + "Greedy", + "Sorting" + ], + "title-slug": "maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts" + }, + { + "leetcode-id": 1466, + "title": "Reorder Routes to Make All Paths Lead to the City Zero", + "difficulty": 2, + "description": "There are n cities numbered from 0 to n - 1 and n - 1 roads such that there is only one way to travel between two different cities (this network form a tree). Last year, The ministry of transport decided to orient the roads in one direction because they are too narrow.\nRoads are represented by connections where connections[i] = [ai, bi] represents a road from city ai to city bi.\nThis year, there will be a big event in the capital (city 0), and many people want to travel to this city.\nYour task consists of reorienting some roads such that each city can visit the city 0. Return the minimum number of edges changed.\nIt's guaranteed that each city can reach city 0 after reorder.", + "examples": [ + "Example 1:\nInput: n = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]]\nOutput: 3\nExplanation: Change the direction of edges show in red such that each node can reach the node 0 (capital).", + "Example 2:\nInput: n = 5, connections = [[1,0],[1,2],[3,2],[3,4]]\nOutput: 2\nExplanation: Change the direction of edges show in red such that each node can reach the node 0 (capital).", + "Example 3:\nInput: n = 3, connections = [[1,0],[2,0]]\nOutput: 0" + ], + "constraints": "Constraints:\n\n2 <= n <= 5 * 10^4\nconnections.length == n - 1\nconnections[i].length == 2\n0 <= ai, bi <= n - 1\nai != bi", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Graph" + ], + "title-slug": "reorder-routes-to-make-all-paths-lead-to-the-city-zero" + }, + { + "leetcode-id": 1467, + "title": "Probability of a Two Boxes Having The Same Number of Distinct Balls", + "difficulty": 3, + "description": "Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.\nAll the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanation of the second example carefully).\nPlease note that the two boxes are considered different. For example, if we have two balls of colors a and b, and two boxes [] and (), then the distribution [a] (b) is considered different than the distribution [b] (a) (Please read the explanation of the first example carefully).\nReturn the probability that the two boxes have the same number of distinct balls. Answers within 10^-5 of the actual value will be accepted as correct.", + "examples": [ + "Example 1:\nInput: balls = [1,1]\nOutput: 1.00000\nExplanation: Only 2 ways to divide the balls equally:\n- A ball of color 1 to box 1 and a ball of color 2 to box 2\n- A ball of color 2 to box 1 and a ball of color 1 to box 2\nIn both ways, the number of distinct colors in each box is equal. The probability is 2/2 = 1", + "Example 2:\nInput: balls = [2,1,1]\nOutput: 0.66667\nExplanation: We have the set of balls [1, 1, 2, 3]\nThis set of balls will be shuffled randomly and we may have one of the 12 distinct shuffles with equal probability (i.e. 1/12):\n[1,1 / 2,3], [1,1 / 3,2], [1,2 / 1,3], [1,2 / 3,1], [1,3 / 1,2], [1,3 / 2,1], [2,1 / 1,3], [2,1 / 3,1], [2,3 / 1,1], [3,1 / 1,2], [3,1 / 2,1], [3,2 / 1,1]\nAfter that, we add the first two balls to the first box and the second two balls to the second box.\nWe can see that 8 of these 12 possible random distributions have the same number of distinct colors of balls in each box.\nProbability is 8/12 = 0.66667", + "Example 3:\nInput: balls = [1,2,1,2]\nOutput: 0.60000\nExplanation: The set of balls is [1, 2, 2, 3, 4, 4]. It is hard to display all the 180 possible random shuffles of this set but it is easy to check that 108 of them will have the same number of distinct colors in each box.\nProbability = 108 / 180 = 0.6" + ], + "constraints": "Constraints:\n\n1 <= balls.length <= 8\n1 <= balls[i] <= 6\nsum(balls) is even.", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Backtracking", + "Combinatorics", + "Probability and Statistics" + ], + "title-slug": "probability-of-a-two-boxes-having-the-same-number-of-distinct-balls" + }, + { + "leetcode-id": 1470, + "title": "Shuffle the Array", + "difficulty": 1, + "description": "Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].\nReturn the array in the form [x1,y1,x2,y2,...,xn,yn].", + "examples": [ + "Example 1:\nInput: nums = [2,5,1,3,4,7], n = 3\r\nOutput: [2,3,5,4,1,7] \r\nExplanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7].", + "Example 2:\nInput: nums = [1,2,3,4,4,3,2,1], n = 4\r\nOutput: [1,4,2,3,3,2,4,1]", + "Example 3:\nInput: nums = [1,1,2,2], n = 2\r\nOutput: [1,2,1,2]" + ], + "constraints": "Constraints:\n\n1 <= n <= 500\nnums.length == 2n\n1 <= nums[i] <= 10^3", + "tags": [ + "Array" + ], + "title-slug": "shuffle-the-array" + }, + { + "leetcode-id": 1471, + "title": "The k Strongest Values in an Array", + "difficulty": 2, + "description": "Given an array of integers arr and an integer k.\nA value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array.\nIf |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j].\nReturn a list of the strongest k values in the array. return the answer in any arbitrary order.\nMedian is the middle value in an ordered integer list. More formally, if the length of the list is n, the median is the element in position ((n - 1) / 2) in the sorted list (0-indexed).\n\nFor arr = [6, -3, 7, 2, 11], n = 5 and the median is obtained by sorting the array arr = [-3, 2, 6, 7, 11] and the median is arr[m] where m = ((5 - 1) / 2) = 2. The median is 6.\nFor arr = [-7, 22, 17,\u20093], n = 4 and the median is obtained by sorting the array arr = [-7, 3, 17, 22] and the median is arr[m] where m = ((4 - 1) / 2) = 1. The median is 3.", + "examples": [ + "Example 1:\nInput: arr = [1,2,3,4,5], k = 2\nOutput: [5,1]\nExplanation: Median is 3, the elements of the array sorted by the strongest are [5,1,4,2,3]. The strongest 2 elements are [5, 1]. [1, 5] is also accepted answer.\nPlease note that although |5 - 3| == |1 - 3| but 5 is stronger than 1 because 5 > 1.", + "Example 2:\nInput: arr = [1,1,3,5,5], k = 2\nOutput: [5,5]\nExplanation: Median is 3, the elements of the array sorted by the strongest are [5,5,1,1,3]. The strongest 2 elements are [5, 5].", + "Example 3:\nInput: arr = [6,7,11,7,6,8], k = 5\nOutput: [11,8,6,6,7]\nExplanation: Median is 7, the elements of the array sorted by the strongest are [11,8,6,6,7,7].\nAny permutation of [11,8,6,6,7] is accepted." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^5\n-10^5 <= arr[i] <= 10^5\n1 <= k <= arr.length", + "tags": [ + "Array", + "Two Pointers", + "Sorting" + ], + "title-slug": "the-k-strongest-values-in-an-array" + }, + { + "leetcode-id": 1472, + "title": "Design Browser History", + "difficulty": 2, + "description": "You have a browser of one tab where you start on the homepage and you can visit another url, get back in the history number of steps or move forward in the history number of steps.\nImplement the BrowserHistory class:\n\nBrowserHistory(string homepage) Initializes the object with the homepage\u00a0of the browser.\nvoid visit(string url)\u00a0Visits\u00a0url from the current page. It clears up all the forward history.\nstring back(int steps)\u00a0Move steps back in history. If you can only return x steps in the history and steps > x, you will\u00a0return only x steps. Return the current url\u00a0after moving back in history at most steps.\nstring forward(int steps)\u00a0Move steps forward in history. If you can only forward x steps in the history and steps > x, you will\u00a0forward only\u00a0x steps. Return the current url\u00a0after forwarding in history at most steps.\n\n\u00a0\nExample:\n\nInput:\n[\"BrowserHistory\",\"visit\",\"visit\",\"visit\",\"back\",\"back\",\"forward\",\"visit\",\"forward\",\"back\",\"back\"]\n[[\"leetcode.com\"],[\"google.com\"],[\"facebook.com\"],[\"youtube.com\"],[1],[1],[1],[\"linkedin.com\"],[2],[2],[7]]\nOutput:\n[null,null,null,null,\"facebook.com\",\"google.com\",\"facebook.com\",null,\"linkedin.com\",\"google.com\",\"leetcode.com\"]\n\nExplanation:\nBrowserHistory browserHistory = new BrowserHistory(\"leetcode.com\");\nbrowserHistory.visit(\"google.com\"); // You are in \"leetcode.com\". Visit \"google.com\"\nbrowserHistory.visit(\"facebook.com\"); // You are in \"google.com\". Visit \"facebook.com\"\nbrowserHistory.visit(\"youtube.com\"); // You are in \"facebook.com\". Visit \"youtube.com\"\nbrowserHistory.back(1); // You are in \"youtube.com\", move back to \"facebook.com\" return \"facebook.com\"\nbrowserHistory.back(1); // You are in \"facebook.com\", move back to \"google.com\" return \"google.com\"\nbrowserHistory.forward(1); // You are in \"google.com\", move forward to \"facebook.com\" return \"facebook.com\"\nbrowserHistory.visit(\"linkedin.com\"); // You are in \"facebook.com\". Visit \"linkedin.com\"\nbrowserHistory.forward(2); // You are in \"linkedin.com\", you cannot move forward any steps.\nbrowserHistory.back(2); // You are in \"linkedin.com\", move back two steps to \"facebook.com\" then to \"google.com\". return \"google.com\"\nbrowserHistory.back(7); // You are in \"google.com\", you can move back only one step to \"leetcode.com\". return \"leetcode.com\"\n\n\u00a0\nConstraints:\n\n1 <= homepage.length <= 20\n1 <= url.length <= 20\n1 <= steps <= 100\nhomepage and url consist of\u00a0 '.' or lower case English letters.\nAt most 5000\u00a0calls will be made to visit, back, and forward.", + "examples": [], + "constraints": "Constraints:\n\n1 <= homepage.length <= 20\n1 <= url.length <= 20\n1 <= steps <= 100\nhomepage and url consist of\u00a0 '.' or lower case English letters.\nAt most 5000\u00a0calls will be made to visit, back, and forward.", + "tags": [ + "Array", + "Linked List", + "Stack", + "Design", + "Doubly-Linked List", + "Data Stream" + ], + "title-slug": "design-browser-history" + }, + { + "leetcode-id": 1473, + "title": "Paint House III", + "difficulty": 3, + "description": "There is a row of m houses in a small city, each house must be painted with one of the n colors (labeled from 1 to n), some houses that have been painted last summer should not be painted again.\nA neighborhood is a maximal group of continuous houses that are painted with the same color.\n\nFor example: houses = [1,2,2,3,3,2,1,1] contains 5 neighborhoods [{1}, {2,2}, {3,3}, {2}, {1,1}].\n\nGiven an array houses, an m x n matrix cost and an integer target where:\n\nhouses[i]: is the color of the house i, and 0 if the house is not painted yet.\ncost[i][j]: is the cost of paint the house i with the color j + 1.\n\nReturn the minimum cost of painting all the remaining houses in such a way that there are exactly target neighborhoods. If it is not possible, return -1.", + "examples": [ + "Example 1:\nInput: houses = [0,0,0,0,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3\nOutput: 9\nExplanation: Paint houses of this way [1,2,2,1,1]\nThis array contains target = 3 neighborhoods, [{1}, {2,2}, {1,1}].\nCost of paint all houses (1 + 1 + 1 + 1 + 5) = 9.", + "Example 2:\nInput: houses = [0,2,1,2,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3\nOutput: 11\nExplanation: Some houses are already painted, Paint the houses of this way [2,2,1,2,2]\nThis array contains target = 3 neighborhoods, [{2,2}, {1}, {2,2}]. \nCost of paint the first and last house (10 + 1) = 11.", + "Example 3:\nInput: houses = [3,1,2,3], cost = [[1,1,1],[1,1,1],[1,1,1],[1,1,1]], m = 4, n = 3, target = 3\nOutput: -1\nExplanation: Houses are already painted with a total of 4 neighborhoods [{3},{1},{2},{3}] different of target = 3." + ], + "constraints": "Constraints:\n\nm == houses.length == cost.length\nn == cost[i].length\n1 <= m <= 100\n1 <= n <= 20\n1 <= target <= m\n0 <= houses[i] <= n\n1 <= cost[i][j] <= 10^4", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "paint-house-iii" + }, + { + "leetcode-id": 1475, + "title": "Final Prices With a Special Discount in a Shop", + "difficulty": 1, + "description": "You are given an integer array prices where prices[i] is the price of the i^th item in a shop.\nThere is a special discount for items in the shop. If you buy the i^th item, then you will receive a discount equivalent to prices[j] where j is the minimum index such that j > i and prices[j] <= prices[i]. Otherwise, you will not receive any discount at all.\nReturn an integer array answer where answer[i] is the final price you will pay for the i^th item of the shop, considering the special discount.", + "examples": [ + "Example 1:\nInput: prices = [8,4,6,2,3]\nOutput: [4,2,4,2,3]\nExplanation: \nFor item 0 with price[0]=8 you will receive a discount equivalent to prices[1]=4, therefore, the final price you will pay is 8 - 4 = 4.\nFor item 1 with price[1]=4 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 4 - 2 = 2.\nFor item 2 with price[2]=6 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 6 - 2 = 4.\nFor items 3 and 4 you will not receive any discount at all.", + "Example 2:\nInput: prices = [1,2,3,4,5]\nOutput: [1,2,3,4,5]\nExplanation: In this case, for all items, you will not receive any discount at all.", + "Example 3:\nInput: prices = [10,1,1,6]\nOutput: [9,0,1,6]" + ], + "constraints": "Constraints:\n\n1 <= prices.length <= 500\n1 <= prices[i] <= 1000", + "tags": [ + "Array", + "Stack", + "Monotonic Stack" + ], + "title-slug": "final-prices-with-a-special-discount-in-a-shop" + }, + { + "leetcode-id": 1476, + "title": "Subrectangle Queries", + "difficulty": 2, + "description": "Implement the class SubrectangleQueries\u00a0which receives a rows x cols rectangle as a matrix of integers in the constructor and supports two methods:\n1.\u00a0updateSubrectangle(int row1, int col1, int row2, int col2, int newValue)\n\nUpdates all values with newValue in the subrectangle whose upper left coordinate is (row1,col1) and bottom right coordinate is (row2,col2).\n\n2.\u00a0getValue(int row, int col)\n\nReturns the current value of the coordinate (row,col) from\u00a0the rectangle.", + "examples": [ + "Example 1:\nInput\n[\"SubrectangleQueries\",\"getValue\",\"updateSubrectangle\",\"getValue\",\"getValue\",\"updateSubrectangle\",\"getValue\",\"getValue\"]\n[[[[1,2,1],[4,3,4],[3,2,1],[1,1,1]]],[0,2],[0,0,3,2,5],[0,2],[3,1],[3,0,3,2,10],[3,1],[0,2]]\nOutput\n[null,1,null,5,5,null,10,5]\nExplanation\nSubrectangleQueries subrectangleQueries = new SubrectangleQueries([[1,2,1],[4,3,4],[3,2,1],[1,1,1]]); \n// The initial rectangle (4x3) looks like:\n// 1 2 1\n// 4 3 4\n// 3 2 1\n// 1 1 1\nsubrectangleQueries.getValue(0, 2); // return 1\nsubrectangleQueries.updateSubrectangle(0, 0, 3, 2, 5);\n// After this update the rectangle looks like:\n// 5 5 5\n// 5 5 5\n// 5 5 5\n// 5 5 5 \nsubrectangleQueries.getValue(0, 2); // return 5\nsubrectangleQueries.getValue(3, 1); // return 5\nsubrectangleQueries.updateSubrectangle(3, 0, 3, 2, 10);\n// After this update the rectangle looks like:\n// 5 5 5\n// 5 5 5\n// 5 5 5\n// 10 10 10 \nsubrectangleQueries.getValue(3, 1); // return 10\nsubrectangleQueries.getValue(0, 2); // return 5", + "Example 2:\nInput\n[\"SubrectangleQueries\",\"getValue\",\"updateSubrectangle\",\"getValue\",\"getValue\",\"updateSubrectangle\",\"getValue\"]\n[[[[1,1,1],[2,2,2],[3,3,3]]],[0,0],[0,0,2,2,100],[0,0],[2,2],[1,1,2,2,20],[2,2]]\nOutput\n[null,1,null,100,100,null,20]\nExplanation\nSubrectangleQueries subrectangleQueries = new SubrectangleQueries([[1,1,1],[2,2,2],[3,3,3]]);\nsubrectangleQueries.getValue(0, 0); // return 1\nsubrectangleQueries.updateSubrectangle(0, 0, 2, 2, 100);\nsubrectangleQueries.getValue(0, 0); // return 100\nsubrectangleQueries.getValue(2, 2); // return 100\nsubrectangleQueries.updateSubrectangle(1, 1, 2, 2, 20);\nsubrectangleQueries.getValue(2, 2); // return 20" + ], + "constraints": "Constraints:\n\nThere will be at most 500\u00a0operations considering both methods:\u00a0updateSubrectangle and getValue.\n1 <= rows, cols <= 100\nrows ==\u00a0rectangle.length\ncols == rectangle[i].length\n0 <= row1 <= row2 < rows\n0 <= col1 <= col2 < cols\n1 <= newValue, rectangle[i][j] <= 10^9\n0 <= row < rows\n0 <= col < cols", + "tags": [ + "Array", + "Design", + "Matrix" + ], + "title-slug": "subrectangle-queries" + }, + { + "leetcode-id": 1477, + "title": "Find Two Non-overlapping Sub-arrays Each With Target Sum", + "difficulty": 2, + "description": "You are given an array of integers arr and an integer target.\nYou have to find two non-overlapping sub-arrays of arr each with a sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.\nReturn the minimum sum of the lengths of the two required sub-arrays, or return -1 if you cannot find such two sub-arrays.", + "examples": [ + "Example 1:\nInput: arr = [3,2,2,4,3], target = 3\nOutput: 2\nExplanation: Only two sub-arrays have sum = 3 ([3] and [3]). The sum of their lengths is 2.", + "Example 2:\nInput: arr = [7,3,4,7], target = 7\nOutput: 2\nExplanation: Although we have three non-overlapping sub-arrays of sum = 7 ([7], [3,4] and [7]), but we will choose the first and third sub-arrays as the sum of their lengths is 2.", + "Example 3:\nInput: arr = [4,3,2,6,2,3,4], target = 6\nOutput: -1\nExplanation: We have only one sub-array of sum = 6." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^5\n1 <= arr[i] <= 1000\n1 <= target <= 10^8", + "tags": [ + "Array", + "Hash Table", + "Binary Search", + "Dynamic Programming", + "Sliding Window" + ], + "title-slug": "find-two-non-overlapping-sub-arrays-each-with-target-sum" + }, + { + "leetcode-id": 1478, + "title": "Allocate Mailboxes", + "difficulty": 3, + "description": "Given the array houses where houses[i] is the location of the i^th house along a street and an integer k, allocate k mailboxes in the street.\nReturn the minimum total distance between each house and its nearest mailbox.\nThe test cases are generated so that the answer fits in a 32-bit integer.", + "examples": [ + "Example 1:\nInput: houses = [1,4,8,10,20], k = 3\nOutput: 5\nExplanation: Allocate mailboxes in position 3, 9 and 20.\nMinimum total distance from each houses to nearest mailboxes is |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5", + "Example 2:\nInput: houses = [2,3,5,12,18], k = 2\nOutput: 9\nExplanation: Allocate mailboxes in position 3 and 14.\nMinimum total distance from each houses to nearest mailboxes is |2-3| + |3-3| + |5-3| + |12-14| + |18-14| = 9." + ], + "constraints": "Constraints:\n\n1 <= k <= houses.length <= 100\n1 <= houses[i] <= 10^4\nAll the integers of houses are unique.", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Sorting" + ], + "title-slug": "allocate-mailboxes" + }, + { + "leetcode-id": 1480, + "title": "Running Sum of 1d Array", + "difficulty": 1, + "description": "Given an array nums. We define a running sum of an array as\u00a0runningSum[i] = sum(nums[0]\u2026nums[i]).\nReturn the running sum of nums.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4]\r\nOutput: [1,3,6,10]\r\nExplanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].", + "Example 2:\nInput: nums = [1,1,1,1,1]\r\nOutput: [1,2,3,4,5]\r\nExplanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].", + "Example 3:\nInput: nums = [3,1,2,10,1]\r\nOutput: [3,4,6,16,17]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n-10^6\u00a0<= nums[i] <=\u00a010^6", + "tags": [ + "Array", + "Prefix Sum" + ], + "title-slug": "running-sum-of-1d-array" + }, + { + "leetcode-id": 1481, + "title": "Least Number of Unique Integers after K Removals", + "difficulty": 2, + "description": "Given an array of integers\u00a0arr\u00a0and an integer k.\u00a0Find the least number of unique integers\u00a0after removing exactly k elements.", + "examples": [ + "Example 1:\nInput: arr = [5,5,4], k = 1\r\nOutput: 1\r\nExplanation: Remove the single 4, only 5 is left.", + "Example 2:\nInput: arr = [4,3,1,1,3,3,2], k = 3\r\nOutput: 2\r\nExplanation: Remove 4, 2 and either one of the two 1s or three 3s. 1 and 3 will be left." + ], + "constraints": "Constraints:\n\n1 <= arr.length\u00a0<= 10^5\n1 <= arr[i] <= 10^9\n0 <= k\u00a0<= arr.length", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Sorting", + "Counting" + ], + "title-slug": "least-number-of-unique-integers-after-k-removals" + }, + { + "leetcode-id": 1482, + "title": "Minimum Number of Days to Make m Bouquets", + "difficulty": 2, + "description": "You are given an integer array bloomDay, an integer m and an integer k.\nYou want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden.\nThe garden consists of n flowers, the i^th flower will bloom in the bloomDay[i] and then can be used in exactly one bouquet.\nReturn the minimum number of days you need to wait to be able to make m bouquets from the garden. If it is impossible to make m bouquets return -1.", + "examples": [ + "Example 1:\nInput: bloomDay = [1,10,3,10,2], m = 3, k = 1\nOutput: 3\nExplanation: Let us see what happened in the first three days. x means flower bloomed and _ means flower did not bloom in the garden.\nWe need 3 bouquets each should contain 1 flower.\nAfter day 1: [x, _, _, _, _] // we can only make one bouquet.\nAfter day 2: [x, _, _, _, x] // we can only make two bouquets.\nAfter day 3: [x, _, x, _, x] // we can make 3 bouquets. The answer is 3.", + "Example 2:\nInput: bloomDay = [1,10,3,10,2], m = 3, k = 2\nOutput: -1\nExplanation: We need 3 bouquets each has 2 flowers, that means we need 6 flowers. We only have 5 flowers so it is impossible to get the needed bouquets and we return -1.", + "Example 3:\nInput: bloomDay = [7,7,7,7,12,7,7], m = 2, k = 3\nOutput: 12\nExplanation: We need 2 bouquets each should have 3 flowers.\nHere is the garden after the 7 and 12 days:\nAfter day 7: [x, x, x, x, _, x, x]\nWe can make one bouquet of the first three flowers that bloomed. We cannot make another bouquet from the last three flowers that bloomed because they are not adjacent.\nAfter day 12: [x, x, x, x, x, x, x]\nIt is obvious that we can make two bouquets in different ways." + ], + "constraints": "Constraints:\n\nbloomDay.length == n\n1 <= n <= 10^5\n1 <= bloomDay[i] <= 10^9\n1 <= m <= 10^6\n1 <= k <= n", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "minimum-number-of-days-to-make-m-bouquets" + }, + { + "leetcode-id": 1483, + "title": "Kth Ancestor of a Tree Node", + "difficulty": 3, + "description": "You are given a tree with n nodes numbered from 0 to n - 1 in the form of a parent array parent where parent[i] is the parent of i^th node. The root of the tree is node 0. Find the k^th ancestor of a given node.\nThe k^th ancestor of a tree node is the k^th node in the path from that node to the root node.\nImplement the TreeAncestor class:\n\nTreeAncestor(int n, int[] parent) Initializes the object with the number of nodes in the tree and the parent array.\nint getKthAncestor(int node, int k) return the k^th ancestor of the given node node. If there is no such ancestor, return -1.", + "examples": [ + "Example 1:\nInput\n[\"TreeAncestor\", \"getKthAncestor\", \"getKthAncestor\", \"getKthAncestor\"]\n[[7, [-1, 0, 0, 1, 1, 2, 2]], [3, 1], [5, 2], [6, 3]]\nOutput\n[null, 1, 0, -1]\n\nExplanation\nTreeAncestor treeAncestor = new TreeAncestor(7, [-1, 0, 0, 1, 1, 2, 2]);\ntreeAncestor.getKthAncestor(3, 1); // returns 1 which is the parent of 3\ntreeAncestor.getKthAncestor(5, 2); // returns 0 which is the grandparent of 5\ntreeAncestor.getKthAncestor(6, 3); // returns -1 because there is no such ancestor" + ], + "constraints": "Constraints:\n\n1 <= k <= n <= 5 * 10^4\nparent.length == n\nparent[0] == -1\n0 <= parent[i] < n for all 0 < i < n\n0 <= node < n\nThere will be at most 5 * 10^4 queries.", + "tags": [ + "Binary Search", + "Dynamic Programming", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Design" + ], + "title-slug": "kth-ancestor-of-a-tree-node" + }, + { + "leetcode-id": 1486, + "title": "XOR Operation in an Array", + "difficulty": 1, + "description": "You are given an integer n and an integer start.\nDefine an array nums where nums[i] = start + 2 * i (0-indexed) and n == nums.length.\nReturn the bitwise XOR of all elements of nums.", + "examples": [ + "Example 1:\nInput: n = 5, start = 0\nOutput: 8\nExplanation: Array nums is equal to [0, 2, 4, 6, 8] where (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8.\nWhere \"^\" corresponds to bitwise XOR operator.", + "Example 2:\nInput: n = 4, start = 3\nOutput: 8\nExplanation: Array nums is equal to [3, 5, 7, 9] where (3 ^ 5 ^ 7 ^ 9) = 8." + ], + "constraints": "Constraints:\n\n1 <= n <= 1000\n0 <= start <= 1000\nn == nums.length", + "tags": [ + "Math", + "Bit Manipulation" + ], + "title-slug": "xor-operation-in-an-array" + }, + { + "leetcode-id": 1487, + "title": "Making File Names Unique", + "difficulty": 2, + "description": "Given an array of strings names of size n. You will create n folders in your file system such that, at the i^th minute, you will create a folder with the name names[i].\nSince two files cannot have the same name, if you enter a folder name that was previously used, the system will have a suffix addition to its name in the form of (k), where, k is the smallest positive integer such that the obtained name remains unique.\nReturn an array of strings of length n where ans[i] is the actual name the system will assign to the i^th folder when you create it.", + "examples": [ + "Example 1:\nInput: names = [\"pes\",\"fifa\",\"gta\",\"pes(2019)\"]\nOutput: [\"pes\",\"fifa\",\"gta\",\"pes(2019)\"]\nExplanation: Let's see how the file system creates folder names:\n\"pes\" --> not assigned before, remains \"pes\"\n\"fifa\" --> not assigned before, remains \"fifa\"\n\"gta\" --> not assigned before, remains \"gta\"\n\"pes(2019)\" --> not assigned before, remains \"pes(2019)\"", + "Example 2:\nInput: names = [\"gta\",\"gta(1)\",\"gta\",\"avalon\"]\nOutput: [\"gta\",\"gta(1)\",\"gta(2)\",\"avalon\"]\nExplanation: Let's see how the file system creates folder names:\n\"gta\" --> not assigned before, remains \"gta\"\n\"gta(1)\" --> not assigned before, remains \"gta(1)\"\n\"gta\" --> the name is reserved, system adds (k), since \"gta(1)\" is also reserved, systems put k = 2. it becomes \"gta(2)\"\n\"avalon\" --> not assigned before, remains \"avalon\"", + "Example 3:\nInput: names = [\"onepiece\",\"onepiece(1)\",\"onepiece(2)\",\"onepiece(3)\",\"onepiece\"]\nOutput: [\"onepiece\",\"onepiece(1)\",\"onepiece(2)\",\"onepiece(3)\",\"onepiece(4)\"]\nExplanation: When the last folder is created, the smallest positive valid k is 4, and it becomes \"onepiece(4)\"." + ], + "constraints": "Constraints:\n\n1 <= names.length <= 5 * 10^4\n1 <= names[i].length <= 20\nnames[i] consists of lowercase English letters, digits, and/or round brackets.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "making-file-names-unique" + }, + { + "leetcode-id": 1488, + "title": "Avoid Flood in The City", + "difficulty": 2, + "description": "Your country has an infinite number of lakes. Initially, all the lakes are empty, but when it rains over the nth lake, the nth lake becomes full of water. If it rains over a lake that is full of water, there will be a flood. Your goal is to avoid floods in any lake.\nGiven an integer array rains where:\n\nrains[i] > 0 means there will be rains over the rains[i] lake.\nrains[i] == 0 means there are no rains this day and you can choose one lake this day and dry it.\n\nReturn an array ans where:\n\nans.length == rains.length\nans[i] == -1 if rains[i] > 0.\nans[i] is the lake you choose to dry in the ith day if rains[i] == 0.\n\nIf there are multiple valid answers return any of them. If it is impossible to avoid flood return an empty array.\nNotice that if you chose to dry a full lake, it becomes empty, but if you chose to dry an empty lake, nothing changes.", + "examples": [ + "Example 1:\nInput: rains = [1,2,3,4]\nOutput: [-1,-1,-1,-1]\nExplanation: After the first day full lakes are [1]\nAfter the second day full lakes are [1,2]\nAfter the third day full lakes are [1,2,3]\nAfter the fourth day full lakes are [1,2,3,4]\nThere's no day to dry any lake and there is no flood in any lake.", + "Example 2:\nInput: rains = [1,2,0,0,2,1]\nOutput: [-1,-1,2,1,-1,-1]\nExplanation: After the first day full lakes are [1]\nAfter the second day full lakes are [1,2]\nAfter the third day, we dry lake 2. Full lakes are [1]\nAfter the fourth day, we dry lake 1. There is no full lakes.\nAfter the fifth day, full lakes are [2].\nAfter the sixth day, full lakes are [1,2].\nIt is easy that this scenario is flood-free. [-1,-1,1,2,-1,-1] is another acceptable scenario.", + "Example 3:\nInput: rains = [1,2,0,1,2]\nOutput: []\nExplanation: After the second day, full lakes are [1,2]. We have to dry one lake in the third day.\nAfter that, it will rain over lakes [1,2]. It's easy to prove that no matter which lake you choose to dry in the 3rd day, the other one will flood." + ], + "constraints": "Constraints:\n\n1 <= rains.length <= 10^5\n0 <= rains[i] <= 10^9", + "tags": [ + "Array", + "Hash Table", + "Binary Search", + "Greedy", + "Heap (Priority Queue)" + ], + "title-slug": "avoid-flood-in-the-city" + }, + { + "leetcode-id": 1489, + "title": "Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree", + "difficulty": 3, + "description": "Given a weighted undirected connected graph with n\u00a0vertices numbered from 0 to n - 1,\u00a0and an array edges\u00a0where edges[i] = [ai, bi, weighti] represents a bidirectional and weighted edge between nodes\u00a0ai\u00a0and bi. A minimum spanning tree (MST) is a subset of the graph's edges that connects all vertices without cycles\u00a0and with the minimum possible total edge weight.\nFind all the critical and pseudo-critical edges in the given graph's minimum spanning tree (MST). An MST edge whose deletion from the graph would cause the MST weight to increase is called a\u00a0critical edge. On\u00a0the other hand, a pseudo-critical edge is that which can appear in some MSTs but not all.\nNote that you can return the indices of the edges in any order.", + "examples": [ + "Example 1:\nInput: n = 5, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]\nOutput: [[0,1],[2,3,4,5]]\nExplanation: The figure above describes the graph.\nThe following figure shows all the possible MSTs:\n\nNotice that the two edges 0 and 1 appear in all MSTs, therefore they are critical edges, so we return them in the first list of the output.\nThe edges 2, 3, 4, and 5 are only part of some MSTs, therefore they are considered pseudo-critical edges. We add them to the second list of the output.", + "Example 2:\nInput: n = 4, edges = [[0,1,1],[1,2,1],[2,3,1],[0,3,1]]\nOutput: [[],[0,1,2,3]]\nExplanation: We can observe that since all 4 edges have equal weight, choosing any 3 edges from the given 4 will yield an MST. Therefore all 4 edges are pseudo-critical." + ], + "constraints": "Constraints:\n\n2 <= n <= 100\n1 <= edges.length <= min(200, n * (n - 1) / 2)\nedges[i].length == 3\n0 <= ai < bi < n\n1 <= weighti\u00a0<= 1000\nAll pairs (ai, bi) are distinct.", + "tags": [ + "Union Find", + "Graph", + "Sorting", + "Minimum Spanning Tree", + "Strongly Connected Component" + ], + "title-slug": "find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree" + }, + { + "leetcode-id": 1491, + "title": "Average Salary Excluding the Minimum and Maximum Salary", + "difficulty": 1, + "description": "You are given an array of unique integers salary where salary[i] is the salary of the i^th employee.\nReturn the average salary of employees excluding the minimum and maximum salary. Answers within 10^-5 of the actual answer will be accepted.", + "examples": [ + "Example 1:\nInput: salary = [4000,3000,1000,2000]\nOutput: 2500.00000\nExplanation: Minimum salary and maximum salary are 1000 and 4000 respectively.\nAverage salary excluding minimum and maximum salary is (2000+3000) / 2 = 2500", + "Example 2:\nInput: salary = [1000,2000,3000]\nOutput: 2000.00000\nExplanation: Minimum salary and maximum salary are 1000 and 3000 respectively.\nAverage salary excluding minimum and maximum salary is (2000) / 1 = 2000" + ], + "constraints": "Constraints:\n\n3 <= salary.length <= 100\n1000 <= salary[i] <= 10^6\nAll the integers of salary are unique.", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "average-salary-excluding-the-minimum-and-maximum-salary" + }, + { + "leetcode-id": 1492, + "title": "The kth Factor of n", + "difficulty": 2, + "description": "You are given two positive integers n and k. A factor of an integer n is defined as an integer i where n % i == 0.\nConsider a list of all factors of n sorted in ascending order, return the k^th factor in this list or return -1 if n has less than k factors.", + "examples": [ + "Example 1:\nInput: n = 12, k = 3\nOutput: 3\nExplanation: Factors list is [1, 2, 3, 4, 6, 12], the 3^rd factor is 3.", + "Example 2:\nInput: n = 7, k = 2\nOutput: 7\nExplanation: Factors list is [1, 7], the 2^nd factor is 7.", + "Example 3:\nInput: n = 4, k = 4\nOutput: -1\nExplanation: Factors list is [1, 2, 4], there is only 3 factors. We should return -1." + ], + "constraints": "Constraints:\n\n1 <= k <= n <= 1000\n\n\u00a0\nFollow up:\nCould you solve this problem in less than O(n) complexity?", + "tags": [ + "Math", + "Number Theory" + ], + "title-slug": "the-kth-factor-of-n" + }, + { + "leetcode-id": 1493, + "title": "Longest Subarray of 1's After Deleting One Element", + "difficulty": 2, + "description": "Given a binary array nums, you should delete one element from it.\nReturn the size of the longest non-empty subarray containing only 1's in the resulting array. Return 0 if there is no such subarray.", + "examples": [ + "Example 1:\nInput: nums = [1,1,0,1]\nOutput: 3\nExplanation: After deleting the number in position 2, [1,1,1] contains 3 numbers with value of 1's.", + "Example 2:\nInput: nums = [0,1,1,1,0,1,1,0,1]\nOutput: 5\nExplanation: After deleting the number in position 4, [0,1,1,1,1,1,0,1] longest subarray with value of 1's is [1,1,1,1,1].", + "Example 3:\nInput: nums = [1,1,1]\nOutput: 2\nExplanation: You must delete one element." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\nnums[i] is either 0 or 1.", + "tags": [ + "Array", + "Dynamic Programming", + "Sliding Window" + ], + "title-slug": "longest-subarray-of-1s-after-deleting-one-element" + }, + { + "leetcode-id": 1494, + "title": "Parallel Courses II", + "difficulty": 3, + "description": "You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCoursei, nextCoursei], representing a prerequisite relationship between course prevCoursei and course nextCoursei: course prevCoursei has to be taken before course nextCoursei. Also, you are given the integer k.\nIn one semester, you can take at most k courses as long as you have taken all the prerequisites in the previous semesters for the courses you are taking.\nReturn the minimum number of semesters needed to take all courses. The testcases will be generated such that it is possible to take every course.", + "examples": [ + "Example 1:\nInput: n = 4, relations = [[2,1],[3,1],[1,4]], k = 2\nOutput: 3\nExplanation: The figure above represents the given graph.\nIn the first semester, you can take courses 2 and 3.\nIn the second semester, you can take course 1.\nIn the third semester, you can take course 4.", + "Example 2:\nInput: n = 5, relations = [[2,1],[3,1],[4,1],[1,5]], k = 2\nOutput: 4\nExplanation: The figure above represents the given graph.\nIn the first semester, you can only take courses 2 and 3 since you cannot take more than two per semester.\nIn the second semester, you can take course 4.\nIn the third semester, you can take course 1.\nIn the fourth semester, you can take course 5." + ], + "constraints": "Constraints:\n\n1 <= n <= 15\n1 <= k <= n\n0 <= relations.length <= n * (n-1) / 2\nrelations[i].length == 2\n1 <= prevCoursei, nextCoursei <= n\nprevCoursei != nextCoursei\nAll the pairs [prevCoursei, nextCoursei] are unique.\nThe given graph is a directed acyclic graph.", + "tags": [ + "Dynamic Programming", + "Bit Manipulation", + "Graph", + "Bitmask" + ], + "title-slug": "parallel-courses-ii" + }, + { + "leetcode-id": 1496, + "title": "Path Crossing", + "difficulty": 1, + "description": "Given a string path, where path[i] = 'N', 'S', 'E' or 'W', each representing moving one unit north, south, east, or west, respectively. You start at the origin (0, 0) on a 2D plane and walk on the path specified by path.\nReturn true if the path crosses itself at any point, that is, if at any time you are on a location you have previously visited. Return false otherwise.", + "examples": [ + "Example 1:\nInput: path = \"NES\"\nOutput: false \nExplanation: Notice that the path doesn't cross any point more than once.", + "Example 2:\nInput: path = \"NESWW\"\nOutput: true\nExplanation: Notice that the path visits the origin twice." + ], + "constraints": "Constraints:\n\n1 <= path.length <= 10^4\npath[i] is either 'N', 'S', 'E', or 'W'.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "path-crossing" + }, + { + "leetcode-id": 1497, + "title": "Check If Array Pairs Are Divisible by k", + "difficulty": 2, + "description": "Given an array of integers arr of even length n and an integer k.\nWe want to divide the array into exactly n / 2 pairs such that the sum of each pair is divisible by k.\nReturn true If you can find a way to do that or false otherwise.", + "examples": [ + "Example 1:\nInput: arr = [1,2,3,4,5,10,6,7,8,9], k = 5\nOutput: true\nExplanation: Pairs are (1,9),(2,8),(3,7),(4,6) and (5,10).", + "Example 2:\nInput: arr = [1,2,3,4,5,6], k = 7\nOutput: true\nExplanation: Pairs are (1,6),(2,5) and(3,4).", + "Example 3:\nInput: arr = [1,2,3,4,5,6], k = 10\nOutput: false\nExplanation: You can try all possible pairs to see that there is no way to divide arr into 3 pairs each with sum divisible by 10." + ], + "constraints": "Constraints:\n\narr.length == n\n1 <= n <= 10^5\nn is even.\n-10^9 <= arr[i] <= 10^9\n1 <= k <= 10^5", + "tags": [ + "Array", + "Hash Table", + "Counting" + ], + "title-slug": "check-if-array-pairs-are-divisible-by-k" + }, + { + "leetcode-id": 1498, + "title": "Number of Subsequences That Satisfy the Given Sum Condition", + "difficulty": 2, + "description": "You are given an array of integers nums and an integer target.\nReturn the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target. Since the answer may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: nums = [3,5,6,7], target = 9\nOutput: 4\nExplanation: There are 4 subsequences that satisfy the condition.\n[3] -> Min value + max value <= target (3 + 3 <= 9)\n[3,5] -> (3 + 5 <= 9)\n[3,5,6] -> (3 + 6 <= 9)\n[3,6] -> (3 + 6 <= 9)", + "Example 2:\nInput: nums = [3,3,6,8], target = 10\nOutput: 6\nExplanation: There are 6 subsequences that satisfy the condition. (nums can have repeated numbers).\n[3] , [3] , [3,3], [3,6] , [3,6] , [3,3,6]", + "Example 3:\nInput: nums = [2,3,3,4,6,7], target = 12\nOutput: 61\nExplanation: There are 63 non-empty subsequences, two of them do not satisfy the condition ([6,7], [7]).\nNumber of valid subsequences (63 - 2 = 61)." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^6\n1 <= target <= 10^6", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Sorting" + ], + "title-slug": "number-of-subsequences-that-satisfy-the-given-sum-condition" + }, + { + "leetcode-id": 1499, + "title": "Max Value of Equation", + "difficulty": 3, + "description": "You are given an array points containing the coordinates of points on a 2D plane, sorted by the x-values, where points[i] = [xi, yi] such that xi < xj for all 1 <= i < j <= points.length. You are also given an integer k.\nReturn the maximum value of the equation yi + yj + |xi - xj| where |xi - xj| <= k and 1 <= i < j <= points.length.\nIt is guaranteed that there exists at least one pair of points that satisfy the constraint |xi - xj| <= k.", + "examples": [ + "Example 1:\nInput: points = [[1,3],[2,0],[5,10],[6,-10]], k = 1\nOutput: 4\nExplanation: The first two points satisfy the condition |xi - xj| <= 1 and if we calculate the equation we get 3 + 0 + |1 - 2| = 4. Third and fourth points also satisfy the condition and give a value of 10 + -10 + |5 - 6| = 1.\nNo other pairs satisfy the condition, so we return the max of 4 and 1.", + "Example 2:\nInput: points = [[0,0],[3,0],[9,2]], k = 3\nOutput: 3\nExplanation: Only the first two points have an absolute difference of 3 or less in the x-values, and give the value of 0 + 0 + |0 - 3| = 3." + ], + "constraints": "Constraints:\n\n2 <= points.length <= 10^5\npoints[i].length == 2\n-10^8 <= xi, yi <= 10^8\n0 <= k <= 2 * 10^8\nxi < xj for all 1 <= i < j <= points.length\nxi form a strictly increasing sequence.", + "tags": [ + "Array", + "Queue", + "Sliding Window", + "Heap (Priority Queue)", + "Monotonic Queue" + ], + "title-slug": "max-value-of-equation" + }, + { + "leetcode-id": 1502, + "title": "Can Make Arithmetic Progression From Sequence", + "difficulty": 1, + "description": "A sequence of numbers is called an arithmetic progression if the difference between any two consecutive elements is the same.\nGiven an array of numbers arr, return true if the array can be rearranged to form an arithmetic progression. Otherwise, return false.", + "examples": [ + "Example 1:\nInput: arr = [3,5,1]\nOutput: true\nExplanation: We can reorder the elements as [1,3,5] or [5,3,1] with differences 2 and -2 respectively, between each consecutive elements.", + "Example 2:\nInput: arr = [1,2,4]\nOutput: false\nExplanation: There is no way to reorder the elements to obtain an arithmetic progression." + ], + "constraints": "Constraints:\n\n2 <= arr.length <= 1000\n-10^6 <= arr[i] <= 10^6", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "can-make-arithmetic-progression-from-sequence" + }, + { + "leetcode-id": 1503, + "title": "Last Moment Before All Ants Fall Out of a Plank", + "difficulty": 2, + "description": "We have a wooden plank of the length n units. Some ants are walking on the plank, each ant moves with a speed of 1 unit per second. Some of the ants move to the left, the other move to the right.\nWhen two ants moving in two different directions meet at some point, they change their directions and continue moving again. Assume changing directions does not take any additional time.\nWhen an ant reaches one end of the plank at a time t, it falls out of the plank immediately.\nGiven an integer n and two integer arrays left and right, the positions of the ants moving to the left and the right, return the moment when the last ant(s) fall out of the plank.", + "examples": [ + "Example 1:\nInput: n = 4, left = [4,3], right = [0,1]\nOutput: 4\nExplanation: In the image above:\n-The ant at index 0 is named A and going to the right.\n-The ant at index 1 is named B and going to the right.\n-The ant at index 3 is named C and going to the left.\n-The ant at index 4 is named D and going to the left.\nThe last moment when an ant was on the plank is t = 4 seconds. After that, it falls immediately out of the plank. (i.e., We can say that at t = 4.0000000001, there are no ants on the plank).", + "Example 2:\nInput: n = 7, left = [], right = [0,1,2,3,4,5,6,7]\nOutput: 7\nExplanation: All ants are going to the right, the ant at index 0 needs 7 seconds to fall.", + "Example 3:\nInput: n = 7, left = [0,1,2,3,4,5,6,7], right = []\nOutput: 7\nExplanation: All ants are going to the left, the ant at index 7 needs 7 seconds to fall." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^4\n0 <= left.length <= n + 1\n0 <= left[i] <= n\n0 <= right.length <= n + 1\n0 <= right[i] <= n\n1 <= left.length + right.length <= n + 1\nAll values of left and right are unique, and each value can appear only in one of the two arrays.", + "tags": [ + "Array", + "Brainteaser", + "Simulation" + ], + "title-slug": "last-moment-before-all-ants-fall-out-of-a-plank" + }, + { + "leetcode-id": 1504, + "title": "Count Submatrices With All Ones", + "difficulty": 2, + "description": "Given an m x n binary matrix mat, return the number of submatrices that have all ones.", + "examples": [ + "Example 1:\nInput: mat = [[1,0,1],[1,1,0],[1,1,0]]\nOutput: 13\nExplanation: \nThere are 6 rectangles of side 1x1.\nThere are 2 rectangles of side 1x2.\nThere are 3 rectangles of side 2x1.\nThere is 1 rectangle of side 2x2. \nThere is 1 rectangle of side 3x1.\nTotal number of rectangles = 6 + 2 + 3 + 1 + 1 = 13.", + "Example 2:\nInput: mat = [[0,1,1,0],[0,1,1,1],[1,1,1,0]]\nOutput: 24\nExplanation: \nThere are 8 rectangles of side 1x1.\nThere are 5 rectangles of side 1x2.\nThere are 2 rectangles of side 1x3. \nThere are 4 rectangles of side 2x1.\nThere are 2 rectangles of side 2x2. \nThere are 2 rectangles of side 3x1. \nThere is 1 rectangle of side 3x2. \nTotal number of rectangles = 8 + 5 + 2 + 4 + 2 + 2 + 1 = 24." + ], + "constraints": "Constraints:\n\n1 <= m, n <= 150\nmat[i][j] is either 0 or 1.", + "tags": [ + "Array", + "Dynamic Programming", + "Stack", + "Matrix", + "Monotonic Stack" + ], + "title-slug": "count-submatrices-with-all-ones" + }, + { + "leetcode-id": 1505, + "title": "Minimum Possible Integer After at Most K Adjacent Swaps On Digits", + "difficulty": 3, + "description": "You are given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times.\nReturn the minimum integer you can obtain also as a string.", + "examples": [ + "Example 1:\nInput: num = \"4321\", k = 4\nOutput: \"1342\"\nExplanation: The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown.", + "Example 2:\nInput: num = \"100\", k = 1\nOutput: \"010\"\nExplanation: It's ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros.", + "Example 3:\nInput: num = \"36789\", k = 1000\nOutput: \"36789\"\nExplanation: We can keep the number without any swaps." + ], + "constraints": "Constraints:\n\n1 <= num.length <= 3 * 10^4\nnum consists of only digits and does not contain leading zeros.\n1 <= k <= 10^9", + "tags": [ + "String", + "Greedy", + "Binary Indexed Tree", + "Segment Tree" + ], + "title-slug": "minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits" + }, + { + "leetcode-id": 1507, + "title": "Reformat Date", + "difficulty": 1, + "description": "Given a date string in the form\u00a0Day Month Year, where:\n\nDay\u00a0is in the set {\"1st\", \"2nd\", \"3rd\", \"4th\", ..., \"30th\", \"31st\"}.\nMonth\u00a0is in the set {\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"}.\nYear\u00a0is in the range [1900, 2100].\n\nConvert the date string to the format YYYY-MM-DD, where:\n\nYYYY denotes the 4 digit year.\nMM denotes the 2 digit month.\nDD denotes the 2 digit day.", + "examples": [ + "Example 1:\nInput: date = \"20th Oct 2052\"\nOutput: \"2052-10-20\"", + "Example 2:\nInput: date = \"6th Jun 1933\"\nOutput: \"1933-06-06\"", + "Example 3:\nInput: date = \"26th May 1960\"\nOutput: \"1960-05-26\"" + ], + "constraints": "Constraints:\n\nThe given dates are guaranteed to be valid, so no error handling is necessary.", + "tags": [ + "String" + ], + "title-slug": "reformat-date" + }, + { + "leetcode-id": 1508, + "title": "Range Sum of Sorted Subarray Sums", + "difficulty": 2, + "description": "You are given the array nums consisting of n positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers.\nReturn the sum of the numbers from index left to index right (indexed from 1), inclusive, in the new array. Since the answer can be a huge number return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4], n = 4, left = 1, right = 5\nOutput: 13 \nExplanation: All subarray sums are 1, 3, 6, 10, 2, 5, 9, 3, 7, 4. After sorting them in non-decreasing order we have the new array [1, 2, 3, 3, 4, 5, 6, 7, 9, 10]. The sum of the numbers from index le = 1 to ri = 5 is 1 + 2 + 3 + 3 + 4 = 13.", + "Example 2:\nInput: nums = [1,2,3,4], n = 4, left = 3, right = 4\nOutput: 6\nExplanation: The given array is the same as example 1. We have the new array [1, 2, 3, 3, 4, 5, 6, 7, 9, 10]. The sum of the numbers from index le = 3 to ri = 4 is 3 + 3 = 6.", + "Example 3:\nInput: nums = [1,2,3,4], n = 4, left = 1, right = 10\nOutput: 50" + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= nums.length <= 1000\n1 <= nums[i] <= 100\n1 <= left <= right <= n * (n + 1) / 2", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Sorting" + ], + "title-slug": "range-sum-of-sorted-subarray-sums" + }, + { + "leetcode-id": 1509, + "title": "Minimum Difference Between Largest and Smallest Value in Three Moves", + "difficulty": 2, + "description": "You are given an integer array nums.\nIn one move, you can choose one element of nums and change it to any value.\nReturn the minimum difference between the largest and smallest value of nums after performing at most three moves.", + "examples": [ + "Example 1:\nInput: nums = [5,3,2,4]\nOutput: 0\nExplanation: We can make at most 3 moves.\nIn the first move, change 2 to 3. nums becomes [5,3,3,4].\nIn the second move, change 4 to 3. nums becomes [5,3,3,3].\nIn the third move, change 5 to 3. nums becomes [3,3,3,3].\nAfter performing 3 moves, the difference between the minimum and maximum is 3 - 3 = 0.", + "Example 2:\nInput: nums = [1,5,0,10,14]\nOutput: 1\nExplanation: We can make at most 3 moves.\nIn the first move, change 5 to 0. nums becomes [1,0,0,10,14].\nIn the second move, change 10 to 0. nums becomes [1,0,0,0,14].\nIn the third move, change 14 to 1. nums becomes [1,0,0,0,1].\nAfter performing 3 moves, the difference between the minimum and maximum is 1 - 0 = 1.\nIt can be shown that there is no way to make the difference 0 in 3 moves.", + "Example 3:\nInput: nums = [3,100,20]\nOutput: 0\nExplanation: We can make at most 3 moves.\nIn the first move, change 100 to 7. nums becomes [3,7,20].\nIn the second move, change 20 to 7. nums becomes [3,7,7].\nIn the third move, change 3 to 7. nums becomes [7,7,7].\nAfter performing 3 moves, the difference between the minimum and maximum is 7 - 7 = 0." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^9 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Greedy", + "Sorting" + ], + "title-slug": "minimum-difference-between-largest-and-smallest-value-in-three-moves" + }, + { + "leetcode-id": 1510, + "title": "Stone Game IV", + "difficulty": 3, + "description": "Alice and Bob take turns playing a game, with Alice starting first.\nInitially, there are n stones in a pile. On each player's turn, that player makes a move consisting of removing any non-zero square number of stones in the pile.\nAlso, if a player cannot make a move, he/she loses the game.\nGiven a positive integer n, return true if and only if Alice wins the game otherwise return false, assuming both players play optimally.", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: true\nExplanation: Alice can remove 1 stone winning the game because Bob doesn't have any moves.", + "Example 2:\nInput: n = 2\nOutput: false\nExplanation: Alice can only remove 1 stone, after that Bob removes the last one winning the game (2 -> 1 -> 0).", + "Example 3:\nInput: n = 4\nOutput: true\nExplanation: n is already a perfect square, Alice can win with one move, removing 4 stones (4 -> 0)." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5", + "tags": [ + "Math", + "Dynamic Programming", + "Game Theory" + ], + "title-slug": "stone-game-iv" + }, + { + "leetcode-id": 1512, + "title": "Number of Good Pairs", + "difficulty": 1, + "description": "Given an array of integers nums, return the number of good pairs.\nA pair (i, j) is called good if nums[i] == nums[j] and i < j.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,1,1,3]\nOutput: 4\nExplanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.", + "Example 2:\nInput: nums = [1,1,1,1]\nOutput: 6\nExplanation: Each pair in the array are good.", + "Example 3:\nInput: nums = [1,2,3]\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100", + "tags": [ + "Array", + "Hash Table", + "Math", + "Counting" + ], + "title-slug": "number-of-good-pairs" + }, + { + "leetcode-id": 1513, + "title": "Number of Substrings With Only 1s", + "difficulty": 2, + "description": "Given a binary string s, return the number of substrings with all characters 1's. Since the answer may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: s = \"0110111\"\nOutput: 9\nExplanation: There are 9 substring in total with only 1's characters.\n\"1\" -> 5 times.\n\"11\" -> 3 times.\n\"111\" -> 1 time.", + "Example 2:\nInput: s = \"101\"\nOutput: 2\nExplanation: Substring \"1\" is shown 2 times in s.", + "Example 3:\nInput: s = \"111111\"\nOutput: 21\nExplanation: Each substring contains only 1's characters." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns[i] is either '0' or '1'.", + "tags": [ + "Math", + "String" + ], + "title-slug": "number-of-substrings-with-only-1s" + }, + { + "leetcode-id": 1514, + "title": "Path with Maximum Probability", + "difficulty": 2, + "description": "You are given an undirected weighted graph of\u00a0n\u00a0nodes (0-indexed), represented by an edge list where\u00a0edges[i] = [a, b]\u00a0is an undirected edge connecting the nodes\u00a0a\u00a0and\u00a0b\u00a0with a probability of success of traversing that edge\u00a0succProb[i].\nGiven two nodes\u00a0start\u00a0and\u00a0end, find the path with the maximum probability of success to go from\u00a0start\u00a0to\u00a0end\u00a0and return its success probability.\nIf there is no path from\u00a0start\u00a0to\u00a0end, return\u00a00. Your answer will be accepted if it differs from the correct answer by at most 1e-5.", + "examples": [ + "Example 1:\nInput: n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start = 0, end = 2\nOutput: 0.25000\nExplanation:\u00a0There are two paths from start to end, one having a probability of success = 0.2 and the other has 0.5 * 0.5 = 0.25.", + "Example 2:\nInput: n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.3], start = 0, end = 2\nOutput: 0.30000", + "Example 3:\nInput: n = 3, edges = [[0,1]], succProb = [0.5], start = 0, end = 2\nOutput: 0.00000\nExplanation:\u00a0There is no path between 0 and 2." + ], + "constraints": "Constraints:\n\n2 <= n <= 10^4\n0 <= start, end < n\nstart != end\n0 <= a, b < n\na != b\n0 <= succProb.length == edges.length <= 2*10^4\n0 <= succProb[i] <= 1\nThere is at most one edge between every two nodes.", + "tags": [ + "Array", + "Graph", + "Heap (Priority Queue)", + "Shortest Path" + ], + "title-slug": "path-with-maximum-probability" + }, + { + "leetcode-id": 1515, + "title": "Best Position for a Service Centre", + "difficulty": 3, + "description": "A delivery company wants to build a new service center in a new city. The company knows the positions of all the customers in this city on a 2D-Map and wants to build the new center in a position such that the sum of the euclidean distances to all customers is minimum.\nGiven an array positions where positions[i] = [xi, yi] is the position of the ith customer on the map, return the minimum sum of the euclidean distances to all customers.\nIn other words, you need to choose the position of the service center [xcentre, ycentre] such that the following formula is minimized:\n\nAnswers within 10^-5 of the actual value will be accepted.", + "examples": [ + "Example 1:\nInput: positions = [[0,1],[1,0],[1,2],[2,1]]\nOutput: 4.00000\nExplanation: As shown, you can see that choosing [xcentre, ycentre] = [1, 1] will make the distance to each customer = 1, the sum of all distances is 4 which is the minimum possible we can achieve.", + "Example 2:\nInput: positions = [[1,1],[3,3]]\nOutput: 2.82843\nExplanation: The minimum possible sum of distances = sqrt(2) + sqrt(2) = 2.82843" + ], + "constraints": "Constraints:\n\n1 <= positions.length <= 50\npositions[i].length == 2\n0 <= xi, yi <= 100", + "tags": [ + "Math", + "Geometry", + "Randomized" + ], + "title-slug": "best-position-for-a-service-centre" + }, + { + "leetcode-id": 1518, + "title": "Water Bottles", + "difficulty": 1, + "description": "There are numBottles water bottles that are initially full of water. You can exchange numExchange empty water bottles from the market with one full water bottle.\nThe operation of drinking a full water bottle turns it into an empty bottle.\nGiven the two integers numBottles and numExchange, return the maximum number of water bottles you can drink.", + "examples": [ + "Example 1:\nInput: numBottles = 9, numExchange = 3\nOutput: 13\nExplanation: You can exchange 3 empty bottles to get 1 full water bottle.\nNumber of water bottles you can drink: 9 + 3 + 1 = 13.", + "Example 2:\nInput: numBottles = 15, numExchange = 4\nOutput: 19\nExplanation: You can exchange 4 empty bottles to get 1 full water bottle. \nNumber of water bottles you can drink: 15 + 3 + 1 = 19." + ], + "constraints": "Constraints:\n\n1 <= numBottles <= 100\n2 <= numExchange <= 100", + "tags": [ + "Math", + "Simulation" + ], + "title-slug": "water-bottles" + }, + { + "leetcode-id": 1519, + "title": "Number of Nodes in the Sub-Tree With the Same Label", + "difficulty": 2, + "description": "You are given a tree (i.e. a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. The root of the tree is the node 0, and each node of the tree has a label which is a lower-case character given in the string labels (i.e. The node with the number i has the label labels[i]).\nThe edges array is given on the form edges[i] = [ai, bi], which means there is an edge between nodes ai and bi in the tree.\nReturn an array of size n where ans[i] is the number of nodes in the subtree of the i^th node which have the same label as node i.\nA subtree of a tree T is the tree consisting of a node in T and all of its descendant nodes.", + "examples": [ + "Example 1:\nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], labels = \"abaedcd\"\nOutput: [2,1,1,1,1,1,1]\nExplanation: Node 0 has label 'a' and its sub-tree has node 2 with label 'a' as well, thus the answer is 2. Notice that any node is part of its sub-tree.\nNode 1 has a label 'b'. The sub-tree of node 1 contains nodes 1,4 and 5, as nodes 4 and 5 have different labels than node 1, the answer is just 1 (the node itself).", + "Example 2:\nInput: n = 4, edges = [[0,1],[1,2],[0,3]], labels = \"bbbb\"\nOutput: [4,2,1,1]\nExplanation: The sub-tree of node 2 contains only node 2, so the answer is 1.\nThe sub-tree of node 3 contains only node 3, so the answer is 1.\nThe sub-tree of node 1 contains nodes 1 and 2, both have label 'b', thus the answer is 2.\nThe sub-tree of node 0 contains nodes 0, 1, 2 and 3, all with label 'b', thus the answer is 4.", + "Example 3:\nInput: n = 5, edges = [[0,1],[0,2],[1,3],[0,4]], labels = \"aabab\"\nOutput: [3,2,1,1,1]" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5\nedges.length == n - 1\nedges[i].length == 2\n0 <= ai, bi < n\nai != bi\nlabels.length == n\nlabels is consisting of only of lowercase English letters.", + "tags": [ + "Hash Table", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Counting" + ], + "title-slug": "number-of-nodes-in-the-sub-tree-with-the-same-label" + }, + { + "leetcode-id": 1520, + "title": "Maximum Number of Non-Overlapping Substrings", + "difficulty": 3, + "description": "Given a string s of lowercase letters, you need to find the maximum number of non-empty substrings of s that meet the following conditions:\n\nThe substrings do not overlap, that is for any two substrings s[i..j] and s[x..y], either j < x or i > y is true.\nA substring that contains a certain character c must also contain all occurrences of c.\n\nFind the maximum number of substrings that meet the above conditions. If there are multiple solutions with the same number of substrings, return the one with minimum total length. It can be shown that there exists a unique solution of minimum total length.\nNotice that you can return the substrings in any order.", + "examples": [ + "Example 1:\nInput: s = \"adefaddaccc\"\nOutput: [\"e\",\"f\",\"ccc\"]\nExplanation:\u00a0The following are all the possible substrings that meet the conditions:\n[\n\u00a0 \"adefaddaccc\"\n\u00a0 \"adefadda\",\n\u00a0 \"ef\",\n\u00a0 \"e\",\n \"f\",\n\u00a0 \"ccc\",\n]\nIf we choose the first string, we cannot choose anything else and we'd get only 1. If we choose \"adefadda\", we are left with \"ccc\" which is the only one that doesn't overlap, thus obtaining 2 substrings. Notice also, that it's not optimal to choose \"ef\" since it can be split into two. Therefore, the optimal way is to choose [\"e\",\"f\",\"ccc\"] which gives us 3 substrings. No other solution of the same number of substrings exist.", + "Example 2:\nInput: s = \"abbaccd\"\nOutput: [\"d\",\"bb\",\"cc\"]\nExplanation: Notice that while the set of substrings [\"d\",\"abba\",\"cc\"] also has length 3, it's considered incorrect since it has larger total length." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns contains only lowercase English letters.", + "tags": [ + "String", + "Greedy" + ], + "title-slug": "maximum-number-of-non-overlapping-substrings" + }, + { + "leetcode-id": 1521, + "title": "Find a Value of a Mysterious Function Closest to Target", + "difficulty": 3, + "description": "Winston was given the above mysterious function func. He has an integer array arr and an integer target and he wants to find the values l and r that make the value |func(arr, l, r) - target| minimum possible.\nReturn the minimum possible value of |func(arr, l, r) - target|.\nNotice that func should be called with the values l and r where 0 <= l, r < arr.length.", + "examples": [ + "Example 1:\nInput: arr = [9,12,3,7,15], target = 5\nOutput: 2\nExplanation: Calling func with all the pairs of [l,r] = [[0,0],[1,1],[2,2],[3,3],[4,4],[0,1],[1,2],[2,3],[3,4],[0,2],[1,3],[2,4],[0,3],[1,4],[0,4]], Winston got the following results [9,12,3,7,15,8,0,3,7,0,0,3,0,0,0]. The value closest to 5 is 7 and 3, thus the minimum difference is 2.", + "Example 2:\nInput: arr = [1000000,1000000,1000000], target = 1\nOutput: 999999\nExplanation: Winston called the func with all possible values of [l,r] and he always got 1000000, thus the min difference is 999999.", + "Example 3:\nInput: arr = [1,2,4,8,16], target = 0\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^5\n1 <= arr[i] <= 10^6\n0 <= target <= 10^7", + "tags": [ + "Array", + "Binary Search", + "Bit Manipulation", + "Segment Tree" + ], + "title-slug": "find-a-value-of-a-mysterious-function-closest-to-target" + }, + { + "leetcode-id": 1523, + "title": "Count Odd Numbers in an Interval Range", + "difficulty": 1, + "description": "Given two non-negative integers low and high. Return the count of odd numbers between low and high\u00a0(inclusive).", + "examples": [ + "Example 1:\nInput: low = 3, high = 7\r\nOutput: 3\r\nExplanation: The odd numbers between 3 and 7 are [3,5,7].", + "Example 2:\nInput: low = 8, high = 10\r\nOutput: 1\r\nExplanation: The odd numbers between 8 and 10 are [9]." + ], + "constraints": "Constraints:\n\n0 <= low <= high\u00a0<= 10^9", + "tags": [ + "Math" + ], + "title-slug": "count-odd-numbers-in-an-interval-range" + }, + { + "leetcode-id": 1524, + "title": "Number of Sub-arrays With Odd Sum", + "difficulty": 2, + "description": "Given an array of integers arr, return the number of subarrays with an odd sum.\nSince the answer can be very large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: arr = [1,3,5]\nOutput: 4\nExplanation: All subarrays are [[1],[1,3],[1,3,5],[3],[3,5],[5]]\nAll sub-arrays sum are [1,4,9,3,8,5].\nOdd sums are [1,9,3,5] so the answer is 4.", + "Example 2:\nInput: arr = [2,4,6]\nOutput: 0\nExplanation: All subarrays are [[2],[2,4],[2,4,6],[4],[4,6],[6]]\nAll sub-arrays sum are [2,6,12,4,10,6].\nAll sub-arrays have even sum and the answer is 0.", + "Example 3:\nInput: arr = [1,2,3,4,5,6,7]\nOutput: 16" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^5\n1 <= arr[i] <= 100", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Prefix Sum" + ], + "title-slug": "number-of-sub-arrays-with-odd-sum" + }, + { + "leetcode-id": 1525, + "title": "Number of Good Ways to Split a String", + "difficulty": 2, + "description": "You are given a string s.\nA split is called good if you can split s into two non-empty strings sleft and sright where their concatenation is equal to s (i.e., sleft + sright = s) and the number of distinct letters in sleft and sright is the same.\nReturn the number of good splits you can make in s.", + "examples": [ + "Example 1:\nInput: s = \"aacaba\"\nOutput: 2\nExplanation: There are 5 ways to split \"aacaba\" and 2 of them are good. \n(\"a\", \"acaba\") Left string and right string contains 1 and 3 different letters respectively.\n(\"aa\", \"caba\") Left string and right string contains 1 and 3 different letters respectively.\n(\"aac\", \"aba\") Left string and right string contains 2 and 2 different letters respectively (good split).\n(\"aaca\", \"ba\") Left string and right string contains 2 and 2 different letters respectively (good split).\n(\"aacab\", \"a\") Left string and right string contains 3 and 1 different letters respectively.", + "Example 2:\nInput: s = \"abcd\"\nOutput: 1\nExplanation: Split the string as follows (\"ab\", \"cd\")." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of only lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming", + "Bit Manipulation" + ], + "title-slug": "number-of-good-ways-to-split-a-string" + }, + { + "leetcode-id": 1526, + "title": "Minimum Number of Increments on Subarrays to Form a Target Array", + "difficulty": 3, + "description": "You are given an integer array target. You have an integer array initial of the same size as target with all elements initially zeros.\nIn one operation you can choose any subarray from initial and increment each value by one.\nReturn the minimum number of operations to form a target array from initial.\nThe test cases are generated so that the answer fits in a 32-bit integer.", + "examples": [ + "Example 1:\nInput: target = [1,2,3,2,1]\nOutput: 3\nExplanation: We need at least 3 operations to form the target array from the initial array.\n[0,0,0,0,0] increment 1 from index 0 to 4 (inclusive).\n[1,1,1,1,1] increment 1 from index 1 to 3 (inclusive).\n[1,2,2,2,1] increment 1 at index 2.\n[1,2,3,2,1] target array is formed.", + "Example 2:\nInput: target = [3,1,1,2]\nOutput: 4\nExplanation: [0,0,0,0] -> [1,1,1,1] -> [1,1,1,2] -> [2,1,1,2] -> [3,1,1,2]", + "Example 3:\nInput: target = [3,1,5,4,2]\nOutput: 7\nExplanation: [0,0,0,0,0] -> [1,1,1,1,1] -> [2,1,1,1,1] -> [3,1,1,1,1] -> [3,1,2,2,2] -> [3,1,3,3,2] -> [3,1,4,4,2] -> [3,1,5,4,2]." + ], + "constraints": "Constraints:\n\n1 <= target.length <= 10^5\n1 <= target[i] <= 10^5", + "tags": [ + "Array", + "Dynamic Programming", + "Stack", + "Greedy", + "Monotonic Stack" + ], + "title-slug": "minimum-number-of-increments-on-subarrays-to-form-a-target-array" + }, + { + "leetcode-id": 1528, + "title": "Shuffle String", + "difficulty": 1, + "description": "You are given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the i^th position moves to indices[i] in the shuffled string.\nReturn the shuffled string.", + "examples": [ + "Example 1:\nInput: s = \"codeleet\", indices = [4,5,6,7,0,2,1,3]\nOutput: \"leetcode\"\nExplanation: As shown, \"codeleet\" becomes \"leetcode\" after shuffling.", + "Example 2:\nInput: s = \"abc\", indices = [0,1,2]\nOutput: \"abc\"\nExplanation: After shuffling, each character remains in its position." + ], + "constraints": "Constraints:\n\ns.length == indices.length == n\n1 <= n <= 100\ns consists of only lowercase English letters.\n0 <= indices[i] < n\nAll values of indices are unique.", + "tags": [ + "Array", + "String" + ], + "title-slug": "shuffle-string" + }, + { + "leetcode-id": 1529, + "title": "Minimum Suffix Flips", + "difficulty": 2, + "description": "You are given a 0-indexed binary string target of length n. You have another binary string s of length n that is initially set to all zeros. You want to make s equal to target.\nIn one operation, you can pick an index i where 0 <= i < n and flip all bits in the inclusive range [i, n - 1]. Flip means changing '0' to '1' and '1' to '0'.\nReturn the minimum number of operations needed to make s equal to target.", + "examples": [ + "Example 1:\nInput: target = \"10111\"\nOutput: 3\nExplanation: Initially, s = \"00000\".\nChoose index i = 2: \"00000\" -> \"00111\"\nChoose index i = 0: \"00111\" -> \"11000\"\nChoose index i = 1: \"11000\" -> \"10111\"\nWe need at least 3 flip operations to form target.", + "Example 2:\nInput: target = \"101\"\nOutput: 3\nExplanation: Initially, s = \"000\".\nChoose index i = 0: \"000\" -> \"111\"\nChoose index i = 1: \"111\" -> \"100\"\nChoose index i = 2: \"100\" -> \"101\"\nWe need at least 3 flip operations to form target.", + "Example 3:\nInput: target = \"00000\"\nOutput: 0\nExplanation: We do not need any operations since the initial s already equals target." + ], + "constraints": "Constraints:\n\nn == target.length\n1 <= n <= 10^5\ntarget[i] is either '0' or '1'.", + "tags": [ + "String", + "Greedy" + ], + "title-slug": "minimum-suffix-flips" + }, + { + "leetcode-id": 1530, + "title": "Number of Good Leaf Nodes Pairs", + "difficulty": 2, + "description": "You are given the root of a binary tree and an integer distance. A pair of two different leaf nodes of a binary tree is said to be good if the length of the shortest path between them is less than or equal to distance.\nReturn the number of good leaf node pairs in the tree.", + "examples": [ + "Example 1:\nInput: root = [1,2,3,null,4], distance = 3\nOutput: 1\nExplanation: The leaf nodes of the tree are 3 and 4 and the length of the shortest path between them is 3. This is the only good pair.", + "Example 2:\nInput: root = [1,2,3,4,5,6,7], distance = 3\nOutput: 2\nExplanation: The good pairs are [4,5] and [6,7] with shortest path = 2. The pair [4,6] is not good because the length of ther shortest path between them is 4.", + "Example 3:\nInput: root = [7,1,4,6,null,5,3,null,null,null,null,null,2], distance = 3\nOutput: 1\nExplanation: The only good pair is [2,5]." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 2^10].\n1 <= Node.val <= 100\n1 <= distance <= 10", + "tags": [ + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "number-of-good-leaf-nodes-pairs" + }, + { + "leetcode-id": 1531, + "title": "String Compression II", + "difficulty": 3, + "description": "Run-length encoding is a string compression method that works by\u00a0replacing consecutive identical characters (repeated 2 or more times) with the concatenation of the character and the number marking the count of the characters (length of the run). For example, to compress the string\u00a0\"aabccc\"\u00a0we replace \"aa\"\u00a0by\u00a0\"a2\"\u00a0and replace \"ccc\"\u00a0by\u00a0\"c3\". Thus the compressed string becomes \"a2bc3\".\nNotice that in this problem, we are not adding\u00a0'1'\u00a0after single characters.\nGiven a\u00a0string s\u00a0and an integer k. You need to delete at most\u00a0k characters from\u00a0s\u00a0such that the run-length encoded version of s\u00a0has minimum length.\nFind the minimum length of the run-length encoded\u00a0version of s after deleting at most k characters.", + "examples": [ + "Example 1:\nInput: s = \"aaabcccd\", k = 2\nOutput: 4\nExplanation: Compressing s without deleting anything will give us \"a3bc3d\" of length 6. Deleting any of the characters 'a' or 'c' would at most decrease the length of the compressed string to 5, for instance delete 2 'a' then we will have s = \"abcccd\" which compressed is abc3d. Therefore, the optimal way is to delete 'b' and 'd', then the compressed version of s will be \"a3c3\" of length 4.", + "Example 2:\nInput: s = \"aabbaa\", k = 2\nOutput: 2\nExplanation: If we delete both 'b' characters, the resulting compressed string would be \"a4\" of length 2.", + "Example 3:\nInput: s = \"aaaaaaaaaaa\", k = 0\nOutput: 3\nExplanation: Since k is zero, we cannot delete anything. The compressed string is \"a11\" of length 3." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\n0 <= k <= s.length\ns contains only lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "string-compression-ii" + }, + { + "leetcode-id": 1534, + "title": "Count Good Triplets", + "difficulty": 1, + "description": "Given an array of integers arr, and three integers\u00a0a,\u00a0b\u00a0and\u00a0c. You need to find the number of good triplets.\nA triplet (arr[i], arr[j], arr[k])\u00a0is good if the following conditions are true:\n\n0 <= i < j < k <\u00a0arr.length\n|arr[i] - arr[j]| <= a\n|arr[j] - arr[k]| <= b\n|arr[i] - arr[k]| <= c\n\nWhere |x| denotes the absolute value of x.\nReturn the number of good triplets.", + "examples": [ + "Example 1:\nInput: arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3\r\nOutput: 4\r\nExplanation:\u00a0There are 4 good triplets: [(3,0,1), (3,0,1), (3,1,1), (0,1,1)].", + "Example 2:\nInput: arr = [1,1,2,2,3], a = 0, b = 0, c = 1\r\nOutput: 0\r\nExplanation: No triplet satisfies all conditions." + ], + "constraints": "Constraints:\n\n3 <= arr.length <= 100\n0 <= arr[i] <= 1000\n0 <= a, b, c <= 1000", + "tags": [ + "Array", + "Enumeration" + ], + "title-slug": "count-good-triplets" + }, + { + "leetcode-id": 1535, + "title": "Find the Winner of an Array Game", + "difficulty": 2, + "description": "Given an integer array arr of distinct integers and an integer k.\nA game will be played between the first two elements of the array (i.e. arr[0] and arr[1]). In each round of the game, we compare arr[0] with arr[1], the larger integer wins and remains at position 0, and the smaller integer moves to the end of the array. The game ends when an integer wins k consecutive rounds.\nReturn the integer which will win the game.\nIt is guaranteed that there will be a winner of the game.", + "examples": [ + "Example 1:\nInput: arr = [2,1,3,5,4,6,7], k = 2\nOutput: 5\nExplanation: Let's see the rounds of the game:\nRound | arr | winner | win_count\n 1 | [2,1,3,5,4,6,7] | 2 | 1\n 2 | [2,3,5,4,6,7,1] | 3 | 1\n 3 | [3,5,4,6,7,1,2] | 5 | 1\n 4 | [5,4,6,7,1,2,3] | 5 | 2\nSo we can see that 4 rounds will be played and 5 is the winner because it wins 2 consecutive games.", + "Example 2:\nInput: arr = [3,2,1], k = 10\nOutput: 3\nExplanation: 3 will win the first 10 rounds consecutively." + ], + "constraints": "Constraints:\n\n2 <= arr.length <= 10^5\n1 <= arr[i] <= 10^6\narr contains distinct integers.\n1 <= k <= 10^9", + "tags": [ + "Array", + "Simulation" + ], + "title-slug": "find-the-winner-of-an-array-game" + }, + { + "leetcode-id": 1536, + "title": "Minimum Swaps to Arrange a Binary Grid", + "difficulty": 2, + "description": "Given an n x n binary grid, in one step you can choose two adjacent rows of the grid and swap them.\nA grid is said to be valid if all the cells above the main diagonal are zeros.\nReturn the minimum number of steps needed to make the grid valid, or -1 if the grid cannot be valid.\nThe main diagonal of a grid is the diagonal that starts at cell (1, 1) and ends at cell (n, n).", + "examples": [ + "Example 1:\nInput: grid = [[0,0,1],[1,1,0],[1,0,0]]\nOutput: 3", + "Example 2:\nInput: grid = [[0,1,1,0],[0,1,1,0],[0,1,1,0],[0,1,1,0]]\nOutput: -1\nExplanation: All rows are similar, swaps have no effect on the grid.", + "Example 3:\nInput: grid = [[1,0,0],[1,1,0],[1,1,1]]\nOutput: 0" + ], + "constraints": "Constraints:\n\nn == grid.length == grid[i].length\n1 <= n <= 200\ngrid[i][j] is either 0 or 1", + "tags": [ + "Array", + "Greedy", + "Matrix" + ], + "title-slug": "minimum-swaps-to-arrange-a-binary-grid" + }, + { + "leetcode-id": 1537, + "title": "Get the Maximum Score", + "difficulty": 3, + "description": "You are given two sorted arrays of distinct integers nums1 and nums2.\nA valid path is defined as follows:\n\nChoose array nums1 or nums2 to traverse (from index-0).\nTraverse the current array from left to right.\nIf you are reading any value that is present in nums1 and nums2 you are allowed to change your path to the other array. (Only one repeated value is considered in the valid path).\n\nThe score is defined as the sum of uniques values in a valid path.\nReturn the maximum score you can obtain of all possible valid paths. Since the answer may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: nums1 = [2,4,5,8,10], nums2 = [4,6,8,9]\nOutput: 30\nExplanation: Valid paths:\n[2,4,5,8,10], [2,4,5,8,9], [2,4,6,8,9], [2,4,6,8,10], (starting from nums1)\n[4,6,8,9], [4,5,8,10], [4,5,8,9], [4,6,8,10] (starting from nums2)\nThe maximum is obtained with the path in green [2,4,6,8,10].", + "Example 2:\nInput: nums1 = [1,3,5,7,9], nums2 = [3,5,100]\nOutput: 109\nExplanation: Maximum sum is obtained with the path [1,3,5,100].", + "Example 3:\nInput: nums1 = [1,2,3,4,5], nums2 = [6,7,8,9,10]\nOutput: 40\nExplanation: There are no common elements between nums1 and nums2.\nMaximum sum is obtained with the path [6,7,8,9,10]." + ], + "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 10^5\n1 <= nums1[i], nums2[i] <= 10^7\nnums1 and nums2 are strictly increasing.", + "tags": [ + "Array", + "Two Pointers", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "get-the-maximum-score" + }, + { + "leetcode-id": 1539, + "title": "Kth Missing Positive Number", + "difficulty": 1, + "description": "Given an array arr of positive integers sorted in a strictly increasing order, and an integer k.\nReturn the k^th positive integer that is missing from this array.", + "examples": [ + "Example 1:\nInput: arr = [2,3,4,7,11], k = 5\nOutput: 9\nExplanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5^th\u00a0missing positive integer is 9.", + "Example 2:\nInput: arr = [1,2,3,4], k = 2\nOutput: 6\nExplanation: The missing positive integers are [5,6,7,...]. The 2^nd missing positive integer is 6." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 1000\n1 <= arr[i] <= 1000\n1 <= k <= 1000\narr[i] < arr[j] for 1 <= i < j <= arr.length\n\n\u00a0\nFollow up:\nCould you solve this problem in less than O(n) complexity?", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "kth-missing-positive-number" + }, + { + "leetcode-id": 1540, + "title": "Can Convert String in K Moves", + "difficulty": 2, + "description": "Given two strings\u00a0s\u00a0and\u00a0t, your goal is to convert\u00a0s\u00a0into\u00a0t\u00a0in\u00a0k\u00a0moves or less.\nDuring the\u00a0i^th\u00a0(1 <= i <= k)\u00a0move you can:\n\nChoose any index\u00a0j\u00a0(1-indexed) from\u00a0s, such that\u00a01 <= j <= s.length\u00a0and j\u00a0has not been chosen in any previous move,\u00a0and shift the character at that index\u00a0i\u00a0times.\nDo nothing.\n\nShifting a character means replacing it by the next letter in the alphabet\u00a0(wrapping around so that\u00a0'z'\u00a0becomes\u00a0'a'). Shifting a character by\u00a0i\u00a0means applying the shift operations\u00a0i\u00a0times.\nRemember that any index\u00a0j\u00a0can be picked at most once.\nReturn\u00a0true\u00a0if it's possible to convert\u00a0s\u00a0into\u00a0t\u00a0in no more than\u00a0k\u00a0moves, otherwise return\u00a0false.", + "examples": [ + "Example 1:\nInput: s = \"input\", t = \"ouput\", k = 9\nOutput: true\nExplanation: In the 6th move, we shift 'i' 6 times to get 'o'. And in the 7th move we shift 'n' to get 'u'.", + "Example 2:\nInput: s = \"abc\", t = \"bcd\", k = 10\nOutput: false\nExplanation: We need to shift each character in s one time to convert it into t. We can shift 'a' to 'b' during the 1st move. However, there is no way to shift the other characters in the remaining moves to obtain t from s.", + "Example 3:\nInput: s = \"aab\", t = \"bbb\", k = 27\nOutput: true\nExplanation: In the 1st move, we shift the first 'a' 1 time to get 'b'. In the 27th move, we shift the second 'a' 27 times to get 'b'." + ], + "constraints": "Constraints:\n\n1 <= s.length, t.length <= 10^5\n0 <= k <= 10^9\ns, t contain\u00a0only lowercase English letters.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "can-convert-string-in-k-moves" + }, + { + "leetcode-id": 1541, + "title": "Minimum Insertions to Balance a Parentheses String", + "difficulty": 2, + "description": "Given a parentheses string s containing only the characters '(' and ')'. A parentheses string is balanced if:\n\nAny left parenthesis '(' must have a corresponding two consecutive right parenthesis '))'.\nLeft parenthesis '(' must go before the corresponding two consecutive right parenthesis '))'.\n\nIn other words, we treat '(' as an opening parenthesis and '))' as a closing parenthesis.\n\nFor example, \"())\", \"())(())))\" and \"(())())))\" are balanced, \")()\", \"()))\" and \"(()))\" are not balanced.\n\nYou can insert the characters '(' and ')' at any position of the string to balance it if needed.\nReturn the minimum number of insertions needed to make s balanced.", + "examples": [ + "Example 1:\nInput: s = \"(()))\"\nOutput: 1\nExplanation: The second '(' has two matching '))', but the first '(' has only ')' matching. We need to add one more ')' at the end of the string to be \"(())))\" which is balanced.", + "Example 2:\nInput: s = \"())\"\nOutput: 0\nExplanation: The string is already balanced.", + "Example 3:\nInput: s = \"))())(\"\nOutput: 3\nExplanation: Add '(' to match the first '))', Add '))' to match the last '('." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of '(' and ')' only.", + "tags": [ + "String", + "Stack", + "Greedy" + ], + "title-slug": "minimum-insertions-to-balance-a-parentheses-string" + }, + { + "leetcode-id": 1542, + "title": "Find Longest Awesome Substring", + "difficulty": 3, + "description": "You are given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it a palindrome.\nReturn the length of the maximum length awesome substring of s.", + "examples": [ + "Example 1:\nInput: s = \"3242415\"\nOutput: 5\nExplanation: \"24241\" is the longest awesome substring, we can form the palindrome \"24142\" with some swaps.", + "Example 2:\nInput: s = \"12345678\"\nOutput: 1", + "Example 3:\nInput: s = \"213123\"\nOutput: 6\nExplanation: \"213123\" is the longest awesome substring, we can form the palindrome \"231132\" with some swaps." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists only of digits.", + "tags": [ + "Hash Table", + "String", + "Bit Manipulation" + ], + "title-slug": "find-longest-awesome-substring" + }, + { + "leetcode-id": 1544, + "title": "Make The String Great", + "difficulty": 1, + "description": "Given a string s of lower and upper case English letters.\nA good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:\n\n0 <= i <= s.length - 2\ns[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa.\n\nTo make the string good, you can choose two adjacent characters that make the string bad and remove them. You can keep doing this until the string becomes good.\nReturn the string after making it good. The answer is guaranteed to be unique under the given constraints.\nNotice that an empty string is also good.", + "examples": [ + "Example 1:\nInput: s = \"leEeetcode\"\nOutput: \"leetcode\"\nExplanation: In the first step, either you choose i = 1 or i = 2, both will result \"leEeetcode\" to be reduced to \"leetcode\".", + "Example 2:\nInput: s = \"abBAcC\"\nOutput: \"\"\nExplanation: We have many possible scenarios, and all lead to the same answer. For example:\n\"abBAcC\" --> \"aAcC\" --> \"cC\" --> \"\"\n\"abBAcC\" --> \"abBA\" --> \"aA\" --> \"\"", + "Example 3:\nInput: s = \"s\"\nOutput: \"s\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\ns contains only lower and upper case English letters.", + "tags": [ + "String", + "Stack" + ], + "title-slug": "make-the-string-great" + }, + { + "leetcode-id": 1545, + "title": "Find Kth Bit in Nth Binary String", + "difficulty": 2, + "description": "Given two positive integers n and k, the binary string Sn is formed as follows:\n\nS1 = \"0\"\nSi = Si - 1 + \"1\" + reverse(invert(Si - 1)) for i > 1\n\nWhere + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).\nFor example, the first four strings in the above sequence are:\n\nS1 = \"0\"\nS2 = \"011\"\nS3 = \"0111001\"\nS4 = \"011100110110001\"\n\nReturn the k^th bit in Sn. It is guaranteed that k is valid for the given n.", + "examples": [ + "Example 1:\nInput: n = 3, k = 1\nOutput: \"0\"\nExplanation: S3 is \"0111001\".\nThe 1^st bit is \"0\".", + "Example 2:\nInput: n = 4, k = 11\nOutput: \"1\"\nExplanation: S4 is \"011100110110001\".\nThe 11^th bit is \"1\"." + ], + "constraints": "Constraints:\n\n1 <= n <= 20\n1 <= k <= 2^n - 1", + "tags": [ + "String", + "Recursion" + ], + "title-slug": "find-kth-bit-in-nth-binary-string" + }, + { + "leetcode-id": 1546, + "title": "Maximum Number of Non-Overlapping Subarrays With Sum Equals Target", + "difficulty": 2, + "description": "Given an array nums and an integer target, return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target.", + "examples": [ + "Example 1:\nInput: nums = [1,1,1,1,1], target = 2\nOutput: 2\nExplanation: There are 2 non-overlapping subarrays [1,1,1,1,1] with sum equals to target(2).", + "Example 2:\nInput: nums = [-1,3,5,1,4,2,-9], target = 6\nOutput: 2\nExplanation: There are 3 subarrays with sum equal to 6.\n([5,1], [4,2], [3,5,1,4,2,-9]) but only the first 2 are non-overlapping." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^4 <= nums[i] <= 10^4\n0 <= target <= 10^6", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Prefix Sum" + ], + "title-slug": "maximum-number-of-non-overlapping-subarrays-with-sum-equals-target" + }, + { + "leetcode-id": 1547, + "title": "Minimum Cost to Cut a Stick", + "difficulty": 3, + "description": "Given a wooden stick of length n units. The stick is labelled from 0 to n. For example, a stick of length 6 is labelled as follows:\n\nGiven an integer array cuts where cuts[i] denotes a position you should perform a cut at.\nYou should perform the cuts in order, you can change the order of the cuts as you wish.\nThe cost of one cut is the length of the stick to be cut, the total cost is the sum of costs of all cuts. When you cut a stick, it will be split into two smaller sticks (i.e. the sum of their lengths is the length of the stick before the cut). Please refer to the first example for a better explanation.\nReturn the minimum total cost of the cuts.", + "examples": [ + "Example 1:\nInput: n = 7, cuts = [1,3,4,5]\nOutput: 16\nExplanation: Using cuts order = [1, 3, 4, 5] as in the input leads to the following scenario:\n\nThe first cut is done to a rod of length 7 so the cost is 7. The second cut is done to a rod of length 6 (i.e. the second part of the first cut), the third is done to a rod of length 4 and the last cut is to a rod of length 3. The total cost is 7 + 6 + 4 + 3 = 20.\nRearranging the cuts to be [3, 5, 1, 4] for example will lead to a scenario with total cost = 16 (as shown in the example photo 7 + 4 + 3 + 2 = 16).", + "Example 2:\nInput: n = 9, cuts = [5,6,1,4,2]\nOutput: 22\nExplanation: If you try the given cuts ordering the cost will be 25.\nThere are much ordering with total cost <= 25, for example, the order [4, 6, 5, 2, 1] has total cost = 22 which is the minimum possible." + ], + "constraints": "Constraints:\n\n2 <= n <= 10^6\n1 <= cuts.length <= min(n - 1, 100)\n1 <= cuts[i] <= n - 1\nAll the integers in cuts array are distinct.", + "tags": [ + "Array", + "Dynamic Programming", + "Sorting" + ], + "title-slug": "minimum-cost-to-cut-a-stick" + }, + { + "leetcode-id": 1550, + "title": "Three Consecutive Odds", + "difficulty": 1, + "description": "Given an integer array arr, return true\u00a0if there are three consecutive odd numbers in the array. Otherwise, return\u00a0false.", + "examples": [ + "Example 1:\nInput: arr = [2,6,4,1]\nOutput: false\nExplanation: There are no three consecutive odds.", + "Example 2:\nInput: arr = [1,2,34,3,4,5,7,23,12]\nOutput: true\nExplanation: [5,7,23] are three consecutive odds." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 1000\n1 <= arr[i] <= 1000", + "tags": [ + "Array" + ], + "title-slug": "three-consecutive-odds" + }, + { + "leetcode-id": 1551, + "title": "Minimum Operations to Make Array Equal", + "difficulty": 2, + "description": "You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e.,\u00a00 <= i < n).\nIn one operation, you can select two indices x and y where 0 <= x, y < n and subtract 1 from arr[x] and add 1 to arr[y] (i.e., perform arr[x] -=1 and arr[y] += 1). The goal is to make all the elements of the array equal. It is guaranteed that all the elements of the array can be made equal using some operations.\nGiven an integer n, the length of the array, return the minimum number of operations needed to make all the elements of arr equal.", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: 2\nExplanation: arr = [1, 3, 5]\nFirst operation choose x = 2 and y = 0, this leads arr to be [2, 3, 4]\nIn the second operation choose x = 2 and y = 0 again, thus arr = [3, 3, 3].", + "Example 2:\nInput: n = 6\nOutput: 9" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^4", + "tags": [ + "Math" + ], + "title-slug": "minimum-operations-to-make-array-equal" + }, + { + "leetcode-id": 1552, + "title": "Magnetic Force Between Two Balls", + "difficulty": 2, + "description": "In the universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the i^th basket is at position[i], Morty has m balls and needs to distribute the balls into the baskets such that the minimum magnetic force between any two balls is maximum.\nRick stated that magnetic force between two different balls at positions x and y is |x - y|.\nGiven the integer array position and the integer m. Return the required force.", + "examples": [ + "Example 1:\nInput: position = [1,2,3,4,7], m = 3\nOutput: 3\nExplanation: Distributing the 3 balls into baskets 1, 4 and 7 will make the magnetic force between ball pairs [3, 3, 6]. The minimum magnetic force is 3. We cannot achieve a larger minimum magnetic force than 3.", + "Example 2:\nInput: position = [5,4,3,2,1,1000000000], m = 2\nOutput: 999999999\nExplanation: We can use baskets 1 and 1000000000." + ], + "constraints": "Constraints:\n\nn == position.length\n2 <= n <= 10^5\n1 <= position[i] <= 10^9\nAll integers in position are distinct.\n2 <= m <= position.length", + "tags": [ + "Array", + "Binary Search", + "Sorting" + ], + "title-slug": "magnetic-force-between-two-balls" + }, + { + "leetcode-id": 1553, + "title": "Minimum Number of Days to Eat N Oranges", + "difficulty": 3, + "description": "There are n oranges in the kitchen and you decided to eat some of these oranges every day as follows:\n\nEat one orange.\nIf the number of remaining oranges n is divisible by 2 then you can eat n / 2 oranges.\nIf the number of remaining oranges n is divisible by 3 then you can eat 2 * (n / 3) oranges.\n\nYou can only choose one of the actions per day.\nGiven the integer n, return the minimum number of days to eat n oranges.", + "examples": [ + "Example 1:\nInput: n = 10\nOutput: 4\nExplanation: You have 10 oranges.\nDay 1: Eat 1 orange, 10 - 1 = 9. \nDay 2: Eat 6 oranges, 9 - 2*(9/3) = 9 - 6 = 3. (Since 9 is divisible by 3)\nDay 3: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. \nDay 4: Eat the last orange 1 - 1 = 0.\nYou need at least 4 days to eat the 10 oranges.", + "Example 2:\nInput: n = 6\nOutput: 3\nExplanation: You have 6 oranges.\nDay 1: Eat 3 oranges, 6 - 6/2 = 6 - 3 = 3. (Since 6 is divisible by 2).\nDay 2: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. (Since 3 is divisible by 3)\nDay 3: Eat the last orange 1 - 1 = 0.\nYou need at least 3 days to eat the 6 oranges." + ], + "constraints": "Constraints:\n\n1 <= n <= 2 * 10^9", + "tags": [ + "Dynamic Programming", + "Memoization" + ], + "title-slug": "minimum-number-of-days-to-eat-n-oranges" + }, + { + "leetcode-id": 1556, + "title": "Thousand Separator", + "difficulty": 1, + "description": "Given an integer n, add a dot (\".\") as the thousands separator and return it in string format.", + "examples": [ + "Example 1:\nInput: n = 987\nOutput: \"987\"", + "Example 2:\nInput: n = 1234\nOutput: \"1.234\"" + ], + "constraints": "Constraints:\n\n0 <= n <= 2^31 - 1", + "tags": [ + "String" + ], + "title-slug": "thousand-separator" + }, + { + "leetcode-id": 1557, + "title": "Minimum Number of Vertices to Reach All Nodes", + "difficulty": 2, + "description": "Given a\u00a0directed acyclic graph,\u00a0with\u00a0n\u00a0vertices numbered from\u00a00\u00a0to\u00a0n-1,\u00a0and an array\u00a0edges\u00a0where\u00a0edges[i] = [fromi, toi]\u00a0represents a directed edge from node\u00a0fromi\u00a0to node\u00a0toi.\nFind the smallest set of vertices from which all nodes in the graph are reachable. It's guaranteed that a unique solution exists.\nNotice that you can return the vertices in any order.", + "examples": [ + "Example 1:\nInput: n = 6, edges = [[0,1],[0,2],[2,5],[3,4],[4,2]]\nOutput: [0,3]\nExplanation: It's not possible to reach all the nodes from a single vertex. From 0 we can reach [0,1,2,5]. From 3 we can reach [3,4,2,5]. So we output [0,3].", + "Example 2:\nInput: n = 5, edges = [[0,1],[2,1],[3,1],[1,4],[2,4]]\nOutput: [0,2,3]\nExplanation: Notice that vertices 0, 3 and 2 are not reachable from any other node, so we must include them. Also any of these vertices can reach nodes 1 and 4." + ], + "constraints": "Constraints:\n\n2 <= n <= 10^5\n1 <= edges.length <= min(10^5, n * (n - 1) / 2)\nedges[i].length == 2\n0 <= fromi,\u00a0toi < n\nAll pairs (fromi, toi) are distinct.", + "tags": [ + "Graph" + ], + "title-slug": "minimum-number-of-vertices-to-reach-all-nodes" + }, + { + "leetcode-id": 1558, + "title": "Minimum Numbers of Function Calls to Make Target Array", + "difficulty": 2, + "description": "You are given an integer array nums. You have an integer array arr of the same length with all values set to 0 initially. You also have the following modify function:\n\nYou want to use the modify function to convert arr to nums using the minimum number of calls.\nReturn the minimum number of function calls to make nums from arr.\nThe test cases are generated so that the answer fits in a 32-bit signed integer.", + "examples": [ + "Example 1:\nInput: nums = [1,5]\nOutput: 5\nExplanation: Increment by 1 (second element): [0, 0] to get [0, 1] (1 operation).\nDouble all the elements: [0, 1] -> [0, 2] -> [0, 4] (2 operations).\nIncrement by 1 (both elements) [0, 4] -> [1, 4] -> [1, 5] (2 operations).\nTotal of operations: 1 + 2 + 2 = 5.", + "Example 2:\nInput: nums = [2,2]\nOutput: 3\nExplanation: Increment by 1 (both elements) [0, 0] -> [0, 1] -> [1, 1] (2 operations).\nDouble all the elements: [1, 1] -> [2, 2] (1 operation).\nTotal of operations: 2 + 1 = 3.", + "Example 3:\nInput: nums = [4,2,5]\nOutput: 6\nExplanation: (initial)[0,0,0] -> [1,0,0] -> [1,0,1] -> [2,0,2] -> [2,1,2] -> [4,2,4] -> [4,2,5](nums)." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Greedy", + "Bit Manipulation" + ], + "title-slug": "minimum-numbers-of-function-calls-to-make-target-array" + }, + { + "leetcode-id": 1559, + "title": "Detect Cycles in 2D Grid", + "difficulty": 2, + "description": "Given a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid.\nA cycle is a path of length 4 or more in the grid that starts and ends at the same cell. From a given cell, you can move to one of the cells adjacent to it - in one of the four directions (up, down, left, or right), if it has the same value of the current cell.\nAlso, you cannot move to the cell that you visited in your last move. For example, the cycle (1, 1) -> (1, 2) -> (1, 1) is invalid because from (1, 2) we visited (1, 1) which was the last visited cell.\nReturn true if any cycle of the same value exists in grid, otherwise, return false.", + "examples": [ + "Example 1:\nInput: grid = [[\"a\",\"a\",\"a\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"b\",\"b\",\"a\"],[\"a\",\"a\",\"a\",\"a\"]]\nOutput: true\nExplanation: There are two valid cycles shown in different colors in the image below:", + "Example 2:\nInput: grid = [[\"c\",\"c\",\"c\",\"a\"],[\"c\",\"d\",\"c\",\"c\"],[\"c\",\"c\",\"e\",\"c\"],[\"f\",\"c\",\"c\",\"c\"]]\nOutput: true\nExplanation: There is only one valid cycle highlighted in the image below:", + "Example 3:\nInput: grid = [[\"a\",\"b\",\"b\"],[\"b\",\"z\",\"b\"],[\"b\",\"b\",\"a\"]]\nOutput: false" + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 500\ngrid consists only of lowercase English letters.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Matrix" + ], + "title-slug": "detect-cycles-in-2d-grid" + }, + { + "leetcode-id": 1560, + "title": "Most Visited Sector in a Circular Track", + "difficulty": 1, + "description": "Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The i^th round starts at sector rounds[i - 1] and ends at sector rounds[i]. For example, round 1 starts at sector rounds[0] and ends at sector rounds[1]\nReturn an array of the most visited sectors sorted in ascending order.\nNotice that you circulate the track in ascending order of sector numbers in the counter-clockwise direction (See the first example).", + "examples": [ + "Example 1:\nInput: n = 4, rounds = [1,3,1,2]\nOutput: [1,2]\nExplanation: The marathon starts at sector 1. The order of the visited sectors is as follows:\n1 --> 2 --> 3 (end of round 1) --> 4 --> 1 (end of round 2) --> 2 (end of round 3 and the marathon)\nWe can see that both sectors 1 and 2 are visited twice and they are the most visited sectors. Sectors 3 and 4 are visited only once.", + "Example 2:\nInput: n = 2, rounds = [2,1,2,1,2,1,2,1,2]\nOutput: [2]", + "Example 3:\nInput: n = 7, rounds = [1,3,5,7]\nOutput: [1,2,3,4,5,6,7]" + ], + "constraints": "Constraints:\n\n2 <= n <= 100\n1 <= m <= 100\nrounds.length == m + 1\n1 <= rounds[i] <= n\nrounds[i] != rounds[i + 1] for 0 <= i < m", + "tags": [ + "Array", + "Simulation" + ], + "title-slug": "most-visited-sector-in-a-circular-track" + }, + { + "leetcode-id": 1561, + "title": "Maximum Number of Coins You Can Get", + "difficulty": 2, + "description": "There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:\n\nIn each step, you will choose any 3 piles of coins (not necessarily consecutive).\nOf your choice, Alice will pick the pile with the maximum number of coins.\nYou will pick the next pile with the maximum number of coins.\nYour friend Bob will pick the last pile.\nRepeat until there are no more piles of coins.\n\nGiven an array of integers piles where piles[i] is the number of coins in the i^th pile.\nReturn the maximum number of coins that you can have.", + "examples": [ + "Example 1:\nInput: piles = [2,4,1,2,7,8]\nOutput: 9\nExplanation: Choose the triplet (2, 7, 8), Alice Pick the pile with 8 coins, you the pile with 7 coins and Bob the last one.\nChoose the triplet (1, 2, 4), Alice Pick the pile with 4 coins, you the pile with 2 coins and Bob the last one.\nThe maximum number of coins which you can have are: 7 + 2 = 9.\nOn the other hand if we choose this arrangement (1, 2, 8), (2, 4, 7) you only get 2 + 4 = 6 coins which is not optimal.", + "Example 2:\nInput: piles = [2,4,5]\nOutput: 4", + "Example 3:\nInput: piles = [9,8,7,6,5,1,2,3,4]\nOutput: 18" + ], + "constraints": "Constraints:\n\n3 <= piles.length <= 10^5\npiles.length % 3 == 0\n1 <= piles[i] <= 10^4", + "tags": [ + "Array", + "Math", + "Greedy", + "Sorting", + "Game Theory" + ], + "title-slug": "maximum-number-of-coins-you-can-get" + }, + { + "leetcode-id": 1562, + "title": "Find Latest Group of Size M", + "difficulty": 2, + "description": "Given an array arr that represents a permutation of numbers from 1 to n.\nYou have a binary string of size n that initially has all its bits set to zero. At each step i (assuming both the binary string and arr are 1-indexed) from 1 to n, the bit at position arr[i] is set to 1.\nYou are also given an integer m. Find the latest step at which there exists a group of ones of length m. A group of ones is a contiguous substring of 1's such that it cannot be extended in either direction.\nReturn the latest step at which there exists a group of ones of length exactly m. If no such group exists, return -1.", + "examples": [ + "Example 1:\nInput: arr = [3,5,1,2,4], m = 1\nOutput: 4\nExplanation: \nStep 1: \"00100\", groups: [\"1\"]\nStep 2: \"00101\", groups: [\"1\", \"1\"]\nStep 3: \"10101\", groups: [\"1\", \"1\", \"1\"]\nStep 4: \"11101\", groups: [\"111\", \"1\"]\nStep 5: \"11111\", groups: [\"11111\"]\nThe latest step at which there exists a group of size 1 is step 4.", + "Example 2:\nInput: arr = [3,1,5,4,2], m = 2\nOutput: -1\nExplanation: \nStep 1: \"00100\", groups: [\"1\"]\nStep 2: \"10100\", groups: [\"1\", \"1\"]\nStep 3: \"10101\", groups: [\"1\", \"1\", \"1\"]\nStep 4: \"10111\", groups: [\"1\", \"111\"]\nStep 5: \"11111\", groups: [\"11111\"]\nNo group of size 2 exists during any step." + ], + "constraints": "Constraints:\n\nn == arr.length\n1 <= m <= n <= 10^5\n1 <= arr[i] <= n\nAll integers in arr are distinct.", + "tags": [ + "Array", + "Binary Search", + "Simulation" + ], + "title-slug": "find-latest-group-of-size-m" + }, + { + "leetcode-id": 1563, + "title": "Stone Game V", + "difficulty": 3, + "description": "There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue.\nIn each round of the game, Alice divides the row into two non-empty rows (i.e. left row and right row), then Bob calculates the value of each row which is the sum of the values of all the stones in this row. Bob throws away the row which has the maximum value, and Alice's score increases by the value of the remaining row. If the value of the two rows are equal, Bob lets Alice decide which row will be thrown away. The next round starts with the remaining row.\nThe game ends when there is only one stone remaining. Alice's is initially zero.\nReturn the maximum score that Alice can obtain.", + "examples": [ + "Example 1:\nInput: stoneValue = [6,2,3,4,5,5]\nOutput: 18\nExplanation: In the first round, Alice divides the row to [6,2,3], [4,5,5]. The left row has the value 11 and the right row has value 14. Bob throws away the right row and Alice's score is now 11.\nIn the second round Alice divides the row to [6], [2,3]. This time Bob throws away the left row and Alice's score becomes 16 (11 + 5).\nThe last round Alice has only one choice to divide the row which is [2], [3]. Bob throws away the right row and Alice's score is now 18 (16 + 2). The game ends because only one stone is remaining in the row.", + "Example 2:\nInput: stoneValue = [7,7,7,7,7,7,7]\nOutput: 28", + "Example 3:\nInput: stoneValue = [4]\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= stoneValue.length <= 500\n1 <= stoneValue[i] <= 10^6", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Game Theory" + ], + "title-slug": "stone-game-v" + }, + { + "leetcode-id": 1566, + "title": "Detect Pattern of Length M Repeated K or More Times", + "difficulty": 1, + "description": "Given an array of positive integers arr, find a pattern of length m that is repeated k or more times.\nA pattern is a subarray (consecutive sub-sequence) that consists of one or more values, repeated multiple times consecutively without overlapping. A pattern is defined by its length and the number of repetitions.\nReturn true if there exists a pattern of length m that is repeated k or more times, otherwise return false.", + "examples": [ + "Example 1:\nInput: arr = [1,2,4,4,4,4], m = 1, k = 3\nOutput: true\nExplanation: The pattern (4) of length 1 is repeated 4 consecutive times. Notice that pattern can be repeated k or more times but not less.", + "Example 2:\nInput: arr = [1,2,1,2,1,1,1,3], m = 2, k = 2\nOutput: true\nExplanation: The pattern (1,2) of length 2 is repeated 2 consecutive times. Another valid pattern (2,1) is also repeated 2 times.", + "Example 3:\nInput: arr = [1,2,1,2,1,3], m = 2, k = 3\nOutput: false\nExplanation: The pattern (1,2) is of length 2 but is repeated only 2 times. There is no pattern of length 2 that is repeated 3 or more times." + ], + "constraints": "Constraints:\n\n2 <= arr.length <= 100\n1 <= arr[i] <= 100\n1 <= m <= 100\n2 <= k <= 100", + "tags": [ + "Array", + "Enumeration" + ], + "title-slug": "detect-pattern-of-length-m-repeated-k-or-more-times" + }, + { + "leetcode-id": 1567, + "title": "Maximum Length of Subarray With Positive Product", + "difficulty": 2, + "description": "Given an array of integers nums, find the maximum length of a subarray where the product of all its elements is positive.\nA subarray of an array is a consecutive sequence of zero or more values taken out of that array.\nReturn the maximum length of a subarray with positive product.", + "examples": [ + "Example 1:\nInput: nums = [1,-2,-3,4]\nOutput: 4\nExplanation: The array nums already has a positive product of 24.", + "Example 2:\nInput: nums = [0,1,-2,-3,-4]\nOutput: 3\nExplanation: The longest subarray with positive product is [1,-2,-3] which has a product of 6.\nNotice that we cannot include 0 in the subarray since that'll make the product 0 which is not positive.", + "Example 3:\nInput: nums = [-1,-2,-3,0,1]\nOutput: 2\nExplanation: The longest subarray with positive product is [-1,-2] or [-2,-3]." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^9 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "maximum-length-of-subarray-with-positive-product" + }, + { + "leetcode-id": 1568, + "title": "Minimum Number of Days to Disconnect Island", + "difficulty": 3, + "description": "You are given an m x n binary grid grid where 1 represents land and 0 represents water. An island is a maximal 4-directionally (horizontal or vertical) connected group of 1's.\nThe grid is said to be connected if we have exactly one island, otherwise is said disconnected.\nIn one day, we are allowed to change any single land cell (1) into a water cell (0).\nReturn the minimum number of days to disconnect the grid.", + "examples": [ + "Example 1:\nInput: grid = [[0,1,1,0],[0,1,1,0],[0,0,0,0]]\n\nOutput: 2\nExplanation: We need at least 2 days to get a disconnected grid.\nChange land grid[1][1] and grid[0][2] to water and get 2 disconnected island.", + "Example 2:\nInput: grid = [[1,1]]\nOutput: 2\nExplanation: Grid of full water is also disconnected ([[1,1]] -> [[0,0]]), 0 islands." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 30\ngrid[i][j] is either 0 or 1.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Matrix", + "Strongly Connected Component" + ], + "title-slug": "minimum-number-of-days-to-disconnect-island" + }, + { + "leetcode-id": 1569, + "title": "Number of Ways to Reorder Array to Get Same BST", + "difficulty": 3, + "description": "Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nums in order into an initially empty BST. Find the number of different ways to reorder nums so that the constructed BST is identical to that formed from the original array nums.\n\nFor example, given nums = [2,1,3], we will have 2 as the root, 1 as a left child, and 3 as a right child. The array [2,3,1] also yields the same BST but [3,2,1] yields a different BST.\n\nReturn the number of ways to reorder nums such that the BST formed is identical to the original BST formed from nums.\nSince the answer may be very large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: nums = [2,1,3]\nOutput: 1\nExplanation: We can reorder nums to be [2,3,1] which will yield the same BST. There are no other ways to reorder nums which will yield the same BST.", + "Example 2:\nInput: nums = [3,4,5,1,2]\nOutput: 5\nExplanation: The following 5 arrays will yield the same BST: \n[3,1,2,4,5]\n[3,1,4,2,5]\n[3,1,4,5,2]\n[3,4,1,2,5]\n[3,4,1,5,2]", + "Example 3:\nInput: nums = [1,2,3]\nOutput: 0\nExplanation: There are no other orderings of nums that will yield the same BST." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= nums.length\nAll integers in nums are distinct.", + "tags": [ + "Array", + "Math", + "Divide and Conquer", + "Dynamic Programming", + "Tree", + "Union Find", + "Binary Search Tree", + "Memoization", + "Combinatorics", + "Binary Tree" + ], + "title-slug": "number-of-ways-to-reorder-array-to-get-same-bst" + }, + { + "leetcode-id": 1572, + "title": "Matrix Diagonal Sum", + "difficulty": 1, + "description": "Given a\u00a0square\u00a0matrix\u00a0mat, return the sum of the matrix diagonals.\nOnly include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal.", + "examples": [ + "Example 1:\nInput: mat = [[1,2,3],\n\u00a0 [4,5,6],\n\u00a0 [7,8,9]]\nOutput: 25\nExplanation: Diagonals sum: 1 + 5 + 9 + 3 + 7 = 25\nNotice that element mat[1][1] = 5 is counted only once.", + "Example 2:\nInput: mat = [[1,1,1,1],\n\u00a0 [1,1,1,1],\n\u00a0 [1,1,1,1],\n\u00a0 [1,1,1,1]]\nOutput: 8", + "Example 3:\nInput: mat = [[5]]\nOutput: 5" + ], + "constraints": "Constraints:\n\nn == mat.length == mat[i].length\n1 <= n <= 100\n1 <= mat[i][j] <= 100", + "tags": [ + "Array", + "Matrix" + ], + "title-slug": "matrix-diagonal-sum" + }, + { + "leetcode-id": 1573, + "title": "Number of Ways to Split a String", + "difficulty": 2, + "description": "Given a binary string s, you can split s into 3 non-empty strings s1, s2, and s3 where s1 + s2 + s3 = s.\nReturn the number of ways s can be split such that the number of ones is the same in s1, s2, and s3. Since the answer may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: s = \"10101\"\nOutput: 4\nExplanation: There are four ways to split s in 3 parts where each part contain the same number of letters '1'.\n\"1|010|1\"\n\"1|01|01\"\n\"10|10|1\"\n\"10|1|01\"", + "Example 2:\nInput: s = \"1001\"\nOutput: 0", + "Example 3:\nInput: s = \"0000\"\nOutput: 3\nExplanation: There are three ways to split s in 3 parts.\n\"0|0|00\"\n\"0|00|0\"\n\"00|0|0\"" + ], + "constraints": "Constraints:\n\n3 <= s.length <= 10^5\ns[i] is either '0' or '1'.", + "tags": [ + "Math", + "String" + ], + "title-slug": "number-of-ways-to-split-a-string" + }, + { + "leetcode-id": 1574, + "title": "Shortest Subarray to be Removed to Make Array Sorted", + "difficulty": 2, + "description": "Given an integer array arr, remove a subarray (can be empty) from arr such that the remaining elements in arr are non-decreasing.\nReturn the length of the shortest subarray to remove.\nA subarray is a contiguous subsequence of the array.", + "examples": [ + "Example 1:\nInput: arr = [1,2,3,10,4,2,3,5]\nOutput: 3\nExplanation: The shortest subarray we can remove is [10,4,2] of length 3. The remaining elements after that will be [1,2,3,3,5] which are sorted.\nAnother correct solution is to remove the subarray [3,10,4].", + "Example 2:\nInput: arr = [5,4,3,2,1]\nOutput: 4\nExplanation: Since the array is strictly decreasing, we can only keep a single element. Therefore we need to remove a subarray of length 4, either [5,4,3,2] or [4,3,2,1].", + "Example 3:\nInput: arr = [1,2,3]\nOutput: 0\nExplanation: The array is already non-decreasing. We do not need to remove any elements." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^5\n0 <= arr[i] <= 10^9", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Stack", + "Monotonic Stack" + ], + "title-slug": "shortest-subarray-to-be-removed-to-make-array-sorted" + }, + { + "leetcode-id": 1575, + "title": "Count All Possible Routes", + "difficulty": 3, + "description": "You are given an array of distinct positive integers locations where locations[i] represents the position of city i. You are also given integers start, finish and fuel representing the starting city, ending city, and the initial amount of fuel you have, respectively.\nAt each step, if you are at city i, you can pick any city j such that j != i and 0 <= j < locations.length and move to city j. Moving from city i to city j reduces the amount of fuel you have by |locations[i] - locations[j]|. Please notice that |x| denotes the absolute value of x.\nNotice that fuel cannot become negative at any point in time, and that you are allowed to visit any city more than once (including start and finish).\nReturn the count of all possible routes from start to finish. Since the answer may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: locations = [2,3,6,8,4], start = 1, finish = 3, fuel = 5\nOutput: 4\nExplanation: The following are all possible routes, each uses 5 units of fuel:\n1 -> 3\n1 -> 2 -> 3\n1 -> 4 -> 3\n1 -> 4 -> 2 -> 3", + "Example 2:\nInput: locations = [4,3,1], start = 1, finish = 0, fuel = 6\nOutput: 5\nExplanation: The following are all possible routes:\n1 -> 0, used fuel = 1\n1 -> 2 -> 0, used fuel = 5\n1 -> 2 -> 1 -> 0, used fuel = 5\n1 -> 0 -> 1 -> 0, used fuel = 3\n1 -> 0 -> 1 -> 0 -> 1 -> 0, used fuel = 5", + "Example 3:\nInput: locations = [5,2,1], start = 0, finish = 2, fuel = 3\nOutput: 0\nExplanation: It is impossible to get from 0 to 2 using only 3 units of fuel since the shortest route needs 4 units of fuel." + ], + "constraints": "Constraints:\n\n2 <= locations.length <= 100\n1 <= locations[i] <= 10^9\nAll integers in locations are distinct.\n0 <= start, finish < locations.length\n1 <= fuel <= 200", + "tags": [ + "Array", + "Dynamic Programming", + "Memoization" + ], + "title-slug": "count-all-possible-routes" + }, + { + "leetcode-id": 1576, + "title": "Replace All ?'s to Avoid Consecutive Repeating Characters", + "difficulty": 1, + "description": "Given a string s containing only lowercase English letters and the '?' character, convert all the '?' characters into lowercase letters such that the final string does not contain any consecutive repeating characters. You cannot modify the non '?' characters.\nIt is guaranteed that there are no consecutive repeating characters in the given string except for '?'.\nReturn the final string after all the conversions (possibly zero) have been made. If there is more than one solution, return any of them. It can be shown that an answer is always possible with the given constraints.", + "examples": [ + "Example 1:\nInput: s = \"?zs\"\nOutput: \"azs\"\nExplanation: There are 25 solutions for this problem. From \"azs\" to \"yzs\", all are valid. Only \"z\" is an invalid modification as the string will consist of consecutive repeating characters in \"zzs\".", + "Example 2:\nInput: s = \"ubv?w\"\nOutput: \"ubvaw\"\nExplanation: There are 24 solutions for this problem. Only \"v\" and \"w\" are invalid modifications as the strings will consist of consecutive repeating characters in \"ubvvw\" and \"ubvww\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\ns consist of lowercase English letters and '?'.", + "tags": [ + "String" + ], + "title-slug": "replace-all-s-to-avoid-consecutive-repeating-characters" + }, + { + "leetcode-id": 1577, + "title": "Number of Ways Where Square of Number Is Equal to Product of Two Numbers", + "difficulty": 2, + "description": "Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:\n\nType 1: Triplet (i, j, k) if nums1[i]^2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.\nType 2: Triplet (i, j, k) if nums2[i]^2 == nums1[j] * nums1[k] where 0 <= i < nums2.length and 0 <= j < k < nums1.length.", + "examples": [ + "Example 1:\nInput: nums1 = [7,4], nums2 = [5,2,8,9]\nOutput: 1\nExplanation: Type 1: (1, 1, 2), nums1[1]^2 = nums2[1] * nums2[2]. (4^2 = 2 * 8).", + "Example 2:\nInput: nums1 = [1,1], nums2 = [1,1,1]\nOutput: 9\nExplanation: All Triplets are valid, because 1^2 = 1 * 1.\nType 1: (0,0,1), (0,0,2), (0,1,2), (1,0,1), (1,0,2), (1,1,2). nums1[i]^2 = nums2[j] * nums2[k].\nType 2: (0,0,1), (1,0,1), (2,0,1). nums2[i]^2 = nums1[j] * nums1[k].", + "Example 3:\nInput: nums1 = [7,7,8,3], nums2 = [1,2,9,7]\nOutput: 2\nExplanation: There are 2 valid triplets.\nType 1: (3,0,2). nums1[3]^2 = nums2[0] * nums2[2].\nType 2: (3,0,1). nums2[3]^2 = nums1[0] * nums1[1]." + ], + "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 1000\n1 <= nums1[i], nums2[i] <= 10^5", + "tags": [ + "Array", + "Hash Table", + "Math", + "Two Pointers" + ], + "title-slug": "number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers" + }, + { + "leetcode-id": 1578, + "title": "Minimum Time to Make Rope Colorful", + "difficulty": 2, + "description": "Alice has n balloons arranged on a rope. You are given a 0-indexed string colors where colors[i] is the color of the i^th balloon.\nAlice wants the rope to be colorful. She does not want two consecutive balloons to be of the same color, so she asks Bob for help. Bob can remove some balloons from the rope to make it colorful. You are given a 0-indexed integer array neededTime where neededTime[i] is the time (in seconds) that Bob needs to remove the i^th balloon from the rope.\nReturn the minimum time Bob needs to make the rope colorful.", + "examples": [ + "Example 1:\nInput: colors = \"abaac\", neededTime = [1,2,3,4,5]\nOutput: 3\nExplanation: In the above image, 'a' is blue, 'b' is red, and 'c' is green.\nBob can remove the blue balloon at index 2. This takes 3 seconds.\nThere are no longer two consecutive balloons of the same color. Total time = 3.", + "Example 2:\nInput: colors = \"abc\", neededTime = [1,2,3]\nOutput: 0\nExplanation: The rope is already colorful. Bob does not need to remove any balloons from the rope.", + "Example 3:\nInput: colors = \"aabaa\", neededTime = [1,2,3,4,1]\nOutput: 2\nExplanation: Bob will remove the ballons at indices 0 and 4. Each ballon takes 1 second to remove.\nThere are no longer two consecutive balloons of the same color. Total time = 1 + 1 = 2." + ], + "constraints": "Constraints:\n\nn == colors.length == neededTime.length\n1 <= n <= 10^5\n1 <= neededTime[i] <= 10^4\ncolors contains only lowercase English letters.", + "tags": [ + "Array", + "String", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "minimum-time-to-make-rope-colorful" + }, + { + "leetcode-id": 1579, + "title": "Remove Max Number of Edges to Keep Graph Fully Traversable", + "difficulty": 3, + "description": "Alice and Bob have an undirected graph of n nodes and three types of edges:\n\nType 1: Can be traversed by Alice only.\nType 2: Can be traversed by Bob only.\nType 3: Can be traversed by both Alice and Bob.\n\nGiven an array edges where edges[i] = [typei, ui, vi] represents a bidirectional edge of type typei between nodes ui and vi, find the maximum number of edges you can remove so that after removing the edges, the graph can still be fully traversed by both Alice and Bob. The graph is fully traversed by Alice and Bob if starting from any node, they can reach all other nodes.\nReturn the maximum number of edges you can remove, or return -1 if Alice and Bob cannot fully traverse the graph.", + "examples": [ + "Example 1:\nInput: n = 4, edges = [[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]]\nOutput: 2\nExplanation: If we remove the 2 edges [1,1,2] and [1,1,3]. The graph will still be fully traversable by Alice and Bob. Removing any additional edge will not make it so. So the maximum number of edges we can remove is 2.", + "Example 2:\nInput: n = 4, edges = [[3,1,2],[3,2,3],[1,1,4],[2,1,4]]\nOutput: 0\nExplanation: Notice that removing any edge will not make the graph fully traversable by Alice and Bob.", + "Example 3:\nInput: n = 4, edges = [[3,2,3],[1,1,2],[2,3,4]]\nOutput: -1\nExplanation: In the current graph, Alice cannot reach node 4 from the other nodes. Likewise, Bob cannot reach 1. Therefore it's impossible to make the graph fully traversable." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5\n1 <= edges.length <= min(10^5, 3 * n * (n - 1) / 2)\nedges[i].length == 3\n1 <= typei <= 3\n1 <= ui < vi <= n\nAll tuples (typei, ui, vi) are distinct.", + "tags": [ + "Union Find", + "Graph" + ], + "title-slug": "remove-max-number-of-edges-to-keep-graph-fully-traversable" + }, + { + "leetcode-id": 1582, + "title": "Special Positions in a Binary Matrix", + "difficulty": 1, + "description": "Given an m x n binary matrix mat, return the number of special positions in mat.\nA position (i, j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed).", + "examples": [ + "Example 1:\nInput: mat = [[1,0,0],[0,0,1],[1,0,0]]\nOutput: 1\nExplanation: (1, 2) is a special position because mat[1][2] == 1 and all other elements in row 1 and column 2 are 0.", + "Example 2:\nInput: mat = [[1,0,0],[0,1,0],[0,0,1]]\nOutput: 3\nExplanation: (0, 0), (1, 1) and (2, 2) are special positions." + ], + "constraints": "Constraints:\n\nm == mat.length\nn == mat[i].length\n1 <= m, n <= 100\nmat[i][j] is either 0 or 1.", + "tags": [ + "Array", + "Matrix" + ], + "title-slug": "special-positions-in-a-binary-matrix" + }, + { + "leetcode-id": 1583, + "title": "Count Unhappy Friends", + "difficulty": 2, + "description": "You are given a list of\u00a0preferences\u00a0for\u00a0n\u00a0friends, where n is always even.\nFor each person i,\u00a0preferences[i]\u00a0contains\u00a0a list of friends\u00a0sorted in the order of preference. In other words, a friend earlier in the list is more preferred than a friend later in the list.\u00a0Friends in\u00a0each list are\u00a0denoted by integers from 0 to n-1.\nAll the friends are divided into pairs.\u00a0The pairings are\u00a0given in a list\u00a0pairs,\u00a0where pairs[i] = [xi, yi] denotes xi\u00a0is paired with yi and yi is paired with xi.\nHowever, this pairing may cause some of the friends to be unhappy.\u00a0A friend x\u00a0is unhappy if x\u00a0is paired with y\u00a0and there exists a friend u\u00a0who\u00a0is paired with v\u00a0but:\n\nx\u00a0prefers u\u00a0over y,\u00a0and\nu\u00a0prefers x\u00a0over v.\n\nReturn the number of unhappy friends.", + "examples": [ + "Example 1:\nInput: n = 4, preferences = [[1, 2, 3], [3, 2, 0], [3, 1, 0], [1, 2, 0]], pairs = [[0, 1], [2, 3]]\nOutput: 2\nExplanation:\nFriend 1 is unhappy because:\n- 1 is paired with 0 but prefers 3 over 0, and\n- 3 prefers 1 over 2.\nFriend 3 is unhappy because:\n- 3 is paired with 2 but prefers 1 over 2, and\n- 1 prefers 3 over 0.\nFriends 0 and 2 are happy.", + "Example 2:\nInput: n = 2, preferences = [[1], [0]], pairs = [[1, 0]]\nOutput: 0\nExplanation: Both friends 0 and 1 are happy.", + "Example 3:\nInput: n = 4, preferences = [[1, 3, 2], [2, 3, 0], [1, 3, 0], [0, 2, 1]], pairs = [[1, 3], [0, 2]]\nOutput: 4" + ], + "constraints": "Constraints:\n\n2 <= n <= 500\nn\u00a0is even.\npreferences.length\u00a0== n\npreferences[i].length\u00a0== n - 1\n0 <= preferences[i][j] <= n - 1\npreferences[i]\u00a0does not contain i.\nAll values in\u00a0preferences[i]\u00a0are unique.\npairs.length\u00a0== n/2\npairs[i].length\u00a0== 2\nxi != yi\n0 <= xi, yi\u00a0<= n - 1\nEach person is contained in exactly one pair.", + "tags": [ + "Array", + "Simulation" + ], + "title-slug": "count-unhappy-friends" + }, + { + "leetcode-id": 1584, + "title": "Min Cost to Connect All Points", + "difficulty": 2, + "description": "You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].\nThe cost of connecting two points [xi, yi] and [xj, yj] is the manhattan distance between them: |xi - xj| + |yi - yj|, where |val| denotes the absolute value of val.\nReturn the minimum cost to make all points connected. All points are connected if there is exactly one simple path between any two points.", + "examples": [ + "Example 1:\nInput: points = [[0,0],[2,2],[3,10],[5,2],[7,0]]\nOutput: 20\nExplanation: \n\nWe can connect the points as shown above to get the minimum cost of 20.\nNotice that there is a unique path between every pair of points.", + "Example 2:\nInput: points = [[3,12],[-2,5],[-4,1]]\nOutput: 18" + ], + "constraints": "Constraints:\n\n1 <= points.length <= 1000\n-10^6 <= xi, yi <= 10^6\nAll pairs (xi, yi) are distinct.", + "tags": [ + "Array", + "Union Find", + "Graph", + "Minimum Spanning Tree" + ], + "title-slug": "min-cost-to-connect-all-points" + }, + { + "leetcode-id": 1585, + "title": "Check If String Is Transformable With Substring Sort Operations", + "difficulty": 3, + "description": "Given two strings s and t, transform string s into string t using the following operation any number of times:\n\nChoose a non-empty substring in s and sort it in place so the characters are in ascending order.\n\n\t\nFor example, applying the operation on the underlined substring in \"14234\" results in \"12344\".\n\n\n\nReturn true if it is possible to transform s into t. Otherwise, return false.\nA substring is a contiguous sequence of characters within a string.", + "examples": [ + "Example 1:\nInput: s = \"84532\", t = \"34852\"\nOutput: true\nExplanation: You can transform s into t using the following sort operations:\n\"84532\" (from index 2 to 3) -> \"84352\"\n\"84352\" (from index 0 to 2) -> \"34852\"", + "Example 2:\nInput: s = \"34521\", t = \"23415\"\nOutput: true\nExplanation: You can transform s into t using the following sort operations:\n\"34521\" -> \"23451\"\n\"23451\" -> \"23415\"", + "Example 3:\nInput: s = \"12345\", t = \"12435\"\nOutput: false" + ], + "constraints": "Constraints:\n\ns.length == t.length\n1 <= s.length <= 10^5\ns and t consist of only digits.", + "tags": [ + "String", + "Greedy", + "Sorting" + ], + "title-slug": "check-if-string-is-transformable-with-substring-sort-operations" + }, + { + "leetcode-id": 1588, + "title": "Sum of All Odd Length Subarrays", + "difficulty": 1, + "description": "Given an array of positive integers arr, return the sum of all possible odd-length subarrays of arr.\nA subarray is a contiguous subsequence of the array.", + "examples": [ + "Example 1:\nInput: arr = [1,4,2,5,3]\nOutput: 58\nExplanation: The odd-length subarrays of arr and their sums are:\n[1] = 1\n[4] = 4\n[2] = 2\n[5] = 5\n[3] = 3\n[1,4,2] = 7\n[4,2,5] = 11\n[2,5,3] = 10\n[1,4,2,5,3] = 15\nIf we add all these together we get 1 + 4 + 2 + 5 + 3 + 7 + 11 + 10 + 15 = 58", + "Example 2:\nInput: arr = [1,2]\nOutput: 3\nExplanation: There are only 2 subarrays of odd length, [1] and [2]. Their sum is 3.", + "Example 3:\nInput: arr = [10,11,12]\nOutput: 66" + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 100\n1 <= arr[i] <= 1000\n\n\u00a0\nFollow up:\nCould you solve this problem in O(n) time complexity?", + "tags": [ + "Array", + "Math", + "Prefix Sum" + ], + "title-slug": "sum-of-all-odd-length-subarrays" + }, + { + "leetcode-id": 1589, + "title": "Maximum Sum Obtained of Any Permutation", + "difficulty": 2, + "description": "We have an array of integers, nums, and an array of requests where requests[i] = [starti, endi]. The i^th request asks for the sum of nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi]. Both starti and endi are 0-indexed.\nReturn the maximum total sum of all requests among all permutations of nums.\nSince the answer may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4,5], requests = [[1,3],[0,1]]\nOutput: 19\nExplanation: One permutation of nums is [2,1,3,4,5] with the following result: \nrequests[0] -> nums[1] + nums[2] + nums[3] = 1 + 3 + 4 = 8\nrequests[1] -> nums[0] + nums[1] = 2 + 1 = 3\nTotal sum: 8 + 3 = 11.\nA permutation with a higher total sum is [3,5,4,2,1] with the following result:\nrequests[0] -> nums[1] + nums[2] + nums[3] = 5 + 4 + 2 = 11\nrequests[1] -> nums[0] + nums[1] = 3 + 5 = 8\nTotal sum: 11 + 8 = 19, which is the best that you can do.", + "Example 2:\nInput: nums = [1,2,3,4,5,6], requests = [[0,1]]\nOutput: 11\nExplanation: A permutation with the max total sum is [6,5,4,3,2,1] with request sums [11].", + "Example 3:\nInput: nums = [1,2,3,4,5,10], requests = [[0,2],[1,3],[1,1]]\nOutput: 47\nExplanation: A permutation with the max total sum is [4,10,5,3,2,1] with request sums [19,18,10]." + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^5\n0 <= nums[i]\u00a0<= 10^5\n1 <= requests.length <=\u00a010^5\nrequests[i].length == 2\n0 <= starti\u00a0<= endi\u00a0<\u00a0n", + "tags": [ + "Array", + "Greedy", + "Sorting", + "Prefix Sum" + ], + "title-slug": "maximum-sum-obtained-of-any-permutation" + }, + { + "leetcode-id": 1590, + "title": "Make Sum Divisible by P", + "difficulty": 2, + "description": "Given an array of positive integers nums, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible by p. It is not allowed to remove the whole array.\nReturn the length of the smallest subarray that you need to remove, or -1 if it's impossible.\nA subarray is defined as a contiguous block of elements in the array.", + "examples": [ + "Example 1:\nInput: nums = [3,1,4,2], p = 6\nOutput: 1\nExplanation: The sum of the elements in nums is 10, which is not divisible by 6. We can remove the subarray [4], and the sum of the remaining elements is 6, which is divisible by 6.", + "Example 2:\nInput: nums = [6,3,5,2], p = 9\nOutput: 2\nExplanation: We cannot remove a single element to get a sum divisible by 9. The best way is to remove the subarray [5,2], leaving us with [6,3] with sum 9.", + "Example 3:\nInput: nums = [1,2,3], p = 3\nOutput: 0\nExplanation: Here the sum is 6. which is already divisible by 3. Thus we do not need to remove anything." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\n1 <= p <= 10^9", + "tags": [ + "Array", + "Hash Table", + "Prefix Sum" + ], + "title-slug": "make-sum-divisible-by-p" + }, + { + "leetcode-id": 1591, + "title": "Strange Printer II", + "difficulty": 3, + "description": "There is a strange printer with the following two special requirements:\n\nOn each turn, the printer will print a solid rectangular pattern of a single color on the grid. This will cover up the existing colors in the rectangle.\nOnce the printer has used a color for the above operation, the same color cannot be used again.\n\nYou are given a m x n matrix targetGrid, where targetGrid[row][col] is the color in the position (row, col) of the grid.\nReturn true if it is possible to print the matrix targetGrid, otherwise, return false.", + "examples": [ + "Example 1:\nInput: targetGrid = [[1,1,1,1],[1,2,2,1],[1,2,2,1],[1,1,1,1]]\nOutput: true", + "Example 2:\nInput: targetGrid = [[1,1,1,1],[1,1,3,3],[1,1,3,4],[5,5,1,4]]\nOutput: true", + "Example 3:\nInput: targetGrid = [[1,2,1],[2,1,2],[1,2,1]]\nOutput: false\nExplanation: It is impossible to form targetGrid because it is not allowed to print the same color in different turns." + ], + "constraints": "Constraints:\n\nm == targetGrid.length\nn == targetGrid[i].length\n1 <= m, n <= 60\n1 <= targetGrid[row][col] <= 60", + "tags": [ + "Array", + "Graph", + "Topological Sort", + "Matrix" + ], + "title-slug": "strange-printer-ii" + }, + { + "leetcode-id": 1592, + "title": "Rearrange Spaces Between Words", + "difficulty": 1, + "description": "You are given a string text of words that are placed among some number of spaces. Each word consists of one or more lowercase English letters and are separated by at least one space. It's guaranteed that text contains at least one word.\nRearrange the spaces so that there is an equal number of spaces between every pair of adjacent words and that number is maximized. If you cannot redistribute all the spaces equally, place the extra spaces at the end, meaning the returned string should be the same length as text.\nReturn the string after rearranging the spaces.", + "examples": [ + "Example 1:\nInput: text = \" this is a sentence \"\nOutput: \"this is a sentence\"\nExplanation: There are a total of 9 spaces and 4 words. We can evenly divide the 9 spaces between the words: 9 / (4-1) = 3 spaces.", + "Example 2:\nInput: text = \" practice makes perfect\"\nOutput: \"practice makes perfect \"\nExplanation: There are a total of 7 spaces and 3 words. 7 / (3-1) = 3 spaces plus 1 extra space. We place this extra space at the end of the string." + ], + "constraints": "Constraints:\n\n1 <= text.length <= 100\ntext consists of lowercase English letters and ' '.\ntext contains at least one word.", + "tags": [ + "String" + ], + "title-slug": "rearrange-spaces-between-words" + }, + { + "leetcode-id": 1593, + "title": "Split a String Into the Max Number of Unique Substrings", + "difficulty": 2, + "description": "Given a string\u00a0s,\u00a0return the maximum\u00a0number of unique substrings that the given string can be split into.\nYou can split string\u00a0s into any list of\u00a0non-empty substrings, where the concatenation of the substrings forms the original string.\u00a0However, you must split the substrings such that all of them are unique.\nA substring is a contiguous sequence of characters within a string.", + "examples": [ + "Example 1:\nInput: s = \"ababccc\"\nOutput: 5\nExplanation: One way to split maximally is ['a', 'b', 'ab', 'c', 'cc']. Splitting like ['a', 'b', 'a', 'b', 'c', 'cc'] is not valid as you have 'a' and 'b' multiple times.", + "Example 2:\nInput: s = \"aba\"\nOutput: 2\nExplanation: One way to split maximally is ['a', 'ba'].", + "Example 3:\nInput: s = \"aa\"\nOutput: 1\nExplanation: It is impossible to split the string any further." + ], + "constraints": "Constraints:\n\n\n1 <= s.length\u00a0<= 16\n\n\ns contains\u00a0only lower case English letters.", + "tags": [ + "Hash Table", + "String", + "Backtracking" + ], + "title-slug": "split-a-string-into-the-max-number-of-unique-substrings" + }, + { + "leetcode-id": 1594, + "title": "Maximum Non Negative Product in a Matrix", + "difficulty": 2, + "description": "You are given a m x n matrix grid. Initially, you are located at the top-left corner (0, 0), and in each step, you can only move right or down in the matrix.\nAmong all possible paths starting from the top-left corner (0, 0) and ending in the bottom-right corner (m - 1, n - 1), find the path with the maximum non-negative product. The product of a path is the product of all integers in the grid cells visited along the path.\nReturn the maximum non-negative product modulo 10^9 + 7. If the maximum product is negative, return -1.\nNotice that the modulo is performed after getting the maximum product.", + "examples": [ + "Example 1:\nInput: grid = [[-1,-2,-3],[-2,-3,-3],[-3,-3,-2]]\nOutput: -1\nExplanation: It is not possible to get non-negative product in the path from (0, 0) to (2, 2), so return -1.", + "Example 2:\nInput: grid = [[1,-2,1],[1,-2,1],[3,-4,1]]\nOutput: 8\nExplanation: Maximum non-negative product is shown (1 * 1 * -2 * -4 * 1 = 8).", + "Example 3:\nInput: grid = [[1,3],[0,-4]]\nOutput: 0\nExplanation: Maximum non-negative product is shown (1 * 0 * -4 = 0)." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 15\n-4 <= grid[i][j] <= 4", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "maximum-non-negative-product-in-a-matrix" + }, + { + "leetcode-id": 1595, + "title": "Minimum Cost to Connect Two Groups of Points", + "difficulty": 3, + "description": "You are given two groups of points where the first group has size1 points, the second group has size2 points, and size1 >= size2.\nThe cost of the connection between any two points are given in an size1 x size2 matrix where cost[i][j] is the cost of connecting point i of the first group and point j of the second group. The groups are connected if each point in both groups is connected to one or more points in the opposite group. In other words, each point in the first group must be connected to at least one point in the second group, and each point in the second group must be connected to at least one point in the first group.\nReturn the minimum cost it takes to connect the two groups.", + "examples": [ + "Example 1:\nInput: cost = [[15, 96], [36, 2]]\nOutput: 17\nExplanation: The optimal way of connecting the groups is:\n1--A\n2--B\nThis results in a total cost of 17.", + "Example 2:\nInput: cost = [[1, 3, 5], [4, 1, 1], [1, 5, 3]]\nOutput: 4\nExplanation: The optimal way of connecting the groups is:\n1--A\n2--B\n2--C\n3--A\nThis results in a total cost of 4.\nNote that there are multiple points connected to point 2 in the first group and point A in the second group. This does not matter as there is no limit to the number of points that can be connected. We only care about the minimum total cost.", + "Example 3:\nInput: cost = [[2, 5, 1], [3, 4, 7], [8, 1, 2], [6, 2, 4], [3, 8, 8]]\nOutput: 10" + ], + "constraints": "Constraints:\n\nsize1 == cost.length\nsize2 == cost[i].length\n1 <= size1, size2 <= 12\nsize1 >= size2\n0 <= cost[i][j] <= 100", + "tags": [ + "Array", + "Dynamic Programming", + "Bit Manipulation", + "Matrix", + "Bitmask" + ], + "title-slug": "minimum-cost-to-connect-two-groups-of-points" + }, + { + "leetcode-id": 1598, + "title": "Crawler Log Folder", + "difficulty": 1, + "description": "The Leetcode file system keeps a log each time some user performs a change folder operation.\nThe operations are described below:\n\n\"../\" : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder).\n\"./\" : Remain in the same folder.\n\"x/\" : Move to the child folder named x (This folder is guaranteed to always exist).\n\nYou are given a list of strings logs where logs[i] is the operation performed by the user at the i^th step.\nThe file system starts in the main folder, then the operations in logs are performed.\nReturn the minimum number of operations needed to go back to the main folder after the change folder operations.", + "examples": [ + "Example 1:\nInput: logs = [\"d1/\",\"d2/\",\"../\",\"d21/\",\"./\"]\nOutput: 2\nExplanation: Use this change folder operation \"../\" 2 times and go back to the main folder.", + "Example 2:\nInput: logs = [\"d1/\",\"d2/\",\"./\",\"d3/\",\"../\",\"d31/\"]\nOutput: 3", + "Example 3:\nInput: logs = [\"d1/\",\"../\",\"../\",\"../\"]\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= logs.length <= 10^3\n2 <= logs[i].length <= 10\nlogs[i] contains lowercase English letters, digits, '.', and '/'.\nlogs[i] follows the format described in the statement.\nFolder names consist of lowercase English letters and digits.", + "tags": [ + "Array", + "String", + "Stack" + ], + "title-slug": "crawler-log-folder" + }, + { + "leetcode-id": 1599, + "title": "Maximum Profit of Operating a Centennial Wheel", + "difficulty": 2, + "description": "You are the operator of a Centennial Wheel that has four gondolas, and each gondola has room for up to four people. You have the ability to rotate the gondolas counterclockwise, which costs you runningCost dollars.\nYou are given an array customers of length n where customers[i] is the number of new customers arriving just before the i^th rotation (0-indexed). This means you must rotate the wheel i times before the customers[i] customers arrive. You cannot make customers wait if there is room in the gondola. Each customer pays boardingCost dollars when they board on the gondola closest to the ground and will exit once that gondola reaches the ground again.\nYou can stop the wheel at any time, including before serving all customers. If you decide to stop serving customers, all subsequent rotations are free in order to get all the customers down safely. Note that if there are currently more than four customers waiting at the wheel, only four will board the gondola, and the rest will wait for the next rotation.\nReturn the minimum number of rotations you need to perform to maximize your profit. If there is no scenario where the profit is positive, return -1.", + "examples": [ + "Example 1:\nInput: customers = [8,3], boardingCost = 5, runningCost = 6\nOutput: 3\nExplanation: The numbers written on the gondolas are the number of people currently there.\n1. 8 customers arrive, 4 board and 4 wait for the next gondola, the wheel rotates. Current profit is 4 * $5 - 1 * $6 = $14.\n2. 3 customers arrive, the 4 waiting board the wheel and the other 3 wait, the wheel rotates. Current profit is 8 * $5 - 2 * $6 = $28.\n3. The final 3 customers board the gondola, the wheel rotates. Current profit is 11 * $5 - 3 * $6 = $37.\nThe highest profit was $37 after rotating the wheel 3 times.", + "Example 2:\nInput: customers = [10,9,6], boardingCost = 6, runningCost = 4\nOutput: 7\nExplanation:\n1. 10 customers arrive, 4 board and 6 wait for the next gondola, the wheel rotates. Current profit is 4 * $6 - 1 * $4 = $20.\n2. 9 customers arrive, 4 board and 11 wait (2 originally waiting, 9 newly waiting), the wheel rotates. Current profit is 8 * $6 - 2 * $4 = $40.\n3. The final 6 customers arrive, 4 board and 13 wait, the wheel rotates. Current profit is 12 * $6 - 3 * $4 = $60.\n4. 4 board and 9 wait, the wheel rotates. Current profit is 16 * $6 - 4 * $4 = $80.\n5. 4 board and 5 wait, the wheel rotates. Current profit is 20 * $6 - 5 * $4 = $100.\n6. 4 board and 1 waits, the wheel rotates. Current profit is 24 * $6 - 6 * $4 = $120.\n7. 1 boards, the wheel rotates. Current profit is 25 * $6 - 7 * $4 = $122.\nThe highest profit was $122 after rotating the wheel 7 times.", + "Example 3:\nInput: customers = [3,4,0,5,1], boardingCost = 1, runningCost = 92\nOutput: -1\nExplanation:\n1. 3 customers arrive, 3 board and 0 wait, the wheel rotates. Current profit is 3 * $1 - 1 * $92 = -$89.\n2. 4 customers arrive, 4 board and 0 wait, the wheel rotates. Current profit is 7 * $1 - 2 * $92 = -$177.\n3. 0 customers arrive, 0 board and 0 wait, the wheel rotates. Current profit is 7 * $1 - 3 * $92 = -$269.\n4. 5 customers arrive, 4 board and 1 waits, the wheel rotates. Current profit is 11 * $1 - 4 * $92 = -$357.\n5. 1 customer arrives, 2 board and 0 wait, the wheel rotates. Current profit is 13 * $1 - 5 * $92 = -$447.\nThe profit was never positive, so return -1." + ], + "constraints": "Constraints:\n\nn == customers.length\n1 <= n <= 10^5\n0 <= customers[i] <= 50\n1 <= boardingCost, runningCost <= 100", + "tags": [ + "Array", + "Simulation" + ], + "title-slug": "maximum-profit-of-operating-a-centennial-wheel" + }, + { + "leetcode-id": 1600, + "title": "Throne Inheritance", + "difficulty": 2, + "description": "A kingdom consists of a king, his children, his grandchildren, and so on. Every once in a while, someone in the family dies or a child is born.\nThe kingdom has a well-defined order of inheritance that consists of the king as the first member. Let's define the recursive function Successor(x, curOrder), which given a person x and the inheritance order so far, returns who should be the next person after x in the order of inheritance.\n\nSuccessor(x, curOrder):\n if x has no children or all of x's children are in curOrder:\n if x is the king return null\n else return Successor(x's parent, curOrder)\n else return x's oldest child who's not in curOrder\n\nFor example, assume we have a kingdom that consists of the king, his children Alice and Bob (Alice is older than Bob), and finally Alice's son Jack.\n\nIn the beginning, curOrder will be [\"king\"].\nCalling Successor(king, curOrder) will return Alice, so we append to curOrder to get [\"king\", \"Alice\"].\nCalling Successor(Alice, curOrder) will return Jack, so we append to curOrder to get [\"king\", \"Alice\", \"Jack\"].\nCalling Successor(Jack, curOrder) will return Bob, so we append to curOrder to get [\"king\", \"Alice\", \"Jack\", \"Bob\"].\nCalling Successor(Bob, curOrder) will return null. Thus the order of inheritance will be [\"king\", \"Alice\", \"Jack\", \"Bob\"].\n\nUsing the above function, we can always obtain a unique order of inheritance.\nImplement the ThroneInheritance class:\n\nThroneInheritance(string kingName) Initializes an object of the ThroneInheritance class. The name of the king is given as part of the constructor.\nvoid birth(string parentName, string childName) Indicates that parentName gave birth to childName.\nvoid death(string name) Indicates the death of name. The death of the person doesn't affect the Successor function nor the current inheritance order. You can treat it as just marking the person as dead.\nstring[] getInheritanceOrder() Returns a list representing the current order of inheritance excluding dead people.", + "examples": [ + "Example 1:\nInput\n[\"ThroneInheritance\", \"birth\", \"birth\", \"birth\", \"birth\", \"birth\", \"birth\", \"getInheritanceOrder\", \"death\", \"getInheritanceOrder\"]\n[[\"king\"], [\"king\", \"andy\"], [\"king\", \"bob\"], [\"king\", \"catherine\"], [\"andy\", \"matthew\"], [\"bob\", \"alex\"], [\"bob\", \"asha\"], [null], [\"bob\"], [null]]\nOutput\n[null, null, null, null, null, null, null, [\"king\", \"andy\", \"matthew\", \"bob\", \"alex\", \"asha\", \"catherine\"], null, [\"king\", \"andy\", \"matthew\", \"alex\", \"asha\", \"catherine\"]]\n\nExplanation\nThroneInheritance t= new ThroneInheritance(\"king\"); // order: king\nt.birth(\"king\", \"andy\"); // order: king > andy\nt.birth(\"king\", \"bob\"); // order: king > andy > bob\nt.birth(\"king\", \"catherine\"); // order: king > andy > bob > catherine\nt.birth(\"andy\", \"matthew\"); // order: king > andy > matthew > bob > catherine\nt.birth(\"bob\", \"alex\"); // order: king > andy > matthew > bob > alex > catherine\nt.birth(\"bob\", \"asha\"); // order: king > andy > matthew > bob > alex > asha > catherine\nt.getInheritanceOrder(); // return [\"king\", \"andy\", \"matthew\", \"bob\", \"alex\", \"asha\", \"catherine\"]\nt.death(\"bob\"); // order: king > andy > matthew > bob > alex > asha > catherine\nt.getInheritanceOrder(); // return [\"king\", \"andy\", \"matthew\", \"alex\", \"asha\", \"catherine\"]" + ], + "constraints": "Constraints:\n\n1 <= kingName.length, parentName.length, childName.length, name.length <= 15\nkingName, parentName, childName, and name consist of lowercase English letters only.\nAll arguments childName and kingName are distinct.\nAll name arguments of death will be passed to either the constructor or as childName to birth first.\nFor each call to\u00a0birth(parentName, childName), it is guaranteed that\u00a0parentName is alive.\nAt most 10^5 calls will be made to birth and death.\nAt most 10 calls will be made to getInheritanceOrder.", + "tags": [ + "Hash Table", + "Tree", + "Depth-First Search", + "Design" + ], + "title-slug": "throne-inheritance" + }, + { + "leetcode-id": 1601, + "title": "Maximum Number of Achievable Transfer Requests", + "difficulty": 3, + "description": "We have n buildings numbered from 0 to n - 1. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.\nYou are given an array requests where requests[i] = [fromi, toi] represents an employee's request to transfer from building fromi to building toi.\nAll buildings are full, so a list of requests is achievable only if for each building, the net change in employee transfers is zero. This means the number of employees leaving is equal to the number of employees moving in. For example if n = 3 and two employees are leaving building 0, one is leaving building 1, and one is leaving building 2, there should be two employees moving to building 0, one employee moving to building 1, and one employee moving to building 2.\nReturn the maximum number of achievable requests.", + "examples": [ + "Example 1:\nInput: n = 5, requests = [[0,1],[1,0],[0,1],[1,2],[2,0],[3,4]]\nOutput: 5\nExplantion: Let's see the requests:\nFrom building 0 we have employees x and y and both want to move to building 1.\nFrom building 1 we have employees a and b and they want to move to buildings 2 and 0 respectively.\nFrom building 2 we have employee z and they want to move to building 0.\nFrom building 3 we have employee c and they want to move to building 4.\nFrom building 4 we don't have any requests.\nWe can achieve the requests of users x and b by swapping their places.\nWe can achieve the requests of users y, a and z by swapping the places in the 3 buildings.", + "Example 2:\nInput: n = 3, requests = [[0,0],[1,2],[2,1]]\nOutput: 3\nExplantion: Let's see the requests:\nFrom building 0 we have employee x and they want to stay in the same building 0.\nFrom building 1 we have employee y and they want to move to building 2.\nFrom building 2 we have employee z and they want to move to building 1.\nWe can achieve all the requests.", + "Example 3:\nInput: n = 4, requests = [[0,3],[3,1],[1,2],[2,0]]\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= n <= 20\n1 <= requests.length <= 16\nrequests[i].length == 2\n0 <= fromi, toi < n", + "tags": [ + "Array", + "Backtracking", + "Bit Manipulation", + "Enumeration" + ], + "title-slug": "maximum-number-of-achievable-transfer-requests" + }, + { + "leetcode-id": 1603, + "title": "Design Parking System", + "difficulty": 1, + "description": "Design a parking system for a parking lot. The parking lot has three kinds of parking spaces: big, medium, and small, with a fixed number of slots for each size.\nImplement the ParkingSystem class:\n\nParkingSystem(int big, int medium, int small) Initializes object of the ParkingSystem class. The number of slots for each parking space are given as part of the constructor.\nbool addCar(int carType) Checks whether there is a parking space of carType for the car that wants to get into the parking lot. carType can be of three kinds: big, medium, or small, which are represented by 1, 2, and 3 respectively. A car can only park in a parking space of its carType. If there is no space available, return false, else park the car in that size space and return true.", + "examples": [ + "Example 1:\nInput\n[\"ParkingSystem\", \"addCar\", \"addCar\", \"addCar\", \"addCar\"]\n[[1, 1, 0], [1], [2], [3], [1]]\nOutput\n[null, true, true, false, false]\n\nExplanation\nParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);\nparkingSystem.addCar(1); // return true because there is 1 available slot for a big car\nparkingSystem.addCar(2); // return true because there is 1 available slot for a medium car\nparkingSystem.addCar(3); // return false because there is no available slot for a small car\nparkingSystem.addCar(1); // return false because there is no available slot for a big car. It is already occupied." + ], + "constraints": "Constraints:\n\n0 <= big, medium, small <= 1000\ncarType is 1, 2, or 3\nAt most 1000 calls will be made to addCar", + "tags": [ + "Design", + "Simulation", + "Counting" + ], + "title-slug": "design-parking-system" + }, + { + "leetcode-id": 1604, + "title": "Alert Using Same Key-Card Three or More Times in a One Hour Period", + "difficulty": 2, + "description": "LeetCode company workers use key-cards to unlock office doors. Each time a worker uses their key-card, the security system saves the worker's name and the time when it was used. The system emits an alert if any worker uses the key-card three or more times in a one-hour period.\nYou are given a list of strings keyName and keyTime where [keyName[i], keyTime[i]] corresponds to a person's name and the time when their key-card was used in a single day.\nAccess times are given in the 24-hour time format \"HH:MM\", such as \"23:51\" and \"09:49\".\nReturn a list of unique worker names who received an alert for frequent keycard use. Sort the names in ascending order alphabetically.\nNotice that \"10:00\" - \"11:00\" is considered to be within a one-hour period, while \"22:51\" - \"23:52\" is not considered to be within a one-hour period.", + "examples": [ + "Example 1:\nInput: keyName = [\"daniel\",\"daniel\",\"daniel\",\"luis\",\"luis\",\"luis\",\"luis\"], keyTime = [\"10:00\",\"10:40\",\"11:00\",\"09:00\",\"11:00\",\"13:00\",\"15:00\"]\nOutput: [\"daniel\"]\nExplanation: \"daniel\" used the keycard 3 times in a one-hour period (\"10:00\",\"10:40\", \"11:00\").", + "Example 2:\nInput: keyName = [\"alice\",\"alice\",\"alice\",\"bob\",\"bob\",\"bob\",\"bob\"], keyTime = [\"12:01\",\"12:00\",\"18:00\",\"21:00\",\"21:20\",\"21:30\",\"23:00\"]\nOutput: [\"bob\"]\nExplanation: \"bob\" used the keycard 3 times in a one-hour period (\"21:00\",\"21:20\", \"21:30\")." + ], + "constraints": "Constraints:\n\n1 <= keyName.length, keyTime.length <= 10^5\nkeyName.length == keyTime.length\nkeyTime[i] is in the format \"HH:MM\".\n[keyName[i], keyTime[i]] is unique.\n1 <= keyName[i].length <= 10\nkeyName[i] contains only lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Sorting" + ], + "title-slug": "alert-using-same-key-card-three-or-more-times-in-a-one-hour-period" + }, + { + "leetcode-id": 1605, + "title": "Find Valid Matrix Given Row and Column Sums", + "difficulty": 2, + "description": "You are given two arrays rowSum and colSum of non-negative integers where rowSum[i] is the sum of the elements in the i^th row and colSum[j] is the sum of the elements of the j^th column of a 2D matrix. In other words, you do not know the elements of the matrix, but you do know the sums of each row and column.\nFind any matrix of non-negative integers of size rowSum.length x colSum.length that satisfies the rowSum and colSum requirements.\nReturn a 2D array representing any matrix that fulfills the requirements. It's guaranteed that at least one matrix that fulfills the requirements exists.", + "examples": [ + "Example 1:\nInput: rowSum = [3,8], colSum = [4,7]\nOutput: [[3,0],\n [1,7]]\nExplanation: \n0^th row: 3 + 0 = 3 == rowSum[0]\n1^st row: 1 + 7 = 8 == rowSum[1]\n0^th column: 3 + 1 = 4 == colSum[0]\n1^st column: 0 + 7 = 7 == colSum[1]\nThe row and column sums match, and all matrix elements are non-negative.\nAnother possible matrix is: [[1,2],\n [3,5]]", + "Example 2:\nInput: rowSum = [5,7,10], colSum = [8,6,8]\nOutput: [[0,5,0],\n [6,1,0],\n [2,0,8]]" + ], + "constraints": "Constraints:\n\n1 <= rowSum.length, colSum.length <= 500\n0 <= rowSum[i], colSum[i] <= 10^8\nsum(rowSum) == sum(colSum)", + "tags": [ + "Array", + "Greedy", + "Matrix" + ], + "title-slug": "find-valid-matrix-given-row-and-column-sums" + }, + { + "leetcode-id": 1606, + "title": "Find Servers That Handled Most Number of Requests", + "difficulty": 3, + "description": "You have k servers numbered from 0 to k-1 that are being used to handle multiple requests simultaneously. Each server has infinite computational capacity but cannot handle more than one request at a time. The requests are assigned to servers according to a specific algorithm:\n\nThe i^th (0-indexed) request arrives.\nIf all servers are busy, the request is dropped (not handled at all).\nIf the (i % k)^th server is available, assign the request to that server.\nOtherwise, assign the request to the next available server (wrapping around the list of servers and starting from 0 if necessary). For example, if the i^th server is busy, try to assign the request to the (i+1)^th server, then the (i+2)^th server, and so on.\n\nYou are given a strictly increasing array arrival of positive integers, where arrival[i] represents the arrival time of the i^th request, and another array load, where load[i] represents the load of the i^th request (the time it takes to complete). Your goal is to find the busiest server(s). A server is considered busiest if it handled the most number of requests successfully among all the servers.\nReturn a list containing the IDs (0-indexed) of the busiest server(s). You may return the IDs in any order.", + "examples": [ + "Example 1:\nInput: k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3] \nOutput: [1] \nExplanation: \nAll of the servers start out available.\nThe first 3 requests are handled by the first 3 servers in order.\nRequest 3 comes in. Server 0 is busy, so it's assigned to the next available server, which is 1.\nRequest 4 comes in. It cannot be handled since all servers are busy, so it is dropped.\nServers 0 and 2 handled one request each, while server 1 handled two requests. Hence server 1 is the busiest server.", + "Example 2:\nInput: k = 3, arrival = [1,2,3,4], load = [1,2,1,2]\nOutput: [0]\nExplanation: \nThe first 3 requests are handled by first 3 servers.\nRequest 3 comes in. It is handled by server 0 since the server is available.\nServer 0 handled two requests, while servers 1 and 2 handled one request each. Hence server 0 is the busiest server.", + "Example 3:\nInput: k = 3, arrival = [1,2,3], load = [10,12,11]\nOutput: [0,1,2]\nExplanation: Each server handles a single request, so they are all considered the busiest." + ], + "constraints": "Constraints:\n\n1 <= k <= 10^5\n1 <= arrival.length, load.length <= 10^5\narrival.length == load.length\n1 <= arrival[i], load[i] <= 10^9\narrival is strictly increasing.", + "tags": [ + "Array", + "Greedy", + "Heap (Priority Queue)", + "Ordered Set" + ], + "title-slug": "find-servers-that-handled-most-number-of-requests" + }, + { + "leetcode-id": 1608, + "title": "Special Array With X Elements Greater Than or Equal X", + "difficulty": 1, + "description": "You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x.\nNotice that x does not have to be an element in nums.\nReturn x if the array is special, otherwise, return -1. It can be proven that if nums is special, the value for x is unique.", + "examples": [ + "Example 1:\nInput: nums = [3,5]\nOutput: 2\nExplanation: There are 2 values (3 and 5) that are greater than or equal to 2.", + "Example 2:\nInput: nums = [0,0]\nOutput: -1\nExplanation: No numbers fit the criteria for x.\nIf x = 0, there should be 0 numbers >= x, but there are 2.\nIf x = 1, there should be 1 number >= x, but there are 0.\nIf x = 2, there should be 2 numbers >= x, but there are 0.\nx cannot be greater since there are only 2 numbers in nums.", + "Example 3:\nInput: nums = [0,4,3,0,4]\nOutput: 3\nExplanation: There are 3 values that are greater than or equal to 3." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n0 <= nums[i] <= 1000", + "tags": [ + "Array", + "Binary Search", + "Sorting" + ], + "title-slug": "special-array-with-x-elements-greater-than-or-equal-x" + }, + { + "leetcode-id": 1609, + "title": "Even Odd Tree", + "difficulty": 2, + "description": "A binary tree is named Even-Odd if it meets the following conditions:\n\nThe root of the binary tree is at level index 0, its children are at level index 1, their children are at level index 2, etc.\nFor every even-indexed level, all nodes at the level have odd integer values in strictly increasing order (from left to right).\nFor every odd-indexed level, all nodes at the level have even integer values in strictly decreasing order (from left to right).\n\nGiven the root of a binary tree, return true if the binary tree is Even-Odd, otherwise return false.", + "examples": [ + "Example 1:\nInput: root = [1,10,4,3,null,7,9,12,8,6,null,null,2]\nOutput: true\nExplanation: The node values on each level are:\nLevel 0: [1]\nLevel 1: [10,4]\nLevel 2: [3,7,9]\nLevel 3: [12,8,6,2]\nSince levels 0 and 2 are all odd and increasing and levels 1 and 3 are all even and decreasing, the tree is Even-Odd.", + "Example 2:\nInput: root = [5,4,2,3,3,7]\nOutput: false\nExplanation: The node values on each level are:\nLevel 0: [5]\nLevel 1: [4,2]\nLevel 2: [3,3,7]\nNode values in level 2 must be in strictly increasing order, so the tree is not Even-Odd.", + "Example 3:\nInput: root = [5,9,1,3,5,7]\nOutput: false\nExplanation: Node values in the level 1 should be even integers." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^5].\n1 <= Node.val <= 10^6", + "tags": [ + "Tree", + "Breadth-First Search", + "Binary Tree" + ], + "title-slug": "even-odd-tree" + }, + { + "leetcode-id": 1610, + "title": "Maximum Number of Visible Points", + "difficulty": 3, + "description": "You are given an array points, an integer angle, and your location, where location = [posx, posy] and points[i] = [xi, yi] both denote integral coordinates on the X-Y plane.\nInitially, you are facing directly east from your position. You cannot move from your position, but you can rotate. In other words, posx and posy cannot be changed. Your field of view in degrees is represented by angle, determining how wide you can see from any given view direction. Let d be the amount in degrees that you rotate counterclockwise. Then, your field of view is the inclusive range of angles [d - angle/2, d + angle/2].\n\nYour browser does not support the video tag or this video format.\n\nYou can see some set of points if, for each point, the angle formed by the point, your position, and the immediate east direction from your position is in your field of view.\nThere can be multiple points at one coordinate. There may be points at your location, and you can always see these points regardless of your rotation. Points do not obstruct your vision to other points.\nReturn the maximum number of points you can see.", + "examples": [ + "Example 1:\nInput: points = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1]\nOutput: 3\nExplanation: The shaded region represents your field of view. All points can be made visible in your field of view, including [3,3] even though [2,2] is in front and in the same line of sight.", + "Example 2:\nInput: points = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1]\nOutput: 4\nExplanation: All points can be made visible in your field of view, including the one at your location.", + "Example 3:\nInput: points = [[1,0],[2,1]], angle = 13, location = [1,1]\nOutput: 1\nExplanation: You can only see one of the two points, as shown above." + ], + "constraints": "Constraints:\n\n1 <= points.length <= 10^5\npoints[i].length == 2\nlocation.length == 2\n0 <= angle < 360\n0 <= posx, posy, xi, yi <= 100", + "tags": [ + "Array", + "Math", + "Geometry", + "Sliding Window", + "Sorting" + ], + "title-slug": "maximum-number-of-visible-points" + }, + { + "leetcode-id": 1611, + "title": "Minimum One Bit Operations to Make Integers Zero", + "difficulty": 3, + "description": "Given an integer n, you must transform it into 0 using the following operations any number of times:\n\nChange the rightmost (0^th) bit in the binary representation of n.\nChange the i^th bit in the binary representation of n if the (i-1)^th bit is set to 1 and the (i-2)^th through 0^th bits are set to 0.\n\nReturn the minimum number of operations to transform n into 0.", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: 2\nExplanation: The binary representation of 3 is \"11\".\n\"11\" -> \"01\" with the 2^nd operation since the 0^th bit is 1.\n\"01\" -> \"00\" with the 1^st operation.", + "Example 2:\nInput: n = 6\nOutput: 4\nExplanation: The binary representation of 6 is \"110\".\n\"110\" -> \"010\" with the 2^nd operation since the 1^st bit is 1 and 0^th through 0^th bits are 0.\n\"010\" -> \"011\" with the 1^st operation.\n\"011\" -> \"001\" with the 2^nd operation since the 0^th bit is 1.\n\"001\" -> \"000\" with the 1^st operation." + ], + "constraints": "Constraints:\n\n0 <= n <= 10^9", + "tags": [ + "Dynamic Programming", + "Bit Manipulation", + "Memoization" + ], + "title-slug": "minimum-one-bit-operations-to-make-integers-zero" + }, + { + "leetcode-id": 1614, + "title": "Maximum Nesting Depth of the Parentheses", + "difficulty": 1, + "description": "A string is a valid parentheses string (denoted VPS) if it meets one of the following:\n\nIt is an empty string \"\", or a single character not equal to \"(\" or \")\",\nIt can be written as AB (A concatenated with B), where A and B are VPS's, or\nIt can be written as (A), where A is a VPS.\n\nWe can similarly define the nesting depth depth(S) of any VPS S as follows:\n\ndepth(\"\") = 0\ndepth(C) = 0, where C is a string with a single character not equal to \"(\" or \")\".\ndepth(A + B) = max(depth(A), depth(B)), where A and B are VPS's.\ndepth(\"(\" + A + \")\") = 1 + depth(A), where A is a VPS.\n\nFor example, \"\", \"()()\", and \"()(()())\" are VPS's (with nesting depths 0, 1, and 2), and \")(\" and \"(()\" are not VPS's.\nGiven a VPS represented as string s, return the nesting depth of s.", + "examples": [ + "Example 1:\nInput: s = \"(1+(2*3)+((8)/4))+1\"\nOutput: 3\nExplanation: Digit 8 is inside of 3 nested parentheses in the string.", + "Example 2:\nInput: s = \"(1)+((2))+(((3)))\"\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\ns consists of digits 0-9 and characters '+', '-', '*', '/', '(', and ')'.\nIt is guaranteed that parentheses expression s is a VPS.", + "tags": [ + "String", + "Stack" + ], + "title-slug": "maximum-nesting-depth-of-the-parentheses" + }, + { + "leetcode-id": 1615, + "title": "Maximal Network Rank", + "difficulty": 2, + "description": "There is an infrastructure of n cities with some number of roads connecting these cities. Each roads[i] = [ai, bi] indicates that there is a bidirectional road between cities ai and bi.\nThe network rank of two different cities is defined as the total number of\u00a0directly connected roads to either city. If a road is directly connected to both cities, it is only counted once.\nThe maximal network rank of the infrastructure is the maximum network rank of all pairs of different cities.\nGiven the integer n and the array roads, return the maximal network rank of the entire infrastructure.", + "examples": [ + "Example 1:\nInput: n = 4, roads = [[0,1],[0,3],[1,2],[1,3]]\nOutput: 4\nExplanation: The network rank of cities 0 and 1 is 4 as there are 4 roads that are connected to either 0 or 1. The road between 0 and 1 is only counted once.", + "Example 2:\nInput: n = 5, roads = [[0,1],[0,3],[1,2],[1,3],[2,3],[2,4]]\nOutput: 5\nExplanation: There are 5 roads that are connected to cities 1 or 2.", + "Example 3:\nInput: n = 8, roads = [[0,1],[1,2],[2,3],[2,4],[5,6],[5,7]]\nOutput: 5\nExplanation: The network rank of 2 and 5 is 5. Notice that all the cities do not have to be connected." + ], + "constraints": "Constraints:\n\n2 <= n <= 100\n0 <= roads.length <= n * (n - 1) / 2\nroads[i].length == 2\n0 <= ai, bi\u00a0<= n-1\nai\u00a0!=\u00a0bi\nEach\u00a0pair of cities has at most one road connecting them.", + "tags": [ + "Graph" + ], + "title-slug": "maximal-network-rank" + }, + { + "leetcode-id": 1616, + "title": "Split Two Strings to Make Palindrome", + "difficulty": 2, + "description": "You are given two strings a and b of the same length. Choose an index and split both strings at the same index, splitting a into two strings: aprefix and asuffix where a = aprefix + asuffix, and splitting b into two strings: bprefix and bsuffix where b = bprefix + bsuffix. Check if aprefix + bsuffix or bprefix + asuffix forms a palindrome.\nWhen you split a string s into sprefix and ssuffix, either ssuffix or sprefix is allowed to be empty. For example, if s = \"abc\", then \"\" + \"abc\", \"a\" + \"bc\", \"ab\" + \"c\" , and \"abc\" + \"\" are valid splits.\nReturn true if it is possible to form a palindrome string, otherwise return false.\nNotice that\u00a0x + y denotes the concatenation of strings x and y.", + "examples": [ + "Example 1:\nInput: a = \"x\", b = \"y\"\nOutput: true\nExplaination: If either a or b are palindromes the answer is true since you can split in the following way:\naprefix = \"\", asuffix = \"x\"\nbprefix = \"\", bsuffix = \"y\"\nThen, aprefix + bsuffix = \"\" + \"y\" = \"y\", which is a palindrome.", + "Example 2:\nInput: a = \"xbdef\", b = \"xecab\"\nOutput: false", + "Example 3:\nInput: a = \"ulacfd\", b = \"jizalu\"\nOutput: true\nExplaination: Split them at index 3:\naprefix = \"ula\", asuffix = \"cfd\"\nbprefix = \"jiz\", bsuffix = \"alu\"\nThen, aprefix + bsuffix = \"ula\" + \"alu\" = \"ulaalu\", which is a palindrome." + ], + "constraints": "Constraints:\n\n1 <= a.length, b.length <= 10^5\na.length == b.length\na and b consist of lowercase English letters", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "split-two-strings-to-make-palindrome" + }, + { + "leetcode-id": 1617, + "title": "Count Subtrees With Max Distance Between Cities", + "difficulty": 3, + "description": "There are n cities numbered from 1 to n. You are given an array edges of size n-1, where edges[i] = [ui, vi] represents a bidirectional edge between cities ui and vi. There exists a unique path between each pair of cities. In other words, the cities form a tree.\nA subtree is a subset of cities where every city is reachable from every other city in the subset, where the path between each pair passes through only the cities from the subset. Two subtrees are different if there is a city in one subtree that is not present in the other.\nFor each d from 1 to n-1, find the number of subtrees in which the maximum distance between any two cities in the subtree is equal to d.\nReturn an array of size n-1 where the d^th element (1-indexed) is the number of subtrees in which the maximum distance between any two cities is equal to d.\nNotice\u00a0that\u00a0the distance between the two cities is the number of edges in the path between them.", + "examples": [ + "Example 1:\nInput: n = 4, edges = [[1,2],[2,3],[2,4]]\r\nOutput: [3,4,0]\r\nExplanation:\r\nThe subtrees with subsets {1,2}, {2,3} and {2,4} have a max distance of 1.\r\nThe subtrees with subsets {1,2,3}, {1,2,4}, {2,3,4} and {1,2,3,4} have a max distance of 2.\r\nNo subtree has two nodes where the max distance between them is 3.", + "Example 2:\nInput: n = 2, edges = [[1,2]]\r\nOutput: [1]", + "Example 3:\nInput: n = 3, edges = [[1,2],[2,3]]\r\nOutput: [2,1]" + ], + "constraints": "Constraints:\n\n2 <= n <= 15\nedges.length == n-1\nedges[i].length == 2\n1 <= ui, vi <= n\nAll pairs (ui, vi) are distinct.", + "tags": [ + "Dynamic Programming", + "Bit Manipulation", + "Tree", + "Enumeration", + "Bitmask" + ], + "title-slug": "count-subtrees-with-max-distance-between-cities" + }, + { + "leetcode-id": 1619, + "title": "Mean of Array After Removing Some Elements", + "difficulty": 1, + "description": "Given an integer array arr, return the mean of the remaining integers after removing the smallest 5% and the largest 5% of the elements.\nAnswers within 10^-5 of the actual answer will be considered accepted.", + "examples": [ + "Example 1:\nInput: arr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3]\nOutput: 2.00000\nExplanation: After erasing the minimum and the maximum values of this array, all elements are equal to 2, so the mean is 2.", + "Example 2:\nInput: arr = [6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0]\nOutput: 4.00000", + "Example 3:\nInput: arr = [6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4]\nOutput: 4.77778" + ], + "constraints": "Constraints:\n\n20 <= arr.length <= 1000\narr.length is a multiple of 20.\n0 <= arr[i] <= 10^5", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "mean-of-array-after-removing-some-elements" + }, + { + "leetcode-id": 1620, + "title": "Coordinate With Maximum Network Quality", + "difficulty": 2, + "description": "You are given an array of network towers towers, where towers[i] = [xi, yi, qi] denotes the i^th network tower with location (xi, yi) and quality factor qi. All the coordinates are integral coordinates on the X-Y plane, and the distance between the two coordinates is the Euclidean distance.\nYou are also given an integer radius where a tower is reachable if the distance is less than or equal to radius. Outside that distance, the signal becomes garbled, and the tower is not reachable.\nThe signal quality of the i^th tower at a coordinate (x, y) is calculated with the formula \u230aqi / (1 + d)\u230b, where d is the distance between the tower and the coordinate. The network quality at a coordinate is the sum of the signal qualities from all the reachable towers.\nReturn the array [cx, cy] representing the integral coordinate (cx, cy) where the network quality is maximum. If there are multiple coordinates with the same network quality, return the lexicographically minimum non-negative coordinate.\nNote:\n\nA coordinate (x1, y1) is lexicographically smaller than (x2, y2) if either:\n\n\t\nx1 < x2, or\nx1 == x2 and y1 < y2.\n\n\n\u230aval\u230b is the greatest integer less than or equal to val (the floor function).", + "examples": [ + "Example 1:\nInput: towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2\nOutput: [2,1]\nExplanation: At coordinate (2, 1) the total quality is 13.\n- Quality of 7 from (2, 1) results in \u230a7 / (1 + sqrt(0)\u230b = \u230a7\u230b = 7\n- Quality of 5 from (1, 2) results in \u230a5 / (1 + sqrt(2)\u230b = \u230a2.07\u230b = 2\n- Quality of 9 from (3, 1) results in \u230a9 / (1 + sqrt(1)\u230b = \u230a4.5\u230b = 4\nNo other coordinate has a higher network quality.", + "Example 2:\nInput: towers = [[23,11,21]], radius = 9\nOutput: [23,11]\nExplanation: Since there is only one tower, the network quality is highest right at the tower's location.", + "Example 3:\nInput: towers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2\nOutput: [1,2]\nExplanation: Coordinate (1, 2) has the highest network quality." + ], + "constraints": "Constraints:\n\n1 <= towers.length <= 50\ntowers[i].length == 3\n0 <= xi, yi, qi <= 50\n1 <= radius <= 50", + "tags": [ + "Array", + "Enumeration" + ], + "title-slug": "coordinate-with-maximum-network-quality" + }, + { + "leetcode-id": 1621, + "title": "Number of Sets of K Non-Overlapping Line Segments", + "difficulty": 2, + "description": "Given n points on a 1-D plane, where the i^th point (from 0 to n-1) is at x = i, find the number of ways we can draw exactly k non-overlapping line segments such that each segment covers two or more points. The endpoints of each segment must have integral coordinates. The k line segments do not have to cover all n points, and they are allowed to share endpoints.\nReturn the number of ways we can draw k non-overlapping line segments. Since this number can be huge, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 4, k = 2\nOutput: 5\nExplanation: The two line segments are shown in red and blue.\nThe image above shows the 5 different ways {(0,2),(2,3)}, {(0,1),(1,3)}, {(0,1),(2,3)}, {(1,2),(2,3)}, {(0,1),(1,2)}.", + "Example 2:\nInput: n = 3, k = 1\nOutput: 3\nExplanation: The 3 ways are {(0,1)}, {(0,2)}, {(1,2)}.", + "Example 3:\nInput: n = 30, k = 7\nOutput: 796297179\nExplanation: The total number of possible ways to draw 7 line segments is 3796297200. Taking this number modulo 10^9 + 7 gives us 796297179." + ], + "constraints": "Constraints:\n\n2 <= n <= 1000\n1 <= k <= n-1", + "tags": [ + "Math", + "Dynamic Programming" + ], + "title-slug": "number-of-sets-of-k-non-overlapping-line-segments" + }, + { + "leetcode-id": 1622, + "title": "Fancy Sequence", + "difficulty": 3, + "description": "Write an API that generates fancy sequences using the append, addAll, and multAll operations.\nImplement the Fancy class:\n\nFancy() Initializes the object with an empty sequence.\nvoid append(val) Appends an integer val to the end of the sequence.\nvoid addAll(inc) Increments all existing values in the sequence by an integer inc.\nvoid multAll(m) Multiplies all existing values in the sequence by an integer m.\nint getIndex(idx) Gets the current value at index idx (0-indexed) of the sequence modulo 10^9 + 7. If the index is greater or equal than the length of the sequence, return -1.", + "examples": [ + "Example 1:\nInput\n[\"Fancy\", \"append\", \"addAll\", \"append\", \"multAll\", \"getIndex\", \"addAll\", \"append\", \"multAll\", \"getIndex\", \"getIndex\", \"getIndex\"]\n[[], [2], [3], [7], [2], [0], [3], [10], [2], [0], [1], [2]]\nOutput\n[null, null, null, null, null, 10, null, null, null, 26, 34, 20]\n\nExplanation\nFancy fancy = new Fancy();\nfancy.append(2); // fancy sequence: [2]\nfancy.addAll(3); // fancy sequence: [2+3] -> [5]\nfancy.append(7); // fancy sequence: [5, 7]\nfancy.multAll(2); // fancy sequence: [5*2, 7*2] -> [10, 14]\nfancy.getIndex(0); // return 10\nfancy.addAll(3); // fancy sequence: [10+3, 14+3] -> [13, 17]\nfancy.append(10); // fancy sequence: [13, 17, 10]\nfancy.multAll(2); // fancy sequence: [13*2, 17*2, 10*2] -> [26, 34, 20]\nfancy.getIndex(0); // return 26\nfancy.getIndex(1); // return 34\nfancy.getIndex(2); // return 20" + ], + "constraints": "Constraints:\n\n1 <= val, inc, m <= 100\n0 <= idx <= 10^5\nAt most 10^5 calls total will be made to append, addAll, multAll, and getIndex.", + "tags": [ + "Math", + "Design", + "Segment Tree" + ], + "title-slug": "fancy-sequence" + }, + { + "leetcode-id": 1624, + "title": "Largest Substring Between Two Equal Characters", + "difficulty": 1, + "description": "Given a string s, return the length of the longest substring between two equal characters, excluding the two characters. If there is no such substring return -1.\nA substring is a contiguous sequence of characters within a string.", + "examples": [ + "Example 1:\nInput: s = \"aa\"\nOutput: 0\nExplanation: The optimal substring here is an empty substring between the two 'a's.", + "Example 2:\nInput: s = \"abca\"\nOutput: 2\nExplanation: The optimal substring here is \"bc\".", + "Example 3:\nInput: s = \"cbzxy\"\nOutput: -1\nExplanation: There are no characters that appear twice in s." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 300\ns contains only lowercase English letters.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "largest-substring-between-two-equal-characters" + }, + { + "leetcode-id": 1625, + "title": "Lexicographically Smallest String After Applying Operations", + "difficulty": 2, + "description": "You are given a string s of even length consisting of digits from 0 to 9, and two integers a and b.\nYou can apply either of the following two operations any number of times and in any order on s:\n\nAdd a to all odd indices of s (0-indexed). Digits post 9 are cycled back to 0. For example, if s = \"3456\" and a = 5, s becomes \"3951\".\nRotate s to the right by b positions. For example, if s = \"3456\" and b = 1, s becomes \"6345\".\n\nReturn the lexicographically smallest string you can obtain by applying the above operations any number of times on s.\nA string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b. For example, \"0158\" is lexicographically smaller than \"0190\" because the first position they differ is at the third letter, and '5' comes before '9'.", + "examples": [ + "Example 1:\nInput: s = \"5525\", a = 9, b = 2\nOutput: \"2050\"\nExplanation: We can apply the following operations:\nStart: \"5525\"\nRotate: \"2555\"\nAdd: \"2454\"\nAdd: \"2353\"\nRotate: \"5323\"\nAdd: \"5222\"\nAdd: \"5121\"\nRotate: \"2151\"\nAdd: \"2050\"\u200b\u200b\u200b\u200b\u200b\nThere is no way to obtain a string that is lexicographically smaller than \"2050\".", + "Example 2:\nInput: s = \"74\", a = 5, b = 1\nOutput: \"24\"\nExplanation: We can apply the following operations:\nStart: \"74\"\nRotate: \"47\"\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bAdd: \"42\"\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bRotate: \"24\"\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\nThere is no way to obtain a string that is lexicographically smaller than \"24\".", + "Example 3:\nInput: s = \"0011\", a = 4, b = 2\nOutput: \"0011\"\nExplanation: There are no sequence of operations that will give us a lexicographically smaller string than \"0011\"." + ], + "constraints": "Constraints:\n\n2 <= s.length <= 100\ns.length is even.\ns consists of digits from 0 to 9 only.\n1 <= a <= 9\n1 <= b <= s.length - 1", + "tags": [ + "String", + "Breadth-First Search" + ], + "title-slug": "lexicographically-smallest-string-after-applying-operations" + }, + { + "leetcode-id": 1626, + "title": "Best Team With No Conflicts", + "difficulty": 2, + "description": "You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of all the players in the team.\nHowever, the basketball team is not allowed to have conflicts. A conflict exists if a younger player has a strictly higher score than an older player. A conflict does not occur between players of the same age.\nGiven two lists, scores and ages, where each scores[i] and ages[i] represents the score and age of the i^th player, respectively, return the highest overall score of all possible basketball teams.", + "examples": [ + "Example 1:\nInput: scores = [1,3,5,10,15], ages = [1,2,3,4,5]\nOutput: 34\nExplanation:\u00a0You can choose all the players.", + "Example 2:\nInput: scores = [4,5,6,5], ages = [2,1,2,1]\nOutput: 16\nExplanation:\u00a0It is best to choose the last 3 players. Notice that you are allowed to choose multiple people of the same age.", + "Example 3:\nInput: scores = [1,2,3,5], ages = [8,9,10,1]\nOutput: 6\nExplanation:\u00a0It is best to choose the first 3 players." + ], + "constraints": "Constraints:\n\n1 <= scores.length, ages.length <= 1000\nscores.length == ages.length\n1 <= scores[i] <= 10^6\n1 <= ages[i] <= 1000", + "tags": [ + "Array", + "Dynamic Programming", + "Sorting" + ], + "title-slug": "best-team-with-no-conflicts" + }, + { + "leetcode-id": 1627, + "title": "Graph Connectivity With Threshold", + "difficulty": 3, + "description": "We have n cities labeled from 1 to n. Two different cities with labels x and y are directly connected by a bidirectional road if and only if x and y share a common divisor strictly greater than some threshold. More formally, cities with labels x and y have a road between them if there exists an integer z such that all of the following are true:\n\nx % z == 0,\ny % z == 0, and\nz > threshold.\n\nGiven the two integers, n and threshold, and an array of queries, you must determine for each queries[i] = [ai, bi] if cities ai and bi are connected directly or indirectly.\u00a0(i.e. there is some path between them).\nReturn an array answer, where answer.length == queries.length and answer[i] is true if for the i^th query, there is a path between ai and bi, or answer[i] is false if there is no path.", + "examples": [ + "Example 1:\nInput: n = 6, threshold = 2, queries = [[1,4],[2,5],[3,6]]\nOutput: [false,false,true]\nExplanation: The divisors for each number:\n1: 1\n2: 1, 2\n3: 1, 3\n4: 1, 2, 4\n5: 1, 5\n6: 1, 2, 3, 6\nUsing the underlined divisors above the threshold, only cities 3 and 6 share a common divisor, so they are the\nonly ones directly connected. The result of each query:\n[1,4] 1 is not connected to 4\n[2,5] 2 is not connected to 5\n[3,6] 3 is connected to 6 through path 3--6", + "Example 2:\nInput: n = 6, threshold = 0, queries = [[4,5],[3,4],[3,2],[2,6],[1,3]]\nOutput: [true,true,true,true,true]\nExplanation: The divisors for each number are the same as the previous example. However, since the threshold is 0,\nall divisors can be used. Since all numbers share 1 as a divisor, all cities are connected.", + "Example 3:\nInput: n = 5, threshold = 1, queries = [[4,5],[4,5],[3,2],[2,3],[3,4]]\nOutput: [false,false,false,false,false]\nExplanation: Only cities 2 and 4 share a common divisor 2 which is strictly greater than the threshold 1, so they are the only ones directly connected.\nPlease notice that there can be multiple queries for the same pair of nodes [x, y], and that the query [x, y] is equivalent to the query [y, x]." + ], + "constraints": "Constraints:\n\n2 <= n <= 10^4\n0 <= threshold <= n\n1 <= queries.length <= 10^5\nqueries[i].length == 2\n1 <= ai, bi <= cities\nai != bi", + "tags": [ + "Array", + "Math", + "Union Find", + "Number Theory" + ], + "title-slug": "graph-connectivity-with-threshold" + }, + { + "leetcode-id": 1629, + "title": "Slowest Key", + "difficulty": 1, + "description": "A newly designed keypad was tested, where a tester pressed a sequence of n keys, one at a time.\nYou are given a string keysPressed of length n, where keysPressed[i] was the i^th key pressed in the testing sequence, and a sorted list releaseTimes, where releaseTimes[i] was the time the i^th key was released. Both arrays are 0-indexed. The 0^th key was pressed at the time 0,\u00a0and every subsequent key was pressed at the exact time the previous key was released.\nThe tester wants to know the key of the keypress that had the longest duration. The i^th^ keypress had a duration of releaseTimes[i] - releaseTimes[i - 1], and the 0^th keypress had a duration of releaseTimes[0].\nNote that the same key could have been pressed multiple times during the test, and these multiple presses of the same key may not have had the same duration.\nReturn the key of the keypress that had the longest duration. If there are multiple such keypresses, return the lexicographically largest key of the keypresses.", + "examples": [ + "Example 1:\nInput: releaseTimes = [9,29,49,50], keysPressed = \"cbcd\"\nOutput: \"c\"\nExplanation: The keypresses were as follows:\nKeypress for 'c' had a duration of 9 (pressed at time 0 and released at time 9).\nKeypress for 'b' had a duration of 29 - 9 = 20 (pressed at time 9 right after the release of the previous character and released at time 29).\nKeypress for 'c' had a duration of 49 - 29 = 20 (pressed at time 29 right after the release of the previous character and released at time 49).\nKeypress for 'd' had a duration of 50 - 49 = 1 (pressed at time 49 right after the release of the previous character and released at time 50).\nThe longest of these was the keypress for 'b' and the second keypress for 'c', both with duration 20.\n'c' is lexicographically larger than 'b', so the answer is 'c'.", + "Example 2:\nInput: releaseTimes = [12,23,36,46,62], keysPressed = \"spuda\"\nOutput: \"a\"\nExplanation: The keypresses were as follows:\nKeypress for 's' had a duration of 12.\nKeypress for 'p' had a duration of 23 - 12 = 11.\nKeypress for 'u' had a duration of 36 - 23 = 13.\nKeypress for 'd' had a duration of 46 - 36 = 10.\nKeypress for 'a' had a duration of 62 - 46 = 16.\nThe longest of these was the keypress for 'a' with duration 16." + ], + "constraints": "Constraints:\n\nreleaseTimes.length == n\nkeysPressed.length == n\n2 <= n <= 1000\n1 <= releaseTimes[i] <= 10^9\nreleaseTimes[i] < releaseTimes[i+1]\nkeysPressed contains only lowercase English letters.", + "tags": [ + "Array", + "String" + ], + "title-slug": "slowest-key" + }, + { + "leetcode-id": 1630, + "title": "Arithmetic Subarrays", + "difficulty": 2, + "description": "A sequence of numbers is called arithmetic if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence s is arithmetic if and only if s[i+1] - s[i] == s[1] - s[0] for all valid i.\nFor example, these are arithmetic sequences:\n\n1, 3, 5, 7, 9\n7, 7, 7, 7\n3, -1, -5, -9\nThe following sequence is not arithmetic:\n\n1, 1, 2, 5, 7\nYou are given an array of n integers, nums, and two arrays of m integers each, l and r, representing the m range queries, where the i^th query is the range [l[i], r[i]]. All the arrays are 0-indexed.\nReturn a list of boolean elements answer, where answer[i] is true if the subarray nums[l[i]], nums[l[i]+1], ... , nums[r[i]] can be rearranged to form an arithmetic sequence, and false otherwise.", + "examples": [ + "Example 1:\nInput: nums = [4,6,5,9,3,7], l = [0,0,2], r = [2,3,5]\nOutput: [true,false,true]\nExplanation:\nIn the 0^th query, the subarray is [4,6,5]. This can be rearranged as [6,5,4], which is an arithmetic sequence.\nIn the 1^st query, the subarray is [4,6,5,9]. This cannot be rearranged as an arithmetic sequence.\nIn the 2^nd query, the subarray is [5,9,3,7]. This can be rearranged as [3,5,7,9], which is an arithmetic sequence.", + "Example 2:\nInput: nums = [-12,-9,-3,-12,-6,15,20,-25,-20,-15,-10], l = [0,1,6,4,8,7], r = [4,4,9,7,9,10]\nOutput: [false,true,false,false,true,true]" + ], + "constraints": "Constraints:\n\nn == nums.length\nm == l.length\nm == r.length\n2 <= n <= 500\n1 <= m <= 500\n0 <= l[i] < r[i] < n\n-10^5 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "arithmetic-subarrays" + }, + { + "leetcode-id": 1631, + "title": "Path With Minimum Effort", + "difficulty": 2, + "description": "You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated in the top-left cell, (0, 0), and you hope to travel to the bottom-right cell, (rows-1, columns-1) (i.e.,\u00a00-indexed). You can move up, down, left, or right, and you wish to find a route that requires the minimum effort.\nA route's effort is the maximum absolute difference in heights between two consecutive cells of the route.\nReturn the minimum effort required to travel from the top-left cell to the bottom-right cell.", + "examples": [ + "Example 1:\nInput: heights = [[1,2,2],[3,8,2],[5,3,5]]\r\nOutput: 2\r\nExplanation: The route of [1,3,5,3,5] has a maximum absolute difference of 2 in consecutive cells.\r\nThis is better than the route of [1,2,2,2,5], where the maximum absolute difference is 3.", + "Example 2:\nInput: heights = [[1,2,3],[3,8,4],[5,3,5]]\r\nOutput: 1\r\nExplanation: The route of [1,2,3,4,5] has a maximum absolute difference of 1 in consecutive cells, which is better than route [1,3,5,3,5].", + "Example 3:\nInput: heights = [[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]\r\nOutput: 0\r\nExplanation: This route does not require any effort." + ], + "constraints": "Constraints:\n\nrows == heights.length\ncolumns == heights[i].length\n1 <= rows, columns <= 100\n1 <= heights[i][j] <= 10^6", + "tags": [ + "Array", + "Binary Search", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Heap (Priority Queue)", + "Matrix" + ], + "title-slug": "path-with-minimum-effort" + }, + { + "leetcode-id": 1632, + "title": "Rank Transform of a Matrix", + "difficulty": 3, + "description": "Given an m x n matrix, return a new matrix answer where answer[row][col] is the rank of matrix[row][col].\nThe rank is an integer that represents how large an element is compared to other elements. It is calculated using the following rules:\n\nThe rank is an integer starting from 1.\nIf two elements p and q are in the same row or column, then:\n\t\nIf p < q then rank(p) < rank(q)\nIf p == q then rank(p) == rank(q)\nIf p > q then rank(p) > rank(q)\n\n\nThe rank should be as small as possible.\n\nThe test cases are generated so that answer is unique under the given rules.", + "examples": [ + "Example 1:\nInput: matrix = [[1,2],[3,4]]\nOutput: [[1,2],[2,3]]\nExplanation:\nThe rank of matrix[0][0] is 1 because it is the smallest integer in its row and column.\nThe rank of matrix[0][1] is 2 because matrix[0][1] > matrix[0][0] and matrix[0][0] is rank 1.\nThe rank of matrix[1][0] is 2 because matrix[1][0] > matrix[0][0] and matrix[0][0] is rank 1.\nThe rank of matrix[1][1] is 3 because matrix[1][1] > matrix[0][1], matrix[1][1] > matrix[1][0], and both matrix[0][1] and matrix[1][0] are rank 2.", + "Example 2:\nInput: matrix = [[7,7],[7,7]]\nOutput: [[1,1],[1,1]]", + "Example 3:\nInput: matrix = [[20,-21,14],[-19,4,19],[22,-47,24],[-19,4,19]]\nOutput: [[4,2,3],[1,3,4],[5,1,6],[1,3,4]]" + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= m, n <= 500\n-10^9 <= matrix[row][col] <= 10^9", + "tags": [ + "Array", + "Union Find", + "Graph", + "Topological Sort", + "Sorting", + "Matrix" + ], + "title-slug": "rank-transform-of-a-matrix" + }, + { + "leetcode-id": 1636, + "title": "Sort Array by Increasing Frequency", + "difficulty": 1, + "description": "Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.\nReturn the sorted array.", + "examples": [ + "Example 1:\nInput: nums = [1,1,2,2,2,3]\nOutput: [3,1,1,2,2,2]\nExplanation: '3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3.", + "Example 2:\nInput: nums = [2,3,1,3,2]\nOutput: [1,3,3,2,2]\nExplanation: '2' and '3' both have a frequency of 2, so they are sorted in decreasing order.", + "Example 3:\nInput: nums = [-1,1,-6,4,5,-6,1,4,1]\nOutput: [5,-1,4,4,-6,-6,1,1,1]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n-100 <= nums[i] <= 100", + "tags": [ + "Array", + "Hash Table", + "Sorting" + ], + "title-slug": "sort-array-by-increasing-frequency" + }, + { + "leetcode-id": 1637, + "title": "Widest Vertical Area Between Two Points Containing No Points", + "difficulty": 2, + "description": "Given n points on a 2D plane where points[i] = [xi, yi], Return\u00a0the widest vertical area between two points such that no points are inside the area.\nA vertical area is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The widest vertical area is the one with the maximum width.\nNote that points on the edge of a vertical area are not considered included in the area.", + "examples": [ + "Example 1:\n\u200b\n\nInput: points = [[8,7],[9,9],[7,4],[9,7]]\nOutput: 1\nExplanation: Both the red and the blue area are optimal.", + "Example 2:\nInput: points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]\nOutput: 3" + ], + "constraints": "Constraints:\n\nn == points.length\n2 <= n <= 10^5\npoints[i].length == 2\n0 <= xi, yi\u00a0<= 10^9", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "widest-vertical-area-between-two-points-containing-no-points" + }, + { + "leetcode-id": 1638, + "title": "Count Substrings That Differ by One Character", + "difficulty": 2, + "description": "Given two strings s and t, find the number of ways you can choose a non-empty substring of s and replace a single character by a different character such that the resulting substring is a substring of t. In other words, find the number of substrings in s that differ from some substring in t by exactly one character.\nFor example, the underlined substrings in \"computer\" and \"computation\" only differ by the 'e'/'a', so this is a valid way.\nReturn the number of substrings that satisfy the condition above.\nA substring is a contiguous sequence of characters within a string.", + "examples": [ + "Example 1:\nInput: s = \"aba\", t = \"baba\"\nOutput: 6\nExplanation: The following are the pairs of substrings from s and t that differ by exactly 1 character:\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\nThe underlined portions are the substrings that are chosen from s and t.\n\n\u200b\u200b", + "Example 2:\nInput: s = \"ab\", t = \"bb\"\nOutput: 3\nExplanation: The following are the pairs of substrings from s and t that differ by 1 character:\n(\"ab\", \"bb\")\n(\"ab\", \"bb\")\n(\"ab\", \"bb\")\n\u200b\u200b\u200b\u200bThe underlined portions are the substrings that are chosen from s and t." + ], + "constraints": "Constraints:\n\n1 <= s.length, t.length <= 100\ns and t consist of lowercase English letters only.", + "tags": [ + "Hash Table", + "String", + "Dynamic Programming" + ], + "title-slug": "count-substrings-that-differ-by-one-character" + }, + { + "leetcode-id": 1639, + "title": "Number of Ways to Form a Target String Given a Dictionary", + "difficulty": 3, + "description": "You are given a list of strings of the same length words and a string target.\nYour task is to form target using the given words under the following rules:\n\ntarget should be formed from left to right.\nTo form the i^th character (0-indexed) of target, you can choose the k^th character of the j^th string in words if target[i] = words[j][k].\nOnce you use the k^th character of the j^th string of words, you can no longer use the x^th character of any string in words where x <= k. In other words, all characters to the left of or at index k become unusuable for every string.\nRepeat the process until you form the string target.\n\nNotice that you can use multiple characters from the same string in words provided the conditions above are met.\nReturn the number of ways to form target from words. Since the answer may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: words = [\"acca\",\"bbbb\",\"caca\"], target = \"aba\"\nOutput: 6\nExplanation: There are 6 ways to form target.\n\"aba\" -> index 0 (\"acca\"), index 1 (\"bbbb\"), index 3 (\"caca\")\n\"aba\" -> index 0 (\"acca\"), index 2 (\"bbbb\"), index 3 (\"caca\")\n\"aba\" -> index 0 (\"acca\"), index 1 (\"bbbb\"), index 3 (\"acca\")\n\"aba\" -> index 0 (\"acca\"), index 2 (\"bbbb\"), index 3 (\"acca\")\n\"aba\" -> index 1 (\"caca\"), index 2 (\"bbbb\"), index 3 (\"acca\")\n\"aba\" -> index 1 (\"caca\"), index 2 (\"bbbb\"), index 3 (\"caca\")", + "Example 2:\nInput: words = [\"abba\",\"baab\"], target = \"bab\"\nOutput: 4\nExplanation: There are 4 ways to form target.\n\"bab\" -> index 0 (\"baab\"), index 1 (\"baab\"), index 2 (\"abba\")\n\"bab\" -> index 0 (\"baab\"), index 1 (\"baab\"), index 3 (\"baab\")\n\"bab\" -> index 0 (\"baab\"), index 2 (\"baab\"), index 3 (\"baab\")\n\"bab\" -> index 1 (\"abba\"), index 2 (\"baab\"), index 3 (\"baab\")" + ], + "constraints": "Constraints:\n\n1 <= words.length <= 1000\n1 <= words[i].length <= 1000\nAll strings in words have the same length.\n1 <= target.length <= 1000\nwords[i] and target contain only lowercase English letters.", + "tags": [ + "Array", + "String", + "Dynamic Programming" + ], + "title-slug": "number-of-ways-to-form-a-target-string-given-a-dictionary" + }, + { + "leetcode-id": 1640, + "title": "Check Array Formation Through Concatenation", + "difficulty": 1, + "description": "You are given an array of distinct integers arr and an array of integer arrays pieces, where the integers in pieces are distinct. Your goal is to form arr by concatenating the arrays in pieces in any order. However, you are not allowed to reorder the integers in each array pieces[i].\nReturn true if it is possible to form the array arr from pieces. Otherwise, return false.", + "examples": [ + "Example 1:\nInput: arr = [15,88], pieces = [[88],[15]]\nOutput: true\nExplanation: Concatenate [15] then [88]", + "Example 2:\nInput: arr = [49,18,16], pieces = [[16,18,49]]\nOutput: false\nExplanation: Even though the numbers match, we cannot reorder pieces[0].", + "Example 3:\nInput: arr = [91,4,64,78], pieces = [[78],[4,64],[91]]\nOutput: true\nExplanation: Concatenate [91] then [4,64] then [78]" + ], + "constraints": "Constraints:\n\n1 <= pieces.length <= arr.length <= 100\nsum(pieces[i].length) == arr.length\n1 <= pieces[i].length <= arr.length\n1 <= arr[i], pieces[i][j] <= 100\nThe integers in arr are distinct.\nThe integers in pieces are distinct (i.e., If we flatten pieces in a 1D array, all the integers in this array are distinct).", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "check-array-formation-through-concatenation" + }, + { + "leetcode-id": 1641, + "title": "Count Sorted Vowel Strings", + "difficulty": 2, + "description": "Given an integer n, return the number of strings of length n that consist only of vowels (a, e, i, o, u) and are lexicographically sorted.\nA string s is lexicographically sorted if for all valid i, s[i] is the same as or comes before s[i+1] in the alphabet.", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: 5\nExplanation: The 5 sorted strings that consist of vowels only are [\"a\",\"e\",\"i\",\"o\",\"u\"].", + "Example 2:\nInput: n = 2\nOutput: 15\nExplanation: The 15 sorted strings that consist of vowels only are\n[\"aa\",\"ae\",\"ai\",\"ao\",\"au\",\"ee\",\"ei\",\"eo\",\"eu\",\"ii\",\"io\",\"iu\",\"oo\",\"ou\",\"uu\"].\nNote that \"ea\" is not a valid string since 'e' comes after 'a' in the alphabet.", + "Example 3:\nInput: n = 33\nOutput: 66045" + ], + "constraints": "Constraints:\n\n1 <= n <= 50", + "tags": [ + "Math", + "Dynamic Programming", + "Combinatorics" + ], + "title-slug": "count-sorted-vowel-strings" + }, + { + "leetcode-id": 1642, + "title": "Furthest Building You Can Reach", + "difficulty": 2, + "description": "You are given an integer array heights representing the heights of buildings, some bricks, and some ladders.\nYou start your journey from building 0 and move to the next building by possibly using bricks or ladders.\nWhile moving from building i to building i+1 (0-indexed),\n\nIf the current building's height is greater than or equal to the next building's height, you do not need a ladder or bricks.\nIf the current building's height is less than the next building's height, you can either use one ladder or (h[i+1] - h[i]) bricks.\n\nReturn the furthest building index (0-indexed) you can reach if you use the given ladders and bricks optimally.", + "examples": [ + "Example 1:\nInput: heights = [4,2,7,6,9,14,12], bricks = 5, ladders = 1\nOutput: 4\nExplanation: Starting at building 0, you can follow these steps:\n- Go to building 1 without using ladders nor bricks since 4 >= 2.\n- Go to building 2 using 5 bricks. You must use either bricks or ladders because 2 < 7.\n- Go to building 3 without using ladders nor bricks since 7 >= 6.\n- Go to building 4 using your only ladder. You must use either bricks or ladders because 6 < 9.\nIt is impossible to go beyond building 4 because you do not have any more bricks or ladders.", + "Example 2:\nInput: heights = [4,12,2,7,3,18,20,3,19], bricks = 10, ladders = 2\nOutput: 7", + "Example 3:\nInput: heights = [14,3,19,3], bricks = 17, ladders = 0\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= heights.length <= 10^5\n1 <= heights[i] <= 10^6\n0 <= bricks <= 10^9\n0 <= ladders <= heights.length", + "tags": [ + "Array", + "Greedy", + "Heap (Priority Queue)" + ], + "title-slug": "furthest-building-you-can-reach" + }, + { + "leetcode-id": 1643, + "title": "Kth Smallest Instructions", + "difficulty": 3, + "description": "Bob is standing at cell (0, 0), and he wants to reach destination: (row, column). He can only travel right and down. You are going to help Bob by providing instructions for him to reach destination.\nThe instructions are represented as a string, where each character is either:\n\n'H', meaning move horizontally (go right), or\n'V', meaning move vertically (go down).\n\nMultiple instructions will lead Bob to destination. For example, if destination is (2, 3), both \"HHHVV\" and \"HVHVH\" are valid instructions.\nHowever, Bob is very picky. Bob has a lucky number k, and he wants the k^th lexicographically smallest instructions that will lead him to destination. k is 1-indexed.\nGiven an integer array destination and an integer k, return the k^th lexicographically smallest instructions that will take Bob to destination.", + "examples": [ + "Example 1:\nInput: destination = [2,3], k = 1\nOutput: \"HHHVV\"\nExplanation: All the instructions that reach (2, 3) in lexicographic order are as follows:\n[\"HHHVV\", \"HHVHV\", \"HHVVH\", \"HVHHV\", \"HVHVH\", \"HVVHH\", \"VHHHV\", \"VHHVH\", \"VHVHH\", \"VVHHH\"].", + "Example 2:\nInput: destination = [2,3], k = 2\nOutput: \"HHVHV\"", + "Example 3:\nInput: destination = [2,3], k = 3\nOutput: \"HHVVH\"" + ], + "constraints": "Constraints:\n\ndestination.length == 2\n1 <= row, column <= 15\n1 <= k <= nCr(row + column, row), where nCr(a, b) denotes a choose b\u200b\u200b\u200b\u200b\u200b.", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Combinatorics" + ], + "title-slug": "kth-smallest-instructions" + }, + { + "leetcode-id": 1646, + "title": "Get Maximum in Generated Array", + "difficulty": 1, + "description": "You are given an integer n. A 0-indexed integer array nums of length n + 1 is generated in the following way:\n\nnums[0] = 0\nnums[1] = 1\nnums[2 * i] = nums[i] when 2 <= 2 * i <= n\nnums[2 * i + 1] = nums[i] + nums[i + 1] when 2 <= 2 * i + 1 <= n\n\nReturn the maximum integer in the array nums\u200b\u200b\u200b.", + "examples": [ + "Example 1:\nInput: n = 7\nOutput: 3\nExplanation: According to the given rules:\n nums[0] = 0\n nums[1] = 1\n nums[(1 * 2) = 2] = nums[1] = 1\n nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2\n nums[(2 * 2) = 4] = nums[2] = 1\n nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3\n nums[(3 * 2) = 6] = nums[3] = 2\n nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3\nHence, nums = [0,1,1,2,1,3,2,3], and the maximum is max(0,1,1,2,1,3,2,3) = 3.", + "Example 2:\nInput: n = 2\nOutput: 1\nExplanation: According to the given rules, nums = [0,1,1]. The maximum is max(0,1,1) = 1.", + "Example 3:\nInput: n = 3\nOutput: 2\nExplanation: According to the given rules, nums = [0,1,1,2]. The maximum is max(0,1,1,2) = 2." + ], + "constraints": "Constraints:\n\n0 <= n <= 100", + "tags": [ + "Array", + "Dynamic Programming", + "Simulation" + ], + "title-slug": "get-maximum-in-generated-array" + }, + { + "leetcode-id": 1647, + "title": "Minimum Deletions to Make Character Frequencies Unique", + "difficulty": 2, + "description": "A string s is called good if there are no two different characters in s that have the same frequency.\nGiven a string s, return the minimum number of characters you need to delete to make s good.\nThe frequency of a character in a string is the number of times it appears in the string. For example, in the string \"aab\", the frequency of 'a' is 2, while the frequency of 'b' is 1.", + "examples": [ + "Example 1:\nInput: s = \"aab\"\nOutput: 0\nExplanation: s is already good.", + "Example 2:\nInput: s = \"aaabbbcc\"\nOutput: 2\nExplanation: You can delete two 'b's resulting in the good string \"aaabcc\".\nAnother way it to delete one 'b' and one 'c' resulting in the good string \"aaabbc\".", + "Example 3:\nInput: s = \"ceabaacb\"\nOutput: 2\nExplanation: You can delete both 'c's resulting in the good string \"eabaab\".\nNote that we only care about characters that are still in the string at the end (i.e. frequency of 0 is ignored)." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns\u00a0contains only lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Greedy", + "Sorting" + ], + "title-slug": "minimum-deletions-to-make-character-frequencies-unique" + }, + { + "leetcode-id": 1648, + "title": "Sell Diminishing-Valued Colored Balls", + "difficulty": 2, + "description": "You have an inventory of different colored balls, and there is a customer that wants orders balls of any color.\nThe customer weirdly values the colored balls. Each colored ball's value is the number of balls of that color\u00a0you currently have in your inventory. For example, if you own 6 yellow balls, the customer would pay 6 for the first yellow ball. After the transaction, there are only 5 yellow balls left, so the next yellow ball is then valued at 5 (i.e., the value of the balls decreases as you sell more to the customer).\nYou are given an integer array, inventory, where inventory[i] represents the number of balls of the i^th color that you initially own. You are also given an integer orders, which represents the total number of balls that the customer wants. You can sell the balls in any order.\nReturn the maximum total value that you can attain after selling orders colored balls. As the answer may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: inventory = [2,5], orders = 4\nOutput: 14\nExplanation: Sell the 1st color 1 time (2) and the 2nd color 3 times (5 + 4 + 3).\nThe maximum total value is 2 + 5 + 4 + 3 = 14.", + "Example 2:\nInput: inventory = [3,5], orders = 6\nOutput: 19\nExplanation: Sell the 1st color 2 times (3 + 2) and the 2nd color 4 times (5 + 4 + 3 + 2).\nThe maximum total value is 3 + 2 + 5 + 4 + 3 + 2 = 19." + ], + "constraints": "Constraints:\n\n1 <= inventory.length <= 10^5\n1 <= inventory[i] <= 10^9\n1 <= orders <= min(sum(inventory[i]), 10^9)", + "tags": [ + "Array", + "Math", + "Binary Search", + "Greedy", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "sell-diminishing-valued-colored-balls" + }, + { + "leetcode-id": 1649, + "title": "Create Sorted Array through Instructions", + "difficulty": 3, + "description": "Given an integer array instructions, you are asked to create a sorted array from the elements in instructions. You start with an empty container nums. For each element from left to right in instructions, insert it into nums. The cost of each insertion is the minimum of the following:\n\nThe number of elements currently in nums that are strictly less than instructions[i].\nThe number of elements currently in nums that are strictly greater than instructions[i].\n\nFor example, if inserting element 3 into nums = [1,2,3,5], the cost of insertion is min(2, 1) (elements 1 and 2 are less than 3, element 5 is greater than 3) and nums will become [1,2,3,3,5].\nReturn the total cost to insert all elements from instructions into nums. Since the answer may be large, return it modulo 10^9 + 7", + "examples": [ + "Example 1:\nInput: instructions = [1,5,6,2]\r\nOutput: 1\r\nExplanation: Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 5 with cost min(1, 0) = 0, now nums = [1,5].\r\nInsert 6 with cost min(2, 0) = 0, now nums = [1,5,6].\r\nInsert 2 with cost min(1, 2) = 1, now nums = [1,2,5,6].\r\nThe total cost is 0 + 0 + 0 + 1 = 1.", + "Example 2:\nInput: instructions = [1,2,3,6,5,4]\r\nOutput: 3\r\nExplanation: Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 2 with cost min(1, 0) = 0, now nums = [1,2].\r\nInsert 3 with cost min(2, 0) = 0, now nums = [1,2,3].\r\nInsert 6 with cost min(3, 0) = 0, now nums = [1,2,3,6].\r\nInsert 5 with cost min(3, 1) = 1, now nums = [1,2,3,5,6].\r\nInsert 4 with cost min(3, 2) = 2, now nums = [1,2,3,4,5,6].\r\nThe total cost is 0 + 0 + 0 + 0 + 1 + 2 = 3.", + "Example 3:\nInput: instructions = [1,3,3,3,2,4,2,1,2]\r\nOutput: 4\r\nExplanation: Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3,3].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3,3,3].\r\nInsert 2 with cost min(1, 3) = 1, now nums = [1,2,3,3,3].\r\nInsert 4 with cost min(5, 0) = 0, now nums = [1,2,3,3,3,4].\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bInsert 2 with cost min(1, 4) = 1, now nums = [1,2,2,3,3,3,4].\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bInsert 1 with cost min(0, 6) = 0, now nums = [1,1,2,2,3,3,3,4].\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bInsert 2 with cost min(2, 4) = 2, now nums = [1,1,2,2,2,3,3,3,4].\r\nThe total cost is 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4." + ], + "constraints": "Constraints:\n\n1 <= instructions.length <= 10^5\n1 <= instructions[i] <= 10^5", + "tags": [ + "Array", + "Binary Search", + "Divide and Conquer", + "Binary Indexed Tree", + "Segment Tree", + "Merge Sort", + "Ordered Set" + ], + "title-slug": "create-sorted-array-through-instructions" + }, + { + "leetcode-id": 1652, + "title": "Defuse the Bomb", + "difficulty": 1, + "description": "You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code\u00a0of length of n\u00a0and a key k.\nTo decrypt the code, you must replace every number. All the numbers are replaced simultaneously.\n\nIf k > 0, replace the i^th number with the sum of the next k numbers.\nIf k < 0, replace the i^th number with the sum of the previous k numbers.\nIf k == 0, replace the i^th number with 0.\n\nAs code is circular, the next element of code[n-1] is code[0], and the previous element of code[0] is code[n-1].\nGiven the circular array code and an integer key k, return the decrypted code to defuse the bomb!", + "examples": [ + "Example 1:\nInput: code = [5,7,1,4], k = 3\nOutput: [12,10,16,13]\nExplanation: Each number is replaced by the sum of the next 3 numbers. The decrypted code is [7+1+4, 1+4+5, 4+5+7, 5+7+1]. Notice that the numbers wrap around.", + "Example 2:\nInput: code = [1,2,3,4], k = 0\nOutput: [0,0,0,0]\nExplanation: When k is zero, the numbers are replaced by 0.", + "Example 3:\nInput: code = [2,4,9,3], k = -2\nOutput: [12,5,6,13]\nExplanation: The decrypted code is [3+9, 2+3, 4+2, 9+4]. Notice that the numbers wrap around again. If k is negative, the sum is of the previous numbers." + ], + "constraints": "Constraints:\n\nn == code.length\n1 <= n\u00a0<= 100\n1 <= code[i] <= 100\n-(n - 1) <= k <= n - 1", + "tags": [ + "Array" + ], + "title-slug": "defuse-the-bomb" + }, + { + "leetcode-id": 1653, + "title": "Minimum Deletions to Make String Balanced", + "difficulty": 2, + "description": "You are given a string s consisting only of characters 'a' and 'b'\u200b\u200b\u200b\u200b.\nYou can delete any number of characters in s to make s balanced. s is balanced if there is no pair of indices (i,j) such that i < j and s[i] = 'b' and s[j]= 'a'.\nReturn the minimum number of deletions needed to make s balanced.", + "examples": [ + "Example 1:\nInput: s = \"aababbab\"\nOutput: 2\nExplanation: You can either:\nDelete the characters at 0-indexed positions 2 and 6 (\"aababbab\" -> \"aaabbb\"), or\nDelete the characters at 0-indexed positions 3 and 6 (\"aababbab\" -> \"aabbbb\").", + "Example 2:\nInput: s = \"bbaaaaabb\"\nOutput: 2\nExplanation: The only solution is to delete the first two characters." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns[i] is\u00a0'a' or 'b'\u200b\u200b.", + "tags": [ + "String", + "Dynamic Programming", + "Stack" + ], + "title-slug": "minimum-deletions-to-make-string-balanced" + }, + { + "leetcode-id": 1654, + "title": "Minimum Jumps to Reach Home", + "difficulty": 2, + "description": "A certain bug's home is on the x-axis at position x. Help them get there from position 0.\nThe bug jumps according to the following rules:\n\nIt can jump exactly a positions forward (to the right).\nIt can jump exactly b positions backward (to the left).\nIt cannot jump backward twice in a row.\nIt cannot jump to any forbidden positions.\n\nThe bug may jump forward beyond its home, but it cannot jump to positions numbered with negative integers.\nGiven an array of integers forbidden, where forbidden[i] means that the bug cannot jump to the position forbidden[i], and integers a, b, and x, return the minimum number of jumps needed for the bug to reach its home. If there is no possible sequence of jumps that lands the bug on position x, return -1.", + "examples": [ + "Example 1:\nInput: forbidden = [14,4,18,1,15], a = 3, b = 15, x = 9\nOutput: 3\nExplanation: 3 jumps forward (0 -> 3 -> 6 -> 9) will get the bug home.", + "Example 2:\nInput: forbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11\nOutput: -1", + "Example 3:\nInput: forbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7\nOutput: 2\nExplanation: One jump forward (0 -> 16) then one jump backward (16 -> 7) will get the bug home." + ], + "constraints": "Constraints:\n\n1 <= forbidden.length <= 1000\n1 <= a, b, forbidden[i] <= 2000\n0 <= x <= 2000\nAll the elements in forbidden are distinct.\nPosition x is not forbidden.", + "tags": [ + "Array", + "Dynamic Programming", + "Breadth-First Search" + ], + "title-slug": "minimum-jumps-to-reach-home" + }, + { + "leetcode-id": 1655, + "title": "Distribute Repeating Integers", + "difficulty": 3, + "description": "You are given an array of n integers, nums, where there are at most 50 unique values in the array. You are also given an array of m customer order quantities, quantity, where quantity[i] is the amount of integers the i^th customer ordered. Determine if it is possible to distribute nums such that:\n\nThe i^th customer gets exactly quantity[i] integers,\nThe integers the i^th customer gets are all equal, and\nEvery customer is satisfied.\n\nReturn true if it is possible to distribute nums according to the above conditions.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4], quantity = [2]\nOutput: false\nExplanation: The 0^th customer cannot be given two different integers.", + "Example 2:\nInput: nums = [1,2,3,3], quantity = [2]\nOutput: true\nExplanation: The 0^th customer is given [3,3]. The integers [1,2] are not used.", + "Example 3:\nInput: nums = [1,1,2,2], quantity = [2,2]\nOutput: true\nExplanation: The 0^th customer is given [1,1], and the 1st customer is given [2,2]." + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^5\n1 <= nums[i] <= 1000\nm == quantity.length\n1 <= m <= 10\n1 <= quantity[i] <= 10^5\nThere are at most 50 unique values in nums.", + "tags": [ + "Array", + "Dynamic Programming", + "Backtracking", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "distribute-repeating-integers" + }, + { + "leetcode-id": 1656, + "title": "Design an Ordered Stream", + "difficulty": 1, + "description": "There is a stream of n (idKey, value) pairs arriving in an arbitrary order, where idKey is an integer between 1 and n and value is a string. No two pairs have the same id.\nDesign a stream that returns the values in increasing order of their IDs by returning a chunk (list) of values after each insertion. The concatenation of all the chunks should result in a list of the sorted values.\nImplement the OrderedStream class:\n\nOrderedStream(int n) Constructs the stream to take n values.\nString[] insert(int idKey, String value) Inserts the pair (idKey, value) into the stream, then returns the largest possible chunk of currently inserted values that appear next in the order.\n\n\u00a0\nExample:\n\n\nInput\n[\"OrderedStream\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\"]\n[[5], [3, \"ccccc\"], [1, \"aaaaa\"], [2, \"bbbbb\"], [5, \"eeeee\"], [4, \"ddddd\"]]\nOutput\n[null, [], [\"aaaaa\"], [\"bbbbb\", \"ccccc\"], [], [\"ddddd\", \"eeeee\"]]\n\nExplanation\n// Note that the values ordered by ID is [\"aaaaa\", \"bbbbb\", \"ccccc\", \"ddddd\", \"eeeee\"].\nOrderedStream os = new OrderedStream(5);\nos.insert(3, \"ccccc\"); // Inserts (3, \"ccccc\"), returns [].\nos.insert(1, \"aaaaa\"); // Inserts (1, \"aaaaa\"), returns [\"aaaaa\"].\nos.insert(2, \"bbbbb\"); // Inserts (2, \"bbbbb\"), returns [\"bbbbb\", \"ccccc\"].\nos.insert(5, \"eeeee\"); // Inserts (5, \"eeeee\"), returns [].\nos.insert(4, \"ddddd\"); // Inserts (4, \"ddddd\"), returns [\"ddddd\", \"eeeee\"].\n// Concatentating all the chunks returned:\n// [] + [\"aaaaa\"] + [\"bbbbb\", \"ccccc\"] + [] + [\"ddddd\", \"eeeee\"] = [\"aaaaa\", \"bbbbb\", \"ccccc\", \"ddddd\", \"eeeee\"]\n// The resulting order is the same as the order above.\n\n\u00a0\nConstraints:\n\n1 <= n <= 1000\n1 <= id <= n\nvalue.length == 5\nvalue\u00a0consists only of lowercase letters.\nEach call to insert\u00a0will have a unique id.\nExactly n calls will be made to insert.", + "examples": [], + "constraints": "Constraints:\n\n1 <= n <= 1000\n1 <= id <= n\nvalue.length == 5\nvalue\u00a0consists only of lowercase letters.\nEach call to insert\u00a0will have a unique id.\nExactly n calls will be made to insert.", + "tags": [ + "Array", + "Hash Table", + "Design", + "Data Stream" + ], + "title-slug": "design-an-ordered-stream" + }, + { + "leetcode-id": 1657, + "title": "Determine if Two Strings Are Close", + "difficulty": 2, + "description": "Two strings are considered close if you can attain one from the other using the following operations:\n\nOperation 1: Swap any two existing characters.\n\n\t\nFor example, abcde -> aecdb\n\n\nOperation 2: Transform every occurrence of one existing character into another existing character, and do the same with the other character.\n\t\nFor example, aacabb -> bbcbaa (all a's turn into b's, and all b's turn into a's)\n\n\n\nYou can use the operations on either string as many times as necessary.\nGiven two strings, word1 and word2, return true if word1 and word2 are close, and false otherwise.", + "examples": [ + "Example 1:\nInput: word1 = \"abc\", word2 = \"bca\"\nOutput: true\nExplanation: You can attain word2 from word1 in 2 operations.\nApply Operation 1: \"abc\" -> \"acb\"\nApply Operation 1: \"acb\" -> \"bca\"", + "Example 2:\nInput: word1 = \"a\", word2 = \"aa\"\nOutput: false\nExplanation: It is impossible to attain word2 from word1, or vice versa, in any number of operations.", + "Example 3:\nInput: word1 = \"cabbba\", word2 = \"abbccc\"\nOutput: true\nExplanation: You can attain word2 from word1 in 3 operations.\nApply Operation 1: \"cabbba\" -> \"caabbb\"\nApply Operation 2: \"caabbb\" -> \"baaccc\"\nApply Operation 2: \"baaccc\" -> \"abbccc\"" + ], + "constraints": "Constraints:\n\n1 <= word1.length, word2.length <= 10^5\nword1 and word2 contain only lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Sorting" + ], + "title-slug": "determine-if-two-strings-are-close" + }, + { + "leetcode-id": 1658, + "title": "Minimum Operations to Reduce X to Zero", + "difficulty": 2, + "description": "You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifies the array for future operations.\nReturn the minimum number of operations to reduce x to exactly 0 if it is possible, otherwise, return -1.", + "examples": [ + "Example 1:\nInput: nums = [1,1,4,2,3], x = 5\nOutput: 2\nExplanation: The optimal solution is to remove the last two elements to reduce x to zero.", + "Example 2:\nInput: nums = [5,6,7,8,9], x = 4\nOutput: -1", + "Example 3:\nInput: nums = [3,2,20,1,1,3], x = 10\nOutput: 5\nExplanation: The optimal solution is to remove the last three elements and the first two elements (5 operations in total) to reduce x to zero." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^4\n1 <= x <= 10^9", + "tags": [ + "Array", + "Hash Table", + "Binary Search", + "Sliding Window", + "Prefix Sum" + ], + "title-slug": "minimum-operations-to-reduce-x-to-zero" + }, + { + "leetcode-id": 1659, + "title": "Maximize Grid Happiness", + "difficulty": 3, + "description": "You are given four integers, m, n, introvertsCount, and extrovertsCount. You have an m x n grid, and there are two types of people: introverts and extroverts. There are introvertsCount introverts and extrovertsCount extroverts.\nYou should decide how many people you want to live in the grid and assign each of them one grid cell. Note that you do not have to have all the people living in the grid.\nThe happiness of each person is calculated as follows:\n\nIntroverts start with 120 happiness and lose 30 happiness for each neighbor (introvert or extrovert).\nExtroverts start with 40 happiness and gain 20 happiness for each neighbor (introvert or extrovert).\n\nNeighbors live in the directly adjacent cells north, east, south, and west of a person's cell.\nThe grid happiness is the sum of each person's happiness. Return the maximum possible grid happiness.", + "examples": [ + "Example 1:\nInput: m = 2, n = 3, introvertsCount = 1, extrovertsCount = 2\nOutput: 240\nExplanation: Assume the grid is 1-indexed with coordinates (row, column).\nWe can put the introvert in cell (1,1) and put the extroverts in cells (1,3) and (2,3).\n- Introvert at (1,1) happiness: 120 (starting happiness) - (0 * 30) (0 neighbors) = 120\n- Extrovert at (1,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60\n- Extrovert at (2,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60\nThe grid happiness is 120 + 60 + 60 = 240.\nThe above figure shows the grid in this example with each person's happiness. The introvert stays in the light green cell while the extroverts live on the light purple cells.", + "Example 2:\nInput: m = 3, n = 1, introvertsCount = 2, extrovertsCount = 1\nOutput: 260\nExplanation: Place the two introverts in (1,1) and (3,1) and the extrovert at (2,1).\n- Introvert at (1,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90\n- Extrovert at (2,1) happiness: 40 (starting happiness) + (2 * 20) (2 neighbors) = 80\n- Introvert at (3,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90\nThe grid happiness is 90 + 80 + 90 = 260.", + "Example 3:\nInput: m = 2, n = 2, introvertsCount = 4, extrovertsCount = 0\nOutput: 240" + ], + "constraints": "Constraints:\n\n1 <= m, n <= 5\n0 <= introvertsCount, extrovertsCount <= min(m * n, 6)", + "tags": [ + "Dynamic Programming", + "Bit Manipulation", + "Memoization", + "Bitmask" + ], + "title-slug": "maximize-grid-happiness" + }, + { + "leetcode-id": 1662, + "title": "Check If Two String Arrays are Equivalent", + "difficulty": 1, + "description": "Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise.\nA string is represented by an array if the array elements concatenated in order forms the string.", + "examples": [ + "Example 1:\nInput: word1 = [\"ab\", \"c\"], word2 = [\"a\", \"bc\"]\nOutput: true\nExplanation:\nword1 represents string \"ab\" + \"c\" -> \"abc\"\nword2 represents string \"a\" + \"bc\" -> \"abc\"\nThe strings are the same, so return true.", + "Example 2:\nInput: word1 = [\"a\", \"cb\"], word2 = [\"ab\", \"c\"]\nOutput: false", + "Example 3:\nInput: word1 = [\"abc\", \"d\", \"defg\"], word2 = [\"abcddefg\"]\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= word1.length, word2.length <= 10^3\n1 <= word1[i].length, word2[i].length <= 10^3\n1 <= sum(word1[i].length), sum(word2[i].length) <= 10^3\nword1[i] and word2[i] consist of lowercase letters.", + "tags": [ + "Array", + "String" + ], + "title-slug": "check-if-two-string-arrays-are-equivalent" + }, + { + "leetcode-id": 1663, + "title": "Smallest String With A Given Numeric Value", + "difficulty": 2, + "description": "The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on.\nThe numeric value of a string consisting of lowercase characters is defined as the sum of its characters' numeric values. For example, the numeric value of the string \"abe\" is equal to 1 + 2 + 5 = 8.\nYou are given two integers n and k. Return the lexicographically smallest string with length equal to n and numeric value equal to k.\nNote that a string x is lexicographically smaller than string y if x comes before y in dictionary order, that is, either x is a prefix of y, or if i is the first position such that x[i] != y[i], then x[i] comes before y[i] in alphabetic order.", + "examples": [ + "Example 1:\nInput: n = 3, k = 27\nOutput: \"aay\"\nExplanation: The numeric value of the string is 1 + 1 + 25 = 27, and it is the smallest string with such a value and length equal to 3.", + "Example 2:\nInput: n = 5, k = 73\nOutput: \"aaszz\"" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5\nn <= k <= 26 * n", + "tags": [ + "String", + "Greedy" + ], + "title-slug": "smallest-string-with-a-given-numeric-value" + }, + { + "leetcode-id": 1664, + "title": "Ways to Make a Fair Array", + "difficulty": 2, + "description": "You are given an integer array\u00a0nums. You can choose exactly one index (0-indexed) and remove the element. Notice that the index of the elements may change after the removal.\nFor example, if nums = [6,1,7,4,1]:\n\nChoosing to remove index 1 results in nums = [6,7,4,1].\nChoosing to remove index 2 results in nums = [6,1,4,1].\nChoosing to remove index 4 results in nums = [6,1,7,4].\n\nAn array is fair if the sum of the odd-indexed values equals the sum of the even-indexed values.\nReturn the number of indices that you could choose such that after the removal, nums is fair.", + "examples": [ + "Example 1:\nInput: nums = [2,1,6,4]\nOutput: 1\nExplanation:\nRemove index 0: [1,6,4] -> Even sum: 1 + 4 = 5. Odd sum: 6. Not fair.\nRemove index 1: [2,6,4] -> Even sum: 2 + 4 = 6. Odd sum: 6. Fair.\nRemove index 2: [2,1,4] -> Even sum: 2 + 4 = 6. Odd sum: 1. Not fair.\nRemove index 3: [2,1,6] -> Even sum: 2 + 6 = 8. Odd sum: 1. Not fair.\nThere is 1 index that you can remove to make nums fair.", + "Example 2:\nInput: nums = [1,1,1]\nOutput: 3\nExplanation:\u00a0You can remove any index and the remaining array is fair.", + "Example 3:\nInput: nums = [1,2,3]\nOutput: 0\nExplanation:\u00a0You cannot make a fair array after removing any index." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "ways-to-make-a-fair-array" + }, + { + "leetcode-id": 1665, + "title": "Minimum Initial Energy to Finish Tasks", + "difficulty": 3, + "description": "You are given an array tasks where tasks[i] = [actuali, minimumi]:\n\nactuali is the actual amount of energy you spend to finish the i^th task.\nminimumi is the minimum amount of energy you require to begin the i^th task.\n\nFor example, if the task is [10, 12] and your current energy is 11, you cannot start this task. However, if your current energy is 13, you can complete this task, and your energy will be 3 after finishing it.\nYou can finish the tasks in any order you like.\nReturn the minimum initial amount of energy you will need to finish all the tasks.", + "examples": [ + "Example 1:\nInput: tasks = [[1,2],[2,4],[4,8]]\nOutput: 8\nExplanation:\nStarting with 8 energy, we finish the tasks in the following order:\n - 3rd task. Now energy = 8 - 4 = 4.\n - 2nd task. Now energy = 4 - 2 = 2.\n - 1st task. Now energy = 2 - 1 = 1.\nNotice that even though we have leftover energy, starting with 7 energy does not work because we cannot do the 3rd task.", + "Example 2:\nInput: tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]\nOutput: 32\nExplanation:\nStarting with 32 energy, we finish the tasks in the following order:\n - 1st task. Now energy = 32 - 1 = 31.\n - 2nd task. Now energy = 31 - 2 = 29.\n - 3rd task. Now energy = 29 - 10 = 19.\n - 4th task. Now energy = 19 - 10 = 9.\n - 5th task. Now energy = 9 - 8 = 1.", + "Example 3:\nInput: tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]\nOutput: 27\nExplanation:\nStarting with 27 energy, we finish the tasks in the following order:\n - 5th task. Now energy = 27 - 5 = 22.\n - 2nd task. Now energy = 22 - 2 = 20.\n - 3rd task. Now energy = 20 - 3 = 17.\n - 1st task. Now energy = 17 - 1 = 16.\n - 4th task. Now energy = 16 - 4 = 12.\n - 6th task. Now energy = 12 - 6 = 6." + ], + "constraints": "Constraints:\n\n1 <= tasks.length <= 10^5\n1 <= actual\u200bi\u00a0<= minimumi\u00a0<= 10^4", + "tags": [ + "Array", + "Greedy", + "Sorting" + ], + "title-slug": "minimum-initial-energy-to-finish-tasks" + }, + { + "leetcode-id": 1668, + "title": "Maximum Repeating Substring", + "difficulty": 1, + "description": "For a string sequence, a string word is k-repeating if word concatenated k times is a substring of sequence. The word's maximum k-repeating value is the highest value k where word is k-repeating in sequence. If word is not a substring of sequence, word's maximum k-repeating value is 0.\nGiven strings sequence and word, return the maximum k-repeating value of word in sequence.", + "examples": [ + "Example 1:\nInput: sequence = \"ababc\", word = \"ab\"\nOutput: 2\nExplanation: \"abab\" is a substring in \"ababc\".", + "Example 2:\nInput: sequence = \"ababc\", word = \"ba\"\nOutput: 1\nExplanation: \"ba\" is a substring in \"ababc\". \"baba\" is not a substring in \"ababc\".", + "Example 3:\nInput: sequence = \"ababc\", word = \"ac\"\nOutput: 0\nExplanation: \"ac\" is not a substring in \"ababc\"." + ], + "constraints": "Constraints:\n\n1 <= sequence.length <= 100\n1 <= word.length <= 100\nsequence and word\u00a0contains only lowercase English letters.", + "tags": [ + "String", + "String Matching" + ], + "title-slug": "maximum-repeating-substring" + }, + { + "leetcode-id": 1669, + "title": "Merge In Between Linked Lists", + "difficulty": 2, + "description": "You are given two linked lists: list1 and list2 of sizes n and m respectively.\nRemove list1's nodes from the a^th node to the b^th node, and put list2 in their place.\nThe blue edges and nodes in the following figure indicate the result:\n\nBuild the result list and return its head.", + "examples": [ + "Example 1:\nInput: list1 = [0,1,2,3,4,5], a = 3, b = 4, list2 = [1000000,1000001,1000002]\nOutput: [0,1,2,1000000,1000001,1000002,5]\nExplanation: We remove the nodes 3 and 4 and put the entire list2 in their place. The blue edges and nodes in the above figure indicate the result.", + "Example 2:\nInput: list1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004]\nOutput: [0,1,1000000,1000001,1000002,1000003,1000004,6]\nExplanation: The blue edges and nodes in the above figure indicate the result." + ], + "constraints": "Constraints:\n\n3 <= list1.length <= 10^4\n1 <= a <= b < list1.length - 1\n1 <= list2.length <= 10^4", + "tags": [ + "Linked List" + ], + "title-slug": "merge-in-between-linked-lists" + }, + { + "leetcode-id": 1670, + "title": "Design Front Middle Back Queue", + "difficulty": 2, + "description": "Design a queue that supports push and pop operations in the front, middle, and back.\nImplement the FrontMiddleBack class:\n\nFrontMiddleBack() Initializes the queue.\nvoid pushFront(int val) Adds val to the front of the queue.\nvoid pushMiddle(int val) Adds val to the middle of the queue.\nvoid pushBack(int val) Adds val to the back of the queue.\nint popFront() Removes the front element of the queue and returns it. If the queue is empty, return -1.\nint popMiddle() Removes the middle element of the queue and returns it. If the queue is empty, return -1.\nint popBack() Removes the back element of the queue and returns it. If the queue is empty, return -1.\n\nNotice that when there are two middle position choices, the operation is performed on the frontmost middle position choice. For example:\n\nPushing 6 into the middle of [1, 2, 3, 4, 5] results in [1, 2, 6, 3, 4, 5].\nPopping the middle from [1, 2, 3, 4, 5, 6] returns 3 and results in [1, 2, 4, 5, 6].", + "examples": [ + "Example 1:\nInput:\n[\"FrontMiddleBackQueue\", \"pushFront\", \"pushBack\", \"pushMiddle\", \"pushMiddle\", \"popFront\", \"popMiddle\", \"popMiddle\", \"popBack\", \"popFront\"]\n[[], [1], [2], [3], [4], [], [], [], [], []]\nOutput:\n[null, null, null, null, null, 1, 3, 4, 2, -1]\n\nExplanation:\nFrontMiddleBackQueue q = new FrontMiddleBackQueue();\nq.pushFront(1); // [1]\nq.pushBack(2); // [1, 2]\nq.pushMiddle(3); // [1, 3, 2]\nq.pushMiddle(4); // [1, 4, 3, 2]\nq.popFront(); // return 1 -> [4, 3, 2]\nq.popMiddle(); // return 3 -> [4, 2]\nq.popMiddle(); // return 4 -> [2]\nq.popBack(); // return 2 -> []\nq.popFront(); // return -1 -> [] (The queue is empty)" + ], + "constraints": "Constraints:\n\n1 <= val <= 10^9\nAt most\u00a01000\u00a0calls will be made to\u00a0pushFront,\u00a0pushMiddle,\u00a0pushBack, popFront, popMiddle, and popBack.", + "tags": [ + "Array", + "Linked List", + "Design", + "Queue", + "Data Stream" + ], + "title-slug": "design-front-middle-back-queue" + }, + { + "leetcode-id": 1671, + "title": "Minimum Number of Removals to Make Mountain Array", + "difficulty": 3, + "description": "You may recall that an array arr is a mountain array if and only if:\n\narr.length >= 3\nThere exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:\n\t\narr[0] < arr[1] < ... < arr[i - 1] < arr[i]\narr[i] > arr[i + 1] > ... > arr[arr.length - 1]\n\n\n\nGiven an integer array nums\u200b\u200b\u200b, return the minimum number of elements to remove to make nums\u200b\u200b\u200b a mountain array.", + "examples": [ + "Example 1:\nInput: nums = [1,3,1]\nOutput: 0\nExplanation: The array itself is a mountain array so we do not need to remove any elements.", + "Example 2:\nInput: nums = [2,1,1,5,6,2,3,1]\nOutput: 3\nExplanation: One solution is to remove the elements at indices 0, 1, and 5, making the array nums = [1,5,6,3,1]." + ], + "constraints": "Constraints:\n\n3 <= nums.length <= 1000\n1 <= nums[i] <= 10^9\nIt is guaranteed that you can make a mountain array out of nums.", + "tags": [ + "Array", + "Binary Search", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "minimum-number-of-removals-to-make-mountain-array" + }, + { + "leetcode-id": 1672, + "title": "Richest Customer Wealth", + "difficulty": 1, + "description": "You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i\u200b\u200b\u200b\u200b\u200b^\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b customer has in the j\u200b\u200b\u200b\u200b\u200b^\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b bank. Return the wealth that the richest customer has.\nA customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.", + "examples": [ + "Example 1:\nInput: accounts = [[1,2,3],[3,2,1]]\nOutput: 6\nExplanation:\n1st customer has wealth = 1 + 2 + 3 = 6\n2nd customer has wealth = 3 + 2 + 1 = 6\nBoth customers are considered the richest with a wealth of 6 each, so return 6.", + "Example 2:\nInput: accounts = [[1,5],[7,3],[3,5]]\nOutput: 10\nExplanation: \n1st customer has wealth = 6\n2nd customer has wealth = 10 \n3rd customer has wealth = 8\nThe 2nd customer is the richest with a wealth of 10.", + "Example 3:\nInput: accounts = [[2,8,7],[7,1,3],[1,9,5]]\nOutput: 17" + ], + "constraints": "Constraints:\n\nm ==\u00a0accounts.length\nn ==\u00a0accounts[i].length\n1 <= m, n <= 50\n1 <= accounts[i][j] <= 100", + "tags": [ + "Array", + "Matrix" + ], + "title-slug": "richest-customer-wealth" + }, + { + "leetcode-id": 1673, + "title": "Find the Most Competitive Subsequence", + "difficulty": 2, + "description": "Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k.\nAn array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array.\nWe define that a subsequence a is more competitive than a subsequence b (of the same length) if in the first position where a and b differ, subsequence a has a number less than the corresponding number in b. For example, [1,3,4] is more competitive than [1,3,5] because the first position they differ is at the final number, and 4 is less than 5.", + "examples": [ + "Example 1:\nInput: nums = [3,5,2,6], k = 2\nOutput: [2,6]\nExplanation: Among the set of every possible subsequence: {[3,5], [3,2], [3,6], [5,2], [5,6], [2,6]}, [2,6] is the most competitive.", + "Example 2:\nInput: nums = [2,4,3,3,5,4,9,6], k = 4\nOutput: [2,3,3,4]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^9\n1 <= k <= nums.length", + "tags": [ + "Array", + "Stack", + "Greedy", + "Monotonic Stack" + ], + "title-slug": "find-the-most-competitive-subsequence" + }, + { + "leetcode-id": 1674, + "title": "Minimum Moves to Make Array Complementary", + "difficulty": 2, + "description": "You are given an integer array nums of even length n and an integer limit. In one move, you can replace any integer from nums with another integer between 1 and limit, inclusive.\nThe array nums is complementary if for all indices i (0-indexed), nums[i] + nums[n - 1 - i] equals the same number. For example, the array [1,2,3,4] is complementary because for all indices i, nums[i] + nums[n - 1 - i] = 5.\nReturn the minimum number of moves required to make nums complementary.", + "examples": [ + "Example 1:\nInput: nums = [1,2,4,3], limit = 4\nOutput: 1\nExplanation: In 1 move, you can change nums to [1,2,2,3] (underlined elements are changed).\nnums[0] + nums[3] = 1 + 3 = 4.\nnums[1] + nums[2] = 2 + 2 = 4.\nnums[2] + nums[1] = 2 + 2 = 4.\nnums[3] + nums[0] = 3 + 1 = 4.\nTherefore, nums[i] + nums[n-1-i] = 4 for every i, so nums is complementary.", + "Example 2:\nInput: nums = [1,2,2,1], limit = 2\nOutput: 2\nExplanation: In 2 moves, you can change nums to [2,2,2,2]. You cannot change any number to 3 since 3 > limit.", + "Example 3:\nInput: nums = [1,2,1,2], limit = 2\nOutput: 0\nExplanation: nums is already complementary." + ], + "constraints": "Constraints:\n\nn == nums.length\n2 <= n\u00a0<=\u00a010^5\n1 <= nums[i]\u00a0<= limit <=\u00a010^5\nn is even.", + "tags": [ + "Array", + "Hash Table", + "Prefix Sum" + ], + "title-slug": "minimum-moves-to-make-array-complementary" + }, + { + "leetcode-id": 1675, + "title": "Minimize Deviation in Array", + "difficulty": 3, + "description": "You are given an array nums of n positive integers.\nYou can perform two types of operations on any element of the array any number of times:\n\nIf the element is even, divide it by 2.\n\n\t\nFor example, if the array is [1,2,3,4], then you can do this operation on the last element, and the array will be [1,2,3,2].\n\n\nIf the element is odd, multiply it by 2.\n\t\nFor example, if the array is [1,2,3,4], then you can do this operation on the first element, and the array will be [2,2,3,4].\n\n\n\nThe deviation of the array is the maximum difference between any two elements in the array.\nReturn the minimum deviation the array can have after performing some number of operations.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4]\nOutput: 1\nExplanation: You can transform the array to [1,2,3,2], then to [2,2,3,2], then the deviation will be 3 - 2 = 1.", + "Example 2:\nInput: nums = [4,1,5,20,3]\nOutput: 3\nExplanation: You can transform the array after two operations to [4,2,5,5,3], then the deviation will be 5 - 2 = 3.", + "Example 3:\nInput: nums = [2,10,8]\nOutput: 3" + ], + "constraints": "Constraints:\n\nn == nums.length\n2 <= n <= 5 * 10^4\n1 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Greedy", + "Heap (Priority Queue)", + "Ordered Set" + ], + "title-slug": "minimize-deviation-in-array" + }, + { + "leetcode-id": 1678, + "title": "Goal Parser Interpretation", + "difficulty": 1, + "description": "You own a Goal Parser that can interpret a string command. The command consists of an alphabet of \"G\", \"()\" and/or \"(al)\" in some order. The Goal Parser will interpret \"G\" as the string \"G\", \"()\" as the string \"o\", and \"(al)\" as the string \"al\". The interpreted strings are then concatenated in the original order.\nGiven the string command, return the Goal Parser's interpretation of command.", + "examples": [ + "Example 1:\nInput: command = \"G()(al)\"\nOutput: \"Goal\"\nExplanation:\u00a0The Goal Parser interprets the command as follows:\nG -> G\n() -> o\n(al) -> al\nThe final concatenated result is \"Goal\".", + "Example 2:\nInput: command = \"G()()()()(al)\"\nOutput: \"Gooooal\"", + "Example 3:\nInput: command = \"(al)G(al)()()G\"\nOutput: \"alGalooG\"" + ], + "constraints": "Constraints:\n\n1 <= command.length <= 100\ncommand consists of \"G\", \"()\", and/or \"(al)\" in some order.", + "tags": [ + "String" + ], + "title-slug": "goal-parser-interpretation" + }, + { + "leetcode-id": 1679, + "title": "Max Number of K-Sum Pairs", + "difficulty": 2, + "description": "You are given an integer array nums and an integer k.\nIn one operation, you can pick two numbers from the array whose sum equals k and remove them from the array.\nReturn the maximum number of operations you can perform on the array.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4], k = 5\nOutput: 2\nExplanation: Starting with nums = [1,2,3,4]:\n- Remove numbers 1 and 4, then nums = [2,3]\n- Remove numbers 2 and 3, then nums = []\nThere are no more pairs that sum up to 5, hence a total of 2 operations.", + "Example 2:\nInput: nums = [3,1,3,4,3], k = 6\nOutput: 1\nExplanation: Starting with nums = [3,1,3,4,3]:\n- Remove the first two 3's, then nums = [1,4,3]\nThere are no more pairs that sum up to 6, hence a total of 1 operation." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\n1 <= k <= 10^9", + "tags": [ + "Array", + "Hash Table", + "Two Pointers", + "Sorting" + ], + "title-slug": "max-number-of-k-sum-pairs" + }, + { + "leetcode-id": 1680, + "title": "Concatenation of Consecutive Binary Numbers", + "difficulty": 2, + "description": "Given an integer n, return the decimal value of the binary string formed by concatenating the binary representations of 1 to n in order, modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: 1\nExplanation: \"1\" in binary corresponds to the decimal value 1.", + "Example 2:\nInput: n = 3\nOutput: 27\nExplanation: In binary, 1, 2, and 3 corresponds to \"1\", \"10\", and \"11\".\nAfter concatenating them, we have \"11011\", which corresponds to the decimal value 27.", + "Example 3:\nInput: n = 12\nOutput: 505379714\nExplanation: The concatenation results in \"1101110010111011110001001101010111100\".\nThe decimal value of that is 118505380540.\nAfter modulo 10^9 + 7, the result is 505379714." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5", + "tags": [ + "Math", + "Bit Manipulation", + "Simulation" + ], + "title-slug": "concatenation-of-consecutive-binary-numbers" + }, + { + "leetcode-id": 1681, + "title": "Minimum Incompatibility", + "difficulty": 3, + "description": "You are given an integer array nums\u200b\u200b\u200b and an integer k. You are asked to distribute this array into k subsets of equal size such that there are no two equal elements in the same subset.\nA subset's incompatibility is the difference between the maximum and minimum elements in that array.\nReturn the minimum possible sum of incompatibilities of the k subsets after distributing the array optimally, or return -1 if it is not possible.\nA subset is a group integers that appear in the array with no particular order.", + "examples": [ + "Example 1:\nInput: nums = [1,2,1,4], k = 2\nOutput: 4\nExplanation: The optimal distribution of subsets is [1,2] and [1,4].\nThe incompatibility is (2-1) + (4-1) = 4.\nNote that [1,1] and [2,4] would result in a smaller sum, but the first subset contains 2 equal elements.", + "Example 2:\nInput: nums = [6,3,8,1,3,1,2,2], k = 4\nOutput: 6\nExplanation: The optimal distribution of subsets is [1,2], [2,3], [6,8], and [1,3].\nThe incompatibility is (2-1) + (3-2) + (8-6) + (3-1) = 6.", + "Example 3:\nInput: nums = [5,3,3,6,3,3], k = 3\nOutput: -1\nExplanation: It is impossible to distribute nums into 3 subsets where no two elements are equal in the same subset." + ], + "constraints": "Constraints:\n\n1 <= k <= nums.length <= 16\nnums.length is divisible by k\n1 <= nums[i] <= nums.length", + "tags": [ + "Array", + "Dynamic Programming", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "minimum-incompatibility" + }, + { + "leetcode-id": 1684, + "title": "Count the Number of Consistent Strings", + "difficulty": 1, + "description": "You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed.\nReturn the number of consistent strings in the array words.", + "examples": [ + "Example 1:\nInput: allowed = \"ab\", words = [\"ad\",\"bd\",\"aaab\",\"baa\",\"badab\"]\nOutput: 2\nExplanation: Strings \"aaab\" and \"baa\" are consistent since they only contain characters 'a' and 'b'.", + "Example 2:\nInput: allowed = \"abc\", words = [\"a\",\"b\",\"c\",\"ab\",\"ac\",\"bc\",\"abc\"]\nOutput: 7\nExplanation: All strings are consistent.", + "Example 3:\nInput: allowed = \"cad\", words = [\"cc\",\"acd\",\"b\",\"ba\",\"bac\",\"bad\",\"ac\",\"d\"]\nOutput: 4\nExplanation: Strings \"cc\", \"acd\", \"ac\", and \"d\" are consistent." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 10^4\n1 <= allowed.length <=^ 26\n1 <= words[i].length <= 10\nThe characters in allowed are distinct.\nwords[i] and allowed contain only lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Bit Manipulation" + ], + "title-slug": "count-the-number-of-consistent-strings" + }, + { + "leetcode-id": 1685, + "title": "Sum of Absolute Differences in a Sorted Array", + "difficulty": 2, + "description": "You are given an integer array nums sorted in non-decreasing order.\nBuild and return an integer array result with the same length as nums such that result[i] is equal to the summation of absolute differences between nums[i] and all the other elements in the array.\nIn other words, result[i] is equal to sum(|nums[i]-nums[j]|) where 0 <= j < nums.length and j != i (0-indexed).", + "examples": [ + "Example 1:\nInput: nums = [2,3,5]\nOutput: [4,3,5]\nExplanation: Assuming the arrays are 0-indexed, then\nresult[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4,\nresult[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3,\nresult[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5.", + "Example 2:\nInput: nums = [1,4,6,8,10]\nOutput: [24,15,13,15,21]" + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 10^5\n1 <= nums[i] <= nums[i + 1] <= 10^4", + "tags": [ + "Array", + "Math", + "Prefix Sum" + ], + "title-slug": "sum-of-absolute-differences-in-a-sorted-array" + }, + { + "leetcode-id": 1686, + "title": "Stone Game VI", + "difficulty": 2, + "description": "Alice and Bob take turns playing a game, with Alice starting first.\nThere are n stones in a pile. On each player's turn, they can remove a stone from the pile and receive points based on the stone's value. Alice and Bob may value the stones differently.\nYou are given two integer arrays of length n, aliceValues and bobValues. Each aliceValues[i] and bobValues[i] represents how Alice and Bob, respectively, value the i^th stone.\nThe winner is the person with the most points after all the stones are chosen. If both players have the same amount of points, the game results in a draw. Both players will play optimally.\u00a0Both players know the other's values.\nDetermine the result of the game, and:\n\nIf Alice wins, return 1.\nIf Bob wins, return -1.\nIf the game results in a draw, return 0.", + "examples": [ + "Example 1:\nInput: aliceValues = [1,3], bobValues = [2,1]\nOutput: 1\nExplanation:\nIf Alice takes stone 1 (0-indexed) first, Alice will receive 3 points.\nBob can only choose stone 0, and will only receive 2 points.\nAlice wins.", + "Example 2:\nInput: aliceValues = [1,2], bobValues = [3,1]\nOutput: 0\nExplanation:\nIf Alice takes stone 0, and Bob takes stone 1, they will both have 1 point.\nDraw.", + "Example 3:\nInput: aliceValues = [2,4,3], bobValues = [1,6,7]\nOutput: -1\nExplanation:\nRegardless of how Alice plays, Bob will be able to have more points than Alice.\nFor example, if Alice takes stone 1, Bob can take stone 2, and Alice takes stone 0, Alice will have 6 points to Bob's 7.\nBob wins." + ], + "constraints": "Constraints:\n\nn == aliceValues.length == bobValues.length\n1 <= n <= 10^5\n1 <= aliceValues[i], bobValues[i] <= 100", + "tags": [ + "Array", + "Math", + "Greedy", + "Sorting", + "Heap (Priority Queue)", + "Game Theory" + ], + "title-slug": "stone-game-vi" + }, + { + "leetcode-id": 1687, + "title": "Delivering Boxes from Storage to Ports", + "difficulty": 3, + "description": "You have the task of delivering some boxes from storage to their ports using only one ship. However, this ship has a limit on the number of boxes and the total weight that it can carry.\nYou are given an array boxes, where boxes[i] = [ports\u200b\u200bi\u200b, weighti], and three integers portsCount, maxBoxes, and maxWeight.\n\nports\u200b\u200bi is the port where you need to deliver the i^th box and weightsi is the weight of the i^th box.\nportsCount is the number of ports.\nmaxBoxes and maxWeight are the respective box and weight limits of the ship.\n\nThe boxes need to be delivered in the order they are given. The ship will follow these steps:\n\nThe ship will take some number of boxes from the boxes queue, not violating the maxBoxes and maxWeight constraints.\nFor each loaded box in order, the ship will make a trip to the port the box needs to be delivered to and deliver it. If the ship is already at the correct port, no trip is needed, and the box can immediately be delivered.\nThe ship then makes a return trip to storage to take more boxes from the queue.\n\nThe ship must end at storage after all the boxes have been delivered.\nReturn the minimum number of trips the ship needs to make to deliver all boxes to their respective ports.", + "examples": [ + "Example 1:\nInput: boxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3\nOutput: 4\nExplanation: The optimal strategy is as follows: \n- The ship takes all the boxes in the queue, goes to port 1, then port 2, then port 1 again, then returns to storage. 4 trips.\nSo the total number of trips is 4.\nNote that the first and third boxes cannot be delivered together because the boxes need to be delivered in order (i.e. the second box needs to be delivered at port 2 before the third box).", + "Example 2:\nInput: boxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6\nOutput: 6\nExplanation: The optimal strategy is as follows: \n- The ship takes the first box, goes to port 1, then returns to storage. 2 trips.\n- The ship takes the second, third and fourth boxes, goes to port 3, then returns to storage. 2 trips.\n- The ship takes the fifth box, goes to port 2, then returns to storage. 2 trips.\nSo the total number of trips is 2 + 2 + 2 = 6.", + "Example 3:\nInput: boxes = [[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]], portsCount = 3, maxBoxes = 6, maxWeight = 7\nOutput: 6\nExplanation: The optimal strategy is as follows:\n- The ship takes the first and second boxes, goes to port 1, then returns to storage. 2 trips.\n- The ship takes the third and fourth boxes, goes to port 2, then returns to storage. 2 trips.\n- The ship takes the fifth and sixth boxes, goes to port 3, then returns to storage. 2 trips.\nSo the total number of trips is 2 + 2 + 2 = 6." + ], + "constraints": "Constraints:\n\n1 <= boxes.length <= 10^5\n1 <= portsCount, maxBoxes, maxWeight <= 10^5\n1 <= ports\u200b\u200bi <= portsCount\n1 <= weightsi <= maxWeight", + "tags": [ + "Array", + "Dynamic Programming", + "Segment Tree", + "Queue", + "Heap (Priority Queue)", + "Prefix Sum", + "Monotonic Queue" + ], + "title-slug": "delivering-boxes-from-storage-to-ports" + }, + { + "leetcode-id": 1688, + "title": "Count of Matches in Tournament", + "difficulty": 1, + "description": "You are given an integer n, the number of teams in a tournament that has strange rules:\n\nIf the current number of teams is even, each team gets paired with another team. A total of n / 2 matches are played, and n / 2 teams advance to the next round.\nIf the current number of teams is odd, one team randomly advances in the tournament, and the rest gets paired. A total of (n - 1) / 2 matches are played, and (n - 1) / 2 + 1 teams advance to the next round.\n\nReturn the number of matches played in the tournament until a winner is decided.", + "examples": [ + "Example 1:\nInput: n = 7\nOutput: 6\nExplanation: Details of the tournament: \n- 1st Round: Teams = 7, Matches = 3, and 4 teams advance.\n- 2nd Round: Teams = 4, Matches = 2, and 2 teams advance.\n- 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner.\nTotal number of matches = 3 + 2 + 1 = 6.", + "Example 2:\nInput: n = 14\nOutput: 13\nExplanation: Details of the tournament:\n- 1st Round: Teams = 14, Matches = 7, and 7 teams advance.\n- 2nd Round: Teams = 7, Matches = 3, and 4 teams advance.\n- 3rd Round: Teams = 4, Matches = 2, and 2 teams advance.\n- 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner.\nTotal number of matches = 7 + 3 + 2 + 1 = 13." + ], + "constraints": "Constraints:\n\n1 <= n <= 200", + "tags": [ + "Math", + "Simulation" + ], + "title-slug": "count-of-matches-in-tournament" + }, + { + "leetcode-id": 1689, + "title": "Partitioning Into Minimum Number Of Deci-Binary Numbers", + "difficulty": 2, + "description": "A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. For example, 101 and 1100 are deci-binary, while 112 and 3001 are not.\nGiven a string n that represents a positive decimal integer, return the minimum number of positive deci-binary numbers needed so that they sum up to n.", + "examples": [ + "Example 1:\nInput: n = \"32\"\nOutput: 3\nExplanation: 10 + 11 + 11 = 32", + "Example 2:\nInput: n = \"82734\"\nOutput: 8", + "Example 3:\nInput: n = \"27346209830709182346\"\nOutput: 9" + ], + "constraints": "Constraints:\n\n1 <= n.length <= 10^5\nn consists of only digits.\nn does not contain any leading zeros and represents a positive integer.", + "tags": [ + "String", + "Greedy" + ], + "title-slug": "partitioning-into-minimum-number-of-deci-binary-numbers" + }, + { + "leetcode-id": 1690, + "title": "Stone Game VII", + "difficulty": 2, + "description": "Alice and Bob take turns playing a game, with Alice starting first.\nThere are n stones arranged in a row. On each player's turn, they can remove either the leftmost stone or the rightmost stone from the row and receive points equal to the sum of the remaining stones' values in the row. The winner is the one with the higher score when there are no stones left to remove.\nBob found that he will always lose this game (poor Bob, he always loses), so he decided to minimize the score's difference. Alice's goal is to maximize the difference in the score.\nGiven an array of integers stones where stones[i] represents the value of the i^th stone from the left, return the difference in Alice and Bob's score if they both play optimally.", + "examples": [ + "Example 1:\nInput: stones = [5,3,1,4,2]\nOutput: 6\nExplanation: \n- Alice removes 2 and gets 5 + 3 + 1 + 4 = 13 points. Alice = 13, Bob = 0, stones = [5,3,1,4].\n- Bob removes 5 and gets 3 + 1 + 4 = 8 points. Alice = 13, Bob = 8, stones = [3,1,4].\n- Alice removes 3 and gets 1 + 4 = 5 points. Alice = 18, Bob = 8, stones = [1,4].\n- Bob removes 1 and gets 4 points. Alice = 18, Bob = 12, stones = [4].\n- Alice removes 4 and gets 0 points. Alice = 18, Bob = 12, stones = [].\nThe score difference is 18 - 12 = 6.", + "Example 2:\nInput: stones = [7,90,5,1,100,10,10,2]\nOutput: 122" + ], + "constraints": "Constraints:\n\nn == stones.length\n2 <= n <= 1000\n1 <= stones[i] <= 1000", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Game Theory" + ], + "title-slug": "stone-game-vii" + }, + { + "leetcode-id": 1691, + "title": "Maximum Height by Stacking Cuboids ", + "difficulty": 3, + "description": "Given n cuboids where the dimensions of the i^th cuboid is cuboids[i] = [widthi, lengthi, heighti] (0-indexed). Choose a subset of cuboids and place them on each other.\nYou can place cuboid i on cuboid j if widthi <= widthj and lengthi <= lengthj and heighti <= heightj. You can rearrange any cuboid's dimensions by rotating it to put it on another cuboid.\nReturn the maximum height of the stacked cuboids.", + "examples": [ + "Example 1:\nInput: cuboids = [[50,45,20],[95,37,53],[45,23,12]]\nOutput: 190\nExplanation:\nCuboid 1 is placed on the bottom with the 53x37 side facing down with height 95.\nCuboid 0 is placed next with the 45x20 side facing down with height 50.\nCuboid 2 is placed next with the 23x12 side facing down with height 45.\nThe total height is 95 + 50 + 45 = 190.", + "Example 2:\nInput: cuboids = [[38,25,45],[76,35,3]]\nOutput: 76\nExplanation:\nYou can't place any of the cuboids on the other.\nWe choose cuboid 1 and rotate it so that the 35x3 side is facing down and its height is 76.", + "Example 3:\nInput: cuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]\nOutput: 102\nExplanation:\nAfter rearranging the cuboids, you can see that all cuboids have the same dimension.\nYou can place the 11x7 side down on all cuboids so their heights are 17.\nThe maximum height of stacked cuboids is 6 * 17 = 102." + ], + "constraints": "Constraints:\n\nn == cuboids.length\n1 <= n <= 100\n1 <= widthi, lengthi, heighti <= 100", + "tags": [ + "Array", + "Dynamic Programming", + "Sorting" + ], + "title-slug": "maximum-height-by-stacking-cuboids" + }, + { + "leetcode-id": 1694, + "title": "Reformat Phone Number", + "difficulty": 1, + "description": "You are given a phone number as a string number. number consists of digits, spaces ' ', and/or dashes '-'.\nYou would like to reformat the phone number in a certain manner. Firstly, remove all spaces and dashes. Then, group the digits from left to right into blocks of length 3 until there are 4 or fewer digits. The final digits are then grouped as follows:\n\n2 digits: A single block of length 2.\n3 digits: A single block of length 3.\n4 digits: Two blocks of length 2 each.\n\nThe blocks are then joined by dashes. Notice that the reformatting process should never produce any blocks of length 1 and produce at most two blocks of length 2.\nReturn the phone number after formatting.", + "examples": [ + "Example 1:\nInput: number = \"1-23-45 6\"\nOutput: \"123-456\"\nExplanation: The digits are \"123456\".\nStep 1: There are more than 4 digits, so group the next 3 digits. The 1st block is \"123\".\nStep 2: There are 3 digits remaining, so put them in a single block of length 3. The 2nd block is \"456\".\nJoining the blocks gives \"123-456\".", + "Example 2:\nInput: number = \"123 4-567\"\nOutput: \"123-45-67\"\nExplanation: The digits are \"1234567\".\nStep 1: There are more than 4 digits, so group the next 3 digits. The 1st block is \"123\".\nStep 2: There are 4 digits left, so split them into two blocks of length 2. The blocks are \"45\" and \"67\".\nJoining the blocks gives \"123-45-67\".", + "Example 3:\nInput: number = \"123 4-5678\"\nOutput: \"123-456-78\"\nExplanation: The digits are \"12345678\".\nStep 1: The 1st block is \"123\".\nStep 2: The 2nd block is \"456\".\nStep 3: There are 2 digits left, so put them in a single block of length 2. The 3rd block is \"78\".\nJoining the blocks gives \"123-456-78\"." + ], + "constraints": "Constraints:\n\n2 <= number.length <= 100\nnumber consists of digits and the characters '-' and ' '.\nThere are at least two digits in number.", + "tags": [ + "String" + ], + "title-slug": "reformat-phone-number" + }, + { + "leetcode-id": 1695, + "title": "Maximum Erasure Value", + "difficulty": 2, + "description": "You are given an array of positive integers nums and want to erase a subarray containing\u00a0unique elements. The score you get by erasing the subarray is equal to the sum of its elements.\nReturn the maximum score you can get by erasing exactly one subarray.\nAn array b is called to be a subarray of a if it forms a contiguous subsequence of a, that is, if it is equal to a[l],a[l+1],...,a[r] for some (l,r).", + "examples": [ + "Example 1:\nInput: nums = [4,2,4,5,6]\nOutput: 17\nExplanation: The optimal subarray here is [2,4,5,6].", + "Example 2:\nInput: nums = [5,2,1,2,5,2,1,2,5]\nOutput: 8\nExplanation: The optimal subarray here is [5,2,1] or [1,2,5]." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Hash Table", + "Sliding Window" + ], + "title-slug": "maximum-erasure-value" + }, + { + "leetcode-id": 1696, + "title": "Jump Game VI", + "difficulty": 2, + "description": "You are given a 0-indexed integer array nums and an integer k.\nYou are initially standing at index 0. In one move, you can jump at most k steps forward without going outside the boundaries of the array. That is, you can jump from index i to any index in the range [i + 1, min(n - 1, i + k)] inclusive.\nYou want to reach the last index of the array (index n - 1). Your score is the sum of all nums[j] for each index j you visited in the array.\nReturn the maximum score you can get.", + "examples": [ + "Example 1:\nInput: nums = [1,-1,-2,4,-7,3], k = 2\nOutput: 7\nExplanation: You can choose your jumps forming the subsequence [1,-1,4,3] (underlined above). The sum is 7.", + "Example 2:\nInput: nums = [10,-5,-2,4,0,3], k = 3\nOutput: 17\nExplanation: You can choose your jumps forming the subsequence [10,4,3] (underlined above). The sum is 17.", + "Example 3:\nInput: nums = [1,-5,-20,4,-1,3,-6,-3], k = 2\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= nums.length, k <= 10^5\n-10^4 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Dynamic Programming", + "Queue", + "Heap (Priority Queue)", + "Monotonic Queue" + ], + "title-slug": "jump-game-vi" + }, + { + "leetcode-id": 1697, + "title": "Checking Existence of Edge Length Limited Paths", + "difficulty": 3, + "description": "An undirected graph of n nodes is defined by edgeList, where edgeList[i] = [ui, vi, disi] denotes an edge between nodes ui and vi with distance disi. Note that there may be multiple edges between two nodes.\nGiven an array queries, where queries[j] = [pj, qj, limitj], your task is to determine for each queries[j] whether there is a path between pj and qj such that each edge on the path has a distance strictly less than limitj .\nReturn a boolean array answer, where answer.length == queries.length and the j^th value of answer is true if there is a path for queries[j] is true, and false otherwise.", + "examples": [ + "Example 1:\nInput: n = 3, edgeList = [[0,1,2],[1,2,4],[2,0,8],[1,0,16]], queries = [[0,1,2],[0,2,5]]\nOutput: [false,true]\nExplanation: The above figure shows the given graph. Note that there are two overlapping edges between 0 and 1 with distances 2 and 16.\nFor the first query, between 0 and 1 there is no path where each distance is less than 2, thus we return false for this query.\nFor the second query, there is a path (0 -> 1 -> 2) of two edges with distances less than 5, thus we return true for this query.", + "Example 2:\nInput: n = 5, edgeList = [[0,1,10],[1,2,5],[2,3,9],[3,4,13]], queries = [[0,4,14],[1,4,13]]\nOutput: [true,false]\nExplanation: The above figure shows the given graph." + ], + "constraints": "Constraints:\n\n2 <= n <= 10^5\n1 <= edgeList.length, queries.length <= 10^5\nedgeList[i].length == 3\nqueries[j].length == 3\n0 <= ui, vi, pj, qj <= n - 1\nui != vi\npj != qj\n1 <= disi, limitj <= 10^9\nThere may be multiple edges between two nodes.", + "tags": [ + "Array", + "Two Pointers", + "Union Find", + "Graph", + "Sorting" + ], + "title-slug": "checking-existence-of-edge-length-limited-paths" + }, + { + "leetcode-id": 1700, + "title": "Number of Students Unable to Eat Lunch", + "difficulty": 1, + "description": "The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.\nThe number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a stack. At each step:\n\nIf the student at the front of the queue prefers the sandwich on the top of the stack, they will take it and leave the queue.\nOtherwise, they will leave it and go to the queue's end.\n\nThis continues until none of the queue students want to take the top sandwich and are thus unable to eat.\nYou are given two integer arrays students and sandwiches where sandwiches[i] is the type of the i^\u200b\u200b\u200b\u200b\u200b\u200bth sandwich in the stack (i = 0 is the top of the stack) and students[j] is the preference of the j^\u200b\u200b\u200b\u200b\u200b\u200bth student in the initial queue (j = 0 is the front of the queue). Return the number of students that are unable to eat.", + "examples": [ + "Example 1:\nInput: students = [1,1,0,0], sandwiches = [0,1,0,1]\nOutput: 0 \nExplanation:\n- Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].\n- Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0].\n- Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [0,1].\n- Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1].\n- Front student takes the top sandwich and leaves the line making students = [] and sandwiches = [].\nHence all students are able to eat.", + "Example 2:\nInput: students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= students.length, sandwiches.length <= 100\nstudents.length == sandwiches.length\nsandwiches[i] is 0 or 1.\nstudents[i] is 0 or 1.", + "tags": [ + "Array", + "Stack", + "Queue", + "Simulation" + ], + "title-slug": "number-of-students-unable-to-eat-lunch" + }, + { + "leetcode-id": 1701, + "title": "Average Waiting Time", + "difficulty": 2, + "description": "There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrivali, timei]:\n\narrivali is the arrival time of the i^th customer. The arrival times are sorted in non-decreasing order.\ntimei is the time needed to prepare the order of the i^th customer.\n\nWhen a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits till the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers in the order they were given in the input.\nReturn the average waiting time of all customers. Solutions within 10^-5 from the actual answer are considered accepted.", + "examples": [ + "Example 1:\nInput: customers = [[1,2],[2,5],[4,3]]\nOutput: 5.00000\nExplanation:\n1) The first customer arrives at time 1, the chef takes his order and starts preparing it immediately at time 1, and finishes at time 3, so the waiting time of the first customer is 3 - 1 = 2.\n2) The second customer arrives at time 2, the chef takes his order and starts preparing it at time 3, and finishes at time 8, so the waiting time of the second customer is 8 - 2 = 6.\n3) The third customer arrives at time 4, the chef takes his order and starts preparing it at time 8, and finishes at time 11, so the waiting time of the third customer is 11 - 4 = 7.\nSo the average waiting time = (2 + 6 + 7) / 3 = 5.", + "Example 2:\nInput: customers = [[5,2],[5,4],[10,3],[20,1]]\nOutput: 3.25000\nExplanation:\n1) The first customer arrives at time 5, the chef takes his order and starts preparing it immediately at time 5, and finishes at time 7, so the waiting time of the first customer is 7 - 5 = 2.\n2) The second customer arrives at time 5, the chef takes his order and starts preparing it at time 7, and finishes at time 11, so the waiting time of the second customer is 11 - 5 = 6.\n3) The third customer arrives at time 10, the chef takes his order and starts preparing it at time 11, and finishes at time 14, so the waiting time of the third customer is 14 - 10 = 4.\n4) The fourth customer arrives at time 20, the chef takes his order and starts preparing it immediately at time 20, and finishes at time 21, so the waiting time of the fourth customer is 21 - 20 = 1.\nSo the average waiting time = (2 + 6 + 4 + 1) / 4 = 3.25." + ], + "constraints": "Constraints:\n\n1 <= customers.length <= 10^5\n1 <= arrivali, timei <= 10^4\narrivali\u00a0<= arrivali+1", + "tags": [ + "Array", + "Simulation" + ], + "title-slug": "average-waiting-time" + }, + { + "leetcode-id": 1702, + "title": "Maximum Binary String After Change", + "difficulty": 2, + "description": "You are given a binary string binary consisting of only 0's or 1's. You can apply each of the following operations any number of times:\n\nOperation 1: If the number contains the substring \"00\", you can replace it with \"10\".\n\n\t\nFor example, \"00010\" -> \"10010\"\n\n\nOperation 2: If the number contains the substring \"10\", you can replace it with \"01\".\n\t\nFor example, \"00010\" -> \"00001\"\n\n\n\nReturn the maximum binary string you can obtain after any number of operations. Binary string x is greater than binary string y if x's decimal representation is greater than y's decimal representation.", + "examples": [ + "Example 1:\nInput: binary = \"000110\"\nOutput: \"111011\"\nExplanation: A valid transformation sequence can be:\n\"000110\" -> \"000101\" \n\"000101\" -> \"100101\" \n\"100101\" -> \"110101\" \n\"110101\" -> \"110011\" \n\"110011\" -> \"111011\"", + "Example 2:\nInput: binary = \"01\"\nOutput: \"01\"\nExplanation:\u00a0\"01\" cannot be transformed any further." + ], + "constraints": "Constraints:\n\n1 <= binary.length <= 10^5\nbinary consist of '0' and '1'.", + "tags": [ + "String", + "Greedy" + ], + "title-slug": "maximum-binary-string-after-change" + }, + { + "leetcode-id": 1703, + "title": "Minimum Adjacent Swaps for K Consecutive Ones", + "difficulty": 3, + "description": "You are given an integer array, nums, and an integer k. nums comprises of only 0's and 1's. In one move, you can choose two adjacent indices and swap their values.\nReturn the minimum number of moves required so that nums has k consecutive 1's.", + "examples": [ + "Example 1:\nInput: nums = [1,0,0,1,0,1], k = 2\nOutput: 1\nExplanation: In 1 move, nums could be [1,0,0,0,1,1] and have 2 consecutive 1's.", + "Example 2:\nInput: nums = [1,0,0,0,0,0,1,1], k = 3\nOutput: 5\nExplanation: In 5 moves, the leftmost 1 can be shifted right until nums = [0,0,0,0,0,1,1,1].", + "Example 3:\nInput: nums = [1,1,0,1], k = 2\nOutput: 0\nExplanation: nums already has 2 consecutive 1's." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\nnums[i] is 0 or 1.\n1 <= k <= sum(nums)", + "tags": [ + "Array", + "Greedy", + "Sliding Window", + "Prefix Sum" + ], + "title-slug": "minimum-adjacent-swaps-for-k-consecutive-ones" + }, + { + "leetcode-id": 1704, + "title": "Determine if String Halves Are Alike", + "difficulty": 1, + "description": "You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half.\nTwo strings are alike if they have the same number of vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). Notice that s contains uppercase and lowercase letters.\nReturn true if a and b are alike. Otherwise, return false.", + "examples": [ + "Example 1:\nInput: s = \"book\"\nOutput: true\nExplanation: a = \"bo\" and b = \"ok\". a has 1 vowel and b has 1 vowel. Therefore, they are alike.", + "Example 2:\nInput: s = \"textbook\"\nOutput: false\nExplanation: a = \"text\" and b = \"book\". a has 1 vowel whereas b has 2. Therefore, they are not alike.\nNotice that the vowel o is counted twice." + ], + "constraints": "Constraints:\n\n2 <= s.length <= 1000\ns.length is even.\ns consists of uppercase and lowercase letters.", + "tags": [ + "String", + "Counting" + ], + "title-slug": "determine-if-string-halves-are-alike" + }, + { + "leetcode-id": 1705, + "title": "Maximum Number of Eaten Apples", + "difficulty": 2, + "description": "There is a special kind of apple tree that grows apples every day for n days. On the i^th day, the tree grows apples[i] apples that will rot after days[i] days, that is on day i + days[i] the apples will be rotten and cannot be eaten. On some days, the apple tree does not grow any apples, which are denoted by apples[i] == 0 and days[i] == 0.\nYou decided to eat at most one apple a day (to keep the doctors away). Note that you can keep eating after the first n days.\nGiven two integer arrays days and apples of length n, return the maximum number of apples you can eat.", + "examples": [ + "Example 1:\nInput: apples = [1,2,3,5,2], days = [3,2,1,4,2]\nOutput: 7\nExplanation: You can eat 7 apples:\n- On the first day, you eat an apple that grew on the first day.\n- On the second day, you eat an apple that grew on the second day.\n- On the third day, you eat an apple that grew on the second day. After this day, the apples that grew on the third day rot.\n- On the fourth to the seventh days, you eat apples that grew on the fourth day.", + "Example 2:\nInput: apples = [3,0,0,0,0,2], days = [3,0,0,0,0,2]\nOutput: 5\nExplanation: You can eat 5 apples:\n- On the first to the third day you eat apples that grew on the first day.\n- Do nothing on the fouth and fifth days.\n- On the sixth and seventh days you eat apples that grew on the sixth day." + ], + "constraints": "Constraints:\n\nn == apples.length == days.length\n1 <= n <= 2 * 10^4\n0 <= apples[i], days[i] <= 2 * 10^4\ndays[i] = 0 if and only if apples[i] = 0.", + "tags": [ + "Array", + "Greedy", + "Heap (Priority Queue)" + ], + "title-slug": "maximum-number-of-eaten-apples" + }, + { + "leetcode-id": 1706, + "title": "Where Will the Ball Fall", + "difficulty": 2, + "description": "You have a 2-D grid of size m x n representing a box, and you have n balls. The box is open on the top and bottom sides.\nEach cell in the box has a diagonal board spanning two corners of the cell that can redirect a ball to the right or to the left.\n\nA board that redirects the ball to the right spans the top-left corner to the bottom-right corner and is represented in the grid as 1.\nA board that redirects the ball to the left spans the top-right corner to the bottom-left corner and is represented in the grid as -1.\n\nWe drop one ball at the top of each column of the box. Each ball can get stuck in the box or fall out of the bottom. A ball gets stuck if it hits a \"V\" shaped pattern between two boards or if a board redirects the ball into either wall of the box.\nReturn an array answer of size n where answer[i] is the column that the ball falls out of at the bottom after dropping the ball from the i^th column at the top, or -1 if the ball gets stuck in the box.", + "examples": [ + "Example 1:\nInput: grid = [[1,1,1,-1,-1],[1,1,1,-1,-1],[-1,-1,-1,1,1],[1,1,1,1,-1],[-1,-1,-1,-1,-1]]\nOutput: [1,-1,-1,-1,-1]\nExplanation: This example is shown in the photo.\nBall b0 is dropped at column 0 and falls out of the box at column 1.\nBall b1 is dropped at column 1 and will get stuck in the box between column 2 and 3 and row 1.\nBall b2 is dropped at column 2 and will get stuck on the box between column 2 and 3 and row 0.\nBall b3 is dropped at column 3 and will get stuck on the box between column 2 and 3 and row 0.\nBall b4 is dropped at column 4 and will get stuck on the box between column 2 and 3 and row 1.", + "Example 2:\nInput: grid = [[-1]]\nOutput: [-1]\nExplanation: The ball gets stuck against the left wall.", + "Example 3:\nInput: grid = [[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1],[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1]]\nOutput: [0,1,2,3,4,-1]" + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 100\ngrid[i][j] is 1 or -1.", + "tags": [ + "Array", + "Dynamic Programming", + "Depth-First Search", + "Matrix", + "Simulation" + ], + "title-slug": "where-will-the-ball-fall" + }, + { + "leetcode-id": 1707, + "title": "Maximum XOR With an Element From Array", + "difficulty": 3, + "description": "You are given an array nums consisting of non-negative integers. You are also given a queries array, where queries[i] = [xi, mi].\nThe answer to the i^th query is the maximum bitwise XOR value of xi and any element of nums that does not exceed mi. In other words, the answer is max(nums[j] XOR xi) for all j such that nums[j] <= mi. If all elements in nums are larger than mi, then the answer is -1.\nReturn an integer array answer where answer.length == queries.length and answer[i] is the answer to the i^th query.", + "examples": [ + "Example 1:\nInput: nums = [0,1,2,3,4], queries = [[3,1],[1,3],[5,6]]\nOutput: [3,3,7]\nExplanation:\n1) 0 and 1 are the only two integers not greater than 1. 0 XOR 3 = 3 and 1 XOR 3 = 2. The larger of the two is 3.\n2) 1 XOR 2 = 3.\n3) 5 XOR 2 = 7.", + "Example 2:\nInput: nums = [5,2,4,6,6,3], queries = [[12,4],[8,1],[6,3]]\nOutput: [15,-1,5]" + ], + "constraints": "Constraints:\n\n1 <= nums.length, queries.length <= 10^5\nqueries[i].length == 2\n0 <= nums[j], xi, mi <= 10^9", + "tags": [ + "Array", + "Bit Manipulation", + "Trie" + ], + "title-slug": "maximum-xor-with-an-element-from-array" + }, + { + "leetcode-id": 1710, + "title": "Maximum Units on a Truck", + "difficulty": 1, + "description": "You are assigned to put some amount of boxes onto one truck. You are given a 2D array boxTypes, where boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi]:\n\nnumberOfBoxesi is the number of boxes of type i.\nnumberOfUnitsPerBoxi is the number of units in each box of the type i.\n\nYou are also given an integer truckSize, which is the maximum number of boxes that can be put on the truck. You can choose any boxes to put on the truck as long as the number\u00a0of boxes does not exceed truckSize.\nReturn the maximum total number of units that can be put on the truck.", + "examples": [ + "Example 1:\nInput: boxTypes = [[1,3],[2,2],[3,1]], truckSize = 4\nOutput: 8\nExplanation: There are:\n- 1 box of the first type that contains 3 units.\n- 2 boxes of the second type that contain 2 units each.\n- 3 boxes of the third type that contain 1 unit each.\nYou can take all the boxes of the first and second types, and one box of the third type.\nThe total number of units will be = (1 * 3) + (2 * 2) + (1 * 1) = 8.", + "Example 2:\nInput: boxTypes = [[5,10],[2,5],[4,7],[3,9]], truckSize = 10\nOutput: 91" + ], + "constraints": "Constraints:\n\n1 <= boxTypes.length <= 1000\n1 <= numberOfBoxesi, numberOfUnitsPerBoxi <= 1000\n1 <= truckSize <= 10^6", + "tags": [ + "Array", + "Greedy", + "Sorting" + ], + "title-slug": "maximum-units-on-a-truck" + }, + { + "leetcode-id": 1711, + "title": "Count Good Meals", + "difficulty": 2, + "description": "A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two.\nYou can pick any two different foods to make a good meal.\nGiven an array of integers deliciousness where deliciousness[i] is the deliciousness of the i^\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b item of food, return the number of different good meals you can make from this list modulo 10^9 + 7.\nNote that items with different indices are considered different even if they have the same deliciousness value.", + "examples": [ + "Example 1:\nInput: deliciousness = [1,3,5,7,9]\nOutput: 4\nExplanation: The good meals are (1,3), (1,7), (3,5) and, (7,9).\nTheir respective sums are 4, 8, 8, and 16, all of which are powers of 2.", + "Example 2:\nInput: deliciousness = [1,1,1,3,3,3,7]\nOutput: 15\nExplanation: The good meals are (1,1) with 3 ways, (1,3) with 9 ways, and (1,7) with 3 ways." + ], + "constraints": "Constraints:\n\n1 <= deliciousness.length <= 10^5\n0 <= deliciousness[i] <= 2^20", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "count-good-meals" + }, + { + "leetcode-id": 1712, + "title": "Ways to Split Array Into Three Subarrays", + "difficulty": 2, + "description": "A split of an integer array is good if:\n\nThe array is split into three non-empty contiguous subarrays - named left, mid, right respectively from left to right.\nThe sum of the elements in left is less than or equal to the sum of the elements in mid, and the sum of the elements in mid is less than or equal to the sum of the elements in right.\n\nGiven nums, an array of non-negative integers, return the number of good ways to split nums. As the number may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: nums = [1,1,1]\nOutput: 1\nExplanation: The only good way to split nums is [1] [1] [1].", + "Example 2:\nInput: nums = [1,2,2,2,5,0]\nOutput: 3\nExplanation: There are three good ways of splitting nums:\n[1] [2] [2,2,5,0]\n[1] [2,2] [2,5,0]\n[1,2] [2,2] [5,0]", + "Example 3:\nInput: nums = [3,2,1]\nOutput: 0\nExplanation: There is no good way to split nums." + ], + "constraints": "Constraints:\n\n3 <= nums.length <= 10^5\n0 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Prefix Sum" + ], + "title-slug": "ways-to-split-array-into-three-subarrays" + }, + { + "leetcode-id": 1713, + "title": "Minimum Operations to Make a Subsequence", + "difficulty": 3, + "description": "You are given an array target that consists of distinct integers and another integer array arr that can have duplicates.\nIn one operation, you can insert any integer at any position in arr. For example, if arr = [1,4,1,2], you can add 3 in the middle and make it [1,4,3,1,2]. Note that you can insert the integer at the very beginning or end of the array.\nReturn the minimum number of operations needed to make target a subsequence of arr.\nA subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order. For example, [2,7,4] is a subsequence of [4,2,3,7,2,1,4] (the underlined elements), while [2,4,2] is not.", + "examples": [ + "Example 1:\nInput: target = [5,1,3], arr = [9,4,2,3,4]\nOutput: 2\nExplanation: You can add 5 and 1 in such a way that makes arr = [5,9,4,1,2,3,4], then target will be a subsequence of arr.", + "Example 2:\nInput: target = [6,4,8,1,3,2], arr = [4,7,6,2,3,8,6,1]\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= target.length, arr.length <= 10^5\n1 <= target[i], arr[i] <= 10^9\ntarget contains no duplicates.", + "tags": [ + "Array", + "Hash Table", + "Binary Search", + "Greedy" + ], + "title-slug": "minimum-operations-to-make-a-subsequence" + }, + { + "leetcode-id": 1716, + "title": "Calculate Money in Leetcode Bank", + "difficulty": 1, + "description": "Hercy wants to save money for his first car. He puts money in the Leetcode\u00a0bank every day.\nHe starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sunday, he will put in $1 more than the day before. On every subsequent Monday, he will put in $1 more than the previous Monday. \nGiven n, return the total amount of money he will have in the Leetcode bank at the end of the n^th day.", + "examples": [ + "Example 1:\nInput: n = 4\nOutput: 10\nExplanation:\u00a0After the 4^th day, the total is 1 + 2 + 3 + 4 = 10.", + "Example 2:\nInput: n = 10\nOutput: 37\nExplanation:\u00a0After the 10^th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4) = 37. Notice that on the 2^nd Monday, Hercy only puts in $2.", + "Example 3:\nInput: n = 20\nOutput: 96\nExplanation:\u00a0After the 20^th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4 + 5 + 6 + 7 + 8) + (3 + 4 + 5 + 6 + 7 + 8) = 96." + ], + "constraints": "Constraints:\n\n1 <= n <= 1000", + "tags": [ + "Math" + ], + "title-slug": "calculate-money-in-leetcode-bank" + }, + { + "leetcode-id": 1717, + "title": "Maximum Score From Removing Substrings", + "difficulty": 2, + "description": "You are given a string s and two integers x and y. You can perform two types of operations any number of times.\n\nRemove substring \"ab\" and gain x points.\n\n\t\nFor example, when removing \"ab\" from \"cabxbae\" it becomes \"cxbae\".\n\n\nRemove substring \"ba\" and gain y points.\n\t\nFor example, when removing \"ba\" from \"cabxbae\" it becomes \"cabxe\".\n\n\n\nReturn the maximum points you can gain after applying the above operations on s.", + "examples": [ + "Example 1:\nInput: s = \"cdbcbbaaabab\", x = 4, y = 5\nOutput: 19\nExplanation:\n- Remove the \"ba\" underlined in \"cdbcbbaaabab\". Now, s = \"cdbcbbaaab\" and 5 points are added to the score.\n- Remove the \"ab\" underlined in \"cdbcbbaaab\". Now, s = \"cdbcbbaa\" and 4 points are added to the score.\n- Remove the \"ba\" underlined in \"cdbcbbaa\". Now, s = \"cdbcba\" and 5 points are added to the score.\n- Remove the \"ba\" underlined in \"cdbcba\". Now, s = \"cdbc\" and 5 points are added to the score.\nTotal score = 5 + 4 + 5 + 5 = 19.", + "Example 2:\nInput: s = \"aabbaaxybbaabb\", x = 5, y = 4\nOutput: 20" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\n1 <= x, y <= 10^4\ns consists of lowercase English letters.", + "tags": [ + "String", + "Stack", + "Greedy" + ], + "title-slug": "maximum-score-from-removing-substrings" + }, + { + "leetcode-id": 1718, + "title": "Construct the Lexicographically Largest Valid Sequence", + "difficulty": 2, + "description": "Given an integer n, find a sequence that satisfies all of the following:\n\nThe integer 1 occurs once in the sequence.\nEach integer between 2 and n occurs twice in the sequence.\nFor every integer i between 2 and n, the distance between the two occurrences of i is exactly i.\n\nThe distance between two numbers on the sequence, a[i] and a[j], is the absolute difference of their indices, |j - i|.\nReturn the lexicographically largest sequence. It is guaranteed that under the given constraints, there is always a solution. \nA sequence a is lexicographically larger than a sequence b (of the same length) if in the first position where a and b differ, sequence a has a number greater than the corresponding number in b. For example, [0,1,9,0] is lexicographically larger than [0,1,5,6] because the first position they differ is at the third number, and 9 is greater than 5.", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: [3,1,2,3,2]\nExplanation: [2,3,2,1,3] is also a valid sequence, but [3,1,2,3,2] is the lexicographically largest valid sequence.", + "Example 2:\nInput: n = 5\nOutput: [5,3,1,4,3,5,2,4,2]" + ], + "constraints": "Constraints:\n\n1 <= n <= 20", + "tags": [ + "Array", + "Backtracking" + ], + "title-slug": "construct-the-lexicographically-largest-valid-sequence" + }, + { + "leetcode-id": 1719, + "title": "Number Of Ways To Reconstruct A Tree", + "difficulty": 3, + "description": "You are given an array pairs, where pairs[i] = [xi, yi], and:\n\nThere are no duplicates.\nxi < yi\n\nLet ways be the number of rooted trees that satisfy the following conditions:\n\nThe tree consists of nodes whose values appeared in pairs.\nA pair [xi, yi] exists in pairs if and only if xi is an ancestor of yi or yi is an ancestor of xi.\nNote: the tree does not have to be a binary tree.\n\nTwo ways are considered to be different if there is at least one node that has different parents in both ways.\nReturn:\n\n0 if ways == 0\n1 if ways == 1\n2 if ways > 1\n\nA rooted tree is a tree that has a single root node, and all edges are oriented to be outgoing from the root.\nAn ancestor of a node is any node on the path from the root to that node (excluding the node itself). The root has no ancestors.", + "examples": [ + "Example 1:\nInput: pairs = [[1,2],[2,3]]\nOutput: 1\nExplanation: There is exactly one valid rooted tree, which is shown in the above figure.", + "Example 2:\nInput: pairs = [[1,2],[2,3],[1,3]]\nOutput: 2\nExplanation: There are multiple valid rooted trees. Three of them are shown in the above figures.", + "Example 3:\nInput: pairs = [[1,2],[2,3],[2,4],[1,5]]\nOutput: 0\nExplanation: There are no valid rooted trees." + ], + "constraints": "Constraints:\n\n1 <= pairs.length <= 10^5\n1 <= xi < yi <= 500\nThe elements in pairs are unique.", + "tags": [ + "Tree", + "Graph" + ], + "title-slug": "number-of-ways-to-reconstruct-a-tree" + }, + { + "leetcode-id": 1720, + "title": "Decode XORed Array", + "difficulty": 1, + "description": "There is a hidden integer array arr that consists of n non-negative integers.\nIt was encoded into another integer array encoded of length n - 1, such that encoded[i] = arr[i] XOR arr[i + 1]. For example, if arr = [1,0,2,1], then encoded = [1,2,3].\nYou are given the encoded array. You are also given an integer first, that is the first element of arr, i.e. arr[0].\nReturn the original array arr. It can be proved that the answer exists and is unique.", + "examples": [ + "Example 1:\nInput: encoded = [1,2,3], first = 1\nOutput: [1,0,2,1]\nExplanation: If arr = [1,0,2,1], then first = 1 and encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3]", + "Example 2:\nInput: encoded = [6,2,7,3], first = 4\nOutput: [4,2,0,7,4]" + ], + "constraints": "Constraints:\n\n2 <= n <= 10^4\nencoded.length == n - 1\n0 <= encoded[i] <= 10^5\n0 <= first <= 10^5", + "tags": [ + "Array", + "Bit Manipulation" + ], + "title-slug": "decode-xored-array" + }, + { + "leetcode-id": 1721, + "title": "Swapping Nodes in a Linked List", + "difficulty": 2, + "description": "You are given the head of a linked list, and an integer k.\nReturn the head of the linked list after swapping the values of the k^th node from the beginning and the k^th node from the end (the list is 1-indexed).", + "examples": [ + "Example 1:\nInput: head = [1,2,3,4,5], k = 2\nOutput: [1,4,3,2,5]", + "Example 2:\nInput: head = [7,9,6,6,7,8,3,0,9,5], k = 5\nOutput: [7,9,6,6,8,7,3,0,9,5]" + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is n.\n1 <= k <= n <= 10^5\n0 <= Node.val <= 100", + "tags": [ + "Linked List", + "Two Pointers" + ], + "title-slug": "swapping-nodes-in-a-linked-list" + }, + { + "leetcode-id": 1722, + "title": "Minimize Hamming Distance After Swap Operations", + "difficulty": 2, + "description": "You are given two integer arrays, source and target, both of length n. You are also given an array allowedSwaps where each allowedSwaps[i] = [ai, bi] indicates that you are allowed to swap the elements at index ai and index bi (0-indexed) of array source. Note that you can swap elements at a specific pair of indices multiple times and in any order.\nThe Hamming distance of two arrays of the same length, source and target, is the number of positions where the elements are different. Formally, it is the number of indices i for 0 <= i <= n-1 where source[i] != target[i] (0-indexed).\nReturn the minimum Hamming distance of source and target after performing any amount of swap operations on array source.", + "examples": [ + "Example 1:\nInput: source = [1,2,3,4], target = [2,1,4,5], allowedSwaps = [[0,1],[2,3]]\nOutput: 1\nExplanation: source can be transformed the following way:\n- Swap indices 0 and 1: source = [2,1,3,4]\n- Swap indices 2 and 3: source = [2,1,4,3]\nThe Hamming distance of source and target is 1 as they differ in 1 position: index 3.", + "Example 2:\nInput: source = [1,2,3,4], target = [1,3,2,4], allowedSwaps = []\nOutput: 2\nExplanation: There are no allowed swaps.\nThe Hamming distance of source and target is 2 as they differ in 2 positions: index 1 and index 2.", + "Example 3:\nInput: source = [5,1,2,4,3], target = [1,5,4,2,3], allowedSwaps = [[0,4],[4,2],[1,3],[1,4]]\nOutput: 0" + ], + "constraints": "Constraints:\n\nn == source.length == target.length\n1 <= n <= 10^5\n1 <= source[i], target[i] <= 10^5\n0 <= allowedSwaps.length <= 10^5\nallowedSwaps[i].length == 2\n0 <= ai, bi <= n - 1\nai != bi", + "tags": [ + "Array", + "Depth-First Search", + "Union Find" + ], + "title-slug": "minimize-hamming-distance-after-swap-operations" + }, + { + "leetcode-id": 1723, + "title": "Find Minimum Time to Finish All Jobs", + "difficulty": 3, + "description": "You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete the i^th job.\nThere are k workers that you can assign jobs to. Each job should be assigned to exactly one worker. The working time of a worker is the sum of the time it takes to complete all jobs assigned to them. Your goal is to devise an optimal assignment such that the maximum working time of any worker is minimized.\nReturn the minimum possible maximum working time of any assignment.", + "examples": [ + "Example 1:\nInput: jobs = [3,2,3], k = 3\nOutput: 3\nExplanation: By assigning each person one job, the maximum time is 3.", + "Example 2:\nInput: jobs = [1,2,4,7,8], k = 2\nOutput: 11\nExplanation: Assign the jobs the following way:\nWorker 1: 1, 2, 8 (working time = 1 + 2 + 8 = 11)\nWorker 2: 4, 7 (working time = 4 + 7 = 11)\nThe maximum working time is 11." + ], + "constraints": "Constraints:\n\n1 <= k <= jobs.length <= 12\n1 <= jobs[i] <= 10^7", + "tags": [ + "Array", + "Dynamic Programming", + "Backtracking", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "find-minimum-time-to-finish-all-jobs" + }, + { + "leetcode-id": 1725, + "title": "Number Of Rectangles That Can Form The Largest Square", + "difficulty": 1, + "description": "You are given an array rectangles where rectangles[i] = [li, wi] represents the i^th rectangle of length li and width wi.\nYou can cut the i^th rectangle to form a square with a side length of k if both k <= li and k <= wi. For example, if you have a rectangle [4,6], you can cut it to get a square with a side length of at most 4.\nLet maxLen be the side length of the largest square you can obtain from any of the given rectangles.\nReturn the number of rectangles that can make a square with a side length of maxLen.", + "examples": [ + "Example 1:\nInput: rectangles = [[5,8],[3,9],[5,12],[16,5]]\r\nOutput: 3\r\nExplanation: The largest squares you can get from each rectangle are of lengths [5,3,5,5].\r\nThe largest possible square is of length 5, and you can get it out of 3 rectangles.", + "Example 2:\nInput: rectangles = [[2,3],[3,7],[4,3],[3,7]]\r\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= rectangles.length <= 1000\nrectangles[i].length == 2\n1 <= li, wi <= 10^9\nli != wi", + "tags": [ + "Array" + ], + "title-slug": "number-of-rectangles-that-can-form-the-largest-square" + }, + { + "leetcode-id": 1726, + "title": "Tuple with Same Product", + "difficulty": 2, + "description": "Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d.", + "examples": [ + "Example 1:\nInput: nums = [2,3,4,6]\nOutput: 8\nExplanation: There are 8 valid tuples:\n(2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3)\n(3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2)", + "Example 2:\nInput: nums = [1,2,4,5,10]\nOutput: 16\nExplanation: There are 16 valid tuples:\n(1,10,2,5) , (1,10,5,2) , (10,1,2,5) , (10,1,5,2)\n(2,5,1,10) , (2,5,10,1) , (5,2,1,10) , (5,2,10,1)\n(2,10,4,5) , (2,10,5,4) , (10,2,4,5) , (10,2,5,4)\n(4,5,2,10) , (4,5,10,2) , (5,4,2,10) , (5,4,10,2)" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 10^4\nAll elements in nums are distinct.", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "tuple-with-same-product" + }, + { + "leetcode-id": 1727, + "title": "Largest Submatrix With Rearrangements", + "difficulty": 2, + "description": "You are given a binary matrix matrix of size m x n, and you are allowed to rearrange the columns of the matrix in any order.\nReturn the area of the largest submatrix within matrix where every element of the submatrix is 1 after reordering the columns optimally.", + "examples": [ + "Example 1:\nInput: matrix = [[0,0,1],[1,1,1],[1,0,1]]\nOutput: 4\nExplanation: You can rearrange the columns as shown above.\nThe largest submatrix of 1s, in bold, has an area of 4.", + "Example 2:\nInput: matrix = [[1,0,1,0,1]]\nOutput: 3\nExplanation: You can rearrange the columns as shown above.\nThe largest submatrix of 1s, in bold, has an area of 3.", + "Example 3:\nInput: matrix = [[1,1,0],[1,0,1]]\nOutput: 2\nExplanation: Notice that you must rearrange entire columns, and there is no way to make a submatrix of 1s larger than an area of 2." + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= m * n <= 10^5\nmatrix[i][j] is either 0 or 1.", + "tags": [ + "Array", + "Greedy", + "Sorting", + "Matrix" + ], + "title-slug": "largest-submatrix-with-rearrangements" + }, + { + "leetcode-id": 1728, + "title": "Cat and Mouse II", + "difficulty": 3, + "description": "A game is played by a cat and a mouse named Cat and Mouse.\nThe environment is represented by a grid of size rows x cols, where each element is a wall, floor, player (Cat, Mouse), or food.\n\nPlayers are represented by the characters 'C'(Cat),'M'(Mouse).\nFloors are represented by the character '.' and can be walked on.\nWalls are represented by the character '#' and cannot be walked on.\nFood is represented by the character 'F' and can be walked on.\nThere is only one of each character 'C', 'M', and 'F' in grid.\n\nMouse and Cat play according to the following rules:\n\nMouse moves first, then they take turns to move.\nDuring each turn, Cat and Mouse can jump in one of the four directions (left, right, up, down). They cannot jump over the wall nor outside of the grid.\ncatJump, mouseJump are the maximum lengths Cat and Mouse can jump at a time, respectively. Cat and Mouse can jump less than the maximum length.\nStaying in the same position is allowed.\nMouse can jump over Cat.\n\nThe game can end in 4 ways:\n\nIf Cat occupies the same position as Mouse, Cat wins.\nIf Cat reaches the food first, Cat wins.\nIf Mouse reaches the food first, Mouse wins.\nIf Mouse cannot get to the food within 1000 turns, Cat wins.\n\nGiven a rows x cols matrix grid and two integers catJump and mouseJump, return true if Mouse can win the game if both Cat and Mouse play optimally, otherwise return false.", + "examples": [ + "Example 1:\nInput: grid = [\"####F\",\"#C...\",\"M....\"], catJump = 1, mouseJump = 2\nOutput: true\nExplanation: Cat cannot catch Mouse on its turn nor can it get the food before Mouse.", + "Example 2:\nInput: grid = [\"M.C...F\"], catJump = 1, mouseJump = 4\nOutput: true", + "Example 3:\nInput: grid = [\"M.C...F\"], catJump = 1, mouseJump = 3\nOutput: false" + ], + "constraints": "Constraints:\n\nrows == grid.length\ncols = grid[i].length\n1 <= rows, cols <= 8\ngrid[i][j] consist only of characters 'C', 'M', 'F', '.', and '#'.\nThere is only one of each character 'C', 'M', and 'F' in grid.\n1 <= catJump, mouseJump <= 8", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Graph", + "Topological Sort", + "Memoization", + "Matrix", + "Game Theory" + ], + "title-slug": "cat-and-mouse-ii" + }, + { + "leetcode-id": 1732, + "title": "Find the Highest Altitude", + "difficulty": 1, + "description": "There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitude equal 0.\nYou are given an integer array gain of length n where gain[i] is the net gain in altitude between points i\u200b\u200b\u200b\u200b\u200b\u200b and i + 1 for all (0 <= i < n). Return the highest altitude of a point.", + "examples": [ + "Example 1:\nInput: gain = [-5,1,5,0,-7]\nOutput: 1\nExplanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.", + "Example 2:\nInput: gain = [-4,-3,-2,-1,4,3,2]\nOutput: 0\nExplanation: The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0." + ], + "constraints": "Constraints:\n\nn == gain.length\n1 <= n <= 100\n-100 <= gain[i] <= 100", + "tags": [ + "Array", + "Prefix Sum" + ], + "title-slug": "find-the-highest-altitude" + }, + { + "leetcode-id": 1733, + "title": "Minimum Number of People to Teach", + "difficulty": 2, + "description": "On a social network consisting of m users and some friendships between users, two users can communicate with each other if they know a common language.\nYou are given an integer n, an array languages, and an array friendships where:\n\nThere are n languages numbered 1 through n,\nlanguages[i] is the set of languages the i^\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b user knows, and\nfriendships[i] = [u\u200b\u200b\u200b\u200b\u200b\u200bi\u200b\u200b\u200b, v\u200b\u200b\u200b\u200b\u200b\u200bi] denotes a friendship between the users u^\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bi\u200b\u200b\u200b\u200b\u200b and vi.\n\nYou can choose one language and teach it to some users so that all friends can communicate with each other. Return the minimum number of users you need to teach.\nNote that friendships are not transitive, meaning if x is a friend of y and y is a friend of z, this doesn't guarantee that x is a friend of z.", + "examples": [ + "Example 1:\nInput: n = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]]\nOutput: 1\nExplanation: You can either teach user 1 the second language or user 2 the first language.", + "Example 2:\nInput: n = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]]\nOutput: 2\nExplanation: Teach the third language to users 1 and 3, yielding two users to teach." + ], + "constraints": "Constraints:\n\n2 <= n <= 500\nlanguages.length == m\n1 <= m <= 500\n1 <= languages[i].length <= n\n1 <= languages[i][j] <= n\n1 <= u\u200b\u200b\u200b\u200b\u200b\u200bi < v\u200b\u200b\u200b\u200b\u200b\u200bi <= languages.length\n1 <= friendships.length <= 500\nAll tuples (u\u200b\u200b\u200b\u200b\u200bi, v\u200b\u200b\u200b\u200b\u200b\u200bi) are unique\nlanguages[i] contains only unique values", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "minimum-number-of-people-to-teach" + }, + { + "leetcode-id": 1734, + "title": "Decode XORed Permutation", + "difficulty": 2, + "description": "There is an integer array perm that is a permutation of the first n positive integers, where n is always odd.\nIt was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[i + 1]. For example, if perm = [1,3,2], then encoded = [2,1].\nGiven the encoded array, return the original array perm. It is guaranteed that the answer exists and is unique.", + "examples": [ + "Example 1:\nInput: encoded = [3,1]\nOutput: [1,2,3]\nExplanation: If perm = [1,2,3], then encoded = [1 XOR 2,2 XOR 3] = [3,1]", + "Example 2:\nInput: encoded = [6,5,4,6]\nOutput: [2,4,1,5,3]" + ], + "constraints": "Constraints:\n\n3 <= n <\u00a010^5\nn\u00a0is odd.\nencoded.length == n - 1", + "tags": [ + "Array", + "Bit Manipulation" + ], + "title-slug": "decode-xored-permutation" + }, + { + "leetcode-id": 1735, + "title": "Count Ways to Make Array With Product", + "difficulty": 3, + "description": "You are given a 2D integer array, queries. For each queries[i], where queries[i] = [ni, ki], find the number of different ways you can place positive integers into an array of size ni such that the product of the integers is ki. As the number of ways may be too large, the answer to the i^th query is the number of ways modulo 10^9 + 7.\nReturn an integer array answer where answer.length == queries.length, and answer[i] is the answer to the i^th query.", + "examples": [ + "Example 1:\nInput: queries = [[2,6],[5,1],[73,660]]\nOutput: [4,1,50734910]\nExplanation:\u00a0Each query is independent.\n[2,6]: There are 4 ways to fill an array of size 2 that multiply to 6: [1,6], [2,3], [3,2], [6,1].\n[5,1]: There is 1 way to fill an array of size 5 that multiply to 1: [1,1,1,1,1].\n[73,660]: There are 1050734917 ways to fill an array of size 73 that multiply to 660. 1050734917 modulo 10^9 + 7 = 50734910.", + "Example 2:\nInput: queries = [[1,1],[2,2],[3,3],[4,4],[5,5]]\nOutput: [1,2,3,10,5]" + ], + "constraints": "Constraints:\n\n1 <= queries.length <= 10^4 \n1 <= ni, ki <= 10^4", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Combinatorics", + "Number Theory" + ], + "title-slug": "count-ways-to-make-array-with-product" + }, + { + "leetcode-id": 1736, + "title": "Latest Time by Replacing Hidden Digits", + "difficulty": 1, + "description": "You are given a string time in the form of hh:mm, where some of the digits in the string are hidden (represented by ?).\nThe valid times are those inclusively between 00:00 and 23:59.\nReturn the latest valid time you can get from time by replacing the hidden digits.", + "examples": [ + "Example 1:\nInput: time = \"2?:?0\"\nOutput: \"23:50\"\nExplanation: The latest hour beginning with the digit '2' is 23 and the latest minute ending with the digit '0' is 50.", + "Example 2:\nInput: time = \"0?:3?\"\nOutput: \"09:39\"", + "Example 3:\nInput: time = \"1?:22\"\nOutput: \"19:22\"" + ], + "constraints": "Constraints:\n\ntime is in the format hh:mm.\nIt is guaranteed that you can produce a valid time from the given string.", + "tags": [ + "String", + "Greedy" + ], + "title-slug": "latest-time-by-replacing-hidden-digits" + }, + { + "leetcode-id": 1737, + "title": "Change Minimum Characters to Satisfy One of Three Conditions", + "difficulty": 2, + "description": "You are given two strings a and b that consist of lowercase letters. In one operation, you can change any character in a or b to any lowercase letter.\nYour goal is to satisfy one of the following three conditions:\n\nEvery letter in a is strictly less than every letter in b in the alphabet.\nEvery letter in b is strictly less than every letter in a in the alphabet.\nBoth a and b consist of only one distinct letter.\n\nReturn the minimum number of operations needed to achieve your goal.", + "examples": [ + "Example 1:\nInput: a = \"aba\", b = \"caa\"\nOutput: 2\nExplanation: Consider the best way to make each condition true:\n1) Change b to \"ccc\" in 2 operations, then every letter in a is less than every letter in b.\n2) Change a to \"bbb\" and b to \"aaa\" in 3 operations, then every letter in b is less than every letter in a.\n3) Change a to \"aaa\" and b to \"aaa\" in 2 operations, then a and b consist of one distinct letter.\nThe best way was done in 2 operations (either condition 1 or condition 3).", + "Example 2:\nInput: a = \"dabadd\", b = \"cda\"\nOutput: 3\nExplanation: The best way is to make condition 1 true by changing b to \"eee\"." + ], + "constraints": "Constraints:\n\n1 <= a.length, b.length <= 10^5\na and b consist only of lowercase letters.", + "tags": [ + "Hash Table", + "String", + "Counting", + "Prefix Sum" + ], + "title-slug": "change-minimum-characters-to-satisfy-one-of-three-conditions" + }, + { + "leetcode-id": 1738, + "title": "Find Kth Largest XOR Coordinate Value", + "difficulty": 2, + "description": "You are given a 2D matrix of size m x n, consisting of non-negative integers. You are also given an integer k.\nThe value of coordinate (a, b) of the matrix is the XOR of all matrix[i][j] where 0 <= i <= a < m and 0 <= j <= b < n (0-indexed).\nFind the k^th largest value (1-indexed) of all the coordinates of matrix.", + "examples": [ + "Example 1:\nInput: matrix = [[5,2],[1,6]], k = 1\nOutput: 7\nExplanation: The value of coordinate (0,1) is 5 XOR 2 = 7, which is the largest value.", + "Example 2:\nInput: matrix = [[5,2],[1,6]], k = 2\nOutput: 5\nExplanation: The value of coordinate (0,0) is 5 = 5, which is the 2nd largest value.", + "Example 3:\nInput: matrix = [[5,2],[1,6]], k = 3\nOutput: 4\nExplanation: The value of coordinate (1,0) is 5 XOR 1 = 4, which is the 3rd largest value." + ], + "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= m, n <= 1000\n0 <= matrix[i][j] <= 10^6\n1 <= k <= m * n", + "tags": [ + "Array", + "Divide and Conquer", + "Bit Manipulation", + "Heap (Priority Queue)", + "Matrix", + "Prefix Sum", + "Quickselect" + ], + "title-slug": "find-kth-largest-xor-coordinate-value" + }, + { + "leetcode-id": 1739, + "title": "Building Boxes", + "difficulty": 3, + "description": "You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes:\n\nYou can place the boxes anywhere on the floor.\nIf box x is placed on top of the box y, then each side of the four vertical sides of the box y must either be adjacent to another box or to a wall.\n\nGiven an integer n, return the minimum possible number of boxes touching the floor.", + "examples": [ + "Example 1:\nInput: n = 3\nOutput: 3\nExplanation: The figure above is for the placement of the three boxes.\nThese boxes are placed in the corner of the room, where the corner is on the left side.", + "Example 2:\nInput: n = 4\nOutput: 3\nExplanation: The figure above is for the placement of the four boxes.\nThese boxes are placed in the corner of the room, where the corner is on the left side.", + "Example 3:\nInput: n = 10\nOutput: 6\nExplanation: The figure above is for the placement of the ten boxes.\nThese boxes are placed in the corner of the room, where the corner is on the back side." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^9", + "tags": [ + "Math", + "Binary Search", + "Greedy" + ], + "title-slug": "building-boxes" + }, + { + "leetcode-id": 1742, + "title": "Maximum Number of Balls in a Box", + "difficulty": 1, + "description": "You are working in a ball factory where you have n balls numbered from lowLimit up to highLimit inclusive (i.e., n == highLimit - lowLimit + 1), and an infinite number of boxes numbered from 1 to infinity.\nYour job at this factory is to put each ball in the box with a number equal to the sum of digits of the ball's number. For example, the ball number 321 will be put in the box number 3 + 2 + 1 = 6 and the ball number 10 will be put in the box number 1 + 0 = 1.\nGiven two integers lowLimit and highLimit, return the number of balls in the box with the most balls.", + "examples": [ + "Example 1:\nInput: lowLimit = 1, highLimit = 10\nOutput: 2\nExplanation:\nBox Number: 1 2 3 4 5 6 7 8 9 10 11 ...\nBall Count: 2 1 1 1 1 1 1 1 1 0 0 ...\nBox 1 has the most number of balls with 2 balls.", + "Example 2:\nInput: lowLimit = 5, highLimit = 15\nOutput: 2\nExplanation:\nBox Number: 1 2 3 4 5 6 7 8 9 10 11 ...\nBall Count: 1 1 1 1 2 2 1 1 1 0 0 ...\nBoxes 5 and 6 have the most number of balls with 2 balls in each.", + "Example 3:\nInput: lowLimit = 19, highLimit = 28\nOutput: 2\nExplanation:\nBox Number: 1 2 3 4 5 6 7 8 9 10 11 12 ...\nBall Count: 0 1 1 1 1 1 1 1 1 2 0 0 ...\nBox 10 has the most number of balls with 2 balls." + ], + "constraints": "Constraints:\n\n1 <= lowLimit <= highLimit <= 10^5", + "tags": [ + "Hash Table", + "Math", + "Counting" + ], + "title-slug": "maximum-number-of-balls-in-a-box" + }, + { + "leetcode-id": 1743, + "title": "Restore the Array From Adjacent Pairs", + "difficulty": 2, + "description": "There is an integer array nums that consists of n unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums.\nYou are given a 2D integer array adjacentPairs of size n - 1 where each adjacentPairs[i] = [ui, vi] indicates that the elements ui and vi are adjacent in nums.\nIt is guaranteed that every adjacent pair of elements nums[i] and nums[i+1] will exist in adjacentPairs, either as [nums[i], nums[i+1]] or [nums[i+1], nums[i]]. The pairs can appear in any order.\nReturn the original array nums. If there are multiple solutions, return any of them.", + "examples": [ + "Example 1:\nInput: adjacentPairs = [[2,1],[3,4],[3,2]]\nOutput: [1,2,3,4]\nExplanation: This array has all its adjacent pairs in adjacentPairs.\nNotice that adjacentPairs[i] may not be in left-to-right order.", + "Example 2:\nInput: adjacentPairs = [[4,-2],[1,4],[-3,1]]\nOutput: [-2,4,1,-3]\nExplanation: There can be negative numbers.\nAnother solution is [-3,1,4,-2], which would also be accepted.", + "Example 3:\nInput: adjacentPairs = [[100000,-100000]]\nOutput: [100000,-100000]" + ], + "constraints": "Constraints:\n\nnums.length == n\nadjacentPairs.length == n - 1\nadjacentPairs[i].length == 2\n2 <= n <= 10^5\n-10^5 <= nums[i], ui, vi <= 10^5\nThere exists some nums that has adjacentPairs as its pairs.", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "restore-the-array-from-adjacent-pairs" + }, + { + "leetcode-id": 1744, + "title": "Can You Eat Your Favorite Candy on Your Favorite Day?", + "difficulty": 2, + "description": "You are given a (0-indexed) array of positive integers candiesCount where candiesCount[i] represents the number of candies of the\u00a0i^th\u00a0type you have. You are also given a 2D array queries where queries[i] = [favoriteTypei, favoriteDayi, dailyCapi].\nYou play a game with the following rules:\n\nYou start eating candies on day 0.\nYou cannot eat any candy of type i unless you have eaten all candies of type i - 1.\nYou must eat at least one candy per day until you have eaten all the candies.\n\nConstruct a boolean array answer such that answer.length == queries.length and answer[i] is true if you can eat a candy of type favoriteTypei on day favoriteDayi without eating more than dailyCapi candies on any day, and false otherwise. Note that you can eat different types of candy on the same day, provided that you follow rule 2.\nReturn the constructed array answer.", + "examples": [ + "Example 1:\nInput: candiesCount = [7,4,5,3,8], queries = [[0,2,2],[4,2,4],[2,13,1000000000]]\nOutput: [true,false,true]\nExplanation:\n1- If you eat 2 candies (type 0) on day 0 and 2 candies (type 0) on day 1, you will eat a candy of type 0 on day 2.\n2- You can eat at most 4 candies each day.\n If you eat 4 candies every day, you will eat 4 candies (type 0) on day 0 and 4 candies (type 0 and type 1) on day 1.\n On day 2, you can only eat 4 candies (type 1 and type 2), so you cannot eat a candy of type 4 on day 2.\n3- If you eat 1 candy each day, you will eat a candy of type 2 on day 13.", + "Example 2:\nInput: candiesCount = [5,2,6,4,1], queries = [[3,1,2],[4,10,3],[3,10,100],[4,100,30],[1,3,1]]\nOutput: [false,true,true,false,false]" + ], + "constraints": "Constraints:\n\n1 <= candiesCount.length <= 10^5\n1 <= candiesCount[i] <= 10^5\n1 <= queries.length <= 10^5\nqueries[i].length == 3\n0 <= favoriteTypei < candiesCount.length\n0 <= favoriteDayi <= 10^9\n1 <= dailyCapi <= 10^9", + "tags": [ + "Array", + "Prefix Sum" + ], + "title-slug": "can-you-eat-your-favorite-candy-on-your-favorite-day" + }, + { + "leetcode-id": 1745, + "title": "Palindrome Partitioning IV", + "difficulty": 3, + "description": "Given a string s, return true if it is possible to split the string s into three non-empty palindromic substrings. Otherwise, return false.\u200b\u200b\u200b\u200b\u200b\nA string is said to be palindrome if it the same string when reversed.", + "examples": [ + "Example 1:\nInput: s = \"abcbdd\"\nOutput: true\nExplanation: \"abcbdd\" = \"a\" + \"bcb\" + \"dd\", and all three substrings are palindromes.", + "Example 2:\nInput: s = \"bcbddxy\"\nOutput: false\nExplanation: s cannot be split into 3 palindromes." + ], + "constraints": "Constraints:\n\n3 <= s.length <= 2000\ns\u200b\u200b\u200b\u200b\u200b\u200b consists only of lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "palindrome-partitioning-iv" + }, + { + "leetcode-id": 1748, + "title": "Sum of Unique Elements", + "difficulty": 1, + "description": "You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array.\nReturn the sum of all the unique elements of nums.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,2]\nOutput: 4\nExplanation: The unique elements are [1,3], and the sum is 4.", + "Example 2:\nInput: nums = [1,1,1,1,1]\nOutput: 0\nExplanation: There are no unique elements, and the sum is 0.", + "Example 3:\nInput: nums = [1,2,3,4,5]\nOutput: 15\nExplanation: The unique elements are [1,2,3,4,5], and the sum is 15." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100", + "tags": [ + "Array", + "Hash Table", + "Counting" + ], + "title-slug": "sum-of-unique-elements" + }, + { + "leetcode-id": 1749, + "title": "Maximum Absolute Sum of Any Subarray", + "difficulty": 2, + "description": "You are given an integer array nums. The absolute sum of a subarray [numsl, numsl+1, ..., numsr-1, numsr] is abs(numsl + numsl+1 + ... + numsr-1 + numsr).\nReturn the maximum absolute sum of any (possibly empty) subarray of nums.\nNote that abs(x) is defined as follows:\n\nIf x is a negative integer, then abs(x) = -x.\nIf x is a non-negative integer, then abs(x) = x.", + "examples": [ + "Example 1:\nInput: nums = [1,-3,2,3,-4]\nOutput: 5\nExplanation: The subarray [2,3] has absolute sum = abs(2+3) = abs(5) = 5.", + "Example 2:\nInput: nums = [2,-5,1,-4,3,-2]\nOutput: 8\nExplanation: The subarray [-5,1,-4] has absolute sum = abs(-5+1-4) = abs(-8) = 8." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^4 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "maximum-absolute-sum-of-any-subarray" + }, + { + "leetcode-id": 1750, + "title": "Minimum Length of String After Deleting Similar Ends", + "difficulty": 2, + "description": "Given a string s consisting only of characters 'a', 'b', and 'c'. You are asked to apply the following algorithm on the string any number of times:\n\nPick a non-empty prefix from the string s where all the characters in the prefix are equal.\nPick a non-empty suffix from the string s where all the characters in this suffix are equal.\nThe prefix and the suffix should not intersect at any index.\nThe characters from the prefix and suffix must be the same.\nDelete both the prefix and the suffix.\n\nReturn the minimum length of s after performing the above operation any number of times (possibly zero times).", + "examples": [ + "Example 1:\nInput: s = \"ca\"\nOutput: 2\nExplanation: You can't remove any characters, so the string stays as is.", + "Example 2:\nInput: s = \"cabaabac\"\nOutput: 0\nExplanation: An optimal sequence of operations is:\n- Take prefix = \"c\" and suffix = \"c\" and remove them, s = \"abaaba\".\n- Take prefix = \"a\" and suffix = \"a\" and remove them, s = \"baab\".\n- Take prefix = \"b\" and suffix = \"b\" and remove them, s = \"aa\".\n- Take prefix = \"a\" and suffix = \"a\" and remove them, s = \"\".", + "Example 3:\nInput: s = \"aabccabba\"\nOutput: 3\nExplanation: An optimal sequence of operations is:\n- Take prefix = \"aa\" and suffix = \"a\" and remove them, s = \"bccabb\".\n- Take prefix = \"b\" and suffix = \"bb\" and remove them, s = \"cca\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns only consists of characters 'a', 'b', and 'c'.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "minimum-length-of-string-after-deleting-similar-ends" + }, + { + "leetcode-id": 1751, + "title": "Maximum Number of Events That Can Be Attended II", + "difficulty": 3, + "description": "You are given an array of events where events[i] = [startDayi, endDayi, valuei]. The i^th event starts at startDayi and ends at endDayi, and if you attend this event, you will receive a value of valuei. You are also given an integer k which represents the maximum number of events you can attend.\nYou can only attend one event at a time. If you choose to attend an event, you must attend the entire event. Note that the end day is inclusive: that is, you cannot attend two events where one of them starts and the other ends on the same day.\nReturn the maximum sum of values that you can receive by attending events.", + "examples": [ + "Example 1:\nInput: events = [[1,2,4],[3,4,3],[2,3,1]], k = 2\nOutput: 7\nExplanation: Choose the green events, 0 and 1 (0-indexed) for a total value of 4 + 3 = 7.", + "Example 2:\nInput: events = [[1,2,4],[3,4,3],[2,3,10]], k = 2\nOutput: 10\nExplanation: Choose event 2 for a total value of 10.\nNotice that you cannot attend any other event as they overlap, and that you do not have to attend k events.", + "Example 3:\nInput: events = [[1,1,1],[2,2,2],[3,3,3],[4,4,4]], k = 3\nOutput: 9\nExplanation: Although the events do not overlap, you can only attend 3 events. Pick the highest valued three." + ], + "constraints": "Constraints:\n\n1 <= k <= events.length\n1 <= k * events.length <= 10^6\n1 <= startDayi <= endDayi <= 10^9\n1 <= valuei <= 10^6", + "tags": [ + "Array", + "Binary Search", + "Dynamic Programming", + "Sorting" + ], + "title-slug": "maximum-number-of-events-that-can-be-attended-ii" + }, + { + "leetcode-id": 1752, + "title": "Check if Array Is Sorted and Rotated", + "difficulty": 1, + "description": "Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise, return false.\nThere may be duplicates in the original array.\nNote: An array A rotated by x positions results in an array B of the same length such that A[i] == B[(i+x) % A.length], where % is the modulo operation.", + "examples": [ + "Example 1:\nInput: nums = [3,4,5,1,2]\nOutput: true\nExplanation: [1,2,3,4,5] is the original sorted array.\nYou can rotate the array by x = 3 positions to begin on the the element of value 3: [3,4,5,1,2].", + "Example 2:\nInput: nums = [2,1,3,4]\nOutput: false\nExplanation: There is no sorted array once rotated that can make nums.", + "Example 3:\nInput: nums = [1,2,3]\nOutput: true\nExplanation: [1,2,3] is the original sorted array.\nYou can rotate the array by x = 0 positions (i.e. no rotation) to make nums." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100", + "tags": [ + "Array" + ], + "title-slug": "check-if-array-is-sorted-and-rotated" + }, + { + "leetcode-id": 1753, + "title": "Maximum Score From Removing Stones", + "difficulty": 2, + "description": "You are playing a solitaire game with three piles of stones of sizes a\u200b\u200b\u200b\u200b\u200b\u200b, b,\u200b\u200b\u200b\u200b\u200b\u200b and c\u200b\u200b\u200b\u200b\u200b\u200b respectively. Each turn you choose two different non-empty piles, take one stone from each, and add 1 point to your score. The game stops when there are fewer than two non-empty piles (meaning there are no more available moves).\nGiven three integers a\u200b\u200b\u200b\u200b\u200b, b,\u200b\u200b\u200b\u200b\u200b and c\u200b\u200b\u200b\u200b\u200b, return the maximum score you can get.", + "examples": [ + "Example 1:\nInput: a = 2, b = 4, c = 6\nOutput: 6\nExplanation: The starting state is (2, 4, 6). One optimal set of moves is:\n- Take from 1st and 3rd piles, state is now (1, 4, 5)\n- Take from 1st and 3rd piles, state is now (0, 4, 4)\n- Take from 2nd and 3rd piles, state is now (0, 3, 3)\n- Take from 2nd and 3rd piles, state is now (0, 2, 2)\n- Take from 2nd and 3rd piles, state is now (0, 1, 1)\n- Take from 2nd and 3rd piles, state is now (0, 0, 0)\nThere are fewer than two non-empty piles, so the game ends. Total: 6 points.", + "Example 2:\nInput: a = 4, b = 4, c = 6\nOutput: 7\nExplanation: The starting state is (4, 4, 6). One optimal set of moves is:\n- Take from 1st and 2nd piles, state is now (3, 3, 6)\n- Take from 1st and 3rd piles, state is now (2, 3, 5)\n- Take from 1st and 3rd piles, state is now (1, 3, 4)\n- Take from 1st and 3rd piles, state is now (0, 3, 3)\n- Take from 2nd and 3rd piles, state is now (0, 2, 2)\n- Take from 2nd and 3rd piles, state is now (0, 1, 1)\n- Take from 2nd and 3rd piles, state is now (0, 0, 0)\nThere are fewer than two non-empty piles, so the game ends. Total: 7 points.", + "Example 3:\nInput: a = 1, b = 8, c = 8\nOutput: 8\nExplanation: One optimal set of moves is to take from the 2nd and 3rd piles for 8 turns until they are empty.\nAfter that, there are fewer than two non-empty piles, so the game ends." + ], + "constraints": "Constraints:\n\n1 <= a, b, c <= 10^5", + "tags": [ + "Math", + "Greedy", + "Heap (Priority Queue)" + ], + "title-slug": "maximum-score-from-removing-stones" + }, + { + "leetcode-id": 1754, + "title": "Largest Merge Of Two Strings", + "difficulty": 2, + "description": "You are given two strings word1 and word2. You want to construct a string merge in the following way: while either word1 or word2 are non-empty, choose one of the following options:\n\nIf word1 is non-empty, append the first character in word1 to merge and delete it from word1.\n\n\t\nFor example, if word1 = \"abc\" and merge = \"dv\", then after choosing this operation, word1 = \"bc\" and merge = \"dva\".\n\n\nIf word2 is non-empty, append the first character in word2 to merge and delete it from word2.\n\t\nFor example, if word2 = \"abc\" and merge = \"\", then after choosing this operation, word2 = \"bc\" and merge = \"a\".\n\n\n\nReturn the lexicographically largest merge you can construct.\nA string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b. For example, \"abcd\" is lexicographically larger than \"abcc\" because the first position they differ is at the fourth character, and d is greater than c.", + "examples": [ + "Example 1:\nInput: word1 = \"cabaa\", word2 = \"bcaaa\"\nOutput: \"cbcabaaaaa\"\nExplanation: One way to get the lexicographically largest merge is:\n- Take from word1: merge = \"c\", word1 = \"abaa\", word2 = \"bcaaa\"\n- Take from word2: merge = \"cb\", word1 = \"abaa\", word2 = \"caaa\"\n- Take from word2: merge = \"cbc\", word1 = \"abaa\", word2 = \"aaa\"\n- Take from word1: merge = \"cbca\", word1 = \"baa\", word2 = \"aaa\"\n- Take from word1: merge = \"cbcab\", word1 = \"aa\", word2 = \"aaa\"\n- Append the remaining 5 a's from word1 and word2 at the end of merge.", + "Example 2:\nInput: word1 = \"abcabc\", word2 = \"abdcaba\"\nOutput: \"abdcabcabcaba\"" + ], + "constraints": "Constraints:\n\n1 <= word1.length, word2.length <= 3000\nword1 and word2 consist only of lowercase English letters.", + "tags": [ + "Two Pointers", + "String", + "Greedy" + ], + "title-slug": "largest-merge-of-two-strings" + }, + { + "leetcode-id": 1755, + "title": "Closest Subsequence Sum", + "difficulty": 3, + "description": "You are given an integer array nums and an integer goal.\nYou want to choose a subsequence of nums such that the sum of its elements is the closest possible to goal. That is, if the sum of the subsequence's elements is sum, then you want to minimize the absolute difference abs(sum - goal).\nReturn the minimum possible value of abs(sum - goal).\nNote that a subsequence of an array is an array formed by removing some elements (possibly all or none) of the original array.", + "examples": [ + "Example 1:\nInput: nums = [5,-7,3,5], goal = 6\nOutput: 0\nExplanation: Choose the whole array as a subsequence, with a sum of 6.\nThis is equal to the goal, so the absolute difference is 0.", + "Example 2:\nInput: nums = [7,-9,15,-2], goal = -5\nOutput: 1\nExplanation: Choose the subsequence [7,-9,-2], with a sum of -4.\nThe absolute difference is abs(-4 - (-5)) = abs(1) = 1, which is the minimum.", + "Example 3:\nInput: nums = [1,2,3], goal = -7\nOutput: 7" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 40\n-10^7 <= nums[i] <= 10^7\n-10^9 <= goal <= 10^9", + "tags": [ + "Array", + "Two Pointers", + "Dynamic Programming", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "closest-subsequence-sum" + }, + { + "leetcode-id": 1758, + "title": "Minimum Changes To Make Alternating Binary String", + "difficulty": 1, + "description": "You are given a string s consisting only of the characters '0' and '1'. In one operation, you can change any '0' to '1' or vice versa.\nThe string is called alternating if no two adjacent characters are equal. For example, the string \"010\" is alternating, while the string \"0100\" is not.\nReturn the minimum number of operations needed to make s alternating.", + "examples": [ + "Example 1:\nInput: s = \"0100\"\nOutput: 1\nExplanation: If you change the last character to '1', s will be \"0101\", which is alternating.", + "Example 2:\nInput: s = \"10\"\nOutput: 0\nExplanation: s is already alternating.", + "Example 3:\nInput: s = \"1111\"\nOutput: 2\nExplanation: You need two operations to reach \"0101\" or \"1010\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^4\ns[i] is either '0' or '1'.", + "tags": [ + "String" + ], + "title-slug": "minimum-changes-to-make-alternating-binary-string" + }, + { + "leetcode-id": 1759, + "title": "Count Number of Homogenous Substrings", + "difficulty": 2, + "description": "Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 10^9 + 7.\nA string is homogenous if all the characters of the string are the same.\nA substring is a contiguous sequence of characters within a string.", + "examples": [ + "Example 1:\nInput: s = \"abbcccaa\"\r\nOutput: 13\r\nExplanation: The homogenous substrings are listed as below:\r\n\"a\" appears 3 times.\r\n\"aa\" appears 1 time.\r\n\"b\" appears 2 times.\r\n\"bb\" appears 1 time.\r\n\"c\" appears 3 times.\r\n\"cc\" appears 2 times.\r\n\"ccc\" appears 1 time.\r\n3 + 1 + 2 + 1 + 3 + 2 + 1 = 13.", + "Example 2:\nInput: s = \"xy\"\r\nOutput: 2\r\nExplanation: The homogenous substrings are \"x\" and \"y\".", + "Example 3:\nInput: s = \"zzzzz\"\r\nOutput: 15" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of lowercase letters.", + "tags": [ + "Math", + "String" + ], + "title-slug": "count-number-of-homogenous-substrings" + }, + { + "leetcode-id": 1760, + "title": "Minimum Limit of Balls in a Bag", + "difficulty": 2, + "description": "You are given an integer array nums where the i^th bag contains nums[i] balls. You are also given an integer maxOperations.\nYou can perform the following operation at most maxOperations times:\n\nTake any bag of balls and divide it into two new bags with a positive number of balls.\n\n\t\nFor example, a bag of 5 balls can become two new bags of 1 and 4 balls, or two new bags of 2 and 3 balls.\n\n\n\nYour penalty is the maximum number of balls in a bag. You want to minimize your penalty after the operations.\nReturn the minimum possible penalty after performing the operations.", + "examples": [ + "Example 1:\nInput: nums = [9], maxOperations = 2\nOutput: 3\nExplanation: \n- Divide the bag with 9 balls into two bags of sizes 6 and 3. [9] -> [6,3].\n- Divide the bag with 6 balls into two bags of sizes 3 and 3. [6,3] -> [3,3,3].\nThe bag with the most number of balls has 3 balls, so your penalty is 3 and you should return 3.", + "Example 2:\nInput: nums = [2,4,8,2], maxOperations = 4\nOutput: 2\nExplanation:\n- Divide the bag with 8 balls into two bags of sizes 4 and 4. [2,4,8,2] -> [2,4,4,4,2].\n- Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,4,4,4,2] -> [2,2,2,4,4,2].\n- Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,2,2,4,4,2] -> [2,2,2,2,2,4,2].\n- Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,2,2,2,2,4,2] -> [2,2,2,2,2,2,2,2].\nThe bag with the most number of balls has 2 balls, so your penalty is 2, and you should return 2." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= maxOperations, nums[i] <= 10^9", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "minimum-limit-of-balls-in-a-bag" + }, + { + "leetcode-id": 1761, + "title": "Minimum Degree of a Connected Trio in a Graph", + "difficulty": 3, + "description": "You are given an undirected graph. You are given an integer n which is the number of nodes in the graph and an array edges, where each edges[i] = [ui, vi] indicates that there is an undirected edge between ui and vi.\nA connected trio is a set of three nodes where there is an edge between every pair of them.\nThe degree of a connected trio is the number of edges where one endpoint is in the trio, and the other is not.\nReturn the minimum degree of a connected trio in the graph, or -1 if the graph has no connected trios.", + "examples": [ + "Example 1:\nInput: n = 6, edges = [[1,2],[1,3],[3,2],[4,1],[5,2],[3,6]]\nOutput: 3\nExplanation: There is exactly one trio, which is [1,2,3]. The edges that form its degree are bolded in the figure above.", + "Example 2:\nInput: n = 7, edges = [[1,3],[4,1],[4,3],[2,5],[5,6],[6,7],[7,5],[2,6]]\nOutput: 0\nExplanation: There are exactly three trios:\n1) [1,4,3] with degree 0.\n2) [2,5,6] with degree 2.\n3) [5,6,7] with degree 2." + ], + "constraints": "Constraints:\n\n2 <= n <= 400\nedges[i].length == 2\n1 <= edges.length <= n * (n-1) / 2\n1 <= ui, vi <= n\nui != vi\nThere are no repeated edges.", + "tags": [ + "Graph" + ], + "title-slug": "minimum-degree-of-a-connected-trio-in-a-graph" + }, + { + "leetcode-id": 1763, + "title": "Longest Nice Substring", + "difficulty": 1, + "description": "A string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase. For example, \"abABB\" is nice because 'A' and 'a' appear, and 'B' and 'b' appear. However, \"abA\" is not because 'b' appears, but 'B' does not.\nGiven a string s, return the longest substring of s that is nice. If there are multiple, return the substring of the earliest occurrence. If there are none, return an empty string.", + "examples": [ + "Example 1:\nInput: s = \"YazaAay\"\nOutput: \"aAa\"\nExplanation: \"aAa\" is a nice string because 'A/a' is the only letter of the alphabet in s, and both 'A' and 'a' appear.\n\"aAa\" is the longest nice substring.", + "Example 2:\nInput: s = \"Bb\"\nOutput: \"Bb\"\nExplanation: \"Bb\" is a nice string because both 'B' and 'b' appear. The whole string is a substring.", + "Example 3:\nInput: s = \"c\"\nOutput: \"\"\nExplanation: There are no nice substrings." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\ns consists of uppercase and lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Divide and Conquer", + "Bit Manipulation", + "Sliding Window" + ], + "title-slug": "longest-nice-substring" + }, + { + "leetcode-id": 1764, + "title": "Form Array by Concatenating Subarrays of Another Array", + "difficulty": 2, + "description": "You are given a 2D integer array groups of length n. You are also given an integer array nums.\nYou are asked if you can choose n disjoint subarrays from the array nums such that the i^th subarray is equal to groups[i] (0-indexed), and if i > 0, the (i-1)^th subarray appears before the i^th subarray in nums (i.e. the subarrays must be in the same order as groups).\nReturn true if you can do this task, and false otherwise.\nNote that the subarrays are disjoint if and only if there is no index k such that nums[k] belongs to more than one subarray. A subarray is a contiguous sequence of elements within an array.", + "examples": [ + "Example 1:\nInput: groups = [[1,-1,-1],[3,-2,0]], nums = [1,-1,0,1,-1,-1,3,-2,0]\nOutput: true\nExplanation: You can choose the 0^th subarray as [1,-1,0,1,-1,-1,3,-2,0] and the 1^st one as [1,-1,0,1,-1,-1,3,-2,0].\nThese subarrays are disjoint as they share no common nums[k] element.", + "Example 2:\nInput: groups = [[10,-2],[1,2,3,4]], nums = [1,2,3,4,10,-2]\nOutput: false\nExplanation: Note that choosing the subarrays [1,2,3,4,10,-2] and [1,2,3,4,10,-2] is incorrect because they are not in the same order as in groups.\n[10,-2] must come before [1,2,3,4].", + "Example 3:\nInput: groups = [[1,2,3],[3,4]], nums = [7,7,1,2,3,4,7,7]\nOutput: false\nExplanation: Note that choosing the subarrays [7,7,1,2,3,4,7,7] and [7,7,1,2,3,4,7,7] is invalid because they are not disjoint.\nThey share a common elements nums[4] (0-indexed)." + ], + "constraints": "Constraints:\n\ngroups.length == n\n1 <= n <= 10^3\n1 <= groups[i].length, sum(groups[i].length) <= 10^3\n1 <= nums.length <= 10^3\n-10^7 <= groups[i][j], nums[k] <= 10^7", + "tags": [ + "Array", + "Greedy", + "String Matching" + ], + "title-slug": "form-array-by-concatenating-subarrays-of-another-array" + }, + { + "leetcode-id": 1765, + "title": "Map of Highest Peak", + "difficulty": 2, + "description": "You are given an integer matrix isWater of size m x n that represents a map of land and water cells.\n\nIf isWater[i][j] == 0, cell (i, j) is a land cell.\nIf isWater[i][j] == 1, cell (i, j) is a water cell.\n\nYou must assign each cell a height in a way that follows these rules:\n\nThe height of each cell must be non-negative.\nIf the cell is a water cell, its height must be 0.\nAny two adjacent cells must have an absolute height difference of at most 1. A cell is adjacent to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).\n\nFind an assignment of heights such that the maximum height in the matrix is maximized.\nReturn an integer matrix height of size m x n where height[i][j] is cell (i, j)'s height. If there are multiple solutions, return any of them.", + "examples": [ + "Example 1:\nInput: isWater = [[0,1],[0,0]]\nOutput: [[1,0],[2,1]]\nExplanation: The image shows the assigned heights of each cell.\nThe blue cell is the water cell, and the green cells are the land cells.", + "Example 2:\nInput: isWater = [[0,0,1],[1,0,0],[0,0,0]]\nOutput: [[1,1,0],[0,1,1],[1,2,2]]\nExplanation: A height of 2 is the maximum possible height of any assignment.\nAny height assignment that has a maximum height of 2 while still meeting the rules will also be accepted." + ], + "constraints": "Constraints:\n\nm == isWater.length\nn == isWater[i].length\n1 <= m, n <= 1000\nisWater[i][j] is 0 or 1.\nThere is at least one water cell.", + "tags": [ + "Array", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "map-of-highest-peak" + }, + { + "leetcode-id": 1766, + "title": "Tree of Coprimes", + "difficulty": 3, + "description": "There is a tree (i.e.,\u00a0a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. Each node has a value associated with it, and the root of the tree is node 0.\nTo represent this tree, you are given an integer array nums and a 2D array edges. Each nums[i] represents the i^th node's value, and each edges[j] = [uj, vj] represents an edge between nodes uj and vj in the tree.\nTwo values x and y are coprime if gcd(x, y) == 1 where gcd(x, y) is the greatest common divisor of x and y.\nAn ancestor of a node i is any other node on the shortest path from node i to the root. A node is not considered an ancestor of itself.\nReturn an array ans of size n, where ans[i] is the closest ancestor to node i such that nums[i] and nums[ans[i]] are coprime, or -1 if there is no such ancestor.", + "examples": [ + "Example 1:\nInput: nums = [2,3,3,2], edges = [[0,1],[1,2],[1,3]]\nOutput: [-1,0,0,1]\nExplanation: In the above figure, each node's value is in parentheses.\n- Node 0 has no coprime ancestors.\n- Node 1 has only one ancestor, node 0. Their values are coprime (gcd(2,3) == 1).\n- Node 2 has two ancestors, nodes 1 and 0. Node 1's value is not coprime (gcd(3,3) == 3), but node 0's\n value is (gcd(2,3) == 1), so node 0 is the closest valid ancestor.\n- Node 3 has two ancestors, nodes 1 and 0. It is coprime with node 1 (gcd(3,2) == 1), so node 1 is its\n closest valid ancestor.", + "Example 2:\nInput: nums = [5,6,10,2,3,6,15], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]\nOutput: [-1,0,-1,0,0,0,-1]" + ], + "constraints": "Constraints:\n\nnums.length == n\n1 <= nums[i] <= 50\n1 <= n <= 10^5\nedges.length == n - 1\nedges[j].length == 2\n0 <= uj, vj < n\nuj != vj", + "tags": [ + "Math", + "Tree", + "Depth-First Search", + "Breadth-First Search" + ], + "title-slug": "tree-of-coprimes" + }, + { + "leetcode-id": 1768, + "title": "Merge Strings Alternately", + "difficulty": 1, + "description": "You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.\nReturn the merged string.", + "examples": [ + "Example 1:\nInput: word1 = \"abc\", word2 = \"pqr\"\r\nOutput: \"apbqcr\"\r\nExplanation:\u00a0The merged string will be merged as so:\r\nword1: a b c\r\nword2: p q r\r\nmerged: a p b q c r", + "Example 2:\nInput: word1 = \"ab\", word2 = \"pqrs\"\r\nOutput: \"apbqrs\"\r\nExplanation:\u00a0Notice that as word2 is longer, \"rs\" is appended to the end.\r\nword1: a b \r\nword2: p q r s\r\nmerged: a p b q r s", + "Example 3:\nInput: word1 = \"abcd\", word2 = \"pq\"\r\nOutput: \"apbqcd\"\r\nExplanation:\u00a0Notice that as word1 is longer, \"cd\" is appended to the end.\r\nword1: a b c d\r\nword2: p q \r\nmerged: a p b q c d" + ], + "constraints": "Constraints:\n\n1 <= word1.length, word2.length <= 100\nword1 and word2 consist of lowercase English letters.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "merge-strings-alternately" + }, + { + "leetcode-id": 1769, + "title": "Minimum Number of Operations to Move All Balls to Each Box", + "difficulty": 2, + "description": "You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the i^th box is empty, and '1' if it contains one ball.\nIn one operation, you can move one ball from a box to an adjacent box. Box i is adjacent to box j if abs(i - j) == 1. Note that after doing so, there may be more than one ball in some boxes.\nReturn an array answer of size n, where answer[i] is the minimum number of operations needed to move all the balls to the i^th box.\nEach answer[i] is calculated considering the initial state of the boxes.", + "examples": [ + "Example 1:\nInput: boxes = \"110\"\nOutput: [1,1,3]\nExplanation: The answer for each box is as follows:\n1) First box: you will have to move one ball from the second box to the first box in one operation.\n2) Second box: you will have to move one ball from the first box to the second box in one operation.\n3) Third box: you will have to move one ball from the first box to the third box in two operations, and move one ball from the second box to the third box in one operation.", + "Example 2:\nInput: boxes = \"001011\"\nOutput: [11,8,5,4,3,4]" + ], + "constraints": "Constraints:\n\nn == boxes.length\n1 <= n <= 2000\nboxes[i] is either '0' or '1'.", + "tags": [ + "Array", + "String" + ], + "title-slug": "minimum-number-of-operations-to-move-all-balls-to-each-box" + }, + { + "leetcode-id": 1770, + "title": "Maximum Score from Performing Multiplication Operations", + "difficulty": 3, + "description": "You are given two 0-indexed integer arrays nums and multipliers of size n and m respectively, where n >= m.\nYou begin with a score of 0. You want to perform exactly m operations. On the i^th operation (0-indexed) you will:\n\nChoose one integer x from either the start or the end of the array nums.\nAdd multipliers[i] * x to your score.\n \nNote that multipliers[0] corresponds to the first operation, multipliers[1] to the second operation, and so on.\n\n\nRemove x from nums.\n\nReturn the maximum score after performing m operations.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3], multipliers = [3,2,1]\nOutput: 14\nExplanation:\u00a0An optimal solution is as follows:\n- Choose from the end, [1,2,3], adding 3 * 3 = 9 to the score.\n- Choose from the end, [1,2], adding 2 * 2 = 4 to the score.\n- Choose from the end, [1], adding 1 * 1 = 1 to the score.\nThe total score is 9 + 4 + 1 = 14.", + "Example 2:\nInput: nums = [-5,-3,-3,-2,7,1], multipliers = [-10,-5,3,4,6]\nOutput: 102\nExplanation: An optimal solution is as follows:\n- Choose from the start, [-5,-3,-3,-2,7,1], adding -5 * -10 = 50 to the score.\n- Choose from the start, [-3,-3,-2,7,1], adding -3 * -5 = 15 to the score.\n- Choose from the start, [-3,-2,7,1], adding -3 * 3 = -9 to the score.\n- Choose from the end, [-2,7,1], adding 1 * 4 = 4 to the score.\n- Choose from the end, [-2,7], adding 7 * 6 = 42 to the score. \nThe total score is 50 + 15 - 9 + 4 + 42 = 102." + ], + "constraints": "Constraints:\n\nn == nums.length\nm == multipliers.length\n1 <= m <= 300\nm <= n <= 10^5 \n-1000 <= nums[i], multipliers[i] <= 1000", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "maximum-score-from-performing-multiplication-operations" + }, + { + "leetcode-id": 1771, + "title": "Maximize Palindrome Length From Subsequences", + "difficulty": 3, + "description": "You are given two strings, word1 and word2. You want to construct a string in the following manner:\n\nChoose some non-empty subsequence subsequence1 from word1.\nChoose some non-empty subsequence subsequence2 from word2.\nConcatenate the subsequences: subsequence1 + subsequence2, to make the string.\n\nReturn the length of the longest palindrome that can be constructed in the described manner. If no palindromes can be constructed, return 0.\nA subsequence of a string s is a string that can be made by deleting some (possibly none) characters from s without changing the order of the remaining characters.\nA palindrome is a string that reads the same forward\u00a0as well as backward.", + "examples": [ + "Example 1:\nInput: word1 = \"cacb\", word2 = \"cbba\"\nOutput: 5\nExplanation: Choose \"ab\" from word1 and \"cba\" from word2 to make \"abcba\", which is a palindrome.", + "Example 2:\nInput: word1 = \"ab\", word2 = \"ab\"\nOutput: 3\nExplanation: Choose \"ab\" from word1 and \"a\" from word2 to make \"aba\", which is a palindrome.", + "Example 3:\nInput: word1 = \"aa\", word2 = \"bb\"\nOutput: 0\nExplanation: You cannot construct a palindrome from the described method, so return 0." + ], + "constraints": "Constraints:\n\n1 <= word1.length, word2.length <= 1000\nword1 and word2 consist of lowercase English letters.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "maximize-palindrome-length-from-subsequences" + }, + { + "leetcode-id": 1773, + "title": "Count Items Matching a Rule", + "difficulty": 1, + "description": "You are given an array items, where each items[i] = [typei, colori, namei] describes the type, color, and name of the i^th item. You are also given a rule represented by two strings, ruleKey and ruleValue.\nThe i^th item is said to match the rule if one of the following is true:\n\nruleKey == \"type\" and ruleValue == typei.\nruleKey == \"color\" and ruleValue == colori.\nruleKey == \"name\" and ruleValue == namei.\n\nReturn the number of items that match the given rule.", + "examples": [ + "Example 1:\nInput: items = [[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"lenovo\"],[\"phone\",\"gold\",\"iphone\"]], ruleKey = \"color\", ruleValue = \"silver\"\nOutput: 1\nExplanation: There is only one item matching the given rule, which is [\"computer\",\"silver\",\"lenovo\"].", + "Example 2:\nInput: items = [[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"phone\"],[\"phone\",\"gold\",\"iphone\"]], ruleKey = \"type\", ruleValue = \"phone\"\nOutput: 2\nExplanation: There are only two items matching the given rule, which are [\"phone\",\"blue\",\"pixel\"] and [\"phone\",\"gold\",\"iphone\"]. Note that the item [\"computer\",\"silver\",\"phone\"] does not match." + ], + "constraints": "Constraints:\n\n1 <= items.length <= 10^4\n1 <= typei.length, colori.length, namei.length, ruleValue.length <= 10\nruleKey is equal to either \"type\", \"color\", or \"name\".\nAll strings consist only of lowercase letters.", + "tags": [ + "Array", + "String" + ], + "title-slug": "count-items-matching-a-rule" + }, + { + "leetcode-id": 1774, + "title": "Closest Dessert Cost", + "difficulty": 2, + "description": "You would like to make dessert and are preparing to buy the ingredients. You have n ice cream base flavors and m types of toppings to choose from. You must follow these rules when making your dessert:\n\nThere must be exactly one ice cream base.\nYou can add one or more types of topping or have no toppings at all.\nThere are at most two of each type of topping.\n\nYou are given three inputs:\n\nbaseCosts, an integer array of length n, where each baseCosts[i] represents the price of the i^th ice cream base flavor.\ntoppingCosts, an integer array of length m, where each toppingCosts[i] is the price of one of the i^th topping.\ntarget, an integer representing your target price for dessert.\n\nYou want to make a dessert with a total cost as close to target as possible.\nReturn the closest possible cost of the dessert to target. If there are multiple, return the lower one.", + "examples": [ + "Example 1:\nInput: baseCosts = [1,7], toppingCosts = [3,4], target = 10\nOutput: 10\nExplanation: Consider the following combination (all 0-indexed):\n- Choose base 1: cost 7\n- Take 1 of topping 0: cost 1 x 3 = 3\n- Take 0 of topping 1: cost 0 x 4 = 0\nTotal: 7 + 3 + 0 = 10.", + "Example 2:\nInput: baseCosts = [2,3], toppingCosts = [4,5,100], target = 18\nOutput: 17\nExplanation: Consider the following combination (all 0-indexed):\n- Choose base 1: cost 3\n- Take 1 of topping 0: cost 1 x 4 = 4\n- Take 2 of topping 1: cost 2 x 5 = 10\n- Take 0 of topping 2: cost 0 x 100 = 0\nTotal: 3 + 4 + 10 + 0 = 17. You cannot make a dessert with a total cost of 18.", + "Example 3:\nInput: baseCosts = [3,10], toppingCosts = [2,5], target = 9\nOutput: 8\nExplanation: It is possible to make desserts with cost 8 and 10. Return 8 as it is the lower cost." + ], + "constraints": "Constraints:\n\nn == baseCosts.length\nm == toppingCosts.length\n1 <= n, m <= 10\n1 <= baseCosts[i], toppingCosts[i] <= 10^4\n1 <= target <= 10^4", + "tags": [ + "Array", + "Dynamic Programming", + "Backtracking" + ], + "title-slug": "closest-dessert-cost" + }, + { + "leetcode-id": 1775, + "title": "Equal Sum Arrays With Minimum Number of Operations", + "difficulty": 2, + "description": "You are given two arrays of integers nums1 and nums2, possibly of different lengths. The values in the arrays are between 1 and 6, inclusive.\nIn one operation, you can change any integer's value in any of the arrays to any value between 1 and 6, inclusive.\nReturn the minimum number of operations required to make the sum of values in nums1 equal to the sum of values in nums2. Return -1\u200b\u200b\u200b\u200b\u200b if it is not possible to make the sum of the two arrays equal.", + "examples": [ + "Example 1:\nInput: nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]\nOutput: 3\nExplanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.\n- Change nums2[0] to 6. nums1 = [1,2,3,4,5,6], nums2 = [6,1,2,2,2,2].\n- Change nums1[5] to 1. nums1 = [1,2,3,4,5,1], nums2 = [6,1,2,2,2,2].\n- Change nums1[2] to 2. nums1 = [1,2,2,4,5,1], nums2 = [6,1,2,2,2,2].", + "Example 2:\nInput: nums1 = [1,1,1,1,1,1,1], nums2 = [6]\nOutput: -1\nExplanation: There is no way to decrease the sum of nums1 or to increase the sum of nums2 to make them equal.", + "Example 3:\nInput: nums1 = [6,6], nums2 = [1]\nOutput: 3\nExplanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed. \n- Change nums1[0] to 2. nums1 = [2,6], nums2 = [1].\n- Change nums1[1] to 2. nums1 = [2,2], nums2 = [1].\n- Change nums2[0] to 4. nums1 = [2,2], nums2 = [4]." + ], + "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 10^5\n1 <= nums1[i], nums2[i] <= 6", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Counting" + ], + "title-slug": "equal-sum-arrays-with-minimum-number-of-operations" + }, + { + "leetcode-id": 1776, + "title": "Car Fleet II", + "difficulty": 3, + "description": "There are n cars traveling at different speeds in the same direction along a one-lane road. You are given an array cars of length n, where cars[i] = [positioni, speedi] represents:\n\npositioni is the distance between the i^th car and the beginning of the road in meters. It is guaranteed that positioni < positioni+1.\nspeedi is the initial speed of the i^th car in meters per second.\n\nFor simplicity, cars can be considered as points moving along the number line. Two cars collide when they occupy the same position. Once a car collides with another car, they unite and form a single car fleet. The cars in the formed fleet will have the same position and the same speed, which is the initial speed of the slowest car in the fleet.\nReturn an array answer, where answer[i] is the time, in seconds, at which the i^th car collides with the next car, or -1 if the car does not collide with the next car. Answers within 10^-5 of the actual answers are accepted.", + "examples": [ + "Example 1:\nInput: cars = [[1,2],[2,1],[4,3],[7,2]]\nOutput: [1.00000,-1.00000,3.00000,-1.00000]\nExplanation: After exactly one second, the first car will collide with the second car, and form a car fleet with speed 1 m/s. After exactly 3 seconds, the third car will collide with the fourth car, and form a car fleet with speed 2 m/s.", + "Example 2:\nInput: cars = [[3,4],[5,4],[6,3],[9,1]]\nOutput: [2.00000,1.00000,1.50000,-1.00000]" + ], + "constraints": "Constraints:\n\n1 <= cars.length <= 10^5\n1 <= positioni, speedi <= 10^6\npositioni < positioni+1", + "tags": [ + "Array", + "Math", + "Stack", + "Heap (Priority Queue)", + "Monotonic Stack" + ], + "title-slug": "car-fleet-ii" + }, + { + "leetcode-id": 1779, + "title": "Find Nearest Point That Has the Same X or Y Coordinate", + "difficulty": 1, + "description": "You are given two integers, x and y, which represent your current location on a Cartesian grid: (x, y). You are also given an array points where each points[i] = [ai, bi] represents that a point exists at (ai, bi). A point is valid if it shares the same x-coordinate or the same y-coordinate as your location.\nReturn the index (0-indexed) of the valid point with the smallest Manhattan distance from your current location. If there are multiple, return the valid point with the smallest index. If there are no valid points, return -1.\nThe Manhattan distance between two points (x1, y1) and (x2, y2) is abs(x1 - x2) + abs(y1 - y2).", + "examples": [ + "Example 1:\nInput: x = 3, y = 4, points = [[1,2],[3,1],[2,4],[2,3],[4,4]]\nOutput: 2\nExplanation: Of all the points, only [3,1], [2,4] and [4,4] are valid. Of the valid points, [2,4] and [4,4] have the smallest Manhattan distance from your current location, with a distance of 1. [2,4] has the smallest index, so return 2.", + "Example 2:\nInput: x = 3, y = 4, points = [[3,4]]\nOutput: 0\nExplanation: The answer is allowed to be on the same location as your current location.", + "Example 3:\nInput: x = 3, y = 4, points = [[2,3]]\nOutput: -1\nExplanation: There are no valid points." + ], + "constraints": "Constraints:\n\n1 <= points.length <= 10^4\npoints[i].length == 2\n1 <= x, y, ai, bi <= 10^4", + "tags": [ + "Array" + ], + "title-slug": "find-nearest-point-that-has-the-same-x-or-y-coordinate" + }, + { + "leetcode-id": 1780, + "title": "Check if Number is a Sum of Powers of Three", + "difficulty": 2, + "description": "Given an integer n, return true if it is possible to represent n as the sum of distinct powers of three. Otherwise, return false.\nAn integer y is a power of three if there exists an integer x such that y == 3^x.", + "examples": [ + "Example 1:\nInput: n = 12\nOutput: true\nExplanation: 12 = 3^1 + 3^2", + "Example 2:\nInput: n = 91\nOutput: true\nExplanation: 91 = 3^0 + 3^2 + 3^4", + "Example 3:\nInput: n = 21\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^7", + "tags": [ + "Math" + ], + "title-slug": "check-if-number-is-a-sum-of-powers-of-three" + }, + { + "leetcode-id": 1781, + "title": "Sum of Beauty of All Substrings", + "difficulty": 2, + "description": "The beauty of a string is the difference in frequencies between the most frequent and least frequent characters.\n\nFor example, the beauty of \"abaacc\" is 3 - 1 = 2.\n\nGiven a string s, return the sum of beauty of all of its substrings.", + "examples": [ + "Example 1:\nInput: s = \"aabcb\"\nOutput: 5\nExplanation: The substrings with non-zero beauty are [\"aab\",\"aabc\",\"aabcb\",\"abcb\",\"bcb\"], each with beauty equal to 1.", + "Example 2:\nInput: s = \"aabcbaa\"\nOutput: 17" + ], + "constraints": "Constraints:\n\n1 <= s.length <=^ 500\ns consists of only lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Counting" + ], + "title-slug": "sum-of-beauty-of-all-substrings" + }, + { + "leetcode-id": 1782, + "title": "Count Pairs Of Nodes", + "difficulty": 3, + "description": "You are given an undirected graph defined by an integer n, the number of nodes, and a 2D integer array edges, the edges in the graph, where edges[i] = [ui, vi] indicates that there is an undirected edge between ui and vi. You are also given an integer array queries.\nLet incident(a, b) be defined as the number of edges that are connected to either node a or b.\nThe answer to the j^th query is the number of pairs of nodes (a, b) that satisfy both of the following conditions:\n\na < b\nincident(a, b) > queries[j]\n\nReturn an array answers such that answers.length == queries.length and answers[j] is the answer of the j^th query.\nNote that there can be multiple edges between the same two nodes.", + "examples": [ + "Example 1:\nInput: n = 4, edges = [[1,2],[2,4],[1,3],[2,3],[2,1]], queries = [2,3]\nOutput: [6,5]\nExplanation: The calculations for incident(a, b) are shown in the table above.\nThe answers for each of the queries are as follows:\n- answers[0] = 6. All the pairs have an incident(a, b) value greater than 2.\n- answers[1] = 5. All the pairs except (3, 4) have an incident(a, b) value greater than 3.", + "Example 2:\nInput: n = 5, edges = [[1,5],[1,5],[3,4],[2,5],[1,3],[5,1],[2,3],[2,5]], queries = [1,2,3,4,5]\nOutput: [10,10,9,8,6]" + ], + "constraints": "Constraints:\n\n2 <= n <= 2 * 10^4\n1 <= edges.length <= 10^5\n1 <= ui, vi <= n\nui != vi\n1 <= queries.length <= 20\n0 <= queries[j] < edges.length", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Graph", + "Sorting" + ], + "title-slug": "count-pairs-of-nodes" + }, + { + "leetcode-id": 1784, + "title": "Check if Binary String Has at Most One Segment of Ones", + "difficulty": 1, + "description": "Given a binary string s \u200b\u200b\u200b\u200b\u200bwithout leading zeros, return true\u200b\u200b\u200b if s contains at most one contiguous segment of ones. Otherwise, return false.", + "examples": [ + "Example 1:\nInput: s = \"1001\"\nOutput: false\nExplanation: The ones do not form a contiguous segment.", + "Example 2:\nInput: s = \"110\"\nOutput: true" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\ns[i]\u200b\u200b\u200b\u200b is either '0' or '1'.\ns[0] is\u00a0'1'.", + "tags": [ + "String" + ], + "title-slug": "check-if-binary-string-has-at-most-one-segment-of-ones" + }, + { + "leetcode-id": 1785, + "title": "Minimum Elements to Add to Form a Given Sum", + "difficulty": 2, + "description": "You are given an integer array nums and two integers limit and goal. The array nums has an interesting property that abs(nums[i]) <= limit.\nReturn the minimum number of elements you need to add to make the sum of the array equal to goal. The array must maintain its property that abs(nums[i]) <= limit.\nNote that abs(x) equals x if x >= 0, and -x otherwise.", + "examples": [ + "Example 1:\nInput: nums = [1,-1,1], limit = 3, goal = -4\nOutput: 2\nExplanation: You can add -2 and -3, then the sum of the array will be 1 - 1 + 1 - 2 - 3 = -4.", + "Example 2:\nInput: nums = [1,-10,9,1], limit = 100, goal = 0\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= limit <= 10^6\n-limit <= nums[i] <= limit\n-10^9 <= goal <= 10^9", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "minimum-elements-to-add-to-form-a-given-sum" + }, + { + "leetcode-id": 1786, + "title": "Number of Restricted Paths From First to Last Node", + "difficulty": 2, + "description": "There is an undirected weighted connected graph. You are given a positive integer n which denotes that the graph has n nodes labeled from 1 to n, and an array edges where each edges[i] = [ui, vi, weighti] denotes that there is an edge between nodes ui and vi with weight equal to weighti.\nA path from node start to node end is a sequence of nodes [z0, z1, z2, ..., zk] such that z0 = start and zk = end and there is an edge between zi and zi+1 where 0 <= i <= k-1.\nThe distance of a path is the sum of the weights on the edges of the path. Let distanceToLastNode(x) denote the shortest distance of a path between node n and node x. A restricted path is a path that also satisfies that distanceToLastNode(zi) > distanceToLastNode(zi+1) where 0 <= i <= k-1.\nReturn the number of restricted paths from node 1 to node n. Since that number may be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 5, edges = [[1,2,3],[1,3,3],[2,3,1],[1,4,2],[5,2,2],[3,5,1],[5,4,10]]\nOutput: 3\nExplanation: Each circle contains the node number in black and its distanceToLastNode value in blue. The three restricted paths are:\n1) 1 --> 2 --> 5\n2) 1 --> 2 --> 3 --> 5\n3) 1 --> 3 --> 5", + "Example 2:\nInput: n = 7, edges = [[1,3,1],[4,1,2],[7,3,4],[2,5,3],[5,6,1],[6,7,2],[7,5,3],[2,6,4]]\nOutput: 1\nExplanation: Each circle contains the node number in black and its distanceToLastNode value in blue. The only restricted path is 1 --> 3 --> 7." + ], + "constraints": "Constraints:\n\n1 <= n <= 2 * 10^4\nn - 1 <= edges.length <= 4 * 10^4\nedges[i].length == 3\n1 <= ui, vi <= n\nui != vi\n1 <= weighti <= 10^5\nThere is at most one edge between any two nodes.\nThere is at least one path between any two nodes.", + "tags": [ + "Dynamic Programming", + "Graph", + "Topological Sort", + "Heap (Priority Queue)", + "Shortest Path" + ], + "title-slug": "number-of-restricted-paths-from-first-to-last-node" + }, + { + "leetcode-id": 1787, + "title": "Make the XOR of All Segments Equal to Zero", + "difficulty": 3, + "description": "You are given an array nums\u200b\u200b\u200b and an integer k\u200b\u200b\u200b\u200b\u200b. The XOR of a segment [left, right] where left <= right is the XOR of all the elements with indices between left and right, inclusive: nums[left] XOR nums[left+1] XOR ... XOR nums[right].\nReturn the minimum number of elements to change in the array such that the XOR of all segments of size k\u200b\u200b\u200b\u200b\u200b\u200b is equal to zero.", + "examples": [ + "Example 1:\nInput: nums = [1,2,0,3,0], k = 1\nOutput: 3\nExplanation: Modify the array from [1,2,0,3,0] to from [0,0,0,0,0].", + "Example 2:\nInput: nums = [3,4,5,2,1,7,3,4,7], k = 3\nOutput: 3\nExplanation: Modify the array from [3,4,5,2,1,7,3,4,7] to [3,4,7,3,4,7,3,4,7].", + "Example 3:\nInput: nums = [1,2,4,1,2,5,1,2,6], k = 3\nOutput: 3\nExplanation: Modify the array from [1,2,4,1,2,5,1,2,6] to [1,2,3,1,2,3,1,2,3]." + ], + "constraints": "Constraints:\n\n1 <= k <= nums.length <= 2000\n\u200b\u200b\u200b\u200b\u200b\u200b0 <= nums[i] < 2^10", + "tags": [ + "Array", + "Dynamic Programming", + "Bit Manipulation" + ], + "title-slug": "make-the-xor-of-all-segments-equal-to-zero" + }, + { + "leetcode-id": 1790, + "title": "Check if One String Swap Can Make Strings Equal", + "difficulty": 1, + "description": "You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices.\nReturn true if it is possible to make both strings equal by performing at most one string swap on exactly one of the strings. Otherwise, return false.", + "examples": [ + "Example 1:\nInput: s1 = \"bank\", s2 = \"kanb\"\nOutput: true\nExplanation: For example, swap the first character with the last character of s2 to make \"bank\".", + "Example 2:\nInput: s1 = \"attack\", s2 = \"defend\"\nOutput: false\nExplanation: It is impossible to make them equal with one string swap.", + "Example 3:\nInput: s1 = \"kelb\", s2 = \"kelb\"\nOutput: true\nExplanation: The two strings are already equal, so no string swap operation is required." + ], + "constraints": "Constraints:\n\n1 <= s1.length, s2.length <= 100\ns1.length == s2.length\ns1 and s2 consist of only lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Counting" + ], + "title-slug": "check-if-one-string-swap-can-make-strings-equal" + }, + { + "leetcode-id": 1791, + "title": "Find Center of Star Graph", + "difficulty": 1, + "description": "There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.\nYou are given a 2D integer array edges where each edges[i] = [ui, vi] indicates that there is an edge between the nodes ui and vi. Return the center of the given star graph.", + "examples": [ + "Example 1:\nInput: edges = [[1,2],[2,3],[4,2]]\nOutput: 2\nExplanation: As shown in the figure above, node 2 is connected to every other node, so 2 is the center.", + "Example 2:\nInput: edges = [[1,2],[5,1],[1,3],[1,4]]\nOutput: 1" + ], + "constraints": "Constraints:\n\n3 <= n <= 10^5\nedges.length == n - 1\nedges[i].length == 2\n1 <= ui, vi <= n\nui != vi\nThe given edges represent a valid star graph.", + "tags": [ + "Graph" + ], + "title-slug": "find-center-of-star-graph" + }, + { + "leetcode-id": 1792, + "title": "Maximum Average Pass Ratio", + "difficulty": 2, + "description": "There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array classes, where classes[i] = [passi, totali]. You know beforehand that in the i^th class, there are totali total students, but only passi number of students will pass the exam.\nYou are also given an integer extraStudents. There are another extraStudents brilliant students that are guaranteed to pass the exam of any class they are assigned to. You want to assign each of the extraStudents students to a class in a way that maximizes the average pass ratio across all the classes.\nThe pass ratio of a class is equal to the number of students of the class that will pass the exam divided by the total number of students of the class. The average pass ratio is the sum of pass ratios of all the classes divided by the number of the classes.\nReturn the maximum possible average pass ratio after assigning the extraStudents students. Answers within 10^-5 of the actual answer will be accepted.", + "examples": [ + "Example 1:\nInput: classes = [[1,2],[3,5],[2,2]], extraStudents = 2\nOutput: 0.78333\nExplanation: You can assign the two extra students to the first class. The average pass ratio will be equal to (3/4 + 3/5 + 2/2) / 3 = 0.78333.", + "Example 2:\nInput: classes = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4\nOutput: 0.53485" + ], + "constraints": "Constraints:\n\n1 <= classes.length <= 10^5\nclasses[i].length == 2\n1 <= passi <= totali <= 10^5\n1 <= extraStudents <= 10^5", + "tags": [ + "Array", + "Greedy", + "Heap (Priority Queue)" + ], + "title-slug": "maximum-average-pass-ratio" + }, + { + "leetcode-id": 1793, + "title": "Maximum Score of a Good Subarray", + "difficulty": 3, + "description": "You are given an array of integers nums (0-indexed) and an integer k.\nThe score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1). A good subarray is a subarray where i <= k <= j.\nReturn the maximum possible score of a good subarray.", + "examples": [ + "Example 1:\nInput: nums = [1,4,3,7,4,5], k = 3\nOutput: 15\nExplanation: The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15.", + "Example 2:\nInput: nums = [5,5,4,5,4,1,1,1], k = 0\nOutput: 20\nExplanation: The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 2 * 10^4\n0 <= k < nums.length", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Stack", + "Monotonic Stack" + ], + "title-slug": "maximum-score-of-a-good-subarray" + }, + { + "leetcode-id": 1796, + "title": "Second Largest Digit in a String", + "difficulty": 1, + "description": "Given an alphanumeric string s, return the second largest numerical digit that appears in s, or -1 if it does not exist.\nAn alphanumeric string is a string consisting of lowercase English letters and digits.", + "examples": [ + "Example 1:\nInput: s = \"dfa12321afd\"\nOutput: 2\nExplanation: The digits that appear in s are [1, 2, 3]. The second largest digit is 2.", + "Example 2:\nInput: s = \"abc1111\"\nOutput: -1\nExplanation: The digits that appear in s are [1]. There is no second largest digit." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 500\ns consists of only lowercase English letters and/or digits.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "second-largest-digit-in-a-string" + }, + { + "leetcode-id": 1797, + "title": "Design Authentication Manager", + "difficulty": 2, + "description": "There is an authentication system that works with authentication tokens. For each session, the user will receive a new authentication token that will expire timeToLive seconds after the currentTime. If the token is renewed, the expiry time will be extended to expire timeToLive seconds after the (potentially different) currentTime.\nImplement the AuthenticationManager class:\n\nAuthenticationManager(int timeToLive) constructs the AuthenticationManager and sets the timeToLive.\ngenerate(string tokenId, int currentTime) generates a new token with the given tokenId at the given currentTime in seconds.\nrenew(string tokenId, int currentTime) renews the unexpired token with the given tokenId at the given currentTime in seconds. If there are no unexpired tokens with the given tokenId, the request is ignored, and nothing happens.\ncountUnexpiredTokens(int currentTime) returns the number of unexpired tokens at the given currentTime.\n\nNote that if a token expires at time t, and another action happens on time t (renew or countUnexpiredTokens), the expiration takes place before the other actions.", + "examples": [ + "Example 1:\nInput\n[\"AuthenticationManager\", \"renew\", \"generate\", \"countUnexpiredTokens\", \"generate\", \"renew\", \"renew\", \"countUnexpiredTokens\"]\n[[5], [\"aaa\", 1], [\"aaa\", 2], [6], [\"bbb\", 7], [\"aaa\", 8], [\"bbb\", 10], [15]]\nOutput\n[null, null, null, 1, null, null, null, 0]\n\nExplanation\nAuthenticationManager authenticationManager = new AuthenticationManager(5); // Constructs the AuthenticationManager with timeToLive = 5 seconds.\nauthenticationManager.renew(\"aaa\", 1); // No token exists with tokenId \"aaa\" at time 1, so nothing happens.\nauthenticationManager.generate(\"aaa\", 2); // Generates a new token with tokenId \"aaa\" at time 2.\nauthenticationManager.countUnexpiredTokens(6); // The token with tokenId \"aaa\" is the only unexpired one at time 6, so return 1.\nauthenticationManager.generate(\"bbb\", 7); // Generates a new token with tokenId \"bbb\" at time 7.\nauthenticationManager.renew(\"aaa\", 8); // The token with tokenId \"aaa\" expired at time 7, and 8 >= 7, so at time 8 the renew request is ignored, and nothing happens.\nauthenticationManager.renew(\"bbb\", 10); // The token with tokenId \"bbb\" is unexpired at time 10, so the renew request is fulfilled and now the token will expire at time 15.\nauthenticationManager.countUnexpiredTokens(15); // The token with tokenId \"bbb\" expires at time 15, and the token with tokenId \"aaa\" expired at time 7, so currently no token is unexpired, so return 0." + ], + "constraints": "Constraints:\n\n1 <= timeToLive <= 10^8\n1 <= currentTime <= 10^8\n1 <= tokenId.length <= 5\ntokenId consists only of lowercase letters.\nAll calls to generate will contain unique values of tokenId.\nThe values of currentTime across all the function calls will be strictly increasing.\nAt most 2000 calls will be made to all functions combined.", + "tags": [ + "Hash Table", + "Design" + ], + "title-slug": "design-authentication-manager" + }, + { + "leetcode-id": 1798, + "title": "Maximum Number of Consecutive Values You Can Make", + "difficulty": 2, + "description": "You are given an integer array coins of length n which represents the n coins that you own. The value of the i^th coin is coins[i]. You can make some value x if you can choose some of your n coins such that their values sum up to x.\nReturn the maximum number of consecutive integer values that you can make with your coins starting from and including 0.\nNote that you may have multiple coins of the same value.", + "examples": [ + "Example 1:\nInput: coins = [1,3]\nOutput: 2\nExplanation: You can make the following values:\n- 0: take []\n- 1: take [1]\nYou can make 2 consecutive integer values starting from 0.", + "Example 2:\nInput: coins = [1,1,1,4]\nOutput: 8\nExplanation: You can make the following values:\n- 0: take []\n- 1: take [1]\n- 2: take [1,1]\n- 3: take [1,1,1]\n- 4: take [4]\n- 5: take [4,1]\n- 6: take [4,1,1]\n- 7: take [4,1,1,1]\nYou can make 8 consecutive integer values starting from 0.", + "Example 3:\nInput: nums = [1,4,10,3,1]\nOutput: 20" + ], + "constraints": "Constraints:\n\ncoins.length == n\n1 <= n <= 4 * 10^4\n1 <= coins[i] <= 4 * 10^4", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "maximum-number-of-consecutive-values-you-can-make" + }, + { + "leetcode-id": 1799, + "title": "Maximize Score After N Operations", + "difficulty": 3, + "description": "You are given nums, an array of positive integers of size 2 * n. You must perform n operations on this array.\nIn the i^th operation (1-indexed), you will:\n\nChoose two elements, x and y.\nReceive a score of i * gcd(x, y).\nRemove x and y from nums.\n\nReturn the maximum score you can receive after performing n operations.\nThe function gcd(x, y) is the greatest common divisor of x and y.", + "examples": [ + "Example 1:\nInput: nums = [1,2]\nOutput: 1\nExplanation:\u00a0The optimal choice of operations is:\n(1 * gcd(1, 2)) = 1", + "Example 2:\nInput: nums = [3,4,6,8]\nOutput: 11\nExplanation:\u00a0The optimal choice of operations is:\n(1 * gcd(3, 6)) + (2 * gcd(4, 8)) = 3 + 8 = 11", + "Example 3:\nInput: nums = [1,2,3,4,5,6]\nOutput: 14\nExplanation:\u00a0The optimal choice of operations is:\n(1 * gcd(1, 5)) + (2 * gcd(2, 4)) + (3 * gcd(3, 6)) = 1 + 4 + 9 = 14" + ], + "constraints": "Constraints:\n\n1 <= n <= 7\nnums.length == 2 * n\n1 <= nums[i] <= 10^6", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Backtracking", + "Bit Manipulation", + "Number Theory", + "Bitmask" + ], + "title-slug": "maximize-score-after-n-operations" + }, + { + "leetcode-id": 1800, + "title": "Maximum Ascending Subarray Sum", + "difficulty": 1, + "description": "Given an array of positive integers nums, return the maximum possible sum of an ascending subarray in nums.\nA subarray is defined as a contiguous sequence of numbers in an array.\nA subarray [numsl, numsl+1, ..., numsr-1, numsr] is ascending if for all i where l <= i < r, numsi < numsi+1. Note that a subarray of size 1 is ascending.", + "examples": [ + "Example 1:\nInput: nums = [10,20,30,5,10,50]\nOutput: 65\nExplanation: [5,10,50] is the ascending subarray with the maximum sum of 65.", + "Example 2:\nInput: nums = [10,20,30,40,50]\nOutput: 150\nExplanation: [10,20,30,40,50] is the ascending subarray with the maximum sum of 150.", + "Example 3:\nInput: nums = [12,17,15,13,10,11,12]\nOutput: 33\nExplanation: [10,11,12] is the ascending subarray with the maximum sum of 33." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100", + "tags": [ + "Array" + ], + "title-slug": "maximum-ascending-subarray-sum" + }, + { + "leetcode-id": 1801, + "title": "Number of Orders in the Backlog", + "difficulty": 2, + "description": "You are given a 2D integer array orders, where each orders[i] = [pricei, amounti, orderTypei] denotes that amounti orders have been placed of type orderTypei at the price pricei. The orderTypei is:\n\n0 if it is a batch of buy orders, or\n1 if it is a batch of sell orders.\n\nNote that orders[i] represents a batch of amounti independent orders with the same price and order type. All orders represented by orders[i] will be placed before all orders represented by orders[i+1] for all valid i.\nThere is a backlog that consists of orders that have not been executed. The backlog is initially empty. When an order is placed, the following happens:\n\nIf the order is a buy order, you look at the sell order with the smallest price in the backlog. If that sell order's price is smaller than or equal to the current buy order's price, they will match and be executed, and that sell order will be removed from the backlog. Else, the buy order is added to the backlog.\nVice versa, if the order is a sell order, you look at the buy order with the largest price in the backlog. If that buy order's price is larger than or equal to the current sell order's price, they will match and be executed, and that buy order will be removed from the backlog. Else, the sell order is added to the backlog.\n\nReturn the total amount of orders in the backlog after placing all the orders from the input. Since this number can be large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: orders = [[10,5,0],[15,2,1],[25,1,1],[30,4,0]]\r\nOutput: 6\r\nExplanation: Here is what happens with the orders:\r\n- 5 orders of type buy with price 10 are placed. There are no sell orders, so the 5 orders are added to the backlog.\r\n- 2 orders of type sell with price 15 are placed. There are no buy orders with prices larger than or equal to 15, so the 2 orders are added to the backlog.\r\n- 1 order of type sell with price 25 is placed. There are no buy orders with prices larger than or equal to 25 in the backlog, so this order is added to the backlog.\r\n- 4 orders of type buy with price 30 are placed. The first 2 orders are matched with the 2 sell orders of the least price, which is 15 and these 2 sell orders are removed from the backlog. The 3^rd order is matched with the sell order of the least price, which is 25 and this sell order is removed from the backlog. Then, there are no more sell orders in the backlog, so the 4^th order is added to the backlog.\r\nFinally, the backlog has 5 buy orders with price 10, and 1 buy order with price 30. So the total number of orders in the backlog is 6.", + "Example 2:\nInput: orders = [[7,1000000000,1],[15,3,0],[5,999999995,0],[5,1,1]]\r\nOutput: 999999984\r\nExplanation: Here is what happens with the orders:\r\n- 10^9 orders of type sell with price 7 are placed. There are no buy orders, so the 10^9 orders are added to the backlog.\r\n- 3 orders of type buy with price 15 are placed. They are matched with the 3 sell orders with the least price which is 7, and those 3 sell orders are removed from the backlog.\r\n- 999999995 orders of type buy with price 5 are placed. The least price of a sell order is 7, so the 999999995 orders are added to the backlog.\r\n- 1 order of type sell with price 5 is placed. It is matched with the buy order of the highest price, which is 5, and that buy order is removed from the backlog.\r\nFinally, the backlog has (1000000000-3) sell orders with price 7, and (999999995-1) buy orders with price 5. So the total number of orders = 1999999991, which is equal to 999999984 % (10^9 + 7)." + ], + "constraints": "Constraints:\n\n1 <= orders.length <= 10^5\norders[i].length == 3\n1 <= pricei, amounti <= 10^9\norderTypei is either 0 or 1.", + "tags": [ + "Array", + "Heap (Priority Queue)", + "Simulation" + ], + "title-slug": "number-of-orders-in-the-backlog" + }, + { + "leetcode-id": 1802, + "title": "Maximum Value at a Given Index in a Bounded Array", + "difficulty": 2, + "description": "You are given three positive integers:\u00a0n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions:\n\nnums.length == n\nnums[i] is a positive integer where 0 <= i < n.\nabs(nums[i] - nums[i+1]) <= 1 where 0 <= i < n-1.\nThe sum of all the elements of nums does not exceed maxSum.\nnums[index] is maximized.\n\nReturn nums[index] of the constructed array.\nNote that abs(x) equals x if x >= 0, and -x otherwise.", + "examples": [ + "Example 1:\nInput: n = 4, index = 2, maxSum = 6\nOutput: 2\nExplanation: nums = [1,2,2,1] is one array that satisfies all the conditions.\nThere are no arrays that satisfy all the conditions and have nums[2] == 3, so 2 is the maximum nums[2].", + "Example 2:\nInput: n = 6, index = 1, maxSum = 10\nOutput: 3" + ], + "constraints": "Constraints:\n\n1 <= n <= maxSum <= 10^9\n0 <= index < n", + "tags": [ + "Binary Search", + "Greedy" + ], + "title-slug": "maximum-value-at-a-given-index-in-a-bounded-array" + }, + { + "leetcode-id": 1803, + "title": "Count Pairs With XOR in a Range", + "difficulty": 3, + "description": "Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.\nA nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high.", + "examples": [ + "Example 1:\nInput: nums = [1,4,2,7], low = 2, high = 6\r\nOutput: 6\r\nExplanation: All nice pairs (i, j) are as follows:\r\n - (0, 1): nums[0] XOR nums[1] = 5 \r\n - (0, 2): nums[0] XOR nums[2] = 3\r\n - (0, 3): nums[0] XOR nums[3] = 6\r\n - (1, 2): nums[1] XOR nums[2] = 6\r\n - (1, 3): nums[1] XOR nums[3] = 3\r\n - (2, 3): nums[2] XOR nums[3] = 5", + "Example 2:\nInput: nums = [9,8,4,2,1], low = 5, high = 14\r\nOutput: 8\r\nExplanation: All nice pairs (i, j) are as follows:\r\n\u200b\u200b\u200b\u200b\u200b - (0, 2): nums[0] XOR nums[2] = 13\r\n\u00a0 - (0, 3): nums[0] XOR nums[3] = 11\r\n\u00a0 - (0, 4): nums[0] XOR nums[4] = 8\r\n\u00a0 - (1, 2): nums[1] XOR nums[2] = 12\r\n\u00a0 - (1, 3): nums[1] XOR nums[3] = 10\r\n\u00a0 - (1, 4): nums[1] XOR nums[4] = 9\r\n\u00a0 - (2, 3): nums[2] XOR nums[3] = 6\r\n\u00a0 - (2, 4): nums[2] XOR nums[4] = 5" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 2 * 10^4\n1 <= nums[i] <= 2 * 10^4\n1 <= low <= high <= 2 * 10^4", + "tags": [ + "Array", + "Bit Manipulation", + "Trie" + ], + "title-slug": "count-pairs-with-xor-in-a-range" + }, + { + "leetcode-id": 1805, + "title": "Number of Different Integers in a String", + "difficulty": 1, + "description": "You are given a string word that consists of digits and lowercase English letters.\nYou will replace every non-digit character with a space. For example, \"a123bc34d8ef34\" will become \" 123\u00a0 34 8\u00a0 34\". Notice that you are left with some integers that are separated by at least one space: \"123\", \"34\", \"8\", and \"34\".\nReturn the number of different integers after performing the replacement operations on word.\nTwo integers are considered different if their decimal representations without any leading zeros are different.", + "examples": [ + "Example 1:\nInput: word = \"a123bc34d8ef34\"\nOutput: 3\nExplanation: The three different integers are \"123\", \"34\", and \"8\". Notice that \"34\" is only counted once.", + "Example 2:\nInput: word = \"leet1234code234\"\nOutput: 2", + "Example 3:\nInput: word = \"a1b01c001\"\nOutput: 1\nExplanation: The three integers \"1\", \"01\", and \"001\" all represent the same integer because\nthe leading zeros are ignored when comparing their decimal values." + ], + "constraints": "Constraints:\n\n1 <= word.length <= 1000\nword consists of digits and lowercase English letters.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "number-of-different-integers-in-a-string" + }, + { + "leetcode-id": 1806, + "title": "Minimum Number of Operations to Reinitialize a Permutation", + "difficulty": 2, + "description": "You are given an even integer n\u200b\u200b\u200b\u200b\u200b\u200b. You initially have a permutation perm of size n\u200b\u200b where perm[i] == i\u200b (0-indexed)\u200b\u200b\u200b\u200b.\nIn one operation, you will create a new array arr, and for each i:\n\nIf i % 2 == 0, then arr[i] = perm[i / 2].\nIf i % 2 == 1, then arr[i] = perm[n / 2 + (i - 1) / 2].\n\nYou will then assign arr\u200b\u200b\u200b\u200b to perm.\nReturn the minimum non-zero number of operations you need to perform on perm to return the permutation to its initial value.", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: 1\nExplanation: perm = [0,1] initially.\nAfter the 1^st operation, perm = [0,1]\nSo it takes only 1 operation.", + "Example 2:\nInput: n = 4\nOutput: 2\nExplanation: perm = [0,1,2,3] initially.\nAfter the 1^st operation, perm = [0,2,1,3]\nAfter the 2^nd operation, perm = [0,1,2,3]\nSo it takes only 2 operations.", + "Example 3:\nInput: n = 6\nOutput: 4" + ], + "constraints": "Constraints:\n\n2 <= n <= 1000\nn\u200b\u200b\u200b\u200b\u200b\u200b is even.", + "tags": [ + "Array", + "Math", + "Simulation" + ], + "title-slug": "minimum-number-of-operations-to-reinitialize-a-permutation" + }, + { + "leetcode-id": 1807, + "title": "Evaluate the Bracket Pairs of a String", + "difficulty": 2, + "description": "You are given a string s that contains some bracket pairs, with each pair containing a non-empty key.\n\nFor example, in the string \"(name)is(age)yearsold\", there are two bracket pairs that contain the keys \"name\" and \"age\".\n\nYou know the values of a wide range of keys. This is represented by a 2D string array knowledge where each knowledge[i] = [keyi, valuei] indicates that key keyi has a value of valuei.\nYou are tasked to evaluate all of the bracket pairs. When you evaluate a bracket pair that contains some key keyi, you will:\n\nReplace keyi and the bracket pair with the key's corresponding valuei.\nIf you do not know the value of the key, you will replace keyi and the bracket pair with a question mark \"?\" (without the quotation marks).\n\nEach key will appear at most once in your knowledge. There will not be any nested brackets in s.\nReturn the resulting string after evaluating all of the bracket pairs.", + "examples": [ + "Example 1:\nInput: s = \"(name)is(age)yearsold\", knowledge = [[\"name\",\"bob\"],[\"age\",\"two\"]]\nOutput: \"bobistwoyearsold\"\nExplanation:\nThe key \"name\" has a value of \"bob\", so replace \"(name)\" with \"bob\".\nThe key \"age\" has a value of \"two\", so replace \"(age)\" with \"two\".", + "Example 2:\nInput: s = \"hi(name)\", knowledge = [[\"a\",\"b\"]]\nOutput: \"hi?\"\nExplanation: As you do not know the value of the key \"name\", replace \"(name)\" with \"?\".", + "Example 3:\nInput: s = \"(a)(a)(a)aaa\", knowledge = [[\"a\",\"yes\"]]\nOutput: \"yesyesyesaaa\"\nExplanation: The same key can appear multiple times.\nThe key \"a\" has a value of \"yes\", so replace all occurrences of \"(a)\" with \"yes\".\nNotice that the \"a\"s not in a bracket pair are not evaluated." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\n0 <= knowledge.length <= 10^5\nknowledge[i].length == 2\n1 <= keyi.length, valuei.length <= 10\ns consists of lowercase English letters and round brackets '(' and ')'.\nEvery open bracket '(' in s will have a corresponding close bracket ')'.\nThe key in each bracket pair of s will be non-empty.\nThere will not be any nested bracket pairs in s.\nkeyi and valuei consist of lowercase English letters.\nEach keyi in knowledge is unique.", + "tags": [ + "Array", + "Hash Table", + "String" + ], + "title-slug": "evaluate-the-bracket-pairs-of-a-string" + }, + { + "leetcode-id": 1808, + "title": "Maximize Number of Nice Divisors", + "difficulty": 3, + "description": "You are given a positive integer primeFactors. You are asked to construct a positive integer n that satisfies the following conditions:\n\nThe number of prime factors of n (not necessarily distinct) is at most primeFactors.\nThe number of nice divisors of n is maximized. Note that a divisor of n is nice if it is divisible by every prime factor of n. For example, if n = 12, then its prime factors are [2,2,3], then 6 and 12 are nice divisors, while 3 and 4 are not.\n\nReturn the number of nice divisors of n. Since that number can be too large, return it modulo 10^9 + 7.\nNote that a prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. The prime factors of a number n is a list of prime numbers such that their product equals n.", + "examples": [ + "Example 1:\nInput: primeFactors = 5\r\nOutput: 6\r\nExplanation: 200 is a valid value of n.\r\nIt has 5 prime factors: [2,2,2,5,5], and it has 6 nice divisors: [10,20,40,50,100,200].\r\nThere is not other value of n that has at most 5 prime factors and more nice divisors.", + "Example 2:\nInput: primeFactors = 8\r\nOutput: 18" + ], + "constraints": "Constraints:\n\n1 <= primeFactors <= 10^9", + "tags": [ + "Math", + "Recursion" + ], + "title-slug": "maximize-number-of-nice-divisors" + }, + { + "leetcode-id": 1812, + "title": "Determine Color of a Chessboard Square", + "difficulty": 1, + "description": "You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.\n\nReturn true if the square is white, and false if the square is black.\nThe coordinate will always represent a valid chessboard square. The coordinate will always have the letter first, and the number second.", + "examples": [ + "Example 1:\nInput: coordinates = \"a1\"\nOutput: false\nExplanation: From the chessboard above, the square with coordinates \"a1\" is black, so return false.", + "Example 2:\nInput: coordinates = \"h3\"\nOutput: true\nExplanation: From the chessboard above, the square with coordinates \"h3\" is white, so return true.", + "Example 3:\nInput: coordinates = \"c7\"\nOutput: false" + ], + "constraints": "Constraints:\n\ncoordinates.length == 2\n'a' <= coordinates[0] <= 'h'\n'1' <= coordinates[1] <= '8'", + "tags": [ + "Math", + "String" + ], + "title-slug": "determine-color-of-a-chessboard-square" + }, + { + "leetcode-id": 1813, + "title": "Sentence Similarity III", + "difficulty": 2, + "description": "A sentence is a list of words that are separated by a single space with no leading or trailing spaces. For example, \"Hello World\", \"HELLO\", \"hello world hello world\" are all sentences. Words consist of only uppercase and lowercase English letters.\nTwo sentences sentence1 and sentence2 are similar if it is possible to insert an arbitrary sentence (possibly empty) inside one of these sentences such that the two sentences become equal. For example, sentence1 = \"Hello my name is Jane\" and sentence2 = \"Hello Jane\" can be made equal by inserting \"my name is\" between \"Hello\" and \"Jane\" in sentence2.\nGiven two sentences sentence1 and sentence2, return true if sentence1 and sentence2 are similar. Otherwise, return false.", + "examples": [ + "Example 1:\nInput: sentence1 = \"My name is Haley\", sentence2 = \"My Haley\"\nOutput: true\nExplanation: sentence2 can be turned to sentence1 by inserting \"name is\" between \"My\" and \"Haley\".", + "Example 2:\nInput: sentence1 = \"of\", sentence2 = \"A lot of words\"\nOutput: false\nExplanation: No single sentence can be inserted inside one of the sentences to make it equal to the other.", + "Example 3:\nInput: sentence1 = \"Eating right now\", sentence2 = \"Eating\"\nOutput: true\nExplanation: sentence2 can be turned to sentence1 by inserting \"right now\" at the end of the sentence." + ], + "constraints": "Constraints:\n\n1 <= sentence1.length, sentence2.length <= 100\nsentence1 and sentence2 consist of lowercase and uppercase English letters and spaces.\nThe words in sentence1 and sentence2 are separated by a single space.", + "tags": [ + "Array", + "Two Pointers", + "String" + ], + "title-slug": "sentence-similarity-iii" + }, + { + "leetcode-id": 1814, + "title": "Count Nice Pairs in an Array", + "difficulty": 2, + "description": "You are given an array nums that consists of non-negative integers. Let us define rev(x) as the reverse of the non-negative integer x. For example, rev(123) = 321, and rev(120) = 21. A pair of indices (i, j) is nice if it satisfies all of the following conditions:\n\n0 <= i < j < nums.length\nnums[i] + rev(nums[j]) == nums[j] + rev(nums[i])\n\nReturn the number of nice pairs of indices. Since that number can be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: nums = [42,11,1,97]\nOutput: 2\nExplanation: The two pairs are:\n - (0,3) : 42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121.\n - (1,2) : 11 + rev(1) = 11 + 1 = 12, 1 + rev(11) = 1 + 11 = 12.", + "Example 2:\nInput: nums = [13,10,35,24,76]\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Hash Table", + "Math", + "Counting" + ], + "title-slug": "count-nice-pairs-in-an-array" + }, + { + "leetcode-id": 1815, + "title": "Maximum Number of Groups Getting Fresh Donuts", + "difficulty": 3, + "description": "There is a donuts shop that bakes donuts in batches of batchSize. They have a rule where they must serve all of the donuts of a batch before serving any donuts of the next batch. You are given an integer batchSize and an integer array groups, where groups[i] denotes that there is a group of groups[i] customers that will visit the shop. Each customer will get exactly one donut.\nWhen a group visits the shop, all customers of the group must be served before serving any of the following groups. A group will be happy if they all get fresh donuts. That is, the first customer of the group does not receive a donut that was left over from the previous group.\nYou can freely rearrange the ordering of the groups. Return the maximum possible number of happy groups after rearranging the groups.", + "examples": [ + "Example 1:\nInput: batchSize = 3, groups = [1,2,3,4,5,6]\nOutput: 4\nExplanation: You can arrange the groups as [6,2,4,5,1,3]. Then the 1^st, 2^nd, 4^th, and 6^th groups will be happy.", + "Example 2:\nInput: batchSize = 4, groups = [1,3,2,5,2,2,1,6]\nOutput: 4" + ], + "constraints": "Constraints:\n\n1 <= batchSize <= 9\n1 <= groups.length <= 30\n1 <= groups[i] <= 10^9", + "tags": [ + "Array", + "Dynamic Programming", + "Bit Manipulation", + "Memoization", + "Bitmask" + ], + "title-slug": "maximum-number-of-groups-getting-fresh-donuts" + }, + { + "leetcode-id": 1816, + "title": "Truncate Sentence", + "difficulty": 1, + "description": "A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation).\n\nFor example, \"Hello World\", \"HELLO\", and \"hello world hello world\" are all sentences.\n\nYou are given a sentence s\u200b\u200b\u200b\u200b\u200b\u200b and an integer k\u200b\u200b\u200b\u200b\u200b\u200b. You want to truncate s\u200b\u200b\u200b\u200b\u200b\u200b such that it contains only the first k\u200b\u200b\u200b\u200b\u200b\u200b words. Return s\u200b\u200b\u200b\u200b\u200b\u200b after truncating it.", + "examples": [ + "Example 1:\nInput: s = \"Hello how are you Contestant\", k = 4\nOutput: \"Hello how are you\"\nExplanation:\nThe words in s are [\"Hello\", \"how\" \"are\", \"you\", \"Contestant\"].\nThe first 4 words are [\"Hello\", \"how\", \"are\", \"you\"].\nHence, you should return \"Hello how are you\".", + "Example 2:\nInput: s = \"What is the solution to this problem\", k = 4\nOutput: \"What is the solution\"\nExplanation:\nThe words in s are [\"What\", \"is\" \"the\", \"solution\", \"to\", \"this\", \"problem\"].\nThe first 4 words are [\"What\", \"is\", \"the\", \"solution\"].\nHence, you should return \"What is the solution\".", + "Example 3:\nInput: s = \"chopper is not a tanuki\", k = 5\nOutput: \"chopper is not a tanuki\"" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 500\nk is in the range [1, the number of words in s].\ns consist of only lowercase and uppercase English letters and spaces.\nThe words in s are separated by a single space.\nThere are no leading or trailing spaces.", + "tags": [ + "Array", + "String" + ], + "title-slug": "truncate-sentence" + }, + { + "leetcode-id": 1817, + "title": "Finding the Users Active Minutes", + "difficulty": 2, + "description": "You are given the logs for users' actions on LeetCode, and an integer k. The logs are represented by a 2D integer array logs where each logs[i] = [IDi, timei] indicates that the user with IDi performed an action at the minute timei.\nMultiple users can perform actions simultaneously, and a single user can perform multiple actions in the same minute.\nThe user active minutes (UAM) for a given user is defined as the number of unique minutes in which the user performed an action on LeetCode. A minute can only be counted once, even if multiple actions occur during it.\nYou are to calculate a 1-indexed array answer of size k such that, for each j (1 <= j <= k), answer[j] is the number of users whose UAM equals j.\nReturn the array answer as described above.", + "examples": [ + "Example 1:\nInput: logs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5\nOutput: [0,2,0,0,0]\nExplanation:\nThe user with ID=0 performed actions at minutes 5, 2, and 5 again. Hence, they have a UAM of 2 (minute 5 is only counted once).\nThe user with ID=1 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.\nSince both users have a UAM of 2, answer[2] is 2, and the remaining answer[j] values are 0.", + "Example 2:\nInput: logs = [[1,1],[2,2],[2,3]], k = 4\nOutput: [1,1,0,0]\nExplanation:\nThe user with ID=1 performed a single action at minute 1. Hence, they have a UAM of 1.\nThe user with ID=2 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.\nThere is one user with a UAM of 1 and one with a UAM of 2.\nHence, answer[1] = 1, answer[2] = 1, and the remaining values are 0." + ], + "constraints": "Constraints:\n\n1 <= logs.length <= 10^4\n0 <= IDi <= 10^9\n1 <= timei <= 10^5\nk is in the range [The maximum UAM for a user, 10^5].", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "finding-the-users-active-minutes" + }, + { + "leetcode-id": 1818, + "title": "Minimum Absolute Sum Difference", + "difficulty": 2, + "description": "You are given two positive integer arrays nums1 and nums2, both of length n.\nThe absolute sum difference of arrays nums1 and nums2 is defined as the sum of |nums1[i] - nums2[i]| for each 0 <= i < n (0-indexed).\nYou can replace at most one element of nums1 with any other element in nums1 to minimize the absolute sum difference.\nReturn the minimum absolute sum difference after replacing at most one element in the array nums1. Since the answer may be large, return it modulo 10^9 + 7.\n|x| is defined as:\n\nx if x >= 0, or\n-x if x < 0.", + "examples": [ + "Example 1:\nInput: nums1 = [1,7,5], nums2 = [2,3,5]\nOutput: 3\nExplanation: There are two possible optimal solutions:\n- Replace the second element with the first: [1,7,5] => [1,1,5], or\n- Replace the second element with the third: [1,7,5] => [1,5,5].\nBoth will yield an absolute sum difference of |1-2| + (|1-3| or |5-3|) + |5-5| = 3.", + "Example 2:\nInput: nums1 = [2,4,6,8,10], nums2 = [2,4,6,8,10]\nOutput: 0\nExplanation: nums1 is equal to nums2 so no replacement is needed. This will result in an \nabsolute sum difference of 0.", + "Example 3:\nInput: nums1 = [1,10,4,4,2,7], nums2 = [9,3,5,1,7,4]\nOutput: 20\nExplanation: Replace the first element with the second: [1,10,4,4,2,7] => [10,10,4,4,2,7].\nThis yields an absolute sum difference of |10-9| + |10-3| + |4-5| + |4-1| + |2-7| + |7-4| = 20" + ], + "constraints": "Constraints:\n\nn == nums1.length\nn == nums2.length\n1 <= n <= 10^5\n1 <= nums1[i], nums2[i] <= 10^5", + "tags": [ + "Array", + "Binary Search", + "Sorting", + "Ordered Set" + ], + "title-slug": "minimum-absolute-sum-difference" + }, + { + "leetcode-id": 1819, + "title": "Number of Different Subsequences GCDs", + "difficulty": 3, + "description": "You are given an array nums that consists of positive integers.\nThe GCD of a sequence of numbers is defined as the greatest integer that divides all the numbers in the sequence evenly.\n\nFor example, the GCD of the sequence [4,6,16] is 2.\n\nA subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array.\n\nFor example, [2,5,10] is a subsequence of [1,2,1,2,4,1,5,10].\n\nReturn the number of different GCDs among all non-empty subsequences of nums.", + "examples": [ + "Example 1:\nInput: nums = [6,10,3]\nOutput: 5\nExplanation: The figure shows all the non-empty subsequences and their GCDs.\nThe different GCDs are 6, 10, 3, 2, and 1.", + "Example 2:\nInput: nums = [5,15,40,5,6]\nOutput: 7" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 2 * 10^5", + "tags": [ + "Array", + "Math", + "Counting", + "Number Theory" + ], + "title-slug": "number-of-different-subsequences-gcds" + }, + { + "leetcode-id": 1822, + "title": "Sign of the Product of an Array", + "difficulty": 1, + "description": "There is a function signFunc(x) that returns:\n\n1 if x is positive.\n-1 if x is negative.\n0 if x is equal to 0.\n\nYou are given an integer array nums. Let product be the product of all values in the array nums.\nReturn signFunc(product).", + "examples": [ + "Example 1:\nInput: nums = [-1,-2,-3,-4,3,2,1]\nOutput: 1\nExplanation: The product of all values in the array is 144, and signFunc(144) = 1", + "Example 2:\nInput: nums = [1,5,0,2,-3]\nOutput: 0\nExplanation: The product of all values in the array is 0, and signFunc(0) = 0", + "Example 3:\nInput: nums = [-1,1,-1,1,-1]\nOutput: -1\nExplanation: The product of all values in the array is -1, and signFunc(-1) = -1" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n-100 <= nums[i] <= 100", + "tags": [ + "Array", + "Math" + ], + "title-slug": "sign-of-the-product-of-an-array" + }, + { + "leetcode-id": 1823, + "title": "Find the Winner of the Circular Game", + "difficulty": 2, + "description": "There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the i^th friend brings you to the (i+1)^th friend for 1 <= i < n, and moving clockwise from the n^th friend brings you to the 1^st friend.\nThe rules of the game are as follows:\n\nStart at the 1^st friend.\nCount the next k friends in the clockwise direction including the friend you started at. The counting wraps around the circle and may count some friends more than once.\nThe last friend you counted leaves the circle and loses the game.\nIf there is still more than one friend in the circle, go back to step 2 starting from the friend immediately clockwise of the friend who just lost and repeat.\nElse, the last friend in the circle wins the game.\n\nGiven the number of friends, n, and an integer k, return the winner of the game.", + "examples": [ + "Example 1:\nInput: n = 5, k = 2\nOutput: 3\nExplanation: Here are the steps of the game:\n1) Start at friend 1.\n2) Count 2 friends clockwise, which are friends 1 and 2.\n3) Friend 2 leaves the circle. Next start is friend 3.\n4) Count 2 friends clockwise, which are friends 3 and 4.\n5) Friend 4 leaves the circle. Next start is friend 5.\n6) Count 2 friends clockwise, which are friends 5 and 1.\n7) Friend 1 leaves the circle. Next start is friend 3.\n8) Count 2 friends clockwise, which are friends 3 and 5.\n9) Friend 5 leaves the circle. Only friend 3 is left, so they are the winner.", + "Example 2:\nInput: n = 6, k = 5\nOutput: 1\nExplanation: The friends leave in this order: 5, 4, 6, 2, 3. The winner is friend 1." + ], + "constraints": "Constraints:\n\n1 <= k <= n <= 500\n\n\u00a0\nFollow up:\nCould you solve this problem in linear time with constant space?", + "tags": [ + "Array", + "Math", + "Recursion", + "Queue", + "Simulation" + ], + "title-slug": "find-the-winner-of-the-circular-game" + }, + { + "leetcode-id": 1824, + "title": "Minimum Sideway Jumps", + "difficulty": 2, + "description": "There is a 3 lane road of length n that consists of n + 1 points labeled from 0 to n. A frog starts at point 0 in the second lane and wants to jump to point n. However, there could be obstacles along the way.\nYou are given an array obstacles of length n + 1 where each obstacles[i] (ranging from 0 to 3) describes an obstacle on the lane obstacles[i] at point i. If obstacles[i] == 0, there are no obstacles at point i. There will be at most one obstacle in the 3 lanes at each point.\n\nFor example, if obstacles[2] == 1, then there is an obstacle on lane 1 at point 2.\n\nThe frog can only travel from point i to point i + 1 on the same lane if there is not an obstacle on the lane at point i + 1. To avoid obstacles, the frog can also perform a side jump to jump to another lane (even if they are not adjacent) at the same point if there is no obstacle on the new lane.\n\nFor example, the frog can jump from lane 3 at point 3 to lane 1 at point 3.\n\nReturn the minimum number of side jumps the frog needs to reach any lane at point n starting from lane 2 at point 0.\nNote: There will be no obstacles on points 0 and n.", + "examples": [ + "Example 1:\nInput: obstacles = [0,1,2,3,0]\nOutput: 2 \nExplanation: The optimal solution is shown by the arrows above. There are 2 side jumps (red arrows).\nNote that the frog can jump over obstacles only when making side jumps (as shown at point 2).", + "Example 2:\nInput: obstacles = [0,1,1,3,3,0]\nOutput: 0\nExplanation: There are no obstacles on lane 2. No side jumps are required.", + "Example 3:\nInput: obstacles = [0,2,1,0,3,0]\nOutput: 2\nExplanation: The optimal solution is shown by the arrows above. There are 2 side jumps." + ], + "constraints": "Constraints:\n\nobstacles.length == n + 1\n1 <= n <= 5 * 10^5\n0 <= obstacles[i] <= 3\nobstacles[0] == obstacles[n] == 0", + "tags": [ + "Array", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "minimum-sideway-jumps" + }, + { + "leetcode-id": 1825, + "title": "Finding MK Average", + "difficulty": 3, + "description": "You are given two integers, m and k, and a stream of integers. You are tasked to implement a data structure that calculates the MKAverage for the stream.\nThe MKAverage can be calculated using these steps:\n\nIf the number of the elements in the stream is less than m you should consider the MKAverage to be -1. Otherwise, copy the last m elements of the stream to a separate container.\nRemove the smallest k elements and the largest k elements from the container.\nCalculate the average value for the rest of the elements rounded down to the nearest integer.\n\nImplement the MKAverage class:\n\nMKAverage(int m, int k) Initializes the MKAverage object with an empty stream and the two integers m and k.\nvoid addElement(int num) Inserts a new element num into the stream.\nint calculateMKAverage() Calculates and returns the MKAverage for the current stream rounded down to the nearest integer.", + "examples": [ + "Example 1:\nInput\n[\"MKAverage\", \"addElement\", \"addElement\", \"calculateMKAverage\", \"addElement\", \"calculateMKAverage\", \"addElement\", \"addElement\", \"addElement\", \"calculateMKAverage\"]\n[[3, 1], [3], [1], [], [10], [], [5], [5], [5], []]\nOutput\n[null, null, null, -1, null, 3, null, null, null, 5]\n\nExplanation\nMKAverage obj = new MKAverage(3, 1); \nobj.addElement(3); // current elements are [3]\nobj.addElement(1); // current elements are [3,1]\nobj.calculateMKAverage(); // return -1, because m = 3 and only 2 elements exist.\nobj.addElement(10); // current elements are [3,1,10]\nobj.calculateMKAverage(); // The last 3 elements are [3,1,10].\n // After removing smallest and largest 1 element the container will be [3].\n // The average of [3] equals 3/1 = 3, return 3\nobj.addElement(5); // current elements are [3,1,10,5]\nobj.addElement(5); // current elements are [3,1,10,5,5]\nobj.addElement(5); // current elements are [3,1,10,5,5,5]\nobj.calculateMKAverage(); // The last 3 elements are [5,5,5].\n // After removing smallest and largest 1 element the container will be [5].\n // The average of [5] equals 5/1 = 5, return 5" + ], + "constraints": "Constraints:\n\n3 <= m <= 10^5\n1 <= k*2 < m\n1 <= num <= 10^5\nAt most 10^5 calls will be made to addElement and calculateMKAverage.", + "tags": [ + "Design", + "Queue", + "Heap (Priority Queue)", + "Data Stream", + "Ordered Set" + ], + "title-slug": "finding-mk-average" + }, + { + "leetcode-id": 1827, + "title": "Minimum Operations to Make the Array Increasing", + "difficulty": 1, + "description": "You are given an integer array nums (0-indexed). In one operation, you can choose an element of the array and increment it by 1.\n\nFor example, if nums = [1,2,3], you can choose to increment nums[1] to make nums = [1,3,3].\n\nReturn the minimum number of operations needed to make nums strictly increasing.\nAn array nums is strictly increasing if nums[i] < nums[i+1] for all 0 <= i < nums.length - 1. An array of length 1 is trivially strictly increasing.", + "examples": [ + "Example 1:\nInput: nums = [1,1,1]\r\nOutput: 3\r\nExplanation: You can do the following operations:\r\n1) Increment nums[2], so nums becomes [1,1,2].\r\n2) Increment nums[1], so nums becomes [1,2,2].\r\n3) Increment nums[2], so nums becomes [1,2,3].", + "Example 2:\nInput: nums = [1,5,2,4,1]\r\nOutput: 14", + "Example 3:\nInput: nums = [8]\r\nOutput: 0" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 5000\n1 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "minimum-operations-to-make-the-array-increasing" + }, + { + "leetcode-id": 1828, + "title": "Queries on Number of Points Inside a Circle", + "difficulty": 2, + "description": "You are given an array points where points[i] = [xi, yi] is the coordinates of the i^th point on a 2D plane. Multiple points can have the same coordinates.\nYou are also given an array queries where queries[j] = [xj, yj, rj] describes a circle centered at (xj, yj) with a radius of rj.\nFor each query queries[j], compute the number of points inside the j^th circle. Points on the border of the circle are considered inside.\nReturn an array answer, where answer[j] is the answer to the j^th query.", + "examples": [ + "Example 1:\nInput: points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]\nOutput: [3,2,2]\nExplanation: The points and circles are shown above.\nqueries[0] is the green circle, queries[1] is the red circle, and queries[2] is the blue circle.", + "Example 2:\nInput: points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]\nOutput: [2,3,2,4]\nExplanation: The points and circles are shown above.\nqueries[0] is green, queries[1] is red, queries[2] is blue, and queries[3] is purple." + ], + "constraints": "Constraints:\n\n1 <= points.length <= 500\npoints[i].length == 2\n0 <= x\u200b\u200b\u200b\u200b\u200b\u200bi, y\u200b\u200b\u200b\u200b\u200b\u200bi <= 500\n1 <= queries.length <= 500\nqueries[j].length == 3\n0 <= xj, yj <= 500\n1 <= rj <= 500\nAll coordinates are integers.\n\n\u00a0\nFollow up: Could you find the answer for each query in better complexity than O(n)?", + "tags": [ + "Array", + "Math", + "Geometry" + ], + "title-slug": "queries-on-number-of-points-inside-a-circle" + }, + { + "leetcode-id": 1829, + "title": "Maximum XOR for Each Query", + "difficulty": 2, + "description": "You are given a sorted array nums of n non-negative integers and an integer maximumBit. You want to perform the following query n times:\n\nFind a non-negative integer k < 2^maximumBit such that nums[0] XOR nums[1] XOR ... XOR nums[nums.length-1] XOR k is maximized. k is the answer to the i^th query.\nRemove the last element from the current array nums.\n\nReturn an array answer, where answer[i] is the answer to the i^th query.", + "examples": [ + "Example 1:\nInput: nums = [0,1,1,3], maximumBit = 2\nOutput: [0,3,2,3]\nExplanation: The queries are answered as follows:\n1^st query: nums = [0,1,1,3], k = 0 since 0 XOR 1 XOR 1 XOR 3 XOR 0 = 3.\n2^nd query: nums = [0,1,1], k = 3 since 0 XOR 1 XOR 1 XOR 3 = 3.\n3^rd query: nums = [0,1], k = 2 since 0 XOR 1 XOR 2 = 3.\n4^th query: nums = [0], k = 3 since 0 XOR 3 = 3.", + "Example 2:\nInput: nums = [2,3,4,7], maximumBit = 3\nOutput: [5,2,6,5]\nExplanation: The queries are answered as follows:\n1^st query: nums = [2,3,4,7], k = 5 since 2 XOR 3 XOR 4 XOR 7 XOR 5 = 7.\n2^nd query: nums = [2,3,4], k = 2 since 2 XOR 3 XOR 4 XOR 2 = 7.\n3^rd query: nums = [2,3], k = 6 since 2 XOR 3 XOR 6 = 7.\n4^th query: nums = [2], k = 5 since 2 XOR 5 = 7.", + "Example 3:\nInput: nums = [0,1,2,2,5,7], maximumBit = 3\nOutput: [4,3,6,4,6,7]" + ], + "constraints": "Constraints:\n\nnums.length == n\n1 <= n <= 10^5\n1 <= maximumBit <= 20\n0 <= nums[i] < 2^maximumBit\nnums\u200b\u200b\u200b is sorted in ascending order.", + "tags": [ + "Array", + "Bit Manipulation", + "Prefix Sum" + ], + "title-slug": "maximum-xor-for-each-query" + }, + { + "leetcode-id": 1830, + "title": "Minimum Number of Operations to Make String Sorted", + "difficulty": 3, + "description": "You are given a string s (0-indexed)\u200b\u200b\u200b\u200b\u200b\u200b. You are asked to perform the following operation on s\u200b\u200b\u200b\u200b\u200b\u200b until you get a sorted string:\n\nFind the largest index i such that 1 <= i < s.length and s[i] < s[i - 1].\nFind the largest index j such that i <= j < s.length and s[k] < s[i - 1] for all the possible values of k in the range [i, j] inclusive.\nSwap the two characters at indices i - 1\u200b\u200b\u200b\u200b and j\u200b\u200b\u200b\u200b\u200b.\nReverse the suffix starting at index i\u200b\u200b\u200b\u200b\u200b\u200b.\n\nReturn the number of operations needed to make the string sorted. Since the answer can be too large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: s = \"cba\"\nOutput: 5\nExplanation: The simulation goes as follows:\nOperation 1: i=2, j=2. Swap s[1] and s[2] to get s=\"cab\", then reverse the suffix starting at 2. Now, s=\"cab\".\nOperation 2: i=1, j=2. Swap s[0] and s[2] to get s=\"bac\", then reverse the suffix starting at 1. Now, s=\"bca\".\nOperation 3: i=2, j=2. Swap s[1] and s[2] to get s=\"bac\", then reverse the suffix starting at 2. Now, s=\"bac\".\nOperation 4: i=1, j=1. Swap s[0] and s[1] to get s=\"abc\", then reverse the suffix starting at 1. Now, s=\"acb\".\nOperation 5: i=2, j=2. Swap s[1] and s[2] to get s=\"abc\", then reverse the suffix starting at 2. Now, s=\"abc\".", + "Example 2:\nInput: s = \"aabaa\"\nOutput: 2\nExplanation: The simulation goes as follows:\nOperation 1: i=3, j=4. Swap s[2] and s[4] to get s=\"aaaab\", then reverse the substring starting at 3. Now, s=\"aaaba\".\nOperation 2: i=4, j=4. Swap s[3] and s[4] to get s=\"aaaab\", then reverse the substring starting at 4. Now, s=\"aaaab\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 3000\ns\u200b\u200b\u200b\u200b\u200b\u200b consists only of lowercase English letters.", + "tags": [ + "Math", + "String", + "Combinatorics" + ], + "title-slug": "minimum-number-of-operations-to-make-string-sorted" + }, + { + "leetcode-id": 1832, + "title": "Check if the Sentence Is Pangram", + "difficulty": 1, + "description": "A pangram is a sentence where every letter of the English alphabet appears at least once.\nGiven a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.", + "examples": [ + "Example 1:\nInput: sentence = \"thequickbrownfoxjumpsoverthelazydog\"\nOutput: true\nExplanation: sentence contains at least one of every letter of the English alphabet.", + "Example 2:\nInput: sentence = \"leetcode\"\nOutput: false" + ], + "constraints": "Constraints:\n\n1 <= sentence.length <= 1000\nsentence consists of lowercase English letters.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "check-if-the-sentence-is-pangram" + }, + { + "leetcode-id": 1833, + "title": "Maximum Ice Cream Bars", + "difficulty": 2, + "description": "It is a sweltering summer day, and a boy wants to buy some ice cream bars.\nAt the store, there are n ice cream bars. You are given an array costs of length n, where costs[i] is the price of the i^th ice cream bar in coins. The boy initially has coins coins to spend, and he wants to buy as many ice cream bars as possible.\u00a0\nNote: The boy can buy the ice cream bars in any order.\nReturn the maximum number of ice cream bars the boy can buy with coins coins.\nYou must solve the problem by counting sort.", + "examples": [ + "Example 1:\nInput: costs = [1,3,2,4,1], coins = 7\nOutput: 4\nExplanation: The boy can buy ice cream bars at indices 0,1,2,4 for a total price of 1 + 3 + 2 + 1 = 7.", + "Example 2:\nInput: costs = [10,6,8,7,7,8], coins = 5\nOutput: 0\nExplanation: The boy cannot afford any of the ice cream bars.", + "Example 3:\nInput: costs = [1,6,3,1,2,5], coins = 20\nOutput: 6\nExplanation: The boy can buy all the ice cream bars for a total price of 1 + 6 + 3 + 1 + 2 + 5 = 18." + ], + "constraints": "Constraints:\n\ncosts.length == n\n1 <= n <= 10^5\n1 <= costs[i] <= 10^5\n1 <= coins <= 10^8", + "tags": [ + "Array", + "Greedy", + "Sorting" + ], + "title-slug": "maximum-ice-cream-bars" + }, + { + "leetcode-id": 1834, + "title": "Single-Threaded CPU", + "difficulty": 2, + "description": "You are given n\u200b\u200b\u200b\u200b\u200b\u200b tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTimei, processingTimei] means that the i^\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b task will be available to process at enqueueTimei and will take processingTimei to finish processing.\nYou have a single-threaded CPU that can process at most one task at a time and will act in the following way:\n\nIf the CPU is idle and there are no available tasks to process, the CPU remains idle.\nIf the CPU is idle and there are available tasks, the CPU will choose the one with the shortest processing time. If multiple tasks have the same shortest processing time, it will choose the task with the smallest index.\nOnce a task is started, the CPU will process the entire task without stopping.\nThe CPU can finish a task then start a new one instantly.\n\nReturn the order in which the CPU will process the tasks.", + "examples": [ + "Example 1:\nInput: tasks = [[1,2],[2,4],[3,2],[4,1]]\nOutput: [0,2,3,1]\nExplanation: The events go as follows: \n- At time = 1, task 0 is available to process. Available tasks = {0}.\n- Also at time = 1, the idle CPU starts processing task 0. Available tasks = {}.\n- At time = 2, task 1 is available to process. Available tasks = {1}.\n- At time = 3, task 2 is available to process. Available tasks = {1, 2}.\n- Also at time = 3, the CPU finishes task 0 and starts processing task 2 as it is the shortest. Available tasks = {1}.\n- At time = 4, task 3 is available to process. Available tasks = {1, 3}.\n- At time = 5, the CPU finishes task 2 and starts processing task 3 as it is the shortest. Available tasks = {1}.\n- At time = 6, the CPU finishes task 3 and starts processing task 1. Available tasks = {}.\n- At time = 10, the CPU finishes task 1 and becomes idle.", + "Example 2:\nInput: tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]\nOutput: [4,3,2,0,1]\nExplanation: The events go as follows:\n- At time = 7, all the tasks become available. Available tasks = {0,1,2,3,4}.\n- Also at time = 7, the idle CPU starts processing task 4. Available tasks = {0,1,2,3}.\n- At time = 9, the CPU finishes task 4 and starts processing task 3. Available tasks = {0,1,2}.\n- At time = 13, the CPU finishes task 3 and starts processing task 2. Available tasks = {0,1}.\n- At time = 18, the CPU finishes task 2 and starts processing task 0. Available tasks = {1}.\n- At time = 28, the CPU finishes task 0 and starts processing task 1. Available tasks = {}.\n- At time = 40, the CPU finishes task 1 and becomes idle." + ], + "constraints": "Constraints:\n\ntasks.length == n\n1 <= n <= 10^5\n1 <= enqueueTimei, processingTimei <= 10^9", + "tags": [ + "Array", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "single-threaded-cpu" + }, + { + "leetcode-id": 1835, + "title": "Find XOR Sum of All Pairs Bitwise AND", + "difficulty": 3, + "description": "The XOR sum of a list is the bitwise XOR of all its elements. If the list only contains one element, then its XOR sum will be equal to this element.\n\nFor example, the XOR sum of [1,2,3,4] is equal to 1 XOR 2 XOR 3 XOR 4 = 4, and the XOR sum of [3] is equal to 3.\n\nYou are given two 0-indexed arrays arr1 and arr2 that consist only of non-negative integers.\nConsider the list containing the result of arr1[i] AND arr2[j] (bitwise AND) for every (i, j) pair where 0 <= i < arr1.length and 0 <= j < arr2.length.\nReturn the XOR sum of the aforementioned list.", + "examples": [ + "Example 1:\nInput: arr1 = [1,2,3], arr2 = [6,5]\nOutput: 0\nExplanation: The list = [1 AND 6, 1 AND 5, 2 AND 6, 2 AND 5, 3 AND 6, 3 AND 5] = [0,1,2,0,2,1].\nThe XOR sum = 0 XOR 1 XOR 2 XOR 0 XOR 2 XOR 1 = 0.", + "Example 2:\nInput: arr1 = [12], arr2 = [4]\nOutput: 4\nExplanation: The list = [12 AND 4] = [4]. The XOR sum = 4." + ], + "constraints": "Constraints:\n\n1 <= arr1.length, arr2.length <= 10^5\n0 <= arr1[i], arr2[j] <= 10^9", + "tags": [ + "Array", + "Math", + "Bit Manipulation" + ], + "title-slug": "find-xor-sum-of-all-pairs-bitwise-and" + }, + { + "leetcode-id": 1837, + "title": "Sum of Digits in Base K", + "difficulty": 1, + "description": "Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k.\nAfter converting, each digit should be interpreted as a base 10 number, and the sum should be returned in base 10.", + "examples": [ + "Example 1:\nInput: n = 34, k = 6\nOutput: 9\nExplanation: 34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.", + "Example 2:\nInput: n = 10, k = 10\nOutput: 1\nExplanation: n is already in base 10. 1 + 0 = 1." + ], + "constraints": "Constraints:\n\n1 <= n <= 100\n2 <= k <= 10", + "tags": [ + "Math" + ], + "title-slug": "sum-of-digits-in-base-k" + }, + { + "leetcode-id": 1838, + "title": "Frequency of the Most Frequent Element", + "difficulty": 2, + "description": "The frequency of an element is the number of times it occurs in an array.\nYou are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1.\nReturn the maximum possible frequency of an element after performing at most k operations.", + "examples": [ + "Example 1:\nInput: nums = [1,2,4], k = 5\nOutput: 3\nExplanation: Increment the first element three times and the second element two times to make nums = [4,4,4].\n4 has a frequency of 3.", + "Example 2:\nInput: nums = [1,4,8,13], k = 5\nOutput: 2\nExplanation: There are multiple optimal solutions:\n- Increment the first element three times to make nums = [4,4,8,13]. 4 has a frequency of 2.\n- Increment the second element four times to make nums = [1,8,8,13]. 8 has a frequency of 2.\n- Increment the third element five times to make nums = [1,4,13,13]. 13 has a frequency of 2.", + "Example 3:\nInput: nums = [3,9,6], k = 2\nOutput: 1" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^5\n1 <= k <= 10^5", + "tags": [ + "Array", + "Binary Search", + "Greedy", + "Sliding Window", + "Sorting", + "Prefix Sum" + ], + "title-slug": "frequency-of-the-most-frequent-element" + }, + { + "leetcode-id": 1839, + "title": "Longest Substring Of All Vowels in Order", + "difficulty": 2, + "description": "A string is considered beautiful if it satisfies the following conditions:\n\nEach of the 5 English vowels ('a', 'e', 'i', 'o', 'u') must appear at least once in it.\nThe letters must be sorted in alphabetical order (i.e. all 'a's before 'e's, all 'e's before 'i's, etc.).\n\nFor example, strings \"aeiou\" and \"aaaaaaeiiiioou\" are considered beautiful, but \"uaeio\", \"aeoiu\", and \"aaaeeeooo\" are not beautiful.\nGiven a string word consisting of English vowels, return the length of the longest beautiful substring of word. If no such substring exists, return 0.\nA substring is a contiguous sequence of characters in a string.", + "examples": [ + "Example 1:\nInput: word = \"aeiaaioaaaaeiiiiouuuooaauuaeiu\"\nOutput: 13\nExplanation: The longest beautiful substring in word is \"aaaaeiiiiouuu\" of length 13.", + "Example 2:\nInput: word = \"aeeeiiiioooauuuaeiou\"\nOutput: 5\nExplanation: The longest beautiful substring in word is \"aeiou\" of length 5.", + "Example 3:\nInput: word = \"a\"\nOutput: 0\nExplanation: There is no beautiful substring, so return 0." + ], + "constraints": "Constraints:\n\n1 <= word.length <= 5 * 10^5\nword consists of characters 'a', 'e', 'i', 'o', and 'u'.", + "tags": [ + "String", + "Sliding Window" + ], + "title-slug": "longest-substring-of-all-vowels-in-order" + }, + { + "leetcode-id": 1840, + "title": "Maximum Building Height", + "difficulty": 3, + "description": "You want to build n new buildings in a city. The new buildings will be built in a line and are labeled from 1 to n.\nHowever, there are city restrictions on the heights of the new buildings:\n\nThe height of each building must be a non-negative integer.\nThe height of the first building must be 0.\nThe height difference between any two adjacent buildings cannot exceed 1.\n\nAdditionally, there are city restrictions on the maximum height of specific buildings. These restrictions are given as a 2D integer array restrictions where restrictions[i] = [idi, maxHeighti] indicates that building idi must have a height less than or equal to maxHeighti.\nIt is guaranteed that each building will appear at most once in restrictions, and building 1 will not be in restrictions.\nReturn the maximum possible height of the tallest building.", + "examples": [ + "Example 1:\nInput: n = 5, restrictions = [[2,1],[4,1]]\nOutput: 2\nExplanation: The green area in the image indicates the maximum allowed height for each building.\nWe can build the buildings with heights [0,1,2,1,2], and the tallest building has a height of 2.", + "Example 2:\nInput: n = 6, restrictions = []\nOutput: 5\nExplanation: The green area in the image indicates the maximum allowed height for each building.\nWe can build the buildings with heights [0,1,2,3,4,5], and the tallest building has a height of 5.", + "Example 3:\nInput: n = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]]\nOutput: 5\nExplanation: The green area in the image indicates the maximum allowed height for each building.\nWe can build the buildings with heights [0,1,2,3,3,4,4,5,4,3], and the tallest building has a height of 5." + ], + "constraints": "Constraints:\n\n2 <= n <= 10^9\n0 <= restrictions.length <= min(n - 1, 10^5)\n2 <= idi <= n\nidi\u00a0is unique.\n0 <= maxHeighti <= 10^9", + "tags": [ + "Array", + "Math" + ], + "title-slug": "maximum-building-height" + }, + { + "leetcode-id": 1844, + "title": "Replace All Digits with Characters", + "difficulty": 1, + "description": "You are given a 0-indexed string s that has lowercase English letters in its even indices and digits in its odd indices.\nThere is a function shift(c, x), where c is a character and x is a digit, that returns the x^th character after c.\n\nFor example, shift('a', 5) = 'f' and shift('x', 0) = 'x'.\n\nFor every odd\u00a0index i, you want to replace the digit s[i] with shift(s[i-1], s[i]).\nReturn s after replacing all digits. It is guaranteed that shift(s[i-1], s[i]) will never exceed 'z'.", + "examples": [ + "Example 1:\nInput: s = \"a1c1e1\"\nOutput: \"abcdef\"\nExplanation: The digits are replaced as follows:\n- s[1] -> shift('a',1) = 'b'\n- s[3] -> shift('c',1) = 'd'\n- s[5] -> shift('e',1) = 'f'", + "Example 2:\nInput: s = \"a1b2c3d4e\"\nOutput: \"abbdcfdhe\"\nExplanation: The digits are replaced as follows:\n- s[1] -> shift('a',1) = 'b'\n- s[3] -> shift('b',2) = 'd'\n- s[5] -> shift('c',3) = 'f'\n- s[7] -> shift('d',4) = 'h'" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\ns consists only of lowercase English letters and digits.\nshift(s[i-1], s[i]) <= 'z' for all odd indices i.", + "tags": [ + "String" + ], + "title-slug": "replace-all-digits-with-characters" + }, + { + "leetcode-id": 1845, + "title": "Seat Reservation Manager", + "difficulty": 2, + "description": "Design a system that manages the reservation state of n seats that are numbered from 1 to n.\nImplement the SeatManager class:\n\nSeatManager(int n) Initializes a SeatManager object that will manage n seats numbered from 1 to n. All seats are initially available.\nint reserve() Fetches the smallest-numbered unreserved seat, reserves it, and returns its number.\nvoid unreserve(int seatNumber) Unreserves the seat with the given seatNumber.", + "examples": [ + "Example 1:\nInput\n[\"SeatManager\", \"reserve\", \"reserve\", \"unreserve\", \"reserve\", \"reserve\", \"reserve\", \"reserve\", \"unreserve\"]\n[[5], [], [], [2], [], [], [], [], [5]]\nOutput\n[null, 1, 2, null, 2, 3, 4, 5, null]\n\nExplanation\nSeatManager seatManager = new SeatManager(5); // Initializes a SeatManager with 5 seats.\nseatManager.reserve(); // All seats are available, so return the lowest numbered seat, which is 1.\nseatManager.reserve(); // The available seats are [2,3,4,5], so return the lowest of them, which is 2.\nseatManager.unreserve(2); // Unreserve seat 2, so now the available seats are [2,3,4,5].\nseatManager.reserve(); // The available seats are [2,3,4,5], so return the lowest of them, which is 2.\nseatManager.reserve(); // The available seats are [3,4,5], so return the lowest of them, which is 3.\nseatManager.reserve(); // The available seats are [4,5], so return the lowest of them, which is 4.\nseatManager.reserve(); // The only available seat is seat 5, so return 5.\nseatManager.unreserve(5); // Unreserve seat 5, so now the available seats are [5]." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5\n1 <= seatNumber <= n\nFor each call to reserve, it is guaranteed that there will be at least one unreserved seat.\nFor each call to unreserve, it is guaranteed that seatNumber will be reserved.\nAt most 10^5 calls in total will be made to reserve and unreserve.", + "tags": [ + "Design", + "Heap (Priority Queue)" + ], + "title-slug": "seat-reservation-manager" + }, + { + "leetcode-id": 1846, + "title": "Maximum Element After Decreasing and Rearranging", + "difficulty": 2, + "description": "You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it satisfies these conditions:\n\nThe value of the first element in arr must be 1.\nThe absolute difference between any 2 adjacent elements must be less than or equal to 1. In other words, abs(arr[i] - arr[i - 1]) <= 1 for each i where 1 <= i < arr.length (0-indexed). abs(x) is the absolute value of x.\n\nThere are 2 types of operations that you can perform any number of times:\n\nDecrease the value of any element of arr to a smaller positive integer.\nRearrange the elements of arr to be in any order.\n\nReturn the maximum possible value of an element in arr after performing the operations to satisfy the conditions.", + "examples": [ + "Example 1:\nInput: arr = [2,2,1,2,1]\nOutput: 2\nExplanation: \nWe can satisfy the conditions by rearranging arr so it becomes [1,2,2,2,1].\nThe largest element in arr is 2.", + "Example 2:\nInput: arr = [100,1,1000]\nOutput: 3\nExplanation: \nOne possible way to satisfy the conditions is by doing the following:\n1. Rearrange arr so it becomes [1,100,1000].\n2. Decrease the value of the second element to 2.\n3. Decrease the value of the third element to 3.\nNow arr = [1,2,3], which satisfies the conditions.\nThe largest element in arr is 3.", + "Example 3:\nInput: arr = [1,2,3,4,5]\nOutput: 5\nExplanation: The array already satisfies the conditions, and the largest element is 5." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^5\n1 <= arr[i] <= 10^9", + "tags": [ + "Array", + "Greedy", + "Sorting" + ], + "title-slug": "maximum-element-after-decreasing-and-rearranging" + }, + { + "leetcode-id": 1847, + "title": "Closest Room", + "difficulty": 3, + "description": "There is a hotel with n rooms. The rooms are represented by a 2D integer array rooms where rooms[i] = [roomIdi, sizei] denotes that there is a room with room number roomIdi and size equal to sizei. Each roomIdi is guaranteed to be unique.\nYou are also given k queries in a 2D array queries where queries[j] = [preferredj, minSizej]. The answer to the j^th query is the room number id of a room such that:\n\nThe room has a size of at least minSizej, and\nabs(id - preferredj) is minimized, where abs(x) is the absolute value of x.\n\nIf there is a tie in the absolute difference, then use the room with the smallest such id. If there is no such room, the answer is -1.\nReturn an array answer of length k where answer[j] contains the answer to the j^th query.", + "examples": [ + "Example 1:\nInput: rooms = [[2,2],[1,2],[3,2]], queries = [[3,1],[3,3],[5,2]]\nOutput: [3,-1,3]\nExplanation: The answers to the queries are as follows:\nQuery = [3,1]: Room number 3 is the closest as abs(3 - 3) = 0, and its size of 2 is at least 1. The answer is 3.\nQuery = [3,3]: There are no rooms with a size of at least 3, so the answer is -1.\nQuery = [5,2]: Room number 3 is the closest as abs(3 - 5) = 2, and its size of 2 is at least 2. The answer is 3.", + "Example 2:\nInput: rooms = [[1,4],[2,3],[3,5],[4,1],[5,2]], queries = [[2,3],[2,4],[2,5]]\nOutput: [2,1,3]\nExplanation: The answers to the queries are as follows:\nQuery = [2,3]: Room number 2 is the closest as abs(2 - 2) = 0, and its size of 3 is at least 3. The answer is 2.\nQuery = [2,4]: Room numbers 1 and 3 both have sizes of at least 4. The answer is 1 since it is smaller.\nQuery = [2,5]: Room number 3 is the only room with a size of at least 5. The answer is 3." + ], + "constraints": "Constraints:\n\nn == rooms.length\n1 <= n <= 10^5\nk == queries.length\n1 <= k <= 10^4\n1 <= roomIdi, preferredj <= 10^7\n1 <= sizei, minSizej <= 10^7", + "tags": [ + "Array", + "Binary Search", + "Sorting" + ], + "title-slug": "closest-room" + }, + { + "leetcode-id": 1848, + "title": "Minimum Distance to the Target Element", + "difficulty": 1, + "description": "Given an integer array nums (0-indexed) and two integers target and start, find an index i such that nums[i] == target and abs(i - start) is minimized. Note that\u00a0abs(x)\u00a0is the absolute value of x.\nReturn abs(i - start).\nIt is guaranteed that target exists in nums.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4,5], target = 5, start = 3\nOutput: 1\nExplanation: nums[4] = 5 is the only value equal to target, so the answer is abs(4 - 3) = 1.", + "Example 2:\nInput: nums = [1], target = 1, start = 0\nOutput: 0\nExplanation: nums[0] = 1 is the only value equal to target, so the answer is abs(0 - 0) = 0.", + "Example 3:\nInput: nums = [1,1,1,1,1,1,1,1,1,1], target = 1, start = 0\nOutput: 0\nExplanation: Every value of nums is 1, but nums[0] minimizes abs(i - start), which is abs(0 - 0) = 0." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 10^4\n0 <= start < nums.length\ntarget is in nums.", + "tags": [ + "Array" + ], + "title-slug": "minimum-distance-to-the-target-element" + }, + { + "leetcode-id": 1849, + "title": "Splitting a String Into Descending Consecutive Values", + "difficulty": 2, + "description": "You are given a string s that consists of only digits.\nCheck if we can split s into two or more non-empty substrings such that the numerical values of the substrings are in descending order and the difference between numerical values of every two adjacent substrings is equal to 1.\n\nFor example, the string s = \"0090089\" can be split into [\"0090\", \"089\"] with numerical values [90,89]. The values are in descending order and adjacent values differ by 1, so this way is valid.\nAnother example, the string s = \"001\" can be split into [\"0\", \"01\"], [\"00\", \"1\"], or [\"0\", \"0\", \"1\"]. However all the ways are invalid because they have numerical values [0,1], [0,1], and [0,0,1] respectively, all of which are not in descending order.\n\nReturn true if it is possible to split s\u200b\u200b\u200b\u200b\u200b\u200b as described above, or false otherwise.\nA substring is a contiguous sequence of characters in a string.", + "examples": [ + "Example 1:\nInput: s = \"1234\"\nOutput: false\nExplanation: There is no valid way to split s.", + "Example 2:\nInput: s = \"050043\"\nOutput: true\nExplanation: s can be split into [\"05\", \"004\", \"3\"] with numerical values [5,4,3].\nThe values are in descending order with adjacent values differing by 1.", + "Example 3:\nInput: s = \"9080701\"\nOutput: false\nExplanation: There is no valid way to split s." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 20\ns only consists of digits.", + "tags": [ + "String", + "Backtracking" + ], + "title-slug": "splitting-a-string-into-descending-consecutive-values" + }, + { + "leetcode-id": 1850, + "title": "Minimum Adjacent Swaps to Reach the Kth Smallest Number", + "difficulty": 2, + "description": "You are given a string num, representing a large integer, and an integer k.\nWe call some integer wonderful if it is a permutation of the digits in num and is greater in value than num. There can be many wonderful integers. However, we only care about the smallest-valued ones.\n\nFor example, when num = \"5489355142\":\n\n\t\nThe 1^st smallest wonderful integer is \"5489355214\".\nThe 2^nd smallest wonderful integer is \"5489355241\".\nThe 3^rd smallest wonderful integer is \"5489355412\".\nThe 4^th smallest wonderful integer is \"5489355421\".\n\n\n\nReturn the minimum number of adjacent digit swaps that needs to be applied to num to reach the k^th smallest wonderful integer.\nThe tests are generated in such a way that k^th\u00a0smallest wonderful integer exists.", + "examples": [ + "Example 1:\nInput: num = \"5489355142\", k = 4\nOutput: 2\nExplanation: The 4^th smallest wonderful number is \"5489355421\". To get this number:\n- Swap index 7 with index 8: \"5489355142\" -> \"5489355412\"\n- Swap index 8 with index 9: \"5489355412\" -> \"5489355421\"", + "Example 2:\nInput: num = \"11112\", k = 4\nOutput: 4\nExplanation: The 4^th smallest wonderful number is \"21111\". To get this number:\n- Swap index 3 with index 4: \"11112\" -> \"11121\"\n- Swap index 2 with index 3: \"11121\" -> \"11211\"\n- Swap index 1 with index 2: \"11211\" -> \"12111\"\n- Swap index 0 with index 1: \"12111\" -> \"21111\"", + "Example 3:\nInput: num = \"00123\", k = 1\nOutput: 1\nExplanation: The 1^st smallest wonderful number is \"00132\". To get this number:\n- Swap index 3 with index 4: \"00123\" -> \"00132\"" + ], + "constraints": "Constraints:\n\n2 <= num.length <= 1000\n1 <= k <= 1000\nnum only consists of digits.", + "tags": [ + "Two Pointers", + "String", + "Greedy" + ], + "title-slug": "minimum-adjacent-swaps-to-reach-the-kth-smallest-number" + }, + { + "leetcode-id": 1851, + "title": "Minimum Interval to Include Each Query", + "difficulty": 3, + "description": "You are given a 2D integer array intervals, where intervals[i] = [lefti, righti] describes the i^th interval starting at lefti and ending at righti (inclusive). The size of an interval is defined as the number of integers it contains, or more formally righti - lefti + 1.\nYou are also given an integer array queries. The answer to the j^th query is the size of the smallest interval i such that lefti <= queries[j] <= righti. If no such interval exists, the answer is -1.\nReturn an array containing the answers to the queries.", + "examples": [ + "Example 1:\nInput: intervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5]\nOutput: [3,3,1,4]\nExplanation: The queries are processed as follows:\n- Query = 2: The interval [2,4] is the smallest interval containing 2. The answer is 4 - 2 + 1 = 3.\n- Query = 3: The interval [2,4] is the smallest interval containing 3. The answer is 4 - 2 + 1 = 3.\n- Query = 4: The interval [4,4] is the smallest interval containing 4. The answer is 4 - 4 + 1 = 1.\n- Query = 5: The interval [3,6] is the smallest interval containing 5. The answer is 6 - 3 + 1 = 4.", + "Example 2:\nInput: intervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22]\nOutput: [2,-1,4,6]\nExplanation: The queries are processed as follows:\n- Query = 2: The interval [2,3] is the smallest interval containing 2. The answer is 3 - 2 + 1 = 2.\n- Query = 19: None of the intervals contain 19. The answer is -1.\n- Query = 5: The interval [2,5] is the smallest interval containing 5. The answer is 5 - 2 + 1 = 4.\n- Query = 22: The interval [20,25] is the smallest interval containing 22. The answer is 25 - 20 + 1 = 6." + ], + "constraints": "Constraints:\n\n1 <= intervals.length <= 10^5\n1 <= queries.length <= 10^5\nintervals[i].length == 2\n1 <= lefti <= righti <= 10^7\n1 <= queries[j] <= 10^7", + "tags": [ + "Array", + "Binary Search", + "Line Sweep", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "minimum-interval-to-include-each-query" + }, + { + "leetcode-id": 1854, + "title": "Maximum Population Year", + "difficulty": 1, + "description": "You are given a 2D integer array logs where each logs[i] = [birthi, deathi] indicates the birth and death years of the i^th person.\nThe population of some year x is the number of people alive during that year. The i^th person is counted in year x's population if x is in the inclusive range [birthi, deathi - 1]. Note that the person is not counted in the year that they die.\nReturn the earliest year with the maximum population.", + "examples": [ + "Example 1:\nInput: logs = [[1993,1999],[2000,2010]]\nOutput: 1993\nExplanation: The maximum population is 1, and 1993 is the earliest year with this population.", + "Example 2:\nInput: logs = [[1950,1961],[1960,1971],[1970,1981]]\nOutput: 1960\nExplanation: \nThe maximum population is 2, and it had happened in years 1960 and 1970.\nThe earlier year between them is 1960." + ], + "constraints": "Constraints:\n\n1 <= logs.length <= 100\n1950 <= birthi < deathi <= 2050", + "tags": [ + "Array", + "Counting" + ], + "title-slug": "maximum-population-year" + }, + { + "leetcode-id": 1855, + "title": "Maximum Distance Between a Pair of Values", + "difficulty": 2, + "description": "You are given two non-increasing 0-indexed integer arrays nums1\u200b\u200b\u200b\u200b\u200b\u200b and nums2\u200b\u200b\u200b\u200b\u200b\u200b.\nA pair of indices (i, j), where 0 <= i < nums1.length and 0 <= j < nums2.length, is valid if both i <= j and nums1[i] <= nums2[j]. The distance of the pair is j - i\u200b\u200b\u200b\u200b.\nReturn the maximum distance of any valid pair (i, j). If there are no valid pairs, return 0.\nAn array arr is non-increasing if arr[i-1] >= arr[i] for every 1 <= i < arr.length.", + "examples": [ + "Example 1:\nInput: nums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5]\nOutput: 2\nExplanation: The valid pairs are (0,0), (2,2), (2,3), (2,4), (3,3), (3,4), and (4,4).\nThe maximum distance is 2 with pair (2,4).", + "Example 2:\nInput: nums1 = [2,2,2], nums2 = [10,10,1]\nOutput: 1\nExplanation: The valid pairs are (0,0), (0,1), and (1,1).\nThe maximum distance is 1 with pair (0,1).", + "Example 3:\nInput: nums1 = [30,29,19,5], nums2 = [25,25,25,25,25]\nOutput: 2\nExplanation: The valid pairs are (2,2), (2,3), (2,4), (3,3), and (3,4).\nThe maximum distance is 2 with pair (2,4)." + ], + "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 10^5\n1 <= nums1[i], nums2[j] <= 10^5\nBoth nums1 and nums2 are non-increasing.", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Greedy" + ], + "title-slug": "maximum-distance-between-a-pair-of-values" + }, + { + "leetcode-id": 1856, + "title": "Maximum Subarray Min-Product", + "difficulty": 2, + "description": "The min-product of an array is equal to the minimum value in the array multiplied by the array's sum.\n\nFor example, the array [3,2,5] (minimum value is 2) has a min-product of 2 * (3+2+5) = 2 * 10 = 20.\n\nGiven an array of integers nums, return the maximum min-product of any non-empty subarray of nums. Since the answer may be large, return it modulo 10^9 + 7.\nNote that the min-product should be maximized before performing the modulo operation. Testcases are generated such that the maximum min-product without modulo will fit in a 64-bit signed integer.\nA subarray is a contiguous part of an array.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,2]\nOutput: 14\nExplanation: The maximum min-product is achieved with the subarray [2,3,2] (minimum value is 2).\n2 * (2+3+2) = 2 * 7 = 14.", + "Example 2:\nInput: nums = [2,3,3,1,2]\nOutput: 18\nExplanation: The maximum min-product is achieved with the subarray [3,3] (minimum value is 3).\n3 * (3+3) = 3 * 6 = 18.", + "Example 3:\nInput: nums = [3,1,5,6,4,2]\nOutput: 60\nExplanation: The maximum min-product is achieved with the subarray [5,6,4] (minimum value is 4).\n4 * (5+6+4) = 4 * 15 = 60." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^7", + "tags": [ + "Array", + "Stack", + "Monotonic Stack", + "Prefix Sum" + ], + "title-slug": "maximum-subarray-min-product" + }, + { + "leetcode-id": 1857, + "title": "Largest Color Value in a Directed Graph", + "difficulty": 3, + "description": "There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1.\nYou are given a string colors where colors[i] is a lowercase English letter representing the color of the i^th node in this graph (0-indexed). You are also given a 2D array edges where edges[j] = [aj, bj] indicates that there is a directed edge from node aj to node bj.\nA valid path in the graph is a sequence of nodes x1 -> x2 -> x3 -> ... -> xk such that there is a directed edge from xi to xi+1 for every 1 <= i < k. The color value of the path is the number of nodes that are colored the most frequently occurring color along that path.\nReturn the largest color value of any valid path in the given graph, or -1 if the graph contains a cycle.", + "examples": [ + "Example 1:\nInput: colors = \"abaca\", edges = [[0,1],[0,2],[2,3],[3,4]]\r\nOutput: 3\r\nExplanation: The path 0 -> 2 -> 3 -> 4 contains 3 nodes that are colored \"a\" (red in the above image).", + "Example 2:\nInput: colors = \"a\", edges = [[0,0]]\r\nOutput: -1\r\nExplanation: There is a cycle from 0 to 0." + ], + "constraints": "Constraints:\n\nn == colors.length\nm == edges.length\n1 <= n <= 10^5\n0 <= m <= 10^5\ncolors consists of lowercase English letters.\n0 <= aj, bj\u00a0< n", + "tags": [ + "Hash Table", + "Dynamic Programming", + "Graph", + "Topological Sort", + "Memoization", + "Counting" + ], + "title-slug": "largest-color-value-in-a-directed-graph" + }, + { + "leetcode-id": 1859, + "title": "Sorting the Sentence", + "difficulty": 1, + "description": "A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.\nA sentence can be shuffled by appending the 1-indexed word position to each word then rearranging the words in the sentence.\n\nFor example, the sentence \"This is a sentence\" can be shuffled as \"sentence4 a3 is2 This1\" or \"is2 sentence4 This1 a3\".\n\nGiven a shuffled sentence s containing no more than 9 words, reconstruct and return the original sentence.", + "examples": [ + "Example 1:\nInput: s = \"is2 sentence4 This1 a3\"\r\nOutput: \"This is a sentence\"\r\nExplanation: Sort the words in s to their original positions \"This1 is2 a3 sentence4\", then remove the numbers.", + "Example 2:\nInput: s = \"Myself2 Me1 I4 and3\"\r\nOutput: \"Me Myself and I\"\r\nExplanation: Sort the words in s to their original positions \"Me1 Myself2 and3 I4\", then remove the numbers." + ], + "constraints": "Constraints:\n\n2 <= s.length <= 200\ns consists of lowercase and uppercase English letters, spaces, and digits from 1 to 9.\nThe number of words in s is between 1 and 9.\nThe words in s are separated by a single space.\ns contains no leading or trailing spaces.", + "tags": [ + "String", + "Sorting" + ], + "title-slug": "sorting-the-sentence" + }, + { + "leetcode-id": 1860, + "title": "Incremental Memory Leak", + "difficulty": 2, + "description": "You are given two integers memory1 and memory2 representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.\nAt the i^th second (starting from 1), i bits of memory are allocated to the stick with more available memory (or from the first memory stick if both have the same available memory). If neither stick has at least i bits of available memory, the program crashes.\nReturn an array containing [crashTime, memory1crash, memory2crash], where crashTime is the time (in seconds) when the program crashed and memory1crash and memory2crash are the available bits of memory in the first and second sticks respectively.", + "examples": [ + "Example 1:\nInput: memory1 = 2, memory2 = 2\nOutput: [3,1,0]\nExplanation: The memory is allocated as follows:\n- At the 1^st second, 1 bit of memory is allocated to stick 1. The first stick now has 1 bit of available memory.\n- At the 2^nd second, 2 bits of memory are allocated to stick 2. The second stick now has 0 bits of available memory.\n- At the 3^rd second, the program crashes. The sticks have 1 and 0 bits available respectively.", + "Example 2:\nInput: memory1 = 8, memory2 = 11\nOutput: [6,0,4]\nExplanation: The memory is allocated as follows:\n- At the 1^st second, 1 bit of memory is allocated to stick 2. The second stick now has 10 bit of available memory.\n- At the 2^nd second, 2 bits of memory are allocated to stick 2. The second stick now has 8 bits of available memory.\n- At the 3^rd second, 3 bits of memory are allocated to stick 1. The first stick now has 5 bits of available memory.\n- At the 4^th second, 4 bits of memory are allocated to stick 2. The second stick now has 4 bits of available memory.\n- At the 5^th second, 5 bits of memory are allocated to stick 1. The first stick now has 0 bits of available memory.\n- At the 6^th second, the program crashes. The sticks have 0 and 4 bits available respectively." + ], + "constraints": "Constraints:\n\n0 <= memory1, memory2 <= 2^31 - 1", + "tags": [ + "Simulation" + ], + "title-slug": "incremental-memory-leak" + }, + { + "leetcode-id": 1861, + "title": "Rotating the Box", + "difficulty": 2, + "description": "You are given an m x n matrix of characters box representing a side-view of a box. Each cell of the box is one of the following:\n\nA stone '#'\nA stationary obstacle '*'\nEmpty '.'\n\nThe box is rotated 90 degrees clockwise, causing some of the stones to fall due to gravity. Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box. Gravity does not affect the obstacles' positions, and the inertia from the box's rotation does not affect the stones' horizontal positions.\nIt is guaranteed that each stone in box rests on an obstacle, another stone, or the bottom of the box.\nReturn an n x m matrix representing the box after the rotation described above.", + "examples": [ + "Example 1:\nInput: box = [[\"#\",\".\",\"#\"]]\r\nOutput: [[\".\"],\r\n\u00a0 [\"#\"],\r\n\u00a0 [\"#\"]]", + "Example 2:\nInput: box = [[\"#\",\".\",\"*\",\".\"],\r\n\u00a0 [\"#\",\"#\",\"*\",\".\"]]\r\nOutput: [[\"#\",\".\"],\r\n\u00a0 [\"#\",\"#\"],\r\n\u00a0 [\"*\",\"*\"],\r\n\u00a0 [\".\",\".\"]]", + "Example 3:\nInput: box = [[\"#\",\"#\",\"*\",\".\",\"*\",\".\"],\r\n\u00a0 [\"#\",\"#\",\"#\",\"*\",\".\",\".\"],\r\n\u00a0 [\"#\",\"#\",\"#\",\".\",\"#\",\".\"]]\r\nOutput: [[\".\",\"#\",\"#\"],\r\n\u00a0 [\".\",\"#\",\"#\"],\r\n\u00a0 [\"#\",\"#\",\"*\"],\r\n\u00a0 [\"#\",\"*\",\".\"],\r\n\u00a0 [\"#\",\".\",\"*\"],\r\n\u00a0 [\"#\",\".\",\".\"]]" + ], + "constraints": "Constraints:\n\nm == box.length\nn == box[i].length\n1 <= m, n <= 500\nbox[i][j] is either '#', '*', or '.'.", + "tags": [ + "Array", + "Two Pointers", + "Matrix" + ], + "title-slug": "rotating-the-box" + }, + { + "leetcode-id": 1862, + "title": "Sum of Floored Pairs", + "difficulty": 3, + "description": "Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.length in the array. Since the answer may be too large, return it modulo 10^9 + 7.\nThe floor() function returns the integer part of the division.", + "examples": [ + "Example 1:\nInput: nums = [2,5,9]\nOutput: 10\nExplanation:\nfloor(2 / 5) = floor(2 / 9) = floor(5 / 9) = 0\nfloor(2 / 2) = floor(5 / 5) = floor(9 / 9) = 1\nfloor(5 / 2) = 2\nfloor(9 / 2) = 4\nfloor(9 / 5) = 1\nWe calculate the floor of the division for every pair of indices in the array then sum them up.", + "Example 2:\nInput: nums = [7,7,7,7,7,7,7]\nOutput: 49" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Math", + "Binary Search", + "Prefix Sum" + ], + "title-slug": "sum-of-floored-pairs" + }, + { + "leetcode-id": 1863, + "title": "Sum of All Subset XOR Totals", + "difficulty": 1, + "description": "The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty.\n\nFor example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1.\n\nGiven an array nums, return the sum of all XOR totals for every subset of nums.\u00a0\nNote: Subsets with the same elements should be counted multiple times.\nAn array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b.", + "examples": [ + "Example 1:\nInput: nums = [1,3]\nOutput: 6\nExplanation: The 4 subsets of [1,3] are:\n- The empty subset has an XOR total of 0.\n- [1] has an XOR total of 1.\n- [3] has an XOR total of 3.\n- [1,3] has an XOR total of 1 XOR 3 = 2.\n0 + 1 + 3 + 2 = 6", + "Example 2:\nInput: nums = [5,1,6]\nOutput: 28\nExplanation: The 8 subsets of [5,1,6] are:\n- The empty subset has an XOR total of 0.\n- [5] has an XOR total of 5.\n- [1] has an XOR total of 1.\n- [6] has an XOR total of 6.\n- [5,1] has an XOR total of 5 XOR 1 = 4.\n- [5,6] has an XOR total of 5 XOR 6 = 3.\n- [1,6] has an XOR total of 1 XOR 6 = 7.\n- [5,1,6] has an XOR total of 5 XOR 1 XOR 6 = 2.\n0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28", + "Example 3:\nInput: nums = [3,4,5,6,7,8]\nOutput: 480\nExplanation: The sum of all XOR totals for every subset is 480." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 12\n1 <= nums[i] <= 20", + "tags": [ + "Array", + "Math", + "Backtracking", + "Bit Manipulation", + "Combinatorics" + ], + "title-slug": "sum-of-all-subset-xor-totals" + }, + { + "leetcode-id": 1864, + "title": "Minimum Number of Swaps to Make the Binary String Alternating", + "difficulty": 2, + "description": "Given a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible.\nThe string is called alternating if no two adjacent characters are equal. For example, the strings \"010\" and \"1010\" are alternating, while the string \"0100\" is not.\nAny two characters may be swapped, even if they are\u00a0not adjacent.", + "examples": [ + "Example 1:\nInput: s = \"111000\"\nOutput: 1\nExplanation: Swap positions 1 and 4: \"111000\" -> \"101010\"\nThe string is now alternating.", + "Example 2:\nInput: s = \"010\"\nOutput: 0\nExplanation: The string is already alternating, no swaps are needed.", + "Example 3:\nInput: s = \"1110\"\nOutput: -1" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns[i] is either '0' or '1'.", + "tags": [ + "String", + "Greedy" + ], + "title-slug": "minimum-number-of-swaps-to-make-the-binary-string-alternating" + }, + { + "leetcode-id": 1865, + "title": "Finding Pairs With a Certain Sum", + "difficulty": 2, + "description": "You are given two integer arrays nums1 and nums2. You are tasked to implement a data structure that supports queries of two types:\n\nAdd a positive integer to an element of a given index in the array nums2.\nCount the number of pairs (i, j) such that nums1[i] + nums2[j] equals a given value (0 <= i < nums1.length and 0 <= j < nums2.length).\n\nImplement the FindSumPairs class:\n\nFindSumPairs(int[] nums1, int[] nums2) Initializes the FindSumPairs object with two integer arrays nums1 and nums2.\nvoid add(int index, int val) Adds val to nums2[index], i.e., apply nums2[index] += val.\nint count(int tot) Returns the number of pairs (i, j) such that nums1[i] + nums2[j] == tot.", + "examples": [ + "Example 1:\nInput\n[\"FindSumPairs\", \"count\", \"add\", \"count\", \"count\", \"add\", \"add\", \"count\"]\n[[[1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]], [7], [3, 2], [8], [4], [0, 1], [1, 1], [7]]\nOutput\n[null, 8, null, 2, 1, null, null, 11]\n\nExplanation\nFindSumPairs findSumPairs = new FindSumPairs([1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]);\nfindSumPairs.count(7); // return 8; pairs (2,2), (3,2), (4,2), (2,4), (3,4), (4,4) make 2 + 5 and pairs (5,1), (5,5) make 3 + 4\nfindSumPairs.add(3, 2); // now nums2 = [1,4,5,4,5,4]\nfindSumPairs.count(8); // return 2; pairs (5,2), (5,4) make 3 + 5\nfindSumPairs.count(4); // return 1; pair (5,0) makes 3 + 1\nfindSumPairs.add(0, 1); // now nums2 = [2,4,5,4,5,4]\nfindSumPairs.add(1, 1); // now nums2 = [2,5,5,4,5,4]\nfindSumPairs.count(7); // return 11; pairs (2,1), (2,2), (2,4), (3,1), (3,2), (3,4), (4,1), (4,2), (4,4) make 2 + 5 and pairs (5,3), (5,5) make 3 + 4" + ], + "constraints": "Constraints:\n\n1 <= nums1.length <= 1000\n1 <= nums2.length <= 10^5\n1 <= nums1[i] <= 10^9\n1 <= nums2[i] <= 10^5\n0 <= index < nums2.length\n1 <= val <= 10^5\n1 <= tot <= 10^9\nAt most 1000 calls are made to add and count each.", + "tags": [ + "Array", + "Hash Table", + "Design" + ], + "title-slug": "finding-pairs-with-a-certain-sum" + }, + { + "leetcode-id": 1866, + "title": "Number of Ways to Rearrange Sticks With K Sticks Visible", + "difficulty": 3, + "description": "There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k\u00a0sticks are visible from the left. A stick\u00a0is visible from the left if there are no longer\u00a0sticks to the left of it.\n\nFor example, if the sticks are arranged [1,3,2,5,4], then the sticks with lengths 1, 3, and 5 are visible from the left.\n\nGiven n and k, return the number of such arrangements. Since the answer may be large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 3, k = 2\nOutput: 3\nExplanation: [1,3,2], [2,3,1], and [2,1,3] are the only arrangements such that exactly 2 sticks are visible.\nThe visible sticks are underlined.", + "Example 2:\nInput: n = 5, k = 5\nOutput: 1\nExplanation: [1,2,3,4,5] is the only arrangement such that all 5 sticks are visible.\nThe visible sticks are underlined.", + "Example 3:\nInput: n = 20, k = 11\nOutput: 647427950\nExplanation: There are 647427950 (mod 10^9 + 7) ways to rearrange the sticks such that exactly 11 sticks are visible." + ], + "constraints": "Constraints:\n\n1 <= n <= 1000\n1 <= k <= n", + "tags": [ + "Math", + "Dynamic Programming", + "Combinatorics" + ], + "title-slug": "number-of-ways-to-rearrange-sticks-with-k-sticks-visible" + }, + { + "leetcode-id": 1869, + "title": "Longer Contiguous Segments of Ones than Zeros", + "difficulty": 1, + "description": "Given a binary string s, return true if the longest contiguous segment of 1's is strictly longer than the longest contiguous segment of 0's in s, or return false otherwise.\n\nFor example, in s = \"110100010\" the longest continuous segment of 1s has length 2, and the longest continuous segment of 0s has length 3.\n\nNote that if there are no 0's, then the longest continuous segment of 0's is considered to have a length 0. The same applies if there is no 1's.", + "examples": [ + "Example 1:\nInput: s = \"1101\"\nOutput: true\nExplanation:\nThe longest contiguous segment of 1s has length 2: \"1101\"\nThe longest contiguous segment of 0s has length 1: \"1101\"\nThe segment of 1s is longer, so return true.", + "Example 2:\nInput: s = \"111000\"\nOutput: false\nExplanation:\nThe longest contiguous segment of 1s has length 3: \"111000\"\nThe longest contiguous segment of 0s has length 3: \"111000\"\nThe segment of 1s is not longer, so return false.", + "Example 3:\nInput: s = \"110100010\"\nOutput: false\nExplanation:\nThe longest contiguous segment of 1s has length 2: \"110100010\"\nThe longest contiguous segment of 0s has length 3: \"110100010\"\nThe segment of 1s is not longer, so return false." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\ns[i] is either '0' or '1'.", + "tags": [ + "String" + ], + "title-slug": "longer-contiguous-segments-of-ones-than-zeros" + }, + { + "leetcode-id": 1870, + "title": "Minimum Speed to Arrive on Time", + "difficulty": 2, + "description": "You are given a floating-point number hour, representing the amount of time you have to reach the office. To commute to the office, you must take n trains in sequential order. You are also given an integer array dist of length n, where dist[i] describes the distance (in kilometers) of the i^th train ride.\nEach train can only depart at an integer hour, so you may need to wait in between each train ride.\n\nFor example, if the 1^st train ride takes 1.5 hours, you must wait for an additional 0.5 hours before you can depart on the 2^nd train ride at the 2 hour mark.\n\nReturn the minimum positive integer speed (in kilometers per hour) that all the trains must travel at for you to reach the office on time, or -1 if it is impossible to be on time.\nTests are generated such that the answer will not exceed 10^7 and hour will have at most two digits after the decimal point.", + "examples": [ + "Example 1:\nInput: dist = [1,3,2], hour = 6\nOutput: 1\nExplanation: At speed 1:\n- The first train ride takes 1/1 = 1 hour.\n- Since we are already at an integer hour, we depart immediately at the 1 hour mark. The second train takes 3/1 = 3 hours.\n- Since we are already at an integer hour, we depart immediately at the 4 hour mark. The third train takes 2/1 = 2 hours.\n- You will arrive at exactly the 6 hour mark.", + "Example 2:\nInput: dist = [1,3,2], hour = 2.7\nOutput: 3\nExplanation: At speed 3:\n- The first train ride takes 1/3 = 0.33333 hours.\n- Since we are not at an integer hour, we wait until the 1 hour mark to depart. The second train ride takes 3/3 = 1 hour.\n- Since we are already at an integer hour, we depart immediately at the 2 hour mark. The third train takes 2/3 = 0.66667 hours.\n- You will arrive at the 2.66667 hour mark.", + "Example 3:\nInput: dist = [1,3,2], hour = 1.9\nOutput: -1\nExplanation: It is impossible because the earliest the third train can depart is at the 2 hour mark." + ], + "constraints": "Constraints:\n\nn == dist.length\n1 <= n <= 10^5\n1 <= dist[i] <= 10^5\n1 <= hour <= 10^9\nThere will be at most two digits after the decimal point in hour.", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "minimum-speed-to-arrive-on-time" + }, + { + "leetcode-id": 1871, + "title": "Jump Game VII", + "difficulty": 2, + "description": "You are given a 0-indexed binary string s and two integers minJump and maxJump. In the beginning, you are standing at index 0, which is equal to '0'. You can move from index i to index j if the following conditions are fulfilled:\n\ni + minJump <= j <= min(i + maxJump, s.length - 1), and\ns[j] == '0'.\n\nReturn true if you can reach index s.length - 1 in s, or false otherwise.", + "examples": [ + "Example 1:\nInput: s = \"011010\", minJump = 2, maxJump = 3\nOutput: true\nExplanation:\nIn the first step, move from index 0 to index 3. \nIn the second step, move from index 3 to index 5.", + "Example 2:\nInput: s = \"01101110\", minJump = 2, maxJump = 3\nOutput: false" + ], + "constraints": "Constraints:\n\n2 <= s.length <= 10^5\ns[i] is either '0' or '1'.\ns[0] == '0'\n1 <= minJump <= maxJump < s.length", + "tags": [ + "String", + "Dynamic Programming", + "Sliding Window", + "Prefix Sum" + ], + "title-slug": "jump-game-vii" + }, + { + "leetcode-id": 1872, + "title": "Stone Game VIII", + "difficulty": 3, + "description": "Alice and Bob take turns playing a game, with Alice starting first.\nThere are n stones arranged in a row. On each player's turn, while the number of stones is more than one, they will do the following:\n\nChoose an integer x > 1, and remove the leftmost x stones from the row.\nAdd the sum of the removed stones' values to the player's score.\nPlace a new stone, whose value is equal to that sum, on the left side of the row.\n\nThe game stops when only one stone is left in the row.\nThe score difference between Alice and Bob is (Alice's score - Bob's score). Alice's goal is to maximize the score difference, and Bob's goal is the minimize the score difference.\nGiven an integer array stones of length n where stones[i] represents the value of the i^th stone from the left, return the score difference between Alice and Bob if they both play optimally.", + "examples": [ + "Example 1:\nInput: stones = [-1,2,-3,4,-5]\r\nOutput: 5\r\nExplanation:\r\n- Alice removes the first 4 stones, adds (-1) + 2 + (-3) + 4 = 2 to her score, and places a stone of\r\n value 2 on the left. stones = [2,-5].\r\n- Bob removes the first 2 stones, adds 2 + (-5) = -3 to his score, and places a stone of value -3 on\r\n the left. stones = [-3].\r\nThe difference between their scores is 2 - (-3) = 5.", + "Example 2:\nInput: stones = [7,-6,5,10,5,-2,-6]\r\nOutput: 13\r\nExplanation:\r\n- Alice removes all stones, adds 7 + (-6) + 5 + 10 + 5 + (-2) + (-6) = 13 to her score, and places a\r\n stone of value 13 on the left. stones = [13].\r\nThe difference between their scores is 13 - 0 = 13.", + "Example 3:\nInput: stones = [-10,-12]\r\nOutput: -22\r\nExplanation:\r\n- Alice can only make one move, which is to remove both stones. She adds (-10) + (-12) = -22 to her\r\n score and places a stone of value -22 on the left. stones = [-22].\r\nThe difference between their scores is (-22) - 0 = -22." + ], + "constraints": "Constraints:\n\nn == stones.length\n2 <= n <= 10^5\n-10^4 <= stones[i] <= 10^4", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Prefix Sum", + "Game Theory" + ], + "title-slug": "stone-game-viii" + }, + { + "leetcode-id": 1876, + "title": "Substrings of Size Three with Distinct Characters", + "difficulty": 1, + "description": "A string is good if there are no repeated characters.\nGiven a string s\u200b\u200b\u200b\u200b\u200b, return the number of good substrings of length three in s\u200b\u200b\u200b\u200b\u200b\u200b.\nNote that if there are multiple occurrences of the same substring, every occurrence should be counted.\nA substring is a contiguous sequence of characters in a string.", + "examples": [ + "Example 1:\nInput: s = \"xyzzaz\"\nOutput: 1\nExplanation: There are 4 substrings of size 3: \"xyz\", \"yzz\", \"zza\", and \"zaz\". \nThe only good substring of length 3 is \"xyz\".", + "Example 2:\nInput: s = \"aababcabc\"\nOutput: 4\nExplanation: There are 7 substrings of size 3: \"aab\", \"aba\", \"bab\", \"abc\", \"bca\", \"cab\", and \"abc\".\nThe good substrings are \"abc\", \"bca\", \"cab\", and \"abc\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\ns\u200b\u200b\u200b\u200b\u200b\u200b consists of lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Sliding Window", + "Counting" + ], + "title-slug": "substrings-of-size-three-with-distinct-characters" + }, + { + "leetcode-id": 1877, + "title": "Minimize Maximum Pair Sum in Array", + "difficulty": 2, + "description": "The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs.\n\nFor example, if we have pairs (1,5), (2,3), and (4,4), the maximum pair sum would be max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8.\n\nGiven an array nums of even length n, pair up the elements of nums into n / 2 pairs such that:\n\nEach element of nums is in exactly one pair, and\nThe maximum pair sum is minimized.\n\nReturn the minimized maximum pair sum after optimally pairing up the elements.", + "examples": [ + "Example 1:\nInput: nums = [3,5,2,3]\r\nOutput: 7\r\nExplanation: The elements can be paired up into pairs (3,3) and (5,2).\r\nThe maximum pair sum is max(3+3, 5+2) = max(6, 7) = 7.", + "Example 2:\nInput: nums = [3,5,4,2,4,6]\r\nOutput: 8\r\nExplanation: The elements can be paired up into pairs (3,5), (4,4), and (6,2).\r\nThe maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8." + ], + "constraints": "Constraints:\n\nn == nums.length\n2 <= n <= 10^5\nn is even.\n1 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Two Pointers", + "Greedy", + "Sorting" + ], + "title-slug": "minimize-maximum-pair-sum-in-array" + }, + { + "leetcode-id": 1878, + "title": "Get Biggest Three Rhombus Sums in a Grid", + "difficulty": 2, + "description": "You are given an m x n integer matrix grid\u200b\u200b\u200b.\nA rhombus sum is the sum of the elements that form the border of a regular rhombus shape in grid\u200b\u200b\u200b. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell. Below is an image of four valid rhombus shapes with the corresponding colored cells that should be included in each rhombus sum:\n\nNote that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.\nReturn the biggest three distinct rhombus sums in the grid in descending order. If there are less than three distinct values, return all of them.", + "examples": [ + "Example 1:\nInput: grid = [[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]]\nOutput: [228,216,211]\nExplanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n- Blue: 20 + 3 + 200 + 5 = 228\n- Red: 200 + 2 + 10 + 4 = 216\n- Green: 5 + 200 + 4 + 2 = 211", + "Example 2:\nInput: grid = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [20,9,8]\nExplanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n- Blue: 4 + 2 + 6 + 8 = 20\n- Red: 9 (area 0 rhombus in the bottom right corner)\n- Green: 8 (area 0 rhombus in the bottom middle)", + "Example 3:\nInput: grid = [[7,7,7]]\nOutput: [7]\nExplanation: All three possible rhombus sums are the same, so return [7]." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 50\n1 <= grid[i][j] <= 10^5", + "tags": [ + "Array", + "Math", + "Sorting", + "Heap (Priority Queue)", + "Matrix", + "Prefix Sum" + ], + "title-slug": "get-biggest-three-rhombus-sums-in-a-grid" + }, + { + "leetcode-id": 1879, + "title": "Minimum XOR Sum of Two Arrays", + "difficulty": 3, + "description": "You are given two integer arrays nums1 and nums2 of length n.\nThe XOR sum of the two integer arrays is (nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1]) (0-indexed).\n\nFor example, the XOR sum of [1,2,3] and [3,2,1] is equal to (1 XOR 3) + (2 XOR 2) + (3 XOR 1) = 2 + 0 + 2 = 4.\n\nRearrange the elements of nums2 such that the resulting XOR sum is minimized.\nReturn the XOR sum after the rearrangement.", + "examples": [ + "Example 1:\nInput: nums1 = [1,2], nums2 = [2,3]\nOutput: 2\nExplanation: Rearrange nums2 so that it becomes [3,2].\nThe XOR sum is (1 XOR 3) + (2 XOR 2) = 2 + 0 = 2.", + "Example 2:\nInput: nums1 = [1,0,3], nums2 = [5,3,4]\nOutput: 8\nExplanation: Rearrange nums2 so that it becomes [5,4,3]. \nThe XOR sum is (1 XOR 5) + (0 XOR 4) + (3 XOR 3) = 4 + 4 + 0 = 8." + ], + "constraints": "Constraints:\n\nn == nums1.length\nn == nums2.length\n1 <= n <= 14\n0 <= nums1[i], nums2[i] <= 10^7", + "tags": [ + "Array", + "Dynamic Programming", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "minimum-xor-sum-of-two-arrays" + }, + { + "leetcode-id": 1880, + "title": "Check if Word Equals Summation of Two Words", + "difficulty": 1, + "description": "The letter value of a letter is its position in the alphabet starting from 0 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, etc.).\nThe numerical value of some string of lowercase English letters s is the concatenation of the letter values of each letter in s, which is then converted into an integer.\n\nFor example, if s = \"acb\", we concatenate each letter's letter value, resulting in \"021\". After converting it, we get 21.\n\nYou are given three strings firstWord, secondWord, and targetWord, each consisting of lowercase English letters 'a' through 'j' inclusive.\nReturn true if the summation of the numerical values of firstWord and secondWord equals the numerical value of targetWord, or false otherwise.", + "examples": [ + "Example 1:\nInput: firstWord = \"acb\", secondWord = \"cba\", targetWord = \"cdb\"\nOutput: true\nExplanation:\nThe numerical value of firstWord is \"acb\" -> \"021\" -> 21.\nThe numerical value of secondWord is \"cba\" -> \"210\" -> 210.\nThe numerical value of targetWord is \"cdb\" -> \"231\" -> 231.\nWe return true because 21 + 210 == 231.", + "Example 2:\nInput: firstWord = \"aaa\", secondWord = \"a\", targetWord = \"aab\"\nOutput: false\nExplanation: \nThe numerical value of firstWord is \"aaa\" -> \"000\" -> 0.\nThe numerical value of secondWord is \"a\" -> \"0\" -> 0.\nThe numerical value of targetWord is \"aab\" -> \"001\" -> 1.\nWe return false because 0 + 0 != 1.", + "Example 3:\nInput: firstWord = \"aaa\", secondWord = \"a\", targetWord = \"aaaa\"\nOutput: true\nExplanation: \nThe numerical value of firstWord is \"aaa\" -> \"000\" -> 0.\nThe numerical value of secondWord is \"a\" -> \"0\" -> 0.\nThe numerical value of targetWord is \"aaaa\" -> \"0000\" -> 0.\nWe return true because 0 + 0 == 0." + ], + "constraints": "Constraints:\n\n1 <= firstWord.length, secondWord.length, targetWord.length <= 8\nfirstWord, secondWord, and targetWord consist of lowercase English letters from 'a' to 'j' inclusive.", + "tags": [ + "String" + ], + "title-slug": "check-if-word-equals-summation-of-two-words" + }, + { + "leetcode-id": 1881, + "title": "Maximum Value after Insertion", + "difficulty": 2, + "description": "You are given a very large integer n, represented as a string,\u200b\u200b\u200b\u200b\u200b\u200b and an integer digit x. The digits in n and the digit x are in the inclusive range [1, 9], and n may represent a negative number.\nYou want to maximize n's numerical value by inserting x anywhere in the decimal representation of n\u200b\u200b\u200b\u200b\u200b\u200b. You cannot insert x to the left of the negative sign.\n\nFor example, if n = 73 and x = 6, it would be best to insert it between 7 and 3, making n = 763.\nIf n = -55 and x = 2, it would be best to insert it before the first 5, making n = -255.\n\nReturn a string representing the maximum value of n\u200b\u200b\u200b\u200b\u200b\u200b after the insertion.", + "examples": [ + "Example 1:\nInput: n = \"99\", x = 9\nOutput: \"999\"\nExplanation: The result is the same regardless of where you insert 9.", + "Example 2:\nInput: n = \"-13\", x = 2\nOutput: \"-123\"\nExplanation: You can make n one of {-213, -123, -132}, and the largest of those three is -123." + ], + "constraints": "Constraints:\n\n1 <= n.length <= 10^5\n1 <= x <= 9\nThe digits in n\u200b\u200b\u200b are in the range [1, 9].\nn is a valid representation of an integer.\nIn the case of a negative n,\u200b\u200b\u200b\u200b\u200b\u200b it will begin with '-'.", + "tags": [ + "String", + "Greedy" + ], + "title-slug": "maximum-value-after-insertion" + }, + { + "leetcode-id": 1882, + "title": "Process Tasks Using Servers", + "difficulty": 2, + "description": "You are given two 0-indexed integer arrays servers and tasks of lengths n\u200b\u200b\u200b\u200b\u200b\u200b and m\u200b\u200b\u200b\u200b\u200b\u200b respectively. servers[i] is the weight of the i^\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b server, and tasks[j] is the time needed to process the j^\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b task in seconds.\nTasks are assigned to the servers using a task queue. Initially, all servers are free, and the queue is empty.\nAt second j, the j^th task is inserted into the queue (starting with the 0^th task being inserted at second 0). As long as there are free servers and the queue is not empty, the task in the front of the queue will be assigned to a free server with the smallest weight, and in case of a tie, it is assigned to a free server with the smallest index.\nIf there are no free servers and the queue is not empty, we wait until a server becomes free and immediately assign the next task. If multiple servers become free at the same time, then multiple tasks from the queue will be assigned in order of insertion following the weight and index priorities above.\nA server that is assigned task j at second t will be free again at second t + tasks[j].\nBuild an array ans\u200b\u200b\u200b\u200b of length m, where ans[j] is the index of the server the j^\u200b\u200b\u200b\u200b\u200b\u200bth task will be assigned to.\nReturn the array ans\u200b\u200b\u200b\u200b.", + "examples": [ + "Example 1:\nInput: servers = [3,3,2], tasks = [1,2,3,2,1,2]\nOutput: [2,2,0,2,1,2]\nExplanation: Events in chronological order go as follows:\n- At second 0, task 0 is added and processed using server 2 until second 1.\n- At second 1, server 2 becomes free. Task 1 is added and processed using server 2 until second 3.\n- At second 2, task 2 is added and processed using server 0 until second 5.\n- At second 3, server 2 becomes free. Task 3 is added and processed using server 2 until second 5.\n- At second 4, task 4 is added and processed using server 1 until second 5.\n- At second 5, all servers become free. Task 5 is added and processed using server 2 until second 7.", + "Example 2:\nInput: servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]\nOutput: [1,4,1,4,1,3,2]\nExplanation: Events in chronological order go as follows: \n- At second 0, task 0 is added and processed using server 1 until second 2.\n- At second 1, task 1 is added and processed using server 4 until second 2.\n- At second 2, servers 1 and 4 become free. Task 2 is added and processed using server 1 until second 4. \n- At second 3, task 3 is added and processed using server 4 until second 7.\n- At second 4, server 1 becomes free. Task 4 is added and processed using server 1 until second 9. \n- At second 5, task 5 is added and processed using server 3 until second 7.\n- At second 6, task 6 is added and processed using server 2 until second 7." + ], + "constraints": "Constraints:\n\nservers.length == n\ntasks.length == m\n1 <= n, m <= 2 * 10^5\n1 <= servers[i], tasks[j] <= 2 * 10^5", + "tags": [ + "Array", + "Heap (Priority Queue)" + ], + "title-slug": "process-tasks-using-servers" + }, + { + "leetcode-id": 1883, + "title": "Minimum Skips to Arrive at Meeting On Time", + "difficulty": 3, + "description": "You are given an integer hoursBefore, the number of hours you have to travel to your meeting. To arrive at your meeting, you have to travel through n roads. The road lengths are given as an integer array dist of length n, where dist[i] describes the length of the i^th road in kilometers. In addition, you are given an integer speed, which is the speed (in km/h) you will travel at.\nAfter you travel road i, you must rest and wait for the next integer hour before you can begin traveling on the next road. Note that you do not have to rest after traveling the last road because you are already at the meeting.\n\nFor example, if traveling a road takes 1.4 hours, you must wait until the 2 hour mark before traveling the next road. If traveling a road takes exactly\u00a02\u00a0hours, you do not need to wait.\n\nHowever, you are allowed to skip some rests to be able to arrive on time, meaning you do not need to wait for the next integer hour. Note that this means you may finish traveling future roads at different hour marks.\n\nFor example, suppose traveling the first road takes 1.4 hours and traveling the second road takes 0.6 hours. Skipping the rest after the first road will mean you finish traveling the second road right at the 2 hour mark, letting you start traveling the third road immediately.\n\nReturn the minimum number of skips required to arrive at the meeting on time, or -1 if it is impossible.", + "examples": [ + "Example 1:\nInput: dist = [1,3,2], speed = 4, hoursBefore = 2\nOutput: 1\nExplanation:\nWithout skipping any rests, you will arrive in (1/4 + 3/4) + (3/4 + 1/4) + (2/4) = 2.5 hours.\nYou can skip the first rest to arrive in ((1/4 + 0) + (3/4 + 0)) + (2/4) = 1.5 hours.\nNote that the second rest is shortened because you finish traveling the second road at an integer hour due to skipping the first rest.", + "Example 2:\nInput: dist = [7,3,5,5], speed = 2, hoursBefore = 10\nOutput: 2\nExplanation:\nWithout skipping any rests, you will arrive in (7/2 + 1/2) + (3/2 + 1/2) + (5/2 + 1/2) + (5/2) = 11.5 hours.\nYou can skip the first and third rest to arrive in ((7/2 + 0) + (3/2 + 0)) + ((5/2 + 0) + (5/2)) = 10 hours.", + "Example 3:\nInput: dist = [7,3,5,5], speed = 1, hoursBefore = 10\nOutput: -1\nExplanation: It is impossible to arrive at the meeting on time even if you skip all the rests." + ], + "constraints": "Constraints:\n\nn == dist.length\n1 <= n <= 1000\n1 <= dist[i] <= 10^5\n1 <= speed <= 10^6\n1 <= hoursBefore <= 10^7", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "minimum-skips-to-arrive-at-meeting-on-time" + }, + { + "leetcode-id": 1884, + "title": "Egg Drop With 2 Eggs and N Floors", + "difficulty": 2, + "description": "You are given two identical eggs and you have access to a building with n floors labeled from 1 to n.\nYou know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.\nIn each move, you may take an unbroken egg and drop it from any floor x (where 1 <= x <= n). If the egg breaks, you can no longer use it. However, if the egg does not break, you may reuse it in future moves.\nReturn the minimum number of moves that you need to determine with certainty what the value of f is.", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: 2\nExplanation: We can drop the first egg from floor 1 and the second egg from floor 2.\nIf the first egg breaks, we know that f = 0.\nIf the second egg breaks but the first egg didn't, we know that f = 1.\nOtherwise, if both eggs survive, we know that f = 2.", + "Example 2:\nInput: n = 100\nOutput: 14\nExplanation: One optimal strategy is:\n- Drop the 1st egg at floor 9. If it breaks, we know f is between 0 and 8. Drop the 2nd egg starting from floor 1 and going up one at a time to find f within 8 more drops. Total drops is 1 + 8 = 9.\n- If the 1st egg does not break, drop the 1st egg again at floor 22. If it breaks, we know f is between 9 and 21. Drop the 2nd egg starting from floor 10 and going up one at a time to find f within 12 more drops. Total drops is 2 + 12 = 14.\n- If the 1st egg does not break again, follow a similar process dropping the 1st egg from floors 34, 45, 55, 64, 72, 79, 85, 90, 94, 97, 99, and 100.\nRegardless of the outcome, it takes at most 14 drops to determine f." + ], + "constraints": "Constraints:\n\n1 <= n <= 1000", + "tags": [ + "Math", + "Dynamic Programming" + ], + "title-slug": "egg-drop-with-2-eggs-and-n-floors" + }, + { + "leetcode-id": 1886, + "title": "Determine Whether Matrix Can Be Obtained By Rotation", + "difficulty": 1, + "description": "Given two n x n binary matrices mat and target, return true if it is possible to make mat equal to target by rotating mat in 90-degree increments, or false otherwise.", + "examples": [ + "Example 1:\nInput: mat = [[0,1],[1,0]], target = [[1,0],[0,1]]\nOutput: true\nExplanation: We can rotate mat 90 degrees clockwise to make mat equal target.", + "Example 2:\nInput: mat = [[0,1],[1,1]], target = [[1,0],[0,1]]\nOutput: false\nExplanation: It is impossible to make mat equal to target by rotating mat.", + "Example 3:\nInput: mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]]\nOutput: true\nExplanation: We can rotate mat 90 degrees clockwise two times to make mat equal target." + ], + "constraints": "Constraints:\n\nn == mat.length == target.length\nn == mat[i].length == target[i].length\n1 <= n <= 10\nmat[i][j] and target[i][j] are either 0 or 1.", + "tags": [ + "Array", + "Matrix" + ], + "title-slug": "determine-whether-matrix-can-be-obtained-by-rotation" + }, + { + "leetcode-id": 1887, + "title": "Reduction Operations to Make the Array Elements Equal", + "difficulty": 2, + "description": "Given an integer array nums, your goal is to make all elements in nums equal. To complete one operation, follow these steps:\n\nFind the largest value in nums. Let its index be i (0-indexed) and its value be largest. If there are multiple elements with the largest value, pick the smallest i.\nFind the next largest value in nums strictly smaller than largest. Let its value be nextLargest.\nReduce nums[i] to nextLargest.\n\nReturn the number of operations to make all elements in nums equal.", + "examples": [ + "Example 1:\nInput: nums = [5,1,3]\nOutput: 3\nExplanation:\u00a0It takes 3 operations to make all elements in nums equal:\n1. largest = 5 at index 0. nextLargest = 3. Reduce nums[0] to 3. nums = [3,1,3].\n2. largest = 3 at index 0. nextLargest = 1. Reduce nums[0] to 1. nums = [1,1,3].\n3. largest = 3 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1].", + "Example 2:\nInput: nums = [1,1,1]\nOutput: 0\nExplanation:\u00a0All elements in nums are already equal.", + "Example 3:\nInput: nums = [1,1,2,2,3]\nOutput: 4\nExplanation:\u00a0It takes 4 operations to make all elements in nums equal:\n1. largest = 3 at index 4. nextLargest = 2. Reduce nums[4] to 2. nums = [1,1,2,2,2].\n2. largest = 2 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1,2,2].\n3. largest = 2 at index 3. nextLargest = 1. Reduce nums[3] to 1. nums = [1,1,1,1,2].\n4. largest = 2 at index 4. nextLargest = 1. Reduce nums[4] to 1. nums = [1,1,1,1,1]." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 5 * 10^4\n1 <= nums[i] <= 5 * 10^4", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "reduction-operations-to-make-the-array-elements-equal" + }, + { + "leetcode-id": 1888, + "title": "Minimum Number of Flips to Make the Binary String Alternating", + "difficulty": 2, + "description": "You are given a binary string s. You are allowed to perform two types of operations on the string in any sequence:\n\nType-1: Remove the character at the start of the string s and append it to the end of the string.\nType-2: Pick any character in s and flip its value, i.e., if its value is '0' it becomes '1' and vice-versa.\n\nReturn the minimum number of type-2 operations you need to perform such that s becomes alternating.\nThe string is called alternating if no two adjacent characters are equal.\n\nFor example, the strings \"010\" and \"1010\" are alternating, while the string \"0100\" is not.", + "examples": [ + "Example 1:\nInput: s = \"111000\"\nOutput: 2\nExplanation: Use the first operation two times to make s = \"100011\".\nThen, use the second operation on the third and sixth elements to make s = \"101010\".", + "Example 2:\nInput: s = \"010\"\nOutput: 0\nExplanation: The string is already alternating.", + "Example 3:\nInput: s = \"1110\"\nOutput: 1\nExplanation: Use the second operation on the second element to make s = \"1010\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns[i] is either '0' or '1'.", + "tags": [ + "String", + "Dynamic Programming", + "Greedy", + "Sliding Window" + ], + "title-slug": "minimum-number-of-flips-to-make-the-binary-string-alternating" + }, + { + "leetcode-id": 1889, + "title": "Minimum Space Wasted From Packaging", + "difficulty": 3, + "description": "You have n packages that you are trying to place in boxes, one package in each box. There are m suppliers that each produce boxes of different sizes (with infinite supply). A package can be placed in a box if the size of the package is less than or equal to the size of the box.\nThe package sizes are given as an integer array packages, where packages[i] is the size of the i^th package. The suppliers are given as a 2D integer array boxes, where boxes[j] is an array of box sizes that the j^th supplier produces.\nYou want to choose a single supplier and use boxes from them such that the total wasted space is minimized. For each package in a box, we define the space wasted to be size of the box - size of the package. The total wasted space is the sum of the space wasted in all the boxes.\n\nFor example, if you have to fit packages with sizes [2,3,5] and the supplier offers boxes of sizes [4,8], you can fit the packages of size-2 and size-3 into two boxes of size-4 and the package with size-5 into a box of size-8. This would result in a waste of (4-2) + (4-3) + (8-5) = 6.\n\nReturn the minimum total wasted space by choosing the box supplier optimally, or -1 if it is impossible to fit all the packages inside boxes. Since the answer may be large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: packages = [2,3,5], boxes = [[4,8],[2,8]]\nOutput: 6\nExplanation: It is optimal to choose the first supplier, using two size-4 boxes and one size-8 box.\nThe total waste is (4-2) + (4-3) + (8-5) = 6.", + "Example 2:\nInput: packages = [2,3,5], boxes = [[1,4],[2,3],[3,4]]\nOutput: -1\nExplanation: There is no box that the package of size 5 can fit in.", + "Example 3:\nInput: packages = [3,5,8,10,11,12], boxes = [[12],[11,9],[10,5,14]]\nOutput: 9\nExplanation: It is optimal to choose the third supplier, using two size-5 boxes, two size-10 boxes, and two size-14 boxes.\nThe total waste is (5-3) + (5-5) + (10-8) + (10-10) + (14-11) + (14-12) = 9." + ], + "constraints": "Constraints:\n\nn == packages.length\nm == boxes.length\n1 <= n <= 10^5\n1 <= m <= 10^5\n1 <= packages[i] <= 10^5\n1 <= boxes[j].length <= 10^5\n1 <= boxes[j][k] <= 10^5\nsum(boxes[j].length) <= 10^5\nThe elements in boxes[j] are distinct.", + "tags": [ + "Array", + "Binary Search", + "Sorting", + "Prefix Sum" + ], + "title-slug": "minimum-space-wasted-from-packaging" + }, + { + "leetcode-id": 1893, + "title": "Check if All the Integers in a Range Are Covered", + "difficulty": 1, + "description": "You are given a 2D integer array ranges and two integers left and right. Each ranges[i] = [starti, endi] represents an inclusive interval between starti and endi.\nReturn true if each integer in the inclusive range [left, right] is covered by at least one interval in ranges. Return false otherwise.\nAn integer x is covered by an interval ranges[i] = [starti, endi] if starti <= x <= endi.", + "examples": [ + "Example 1:\nInput: ranges = [[1,2],[3,4],[5,6]], left = 2, right = 5\nOutput: true\nExplanation: Every integer between 2 and 5 is covered:\n- 2 is covered by the first range.\n- 3 and 4 are covered by the second range.\n- 5 is covered by the third range.", + "Example 2:\nInput: ranges = [[1,10],[10,20]], left = 21, right = 21\nOutput: false\nExplanation: 21 is not covered by any range." + ], + "constraints": "Constraints:\n\n1 <= ranges.length <= 50\n1 <= starti <= endi <= 50\n1 <= left <= right <= 50", + "tags": [ + "Array", + "Hash Table", + "Prefix Sum" + ], + "title-slug": "check-if-all-the-integers-in-a-range-are-covered" + }, + { + "leetcode-id": 1894, + "title": "Find the Student that Will Replace the Chalk", + "difficulty": 2, + "description": "There are n students in a class numbered from 0 to n - 1. The teacher will give each student a problem starting with the student number 0, then the student number 1, and so on until the teacher reaches the student number n - 1. After that, the teacher will restart the process, starting with the student number 0 again.\nYou are given a 0-indexed integer array chalk and an integer k. There are initially k pieces of chalk. When the student number i is given a problem to solve, they will use chalk[i] pieces of chalk to solve that problem. However, if the current number of chalk pieces is strictly less than chalk[i], then the student number i will be asked to replace the chalk.\nReturn the index of the student that will replace the chalk pieces.", + "examples": [ + "Example 1:\nInput: chalk = [5,1,5], k = 22\nOutput: 0\nExplanation: The students go in turns as follows:\n- Student number 0 uses 5 chalk, so k = 17.\n- Student number 1 uses 1 chalk, so k = 16.\n- Student number 2 uses 5 chalk, so k = 11.\n- Student number 0 uses 5 chalk, so k = 6.\n- Student number 1 uses 1 chalk, so k = 5.\n- Student number 2 uses 5 chalk, so k = 0.\nStudent number 0 does not have enough chalk, so they will have to replace it.", + "Example 2:\nInput: chalk = [3,4,1,2], k = 25\nOutput: 1\nExplanation: The students go in turns as follows:\n- Student number 0 uses 3 chalk so k = 22.\n- Student number 1 uses 4 chalk so k = 18.\n- Student number 2 uses 1 chalk so k = 17.\n- Student number 3 uses 2 chalk so k = 15.\n- Student number 0 uses 3 chalk so k = 12.\n- Student number 1 uses 4 chalk so k = 8.\n- Student number 2 uses 1 chalk so k = 7.\n- Student number 3 uses 2 chalk so k = 5.\n- Student number 0 uses 3 chalk so k = 2.\nStudent number 1 does not have enough chalk, so they will have to replace it." + ], + "constraints": "Constraints:\n\nchalk.length == n\n1 <= n <= 10^5\n1 <= chalk[i] <= 10^5\n1 <= k <= 10^9", + "tags": [ + "Array", + "Binary Search", + "Simulation", + "Prefix Sum" + ], + "title-slug": "find-the-student-that-will-replace-the-chalk" + }, + { + "leetcode-id": 1895, + "title": "Largest Magic Square", + "difficulty": 2, + "description": "A k x k magic square is a k x k grid filled with integers such that every row sum, every column sum, and both diagonal sums are all equal. The integers in the magic square do not have to be distinct. Every 1 x 1 grid is trivially a magic square.\nGiven an m x n integer grid, return the size (i.e., the side length k) of the largest magic square that can be found within this grid.", + "examples": [ + "Example 1:\nInput: grid = [[7,1,4,5,6],[2,5,1,6,4],[1,5,4,3,2],[1,2,7,3,4]]\nOutput: 3\nExplanation: The largest magic square has a size of 3.\nEvery row sum, column sum, and diagonal sum of this magic square is equal to 12.\n- Row sums: 5+1+6 = 5+4+3 = 2+7+3 = 12\n- Column sums: 5+5+2 = 1+4+7 = 6+3+3 = 12\n- Diagonal sums: 5+4+3 = 6+4+2 = 12", + "Example 2:\nInput: grid = [[5,1,3,1],[9,3,3,1],[1,3,3,8]]\nOutput: 2" + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 50\n1 <= grid[i][j] <= 10^6", + "tags": [ + "Array", + "Matrix", + "Prefix Sum" + ], + "title-slug": "largest-magic-square" + }, + { + "leetcode-id": 1896, + "title": "Minimum Cost to Change the Final Value of Expression", + "difficulty": 3, + "description": "You are given a valid boolean expression as a string expression consisting of the characters '1','0','&' (bitwise AND operator),'|' (bitwise OR operator),'(', and ')'.\n\nFor example, \"()1|1\" and \"(1)&()\" are not valid while \"1\", \"(((1))|(0))\", and \"1|(0&(1))\" are valid expressions.\n\nReturn the minimum cost to change the final value of the expression.\n\nFor example, if expression = \"1|1|(0&0)&1\", its value is 1|1|(0&0)&1 = 1|1|0&1 = 1|0&1 = 1&1 = 1. We want to apply operations so that the new expression evaluates to 0.\n\nThe cost of changing the final value of an expression is the number of operations performed on the expression. The types of operations are described as follows:\n\nTurn a '1' into a '0'.\nTurn a '0' into a '1'.\nTurn a '&' into a '|'.\nTurn a '|' into a '&'.\n\nNote: '&' does not take precedence over '|' in the order of calculation. Evaluate parentheses first, then in left-to-right order.", + "examples": [ + "Example 1:\nInput: expression = \"1&(0|1)\"\nOutput: 1\nExplanation: We can turn \"1&(0|1)\" into \"1&(0&1)\" by changing the '|' to a '&' using 1 operation.\nThe new expression evaluates to 0.", + "Example 2:\nInput: expression = \"(0&0)&(0&0&0)\"\nOutput: 3\nExplanation: We can turn \"(0&0)&(0&0&0)\" into \"(0|1)|(0&0&0)\" using 3 operations.\nThe new expression evaluates to 1.", + "Example 3:\nInput: expression = \"(0|(1|0&1))\"\nOutput: 1\nExplanation: We can turn \"(0|(1|0&1))\" into \"(0|(0|0&1))\" using 1 operation.\nThe new expression evaluates to 0." + ], + "constraints": "Constraints:\n\n1 <= expression.length <= 10^5\nexpression\u00a0only contains\u00a0'1','0','&','|','(', and\u00a0')'\nAll parentheses\u00a0are properly matched.\nThere will be no empty parentheses (i.e:\u00a0\"()\"\u00a0is not a substring of\u00a0expression).", + "tags": [ + "Math", + "String", + "Dynamic Programming", + "Stack" + ], + "title-slug": "minimum-cost-to-change-the-final-value-of-expression" + }, + { + "leetcode-id": 1897, + "title": "Redistribute Characters to Make All Strings Equal", + "difficulty": 1, + "description": "You are given an array of strings words (0-indexed).\nIn one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j].\nReturn true if you can make every string in words equal using any number of operations, and false otherwise.", + "examples": [ + "Example 1:\nInput: words = [\"abc\",\"aabc\",\"bc\"]\nOutput: true\nExplanation: Move the first 'a' in words[1] to the front of words[2],\nto make words[1] = \"abc\" and words[2] = \"abc\".\nAll the strings are now equal to \"abc\", so return true.", + "Example 2:\nInput: words = [\"ab\",\"a\"]\nOutput: false\nExplanation: It is impossible to make all the strings equal using the operation." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 100\n1 <= words[i].length <= 100\nwords[i] consists of lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Counting" + ], + "title-slug": "redistribute-characters-to-make-all-strings-equal" + }, + { + "leetcode-id": 1898, + "title": "Maximum Number of Removable Characters", + "difficulty": 2, + "description": "You are given two strings s and p where p is a subsequence of s. You are also given a distinct 0-indexed integer array removable containing a subset of indices of s (s is also 0-indexed).\nYou want to choose an integer k (0 <= k <= removable.length) such that, after removing k characters from s using the first k indices in removable, p is still a subsequence of s. More formally, you will mark the character at s[removable[i]] for each 0 <= i < k, then remove all marked characters and check if p is still a subsequence.\nReturn the maximum k you can choose such that p is still a subsequence of s after the removals.\nA subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.", + "examples": [ + "Example 1:\nInput: s = \"abcacb\", p = \"ab\", removable = [3,1,0]\nOutput: 2\nExplanation: After removing the characters at indices 3 and 1, \"abcacb\" becomes \"accb\".\n\"ab\" is a subsequence of \"accb\".\nIf we remove the characters at indices 3, 1, and 0, \"abcacb\" becomes \"ccb\", and \"ab\" is no longer a subsequence.\nHence, the maximum k is 2.", + "Example 2:\nInput: s = \"abcbddddd\", p = \"abcd\", removable = [3,2,1,4,5,6]\nOutput: 1\nExplanation: After removing the character at index 3, \"abcbddddd\" becomes \"abcddddd\".\n\"abcd\" is a subsequence of \"abcddddd\".", + "Example 3:\nInput: s = \"abcab\", p = \"abc\", removable = [0,1,2,3,4]\nOutput: 0\nExplanation: If you remove the first index in the array removable, \"abc\" is no longer a subsequence." + ], + "constraints": "Constraints:\n\n1 <= p.length <= s.length <= 10^5\n0 <= removable.length < s.length\n0 <= removable[i] < s.length\np is a subsequence of s.\ns and p both consist of lowercase English letters.\nThe elements in removable are distinct.", + "tags": [ + "Array", + "String", + "Binary Search" + ], + "title-slug": "maximum-number-of-removable-characters" + }, + { + "leetcode-id": 1899, + "title": "Merge Triplets to Form Target Triplet", + "difficulty": 2, + "description": "A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the i^th triplet. You are also given an integer array target = [x, y, z] that describes the triplet you want to obtain.\nTo obtain target, you may apply the following operation on triplets any number of times (possibly zero):\n\nChoose two indices (0-indexed) i and j (i != j) and update triplets[j] to become [max(ai, aj), max(bi, bj), max(ci, cj)].\n\n\t\nFor example, if triplets[i] = [2, 5, 3] and triplets[j] = [1, 7, 5], triplets[j] will be updated to [max(2, 1), max(5, 7), max(3, 5)] = [2, 7, 5].\n\n\n\nReturn true if it is possible to obtain the target triplet [x, y, z] as an element of triplets, or false otherwise.", + "examples": [ + "Example 1:\nInput: triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5]\nOutput: true\nExplanation: Perform the following operations:\n- Choose the first and last triplets [[2,5,3],[1,8,4],[1,7,5]]. Update the last triplet to be [max(2,1), max(5,7), max(3,5)] = [2,7,5]. triplets = [[2,5,3],[1,8,4],[2,7,5]]\nThe target triplet [2,7,5] is now an element of triplets.", + "Example 2:\nInput: triplets = [[3,4,5],[4,5,6]], target = [3,2,5]\nOutput: false\nExplanation: It is impossible to have [3,2,5] as an element because there is no 2 in any of the triplets.", + "Example 3:\nInput: triplets = [[2,5,3],[2,3,4],[1,2,5],[5,2,3]], target = [5,5,5]\nOutput: true\nExplanation: Perform the following operations:\n- Choose the first and third triplets [[2,5,3],[2,3,4],[1,2,5],[5,2,3]]. Update the third triplet to be [max(2,1), max(5,2), max(3,5)] = [2,5,5]. triplets = [[2,5,3],[2,3,4],[2,5,5],[5,2,3]].\n- Choose the third and fourth triplets [[2,5,3],[2,3,4],[2,5,5],[5,2,3]]. Update the fourth triplet to be [max(2,5), max(5,2), max(5,3)] = [5,5,5]. triplets = [[2,5,3],[2,3,4],[2,5,5],[5,5,5]].\nThe target triplet [5,5,5] is now an element of triplets." + ], + "constraints": "Constraints:\n\n1 <= triplets.length <= 10^5\ntriplets[i].length == target.length == 3\n1 <= ai, bi, ci, x, y, z <= 1000", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "merge-triplets-to-form-target-triplet" + }, + { + "leetcode-id": 1900, + "title": "The Earliest and Latest Rounds Where Players Compete", + "difficulty": 3, + "description": "There is a tournament where n players are participating. The players are standing in a single row and are numbered from 1 to n based on their initial standing position (player 1 is the first player in the row, player 2 is the second player in the row, etc.).\nThe tournament consists of multiple rounds (starting from round number 1). In each round, the i^th player from the front of the row competes against the i^th player from the end of the row, and the winner advances to the next round. When the number of players is odd for the current round, the player in the middle automatically advances to the next round.\n\nFor example, if the row consists of players 1, 2, 4, 6, 7\n\nPlayer 1 competes against player 7.\nPlayer 2 competes against player 6.\nPlayer 4 automatically advances to the next round.\n\n\n\nAfter each round is over, the winners are lined back up in the row based on the original ordering assigned to them initially (ascending order).\nThe players numbered firstPlayer and secondPlayer are the best in the tournament. They can win against any other player before they compete against each other. If any two other players compete against each other, either of them might win, and thus you may choose the outcome of this round.\nGiven the integers n, firstPlayer, and secondPlayer, return an integer array containing two values, the earliest possible round number and the\u00a0latest possible round number in which these two players will compete against each other, respectively.", + "examples": [ + "Example 1:\nInput: n = 11, firstPlayer = 2, secondPlayer = 4\nOutput: [3,4]\nExplanation:\nOne possible scenario which leads to the earliest round number:\nFirst round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\nSecond round: 2, 3, 4, 5, 6, 11\nThird round: 2, 3, 4\nOne possible scenario which leads to the latest round number:\nFirst round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\nSecond round: 1, 2, 3, 4, 5, 6\nThird round: 1, 2, 4\nFourth round: 2, 4", + "Example 2:\nInput: n = 5, firstPlayer = 1, secondPlayer = 5\nOutput: [1,1]\nExplanation: The players numbered 1 and 5 compete in the first round.\nThere is no way to make them compete in any other round." + ], + "constraints": "Constraints:\n\n2 <= n <= 28\n1 <= firstPlayer < secondPlayer <= n", + "tags": [ + "Dynamic Programming", + "Memoization" + ], + "title-slug": "the-earliest-and-latest-rounds-where-players-compete" + }, + { + "leetcode-id": 1901, + "title": "Find a Peak Element II", + "difficulty": 2, + "description": "A peak element in a 2D grid is an element that is strictly greater than all of its adjacent neighbors to the left, right, top, and bottom.\nGiven a 0-indexed m x n matrix mat where no two adjacent cells are equal, find any peak element mat[i][j] and return the length 2 array [i,j].\nYou may assume that the entire matrix is surrounded by an outer perimeter with the value -1 in each cell.\nYou must write an algorithm that runs in O(m log(n)) or O(n log(m)) time.", + "examples": [ + "Example 1:\nInput: mat = [[1,4],[3,2]]\nOutput: [0,1]\nExplanation:\u00a0Both 3 and 4 are peak elements so [1,0] and [0,1] are both acceptable answers.", + "Example 2:\nInput: mat = [[10,20,15],[21,30,14],[7,16,32]]\nOutput: [1,1]\nExplanation:\u00a0Both 30 and 32 are peak elements so [1,1] and [2,2] are both acceptable answers." + ], + "constraints": "Constraints:\n\nm == mat.length\nn == mat[i].length\n1 <= m, n <= 500\n1 <= mat[i][j] <= 10^5\nNo two adjacent cells are equal.", + "tags": [ + "Array", + "Binary Search", + "Matrix" + ], + "title-slug": "find-a-peak-element-ii" + }, + { + "leetcode-id": 1903, + "title": "Largest Odd Number in String", + "difficulty": 1, + "description": "You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string \"\" if no odd integer exists.\nA substring is a contiguous sequence of characters within a string.", + "examples": [ + "Example 1:\nInput: num = \"52\"\nOutput: \"5\"\nExplanation: The only non-empty substrings are \"5\", \"2\", and \"52\". \"5\" is the only odd number.", + "Example 2:\nInput: num = \"4206\"\nOutput: \"\"\nExplanation: There are no odd numbers in \"4206\".", + "Example 3:\nInput: num = \"35427\"\nOutput: \"35427\"\nExplanation: \"35427\" is already an odd number." + ], + "constraints": "Constraints:\n\n1 <= num.length <= 10^5\nnum only consists of digits and does not contain any leading zeros.", + "tags": [ + "Math", + "String", + "Greedy" + ], + "title-slug": "largest-odd-number-in-string" + }, + { + "leetcode-id": 1904, + "title": "The Number of Full Rounds You Have Played", + "difficulty": 2, + "description": "You are participating in an online chess tournament. There is a chess round that starts every 15 minutes. The first round of the day starts at 00:00, and after every 15 minutes, a new round starts.\n\nFor example, the second round starts at 00:15, the fourth round starts at 00:45, and the seventh round starts at 01:30.\n\nYou are given two strings loginTime and logoutTime where:\n\nloginTime is the time you will login to the game, and\nlogoutTime is the time you will logout from the game.\n\nIf logoutTime is earlier than loginTime, this means you have played from loginTime to midnight and from midnight to logoutTime.\nReturn the number of full chess rounds you have played in the tournament.\nNote:\u00a0All the given times follow the 24-hour clock. That means the first round of the day starts at 00:00 and the last round of the day starts at 23:45.", + "examples": [ + "Example 1:\nInput: loginTime = \"09:31\", logoutTime = \"10:14\"\nOutput: 1\nExplanation: You played one full round from 09:45 to 10:00.\nYou did not play the full round from 09:30 to 09:45 because you logged in at 09:31 after it began.\nYou did not play the full round from 10:00 to 10:15 because you logged out at 10:14 before it ended.", + "Example 2:\nInput: loginTime = \"21:30\", logoutTime = \"03:00\"\nOutput: 22\nExplanation: You played 10 full rounds from 21:30 to 00:00 and 12 full rounds from 00:00 to 03:00.\n10 + 12 = 22." + ], + "constraints": "Constraints:\n\nloginTime and logoutTime are in the format hh:mm.\n00 <= hh <= 23\n00 <= mm <= 59\nloginTime and logoutTime are not equal.", + "tags": [ + "Math", + "String" + ], + "title-slug": "the-number-of-full-rounds-you-have-played" + }, + { + "leetcode-id": 1905, + "title": "Count Sub Islands", + "difficulty": 2, + "description": "You are given two m x n binary matrices grid1 and grid2 containing only 0's (representing water) and 1's (representing land). An island is a group of 1's connected 4-directionally (horizontal or vertical). Any cells outside of the grid are considered water cells.\nAn island in grid2 is considered a sub-island if there is an island in grid1 that contains all the cells that make up this island in grid2.\nReturn the number of islands in grid2 that are considered sub-islands.", + "examples": [ + "Example 1:\nInput: grid1 = [[1,1,1,0,0],[0,1,1,1,1],[0,0,0,0,0],[1,0,0,0,0],[1,1,0,1,1]], grid2 = [[1,1,1,0,0],[0,0,1,1,1],[0,1,0,0,0],[1,0,1,1,0],[0,1,0,1,0]]\nOutput: 3\nExplanation: In the picture above, the grid on the left is grid1 and the grid on the right is grid2.\nThe 1s colored red in grid2 are those considered to be part of a sub-island. There are three sub-islands.", + "Example 2:\nInput: grid1 = [[1,0,1,0,1],[1,1,1,1,1],[0,0,0,0,0],[1,1,1,1,1],[1,0,1,0,1]], grid2 = [[0,0,0,0,0],[1,1,1,1,1],[0,1,0,1,0],[0,1,0,1,0],[1,0,0,0,1]]\nOutput: 2 \nExplanation: In the picture above, the grid on the left is grid1 and the grid on the right is grid2.\nThe 1s colored red in grid2 are those considered to be part of a sub-island. There are two sub-islands." + ], + "constraints": "Constraints:\n\nm == grid1.length == grid2.length\nn == grid1[i].length == grid2[i].length\n1 <= m, n <= 500\ngrid1[i][j] and grid2[i][j] are either 0 or 1.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Matrix" + ], + "title-slug": "count-sub-islands" + }, + { + "leetcode-id": 1906, + "title": "Minimum Absolute Difference Queries", + "difficulty": 2, + "description": "The minimum absolute difference of an array a is defined as the minimum value of |a[i] - a[j]|, where 0 <= i < j < a.length and a[i] != a[j]. If all elements of a are the same, the minimum absolute difference is -1.\n\nFor example, the minimum absolute difference of the array [5,2,3,7,2] is |2 - 3| = 1. Note that it is not 0 because a[i] and a[j] must be different.\n\nYou are given an integer array nums and the array queries where queries[i] = [li, ri]. For each query i, compute the minimum absolute difference of the subarray nums[li...ri] containing the elements of nums between the 0-based indices li and ri (inclusive).\nReturn an array ans where ans[i] is the answer to the i^th query.\nA subarray is a contiguous sequence of elements in an array.\nThe value of |x| is defined as:\n\nx if x >= 0.\n-x if x < 0.", + "examples": [ + "Example 1:\nInput: nums = [1,3,4,8], queries = [[0,1],[1,2],[2,3],[0,3]]\nOutput: [2,1,4,1]\nExplanation: The queries are processed as follows:\n- queries[0] = [0,1]: The subarray is [1,3] and the minimum absolute difference is |1-3| = 2.\n- queries[1] = [1,2]: The subarray is [3,4] and the minimum absolute difference is |3-4| = 1.\n- queries[2] = [2,3]: The subarray is [4,8] and the minimum absolute difference is |4-8| = 4.\n- queries[3] = [0,3]: The subarray is [1,3,4,8] and the minimum absolute difference is |3-4| = 1.", + "Example 2:\nInput: nums = [4,5,2,2,7,10], queries = [[2,3],[0,2],[0,5],[3,5]]\nOutput: [-1,1,1,3]\nExplanation: The queries are processed as follows:\n- queries[0] = [2,3]: The subarray is [2,2] and the minimum absolute difference is -1 because all the\n elements are the same.\n- queries[1] = [0,2]: The subarray is [4,5,2] and the minimum absolute difference is |4-5| = 1.\n- queries[2] = [0,5]: The subarray is [4,5,2,2,7,10] and the minimum absolute difference is |4-5| = 1.\n- queries[3] = [3,5]: The subarray is [2,7,10] and the minimum absolute difference is |7-10| = 3." + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 10^5\n1 <= nums[i] <= 100\n1 <= queries.length <= 2\u00a0* 10^4\n0 <= li < ri < nums.length", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "minimum-absolute-difference-queries" + }, + { + "leetcode-id": 1909, + "title": "Remove One Element to Make the Array Strictly Increasing", + "difficulty": 1, + "description": "Given a 0-indexed integer array nums, return true if it can be made strictly increasing after removing exactly one element, or false otherwise. If the array is already strictly increasing, return true.\nThe array nums is strictly increasing if nums[i - 1] < nums[i] for each index (1 <= i < nums.length).", + "examples": [ + "Example 1:\nInput: nums = [1,2,10,5,7]\nOutput: true\nExplanation: By removing 10 at index 2 from nums, it becomes [1,2,5,7].\n[1,2,5,7] is strictly increasing, so return true.", + "Example 2:\nInput: nums = [2,3,1,2]\nOutput: false\nExplanation:\n[3,1,2] is the result of removing the element at index 0.\n[2,1,2] is the result of removing the element at index 1.\n[2,3,2] is the result of removing the element at index 2.\n[2,3,1] is the result of removing the element at index 3.\nNo resulting array is strictly increasing, so return false.", + "Example 3:\nInput: nums = [1,1,1]\nOutput: false\nExplanation: The result of removing any element is [1,1].\n[1,1] is not strictly increasing, so return false." + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 1000\n1 <= nums[i] <= 1000", + "tags": [ + "Array" + ], + "title-slug": "remove-one-element-to-make-the-array-strictly-increasing" + }, + { + "leetcode-id": 1910, + "title": "Remove All Occurrences of a Substring", + "difficulty": 2, + "description": "Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed:\n\nFind the leftmost occurrence of the substring part and remove it from s.\n\nReturn s after removing all occurrences of part.\nA substring is a contiguous sequence of characters in a string.", + "examples": [ + "Example 1:\nInput: s = \"daabcbaabcbc\", part = \"abc\"\nOutput: \"dab\"\nExplanation: The following operations are done:\n- s = \"daabcbaabcbc\", remove \"abc\" starting at index 2, so s = \"dabaabcbc\".\n- s = \"dabaabcbc\", remove \"abc\" starting at index 4, so s = \"dababc\".\n- s = \"dababc\", remove \"abc\" starting at index 3, so s = \"dab\".\nNow s has no occurrences of \"abc\".", + "Example 2:\nInput: s = \"axxxxyyyyb\", part = \"xy\"\nOutput: \"ab\"\nExplanation: The following operations are done:\n- s = \"axxxxyyyyb\", remove \"xy\" starting at index 4 so s = \"axxxyyyb\".\n- s = \"axxxyyyb\", remove \"xy\" starting at index 3 so s = \"axxyyb\".\n- s = \"axxyyb\", remove \"xy\" starting at index 2 so s = \"axyb\".\n- s = \"axyb\", remove \"xy\" starting at index 1 so s = \"ab\".\nNow s has no occurrences of \"xy\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\n1 <= part.length <= 1000\ns\u200b\u200b\u200b\u200b\u200b\u200b and part consists of lowercase English letters.", + "tags": [ + "String" + ], + "title-slug": "remove-all-occurrences-of-a-substring" + }, + { + "leetcode-id": 1911, + "title": "Maximum Alternating Subsequence Sum", + "difficulty": 2, + "description": "The alternating sum of a 0-indexed array is defined as the sum of the elements at even indices minus the sum of the elements at odd indices.\n\nFor example, the alternating sum of [4,2,5,3] is (4 + 5) - (2 + 3) = 4.\n\nGiven an array nums, return the maximum alternating sum of any subsequence of nums (after reindexing the elements of the subsequence).\n\n\nA subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order. For example, [2,7,4] is a subsequence of [4,2,3,7,2,1,4] (the underlined elements), while [2,4,2] is not.", + "examples": [ + "Example 1:\nInput: nums = [4,2,5,3]\r\nOutput: 7\r\nExplanation: It is optimal to choose the subsequence [4,2,5] with alternating sum (4 + 5) - 2 = 7.", + "Example 2:\nInput: nums = [5,6,7,8]\r\nOutput: 8\r\nExplanation: It is optimal to choose the subsequence [8] with alternating sum 8.", + "Example 3:\nInput: nums = [6,2,1,2,4,5]\r\nOutput: 10\r\nExplanation: It is optimal to choose the subsequence [6,1,5] with alternating sum (6 + 5) - 1 = 10." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "maximum-alternating-subsequence-sum" + }, + { + "leetcode-id": 1912, + "title": "Design Movie Rental System", + "difficulty": 3, + "description": "You have a movie renting company consisting of n shops. You want to implement a renting system that supports searching for, booking, and returning movies. The system should also support generating a report of the currently rented movies.\nEach movie is given as a 2D integer array entries where entries[i] = [shopi, moviei, pricei] indicates that there is a copy of movie moviei at shop shopi with a rental price of pricei. Each shop carries at most one copy of a movie moviei.\nThe system should support the following functions:\n\nSearch: Finds the cheapest 5 shops that have an unrented copy of a given movie. The shops should be sorted by price in ascending order, and in case of a tie, the one with the smaller shopi should appear first. If there are less than 5 matching shops, then all of them should be returned. If no shop has an unrented copy, then an empty list should be returned.\nRent: Rents an unrented copy of a given movie from a given shop.\nDrop: Drops off a previously rented copy of a given movie at a given shop.\nReport: Returns the cheapest 5 rented movies (possibly of the same movie ID) as a 2D list res where res[j] = [shopj, moviej] describes that the j^th cheapest rented movie moviej was rented from the shop shopj. The movies in res should be sorted by price in ascending order, and in case of a tie, the one with the smaller shopj should appear first, and if there is still tie, the one with the smaller moviej should appear first. If there are fewer than 5 rented movies, then all of them should be returned. If no movies are currently being rented, then an empty list should be returned.\n\nImplement the MovieRentingSystem class:\n\nMovieRentingSystem(int n, int[][] entries) Initializes the MovieRentingSystem object with n shops and the movies in entries.\nList search(int movie) Returns a list of shops that have an unrented copy of the given movie as described above.\nvoid rent(int shop, int movie) Rents the given movie from the given shop.\nvoid drop(int shop, int movie) Drops off a previously rented movie at the given shop.\nList> report() Returns a list of cheapest rented movies as described above.\n\nNote: The test cases will be generated such that rent will only be called if the shop has an unrented copy of the movie, and drop will only be called if the shop had previously rented out the movie.", + "examples": [ + "Example 1:\nInput\n[\"MovieRentingSystem\", \"search\", \"rent\", \"rent\", \"report\", \"drop\", \"search\"]\n[[3, [[0, 1, 5], [0, 2, 6], [0, 3, 7], [1, 1, 4], [1, 2, 7], [2, 1, 5]]], [1], [0, 1], [1, 2], [], [1, 2], [2]]\nOutput\n[null, [1, 0, 2], null, null, [[0, 1], [1, 2]], null, [0, 1]]\n\nExplanation\nMovieRentingSystem movieRentingSystem = new MovieRentingSystem(3, [[0, 1, 5], [0, 2, 6], [0, 3, 7], [1, 1, 4], [1, 2, 7], [2, 1, 5]]);\nmovieRentingSystem.search(1); // return [1, 0, 2], Movies of ID 1 are unrented at shops 1, 0, and 2. Shop 1 is cheapest; shop 0 and 2 are the same price, so order by shop number.\nmovieRentingSystem.rent(0, 1); // Rent movie 1 from shop 0. Unrented movies at shop 0 are now [2,3].\nmovieRentingSystem.rent(1, 2); // Rent movie 2 from shop 1. Unrented movies at shop 1 are now [1].\nmovieRentingSystem.report(); // return [[0, 1], [1, 2]]. Movie 1 from shop 0 is cheapest, followed by movie 2 from shop 1.\nmovieRentingSystem.drop(1, 2); // Drop off movie 2 at shop 1. Unrented movies at shop 1 are now [1,2].\nmovieRentingSystem.search(2); // return [0, 1]. Movies of ID 2 are unrented at shops 0 and 1. Shop 0 is cheapest, followed by shop 1." + ], + "constraints": "Constraints:\n\n1 <= n <= 3 * 10^5\n1 <= entries.length <= 10^5\n0 <= shopi < n\n1 <= moviei, pricei <= 10^4\nEach shop carries at most one copy of a movie moviei.\nAt most 10^5 calls in total will be made to search, rent, drop and report.", + "tags": [ + "Array", + "Hash Table", + "Design", + "Heap (Priority Queue)", + "Ordered Set" + ], + "title-slug": "design-movie-rental-system" + }, + { + "leetcode-id": 1913, + "title": "Maximum Product Difference Between Two Pairs", + "difficulty": 1, + "description": "The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d).\n\nFor example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16.\n\nGiven an integer array nums, choose four distinct indices w, x, y, and z such that the product difference between pairs (nums[w], nums[x]) and (nums[y], nums[z]) is maximized.\nReturn the maximum such product difference.", + "examples": [ + "Example 1:\nInput: nums = [5,6,2,7,4]\r\nOutput: 34\r\nExplanation: We can choose indices 1 and 3 for the first pair (6, 7) and indices 2 and 4 for the second pair (2, 4).\r\nThe product difference is (6 * 7) - (2 * 4) = 34.", + "Example 2:\nInput: nums = [4,2,5,9,7,4,8]\r\nOutput: 64\r\nExplanation: We can choose indices 3 and 6 for the first pair (9, 8) and indices 1 and 5 for the second pair (2, 4).\r\nThe product difference is (9 * 8) - (2 * 4) = 64." + ], + "constraints": "Constraints:\n\n4 <= nums.length <= 10^4\n1 <= nums[i] <= 10^4", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "maximum-product-difference-between-two-pairs" + }, + { + "leetcode-id": 1914, + "title": "Cyclically Rotating a Grid", + "difficulty": 2, + "description": "You are given an m x n integer matrix grid\u200b\u200b\u200b, where m and n are both even integers, and an integer k.\nThe matrix is composed of several layers, which is shown in the below image, where each color is its own layer:\n\nA cyclic rotation of the matrix is done by cyclically rotating each layer in the matrix. To cyclically rotate a layer once, each element in the layer will take the place of the adjacent element in the counter-clockwise direction. An example rotation is shown below:\n\nReturn the matrix after applying k cyclic rotations to it.", + "examples": [ + "Example 1:\nInput: grid = [[40,10],[30,20]], k = 1\r\nOutput: [[10,20],[40,30]]\r\nExplanation: The figures above represent the grid at every state.", + "Example 2:\nInput: grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2\r\nOutput: [[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]\r\nExplanation: The figures above represent the grid at every state." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n2 <= m, n <= 50\nBoth m and n are even integers.\n1 <= grid[i][j] <=^ 5000\n1 <= k <= 10^9", + "tags": [ + "Array", + "Matrix", + "Simulation" + ], + "title-slug": "cyclically-rotating-a-grid" + }, + { + "leetcode-id": 1915, + "title": "Number of Wonderful Substrings", + "difficulty": 2, + "description": "A wonderful string is a string where at most one letter appears an odd number of times.\n\nFor example, \"ccjjc\" and \"abab\" are wonderful, but \"ab\" is not.\n\nGiven a string word that consists of the first ten lowercase English letters ('a' through 'j'), return the number of wonderful non-empty substrings in word. If the same substring appears multiple times in word, then count each occurrence separately.\nA substring is a contiguous sequence of characters in a string.", + "examples": [ + "Example 1:\nInput: word = \"aba\"\r\nOutput: 4\r\nExplanation: The four wonderful substrings are underlined below:\r\n- \"aba\" -> \"a\"\r\n- \"aba\" -> \"b\"\r\n- \"aba\" -> \"a\"\r\n- \"aba\" -> \"aba\"", + "Example 2:\nInput: word = \"aabb\"\r\nOutput: 9\r\nExplanation: The nine wonderful substrings are underlined below:\r\n- \"aabb\" -> \"a\"\r\n- \"aabb\" -> \"aa\"\r\n- \"aabb\" -> \"aab\"\r\n- \"aabb\" -> \"aabb\"\r\n- \"aabb\" -> \"a\"\r\n- \"aabb\" -> \"abb\"\r\n- \"aabb\" -> \"b\"\r\n- \"aabb\" -> \"bb\"\r\n- \"aabb\" -> \"b\"", + "Example 3:\nInput: word = \"he\"\r\nOutput: 2\r\nExplanation: The two wonderful substrings are underlined below:\r\n- \"he\" -> \"h\"\r\n- \"he\" -> \"e\"" + ], + "constraints": "Constraints:\n\n1 <= word.length <= 10^5\nword consists of lowercase English letters from 'a'\u00a0to 'j'.", + "tags": [ + "Hash Table", + "String", + "Bit Manipulation", + "Prefix Sum" + ], + "title-slug": "number-of-wonderful-substrings" + }, + { + "leetcode-id": 1916, + "title": "Count Ways to Build Rooms in an Ant Colony", + "difficulty": 3, + "description": "You are an ant tasked with adding n new rooms numbered 0 to n-1 to your colony. You are given the expansion plan as a 0-indexed integer array of length n, prevRoom, where prevRoom[i] indicates that you must build room prevRoom[i] before building room i, and these two rooms must be connected directly. Room 0 is already built, so prevRoom[0] = -1. The expansion\u00a0plan is given such that once all the rooms are built, every room will be reachable from room 0.\nYou can only build one room at a time, and you can travel freely between rooms you have already built only if they are connected.\u00a0You can choose to build any room as long as its previous room\u00a0is already built.\nReturn the number of different orders you can build all the rooms in. Since the answer may be large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: prevRoom = [-1,0,1]\r\nOutput: 1\r\nExplanation:\u00a0There is only one way to build the additional rooms: 0 \u2192 1 \u2192 2", + "Example 2:\nInput: prevRoom = [-1,0,0,1,2]\r\nOutput: 6\r\nExplanation:\r\nThe 6 ways are:\r\n0 \u2192 1 \u2192 3 \u2192 2 \u2192 4\r\n0 \u2192 2 \u2192 4 \u2192 1 \u2192 3\r\n0 \u2192 1 \u2192 2 \u2192 3 \u2192 4\r\n0 \u2192 1 \u2192 2 \u2192 4 \u2192 3\r\n0 \u2192 2 \u2192 1 \u2192 3 \u2192 4\r\n0 \u2192 2 \u2192 1 \u2192 4 \u2192 3" + ], + "constraints": "Constraints:\n\nn == prevRoom.length\n2 <= n <= 10^5\nprevRoom[0] == -1\n0 <= prevRoom[i] < n for all 1 <= i < n\nEvery room is reachable from room 0 once all the rooms are built.", + "tags": [ + "Math", + "Dynamic Programming", + "Tree", + "Graph", + "Topological Sort", + "Combinatorics" + ], + "title-slug": "count-ways-to-build-rooms-in-an-ant-colony" + }, + { + "leetcode-id": 1920, + "title": "Build Array from Permutation", + "difficulty": 1, + "description": "Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it.\nA zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive).", + "examples": [ + "Example 1:\nInput: nums = [0,2,1,5,3,4]\nOutput: [0,1,2,4,5,3]\nExplanation: The array ans is built as follows: \nans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]\n = [nums[0], nums[2], nums[1], nums[5], nums[3], nums[4]]\n = [0,1,2,4,5,3]", + "Example 2:\nInput: nums = [5,0,1,2,3,4]\nOutput: [4,5,0,1,2,3]\nExplanation: The array ans is built as follows:\nans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]\n = [nums[5], nums[0], nums[1], nums[2], nums[3], nums[4]]\n = [4,5,0,1,2,3]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n0 <= nums[i] < nums.length\nThe elements in nums are distinct.\n\n\u00a0\nFollow-up: Can you solve it without using an extra space (i.e., O(1) memory)?", + "tags": [ + "Array", + "Simulation" + ], + "title-slug": "build-array-from-permutation" + }, + { + "leetcode-id": 1921, + "title": "Eliminate Maximum Number of Monsters", + "difficulty": 2, + "description": "You are playing a video game where you are defending your city from a group of n monsters. You are given a 0-indexed integer array dist of size n, where dist[i] is the initial distance in kilometers of the i^th monster from the city.\nThe monsters walk toward the city at a constant speed. The speed of each monster is given to you in an integer array speed of size n, where speed[i] is the speed of the i^th monster in kilometers per minute.\nYou have a weapon that, once fully charged, can eliminate a single monster. However, the weapon takes one minute to charge.The weapon is fully charged at the very start.\nYou lose when any monster reaches your city. If a monster reaches the city at the exact moment the weapon is fully charged, it counts as a loss, and the game ends before you can use your weapon.\nReturn the maximum number of monsters that you can eliminate before you lose, or n if you can eliminate all the monsters before they reach the city.", + "examples": [ + "Example 1:\nInput: dist = [1,3,4], speed = [1,1,1]\nOutput: 3\nExplanation:\nIn the beginning, the distances of the monsters are [1,3,4]. You eliminate the first monster.\nAfter a minute, the distances of the monsters are [X,2,3]. You eliminate the second monster.\nAfter a minute, the distances of the monsters are [X,X,2]. You eliminate the thrid monster.\nAll 3 monsters can be eliminated.", + "Example 2:\nInput: dist = [1,1,2,3], speed = [1,1,1,1]\nOutput: 1\nExplanation:\nIn the beginning, the distances of the monsters are [1,1,2,3]. You eliminate the first monster.\nAfter a minute, the distances of the monsters are [X,0,1,2], so you lose.\nYou can only eliminate 1 monster.", + "Example 3:\nInput: dist = [3,2,4], speed = [5,3,2]\nOutput: 1\nExplanation:\nIn the beginning, the distances of the monsters are [3,2,4]. You eliminate the first monster.\nAfter a minute, the distances of the monsters are [X,0,2], so you lose.\nYou can only eliminate 1 monster." + ], + "constraints": "Constraints:\n\nn == dist.length == speed.length\n1 <= n <= 10^5\n1 <= dist[i], speed[i] <= 10^5", + "tags": [ + "Array", + "Greedy", + "Sorting" + ], + "title-slug": "eliminate-maximum-number-of-monsters" + }, + { + "leetcode-id": 1922, + "title": "Count Good Numbers", + "difficulty": 2, + "description": "A digit string is good if the digits (0-indexed) at even indices are even and the digits at odd indices are prime (2, 3, 5, or 7).\n\nFor example, \"2582\" is good because the digits (2 and 8) at even positions are even and the digits (5 and 2) at odd positions are prime. However, \"3245\" is not good because 3 is at an even index but is not even.\n\nGiven an integer n, return the total number of good digit strings of length n. Since the answer may be large, return it modulo 10^9 + 7.\nA digit string is a string consisting of digits 0 through 9 that may contain leading zeros.", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: 5\nExplanation: The good numbers of length 1 are \"0\", \"2\", \"4\", \"6\", \"8\".", + "Example 2:\nInput: n = 4\nOutput: 400", + "Example 3:\nInput: n = 50\nOutput: 564908303" + ], + "constraints": "Constraints:\n\n1 <= n <= 10^15", + "tags": [ + "Math", + "Recursion" + ], + "title-slug": "count-good-numbers" + }, + { + "leetcode-id": 1923, + "title": "Longest Common Subpath", + "difficulty": 3, + "description": "There is a country of n cities numbered from 0 to n - 1. In this country, there is a road connecting every pair of cities.\nThere are m friends numbered from 0 to m - 1 who are traveling through the country. Each one of them will take a path consisting of some cities. Each path is represented by an integer array that contains the visited cities in order. The path may contain a city more than once, but the same city will not be listed consecutively.\nGiven an integer n and a 2D integer array paths where paths[i] is an integer array representing the path of the i^th friend, return the length of the longest common subpath that is shared by every friend's path, or 0 if there is no common subpath at all.\nA subpath of a path is a contiguous sequence of cities within that path.", + "examples": [ + "Example 1:\nInput: n = 5, paths = [[0,1,2,3,4],\n [2,3,4],\n [4,0,1,2,3]]\nOutput: 2\nExplanation: The longest common subpath is [2,3].", + "Example 2:\nInput: n = 3, paths = [[0],[1],[2]]\nOutput: 0\nExplanation: There is no common subpath shared by the three paths.", + "Example 3:\nInput: n = 5, paths = [[0,1,2,3,4],\n [4,3,2,1,0]]\nOutput: 1\nExplanation: The possible longest common subpaths are [0], [1], [2], [3], and [4]. All have a length of 1." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5\nm == paths.length\n2 <= m <= 10^5\nsum(paths[i].length) <= 10^5\n0 <= paths[i][j] < n\nThe same city is not listed multiple times consecutively in paths[i].", + "tags": [ + "Array", + "Binary Search", + "Rolling Hash", + "Suffix Array", + "Hash Function" + ], + "title-slug": "longest-common-subpath" + }, + { + "leetcode-id": 1925, + "title": "Count Square Sum Triples", + "difficulty": 1, + "description": "A square triple (a,b,c) is a triple where a, b, and c are integers and a^2 + b^2 = c^2.\nGiven an integer n, return the number of square triples such that 1 <= a, b, c <= n.", + "examples": [ + "Example 1:\nInput: n = 5\nOutput: 2\nExplanation: The square triples are (3,4,5) and (4,3,5).", + "Example 2:\nInput: n = 10\nOutput: 4\nExplanation: The square triples are (3,4,5), (4,3,5), (6,8,10), and (8,6,10)." + ], + "constraints": "Constraints:\n\n1 <= n <= 250", + "tags": [ + "Math", + "Enumeration" + ], + "title-slug": "count-square-sum-triples" + }, + { + "leetcode-id": 1926, + "title": "Nearest Exit from Entrance in Maze", + "difficulty": 2, + "description": "You are given an m x n matrix maze (0-indexed) with empty cells (represented as '.') and walls (represented as '+'). You are also given the entrance of the maze, where entrance = [entrancerow, entrancecol] denotes the row and column of the cell you are initially standing at.\nIn one step, you can move one cell up, down, left, or right. You cannot step into a cell with a wall, and you cannot step outside the maze. Your goal is to find the nearest exit from the entrance. An exit is defined as an empty cell that is at the border of the maze. The entrance does not count as an exit.\nReturn the number of steps in the shortest path from the entrance to the nearest exit, or -1 if no such path exists.", + "examples": [ + "Example 1:\nInput: maze = [[\"+\",\"+\",\".\",\"+\"],[\".\",\".\",\".\",\"+\"],[\"+\",\"+\",\"+\",\".\"]], entrance = [1,2]\nOutput: 1\nExplanation: There are 3 exits in this maze at [1,0], [0,2], and [2,3].\nInitially, you are at the entrance cell [1,2].\n- You can reach [1,0] by moving 2 steps left.\n- You can reach [0,2] by moving 1 step up.\nIt is impossible to reach [2,3] from the entrance.\nThus, the nearest exit is [0,2], which is 1 step away.", + "Example 2:\nInput: maze = [[\"+\",\"+\",\"+\"],[\".\",\".\",\".\"],[\"+\",\"+\",\"+\"]], entrance = [1,0]\nOutput: 2\nExplanation: There is 1 exit in this maze at [1,2].\n[1,0] does not count as an exit since it is the entrance cell.\nInitially, you are at the entrance cell [1,0].\n- You can reach [1,2] by moving 2 steps right.\nThus, the nearest exit is [1,2], which is 2 steps away.", + "Example 3:\nInput: maze = [[\".\",\"+\"]], entrance = [0,0]\nOutput: -1\nExplanation: There are no exits in this maze." + ], + "constraints": "Constraints:\n\nmaze.length == m\nmaze[i].length == n\n1 <= m, n <= 100\nmaze[i][j] is either '.' or '+'.\nentrance.length == 2\n0 <= entrancerow < m\n0 <= entrancecol < n\nentrance will always be an empty cell.", + "tags": [ + "Array", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "nearest-exit-from-entrance-in-maze" + }, + { + "leetcode-id": 1927, + "title": "Sum Game", + "difficulty": 2, + "description": "Alice and Bob take turns playing a game, with Alice\u00a0starting first.\nYou are given a string num of even length consisting of digits and '?' characters. On each turn, a player will do the following if there is still at least one '?' in num:\n\nChoose an index i where num[i] == '?'.\nReplace num[i] with any digit between '0' and '9'.\n\nThe game ends when there are no more '?' characters in num.\nFor Bob\u00a0to win, the sum of the digits in the first half of num must be equal to the sum of the digits in the second half. For Alice\u00a0to win, the sums must not be equal.\n\nFor example, if the game ended with num = \"243801\", then Bob\u00a0wins because 2+4+3 = 8+0+1. If the game ended with num = \"243803\", then Alice\u00a0wins because 2+4+3 != 8+0+3.\n\nAssuming Alice and Bob play optimally, return true if Alice will win and false if Bob will win.", + "examples": [ + "Example 1:\nInput: num = \"5023\"\nOutput: false\nExplanation: There are no moves to be made.\nThe sum of the first half is equal to the sum of the second half: 5 + 0 = 2 + 3.", + "Example 2:\nInput: num = \"25??\"\nOutput: true\nExplanation: Alice can replace one of the '?'s with '9' and it will be impossible for Bob to make the sums equal.", + "Example 3:\nInput: num = \"?3295???\"\nOutput: false\nExplanation: It can be proven that Bob will always win. One possible outcome is:\n- Alice replaces the first '?' with '9'. num = \"93295???\".\n- Bob replaces one of the '?' in the right half with '9'. num = \"932959??\".\n- Alice replaces one of the '?' in the right half with '2'. num = \"9329592?\".\n- Bob replaces the last '?' in the right half with '7'. num = \"93295927\".\nBob wins because 9 + 3 + 2 + 9 = 5 + 9 + 2 + 7." + ], + "constraints": "Constraints:\n\n2 <= num.length <= 10^5\nnum.length is even.\nnum consists of only digits and '?'.", + "tags": [ + "Math", + "Greedy", + "Game Theory" + ], + "title-slug": "sum-game" + }, + { + "leetcode-id": 1928, + "title": "Minimum Cost to Reach Destination in Time", + "difficulty": 3, + "description": "There is a country of n cities numbered from 0 to n - 1 where all the cities are connected by bi-directional roads. The roads are represented as a 2D integer array edges where edges[i] = [xi, yi, timei] denotes a road between cities xi and yi that takes timei minutes to travel. There may be multiple roads of differing travel times connecting the same two cities, but no road connects a city to itself.\nEach time you pass through a city, you must pay a passing fee. This is represented as a 0-indexed integer array passingFees of length n where passingFees[j] is the amount of dollars you must pay when you pass through city j.\nIn the beginning, you are at city 0 and want to reach city n - 1 in maxTime minutes or less. The cost of your journey is the summation of passing fees for each city that you passed through at some moment of your journey (including the source and destination cities).\nGiven maxTime, edges, and passingFees, return the minimum cost to complete your journey, or -1 if you cannot complete it within maxTime minutes.", + "examples": [ + "Example 1:\nInput: maxTime = 30, edges = [[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]], passingFees = [5,1,2,20,20,3]\nOutput: 11\nExplanation: The path to take is 0 -> 1 -> 2 -> 5, which takes 30 minutes and has $11 worth of passing fees.", + "Example 2:\nInput: maxTime = 29, edges = [[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]], passingFees = [5,1,2,20,20,3]\nOutput: 48\nExplanation: The path to take is 0 -> 3 -> 4 -> 5, which takes 26 minutes and has $48 worth of passing fees.\nYou cannot take path 0 -> 1 -> 2 -> 5 since it would take too long.", + "Example 3:\nInput: maxTime = 25, edges = [[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]], passingFees = [5,1,2,20,20,3]\nOutput: -1\nExplanation: There is no way to reach city 5 from city 0 within 25 minutes." + ], + "constraints": "Constraints:\n\n1 <= maxTime <= 1000\nn == passingFees.length\n2 <= n <= 1000\nn - 1 <= edges.length <= 1000\n0 <= xi, yi <= n - 1\n1 <= timei <= 1000\n1 <= passingFees[j] <= 1000\u00a0\nThe graph may contain multiple edges between two nodes.\nThe graph does not contain self loops.", + "tags": [ + "Dynamic Programming", + "Graph" + ], + "title-slug": "minimum-cost-to-reach-destination-in-time" + }, + { + "leetcode-id": 1929, + "title": "Concatenation of Array", + "difficulty": 1, + "description": "Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed).\nSpecifically, ans is the concatenation of two nums arrays.\nReturn the array ans.", + "examples": [ + "Example 1:\nInput: nums = [1,2,1]\nOutput: [1,2,1,1,2,1]\nExplanation: The array ans is formed as follows:\n- ans = [nums[0],nums[1],nums[2],nums[0],nums[1],nums[2]]\n- ans = [1,2,1,1,2,1]", + "Example 2:\nInput: nums = [1,3,2,1]\nOutput: [1,3,2,1,1,3,2,1]\nExplanation: The array ans is formed as follows:\n- ans = [nums[0],nums[1],nums[2],nums[3],nums[0],nums[1],nums[2],nums[3]]\n- ans = [1,3,2,1,1,3,2,1]" + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 1000\n1 <= nums[i] <= 1000", + "tags": [ + "Array" + ], + "title-slug": "concatenation-of-array" + }, + { + "leetcode-id": 1930, + "title": "Unique Length-3 Palindromic Subsequences", + "difficulty": 2, + "description": "Given a string s, return the number of unique palindromes of length three that are a subsequence of s.\nNote that even if there are multiple ways to obtain the same subsequence, it is still only counted once.\nA palindrome is a string that reads the same forwards and backwards.\nA subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.\n\nFor example, \"ace\" is a subsequence of \"abcde\".", + "examples": [ + "Example 1:\nInput: s = \"aabca\"\nOutput: 3\nExplanation: The 3 palindromic subsequences of length 3 are:\n- \"aba\" (subsequence of \"aabca\")\n- \"aaa\" (subsequence of \"aabca\")\n- \"aca\" (subsequence of \"aabca\")", + "Example 2:\nInput: s = \"adc\"\nOutput: 0\nExplanation: There are no palindromic subsequences of length 3 in \"adc\".", + "Example 3:\nInput: s = \"bbcbaba\"\nOutput: 4\nExplanation: The 4 palindromic subsequences of length 3 are:\n- \"bbb\" (subsequence of \"bbcbaba\")\n- \"bcb\" (subsequence of \"bbcbaba\")\n- \"bab\" (subsequence of \"bbcbaba\")\n- \"aba\" (subsequence of \"bbcbaba\")" + ], + "constraints": "Constraints:\n\n3 <= s.length <= 10^5\ns consists of only lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Prefix Sum" + ], + "title-slug": "unique-length-3-palindromic-subsequences" + }, + { + "leetcode-id": 1931, + "title": "Painting a Grid With Three Different Colors", + "difficulty": 3, + "description": "You are given two integers m and n. Consider an m x n grid where each cell is initially white. You can paint each cell red, green, or blue. All cells must be painted.\nReturn the number of ways to color the grid with no two adjacent cells having the same color. Since the answer can be very large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: m = 1, n = 1\nOutput: 3\nExplanation: The three possible colorings are shown in the image above.", + "Example 2:\nInput: m = 1, n = 2\nOutput: 6\nExplanation: The six possible colorings are shown in the image above.", + "Example 3:\nInput: m = 5, n = 5\nOutput: 580986" + ], + "constraints": "Constraints:\n\n1 <= m <= 5\n1 <= n <= 1000", + "tags": [ + "Dynamic Programming" + ], + "title-slug": "painting-a-grid-with-three-different-colors" + }, + { + "leetcode-id": 1932, + "title": "Merge BSTs to Create Single BST", + "difficulty": 3, + "description": "You are given n BST (binary search tree) root nodes for n separate BSTs stored in an array trees (0-indexed). Each BST in trees has at most 3 nodes, and no two roots have the same value. In one operation, you can:\n\nSelect two distinct indices i and j such that the value stored at one of the leaves of trees[i] is equal to the root value of trees[j].\nReplace the leaf node in trees[i] with trees[j].\nRemove trees[j] from trees.\n\nReturn the root of the resulting BST if it is possible to form a valid BST after performing n - 1 operations, or null if it is impossible to create a valid BST.\nA BST (binary search tree) is a binary tree where each node satisfies the following property:\n\nEvery node in the node's left subtree has a value\u00a0strictly less\u00a0than the node's value.\nEvery node in the node's right subtree has a value\u00a0strictly greater\u00a0than the node's value.\n\nA leaf is a node that has no children.", + "examples": [ + "Example 1:\nInput: trees = [[2,1],[3,2,5],[5,4]]\nOutput: [3,2,5,1,null,4]\nExplanation:\nIn the first operation, pick i=1 and j=0, and merge trees[0] into trees[1].\nDelete trees[0], so trees = [[3,2,5,1],[5,4]].\n\nIn the second operation, pick i=0 and j=1, and merge trees[1] into trees[0].\nDelete trees[1], so trees = [[3,2,5,1,null,4]].\n\nThe resulting tree, shown above, is a valid BST, so return its root.", + "Example 2:\nInput: trees = [[5,3,8],[3,2,6]]\nOutput: []\nExplanation:\nPick i=0 and j=1 and merge trees[1] into trees[0].\nDelete trees[1], so trees = [[5,3,8,2,6]].\n\nThe resulting tree is shown above. This is the only valid operation that can be performed, but the resulting tree is not a valid BST, so return null.", + "Example 3:\nInput: trees = [[5,4],[3]]\nOutput: []\nExplanation: It is impossible to perform any operations." + ], + "constraints": "Constraints:\n\nn == trees.length\n1 <= n <= 5 * 10^4\nThe number of nodes in each tree is in the range [1, 3].\nEach node in the input may have children but no grandchildren.\nNo two roots of trees have the same value.\nAll the trees in the input are valid BSTs.\n1 <= TreeNode.val <= 5 * 10^4.", + "tags": [ + "Hash Table", + "Binary Search", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "merge-bsts-to-create-single-bst" + }, + { + "leetcode-id": 1935, + "title": "Maximum Number of Words You Can Type", + "difficulty": 1, + "description": "There is a malfunctioning keyboard where some letter keys do not work. All other keys on the keyboard work properly.\nGiven a string text of words separated by a single space (no leading or trailing spaces) and a string brokenLetters of all distinct letter keys that are broken, return the number of words in text you can fully type using this keyboard.", + "examples": [ + "Example 1:\nInput: text = \"hello world\", brokenLetters = \"ad\"\nOutput: 1\nExplanation: We cannot type \"world\" because the 'd' key is broken.", + "Example 2:\nInput: text = \"leet code\", brokenLetters = \"lt\"\nOutput: 1\nExplanation: We cannot type \"leet\" because the 'l' and 't' keys are broken.", + "Example 3:\nInput: text = \"leet code\", brokenLetters = \"e\"\nOutput: 0\nExplanation: We cannot type either word because the 'e' key is broken." + ], + "constraints": "Constraints:\n\n1 <= text.length <= 10^4\n0 <= brokenLetters.length <= 26\ntext consists of words separated by a single space without any leading or trailing spaces.\nEach word only consists of lowercase English letters.\nbrokenLetters consists of distinct lowercase English letters.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "maximum-number-of-words-you-can-type" + }, + { + "leetcode-id": 1936, + "title": "Add Minimum Number of Rungs", + "difficulty": 2, + "description": "You are given a strictly increasing integer array rungs that represents the height of rungs on a ladder. You are currently on the floor at height 0, and you want to reach the last rung.\nYou are also given an integer dist. You can only climb to the next highest rung if the distance between where you are currently at (the floor or on a rung) and the next rung is at most dist. You are able to insert rungs at any positive integer height if a rung is not already there.\nReturn the minimum number of rungs that must be added to the ladder in order for you to climb to the last rung.", + "examples": [ + "Example 1:\nInput: rungs = [1,3,5,10], dist = 2\nOutput: 2\nExplanation:\nYou currently cannot reach the last rung.\nAdd rungs at heights 7 and 8 to climb this ladder. \nThe ladder will now have rungs at [1,3,5,7,8,10].", + "Example 2:\nInput: rungs = [3,6,8,10], dist = 3\nOutput: 0\nExplanation:\nThis ladder can be climbed without adding additional rungs.", + "Example 3:\nInput: rungs = [3,4,6,7], dist = 2\nOutput: 1\nExplanation:\nYou currently cannot reach the first rung from the ground.\nAdd a rung at height 1 to climb this ladder.\nThe ladder will now have rungs at [1,3,4,6,7]." + ], + "constraints": "Constraints:\n\n1 <= rungs.length <= 10^5\n1 <= rungs[i] <= 10^9\n1 <= dist <= 10^9\nrungs is strictly increasing.", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "add-minimum-number-of-rungs" + }, + { + "leetcode-id": 1937, + "title": "Maximum Number of Points with Cost", + "difficulty": 2, + "description": "You are given an m x n integer matrix points (0-indexed). Starting with 0 points, you want to maximize the number of points you can get from the matrix.\nTo gain points, you must pick one cell in each row. Picking the cell at coordinates (r, c) will add points[r][c] to your score.\nHowever, you will lose points if you pick a cell too far from the cell that you picked in the previous row. For every two adjacent rows r and r + 1 (where 0 <= r < m - 1), picking cells at coordinates (r, c1) and (r + 1, c2) will subtract abs(c1 - c2) from your score.\nReturn the maximum number of points you can achieve.\nabs(x) is defined as:\n\nx for x >= 0.\n-x for x < 0.", + "examples": [ + "Example 1:\nInput: points = [[1,2,3],[1,5,1],[3,1,1]]\nOutput: 9\nExplanation:\nThe blue cells denote the optimal cells to pick, which have coordinates (0, 2), (1, 1), and (2, 0).\nYou add 3 + 5 + 3 = 11 to your score.\nHowever, you must subtract abs(2 - 1) + abs(1 - 0) = 2 from your score.\nYour final score is 11 - 2 = 9.", + "Example 2:\nInput: points = [[1,5],[2,3],[4,2]]\nOutput: 11\nExplanation:\nThe blue cells denote the optimal cells to pick, which have coordinates (0, 1), (1, 1), and (2, 0).\nYou add 5 + 3 + 4 = 12 to your score.\nHowever, you must subtract abs(1 - 1) + abs(1 - 0) = 1 from your score.\nYour final score is 12 - 1 = 11." + ], + "constraints": "Constraints:\n\nm == points.length\nn == points[r].length\n1 <= m, n <= 10^5\n1 <= m * n <= 10^5\n0 <= points[r][c] <= 10^5", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "maximum-number-of-points-with-cost" + }, + { + "leetcode-id": 1938, + "title": "Maximum Genetic Difference Query", + "difficulty": 3, + "description": "There is a rooted tree consisting of n nodes numbered 0 to n - 1. Each node's number denotes its unique genetic value (i.e. the genetic value of node x is x). The genetic difference between two genetic values is defined as the bitwise-XOR of their values. You are given the integer array parents, where parents[i] is the parent for node i. If node x is the root of the tree, then parents[x] == -1.\nYou are also given the array queries where queries[i] = [nodei, vali]. For each query i, find the maximum genetic difference between vali and pi, where pi is the genetic value of any node that is on the path between nodei and the root (including nodei and the root). More formally, you want to maximize vali XOR pi.\nReturn an array ans where ans[i] is the answer to the i^th query.", + "examples": [ + "Example 1:\nInput: parents = [-1,0,1,1], queries = [[0,2],[3,2],[2,5]]\nOutput: [2,3,7]\nExplanation: The queries are processed as follows:\n- [0,2]: The node with the maximum genetic difference is 0, with a difference of 2 XOR 0 = 2.\n- [3,2]: The node with the maximum genetic difference is 1, with a difference of 2 XOR 1 = 3.\n- [2,5]: The node with the maximum genetic difference is 2, with a difference of 5 XOR 2 = 7.", + "Example 2:\nInput: parents = [3,7,-1,2,0,7,0,2], queries = [[4,6],[1,15],[0,5]]\nOutput: [6,14,7]\nExplanation: The queries are processed as follows:\n- [4,6]: The node with the maximum genetic difference is 0, with a difference of 6 XOR 0 = 6.\n- [1,15]: The node with the maximum genetic difference is 1, with a difference of 15 XOR 1 = 14.\n- [0,5]: The node with the maximum genetic difference is 2, with a difference of 5 XOR 2 = 7." + ], + "constraints": "Constraints:\n\n2 <= parents.length <= 10^5\n0 <= parents[i] <= parents.length - 1 for every node i that is not the root.\nparents[root] == -1\n1 <= queries.length <= 3 * 10^4\n0 <= nodei <= parents.length - 1\n0 <= vali <= 2 * 10^5", + "tags": [ + "Array", + "Bit Manipulation", + "Trie" + ], + "title-slug": "maximum-genetic-difference-query" + }, + { + "leetcode-id": 1941, + "title": "Check if All Characters Have Equal Number of Occurrences", + "difficulty": 1, + "description": "Given a string s, return true if s is a good string, or false otherwise.\nA string s is good if all the characters that appear in s have the same number of occurrences (i.e., the same frequency).", + "examples": [ + "Example 1:\nInput: s = \"abacbc\"\nOutput: true\nExplanation: The characters that appear in s are 'a', 'b', and 'c'. All characters occur 2 times in s.", + "Example 2:\nInput: s = \"aaabb\"\nOutput: false\nExplanation: The characters that appear in s are 'a' and 'b'.\n'a' occurs 3 times while 'b' occurs 2 times, which is not the same number of times." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns consists of lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Counting" + ], + "title-slug": "check-if-all-characters-have-equal-number-of-occurrences" + }, + { + "leetcode-id": 1942, + "title": "The Number of the Smallest Unoccupied Chair", + "difficulty": 2, + "description": "There is a party where n friends numbered from 0 to n - 1 are attending. There is an infinite number of chairs in this party that are numbered from 0 to infinity. When a friend arrives at the party, they sit on the unoccupied chair with the smallest number.\n\nFor example, if chairs 0, 1, and 5 are occupied when a friend comes, they will sit on chair number 2.\n\nWhen a friend leaves the party, their chair becomes unoccupied at the moment they leave. If another friend arrives at that same moment, they can sit in that chair.\nYou are given a 0-indexed 2D integer array times where times[i] = [arrivali, leavingi], indicating the arrival and leaving times of the i^th friend respectively, and an integer targetFriend. All arrival times are distinct.\nReturn the chair number that the friend numbered targetFriend will sit on.", + "examples": [ + "Example 1:\nInput: times = [[1,4],[2,3],[4,6]], targetFriend = 1\nOutput: 1\nExplanation: \n- Friend 0 arrives at time 1 and sits on chair 0.\n- Friend 1 arrives at time 2 and sits on chair 1.\n- Friend 1 leaves at time 3 and chair 1 becomes empty.\n- Friend 0 leaves at time 4 and chair 0 becomes empty.\n- Friend 2 arrives at time 4 and sits on chair 0.\nSince friend 1 sat on chair 1, we return 1.", + "Example 2:\nInput: times = [[3,10],[1,5],[2,6]], targetFriend = 0\nOutput: 2\nExplanation: \n- Friend 1 arrives at time 1 and sits on chair 0.\n- Friend 2 arrives at time 2 and sits on chair 1.\n- Friend 0 arrives at time 3 and sits on chair 2.\n- Friend 1 leaves at time 5 and chair 0 becomes empty.\n- Friend 2 leaves at time 6 and chair 1 becomes empty.\n- Friend 0 leaves at time 10 and chair 2 becomes empty.\nSince friend 0 sat on chair 2, we return 2." + ], + "constraints": "Constraints:\n\nn == times.length\n2 <= n <= 10^4\ntimes[i].length == 2\n1 <= arrivali < leavingi <= 10^5\n0 <= targetFriend <= n - 1\nEach arrivali time is distinct.", + "tags": [ + "Array", + "Heap (Priority Queue)", + "Ordered Set" + ], + "title-slug": "the-number-of-the-smallest-unoccupied-chair" + }, + { + "leetcode-id": 1943, + "title": "Describe the Painting", + "difficulty": 2, + "description": "There is a long and thin painting that can be represented by a number line. The painting was painted with multiple overlapping segments where each segment was painted with a unique color. You are given a 2D integer array segments, where segments[i] = [starti, endi, colori] represents the half-closed segment [starti, endi) with colori as the color.\nThe colors in the overlapping segments of the painting were mixed when it was painted. When two or more colors mix, they form a new color that can be represented as a set of mixed colors.\n\nFor example, if colors 2, 4, and 6 are mixed, then the resulting mixed color is {2,4,6}.\n\nFor the sake of simplicity, you should only output the sum of the elements in the set rather than the full set.\nYou want to describe the painting with the minimum number of non-overlapping half-closed segments of these mixed colors. These segments can be represented by the 2D array painting where painting[j] = [leftj, rightj, mixj] describes a half-closed segment [leftj, rightj) with the mixed color sum of mixj.\n\nFor example, the painting created with segments = [[1,4,5],[1,7,7]] can be described by painting = [[1,4,12],[4,7,7]] because:\n\n\t\n[1,4) is colored {5,7} (with a sum of 12) from both the first and second segments.\n[4,7) is colored {7} from only the second segment.\n\n\n\nReturn the 2D array painting describing the finished painting (excluding any parts that are not painted). You may return the segments in any order.\nA half-closed segment [a, b) is the section of the number line between points a and b including point a and not including point b.", + "examples": [ + "Example 1:\nInput: segments = [[1,4,5],[4,7,7],[1,7,9]]\nOutput: [[1,4,14],[4,7,16]]\nExplanation: The painting can be described as follows:\n- [1,4) is colored {5,9} (with a sum of 14) from the first and third segments.\n- [4,7) is colored {7,9} (with a sum of 16) from the second and third segments.", + "Example 2:\nInput: segments = [[1,7,9],[6,8,15],[8,10,7]]\nOutput: [[1,6,9],[6,7,24],[7,8,15],[8,10,7]]\nExplanation: The painting can be described as follows:\n- [1,6) is colored 9 from the first segment.\n- [6,7) is colored {9,15} (with a sum of 24) from the first and second segments.\n- [7,8) is colored 15 from the second segment.\n- [8,10) is colored 7 from the third segment.", + "Example 3:\nInput: segments = [[1,4,5],[1,4,7],[4,7,1],[4,7,11]]\nOutput: [[1,4,12],[4,7,12]]\nExplanation: The painting can be described as follows:\n- [1,4) is colored {5,7} (with a sum of 12) from the first and second segments.\n- [4,7) is colored {1,11} (with a sum of 12) from the third and fourth segments.\nNote that returning a single segment [1,7) is incorrect because the mixed color sets are different." + ], + "constraints": "Constraints:\n\n1 <= segments.length <= 2 * 10^4\nsegments[i].length == 3\n1 <= starti < endi <= 10^5\n1 <= colori <= 10^9\nEach colori is distinct.", + "tags": [ + "Array", + "Prefix Sum" + ], + "title-slug": "describe-the-painting" + }, + { + "leetcode-id": 1944, + "title": "Number of Visible People in a Queue", + "difficulty": 3, + "description": "There are n people standing in a queue, and they numbered from 0 to n - 1 in left to right order. You are given an array heights of distinct integers where heights[i] represents the height of the i^th person.\nA person can see another person to their right in the queue if everybody in between is shorter than both of them. More formally, the i^th person can see the j^th person if i < j and min(heights[i], heights[j]) > max(heights[i+1], heights[i+2], ..., heights[j-1]).\nReturn an array answer of length n where answer[i] is the number of people the i^th person can see to their right in the queue.", + "examples": [ + "Example 1:\nInput: heights = [10,6,8,5,11,9]\nOutput: [3,1,2,1,1,0]\nExplanation:\nPerson 0 can see person 1, 2, and 4.\nPerson 1 can see person 2.\nPerson 2 can see person 3 and 4.\nPerson 3 can see person 4.\nPerson 4 can see person 5.\nPerson 5 can see no one since nobody is to the right of them.", + "Example 2:\nInput: heights = [5,1,2,3,10]\nOutput: [4,1,1,1,0]" + ], + "constraints": "Constraints:\n\nn == heights.length\n1 <= n <= 10^5\n1 <= heights[i] <= 10^5\nAll the values of heights are unique.", + "tags": [ + "Array", + "Stack", + "Monotonic Stack" + ], + "title-slug": "number-of-visible-people-in-a-queue" + }, + { + "leetcode-id": 1945, + "title": "Sum of Digits of String After Convert", + "difficulty": 1, + "description": "You are given a string s consisting of lowercase English letters, and an integer k.\nFirst, convert s into an integer by replacing each letter with its position in the alphabet (i.e., replace 'a' with 1, 'b' with 2, ..., 'z' with 26). Then, transform the integer by replacing it with the sum of its digits. Repeat the transform operation k times in total.\nFor example, if s = \"zbax\" and k = 2, then the resulting integer would be 8 by the following operations:\n\nConvert: \"zbax\" \u279d \"(26)(2)(1)(24)\" \u279d \"262124\" \u279d 262124\nTransform #1: 262124 \u279d 2 + 6 + 2 + 1 + 2 + 4\u00a0\u279d 17\nTransform #2: 17 \u279d 1 + 7 \u279d 8\n\nReturn the resulting integer after performing the operations described above.", + "examples": [ + "Example 1:\nInput: s = \"iiii\", k = 1\nOutput: 36\nExplanation: The operations are as follows:\n- Convert: \"iiii\" \u279d \"(9)(9)(9)(9)\" \u279d \"9999\" \u279d 9999\n- Transform #1: 9999 \u279d 9 + 9 + 9 + 9 \u279d 36\nThus the resulting integer is 36.", + "Example 2:\nInput: s = \"leetcode\", k = 2\nOutput: 6\nExplanation: The operations are as follows:\n- Convert: \"leetcode\" \u279d \"(12)(5)(5)(20)(3)(15)(4)(5)\" \u279d \"12552031545\" \u279d 12552031545\n- Transform #1: 12552031545 \u279d 1 + 2 + 5 + 5 + 2 + 0 + 3 + 1 + 5 + 4 + 5 \u279d 33\n- Transform #2: 33 \u279d 3 + 3 \u279d 6\nThus the resulting integer is 6.", + "Example 3:\nInput: s = \"zbax\", k = 2\nOutput: 8" + ], + "constraints": "Constraints:\n\n1 <= s.length <= 100\n1 <= k <= 10\ns consists of lowercase English letters.", + "tags": [ + "String", + "Simulation" + ], + "title-slug": "sum-of-digits-of-string-after-convert" + }, + { + "leetcode-id": 1946, + "title": "Largest Number After Mutating Substring", + "difficulty": 2, + "description": "You are given a string num, which represents a large integer. You are also given a 0-indexed integer array change of length 10 that maps each digit 0-9 to another digit. More formally, digit d maps to digit change[d].\nYou may choose to mutate a single substring of num. To mutate a substring, replace each digit num[i] with the digit it maps to in change (i.e. replace num[i] with change[num[i]]).\nReturn a string representing the largest possible integer after mutating (or choosing not to) a single substring of num.\nA substring is a contiguous sequence of characters within the string.", + "examples": [ + "Example 1:\nInput: num = \"132\", change = [9,8,5,0,3,6,4,2,6,8]\nOutput: \"832\"\nExplanation: Replace the substring \"1\":\n- 1 maps to change[1] = 8.\nThus, \"132\" becomes \"832\".\n\"832\" is the largest number that can be created, so return it.", + "Example 2:\nInput: num = \"021\", change = [9,4,3,5,7,2,1,9,0,6]\nOutput: \"934\"\nExplanation: Replace the substring \"021\":\n- 0 maps to change[0] = 9.\n- 2 maps to change[2] = 3.\n- 1 maps to change[1] = 4.\nThus, \"021\" becomes \"934\".\n\"934\" is the largest number that can be created, so return it.", + "Example 3:\nInput: num = \"5\", change = [1,4,7,5,3,2,5,6,9,4]\nOutput: \"5\"\nExplanation: \"5\" is already the largest number that can be created, so return it." + ], + "constraints": "Constraints:\n\n1 <= num.length <= 10^5\nnum consists of only digits 0-9.\nchange.length == 10\n0 <= change[d] <= 9", + "tags": [ + "Array", + "String", + "Greedy" + ], + "title-slug": "largest-number-after-mutating-substring" + }, + { + "leetcode-id": 1947, + "title": "Maximum Compatibility Score Sum", + "difficulty": 2, + "description": "There is a survey that consists of n questions where each question's answer is either 0 (no) or 1 (yes).\nThe survey was given to m students numbered from 0 to m - 1 and m mentors numbered from 0 to m - 1. The answers of the students are represented by a 2D integer array students where students[i] is an integer array that contains the answers of the i^th student (0-indexed). The answers of the mentors are represented by a 2D integer array mentors where mentors[j] is an integer array that contains the answers of the j^th mentor (0-indexed).\nEach student will be assigned to one mentor, and each mentor will have one student assigned to them. The compatibility score of a student-mentor pair is the number of answers that are the same for both the student and the mentor.\n\nFor example, if the student's answers were [1, 0, 1] and the mentor's answers were [0, 0, 1], then their compatibility score is 2 because only the second and the third answers are the same.\n\nYou are tasked with finding the optimal student-mentor pairings to maximize the sum of the compatibility scores.\nGiven students and mentors, return the maximum compatibility score sum that can be achieved.", + "examples": [ + "Example 1:\nInput: students = [[1,1,0],[1,0,1],[0,0,1]], mentors = [[1,0,0],[0,0,1],[1,1,0]]\nOutput: 8\nExplanation:\u00a0We assign students to mentors in the following way:\n- student 0 to mentor 2 with a compatibility score of 3.\n- student 1 to mentor 0 with a compatibility score of 2.\n- student 2 to mentor 1 with a compatibility score of 3.\nThe compatibility score sum is 3 + 2 + 3 = 8.", + "Example 2:\nInput: students = [[0,0],[0,0],[0,0]], mentors = [[1,1],[1,1],[1,1]]\nOutput: 0\nExplanation: The compatibility score of any student-mentor pair is 0." + ], + "constraints": "Constraints:\n\nm == students.length == mentors.length\nn == students[i].length == mentors[j].length\n1 <= m, n <= 8\nstudents[i][k] is either 0 or 1.\nmentors[j][k] is either 0 or 1.", + "tags": [ + "Array", + "Dynamic Programming", + "Backtracking", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "maximum-compatibility-score-sum" + }, + { + "leetcode-id": 1948, + "title": "Delete Duplicate Folders in System", + "difficulty": 3, + "description": "Due to a bug, there are many duplicate folders in a file system. You are given a 2D array paths, where paths[i] is an array representing an absolute path to the i^th folder in the file system.\n\nFor example, [\"one\", \"two\", \"three\"] represents the path \"/one/two/three\".\n\nTwo folders (not necessarily on the same level) are identical if they contain the same non-empty set of identical subfolders and underlying subfolder structure. The folders do not need to be at the root level to be identical. If two or more folders are identical, then mark the folders as well as all their subfolders.\n\nFor example, folders \"/a\" and \"/b\" in the file structure below are identical. They (as well as their subfolders) should all be marked:\n\n\t\n/a\n/a/x\n/a/x/y\n/a/z\n/b\n/b/x\n/b/x/y\n/b/z\n\n\nHowever, if the file structure also included the path \"/b/w\", then the folders \"/a\" and \"/b\" would not be identical. Note that \"/a/x\" and \"/b/x\" would still be considered identical even with the added folder.\n\nOnce all the identical folders and their subfolders have been marked, the file system will delete all of them. The file system only runs the deletion once, so any folders that become identical after the initial deletion are not deleted.\nReturn the 2D array ans containing the paths of the remaining folders after deleting all the marked folders. The paths may be returned in any order.", + "examples": [ + "Example 1:\nInput: paths = [[\"a\"],[\"c\"],[\"d\"],[\"a\",\"b\"],[\"c\",\"b\"],[\"d\",\"a\"]]\nOutput: [[\"d\"],[\"d\",\"a\"]]\nExplanation: The file structure is as shown.\nFolders \"/a\" and \"/c\" (and their subfolders) are marked for deletion because they both contain an empty\nfolder named \"b\".", + "Example 2:\nInput: paths = [[\"a\"],[\"c\"],[\"a\",\"b\"],[\"c\",\"b\"],[\"a\",\"b\",\"x\"],[\"a\",\"b\",\"x\",\"y\"],[\"w\"],[\"w\",\"y\"]]\nOutput: [[\"c\"],[\"c\",\"b\"],[\"a\"],[\"a\",\"b\"]]\nExplanation: The file structure is as shown. \nFolders \"/a/b/x\" and \"/w\" (and their subfolders) are marked for deletion because they both contain an empty folder named \"y\".\nNote that folders \"/a\" and \"/c\" are identical after the deletion, but they are not deleted because they were not marked beforehand.", + "Example 3:\nInput: paths = [[\"a\",\"b\"],[\"c\",\"d\"],[\"c\"],[\"a\"]]\nOutput: [[\"c\"],[\"c\",\"d\"],[\"a\"],[\"a\",\"b\"]]\nExplanation: All folders are unique in the file system.\nNote that the returned array can be in a different order as the order does not matter." + ], + "constraints": "Constraints:\n\n1 <= paths.length <= 2 * 10^4\n1 <= paths[i].length <= 500\n1 <= paths[i][j].length <= 10\n1 <= sum(paths[i][j].length) <= 2 * 10^5\npath[i][j] consists of lowercase English letters.\nNo two paths lead to the same folder.\nFor any folder not at the root level, its parent folder will also be in the input.", + "tags": [ + "Array", + "Hash Table", + "String", + "Trie", + "Hash Function" + ], + "title-slug": "delete-duplicate-folders-in-system" + }, + { + "leetcode-id": 1952, + "title": "Three Divisors", + "difficulty": 1, + "description": "Given an integer n, return true if n has exactly three positive divisors. Otherwise, return false.\nAn integer m is a divisor of n if there exists an integer k such that n = k * m.", + "examples": [ + "Example 1:\nInput: n = 2\nOutput: false\nExplantion: 2 has only two divisors: 1 and 2.", + "Example 2:\nInput: n = 4\nOutput: true\nExplantion: 4 has three divisors: 1, 2, and 4." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^4", + "tags": [ + "Math" + ], + "title-slug": "three-divisors" + }, + { + "leetcode-id": 1953, + "title": "Maximum Number of Weeks for Which You Can Work", + "difficulty": 2, + "description": "There are n projects numbered from 0 to n - 1. You are given an integer array milestones where each milestones[i] denotes the number of milestones the i^th project has.\nYou can work on the projects following these two rules:\n\nEvery week, you will finish exactly one milestone of one project. You\u00a0must\u00a0work every week.\nYou cannot work on two milestones from the same project for two consecutive weeks.\n\nOnce all the milestones of all the projects are finished, or if the only milestones that you can work on will cause you to violate the above rules, you will stop working. Note that you may not be able to finish every project's milestones due to these constraints.\nReturn the maximum number of weeks you would be able to work on the projects without violating the rules mentioned above.", + "examples": [ + "Example 1:\nInput: milestones = [1,2,3]\nOutput: 6\nExplanation: One possible scenario is:\n\u200b\u200b\u200b\u200b- During the 1^st week, you will work on a milestone of project 0.\n- During the 2^nd week, you will work on a milestone of project 2.\n- During the 3^rd week, you will work on a milestone of project 1.\n- During the 4^th week, you will work on a milestone of project 2.\n- During the 5^th week, you will work on a milestone of project 1.\n- During the 6^th week, you will work on a milestone of project 2.\nThe total number of weeks is 6.", + "Example 2:\nInput: milestones = [5,2,1]\nOutput: 7\nExplanation: One possible scenario is:\n- During the 1^st week, you will work on a milestone of project 0.\n- During the 2^nd week, you will work on a milestone of project 1.\n- During the 3^rd week, you will work on a milestone of project 0.\n- During the 4^th week, you will work on a milestone of project 1.\n- During the 5^th week, you will work on a milestone of project 0.\n- During the 6^th week, you will work on a milestone of project 2.\n- During the 7^th week, you will work on a milestone of project 0.\nThe total number of weeks is 7.\nNote that you cannot work on the last milestone of project 0 on 8^th week because it would violate the rules.\nThus, one milestone in project 0 will remain unfinished." + ], + "constraints": "Constraints:\n\nn == milestones.length\n1 <= n <= 10^5\n1 <= milestones[i] <= 10^9", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "maximum-number-of-weeks-for-which-you-can-work" + }, + { + "leetcode-id": 1954, + "title": "Minimum Garden Perimeter to Collect Enough Apples", + "difficulty": 2, + "description": "In a garden represented as an infinite 2D grid, there is an apple tree planted at every integer coordinate. The apple tree planted at an integer coordinate (i, j) has |i| + |j| apples growing on it.\nYou will buy an axis-aligned square plot of land that is centered at (0, 0).\nGiven an integer neededApples, return the minimum perimeter of a plot such that at least neededApples apples are inside or on the perimeter of that plot.\nThe value of |x| is defined as:\n\nx if x >= 0\n-x if x < 0", + "examples": [ + "Example 1:\nInput: neededApples = 1\nOutput: 8\nExplanation: A square plot of side length 1 does not contain any apples.\nHowever, a square plot of side length 2 has 12 apples inside (as depicted in the image above).\nThe perimeter is 2 * 4 = 8.", + "Example 2:\nInput: neededApples = 13\nOutput: 16", + "Example 3:\nInput: neededApples = 1000000000\nOutput: 5040" + ], + "constraints": "Constraints:\n\n1 <= neededApples <= 10^15", + "tags": [ + "Math", + "Binary Search" + ], + "title-slug": "minimum-garden-perimeter-to-collect-enough-apples" + }, + { + "leetcode-id": 1955, + "title": "Count Number of Special Subsequences", + "difficulty": 3, + "description": "A sequence is special if it consists of a positive number of 0s, followed by a positive number of 1s, then a positive number of 2s.\n\nFor example, [0,1,2] and [0,0,1,1,1,2] are special.\nIn contrast, [2,1,0], [1], and [0,1,2,0] are not special.\n\nGiven an array nums (consisting of only integers 0, 1, and 2), return the number of different subsequences that are special. Since the answer may be very large, return it modulo 10^9 + 7.\nA subsequence of an array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements. Two subsequences are different if the set of indices chosen are different.", + "examples": [ + "Example 1:\nInput: nums = [0,1,2,2]\nOutput: 3\nExplanation: The special subsequences are bolded [0,1,2,2], [0,1,2,2], and [0,1,2,2].", + "Example 2:\nInput: nums = [2,2,0,0]\nOutput: 0\nExplanation: There are no special subsequences in [2,2,0,0].", + "Example 3:\nInput: nums = [0,1,2,0,1,2]\nOutput: 7\nExplanation: The special subsequences are bolded:\n- [0,1,2,0,1,2]\n- [0,1,2,0,1,2]\n- [0,1,2,0,1,2]\n- [0,1,2,0,1,2]\n- [0,1,2,0,1,2]\n- [0,1,2,0,1,2]\n- [0,1,2,0,1,2]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 2", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "count-number-of-special-subsequences" + }, + { + "leetcode-id": 1957, + "title": "Delete Characters to Make Fancy String", + "difficulty": 1, + "description": "A fancy string is a string where no three consecutive characters are equal.\nGiven a string s, delete the minimum possible number of characters from s to make it fancy.\nReturn the final string after the deletion. It can be shown that the answer will always be unique.", + "examples": [ + "Example 1:\nInput: s = \"leeetcode\"\nOutput: \"leetcode\"\nExplanation:\nRemove an 'e' from the first group of 'e's to create \"leetcode\".\nNo three consecutive characters are equal, so return \"leetcode\".", + "Example 2:\nInput: s = \"aaabaaaa\"\nOutput: \"aabaa\"\nExplanation:\nRemove an 'a' from the first group of 'a's to create \"aabaaaa\".\nRemove two 'a's from the second group of 'a's to create \"aabaa\".\nNo three consecutive characters are equal, so return \"aabaa\".", + "Example 3:\nInput: s = \"aab\"\nOutput: \"aab\"\nExplanation: No three consecutive characters are equal, so return \"aab\"." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists only of lowercase English letters.", + "tags": [ + "String" + ], + "title-slug": "delete-characters-to-make-fancy-string" + }, + { + "leetcode-id": 1958, + "title": "Check if Move is Legal", + "difficulty": 2, + "description": "You are given a 0-indexed 8 x 8 grid board, where board[r][c] represents the cell (r, c) on a game board. On the board, free cells are represented by '.', white cells are represented by 'W', and black cells are represented by 'B'.\nEach move in this game consists of choosing a free cell and changing it to the color you are playing as (either white or black). However, a move is only legal if, after changing it, the cell becomes the endpoint of a good line (horizontal, vertical, or diagonal).\nA good line is a line of three or more cells (including the endpoints) where the endpoints of the line are one color, and the remaining cells in the middle are the opposite color (no cells in the line are free). You can find examples for good lines in the figure below:\n\nGiven two integers rMove and cMove and a character color representing the color you are playing as (white or black), return true if changing cell (rMove, cMove) to color color is a legal move, or false if it is not legal.", + "examples": [ + "Example 1:\nInput: board = [[\".\",\".\",\".\",\"B\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"],[\"W\",\"B\",\"B\",\".\",\"W\",\"W\",\"W\",\"B\"],[\".\",\".\",\".\",\"B\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"B\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"]], rMove = 4, cMove = 3, color = \"B\"\nOutput: true\nExplanation: '.', 'W', and 'B' are represented by the colors blue, white, and black respectively, and cell (rMove, cMove) is marked with an 'X'.\nThe two good lines with the chosen cell as an endpoint are annotated above with the red rectangles.", + "Example 2:\nInput: board = [[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\"B\",\".\",\".\",\"W\",\".\",\".\",\".\"],[\".\",\".\",\"W\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\"B\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\".\",\"B\",\"W\",\".\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\"W\",\".\"],[\".\",\".\",\".\",\".\",\".\",\".\",\".\",\"B\"]], rMove = 4, cMove = 4, color = \"W\"\nOutput: false\nExplanation: While there are good lines with the chosen cell as a middle cell, there are no good lines with the chosen cell as an endpoint." + ], + "constraints": "Constraints:\n\nboard.length == board[r].length == 8\n0 <= rMove, cMove < 8\nboard[rMove][cMove] == '.'\ncolor is either 'B' or 'W'.", + "tags": [ + "Array", + "Matrix", + "Enumeration" + ], + "title-slug": "check-if-move-is-legal" + }, + { + "leetcode-id": 1959, + "title": "Minimum Total Space Wasted With K Resizing Operations", + "difficulty": 2, + "description": "You are currently designing a dynamic array. You are given a 0-indexed integer array nums, where nums[i] is the number of elements that will be in the array at time i. In addition, you are given an integer k, the maximum number of times you can resize the array (to any size).\nThe size of the array at time t, sizet, must be at least nums[t] because there needs to be enough space in the array to hold all the elements. The space wasted at\u00a0time t is defined as sizet - nums[t], and the total space wasted is the sum of the space wasted across every time t where 0 <= t < nums.length.\nReturn the minimum total space wasted if you can resize the array at most k times.\nNote: The array can have any size at the start and does not count towards the number of resizing operations.", + "examples": [ + "Example 1:\nInput: nums = [10,20], k = 0\nOutput: 10\nExplanation: size = [20,20].\nWe can set the initial size to be 20.\nThe total wasted space is (20 - 10) + (20 - 20) = 10.", + "Example 2:\nInput: nums = [10,20,30], k = 1\nOutput: 10\nExplanation: size = [20,20,30].\nWe can set the initial size to be 20 and resize to 30 at time 2. \nThe total wasted space is (20 - 10) + (20 - 20) + (30 - 30) = 10.", + "Example 3:\nInput: nums = [10,20,15,30,20], k = 2\nOutput: 15\nExplanation: size = [10,20,20,30,30].\nWe can set the initial size to 10, resize to 20 at time 1, and resize to 30 at time 3.\nThe total wasted space is (10 - 10) + (20 - 20) + (20 - 15) + (30 - 30) + (30 - 20) = 15." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 200\n1 <= nums[i] <= 10^6\n0 <= k <= nums.length - 1", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "minimum-total-space-wasted-with-k-resizing-operations" + }, + { + "leetcode-id": 1960, + "title": "Maximum Product of the Length of Two Palindromic Substrings", + "difficulty": 3, + "description": "You are given a 0-indexed string s and are tasked with finding two non-intersecting palindromic substrings of odd length such that the product of their lengths is maximized.\nMore formally, you want to choose four integers i, j, k, l such that 0 <= i <= j < k <= l < s.length and both the substrings s[i...j] and s[k...l] are palindromes and have odd lengths. s[i...j] denotes a substring from index i to index j inclusive.\nReturn the maximum possible product of the lengths of the two non-intersecting palindromic substrings.\nA palindrome is a string that is the same forward and backward. A substring is a contiguous sequence of characters in a string.", + "examples": [ + "Example 1:\nInput: s = \"ababbb\"\nOutput: 9\nExplanation: Substrings \"aba\" and \"bbb\" are palindromes with odd length. product = 3 * 3 = 9.", + "Example 2:\nInput: s = \"zaaaxbbby\"\nOutput: 9\nExplanation: Substrings \"aaa\" and \"bbb\" are palindromes with odd length. product = 3 * 3 = 9." + ], + "constraints": "Constraints:\n\n2 <= s.length <= 10^5\ns consists of lowercase English letters.", + "tags": [ + "String", + "Rolling Hash", + "Hash Function" + ], + "title-slug": "maximum-product-of-the-length-of-two-palindromic-substrings" + }, + { + "leetcode-id": 1961, + "title": "Check If String Is a Prefix of Array", + "difficulty": 1, + "description": "Given a string s and an array of strings words, determine whether s is a prefix string of words.\nA string s is a prefix string of words if s can be made by concatenating the first k strings in words for some positive k no larger than words.length.\nReturn true if s is a prefix string of words, or false otherwise.", + "examples": [ + "Example 1:\nInput: s = \"iloveleetcode\", words = [\"i\",\"love\",\"leetcode\",\"apples\"]\nOutput: true\nExplanation:\ns can be made by concatenating \"i\", \"love\", and \"leetcode\" together.", + "Example 2:\nInput: s = \"iloveleetcode\", words = [\"apples\",\"i\",\"love\",\"leetcode\"]\nOutput: false\nExplanation:\nIt is impossible to make s using a prefix of arr." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 100\n1 <= words[i].length <= 20\n1 <= s.length <= 1000\nwords[i] and s consist of only lowercase English letters.", + "tags": [ + "Array", + "String" + ], + "title-slug": "check-if-string-is-a-prefix-of-array" + }, + { + "leetcode-id": 1962, + "title": "Remove Stones to Minimize the Total", + "difficulty": 2, + "description": "You are given a 0-indexed integer array piles, where piles[i] represents the number of stones in the i^th pile, and an integer k. You should apply the following operation exactly k times:\n\nChoose any piles[i] and remove floor(piles[i] / 2) stones from it.\n\nNotice that you can apply the operation on the same pile more than once.\nReturn the minimum possible total number of stones remaining after applying the k operations.\nfloor(x) is the greatest integer that is smaller than or equal to x (i.e., rounds x down).", + "examples": [ + "Example 1:\nInput: piles = [5,4,9], k = 2\nOutput: 12\nExplanation:\u00a0Steps of a possible scenario are:\n- Apply the operation on pile 2. The resulting piles are [5,4,5].\n- Apply the operation on pile 0. The resulting piles are [3,4,5].\nThe total number of stones in [3,4,5] is 12.", + "Example 2:\nInput: piles = [4,3,6,7], k = 3\nOutput: 12\nExplanation:\u00a0Steps of a possible scenario are:\n- Apply the operation on pile 2. The resulting piles are [4,3,3,7].\n- Apply the operation on pile 3. The resulting piles are [4,3,3,4].\n- Apply the operation on pile 0. The resulting piles are [2,3,3,4].\nThe total number of stones in [2,3,3,4] is 12." + ], + "constraints": "Constraints:\n\n1 <= piles.length <= 10^5\n1 <= piles[i] <= 10^4\n1 <= k <= 10^5", + "tags": [ + "Array", + "Heap (Priority Queue)" + ], + "title-slug": "remove-stones-to-minimize-the-total" + }, + { + "leetcode-id": 1963, + "title": "Minimum Number of Swaps to Make the String Balanced", + "difficulty": 2, + "description": "You are given a 0-indexed string s of even length n. The string consists of exactly n / 2 opening brackets '[' and n / 2 closing brackets ']'.\nA string is called balanced if and only if:\n\nIt is the empty string, or\nIt can be written as AB, where both A and B are balanced strings, or\nIt can be written as [C], where C is a balanced string.\n\nYou may swap the brackets at any two indices any number of times.\nReturn the minimum number of swaps to make s balanced.", + "examples": [ + "Example 1:\nInput: s = \"][][\"\nOutput: 1\nExplanation: You can make the string balanced by swapping index 0 with index 3.\nThe resulting string is \"[[]]\".", + "Example 2:\nInput: s = \"]]][[[\"\nOutput: 2\nExplanation: You can do the following to make the string balanced:\n- Swap index 0 with index 4. s = \"[]][][\".\n- Swap index 1 with index 5. s = \"[[][]]\".\nThe resulting string is \"[[][]]\".", + "Example 3:\nInput: s = \"[]\"\nOutput: 0\nExplanation: The string is already balanced." + ], + "constraints": "Constraints:\n\nn == s.length\n2 <= n <= 10^6\nn is even.\ns[i] is either '[' or ']'.\nThe number of opening brackets '[' equals n / 2, and the number of closing brackets ']' equals n / 2.", + "tags": [ + "Two Pointers", + "String", + "Stack", + "Greedy" + ], + "title-slug": "minimum-number-of-swaps-to-make-the-string-balanced" + }, + { + "leetcode-id": 1964, + "title": "Find the Longest Valid Obstacle Course at Each Position", + "difficulty": 3, + "description": "You want to build some obstacle courses. You are given a 0-indexed integer array obstacles of length n, where obstacles[i] describes the height of the i^th obstacle.\nFor every index i between 0 and n - 1 (inclusive), find the length of the longest obstacle course in obstacles such that:\n\nYou choose any number of obstacles between 0 and i inclusive.\nYou must include the i^th obstacle in the course.\nYou must put the chosen obstacles in the same order as they appear in obstacles.\nEvery obstacle (except the first) is taller than or the same height as the obstacle immediately before it.\n\nReturn an array ans of length n, where ans[i] is the length of the longest obstacle course for index i as described above.", + "examples": [ + "Example 1:\nInput: obstacles = [1,2,3,2]\nOutput: [1,2,3,3]\nExplanation: The longest valid obstacle course at each position is:\n- i = 0: [1], [1] has length 1.\n- i = 1: [1,2], [1,2] has length 2.\n- i = 2: [1,2,3], [1,2,3] has length 3.\n- i = 3: [1,2,3,2], [1,2,2] has length 3.", + "Example 2:\nInput: obstacles = [2,2,1]\nOutput: [1,2,1]\nExplanation: The longest valid obstacle course at each position is:\n- i = 0: [2], [2] has length 1.\n- i = 1: [2,2], [2,2] has length 2.\n- i = 2: [2,2,1], [1] has length 1.", + "Example 3:\nInput: obstacles = [3,1,5,6,4,2]\nOutput: [1,1,2,3,2,2]\nExplanation: The longest valid obstacle course at each position is:\n- i = 0: [3], [3] has length 1.\n- i = 1: [3,1], [1] has length 1.\n- i = 2: [3,1,5], [3,5] has length 2. [1,5] is also valid.\n- i = 3: [3,1,5,6], [3,5,6] has length 3. [1,5,6] is also valid.\n- i = 4: [3,1,5,6,4], [3,4] has length 2. [1,4] is also valid.\n- i = 5: [3,1,5,6,4,2], [1,2] has length 2." + ], + "constraints": "Constraints:\n\nn == obstacles.length\n1 <= n <= 10^5\n1 <= obstacles[i] <= 10^7", + "tags": [ + "Array", + "Binary Search", + "Binary Indexed Tree" + ], + "title-slug": "find-the-longest-valid-obstacle-course-at-each-position" + }, + { + "leetcode-id": 1967, + "title": "Number of Strings That Appear as Substrings in Word", + "difficulty": 1, + "description": "Given an array of strings patterns and a string word, return the number of strings in patterns that exist as a substring in word.\nA substring is a contiguous sequence of characters within a string.", + "examples": [ + "Example 1:\nInput: patterns = [\"a\",\"abc\",\"bc\",\"d\"], word = \"abc\"\nOutput: 3\nExplanation:\n- \"a\" appears as a substring in \"abc\".\n- \"abc\" appears as a substring in \"abc\".\n- \"bc\" appears as a substring in \"abc\".\n- \"d\" does not appear as a substring in \"abc\".\n3 of the strings in patterns appear as a substring in word.", + "Example 2:\nInput: patterns = [\"a\",\"b\",\"c\"], word = \"aaaaabbbbb\"\nOutput: 2\nExplanation:\n- \"a\" appears as a substring in \"aaaaabbbbb\".\n- \"b\" appears as a substring in \"aaaaabbbbb\".\n- \"c\" does not appear as a substring in \"aaaaabbbbb\".\n2 of the strings in patterns appear as a substring in word.", + "Example 3:\nInput: patterns = [\"a\",\"a\",\"a\"], word = \"ab\"\nOutput: 3\nExplanation: Each of the patterns appears as a substring in word \"ab\"." + ], + "constraints": "Constraints:\n\n1 <= patterns.length <= 100\n1 <= patterns[i].length <= 100\n1 <= word.length <= 100\npatterns[i] and word consist of lowercase English letters.", + "tags": [ + "String" + ], + "title-slug": "number-of-strings-that-appear-as-substrings-in-word" + }, + { + "leetcode-id": 1968, + "title": "Array With Elements Not Equal to Average of Neighbors", + "difficulty": 2, + "description": "You are given a 0-indexed array nums of distinct integers. You want to rearrange the elements in the array such that every element in the rearranged array is not equal to the average of its neighbors.\nMore formally, the rearranged array should have the property such that for every i in the range 1 <= i < nums.length - 1, (nums[i-1] + nums[i+1]) / 2 is not equal to nums[i].\nReturn any rearrangement of nums that meets the requirements.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4,5]\nOutput: [1,2,4,5,3]\nExplanation:\nWhen i=1, nums[i] = 2, and the average of its neighbors is (1+4) / 2 = 2.5.\nWhen i=2, nums[i] = 4, and the average of its neighbors is (2+5) / 2 = 3.5.\nWhen i=3, nums[i] = 5, and the average of its neighbors is (4+3) / 2 = 3.5.", + "Example 2:\nInput: nums = [6,2,0,9,7]\nOutput: [9,7,6,2,0]\nExplanation:\nWhen i=1, nums[i] = 7, and the average of its neighbors is (9+6) / 2 = 7.5.\nWhen i=2, nums[i] = 6, and the average of its neighbors is (7+2) / 2 = 4.5.\nWhen i=3, nums[i] = 2, and the average of its neighbors is (6+0) / 2 = 3." + ], + "constraints": "Constraints:\n\n3 <= nums.length <= 10^5\n0 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Greedy", + "Sorting" + ], + "title-slug": "array-with-elements-not-equal-to-average-of-neighbors" + }, + { + "leetcode-id": 1969, + "title": "Minimum Non-Zero Product of the Array Elements", + "difficulty": 2, + "description": "You are given a positive integer p. Consider an array nums (1-indexed) that consists of the integers in the inclusive range [1, 2^p - 1] in their binary representations. You are allowed to do the following operation any number of times:\n\nChoose two elements x and y from nums.\nChoose a bit in x and swap it with its corresponding bit in y. Corresponding bit refers to the bit that is in the same position in the other integer.\n\nFor example, if x = 1101 and y = 0011, after swapping the 2^nd bit from the right, we have x = 1111 and y = 0001.\nFind the minimum non-zero product of nums after performing the above operation any number of times. Return this product modulo 10^9 + 7.\nNote: The answer should be the minimum product before the modulo operation is done.", + "examples": [ + "Example 1:\nInput: p = 1\nOutput: 1\nExplanation: nums = [1].\nThere is only one element, so the product equals that element.", + "Example 2:\nInput: p = 2\nOutput: 6\nExplanation: nums = [01, 10, 11].\nAny swap would either make the product 0 or stay the same.\nThus, the array product of 1 * 2 * 3 = 6 is already minimized.", + "Example 3:\nInput: p = 3\nOutput: 1512\nExplanation: nums = [001, 010, 011, 100, 101, 110, 111]\n- In the first operation we can swap the leftmost bit of the second and fifth elements.\n - The resulting array is [001, 110, 011, 100, 001, 110, 111].\n- In the second operation we can swap the middle bit of the third and fourth elements.\n - The resulting array is [001, 110, 001, 110, 001, 110, 111].\nThe array product is 1 * 6 * 1 * 6 * 1 * 6 * 7 = 1512, which is the minimum possible product." + ], + "constraints": "Constraints:\n\n1 <= p <= 60", + "tags": [ + "Math", + "Greedy", + "Recursion" + ], + "title-slug": "minimum-non-zero-product-of-the-array-elements" + }, + { + "leetcode-id": 1970, + "title": "Last Day Where You Can Still Cross", + "difficulty": 3, + "description": "There is a 1-based binary matrix where 0 represents land and 1 represents water. You are given integers row and col representing the number of rows and columns in the matrix, respectively.\nInitially on day 0, the entire matrix is land. However, each day a new cell becomes flooded with water. You are given a 1-based 2D array cells, where cells[i] = [ri, ci] represents that on the i^th day, the cell on the ri^th row and ci^th column (1-based coordinates) will be covered with water (i.e., changed to 1).\nYou want to find the last day that it is possible to walk from the top to the bottom by only walking on land cells. You can start from any cell in the top row and end at any cell in the bottom row. You can only travel in the four cardinal directions (left, right, up, and down).\nReturn the last day where it is possible to walk from the top to the bottom by only walking on land cells.", + "examples": [ + "Example 1:\nInput: row = 2, col = 2, cells = [[1,1],[2,1],[1,2],[2,2]]\nOutput: 2\nExplanation: The above image depicts how the matrix changes each day starting from day 0.\nThe last day where it is possible to cross from top to bottom is on day 2.", + "Example 2:\nInput: row = 2, col = 2, cells = [[1,1],[1,2],[2,1],[2,2]]\nOutput: 1\nExplanation: The above image depicts how the matrix changes each day starting from day 0.\nThe last day where it is possible to cross from top to bottom is on day 1.", + "Example 3:\nInput: row = 3, col = 3, cells = [[1,2],[2,1],[3,3],[2,2],[1,1],[1,3],[2,3],[3,2],[3,1]]\nOutput: 3\nExplanation: The above image depicts how the matrix changes each day starting from day 0.\nThe last day where it is possible to cross from top to bottom is on day 3." + ], + "constraints": "Constraints:\n\n2 <= row, col <= 2 * 10^4\n4 <= row * col <= 2 * 10^4\ncells.length == row * col\n1 <= ri <= row\n1 <= ci <= col\nAll the values of cells are unique.", + "tags": [ + "Array", + "Binary Search", + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Matrix" + ], + "title-slug": "last-day-where-you-can-still-cross" + }, + { + "leetcode-id": 1971, + "title": "Find if Path Exists in Graph", + "difficulty": 1, + "description": "There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-directional edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself.\nYou want to determine if there is a valid path that exists from vertex source to vertex destination.\nGiven edges and the integers n, source, and destination, return true if there is a valid path from source to destination, or false otherwise.", + "examples": [ + "Example 1:\nInput: n = 3, edges = [[0,1],[1,2],[2,0]], source = 0, destination = 2\nOutput: true\nExplanation: There are two paths from vertex 0 to vertex 2:\n- 0 \u2192 1 \u2192 2\n- 0 \u2192 2", + "Example 2:\nInput: n = 6, edges = [[0,1],[0,2],[3,5],[5,4],[4,3]], source = 0, destination = 5\nOutput: false\nExplanation: There is no path from vertex 0 to vertex 5." + ], + "constraints": "Constraints:\n\n1 <= n <= 2 * 10^5\n0 <= edges.length <= 2 * 10^5\nedges[i].length == 2\n0 <= ui, vi <= n - 1\nui != vi\n0 <= source, destination <= n - 1\nThere are no duplicate edges.\nThere are no self edges.", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Graph" + ], + "title-slug": "find-if-path-exists-in-graph" + }, + { + "leetcode-id": 1974, + "title": "Minimum Time to Type Word Using Special Typewriter", + "difficulty": 1, + "description": "There is a special typewriter with lowercase English letters 'a' to 'z' arranged in a circle with a pointer. A character can only be typed if the pointer is pointing to that character. The pointer is initially pointing to the character 'a'.\n\nEach second, you may perform one of the following operations:\n\nMove the pointer one character counterclockwise or clockwise.\nType the character the pointer is currently on.\n\nGiven a string word, return the minimum number of seconds to type out the characters in word.", + "examples": [ + "Example 1:\nInput: word = \"abc\"\nOutput: 5\nExplanation: \nThe characters are printed as follows:\n- Type the character 'a' in 1 second since the pointer is initially on 'a'.\n- Move the pointer clockwise to 'b' in 1 second.\n- Type the character 'b' in 1 second.\n- Move the pointer clockwise to 'c' in 1 second.\n- Type the character 'c' in 1 second.", + "Example 2:\nInput: word = \"bza\"\nOutput: 7\nExplanation:\nThe characters are printed as follows:\n- Move the pointer clockwise to 'b' in 1 second.\n- Type the character 'b' in 1 second.\n- Move the pointer counterclockwise to 'z' in 2 seconds.\n- Type the character 'z' in 1 second.\n- Move the pointer clockwise to 'a' in 1 second.\n- Type the character 'a' in 1 second.", + "Example 3:\nInput: word = \"zjpc\"\nOutput: 34\nExplanation:\nThe characters are printed as follows:\n- Move the pointer counterclockwise to 'z' in 1 second.\n- Type the character 'z' in 1 second.\n- Move the pointer clockwise to 'j' in 10 seconds.\n- Type the character 'j' in 1 second.\n- Move the pointer clockwise to 'p' in 6 seconds.\n- Type the character 'p' in 1 second.\n- Move the pointer counterclockwise to 'c' in 13 seconds.\n- Type the character 'c' in 1 second." + ], + "constraints": "Constraints:\n\n1 <= word.length <= 100\nword consists of lowercase English letters.", + "tags": [ + "String", + "Greedy" + ], + "title-slug": "minimum-time-to-type-word-using-special-typewriter" + }, + { + "leetcode-id": 1975, + "title": "Maximum Matrix Sum", + "difficulty": 2, + "description": "You are given an n x n integer matrix. You can do the following operation any number of times:\n\nChoose any two adjacent elements of matrix and multiply each of them by -1.\n\nTwo elements are considered adjacent if and only if they share a border.\nYour goal is to maximize the summation of the matrix's elements. Return the maximum sum of the matrix's elements using the operation mentioned above.", + "examples": [ + "Example 1:\nInput: matrix = [[1,-1],[-1,1]]\nOutput: 4\nExplanation: We can follow the following steps to reach sum equals 4:\n- Multiply the 2 elements in the first row by -1.\n- Multiply the 2 elements in the first column by -1.", + "Example 2:\nInput: matrix = [[1,2,3],[-1,-2,-3],[1,2,3]]\nOutput: 16\nExplanation: We can follow the following step to reach sum equals 16:\n- Multiply the 2 last elements in the second row by -1." + ], + "constraints": "Constraints:\n\nn == matrix.length == matrix[i].length\n2 <= n <= 250\n-10^5 <= matrix[i][j] <= 10^5", + "tags": [ + "Array", + "Greedy", + "Matrix" + ], + "title-slug": "maximum-matrix-sum" + }, + { + "leetcode-id": 1976, + "title": "Number of Ways to Arrive at Destination", + "difficulty": 2, + "description": "You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.\nYou are given an integer n and a 2D integer array roads where roads[i] = [ui, vi, timei] means that there is a road between intersections ui and vi that takes timei minutes to travel. You want to know in how many ways you can travel from intersection 0 to intersection n - 1 in the shortest amount of time.\nReturn the number of ways you can arrive at your destination in the shortest amount of time. Since the answer may be large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: n = 7, roads = [[0,6,7],[0,1,2],[1,2,3],[1,3,3],[6,3,3],[3,5,1],[6,5,1],[2,5,1],[0,4,5],[4,6,2]]\nOutput: 4\nExplanation: The shortest amount of time it takes to go from intersection 0 to intersection 6 is 7 minutes.\nThe four ways to get there in 7 minutes are:\n- 0 \u279d 6\n- 0 \u279d 4 \u279d 6\n- 0 \u279d 1 \u279d 2 \u279d 5 \u279d 6\n- 0 \u279d 1 \u279d 3 \u279d 5 \u279d 6", + "Example 2:\nInput: n = 2, roads = [[1,0,10]]\nOutput: 1\nExplanation: There is only one way to go from intersection 0 to intersection 1, and it takes 10 minutes." + ], + "constraints": "Constraints:\n\n1 <= n <= 200\nn - 1 <= roads.length <= n * (n - 1) / 2\nroads[i].length == 3\n0 <= ui, vi <= n - 1\n1 <= timei <= 10^9\nui != vi\nThere is at most one road connecting any two intersections.\nYou can reach any intersection from any other intersection.", + "tags": [ + "Dynamic Programming", + "Graph", + "Topological Sort", + "Shortest Path" + ], + "title-slug": "number-of-ways-to-arrive-at-destination" + }, + { + "leetcode-id": 1977, + "title": "Number of Ways to Separate Numbers", + "difficulty": 3, + "description": "You wrote down many positive integers in a string called num. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was non-decreasing and that no integer had leading zeros.\nReturn the number of possible lists of integers that you could have written down to get the string num. Since the answer may be large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: num = \"327\"\nOutput: 2\nExplanation: You could have written down the numbers:\n3, 27\n327", + "Example 2:\nInput: num = \"094\"\nOutput: 0\nExplanation: No numbers can have leading zeros and all numbers must be positive.", + "Example 3:\nInput: num = \"0\"\nOutput: 0\nExplanation: No numbers can have leading zeros and all numbers must be positive." + ], + "constraints": "Constraints:\n\n1 <= num.length <= 3500\nnum consists of digits '0' through '9'.", + "tags": [ + "String", + "Dynamic Programming", + "Suffix Array" + ], + "title-slug": "number-of-ways-to-separate-numbers" + }, + { + "leetcode-id": 1979, + "title": "Find Greatest Common Divisor of Array", + "difficulty": 1, + "description": "Given an integer array nums, return the greatest common divisor of the smallest number and largest number in nums.\nThe greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.", + "examples": [ + "Example 1:\nInput: nums = [2,5,6,9,10]\nOutput: 2\nExplanation:\nThe smallest number in nums is 2.\nThe largest number in nums is 10.\nThe greatest common divisor of 2 and 10 is 2.", + "Example 2:\nInput: nums = [7,5,6,8,3]\nOutput: 1\nExplanation:\nThe smallest number in nums is 3.\nThe largest number in nums is 8.\nThe greatest common divisor of 3 and 8 is 1.", + "Example 3:\nInput: nums = [3,3]\nOutput: 3\nExplanation:\nThe smallest number in nums is 3.\nThe largest number in nums is 3.\nThe greatest common divisor of 3 and 3 is 3." + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 1000\n1 <= nums[i] <= 1000", + "tags": [ + "Array", + "Math", + "Number Theory" + ], + "title-slug": "find-greatest-common-divisor-of-array" + }, + { + "leetcode-id": 1980, + "title": "Find Unique Binary String", + "difficulty": 2, + "description": "Given an array of strings nums containing n unique binary strings each of length n, return a binary string of length n that does not appear in nums. If there are multiple answers, you may return any of them.", + "examples": [ + "Example 1:\nInput: nums = [\"01\",\"10\"]\nOutput: \"11\"\nExplanation: \"11\" does not appear in nums. \"00\" would also be correct.", + "Example 2:\nInput: nums = [\"00\",\"01\"]\nOutput: \"11\"\nExplanation: \"11\" does not appear in nums. \"10\" would also be correct.", + "Example 3:\nInput: nums = [\"111\",\"011\",\"001\"]\nOutput: \"101\"\nExplanation: \"101\" does not appear in nums. \"000\", \"010\", \"100\", and \"110\" would also be correct." + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 16\nnums[i].length == n\nnums[i] is either '0' or '1'.\nAll the strings of nums are unique.", + "tags": [ + "Array", + "String", + "Backtracking" + ], + "title-slug": "find-unique-binary-string" + }, + { + "leetcode-id": 1981, + "title": "Minimize the Difference Between Target and Chosen Elements", + "difficulty": 2, + "description": "You are given an m x n integer matrix mat and an integer target.\nChoose one integer from each row in the matrix such that the absolute difference between target and the sum of the chosen elements is minimized.\nReturn the minimum absolute difference.\nThe absolute difference between two numbers a and b is the absolute value of a - b.", + "examples": [ + "Example 1:\nInput: mat = [[1,2,3],[4,5,6],[7,8,9]], target = 13\nOutput: 0\nExplanation: One possible choice is to:\n- Choose 1 from the first row.\n- Choose 5 from the second row.\n- Choose 7 from the third row.\nThe sum of the chosen elements is 13, which equals the target, so the absolute difference is 0.", + "Example 2:\nInput: mat = [[1],[2],[3]], target = 100\nOutput: 94\nExplanation: The best possible choice is to:\n- Choose 1 from the first row.\n- Choose 2 from the second row.\n- Choose 3 from the third row.\nThe sum of the chosen elements is 6, and the absolute difference is 94.", + "Example 3:\nInput: mat = [[1,2,9,8,7]], target = 6\nOutput: 1\nExplanation: The best choice is to choose 7 from the first row.\nThe absolute difference is 1." + ], + "constraints": "Constraints:\n\nm == mat.length\nn == mat[i].length\n1 <= m, n <= 70\n1 <= mat[i][j] <= 70\n1 <= target <= 800", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "minimize-the-difference-between-target-and-chosen-elements" + }, + { + "leetcode-id": 1982, + "title": "Find Array Given Subset Sums", + "difficulty": 3, + "description": "You are given an integer n representing the length of an unknown array that you are trying to recover. You are also given an array sums containing the values of all 2^n subset sums of the unknown array (in no particular order).\nReturn the array ans of length n representing the unknown array. If multiple answers exist, return any of them.\nAn array sub is a subset of an array arr if sub can be obtained from arr by deleting some (possibly zero or all) elements of arr. The sum of the elements in sub is one possible subset sum of arr. The sum of an empty array is considered to be 0.\nNote: Test cases are generated such that there will always be at least one correct answer.", + "examples": [ + "Example 1:\nInput: n = 3, sums = [-3,-2,-1,0,0,1,2,3]\nOutput: [1,2,-3]\nExplanation: [1,2,-3] is able to achieve the given subset sums:\n- []: sum is 0\n- [1]: sum is 1\n- [2]: sum is 2\n- [1,2]: sum is 3\n- [-3]: sum is -3\n- [1,-3]: sum is -2\n- [2,-3]: sum is -1\n- [1,2,-3]: sum is 0\nNote that any permutation of [1,2,-3] and also any permutation of [-1,-2,3] will also be accepted.", + "Example 2:\nInput: n = 2, sums = [0,0,0,0]\nOutput: [0,0]\nExplanation: The only correct answer is [0,0].", + "Example 3:\nInput: n = 4, sums = [0,0,5,5,4,-1,4,9,9,-1,4,3,4,8,3,8]\nOutput: [0,-1,4,5]\nExplanation: [0,-1,4,5] is able to achieve the given subset sums." + ], + "constraints": "Constraints:\n\n1 <= n <= 15\nsums.length == 2^n\n-10^4 <= sums[i] <= 10^4", + "tags": [ + "Array", + "Divide and Conquer" + ], + "title-slug": "find-array-given-subset-sums" + }, + { + "leetcode-id": 1984, + "title": "Minimum Difference Between Highest and Lowest of K Scores", + "difficulty": 1, + "description": "You are given a 0-indexed integer array nums, where nums[i] represents the score of the i^th student. You are also given an integer k.\nPick the scores of any k students from the array so that the difference between the highest and the lowest of the k scores is minimized.\nReturn the minimum possible difference.", + "examples": [ + "Example 1:\nInput: nums = [90], k = 1\nOutput: 0\nExplanation: There is one way to pick score(s) of one student:\n- [90]. The difference between the highest and lowest score is 90 - 90 = 0.\nThe minimum possible difference is 0.", + "Example 2:\nInput: nums = [9,4,1,7], k = 2\nOutput: 2\nExplanation: There are six ways to pick score(s) of two students:\n- [9,4,1,7]. The difference between the highest and lowest score is 9 - 4 = 5.\n- [9,4,1,7]. The difference between the highest and lowest score is 9 - 1 = 8.\n- [9,4,1,7]. The difference between the highest and lowest score is 9 - 7 = 2.\n- [9,4,1,7]. The difference between the highest and lowest score is 4 - 1 = 3.\n- [9,4,1,7]. The difference between the highest and lowest score is 7 - 4 = 3.\n- [9,4,1,7]. The difference between the highest and lowest score is 7 - 1 = 6.\nThe minimum possible difference is 2." + ], + "constraints": "Constraints:\n\n1 <= k <= nums.length <= 1000\n0 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Sliding Window", + "Sorting" + ], + "title-slug": "minimum-difference-between-highest-and-lowest-of-k-scores" + }, + { + "leetcode-id": 1985, + "title": "Find the Kth Largest Integer in the Array", + "difficulty": 2, + "description": "You are given an array of strings nums and an integer k. Each string in nums represents an integer without leading zeros.\nReturn the string that represents the k^th largest integer in nums.\nNote: Duplicate numbers should be counted distinctly. For example, if nums is [\"1\",\"2\",\"2\"], \"2\" is the first largest integer, \"2\" is the second-largest integer, and \"1\" is the third-largest integer.", + "examples": [ + "Example 1:\nInput: nums = [\"3\",\"6\",\"7\",\"10\"], k = 4\nOutput: \"3\"\nExplanation:\nThe numbers in nums sorted in non-decreasing order are [\"3\",\"6\",\"7\",\"10\"].\nThe 4^th largest integer in nums is \"3\".", + "Example 2:\nInput: nums = [\"2\",\"21\",\"12\",\"1\"], k = 3\nOutput: \"2\"\nExplanation:\nThe numbers in nums sorted in non-decreasing order are [\"1\",\"2\",\"12\",\"21\"].\nThe 3^rd largest integer in nums is \"2\".", + "Example 3:\nInput: nums = [\"0\",\"0\"], k = 2\nOutput: \"0\"\nExplanation:\nThe numbers in nums sorted in non-decreasing order are [\"0\",\"0\"].\nThe 2^nd largest integer in nums is \"0\"." + ], + "constraints": "Constraints:\n\n1 <= k <= nums.length <= 10^4\n1 <= nums[i].length <= 100\nnums[i] consists of only digits.\nnums[i] will not have any leading zeros.", + "tags": [ + "Array", + "String", + "Divide and Conquer", + "Sorting", + "Heap (Priority Queue)", + "Quickselect" + ], + "title-slug": "find-the-kth-largest-integer-in-the-array" + }, + { + "leetcode-id": 1986, + "title": "Minimum Number of Work Sessions to Finish the Tasks", + "difficulty": 2, + "description": "There are n tasks assigned to you. The task times are represented as an integer array tasks of length n, where the i^th task takes tasks[i] hours to finish. A work session is when you work for at most sessionTime consecutive hours and then take a break.\nYou should finish the given tasks in a way that satisfies the following conditions:\n\nIf you start a task in a work session, you must complete it in the same work session.\nYou can start a new task immediately after finishing the previous one.\nYou may complete the tasks in any order.\n\nGiven tasks and sessionTime, return the minimum number of work sessions needed to finish all the tasks following the conditions above.\nThe tests are generated such that sessionTime is greater than or equal to the maximum element in tasks[i].", + "examples": [ + "Example 1:\nInput: tasks = [1,2,3], sessionTime = 3\nOutput: 2\nExplanation: You can finish the tasks in two work sessions.\n- First work session: finish the first and the second tasks in 1 + 2 = 3 hours.\n- Second work session: finish the third task in 3 hours.", + "Example 2:\nInput: tasks = [3,1,3,1,1], sessionTime = 8\nOutput: 2\nExplanation: You can finish the tasks in two work sessions.\n- First work session: finish all the tasks except the last one in 3 + 1 + 3 + 1 = 8 hours.\n- Second work session: finish the last task in 1 hour.", + "Example 3:\nInput: tasks = [1,2,3,4,5], sessionTime = 15\nOutput: 1\nExplanation: You can finish all the tasks in one work session." + ], + "constraints": "Constraints:\n\nn == tasks.length\n1 <= n <= 14\n1 <= tasks[i] <= 10\nmax(tasks[i]) <= sessionTime <= 15", + "tags": [ + "Array", + "Dynamic Programming", + "Backtracking", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "minimum-number-of-work-sessions-to-finish-the-tasks" + }, + { + "leetcode-id": 1987, + "title": "Number of Unique Good Subsequences", + "difficulty": 3, + "description": "You are given a binary string binary. A subsequence of binary is considered good if it is not empty and has no leading zeros (with the exception of \"0\").\nFind the number of unique good subsequences of binary.\n\nFor example, if binary = \"001\", then all the good subsequences are [\"0\", \"0\", \"1\"], so the unique good subsequences are \"0\" and \"1\". Note that subsequences \"00\", \"01\", and \"001\" are not good because they have leading zeros.\n\nReturn the number of unique good subsequences of binary. Since the answer may be very large, return it modulo 10^9 + 7.\nA subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.", + "examples": [ + "Example 1:\nInput: binary = \"001\"\nOutput: 2\nExplanation: The good subsequences of binary are [\"0\", \"0\", \"1\"].\nThe unique good subsequences are \"0\" and \"1\".", + "Example 2:\nInput: binary = \"11\"\nOutput: 2\nExplanation: The good subsequences of binary are [\"1\", \"1\", \"11\"].\nThe unique good subsequences are \"1\" and \"11\".", + "Example 3:\nInput: binary = \"101\"\nOutput: 5\nExplanation: The good subsequences of binary are [\"1\", \"0\", \"1\", \"10\", \"11\", \"101\"]. \nThe unique good subsequences are \"0\", \"1\", \"10\", \"11\", and \"101\"." + ], + "constraints": "Constraints:\n\n1 <= binary.length <= 10^5\nbinary consists of only '0's and '1's.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "number-of-unique-good-subsequences" + }, + { + "leetcode-id": 1991, + "title": "Find the Middle Index in Array", + "difficulty": 1, + "description": "Given a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones).\nA middleIndex is an index where nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + ... + nums[nums.length-1].\nIf middleIndex == 0, the left side sum is considered to be 0. Similarly, if middleIndex == nums.length - 1, the right side sum is considered to be 0.\nReturn the leftmost middleIndex that satisfies the condition, or -1 if there is no such index.", + "examples": [ + "Example 1:\nInput: nums = [2,3,-1,8,4]\nOutput: 3\nExplanation: The sum of the numbers before index 3 is: 2 + 3 + -1 = 4\nThe sum of the numbers after index 3 is: 4 = 4", + "Example 2:\nInput: nums = [1,-1,4]\nOutput: 2\nExplanation: The sum of the numbers before index 2 is: 1 + -1 = 0\nThe sum of the numbers after index 2 is: 0", + "Example 3:\nInput: nums = [2,5]\nOutput: -1\nExplanation: There is no valid middleIndex." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n-1000 <= nums[i] <= 1000\n\n\u00a0\nNote: This question is the same as\u00a0724:\u00a0https://leetcode.com/problems/find-pivot-index/", + "tags": [ + "Array", + "Prefix Sum" + ], + "title-slug": "find-the-middle-index-in-array" + }, + { + "leetcode-id": 1992, + "title": "Find All Groups of Farmland", + "difficulty": 2, + "description": "You are given a 0-indexed m x n binary matrix land where a 0 represents a hectare of forested land and a 1 represents a hectare of farmland.\nTo keep the land organized, there are designated rectangular areas of hectares that consist entirely of farmland. These rectangular areas are called groups. No two groups are adjacent, meaning farmland in one group is not four-directionally adjacent to another farmland in a different group.\nland can be represented by a coordinate system where the top left corner of land is (0, 0) and the bottom right corner of land is (m-1, n-1). Find the coordinates of the top left and bottom right corner of each group of farmland. A group of farmland with a top left corner at (r1, c1) and a bottom right corner at (r2, c2) is represented by the 4-length array [r1, c1, r2, c2].\nReturn a 2D array containing the 4-length arrays described above for each group of farmland in land. If there are no groups of farmland, return an empty array. You may return the answer in any order.", + "examples": [ + "Example 1:\nInput: land = [[1,0,0],[0,1,1],[0,1,1]]\nOutput: [[0,0,0,0],[1,1,2,2]]\nExplanation:\nThe first group has a top left corner at land[0][0] and a bottom right corner at land[0][0].\nThe second group has a top left corner at land[1][1] and a bottom right corner at land[2][2].", + "Example 2:\nInput: land = [[1,1],[1,1]]\nOutput: [[0,0,1,1]]\nExplanation:\nThe first group has a top left corner at land[0][0] and a bottom right corner at land[1][1].", + "Example 3:\nInput: land = [[0]]\nOutput: []\nExplanation:\nThere are no groups of farmland." + ], + "constraints": "Constraints:\n\nm == land.length\nn == land[i].length\n1 <= m, n <= 300\nland consists of only 0's and 1's.\nGroups of farmland are rectangular in shape.", + "tags": [ + "Array", + "Depth-First Search", + "Breadth-First Search", + "Matrix" + ], + "title-slug": "find-all-groups-of-farmland" + }, + { + "leetcode-id": 1993, + "title": "Operations on Tree", + "difficulty": 2, + "description": "You are given a tree with n nodes numbered from 0 to n - 1 in the form of a parent array parent where parent[i] is the parent of the i^th node. The root of the tree is node 0, so parent[0] = -1 since it has no parent. You want to design a data structure that allows users to lock, unlock, and upgrade nodes in the tree.\nThe data structure should support the following functions:\n\nLock: Locks the given node for the given user and prevents other users from locking the same node. You may only lock a node using this function if the node is unlocked.\nUnlock: Unlocks the given node for the given user. You may only unlock a node using this function if it is currently locked by the same user.\nUpgrade: Locks the given node for the given user and unlocks all of its descendants regardless of who locked it. You may only upgrade a node if all 3 conditions are true:\n\t\nThe node is unlocked,\nIt has at least one locked descendant (by any user), and\nIt does not have any locked ancestors.\n\n\n\nImplement the LockingTree class:\n\nLockingTree(int[] parent) initializes the data structure with the parent array.\nlock(int num, int user) returns true if it is possible for the user with id user to lock the node num, or false otherwise. If it is possible, the node num will become locked by the user with id user.\nunlock(int num, int user) returns true if it is possible for the user with id user to unlock the node num, or false otherwise. If it is possible, the node num will become unlocked.\nupgrade(int num, int user) returns true if it is possible for the user with id user to upgrade the node num, or false otherwise. If it is possible, the node num will be upgraded.", + "examples": [ + "Example 1:\nInput\n[\"LockingTree\", \"lock\", \"unlock\", \"unlock\", \"lock\", \"upgrade\", \"lock\"]\n[[[-1, 0, 0, 1, 1, 2, 2]], [2, 2], [2, 3], [2, 2], [4, 5], [0, 1], [0, 1]]\nOutput\n[null, true, false, true, true, true, false]\n\nExplanation\nLockingTree lockingTree = new LockingTree([-1, 0, 0, 1, 1, 2, 2]);\nlockingTree.lock(2, 2); // return true because node 2 is unlocked.\n // Node 2 will now be locked by user 2.\nlockingTree.unlock(2, 3); // return false because user 3 cannot unlock a node locked by user 2.\nlockingTree.unlock(2, 2); // return true because node 2 was previously locked by user 2.\n // Node 2 will now be unlocked.\nlockingTree.lock(4, 5); // return true because node 4 is unlocked.\n // Node 4 will now be locked by user 5.\nlockingTree.upgrade(0, 1); // return true because node 0 is unlocked and has at least one locked descendant (node 4).\n // Node 0 will now be locked by user 1 and node 4 will now be unlocked.\nlockingTree.lock(0, 1); // return false because node 0 is already locked." + ], + "constraints": "Constraints:\n\nn == parent.length\n2 <= n <= 2000\n0 <= parent[i] <= n - 1 for i != 0\nparent[0] == -1\n0 <= num <= n - 1\n1 <= user <= 10^4\nparent represents a valid tree.\nAt most 2000 calls in total will be made to lock, unlock, and upgrade.", + "tags": [ + "Array", + "Hash Table", + "Tree", + "Depth-First Search", + "Breadth-First Search", + "Design" + ], + "title-slug": "operations-on-tree" + }, + { + "leetcode-id": 1994, + "title": "The Number of Good Subsets", + "difficulty": 3, + "description": "You are given an integer array nums. We call a subset of nums good if its product can be represented as a product of one or more distinct prime numbers.\n\nFor example, if nums = [1, 2, 3, 4]:\n\n\t\n[2, 3], [1, 2, 3], and [1, 3] are good subsets with products 6 = 2*3, 6 = 2*3, and 3 = 3 respectively.\n[1, 4] and [4] are not good subsets with products 4 = 2*2 and 4 = 2*2 respectively.\n\n\n\nReturn the number of different good subsets in nums modulo 10^9 + 7.\nA subset of nums is any array that can be obtained by deleting some (possibly none or all) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,4]\nOutput: 6\nExplanation: The good subsets are:\n- [1,2]: product is 2, which is the product of distinct prime 2.\n- [1,2,3]: product is 6, which is the product of distinct primes 2 and 3.\n- [1,3]: product is 3, which is the product of distinct prime 3.\n- [2]: product is 2, which is the product of distinct prime 2.\n- [2,3]: product is 6, which is the product of distinct primes 2 and 3.\n- [3]: product is 3, which is the product of distinct prime 3.", + "Example 2:\nInput: nums = [4,2,3,15]\nOutput: 5\nExplanation: The good subsets are:\n- [2]: product is 2, which is the product of distinct prime 2.\n- [2,3]: product is 6, which is the product of distinct primes 2 and 3.\n- [2,15]: product is 30, which is the product of distinct primes 2, 3, and 5.\n- [3]: product is 3, which is the product of distinct prime 3.\n- [15]: product is 15, which is the product of distinct primes 3 and 5." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 30", + "tags": [ + "Array", + "Math", + "Dynamic Programming", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "the-number-of-good-subsets" + }, + { + "leetcode-id": 1995, + "title": "Count Special Quadruplets", + "difficulty": 1, + "description": "Given a 0-indexed integer array nums, return the number of distinct quadruplets (a, b, c, d) such that:\n\nnums[a] + nums[b] + nums[c] == nums[d], and\na < b < c < d", + "examples": [ + "Example 1:\nInput: nums = [1,2,3,6]\nOutput: 1\nExplanation: The only quadruplet that satisfies the requirement is (0, 1, 2, 3) because 1 + 2 + 3 == 6.", + "Example 2:\nInput: nums = [3,3,6,4,5]\nOutput: 0\nExplanation: There are no such quadruplets in [3,3,6,4,5].", + "Example 3:\nInput: nums = [1,1,1,3,5]\nOutput: 4\nExplanation: The 4 quadruplets that satisfy the requirement are:\n- (0, 1, 2, 3): 1 + 1 + 1 == 3\n- (0, 1, 3, 4): 1 + 1 + 3 == 5\n- (0, 2, 3, 4): 1 + 1 + 3 == 5\n- (1, 2, 3, 4): 1 + 1 + 3 == 5" + ], + "constraints": "Constraints:\n\n4 <= nums.length <= 50\n1 <= nums[i] <= 100", + "tags": [ + "Array", + "Enumeration" + ], + "title-slug": "count-special-quadruplets" + }, + { + "leetcode-id": 1996, + "title": "The Number of Weak Characters in the Game", + "difficulty": 2, + "description": "You are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D integer array properties where properties[i] = [attacki, defensei] represents the properties of the i^th character in the game.\nA character is said to be weak if any other character has both attack and defense levels strictly greater than this character's attack and defense levels. More formally, a character i is said to be weak if there exists another character j where attackj > attacki and defensej > defensei.\nReturn the number of weak characters.", + "examples": [ + "Example 1:\nInput: properties = [[5,5],[6,3],[3,6]]\nOutput: 0\nExplanation: No character has strictly greater attack and defense than the other.", + "Example 2:\nInput: properties = [[2,2],[3,3]]\nOutput: 1\nExplanation: The first character is weak because the second character has a strictly greater attack and defense.", + "Example 3:\nInput: properties = [[1,5],[10,4],[4,3]]\nOutput: 1\nExplanation: The third character is weak because the second character has a strictly greater attack and defense." + ], + "constraints": "Constraints:\n\n2 <= properties.length <= 10^5\nproperties[i].length == 2\n1 <= attacki, defensei <= 10^5", + "tags": [ + "Array", + "Stack", + "Greedy", + "Sorting", + "Monotonic Stack" + ], + "title-slug": "the-number-of-weak-characters-in-the-game" + }, + { + "leetcode-id": 1997, + "title": "First Day Where You Have Been in All the Rooms", + "difficulty": 2, + "description": "There are n rooms you need to visit, labeled from 0 to n - 1. Each day is labeled, starting from 0. You will go in and visit one room a day.\nInitially on day 0, you visit room 0. The order you visit the rooms for the coming days is determined by the following rules and a given 0-indexed array nextVisit of length n:\n\nAssuming that on a day, you visit room i,\nif you have been in room i an odd number of times (including the current visit), on the next day you will visit a room with a lower or equal room number specified by nextVisit[i] where 0 <= nextVisit[i] <= i;\nif you have been in room i an even number of times (including the current visit), on the next day you will visit room (i + 1) mod n.\n\nReturn the label of the first day where you have been in all the rooms. It can be shown that such a day exists. Since the answer may be very large, return it modulo 10^9 + 7.", + "examples": [ + "Example 1:\nInput: nextVisit = [0,0]\nOutput: 2\nExplanation:\n- On day 0, you visit room 0. The total times you have been in room 0 is 1, which is odd.\n\u00a0 On the next day you will visit room nextVisit[0] = 0\n- On day 1, you visit room 0, The total times you have been in room 0 is 2, which is even.\n\u00a0 On the next day you will visit room (0 + 1) mod 2 = 1\n- On day 2, you visit room 1. This is the first day where you have been in all the rooms.", + "Example 2:\nInput: nextVisit = [0,0,2]\nOutput: 6\nExplanation:\nYour room visiting order for each day is: [0,0,1,0,0,1,2,...].\nDay 6 is the first day where you have been in all the rooms.", + "Example 3:\nInput: nextVisit = [0,1,2,0]\nOutput: 6\nExplanation:\nYour room visiting order for each day is: [0,0,1,1,2,2,3,...].\nDay 6 is the first day where you have been in all the rooms." + ], + "constraints": "Constraints:\n\nn == nextVisit.length\n2 <= n <= 10^5\n0 <= nextVisit[i] <= i", + "tags": [ + "Array", + "Dynamic Programming" + ], + "title-slug": "first-day-where-you-have-been-in-all-the-rooms" + }, + { + "leetcode-id": 1998, + "title": "GCD Sort of an Array", + "difficulty": 3, + "description": "You are given an integer array nums, and you can perform the following operation any number of times on nums:\n\nSwap the positions of two elements nums[i] and nums[j] if gcd(nums[i], nums[j]) > 1 where gcd(nums[i], nums[j]) is the greatest common divisor of nums[i] and nums[j].\n\nReturn true if it is possible to sort nums in non-decreasing order using the above swap method, or false otherwise.", + "examples": [ + "Example 1:\nInput: nums = [7,21,3]\nOutput: true\nExplanation: We can sort [7,21,3] by performing the following operations:\n- Swap 7 and 21 because gcd(7,21) = 7. nums = [21,7,3]\n- Swap 21 and 3 because gcd(21,3) = 3. nums = [3,7,21]", + "Example 2:\nInput: nums = [5,2,6,2]\nOutput: false\nExplanation: It is impossible to sort the array because 5 cannot be swapped with any other element.", + "Example 3:\nInput: nums = [10,5,9,3,15]\nOutput: true\nWe can sort [10,5,9,3,15] by performing the following operations:\n- Swap 10 and 15 because gcd(10,15) = 5. nums = [15,5,9,3,10]\n- Swap 15 and 3 because gcd(15,3) = 3. nums = [3,5,9,15,10]\n- Swap 10 and 15 because gcd(10,15) = 5. nums = [3,5,9,10,15]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 3 * 10^4\n2 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Math", + "Union Find", + "Sorting", + "Number Theory" + ], + "title-slug": "gcd-sort-of-an-array" + }, + { + "leetcode-id": 2000, + "title": "Reverse Prefix of Word", + "difficulty": 1, + "description": "Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do nothing.\n\nFor example, if word = \"abcdefd\" and ch = \"d\", then you should reverse the segment that starts at 0 and ends at 3 (inclusive). The resulting string will be \"dcbaefd\".\n\nReturn the resulting string.", + "examples": [ + "Example 1:\nInput: word = \"abcdefd\", ch = \"d\"\nOutput: \"dcbaefd\"\nExplanation:\u00a0The first occurrence of \"d\" is at index 3. \nReverse the part of word from 0 to 3 (inclusive), the resulting string is \"dcbaefd\".", + "Example 2:\nInput: word = \"xyxzxe\", ch = \"z\"\nOutput: \"zxyxxe\"\nExplanation:\u00a0The first and only occurrence of \"z\" is at index 3.\nReverse the part of word from 0 to 3 (inclusive), the resulting string is \"zxyxxe\".", + "Example 3:\nInput: word = \"abcd\", ch = \"z\"\nOutput: \"abcd\"\nExplanation:\u00a0\"z\" does not exist in word.\nYou should not do any reverse operation, the resulting string is \"abcd\"." + ], + "constraints": "Constraints:\n\n1 <= word.length <= 250\nword consists of lowercase English letters.\nch is a lowercase English letter.", + "tags": [ + "Two Pointers", + "String" + ], + "title-slug": "reverse-prefix-of-word" + }, + { + "leetcode-id": 2001, + "title": "Number of Pairs of Interchangeable Rectangles", + "difficulty": 2, + "description": "You are given n rectangles represented by a 0-indexed 2D integer array rectangles, where rectangles[i] = [widthi, heighti] denotes the width and height of the i^th rectangle.\nTwo rectangles i and j (i < j) are considered interchangeable if they have the same width-to-height ratio. More formally, two rectangles are interchangeable if widthi/heighti == widthj/heightj (using decimal division, not integer division).\nReturn the number of pairs of interchangeable rectangles in rectangles.", + "examples": [ + "Example 1:\nInput: rectangles = [[4,8],[3,6],[10,20],[15,30]]\nOutput: 6\nExplanation: The following are the interchangeable pairs of rectangles by index (0-indexed):\n- Rectangle 0 with rectangle 1: 4/8 == 3/6.\n- Rectangle 0 with rectangle 2: 4/8 == 10/20.\n- Rectangle 0 with rectangle 3: 4/8 == 15/30.\n- Rectangle 1 with rectangle 2: 3/6 == 10/20.\n- Rectangle 1 with rectangle 3: 3/6 == 15/30.\n- Rectangle 2 with rectangle 3: 10/20 == 15/30.", + "Example 2:\nInput: rectangles = [[4,5],[7,8]]\nOutput: 0\nExplanation: There are no interchangeable pairs of rectangles." + ], + "constraints": "Constraints:\n\nn == rectangles.length\n1 <= n <= 10^5\nrectangles[i].length == 2\n1 <= widthi, heighti <= 10^5", + "tags": [ + "Array", + "Hash Table", + "Math", + "Counting", + "Number Theory" + ], + "title-slug": "number-of-pairs-of-interchangeable-rectangles" + }, + { + "leetcode-id": 2002, + "title": "Maximum Product of the Length of Two Palindromic Subsequences", + "difficulty": 2, + "description": "Given a string s, find two disjoint palindromic subsequences of s such that the product of their lengths is maximized. The two subsequences are disjoint if they do not both pick a character at the same index.\nReturn the maximum possible product of the lengths of the two palindromic subsequences.\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters. A string is palindromic if it reads the same forward and backward.", + "examples": [ + "Example 1:\nInput: s = \"leetcodecom\"\nOutput: 9\nExplanation: An optimal solution is to choose \"ete\" for the 1^st subsequence and \"cdc\" for the 2^nd subsequence.\nThe product of their lengths is: 3 * 3 = 9.", + "Example 2:\nInput: s = \"bb\"\nOutput: 1\nExplanation: An optimal solution is to choose \"b\" (the first character) for the 1^st subsequence and \"b\" (the second character) for the 2^nd subsequence.\nThe product of their lengths is: 1 * 1 = 1.", + "Example 3:\nInput: s = \"accbcaxxcxx\"\nOutput: 25\nExplanation: An optimal solution is to choose \"accca\" for the 1^st subsequence and \"xxcxx\" for the 2^nd subsequence.\nThe product of their lengths is: 5 * 5 = 25." + ], + "constraints": "Constraints:\n\n2 <= s.length <= 12\ns consists of lowercase English letters only.", + "tags": [ + "String", + "Dynamic Programming", + "Backtracking", + "Bit Manipulation", + "Bitmask" + ], + "title-slug": "maximum-product-of-the-length-of-two-palindromic-subsequences" + }, + { + "leetcode-id": 2003, + "title": "Smallest Missing Genetic Value in Each Subtree", + "difficulty": 3, + "description": "There is a family tree rooted at 0 consisting of n nodes numbered 0 to n - 1. You are given a 0-indexed integer array parents, where parents[i] is the parent for node i. Since node 0 is the root, parents[0] == -1.\nThere are 10^5 genetic values, each represented by an integer in the inclusive range [1, 10^5]. You are given a 0-indexed integer array nums, where nums[i] is a distinct genetic value for node i.\nReturn an array ans of length n where ans[i] is the smallest genetic value that is missing from the subtree rooted at node i.\nThe subtree rooted at a node x contains node x and all of its descendant nodes.", + "examples": [ + "Example 1:\nInput: parents = [-1,0,0,2], nums = [1,2,3,4]\nOutput: [5,1,1,1]\nExplanation: The answer for each subtree is calculated as follows:\n- 0: The subtree contains nodes [0,1,2,3] with values [1,2,3,4]. 5 is the smallest missing value.\n- 1: The subtree contains only node 1 with value 2. 1 is the smallest missing value.\n- 2: The subtree contains nodes [2,3] with values [3,4]. 1 is the smallest missing value.\n- 3: The subtree contains only node 3 with value 4. 1 is the smallest missing value.", + "Example 2:\nInput: parents = [-1,0,1,0,3,3], nums = [5,4,6,2,1,3]\nOutput: [7,1,1,4,2,1]\nExplanation: The answer for each subtree is calculated as follows:\n- 0: The subtree contains nodes [0,1,2,3,4,5] with values [5,4,6,2,1,3]. 7 is the smallest missing value.\n- 1: The subtree contains nodes [1,2] with values [4,6]. 1 is the smallest missing value.\n- 2: The subtree contains only node 2 with value 6. 1 is the smallest missing value.\n- 3: The subtree contains nodes [3,4,5] with values [2,1,3]. 4 is the smallest missing value.\n- 4: The subtree contains only node 4 with value 1. 2 is the smallest missing value.\n- 5: The subtree contains only node 5 with value 3. 1 is the smallest missing value.", + "Example 3:\nInput: parents = [-1,2,3,0,2,4,1], nums = [2,3,4,5,6,7,8]\nOutput: [1,1,1,1,1,1,1]\nExplanation: The value 1 is missing from all the subtrees." + ], + "constraints": "Constraints:\n\nn == parents.length == nums.length\n2 <= n <= 10^5\n0 <= parents[i] <= n - 1 for i != 0\nparents[0] == -1\nparents represents a valid tree.\n1 <= nums[i] <= 10^5\nEach nums[i] is distinct.", + "tags": [ + "Dynamic Programming", + "Tree", + "Depth-First Search", + "Union Find" + ], + "title-slug": "smallest-missing-genetic-value-in-each-subtree" + }, + { + "leetcode-id": 2006, + "title": "Count Number of Pairs With Absolute Difference K", + "difficulty": 1, + "description": "Given an integer array nums and an integer k, return the number of pairs (i, j) where i < j such that |nums[i] - nums[j]| == k.\nThe value of |x| is defined as:\n\nx if x >= 0.\n-x if x < 0.", + "examples": [ + "Example 1:\nInput: nums = [1,2,2,1], k = 1\nOutput: 4\nExplanation: The pairs with an absolute difference of 1 are:\n- [1,2,2,1]\n- [1,2,2,1]\n- [1,2,2,1]\n- [1,2,2,1]", + "Example 2:\nInput: nums = [1,3], k = 3\nOutput: 0\nExplanation: There are no pairs with an absolute difference of 3.", + "Example 3:\nInput: nums = [3,2,1,5,4], k = 2\nOutput: 3\nExplanation: The pairs with an absolute difference of 2 are:\n- [3,2,1,5,4]\n- [3,2,1,5,4]\n- [3,2,1,5,4]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 200\n1 <= nums[i] <= 100\n1 <= k <= 99", + "tags": [ + "Array", + "Hash Table", + "Counting" + ], + "title-slug": "count-number-of-pairs-with-absolute-difference-k" + }, + { + "leetcode-id": 2007, + "title": "Find Original Array From Doubled Array", + "difficulty": 2, + "description": "An integer array original is transformed into a doubled array changed by appending twice the value of every element in original, and then randomly shuffling the resulting array.\nGiven an array changed, return original if changed is a doubled array. If changed is not a doubled array, return an empty array. The elements in original may be returned in any order.", + "examples": [ + "Example 1:\nInput: changed = [1,3,4,2,6,8]\nOutput: [1,3,4]\nExplanation: One possible original array could be [1,3,4]:\n- Twice the value of 1 is 1 * 2 = 2.\n- Twice the value of 3 is 3 * 2 = 6.\n- Twice the value of 4 is 4 * 2 = 8.\nOther original arrays could be [4,3,1] or [3,1,4].", + "Example 2:\nInput: changed = [6,3,0,1]\nOutput: []\nExplanation: changed is not a doubled array.", + "Example 3:\nInput: changed = [1]\nOutput: []\nExplanation: changed is not a doubled array." + ], + "constraints": "Constraints:\n\n1 <= changed.length <= 10^5\n0 <= changed[i] <= 10^5", + "tags": [ + "Array", + "Hash Table", + "Greedy", + "Sorting" + ], + "title-slug": "find-original-array-from-doubled-array" + }, + { + "leetcode-id": 2008, + "title": "Maximum Earnings From Taxi", + "difficulty": 2, + "description": "There are n points on a road you are driving your taxi on. The n points on the road are labeled from 1 to n in the direction you are going, and you want to drive from point 1 to point n to make money by picking up passengers. You cannot change the direction of the taxi.\nThe passengers are represented by a 0-indexed 2D integer array rides, where rides[i] = [starti, endi, tipi] denotes the i^th passenger requesting a ride from point starti to point endi who is willing to give a tipi dollar tip.\nFor each passenger i you pick up, you earn endi - starti + tipi dollars. You may only drive at most one passenger at a time.\nGiven n and rides, return the maximum number of dollars you can earn by picking up the passengers optimally.\nNote: You may drop off a passenger and pick up a different passenger at the same point.", + "examples": [ + "Example 1:\nInput: n = 5, rides = [[2,5,4],[1,5,1]]\nOutput: 7\nExplanation: We can pick up passenger 0 to earn 5 - 2 + 4 = 7 dollars.", + "Example 2:\nInput: n = 20, rides = [[1,6,1],[3,10,2],[10,12,3],[11,12,2],[12,15,2],[13,18,1]]\nOutput: 20\nExplanation: We will pick up the following passengers:\n- Drive passenger 1 from point 3 to point 10 for a profit of 10 - 3 + 2 = 9 dollars.\n- Drive passenger 2 from point 10 to point 12 for a profit of 12 - 10 + 3 = 5 dollars.\n- Drive passenger 5 from point 13 to point 18 for a profit of 18 - 13 + 1 = 6 dollars.\nWe earn 9 + 5 + 6 = 20 dollars in total." + ], + "constraints": "Constraints:\n\n1 <= n <= 10^5\n1 <= rides.length <= 3 * 10^4\nrides[i].length == 3\n1 <= starti < endi <= n\n1 <= tipi <= 10^5", + "tags": [ + "Array", + "Binary Search", + "Dynamic Programming", + "Sorting" + ], + "title-slug": "maximum-earnings-from-taxi" + }, + { + "leetcode-id": 2009, + "title": "Minimum Number of Operations to Make Array Continuous", + "difficulty": 3, + "description": "You are given an integer array nums. In one operation, you can replace any element in nums with any integer.\nnums is considered continuous if both of the following conditions are fulfilled:\n\nAll elements in nums are unique.\nThe difference between the maximum element and the minimum element in nums equals nums.length - 1.\n\nFor example, nums = [4, 2, 5, 3] is continuous, but nums = [1, 2, 3, 5, 6] is not continuous.\nReturn the minimum number of operations to make nums continuous.", + "examples": [ + "Example 1:\nInput: nums = [4,2,5,3]\nOutput: 0\nExplanation:\u00a0nums is already continuous.", + "Example 2:\nInput: nums = [1,2,3,5,6]\nOutput: 1\nExplanation:\u00a0One possible solution is to change the last element to 4.\nThe resulting array is [1,2,3,5,4], which is continuous.", + "Example 3:\nInput: nums = [1,10,100,1000]\nOutput: 3\nExplanation:\u00a0One possible solution is to:\n- Change the second element to 2.\n- Change the third element to 3.\n- Change the fourth element to 4.\nThe resulting array is [1,2,3,4], which is continuous." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "minimum-number-of-operations-to-make-array-continuous" + }, + { + "leetcode-id": 2011, + "title": "Final Value of Variable After Performing Operations", + "difficulty": 1, + "description": "There is a programming language with only four operations and one variable X:\n\n++X and X++ increments the value of the variable X by 1.\n--X and X-- decrements the value of the variable X by 1.\n\nInitially, the value of X is 0.\nGiven an array of strings operations containing a list of operations, return the final value of X after performing all the operations.", + "examples": [ + "Example 1:\nInput: operations = [\"--X\",\"X++\",\"X++\"]\nOutput: 1\nExplanation:\u00a0The operations are performed as follows:\nInitially, X = 0.\n--X: X is decremented by 1, X = 0 - 1 = -1.\nX++: X is incremented by 1, X = -1 + 1 = 0.\nX++: X is incremented by 1, X = 0 + 1 = 1.", + "Example 2:\nInput: operations = [\"++X\",\"++X\",\"X++\"]\nOutput: 3\nExplanation: The operations are performed as follows:\nInitially, X = 0.\n++X: X is incremented by 1, X = 0 + 1 = 1.\n++X: X is incremented by 1, X = 1 + 1 = 2.\nX++: X is incremented by 1, X = 2 + 1 = 3.", + "Example 3:\nInput: operations = [\"X++\",\"++X\",\"--X\",\"X--\"]\nOutput: 0\nExplanation:\u00a0The operations are performed as follows:\nInitially, X = 0.\nX++: X is incremented by 1, X = 0 + 1 = 1.\n++X: X is incremented by 1, X = 1 + 1 = 2.\n--X: X is decremented by 1, X = 2 - 1 = 1.\nX--: X is decremented by 1, X = 1 - 1 = 0." + ], + "constraints": "Constraints:\n\n1 <= operations.length <= 100\noperations[i] will be either \"++X\", \"X++\", \"--X\", or \"X--\".", + "tags": [ + "Array", + "String", + "Simulation" + ], + "title-slug": "final-value-of-variable-after-performing-operations" + }, + { + "leetcode-id": 2012, + "title": "Sum of Beauty in the Array", + "difficulty": 2, + "description": "You are given a 0-indexed integer array nums. For each index i (1 <= i <= nums.length - 2) the beauty of nums[i] equals:\n\n2, if nums[j] < nums[i] < nums[k], for all 0 <= j < i and for all i < k <= nums.length - 1.\n1, if nums[i - 1] < nums[i] < nums[i + 1], and the previous condition is not satisfied.\n0, if none of the previous conditions holds.\n\nReturn the sum of beauty of all nums[i] where 1 <= i <= nums.length - 2.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3]\nOutput: 2\nExplanation: For each index i in the range 1 <= i <= 1:\n- The beauty of nums[1] equals 2.", + "Example 2:\nInput: nums = [2,4,6,4]\nOutput: 1\nExplanation: For each index i in the range 1 <= i <= 2:\n- The beauty of nums[1] equals 1.\n- The beauty of nums[2] equals 0.", + "Example 3:\nInput: nums = [3,2,1]\nOutput: 0\nExplanation: For each index i in the range 1 <= i <= 1:\n- The beauty of nums[1] equals 0." + ], + "constraints": "Constraints:\n\n3 <= nums.length <= 10^5\n1 <= nums[i] <= 10^5", + "tags": [ + "Array" + ], + "title-slug": "sum-of-beauty-in-the-array" + }, + { + "leetcode-id": 2013, + "title": "Detect Squares", + "difficulty": 2, + "description": "You are given a stream of points on the X-Y plane. Design an algorithm that:\n\nAdds new points from the stream into a data structure. Duplicate points are allowed and should be treated as different points.\nGiven a query point, counts the number of ways to choose three points from the data structure such that the three points and the query point form an axis-aligned square with positive area.\n\nAn axis-aligned square is a square whose edges are all the same length and are either parallel or perpendicular to the x-axis and y-axis.\nImplement the DetectSquares class:\n\nDetectSquares() Initializes the object with an empty data structure.\nvoid add(int[] point) Adds a new point point = [x, y] to the data structure.\nint count(int[] point) Counts the number of ways to form axis-aligned squares with point point = [x, y] as described above.", + "examples": [ + "Example 1:\nInput\n[\"DetectSquares\", \"add\", \"add\", \"add\", \"count\", \"count\", \"add\", \"count\"]\n[[], [[3, 10]], [[11, 2]], [[3, 2]], [[11, 10]], [[14, 8]], [[11, 2]], [[11, 10]]]\nOutput\n[null, null, null, null, 1, 0, null, 2]\n\nExplanation\nDetectSquares detectSquares = new DetectSquares();\ndetectSquares.add([3, 10]);\ndetectSquares.add([11, 2]);\ndetectSquares.add([3, 2]);\ndetectSquares.count([11, 10]); // return 1. You can choose:\n // - The first, second, and third points\ndetectSquares.count([14, 8]); // return 0. The query point cannot form a square with any points in the data structure.\ndetectSquares.add([11, 2]); // Adding duplicate points is allowed.\ndetectSquares.count([11, 10]); // return 2. You can choose:\n // - The first, second, and third points\n // - The first, third, and fourth points" + ], + "constraints": "Constraints:\n\npoint.length == 2\n0 <= x, y <= 1000\nAt most 3000 calls in total will be made to add and count.", + "tags": [ + "Array", + "Hash Table", + "Design", + "Counting" + ], + "title-slug": "detect-squares" + }, + { + "leetcode-id": 2014, + "title": "Longest Subsequence Repeated k Times", + "difficulty": 3, + "description": "You are given a string s of length n, and an integer k. You are tasked to find the longest subsequence repeated k times in string s.\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\nA subsequence seq is repeated k times in the string s if seq * k is a subsequence of s, where seq * k represents a string constructed by concatenating seq k times.\n\nFor example, \"bba\" is repeated 2 times in the string \"bababcba\", because the string \"bbabba\", constructed by concatenating \"bba\" 2 times, is a subsequence of the string \"bababcba\".\n\nReturn the longest subsequence repeated k times in string s. If multiple such subsequences are found, return the lexicographically largest one. If there is no such subsequence, return an empty string.", + "examples": [ + "Example 1:\nInput: s = \"letsleetcode\", k = 2\nOutput: \"let\"\nExplanation: There are two longest subsequences repeated 2 times: \"let\" and \"ete\".\n\"let\" is the lexicographically largest one.", + "Example 2:\nInput: s = \"bb\", k = 2\nOutput: \"b\"\nExplanation: The longest subsequence repeated 2 times is \"b\".", + "Example 3:\nInput: s = \"ab\", k = 2\nOutput: \"\"\nExplanation: There is no subsequence repeated 2 times. Empty string is returned." + ], + "constraints": "Constraints:\n\nn == s.length\n2 <= n, k <= 2000\n2 <= n < k * 8\ns consists of lowercase English letters.", + "tags": [ + "String", + "Backtracking", + "Greedy", + "Counting", + "Enumeration" + ], + "title-slug": "longest-subsequence-repeated-k-times" + }, + { + "leetcode-id": 2016, + "title": "Maximum Difference Between Increasing Elements", + "difficulty": 1, + "description": "Given a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] - nums[i]), such that 0 <= i < j < n and nums[i] < nums[j].\nReturn the maximum difference. If no such i and j exists, return -1.", + "examples": [ + "Example 1:\nInput: nums = [7,1,5,4]\nOutput: 4\nExplanation:\nThe maximum difference occurs with i = 1 and j = 2, nums[j] - nums[i] = 5 - 1 = 4.\nNote that with i = 1 and j = 0, the difference nums[j] - nums[i] = 7 - 1 = 6, but i > j, so it is not valid.", + "Example 2:\nInput: nums = [9,4,3,2]\nOutput: -1\nExplanation:\nThere is no i and j such that i < j and nums[i] < nums[j].", + "Example 3:\nInput: nums = [1,5,2,10]\nOutput: 9\nExplanation:\nThe maximum difference occurs with i = 0 and j = 3, nums[j] - nums[i] = 10 - 1 = 9." + ], + "constraints": "Constraints:\n\nn == nums.length\n2 <= n <= 1000\n1 <= nums[i] <= 10^9", + "tags": [ + "Array" + ], + "title-slug": "maximum-difference-between-increasing-elements" + }, + { + "leetcode-id": 2017, + "title": "Grid Game", + "difficulty": 2, + "description": "You are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots are playing a game on this matrix.\nBoth robots initially start at (0, 0) and want to reach (1, n-1). Each robot may only move to the right ((r, c) to (r, c + 1)) or down ((r, c) to (r + 1, c)).\nAt the start of the game, the first robot moves from (0, 0) to (1, n-1), collecting all the points from the cells on its path. For all cells (r, c) traversed on the path, grid[r][c] is set to 0. Then, the second robot moves from (0, 0) to (1, n-1), collecting the points on its path. Note that their paths may intersect with one another.\nThe first robot wants to minimize the number of points collected by the second robot. In contrast, the second robot wants to maximize the number of points it collects. If both robots play optimally, return the number of points collected by the second robot.", + "examples": [ + "Example 1:\nInput: grid = [[2,5,4],[1,5,1]]\nOutput: 4\nExplanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.\nThe cells visited by the first robot are set to 0.\nThe second robot will collect 0 + 0 + 4 + 0 = 4 points.", + "Example 2:\nInput: grid = [[3,3,1],[8,5,2]]\nOutput: 4\nExplanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.\nThe cells visited by the first robot are set to 0.\nThe second robot will collect 0 + 3 + 1 + 0 = 4 points.", + "Example 3:\nInput: grid = [[1,3,1,15],[1,3,3,1]]\nOutput: 7\nExplanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.\nThe cells visited by the first robot are set to 0.\nThe second robot will collect 0 + 1 + 3 + 3 + 0 = 7 points." + ], + "constraints": "Constraints:\n\ngrid.length == 2\nn == grid[r].length\n1 <= n <= 5 * 10^4\n1 <= grid[r][c] <= 10^5", + "tags": [ + "Array", + "Matrix", + "Prefix Sum" + ], + "title-slug": "grid-game" + }, + { + "leetcode-id": 2018, + "title": "Check if Word Can Be Placed In Crossword", + "difficulty": 2, + "description": "You are given an m x n matrix board, representing the current state of a crossword puzzle. The crossword contains lowercase English letters (from solved words), ' ' to represent any empty cells, and '#' to represent any blocked cells.\nA word can be placed horizontally (left to right or right to left) or vertically (top to bottom or bottom to top) in the board if:\n\nIt does not occupy a cell containing the character '#'.\nThe cell each letter is placed in must either be ' ' (empty) or match the letter already on the board.\nThere must not be any empty cells ' ' or other lowercase letters directly left or right of the word if the word was placed horizontally.\nThere must not be any empty cells ' ' or other lowercase letters directly above or below the word if the word was placed vertically.\n\nGiven a string word, return true if word can be placed in board, or false otherwise.", + "examples": [ + "Example 1:\nInput: board = [[\"#\", \" \", \"#\"], [\" \", \" \", \"#\"], [\"#\", \"c\", \" \"]], word = \"abc\"\nOutput: true\nExplanation: The word \"abc\" can be placed as shown above (top to bottom).", + "Example 2:\nInput: board = [[\" \", \"#\", \"a\"], [\" \", \"#\", \"c\"], [\" \", \"#\", \"a\"]], word = \"ac\"\nOutput: false\nExplanation: It is impossible to place the word because there will always be a space/letter above or below it.", + "Example 3:\nInput: board = [[\"#\", \" \", \"#\"], [\" \", \" \", \"#\"], [\"#\", \" \", \"c\"]], word = \"ca\"\nOutput: true\nExplanation: The word \"ca\" can be placed as shown above (right to left)." + ], + "constraints": "Constraints:\n\nm == board.length\nn == board[i].length\n1 <= m * n <= 2 * 10^5\nboard[i][j] will be ' ', '#', or a lowercase English letter.\n1 <= word.length <= max(m, n)\nword will contain only lowercase English letters.", + "tags": [ + "Array", + "Matrix", + "Enumeration" + ], + "title-slug": "check-if-word-can-be-placed-in-crossword" + }, + { + "leetcode-id": 2019, + "title": "The Score of Students Solving Math Expression", + "difficulty": 3, + "description": "You are given a string s that contains digits 0-9, addition symbols '+', and multiplication symbols '*' only, representing a valid math expression of single digit numbers (e.g., 3+5*2). This expression was given to n elementary school students. The students were instructed to get the answer of the expression by following this order of operations:\n\nCompute multiplication, reading from left to right; Then,\nCompute addition, reading from left to right.\n\nYou are given an integer array answers of length n, which are the submitted answers of the students in no particular order. You are asked to grade the answers, by following these rules:\n\nIf an answer equals the correct answer of the expression, this student will be rewarded 5 points;\nOtherwise, if the answer could be interpreted as if the student applied the operators in the wrong order but had correct arithmetic, this student will be rewarded 2 points;\nOtherwise, this student will be rewarded 0 points.\n\nReturn the sum of the points of the students.", + "examples": [ + "Example 1:\nInput: s = \"7+3*1*2\", answers = [20,13,42]\nOutput: 7\nExplanation: As illustrated above, the correct answer of the expression is 13, therefore one student is rewarded 5 points: [20,13,42]\nA student might have applied the operators in this wrong order: ((7+3)*1)*2 = 20. Therefore one student is rewarded 2 points: [20,13,42]\nThe points for the students are: [2,5,0]. The sum of the points is 2+5+0=7.", + "Example 2:\nInput: s = \"3+5*2\", answers = [13,0,10,13,13,16,16]\nOutput: 19\nExplanation: The correct answer of the expression is 13, therefore three students are rewarded 5 points each: [13,0,10,13,13,16,16]\nA student might have applied the operators in this wrong order: ((3+5)*2 = 16. Therefore two students are rewarded 2 points: [13,0,10,13,13,16,16]\nThe points for the students are: [5,0,0,5,5,2,2]. The sum of the points is 5+0+0+5+5+2+2=19.", + "Example 3:\nInput: s = \"6+0*1\", answers = [12,9,6,4,8,6]\nOutput: 10\nExplanation: The correct answer of the expression is 6.\nIf a student had incorrectly done (6+0)*1, the answer would also be 6.\nBy the rules of grading, the students will still be rewarded 5 points (as they got the correct answer), not 2 points.\nThe points for the students are: [0,0,5,0,0,5]. The sum of the points is 10." + ], + "constraints": "Constraints:\n\n3 <= s.length <= 31\ns represents a valid expression that contains only digits 0-9, '+', and '*' only.\nAll the integer operands in the expression are in the inclusive range [0, 9].\n1 <= The count of all operators ('+' and '*') in the math expression <= 15\nTest data are generated such that the correct answer of the expression is in the range of [0, 1000].\nn == answers.length\n1 <= n <= 10^4\n0 <= answers[i] <= 1000", + "tags": [ + "Array", + "Math", + "String", + "Dynamic Programming", + "Stack", + "Memoization" + ], + "title-slug": "the-score-of-students-solving-math-expression" + }, + { + "leetcode-id": 2022, + "title": "Convert 1D Array Into 2D Array", + "difficulty": 1, + "description": "You are given a 0-indexed 1-dimensional (1D) integer array original, and two integers, m and n. You are tasked with creating a 2-dimensional (2D) array with m rows and n columns using all the elements from original.\nThe elements from indices 0 to n - 1 (inclusive) of original should form the first row of the constructed 2D array, the elements from indices n to 2 * n - 1 (inclusive) should form the second row of the constructed 2D array, and so on.\nReturn an m x n 2D array constructed according to the above procedure, or an empty 2D array if it is impossible.", + "examples": [ + "Example 1:\nInput: original = [1,2,3,4], m = 2, n = 2\nOutput: [[1,2],[3,4]]\nExplanation: The constructed 2D array should contain 2 rows and 2 columns.\nThe first group of n=2 elements in original, [1,2], becomes the first row in the constructed 2D array.\nThe second group of n=2 elements in original, [3,4], becomes the second row in the constructed 2D array.", + "Example 2:\nInput: original = [1,2,3], m = 1, n = 3\nOutput: [[1,2,3]]\nExplanation: The constructed 2D array should contain 1 row and 3 columns.\nPut all three elements in original into the first row of the constructed 2D array.", + "Example 3:\nInput: original = [1,2], m = 1, n = 1\nOutput: []\nExplanation: There are 2 elements in original.\nIt is impossible to fit 2 elements in a 1x1 2D array, so return an empty 2D array." + ], + "constraints": "Constraints:\n\n1 <= original.length <= 5 * 10^4\n1 <= original[i] <= 10^5\n1 <= m, n <= 4 * 10^4", + "tags": [ + "Array", + "Matrix", + "Simulation" + ], + "title-slug": "convert-1d-array-into-2d-array" + }, + { + "leetcode-id": 2023, + "title": "Number of Pairs of Strings With Concatenation Equal to Target", + "difficulty": 2, + "description": "Given an array of digit strings nums and a digit string target, return the number of pairs of indices (i, j) (where i != j) such that the concatenation of nums[i] + nums[j] equals target.", + "examples": [ + "Example 1:\nInput: nums = [\"777\",\"7\",\"77\",\"77\"], target = \"7777\"\nOutput: 4\nExplanation: Valid pairs are:\n- (0, 1): \"777\" + \"7\"\n- (1, 0): \"7\" + \"777\"\n- (2, 3): \"77\" + \"77\"\n- (3, 2): \"77\" + \"77\"", + "Example 2:\nInput: nums = [\"123\",\"4\",\"12\",\"34\"], target = \"1234\"\nOutput: 2\nExplanation: Valid pairs are:\n- (0, 1): \"123\" + \"4\"\n- (2, 3): \"12\" + \"34\"", + "Example 3:\nInput: nums = [\"1\",\"1\",\"1\"], target = \"11\"\nOutput: 6\nExplanation: Valid pairs are:\n- (0, 1): \"1\" + \"1\"\n- (1, 0): \"1\" + \"1\"\n- (0, 2): \"1\" + \"1\"\n- (2, 0): \"1\" + \"1\"\n- (1, 2): \"1\" + \"1\"\n- (2, 1): \"1\" + \"1\"" + ], + "constraints": "Constraints:\n\n2 <= nums.length <= 100\n1 <= nums[i].length <= 100\n2 <= target.length <= 100\nnums[i] and target consist of digits.\nnums[i] and target do not have leading zeros.", + "tags": [ + "Array", + "String" + ], + "title-slug": "number-of-pairs-of-strings-with-concatenation-equal-to-target" + }, + { + "leetcode-id": 2024, + "title": "Maximize the Confusion of an Exam", + "difficulty": 2, + "description": "A teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting false. He wants to confuse the students by maximizing the number of consecutive questions with the same answer (multiple trues or multiple falses in a row).\nYou are given a string answerKey, where answerKey[i] is the original answer to the i^th question. In addition, you are given an integer k, the maximum number of times you may perform the following operation:\n\nChange the answer key for any question to 'T' or 'F' (i.e., set answerKey[i] to 'T' or 'F').\n\nReturn the maximum number of consecutive 'T's or 'F's in the answer key after performing the operation at most k times.", + "examples": [ + "Example 1:\nInput: answerKey = \"TTFF\", k = 2\nOutput: 4\nExplanation: We can replace both the 'F's with 'T's to make answerKey = \"TTTT\".\nThere are four consecutive 'T's.", + "Example 2:\nInput: answerKey = \"TFFT\", k = 1\nOutput: 3\nExplanation: We can replace the first 'T' with an 'F' to make answerKey = \"FFFT\".\nAlternatively, we can replace the second 'T' with an 'F' to make answerKey = \"TFFF\".\nIn both cases, there are three consecutive 'F's.", + "Example 3:\nInput: answerKey = \"TTFTTFTT\", k = 1\nOutput: 5\nExplanation: We can replace the first 'F' to make answerKey = \"TTTTTFTT\"\nAlternatively, we can replace the second 'F' to make answerKey = \"TTFTTTTT\". \nIn both cases, there are five consecutive 'T's." + ], + "constraints": "Constraints:\n\nn == answerKey.length\n1 <= n <= 5 * 10^4\nanswerKey[i] is either 'T' or 'F'\n1 <= k <= n", + "tags": [ + "String", + "Binary Search", + "Sliding Window", + "Prefix Sum" + ], + "title-slug": "maximize-the-confusion-of-an-exam" + }, + { + "leetcode-id": 2025, + "title": "Maximum Number of Ways to Partition an Array", + "difficulty": 3, + "description": "You are given a 0-indexed integer array nums of length n. The number of ways to partition nums is the number of pivot indices that satisfy both conditions:\n\n1 <= pivot < n\nnums[0] + nums[1] + ... + nums[pivot - 1] == nums[pivot] + nums[pivot + 1] + ... + nums[n - 1]\n\nYou are also given an integer k. You can choose to change the value of one element of nums to k, or to leave the array unchanged.\nReturn the maximum possible number of ways to partition nums to satisfy both conditions after changing at most one element.", + "examples": [ + "Example 1:\nInput: nums = [2,-1,2], k = 3\nOutput: 1\nExplanation: One optimal approach is to change nums[0] to k. The array becomes [3,-1,2].\nThere is one way to partition the array:\n- For pivot = 2, we have the partition [3,-1 | 2]: 3 + -1 == 2.", + "Example 2:\nInput: nums = [0,0,0], k = 1\nOutput: 2\nExplanation: The optimal approach is to leave the array unchanged.\nThere are two ways to partition the array:\n- For pivot = 1, we have the partition [0 | 0,0]: 0 == 0 + 0.\n- For pivot = 2, we have the partition [0,0 | 0]: 0 + 0 == 0.", + "Example 3:\nInput: nums = [22,4,-25,-20,-15,15,-16,7,19,-10,0,-13,-14], k = -33\nOutput: 4\nExplanation: One optimal approach is to change nums[2] to k. The array becomes [22,4,-33,-20,-15,15,-16,7,19,-10,0,-13,-14].\nThere are four ways to partition the array." + ], + "constraints": "Constraints:\n\nn == nums.length\n2 <= n <= 10^5\n-10^5 <= k, nums[i] <= 10^5", + "tags": [ + "Array", + "Hash Table", + "Counting", + "Enumeration", + "Prefix Sum" + ], + "title-slug": "maximum-number-of-ways-to-partition-an-array" + }, + { + "leetcode-id": 2027, + "title": "Minimum Moves to Convert String", + "difficulty": 1, + "description": "You are given a string s consisting of n characters which are either 'X' or 'O'.\nA move is defined as selecting three consecutive characters of s and converting them to 'O'. Note that if a move is applied to the character 'O', it will stay the same.\nReturn the minimum number of moves required so that all the characters of s are converted to 'O'.", + "examples": [ + "Example 1:\nInput: s = \"XXX\"\nOutput: 1\nExplanation: XXX -> OOO\nWe select all the 3 characters and convert them in one move.", + "Example 2:\nInput: s = \"XXOX\"\nOutput: 2\nExplanation: XXOX -> OOOX -> OOOO\nWe select the first 3 characters in the first move, and convert them to 'O'.\nThen we select the last 3 characters and convert them so that the final string contains all 'O's.", + "Example 3:\nInput: s = \"OOOO\"\nOutput: 0\nExplanation: There are no 'X's in s to convert." + ], + "constraints": "Constraints:\n\n3 <= s.length <= 1000\ns[i] is either 'X' or 'O'.", + "tags": [ + "String", + "Greedy" + ], + "title-slug": "minimum-moves-to-convert-string" + }, + { + "leetcode-id": 2028, + "title": "Find Missing Observations", + "difficulty": 2, + "description": "You have observations of n + m 6-sided dice rolls with each face numbered from 1 to 6. n of the observations went missing, and you only have the observations of m rolls. Fortunately, you have also calculated the average value of the n + m rolls.\nYou are given an integer array rolls of length m where rolls[i] is the value of the i^th observation. You are also given the two integers mean and n.\nReturn an array of length n containing the missing observations such that the average value of the n + m rolls is exactly mean. If there are multiple valid answers, return any of them. If no such array exists, return an empty array.\nThe average value of a set of k numbers is the sum of the numbers divided by k.\nNote that mean is an integer, so the sum of the n + m rolls should be divisible by n + m.", + "examples": [ + "Example 1:\nInput: rolls = [3,2,4,3], mean = 4, n = 2\nOutput: [6,6]\nExplanation: The mean of all n + m rolls is (3 + 2 + 4 + 3 + 6 + 6) / 6 = 4.", + "Example 2:\nInput: rolls = [1,5,6], mean = 3, n = 4\nOutput: [2,3,2,2]\nExplanation: The mean of all n + m rolls is (1 + 5 + 6 + 2 + 3 + 2 + 2) / 7 = 3.", + "Example 3:\nInput: rolls = [1,2,3,4], mean = 6, n = 4\nOutput: []\nExplanation: It is impossible for the mean to be 6 no matter what the 4 missing rolls are." + ], + "constraints": "Constraints:\n\nm == rolls.length\n1 <= n, m <= 10^5\n1 <= rolls[i], mean <= 6", + "tags": [ + "Array", + "Math", + "Simulation" + ], + "title-slug": "find-missing-observations" + }, + { + "leetcode-id": 2029, + "title": "Stone Game IX", + "difficulty": 2, + "description": "Alice and Bob continue their games with stones. There is a row of n stones, and each stone has an associated value. You are given an integer array stones, where stones[i] is the value of the i^th stone.\nAlice and Bob take turns, with Alice starting first. On each turn, the player may remove any stone from stones. The player who removes a stone loses if the sum of the values of all removed stones is divisible by 3. Bob will win automatically if there are no remaining stones (even if it is Alice's turn).\nAssuming both players play optimally, return true if Alice wins and false if Bob wins.", + "examples": [ + "Example 1:\nInput: stones = [2,1]\nOutput: true\nExplanation:\u00a0The game will be played as follows:\n- Turn 1: Alice can remove either stone.\n- Turn 2: Bob removes the remaining stone. \nThe sum of the removed stones is 1 + 2 = 3 and is divisible by 3. Therefore, Bob loses and Alice wins the game.", + "Example 2:\nInput: stones = [2]\nOutput: false\nExplanation:\u00a0Alice will remove the only stone, and the sum of the values on the removed stones is 2. \nSince all the stones are removed and the sum of values is not divisible by 3, Bob wins the game.", + "Example 3:\nInput: stones = [5,1,2,4,3]\nOutput: false\nExplanation: Bob will always win. One possible way for Bob to win is shown below:\n- Turn 1: Alice can remove the second stone with value 1. Sum of removed stones = 1.\n- Turn 2: Bob removes the fifth stone with value 3. Sum of removed stones = 1 + 3 = 4.\n- Turn 3: Alices removes the fourth stone with value 4. Sum of removed stones = 1 + 3 + 4 = 8.\n- Turn 4: Bob removes the third stone with value 2. Sum of removed stones = 1 + 3 + 4 + 2 = 10.\n- Turn 5: Alice removes the first stone with value 5. Sum of removed stones = 1 + 3 + 4 + 2 + 5 = 15.\nAlice loses the game because the sum of the removed stones (15) is divisible by 3. Bob wins the game." + ], + "constraints": "Constraints:\n\n1 <= stones.length <= 10^5\n1 <= stones[i] <= 10^4", + "tags": [ + "Array", + "Math", + "Greedy", + "Counting", + "Game Theory" + ], + "title-slug": "stone-game-ix" + }, + { + "leetcode-id": 2030, + "title": "Smallest K-Length Subsequence With Occurrences of a Letter", + "difficulty": 3, + "description": "You are given a string s, an integer k, a letter letter, and an integer repetition.\nReturn the lexicographically smallest subsequence of s of length k that has the letter letter appear at least repetition times. The test cases are generated so that the letter appears in s at least repetition times.\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\nA string a is lexicographically smaller than a string b if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.", + "examples": [ + "Example 1:\nInput: s = \"leet\", k = 3, letter = \"e\", repetition = 1\nOutput: \"eet\"\nExplanation: There are four subsequences of length 3 that have the letter 'e' appear at least 1 time:\n- \"lee\" (from \"leet\")\n- \"let\" (from \"leet\")\n- \"let\" (from \"leet\")\n- \"eet\" (from \"leet\")\nThe lexicographically smallest subsequence among them is \"eet\".", + "Example 2:\nInput: s = \"leetcode\", k = 4, letter = \"e\", repetition = 2\nOutput: \"ecde\"\nExplanation: \"ecde\" is the lexicographically smallest subsequence of length 4 that has the letter \"e\" appear at least 2 times.", + "Example 3:\nInput: s = \"bb\", k = 2, letter = \"b\", repetition = 2\nOutput: \"bb\"\nExplanation: \"bb\" is the only subsequence of length 2 that has the letter \"b\" appear at least 2 times." + ], + "constraints": "Constraints:\n\n1 <= repetition <= k <= s.length <= 5 * 10^4\ns consists of lowercase English letters.\nletter is a lowercase English letter, and appears in s at least repetition times.", + "tags": [ + "String", + "Stack", + "Greedy", + "Monotonic Stack" + ], + "title-slug": "smallest-k-length-subsequence-with-occurrences-of-a-letter" + }, + { + "leetcode-id": 2032, + "title": "Two Out of Three", + "difficulty": 1, + "description": "Given three integer arrays nums1, nums2, and nums3, return a distinct array containing all the values that are present in at least two out of the three arrays. You may return the values in any order.", + "examples": [ + "Example 1:\nInput: nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3]\nOutput: [3,2]\nExplanation: The values that are present in at least two arrays are:\n- 3, in all three arrays.\n- 2, in nums1 and nums2.", + "Example 2:\nInput: nums1 = [3,1], nums2 = [2,3], nums3 = [1,2]\nOutput: [2,3,1]\nExplanation: The values that are present in at least two arrays are:\n- 2, in nums2 and nums3.\n- 3, in nums1 and nums2.\n- 1, in nums1 and nums3.", + "Example 3:\nInput: nums1 = [1,2,2], nums2 = [4,3,3], nums3 = [5]\nOutput: []\nExplanation: No value is present in at least two arrays." + ], + "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length, nums3.length <= 100\n1 <= nums1[i], nums2[j], nums3[k] <= 100", + "tags": [ + "Array", + "Hash Table" + ], + "title-slug": "two-out-of-three" + }, + { + "leetcode-id": 2033, + "title": "Minimum Operations to Make a Uni-Value Grid", + "difficulty": 2, + "description": "You are given a 2D integer grid of size m x n and an integer x. In one operation, you can add x to or subtract x from any element in the grid.\nA uni-value grid is a grid where all the elements of it are equal.\nReturn the minimum number of operations to make the grid uni-value. If it is not possible, return -1.", + "examples": [ + "Example 1:\nInput: grid = [[2,4],[6,8]], x = 2\nOutput: 4\nExplanation: We can make every element equal to 4 by doing the following: \n- Add x to 2 once.\n- Subtract x from 6 once.\n- Subtract x from 8 twice.\nA total of 4 operations were used.", + "Example 2:\nInput: grid = [[1,5],[2,3]], x = 1\nOutput: 5\nExplanation: We can make every element equal to 3.", + "Example 3:\nInput: grid = [[1,2],[3,4]], x = 2\nOutput: -1\nExplanation: It is impossible to make every element equal." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 10^5\n1 <= m * n <= 10^5\n1 <= x, grid[i][j] <= 10^4", + "tags": [ + "Array", + "Math", + "Sorting", + "Matrix" + ], + "title-slug": "minimum-operations-to-make-a-uni-value-grid" + }, + { + "leetcode-id": 2034, + "title": "Stock Price Fluctuation ", + "difficulty": 2, + "description": "You are given a stream of records about a particular stock. Each record contains a timestamp and the corresponding price of the stock at that timestamp.\nUnfortunately due to the volatile nature of the stock market, the records do not come in order. Even worse, some records may be incorrect. Another record with the same timestamp may appear later in the stream correcting the price of the previous wrong record.\nDesign an algorithm that:\n\nUpdates the price of the stock at a particular timestamp, correcting the price from any previous records at the timestamp.\nFinds the latest price of the stock based on the current records. The latest price is the price at the latest timestamp recorded.\nFinds the maximum price the stock has been based on the current records.\nFinds the minimum price the stock has been based on the current records.\n\nImplement the StockPrice class:\n\nStockPrice() Initializes the object with no price records.\nvoid update(int timestamp, int price) Updates the price of the stock at the given timestamp.\nint current() Returns the latest price of the stock.\nint maximum() Returns the maximum price of the stock.\nint minimum() Returns the minimum price of the stock.", + "examples": [ + "Example 1:\nInput\n[\"StockPrice\", \"update\", \"update\", \"current\", \"maximum\", \"update\", \"maximum\", \"update\", \"minimum\"]\n[[], [1, 10], [2, 5], [], [], [1, 3], [], [4, 2], []]\nOutput\n[null, null, null, 5, 10, null, 5, null, 2]\n\nExplanation\nStockPrice stockPrice = new StockPrice();\nstockPrice.update(1, 10); // Timestamps are [1] with corresponding prices [10].\nstockPrice.update(2, 5); // Timestamps are [1,2] with corresponding prices [10,5].\nstockPrice.current(); // return 5, the latest timestamp is 2 with the price being 5.\nstockPrice.maximum(); // return 10, the maximum price is 10 at timestamp 1.\nstockPrice.update(1, 3); // The previous timestamp 1 had the wrong price, so it is updated to 3.\n // Timestamps are [1,2] with corresponding prices [3,5].\nstockPrice.maximum(); // return 5, the maximum price is 5 after the correction.\nstockPrice.update(4, 2); // Timestamps are [1,2,4] with corresponding prices [3,5,2].\nstockPrice.minimum(); // return 2, the minimum price is 2 at timestamp 4." + ], + "constraints": "Constraints:\n\n1 <= timestamp, price <= 10^9\nAt most 10^5 calls will be made in total to update, current, maximum, and minimum.\ncurrent, maximum, and minimum will be called only after update has been called at least once.", + "tags": [ + "Hash Table", + "Design", + "Heap (Priority Queue)", + "Data Stream", + "Ordered Set" + ], + "title-slug": "stock-price-fluctuation" + }, + { + "leetcode-id": 2035, + "title": "Partition Array Into Two Arrays to Minimize Sum Difference", + "difficulty": 3, + "description": "You are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of the sums of the arrays. To partition nums, put each element of nums into one of the two arrays.\nReturn the minimum possible absolute difference.", + "examples": [ + "Example 1:\nInput: nums = [3,9,7,3]\nOutput: 2\nExplanation: One optimal partition is: [3,9] and [7,3].\nThe absolute difference between the sums of the arrays is abs((3 + 9) - (7 + 3)) = 2.", + "Example 2:\nInput: nums = [-36,36]\nOutput: 72\nExplanation: One optimal partition is: [-36] and [36].\nThe absolute difference between the sums of the arrays is abs((-36) - (36)) = 72.", + "Example 3:\nInput: nums = [2,-1,0,4,-2,-9]\nOutput: 0\nExplanation: One optimal partition is: [2,4,-9] and [-1,0,-2].\nThe absolute difference between the sums of the arrays is abs((2 + 4 + -9) - (-1 + 0 + -2)) = 0." + ], + "constraints": "Constraints:\n\n1 <= n <= 15\nnums.length == 2 * n\n-10^7 <= nums[i] <= 10^7", + "tags": [ + "Array", + "Two Pointers", + "Binary Search", + "Dynamic Programming", + "Bit Manipulation", + "Ordered Set", + "Bitmask" + ], + "title-slug": "partition-array-into-two-arrays-to-minimize-sum-difference" + }, + { + "leetcode-id": 2037, + "title": "Minimum Number of Moves to Seat Everyone", + "difficulty": 1, + "description": "There are n seats and n students in a room. You are given an array seats of length n, where seats[i] is the position of the i^th seat. You are also given the array students of length n, where students[j] is the position of the j^th student.\nYou may perform the following move any number of times:\n\nIncrease or decrease the position of the i^th student by 1 (i.e., moving the i^th student from position\u00a0x\u00a0to x + 1 or x - 1)\n\nReturn the minimum number of moves required to move each student to a seat such that no two students are in the same seat.\nNote that there may be multiple seats or students in the same position at the beginning.", + "examples": [ + "Example 1:\nInput: seats = [3,1,5], students = [2,7,4]\nOutput: 4\nExplanation: The students are moved as follows:\n- The first student is moved from from position 2 to position 1 using 1 move.\n- The second student is moved from from position 7 to position 5 using 2 moves.\n- The third student is moved from from position 4 to position 3 using 1 move.\nIn total, 1 + 2 + 1 = 4 moves were used.", + "Example 2:\nInput: seats = [4,1,5,9], students = [1,3,2,6]\nOutput: 7\nExplanation: The students are moved as follows:\n- The first student is not moved.\n- The second student is moved from from position 3 to position 4 using 1 move.\n- The third student is moved from from position 2 to position 5 using 3 moves.\n- The fourth student is moved from from position 6 to position 9 using 3 moves.\nIn total, 0 + 1 + 3 + 3 = 7 moves were used.", + "Example 3:\nInput: seats = [2,2,6,6], students = [1,3,2,6]\nOutput: 4\nExplanation: Note that there are two seats at position 2 and two seats at position 6.\nThe students are moved as follows:\n- The first student is moved from from position 1 to position 2 using 1 move.\n- The second student is moved from from position 3 to position 6 using 3 moves.\n- The third student is not moved.\n- The fourth student is not moved.\nIn total, 1 + 3 + 0 + 0 = 4 moves were used." + ], + "constraints": "Constraints:\n\nn == seats.length == students.length\n1 <= n <= 100\n1 <= seats[i], students[j] <= 100", + "tags": [ + "Array", + "Sorting" + ], + "title-slug": "minimum-number-of-moves-to-seat-everyone" + }, + { + "leetcode-id": 2038, + "title": "Remove Colored Pieces if Both Neighbors are the Same Color", + "difficulty": 2, + "description": "There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] is the color of the i^th piece.\nAlice and Bob are playing a game where they take alternating turns removing pieces from the line. In this game, Alice moves first.\n\nAlice is only allowed to remove a piece colored 'A' if both its neighbors are also colored 'A'. She is not allowed to remove pieces that are colored 'B'.\nBob is only allowed to remove a piece colored 'B' if both its neighbors are also colored 'B'. He is not allowed to remove pieces that are colored 'A'.\nAlice and Bob cannot remove pieces from the edge of the line.\nIf a player cannot make a move on their turn, that player loses and the other player wins.\n\nAssuming Alice and Bob play optimally, return true if Alice wins, or return false if Bob wins.", + "examples": [ + "Example 1:\nInput: colors = \"AAABABB\"\nOutput: true\nExplanation:\nAAABABB -> AABABB\nAlice moves first.\nShe removes the second 'A' from the left since that is the only 'A' whose neighbors are both 'A'.\n\nNow it's Bob's turn.\nBob cannot make a move on his turn since there are no 'B's whose neighbors are both 'B'.\nThus, Alice wins, so return true.", + "Example 2:\nInput: colors = \"AA\"\nOutput: false\nExplanation:\nAlice has her turn first.\nThere are only two 'A's and both are on the edge of the line, so she cannot move on her turn.\nThus, Bob wins, so return false.", + "Example 3:\nInput: colors = \"ABBBBBBBAAA\"\nOutput: false\nExplanation:\nABBBBBBBAAA -> ABBBBBBBAA\nAlice moves first.\nHer only option is to remove the second to last 'A' from the right.\n\nABBBBBBBAA -> ABBBBBBAA\nNext is Bob's turn.\nHe has many options for which 'B' piece to remove. He can pick any.\n\nOn Alice's second turn, she has no more pieces that she can remove.\nThus, Bob wins, so return false." + ], + "constraints": "Constraints:\n\n1 <=\u00a0colors.length <= 10^5\ncolors\u00a0consists of only the letters\u00a0'A'\u00a0and\u00a0'B'", + "tags": [ + "Math", + "String", + "Greedy", + "Game Theory" + ], + "title-slug": "remove-colored-pieces-if-both-neighbors-are-the-same-color" + }, + { + "leetcode-id": 2039, + "title": "The Time When the Network Becomes Idle", + "difficulty": 2, + "description": "There is a network of n servers, labeled from 0 to n - 1. You are given a 2D integer array edges, where edges[i] = [ui, vi] indicates there is a message channel between servers ui and vi, and they can pass any number of messages to each other directly in one second. You are also given a 0-indexed integer array patience of length n.\nAll servers are connected, i.e., a message can be passed from one server to any other server(s) directly or indirectly through the message channels.\nThe server labeled 0 is the master server. The rest are data servers. Each data server needs to send its message to the master server for processing and wait for a reply. Messages move between servers optimally, so every message takes the least amount of time to arrive at the master server. The master server will process all newly arrived messages instantly and send a reply to the originating server via the reversed path the message had gone through.\nAt the beginning of second 0, each data server sends its message to be processed. Starting from second 1, at the beginning of every second, each data server will check if it has received a reply to the message it sent (including any newly arrived replies) from the master server:\n\nIf it has not, it will resend the message periodically. The data server i will resend the message every patience[i] second(s), i.e., the data server i will resend the message if patience[i] second(s) have elapsed since the last time the message was sent from this server.\nOtherwise, no more resending will occur from this server.\n\nThe network becomes idle when there are no messages passing between servers or arriving at servers.\nReturn the earliest second starting from which the network becomes idle.", + "examples": [ + "Example 1:\nInput: edges = [[0,1],[1,2]], patience = [0,2,1]\nOutput: 8\nExplanation:\nAt (the beginning of) second 0,\n- Data server 1 sends its message (denoted 1A) to the master server.\n- Data server 2 sends its message (denoted 2A) to the master server.\n\nAt second 1,\n- Message 1A arrives at the master server. Master server processes message 1A instantly and sends a reply 1A back.\n- Server 1 has not received any reply. 1 second (1 < patience[1] = 2) elapsed since this server has sent the message, therefore it does not resend the message.\n- Server 2 has not received any reply. 1 second (1 == patience[2] = 1) elapsed since this server has sent the message, therefore it resends the message (denoted 2B).\n\nAt second 2,\n- The reply 1A arrives at server 1. No more resending will occur from server 1.\n- Message 2A arrives at the master server. Master server processes message 2A instantly and sends a reply 2A back.\n- Server 2 resends the message (denoted 2C).\n...\nAt second 4,\n- The reply 2A arrives at server 2. No more resending will occur from server 2.\n...\nAt second 7, reply 2D arrives at server 2.\n\nStarting from the beginning of the second 8, there are no messages passing between servers or arriving at servers.\nThis is the time when the network becomes idle.", + "Example 2:\nInput: edges = [[0,1],[0,2],[1,2]], patience = [0,10,10]\nOutput: 3\nExplanation: Data servers 1 and 2 receive a reply back at the beginning of second 2.\nFrom the beginning of the second 3, the network becomes idle." + ], + "constraints": "Constraints:\n\nn == patience.length\n2 <= n <= 10^5\npatience[0] == 0\n1 <= patience[i] <= 10^5 for 1 <= i < n\n1 <= edges.length <= min(10^5, n * (n - 1) / 2)\nedges[i].length == 2\n0 <= ui, vi < n\nui != vi\nThere are no duplicate edges.\nEach server can directly or indirectly reach another server.", + "tags": [ + "Array", + "Breadth-First Search", + "Graph" + ], + "title-slug": "the-time-when-the-network-becomes-idle" + }, + { + "leetcode-id": 2040, + "title": "Kth Smallest Product of Two Sorted Arrays", + "difficulty": 3, + "description": "Given two sorted 0-indexed integer arrays nums1 and nums2 as well as an integer k, return the k^th (1-based) smallest product of nums1[i] * nums2[j] where 0 <= i < nums1.length and 0 <= j < nums2.length.", + "examples": [ + "Example 1:\nInput: nums1 = [2,5], nums2 = [3,4], k = 2\nOutput: 8\nExplanation: The 2 smallest products are:\n- nums1[0] * nums2[0] = 2 * 3 = 6\n- nums1[0] * nums2[1] = 2 * 4 = 8\nThe 2^nd smallest product is 8.", + "Example 2:\nInput: nums1 = [-4,-2,0,3], nums2 = [2,4], k = 6\nOutput: 0\nExplanation: The 6 smallest products are:\n- nums1[0] * nums2[1] = (-4) * 4 = -16\n- nums1[0] * nums2[0] = (-4) * 2 = -8\n- nums1[1] * nums2[1] = (-2) * 4 = -8\n- nums1[1] * nums2[0] = (-2) * 2 = -4\n- nums1[2] * nums2[0] = 0 * 2 = 0\n- nums1[2] * nums2[1] = 0 * 4 = 0\nThe 6^th smallest product is 0.", + "Example 3:\nInput: nums1 = [-2,-1,0,1,2], nums2 = [-3,-1,2,4,5], k = 3\nOutput: -6\nExplanation: The 3 smallest products are:\n- nums1[0] * nums2[4] = (-2) * 5 = -10\n- nums1[0] * nums2[3] = (-2) * 4 = -8\n- nums1[4] * nums2[0] = 2 * (-3) = -6\nThe 3^rd smallest product is -6." + ], + "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 5 * 10^4\n-10^5 <= nums1[i], nums2[j] <= 10^5\n1 <= k <= nums1.length * nums2.length\nnums1 and nums2 are sorted.", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "kth-smallest-product-of-two-sorted-arrays" + }, + { + "leetcode-id": 2042, + "title": "Check if Numbers Are Ascending in a Sentence", + "difficulty": 1, + "description": "A sentence is a list of tokens separated by a single space with no leading or trailing spaces. Every token is either a positive number consisting of digits 0-9 with no leading zeros, or a word consisting of lowercase English letters.\n\nFor example, \"a puppy has 2 eyes 4 legs\" is a sentence with seven tokens: \"2\" and \"4\" are numbers and the other tokens such as \"puppy\" are words.\n\nGiven a string s representing a sentence, you need to check if all the numbers in s are strictly increasing from left to right (i.e., other than the last number, each number is strictly smaller than the number on its right in s).\nReturn true if so, or false otherwise.", + "examples": [ + "Example 1:\nInput: s = \"1 box has 3 blue 4 red 6 green and 12 yellow marbles\"\nOutput: true\nExplanation: The numbers in s are: 1, 3, 4, 6, 12.\nThey are strictly increasing from left to right: 1 < 3 < 4 < 6 < 12.", + "Example 2:\nInput: s = \"hello world 5 x 5\"\nOutput: false\nExplanation: The numbers in s are: 5, 5. They are not strictly increasing.", + "Example 3:\nInput: s = \"sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s\"\nOutput: false\nExplanation: The numbers in s are: 7, 51, 50, 60. They are not strictly increasing." + ], + "constraints": "Constraints:\n\n3 <= s.length <= 200\ns consists of lowercase English letters, spaces, and digits from 0 to 9, inclusive.\nThe number of tokens in s is between 2 and 100, inclusive.\nThe tokens in s are separated by a single space.\nThere are at least two numbers in s.\nEach number in s is a positive number less than 100, with no leading zeros.\ns contains no leading or trailing spaces.", + "tags": [ + "String" + ], + "title-slug": "check-if-numbers-are-ascending-in-a-sentence" + }, + { + "leetcode-id": 2043, + "title": "Simple Bank System", + "difficulty": 2, + "description": "You have been tasked with writing a program for a popular bank that will automate all its incoming transactions (transfer, deposit, and withdraw). The bank has n accounts numbered from 1 to n. The initial balance of each account is stored in a 0-indexed integer array balance, with the (i + 1)^th account having an initial balance of balance[i].\nExecute all the valid transactions. A transaction is valid if:\n\nThe given account number(s) are between 1 and n, and\nThe amount of money withdrawn or transferred from is less than or equal to the balance of the account.\n\nImplement the Bank class:\n\nBank(long[] balance) Initializes the object with the 0-indexed integer array balance.\nboolean transfer(int account1, int account2, long money) Transfers money dollars from the account numbered account1 to the account numbered account2. Return true if the transaction was successful, false otherwise.\nboolean deposit(int account, long money) Deposit money dollars into the account numbered account. Return true if the transaction was successful, false otherwise.\nboolean withdraw(int account, long money) Withdraw money dollars from the account numbered account. Return true if the transaction was successful, false otherwise.", + "examples": [ + "Example 1:\nInput\n[\"Bank\", \"withdraw\", \"transfer\", \"deposit\", \"transfer\", \"withdraw\"]\n[[[10, 100, 20, 50, 30]], [3, 10], [5, 1, 20], [5, 20], [3, 4, 15], [10, 50]]\nOutput\n[null, true, true, true, false, false]\n\nExplanation\nBank bank = new Bank([10, 100, 20, 50, 30]);\nbank.withdraw(3, 10); // return true, account 3 has a balance of $20, so it is valid to withdraw $10.\n // Account 3 has $20 - $10 = $10.\nbank.transfer(5, 1, 20); // return true, account 5 has a balance of $30, so it is valid to transfer $20.\n // Account 5 has $30 - $20 = $10, and account 1 has $10 + $20 = $30.\nbank.deposit(5, 20); // return true, it is valid to deposit $20 to account 5.\n // Account 5 has $10 + $20 = $30.\nbank.transfer(3, 4, 15); // return false, the current balance of account 3 is $10,\n // so it is invalid to transfer $15 from it.\nbank.withdraw(10, 50); // return false, it is invalid because account 10 does not exist." + ], + "constraints": "Constraints:\n\nn == balance.length\n1 <= n, account, account1, account2 <= 10^5\n0 <= balance[i], money <= 10^12\nAt most 10^4 calls will be made to each function transfer, deposit, withdraw.", + "tags": [ + "Array", + "Hash Table", + "Design", + "Simulation" + ], + "title-slug": "simple-bank-system" + }, + { + "leetcode-id": 2044, + "title": "Count Number of Maximum Bitwise-OR Subsets", + "difficulty": 2, + "description": "Given an integer array nums, find the maximum possible bitwise OR of a subset of nums and return the number of different non-empty subsets with the maximum bitwise OR.\nAn array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b. Two subsets are considered different if the indices of the elements chosen are different.\nThe bitwise OR of an array a is equal to a[0] OR a[1] OR ... OR a[a.length - 1] (0-indexed).", + "examples": [ + "Example 1:\nInput: nums = [3,1]\nOutput: 2\nExplanation: The maximum possible bitwise OR of a subset is 3. There are 2 subsets with a bitwise OR of 3:\n- [3]\n- [3,1]", + "Example 2:\nInput: nums = [2,2,2]\nOutput: 7\nExplanation: All non-empty subsets of [2,2,2] have a bitwise OR of 2. There are 2^3 - 1 = 7 total subsets.", + "Example 3:\nInput: nums = [3,2,1,5]\nOutput: 6\nExplanation: The maximum possible bitwise OR of a subset is 7. There are 6 subsets with a bitwise OR of 7:\n- [3,5]\n- [3,1,5]\n- [3,2,5]\n- [3,2,1,5]\n- [2,5]\n- [2,1,5]" + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 16\n1 <= nums[i] <= 10^5", + "tags": [ + "Array", + "Backtracking", + "Bit Manipulation" + ], + "title-slug": "count-number-of-maximum-bitwise-or-subsets" + }, + { + "leetcode-id": 2045, + "title": "Second Minimum Time to Reach Destination", + "difficulty": 3, + "description": "A city is represented as a bi-directional connected graph with n vertices where each vertex is labeled from 1 to n (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-directional edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself. The time taken to traverse any edge is time minutes.\nEach vertex has a traffic signal which changes its color from green to red and vice versa every\u00a0change minutes. All signals change at the same time. You can enter a vertex at any time, but can leave a vertex only when the signal is green. You cannot wait at a vertex if the signal is green.\nThe second minimum value is defined as the smallest value strictly larger than the minimum value.\n\nFor example the second minimum value of [2, 3, 4] is 3, and the second minimum value of [2, 2, 4] is 4.\n\nGiven n, edges, time, and change, return the second minimum time it will take to go from vertex 1 to vertex n.\nNotes:\n\nYou can go through any vertex any number of times, including 1 and n.\nYou can assume that when the journey starts, all signals have just turned green.", + "examples": [ + "Example 1:\nInput: n = 5, edges = [[1,2],[1,3],[1,4],[3,4],[4,5]], time = 3, change = 5\nOutput: 13\nExplanation:\nThe figure on the left shows the given graph.\nThe blue path in the figure on the right is the minimum time path.\nThe time taken is:\n- Start at 1, time elapsed=0\n- 1 -> 4: 3 minutes, time elapsed=3\n- 4 -> 5: 3 minutes, time elapsed=6\nHence the minimum time needed is 6 minutes.\n\nThe red path shows the path to get the second minimum time.\n- Start at 1, time elapsed=0\n- 1 -> 3: 3 minutes, time elapsed=3\n- 3 -> 4: 3 minutes, time elapsed=6\n- Wait at 4 for 4 minutes, time elapsed=10\n- 4 -> 5: 3 minutes, time elapsed=13\nHence the second minimum time is 13 minutes.", + "Example 2:\nInput: n = 2, edges = [[1,2]], time = 3, change = 2\nOutput: 11\nExplanation:\nThe minimum time path is 1 -> 2 with time = 3 minutes.\nThe second minimum time path is 1 -> 2 -> 1 -> 2 with time = 11 minutes." + ], + "constraints": "Constraints:\n\n2 <= n <= 10^4\nn - 1 <= edges.length <= min(2 * 10^4, n * (n - 1) / 2)\nedges[i].length == 2\n1 <= ui, vi <= n\nui != vi\nThere are no duplicate edges.\nEach vertex can be reached directly or indirectly from every other vertex.\n1 <= time, change <= 10^3", + "tags": [ + "Breadth-First Search", + "Graph", + "Shortest Path" + ], + "title-slug": "second-minimum-time-to-reach-destination" + }, + { + "leetcode-id": 2047, + "title": "Number of Valid Words in a Sentence", + "difficulty": 1, + "description": "A sentence consists of lowercase letters ('a' to 'z'), digits ('0' to '9'), hyphens ('-'), punctuation marks ('!', '.', and ','), and spaces (' ') only. Each sentence can be broken down into one or more tokens separated by one or more spaces ' '.\nA token is a valid word if all three of the following are true:\n\nIt only contains lowercase letters, hyphens, and/or punctuation (no digits).\nThere is at most one hyphen '-'. If present, it must be surrounded by lowercase characters (\"a-b\" is valid, but \"-ab\" and \"ab-\" are not valid).\nThere is at most one punctuation mark. If present, it must be at the end of the token (\"ab,\", \"cd!\", and \".\" are valid, but \"a!b\" and \"c.,\" are not valid).\n\nExamples of valid words include \"a-b.\", \"afad\", \"ba-c\", \"a!\", and \"!\".\nGiven a string sentence, return the number of valid words in sentence.", + "examples": [ + "Example 1:\nInput: sentence = \"cat and dog\"\nOutput: 3\nExplanation: The valid words in the sentence are \"cat\", \"and\", and \"dog\".", + "Example 2:\nInput: sentence = \"!this 1-s b8d!\"\nOutput: 0\nExplanation: There are no valid words in the sentence.\n\"!this\" is invalid because it starts with a punctuation mark.\n\"1-s\" and \"b8d\" are invalid because they contain digits.", + "Example 3:\nInput: sentence = \"alice and bob are playing stone-game10\"\nOutput: 5\nExplanation: The valid words in the sentence are \"alice\", \"and\", \"bob\", \"are\", and \"playing\".\n\"stone-game10\" is invalid because it contains digits." + ], + "constraints": "Constraints:\n\n1 <= sentence.length <= 1000\nsentence only contains lowercase English letters, digits, ' ', '-', '!', '.', and ','.\nThere will be at least\u00a01 token.", + "tags": [ + "String" + ], + "title-slug": "number-of-valid-words-in-a-sentence" + }, + { + "leetcode-id": 2048, + "title": "Next Greater Numerically Balanced Number", + "difficulty": 2, + "description": "An integer x is numerically balanced if for every digit d in the number x, there are exactly d occurrences of that digit in x.\nGiven an integer n, return the smallest numerically balanced number strictly greater than n.", + "examples": [ + "Example 1:\nInput: n = 1\nOutput: 22\nExplanation: \n22 is numerically balanced since:\n- The digit 2 occurs 2 times. \nIt is also the smallest numerically balanced number strictly greater than 1.", + "Example 2:\nInput: n = 1000\nOutput: 1333\nExplanation: \n1333 is numerically balanced since:\n- The digit 1 occurs 1 time.\n- The digit 3 occurs 3 times. \nIt is also the smallest numerically balanced number strictly greater than 1000.\nNote that 1022 cannot be the answer because 0 appeared more than 0 times.", + "Example 3:\nInput: n = 3000\nOutput: 3133\nExplanation: \n3133 is numerically balanced since:\n- The digit 1 occurs 1 time.\n- The digit 3 occurs 3 times.\nIt is also the smallest numerically balanced number strictly greater than 3000." + ], + "constraints": "Constraints:\n\n0 <= n <= 10^6", + "tags": [ + "Math", + "Backtracking", + "Enumeration" + ], + "title-slug": "next-greater-numerically-balanced-number" + }, + { + "leetcode-id": 2049, + "title": "Count Nodes With the Highest Score", + "difficulty": 2, + "description": "There is a binary tree rooted at 0 consisting of n nodes. The nodes are labeled from 0 to n - 1. You are given a 0-indexed integer array parents representing the tree, where parents[i] is the parent of node i. Since node 0 is the root, parents[0] == -1.\nEach node has a score. To find the score of a node, consider if the node and the edges connected to it were removed. The tree would become one or more non-empty subtrees. The size of a subtree is the number of the nodes in it. The score of the node is the product of the sizes of all those subtrees.\nReturn the number of nodes that have the highest score.", + "examples": [ + "Example 1:\nInput: parents = [-1,2,0,2,0]\nOutput: 3\nExplanation:\n- The score of node 0 is: 3 * 1 = 3\n- The score of node 1 is: 4 = 4\n- The score of node 2 is: 1 * 1 * 2 = 2\n- The score of node 3 is: 4 = 4\n- The score of node 4 is: 4 = 4\nThe highest score is 4, and three nodes (node 1, node 3, and node 4) have the highest score.", + "Example 2:\nInput: parents = [-1,2,0]\nOutput: 2\nExplanation:\n- The score of node 0 is: 2 = 2\n- The score of node 1 is: 2 = 2\n- The score of node 2 is: 1 * 1 = 1\nThe highest score is 2, and two nodes (node 0 and node 1) have the highest score." + ], + "constraints": "Constraints:\n\nn == parents.length\n2 <= n <= 10^5\nparents[0] == -1\n0 <= parents[i] <= n - 1 for i != 0\nparents represents a valid binary tree.", + "tags": [ + "Array", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "count-nodes-with-the-highest-score" + }, + { + "leetcode-id": 2050, + "title": "Parallel Courses III", + "difficulty": 3, + "description": "You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given a 2D integer array relations where relations[j] = [prevCoursej, nextCoursej] denotes that course prevCoursej has to be completed before course nextCoursej (prerequisite relationship). Furthermore, you are given a 0-indexed integer array time where time[i] denotes how many months it takes to complete the (i+1)^th course.\nYou must find the minimum number of months needed to complete all the courses following these rules:\n\nYou may start taking a course at any time if the prerequisites are met.\nAny number of courses can be taken at the same time.\n\nReturn the minimum number of months needed to complete all the courses.\nNote: The test cases are generated such that it is possible to complete every course (i.e., the graph is a directed acyclic graph).", + "examples": [ + "Example 1:\nInput: n = 3, relations = [[1,3],[2,3]], time = [3,2,5]\nOutput: 8\nExplanation: The figure above represents the given graph and the time required to complete each course. \nWe start course 1 and course 2 simultaneously at month 0.\nCourse 1 takes 3 months and course 2 takes 2 months to complete respectively.\nThus, the earliest time we can start course 3 is at month 3, and the total time required is 3 + 5 = 8 months.", + "Example 2:\nInput: n = 5, relations = [[1,5],[2,5],[3,5],[3,4],[4,5]], time = [1,2,3,4,5]\nOutput: 12\nExplanation: The figure above represents the given graph and the time required to complete each course.\nYou can start courses 1, 2, and 3 at month 0.\nYou can complete them after 1, 2, and 3 months respectively.\nCourse 4 can be taken only after course 3 is completed, i.e., after 3 months. It is completed after 3 + 4 = 7 months.\nCourse 5 can be taken only after courses 1, 2, 3, and 4 have been completed, i.e., after max(1,2,3,7) = 7 months.\nThus, the minimum time needed to complete all the courses is 7 + 5 = 12 months." + ], + "constraints": "Constraints:\n\n1 <= n <= 5 * 10^4\n0 <= relations.length <= min(n * (n - 1) / 2, 5 * 10^4)\nrelations[j].length == 2\n1 <= prevCoursej, nextCoursej <= n\nprevCoursej != nextCoursej\nAll the pairs [prevCoursej, nextCoursej] are unique.\ntime.length == n\n1 <= time[i] <= 10^4\nThe given graph is a directed acyclic graph.", + "tags": [ + "Array", + "Dynamic Programming", + "Graph", + "Topological Sort" + ], + "title-slug": "parallel-courses-iii" + }, + { + "leetcode-id": 2053, + "title": "Kth Distinct String in an Array", + "difficulty": 1, + "description": "A distinct string is a string that is present only once in an array.\nGiven an array of strings arr, and an integer k, return the k^th distinct string present in arr. If there are fewer than k distinct strings, return an empty string \"\".\nNote that the strings are considered in the order in which they appear in the array.", + "examples": [ + "Example 1:\nInput: arr = [\"d\",\"b\",\"c\",\"b\",\"c\",\"a\"], k = 2\nOutput: \"a\"\nExplanation:\nThe only distinct strings in arr are \"d\" and \"a\".\n\"d\" appears 1^st, so it is the 1^st distinct string.\n\"a\" appears 2^nd, so it is the 2^nd distinct string.\nSince k == 2, \"a\" is returned.", + "Example 2:\nInput: arr = [\"aaa\",\"aa\",\"a\"], k = 1\nOutput: \"aaa\"\nExplanation:\nAll strings in arr are distinct, so the 1^st string \"aaa\" is returned.", + "Example 3:\nInput: arr = [\"a\",\"b\",\"a\"], k = 3\nOutput: \"\"\nExplanation:\nThe only distinct string is \"b\". Since there are fewer than 3 distinct strings, we return an empty string \"\"." + ], + "constraints": "Constraints:\n\n1 <= k <= arr.length <= 1000\n1 <= arr[i].length <= 5\narr[i] consists of lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Counting" + ], + "title-slug": "kth-distinct-string-in-an-array" + }, + { + "leetcode-id": 2054, + "title": "Two Best Non-Overlapping Events", + "difficulty": 2, + "description": "You are given a 0-indexed 2D integer array of events where events[i] = [startTimei, endTimei, valuei]. The i^th event starts at startTimei and ends at endTimei, and if you attend this event, you will receive a value of valuei. You can choose at most two non-overlapping events to attend such that the sum of their values is maximized.\nReturn this maximum sum.\nNote that the start time and end time is inclusive: that is, you cannot attend two events where one of them starts and the other ends at the same time. More specifically, if you attend an event with end time t, the next event must start at or after t + 1.", + "examples": [ + "Example 1:\nInput: events = [[1,3,2],[4,5,2],[2,4,3]]\nOutput: 4\nExplanation: Choose the green events, 0 and 1 for a sum of 2 + 2 = 4.", + "Example 2:\nInput: events = [[1,3,2],[4,5,2],[1,5,5]]\nOutput: 5\nExplanation: Choose event 2 for a sum of 5.", + "Example 3:\nInput: events = [[1,5,3],[1,5,1],[6,6,5]]\nOutput: 8\nExplanation: Choose events 0 and 2 for a sum of 3 + 5 = 8." + ], + "constraints": "Constraints:\n\n2 <= events.length <= 10^5\nevents[i].length == 3\n1 <= startTimei <= endTimei <= 10^9\n1 <= valuei <= 10^6", + "tags": [ + "Array", + "Binary Search", + "Dynamic Programming", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "two-best-non-overlapping-events" + }, + { + "leetcode-id": 2055, + "title": "Plates Between Candles", + "difficulty": 2, + "description": "There is a long table with a line of plates and candles arranged on top of it. You are given a 0-indexed string s consisting of characters '*' and '|' only, where a '*' represents a plate and a '|' represents a candle.\nYou are also given a 0-indexed 2D integer array queries where queries[i] = [lefti, righti] denotes the substring s[lefti...righti] (inclusive). For each query, you need to find the number of plates between candles that are in the substring. A plate is considered between candles if there is at least one candle to its left and at least one candle to its right in the substring.\n\nFor example, s = \"||**||**|*\", and a query [3, 8] denotes the substring \"*||**|\". The number of plates between candles in this substring is 2, as each of the two plates has at least one candle in the substring to its left and right.\n\nReturn an integer array answer where answer[i] is the answer to the i^th query.", + "examples": [ + "Example 1:\nInput: s = \"**|**|***|\", queries = [[2,5],[5,9]]\nOutput: [2,3]\nExplanation:\n- queries[0] has two plates between candles.\n- queries[1] has three plates between candles.", + "Example 2:\nInput: s = \"***|**|*****|**||**|*\", queries = [[1,17],[4,5],[14,17],[5,11],[15,16]]\nOutput: [9,0,0,0,0]\nExplanation:\n- queries[0] has nine plates between candles.\n- The other queries have zero plates between candles." + ], + "constraints": "Constraints:\n\n3 <= s.length <= 10^5\ns consists of '*' and '|' characters.\n1 <= queries.length <= 10^5\nqueries[i].length == 2\n0 <= lefti <= righti < s.length", + "tags": [ + "Array", + "String", + "Binary Search", + "Prefix Sum" + ], + "title-slug": "plates-between-candles" + }, + { + "leetcode-id": 2056, + "title": "Number of Valid Move Combinations On Chessboard", + "difficulty": 3, + "description": "There is an 8 x 8 chessboard containing n pieces (rooks, queens, or bishops). You are given a string array pieces of length n, where pieces[i] describes the type (rook, queen, or bishop) of the i^th piece. In addition, you are given a 2D integer array positions also of length n, where positions[i] = [ri, ci] indicates that the i^th piece is currently at the 1-based coordinate (ri, ci) on the chessboard.\nWhen making a move for a piece, you choose a destination square that the piece will travel toward and stop on.\n\nA rook can only travel horizontally or vertically from (r, c) to the direction of (r+1, c), (r-1, c), (r, c+1), or (r, c-1).\nA queen can only travel horizontally, vertically, or diagonally from (r, c) to the direction of (r+1, c), (r-1, c), (r, c+1), (r, c-1), (r+1, c+1), (r+1, c-1), (r-1, c+1), (r-1, c-1).\nA bishop can only travel diagonally from (r, c) to the direction of (r+1, c+1), (r+1, c-1), (r-1, c+1), (r-1, c-1).\n\nYou must make a move for every piece on the board simultaneously. A move combination consists of all the moves performed on all the given pieces. Every second, each piece will instantaneously travel one square towards their destination if they are not already at it. All pieces start traveling at the 0^th second. A move combination is invalid if, at a given time, two or more pieces occupy the same square.\nReturn the number of valid move combinations\u200b\u200b\u200b\u200b\u200b.\nNotes:\n\nNo two pieces will start in the same square.\nYou may choose the square a piece is already on as its destination.\nIf two pieces are directly adjacent to each other, it is valid for them to move past each other and swap positions in one second.", + "examples": [ + "Example 1:\nInput: pieces = [\"rook\"], positions = [[1,1]]\nOutput: 15\nExplanation: The image above shows the possible squares the piece can move to.", + "Example 2:\nInput: pieces = [\"queen\"], positions = [[1,1]]\nOutput: 22\nExplanation: The image above shows the possible squares the piece can move to.", + "Example 3:\nInput: pieces = [\"bishop\"], positions = [[4,3]]\nOutput: 12\nExplanation: The image above shows the possible squares the piece can move to." + ], + "constraints": "Constraints:\n\nn == pieces.length \nn == positions.length\n1 <= n <= 4\npieces only contains the strings \"rook\", \"queen\", and \"bishop\".\nThere will be at most one queen on the chessboard.\n1 <= xi, yi <= 8\nEach positions[i] is distinct.", + "tags": [ + "Array", + "String", + "Backtracking", + "Simulation" + ], + "title-slug": "number-of-valid-move-combinations-on-chessboard" + }, + { + "leetcode-id": 2057, + "title": "Smallest Index With Equal Value", + "difficulty": 1, + "description": "Given a 0-indexed integer array nums, return the smallest index i of nums such that i mod 10 == nums[i], or -1 if such index does not exist.\nx mod y denotes the remainder when x is divided by y.", + "examples": [ + "Example 1:\nInput: nums = [0,1,2]\nOutput: 0\nExplanation: \ni=0: 0 mod 10 = 0 == nums[0].\ni=1: 1 mod 10 = 1 == nums[1].\ni=2: 2 mod 10 = 2 == nums[2].\nAll indices have i mod 10 == nums[i], so we return the smallest index 0.", + "Example 2:\nInput: nums = [4,3,2,1]\nOutput: 2\nExplanation: \ni=0: 0 mod 10 = 0 != nums[0].\ni=1: 1 mod 10 = 1 != nums[1].\ni=2: 2 mod 10 = 2 == nums[2].\ni=3: 3 mod 10 = 3 != nums[3].\n2 is the only index which has i mod 10 == nums[i].", + "Example 3:\nInput: nums = [1,2,3,4,5,6,7,8,9,0]\nOutput: -1\nExplanation: No index satisfies i mod 10 == nums[i]." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n0 <= nums[i] <= 9", + "tags": [ + "Array" + ], + "title-slug": "smallest-index-with-equal-value" + }, + { + "leetcode-id": 2058, + "title": "Find the Minimum and Maximum Number of Nodes Between Critical Points", + "difficulty": 2, + "description": "A critical point in a linked list is defined as either a local maxima or a local minima.\nA node is a local maxima if the current node has a value strictly greater than the previous node and the next node.\nA node is a local minima if the current node has a value strictly smaller than the previous node and the next node.\nNote that a node can only be a local maxima/minima if there exists both a previous node and a next node.\nGiven a linked list head, return an array of length 2 containing [minDistance, maxDistance] where minDistance is the minimum distance between any\u00a0two distinct critical points and maxDistance is the maximum distance between any\u00a0two distinct critical points. If there are fewer than two critical points, return [-1, -1].", + "examples": [ + "Example 1:\nInput: head = [3,1]\nOutput: [-1,-1]\nExplanation: There are no critical points in [3,1].", + "Example 2:\nInput: head = [5,3,1,2,5,1,2]\nOutput: [1,3]\nExplanation: There are three critical points:\n- [5,3,1,2,5,1,2]: The third node is a local minima because 1 is less than 3 and 2.\n- [5,3,1,2,5,1,2]: The fifth node is a local maxima because 5 is greater than 2 and 1.\n- [5,3,1,2,5,1,2]: The sixth node is a local minima because 1 is less than 5 and 2.\nThe minimum distance is between the fifth and the sixth node. minDistance = 6 - 5 = 1.\nThe maximum distance is between the third and the sixth node. maxDistance = 6 - 3 = 3.", + "Example 3:\nInput: head = [1,3,2,2,3,2,2,2,7]\nOutput: [3,3]\nExplanation: There are two critical points:\n- [1,3,2,2,3,2,2,2,7]: The second node is a local maxima because 3 is greater than 1 and 2.\n- [1,3,2,2,3,2,2,2,7]: The fifth node is a local maxima because 3 is greater than 2 and 2.\nBoth the minimum and maximum distances are between the second and the fifth node.\nThus, minDistance and maxDistance is 5 - 2 = 3.\nNote that the last node is not considered a local maxima because it does not have a next node." + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [2, 10^5].\n1 <= Node.val <= 10^5", + "tags": [ + "Linked List" + ], + "title-slug": "find-the-minimum-and-maximum-number-of-nodes-between-critical-points" + }, + { + "leetcode-id": 2059, + "title": "Minimum Operations to Convert Number", + "difficulty": 2, + "description": "You are given a 0-indexed integer array nums containing distinct numbers, an integer start, and an integer goal. There is an integer x that is initially set to start, and you want to perform operations on x such that it is converted to goal. You can perform the following operation repeatedly on the number x:\nIf 0 <= x <= 1000, then for any index i in the array (0 <= i < nums.length), you can set x to any of the following:\n\nx + nums[i]\nx - nums[i]\nx ^ nums[i] (bitwise-XOR)\n\nNote that you can use each nums[i] any number of times in any order. Operations that set x to be out of the range 0 <= x <= 1000 are valid, but no more operations can be done afterward.\nReturn the minimum number of operations needed to convert x = start into goal, and -1 if it is not possible.", + "examples": [ + "Example 1:\nInput: nums = [2,4,12], start = 2, goal = 12\nOutput: 2\nExplanation: We can go from 2 \u2192 14 \u2192 12 with the following 2 operations.\n- 2 + 12 = 14\n- 14 - 2 = 12", + "Example 2:\nInput: nums = [3,5,7], start = 0, goal = -4\nOutput: 2\nExplanation: We can go from 0 \u2192 3 \u2192 -4 with the following 2 operations. \n- 0 + 3 = 3\n- 3 - 7 = -4\nNote that the last operation sets x out of the range 0 <= x <= 1000, which is valid.", + "Example 3:\nInput: nums = [2,8,16], start = 0, goal = 1\nOutput: -1\nExplanation: There is no way to convert 0 into 1." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n-10^9 <= nums[i], goal <= 10^9\n0 <= start <= 1000\nstart != goal\nAll the integers in nums are distinct.", + "tags": [ + "Array", + "Breadth-First Search" + ], + "title-slug": "minimum-operations-to-convert-number" + }, + { + "leetcode-id": 2060, + "title": "Check if an Original String Exists Given Two Encoded Strings", + "difficulty": 3, + "description": "An original string, consisting of lowercase English letters, can be encoded by the following steps:\n\nArbitrarily split it into a sequence of some number of non-empty substrings.\nArbitrarily choose some elements (possibly none) of the sequence, and replace each with its length (as a numeric string).\nConcatenate the sequence as the encoded string.\n\nFor example, one way to encode an original string \"abcdefghijklmnop\" might be:\n\nSplit it as a sequence: [\"ab\", \"cdefghijklmn\", \"o\", \"p\"].\nChoose the second and third elements to be replaced by their lengths, respectively. The sequence becomes [\"ab\", \"12\", \"1\", \"p\"].\nConcatenate the elements of the sequence to get the encoded string: \"ab121p\".\n\nGiven two encoded strings s1 and s2, consisting of lowercase English letters and digits 1-9 (inclusive), return true if there exists an original string that could be encoded as both s1 and s2. Otherwise, return false.\nNote: The test cases are generated such that the number of consecutive digits in s1 and s2 does not exceed 3.", + "examples": [ + "Example 1:\nInput: s1 = \"internationalization\", s2 = \"i18n\"\nOutput: true\nExplanation: It is possible that \"internationalization\" was the original string.\n- \"internationalization\" \n -> Split: [\"internationalization\"]\n -> Do not replace any element\n -> Concatenate: \"internationalization\", which is s1.\n- \"internationalization\"\n -> Split: [\"i\", \"nternationalizatio\", \"n\"]\n -> Replace: [\"i\", \"18\", \"n\"]\n -> Concatenate: \"i18n\", which is s2", + "Example 2:\nInput: s1 = \"l123e\", s2 = \"44\"\nOutput: true\nExplanation: It is possible that \"leetcode\" was the original string.\n- \"leetcode\" \n -> Split: [\"l\", \"e\", \"et\", \"cod\", \"e\"]\n -> Replace: [\"l\", \"1\", \"2\", \"3\", \"e\"]\n -> Concatenate: \"l123e\", which is s1.\n- \"leetcode\" \n -> Split: [\"leet\", \"code\"]\n -> Replace: [\"4\", \"4\"]\n -> Concatenate: \"44\", which is s2.", + "Example 3:\nInput: s1 = \"a5b\", s2 = \"c5b\"\nOutput: false\nExplanation: It is impossible.\n- The original string encoded as s1 must start with the letter 'a'.\n- The original string encoded as s2 must start with the letter 'c'." + ], + "constraints": "Constraints:\n\n1 <= s1.length, s2.length <= 40\ns1 and s2 consist of digits 1-9 (inclusive), and lowercase English letters only.\nThe number of consecutive digits in s1 and s2 does not exceed 3.", + "tags": [ + "String", + "Dynamic Programming" + ], + "title-slug": "check-if-an-original-string-exists-given-two-encoded-strings" + }, + { + "leetcode-id": 2062, + "title": "Count Vowel Substrings of a String", + "difficulty": 1, + "description": "A substring is a contiguous (non-empty) sequence of characters within a string.\nA vowel substring is a substring that only consists of vowels ('a', 'e', 'i', 'o', and 'u') and has all five vowels present in it.\nGiven a string word, return the number of vowel substrings in word.", + "examples": [ + "Example 1:\nInput: word = \"aeiouu\"\nOutput: 2\nExplanation: The vowel substrings of word are as follows (underlined):\n- \"aeiouu\"\n- \"aeiouu\"", + "Example 2:\nInput: word = \"unicornarihan\"\nOutput: 0\nExplanation: Not all 5 vowels are present, so there are no vowel substrings.", + "Example 3:\nInput: word = \"cuaieuouac\"\nOutput: 7\nExplanation: The vowel substrings of word are as follows (underlined):\n- \"cuaieuouac\"\n- \"cuaieuouac\"\n- \"cuaieuouac\"\n- \"cuaieuouac\"\n- \"cuaieuouac\"\n- \"cuaieuouac\"\n- \"cuaieuouac\"" + ], + "constraints": "Constraints:\n\n1 <= word.length <= 100\nword consists of lowercase English letters only.", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "count-vowel-substrings-of-a-string" + }, + { + "leetcode-id": 2063, + "title": "Vowels of All Substrings", + "difficulty": 2, + "description": "Given a string word, return the sum of the number of vowels ('a', 'e', 'i', 'o', and 'u') in every substring of word.\nA substring is a contiguous (non-empty) sequence of characters within a string.\nNote: Due to the large constraints, the answer may not fit in a signed 32-bit integer. Please be careful during the calculations.", + "examples": [ + "Example 1:\nInput: word = \"aba\"\nOutput: 6\nExplanation: \nAll possible substrings are: \"a\", \"ab\", \"aba\", \"b\", \"ba\", and \"a\".\n- \"b\" has 0 vowels in it\n- \"a\", \"ab\", \"ba\", and \"a\" have 1 vowel each\n- \"aba\" has 2 vowels in it\nHence, the total sum of vowels = 0 + 1 + 1 + 1 + 1 + 2 = 6.", + "Example 2:\nInput: word = \"abc\"\nOutput: 3\nExplanation: \nAll possible substrings are: \"a\", \"ab\", \"abc\", \"b\", \"bc\", and \"c\".\n- \"a\", \"ab\", and \"abc\" have 1 vowel each\n- \"b\", \"bc\", and \"c\" have 0 vowels each\nHence, the total sum of vowels = 1 + 1 + 1 + 0 + 0 + 0 = 3.", + "Example 3:\nInput: word = \"ltcd\"\nOutput: 0\nExplanation: There are no vowels in any substring of \"ltcd\"." + ], + "constraints": "Constraints:\n\n1 <= word.length <= 10^5\nword consists of lowercase English letters.", + "tags": [ + "Math", + "String", + "Dynamic Programming", + "Combinatorics" + ], + "title-slug": "vowels-of-all-substrings" + }, + { + "leetcode-id": 2064, + "title": "Minimized Maximum of Products Distributed to Any Store", + "difficulty": 2, + "description": "You are given an integer n indicating there are n specialty retail stores. There are m product types of varying amounts, which are given as a 0-indexed integer array quantities, where quantities[i] represents the number of products of the i^th product type.\nYou need to distribute all products to the retail stores following these rules:\n\nA store can only be given at most one product type but can be given any amount of it.\nAfter distribution, each store will have been given some number of products (possibly 0). Let x represent the maximum number of products given to any store. You want x to be as small as possible, i.e., you want to minimize the maximum number of products that are given to any store.\n\nReturn the minimum possible x.", + "examples": [ + "Example 1:\nInput: n = 6, quantities = [11,6]\nOutput: 3\nExplanation: One optimal way is:\n- The 11 products of type 0 are distributed to the first four stores in these amounts: 2, 3, 3, 3\n- The 6 products of type 1 are distributed to the other two stores in these amounts: 3, 3\nThe maximum number of products given to any store is max(2, 3, 3, 3, 3, 3) = 3.", + "Example 2:\nInput: n = 7, quantities = [15,10,10]\nOutput: 5\nExplanation: One optimal way is:\n- The 15 products of type 0 are distributed to the first three stores in these amounts: 5, 5, 5\n- The 10 products of type 1 are distributed to the next two stores in these amounts: 5, 5\n- The 10 products of type 2 are distributed to the last two stores in these amounts: 5, 5\nThe maximum number of products given to any store is max(5, 5, 5, 5, 5, 5, 5) = 5.", + "Example 3:\nInput: n = 1, quantities = [100000]\nOutput: 100000\nExplanation: The only optimal way is:\n- The 100000 products of type 0 are distributed to the only store.\nThe maximum number of products given to any store is max(100000) = 100000." + ], + "constraints": "Constraints:\n\nm == quantities.length\n1 <= m <= n <= 10^5\n1 <= quantities[i] <= 10^5", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "minimized-maximum-of-products-distributed-to-any-store" + }, + { + "leetcode-id": 2065, + "title": "Maximum Path Quality of a Graph", + "difficulty": 3, + "description": "There is an undirected graph with n nodes numbered from 0 to n - 1 (inclusive). You are given a 0-indexed integer array values where values[i] is the value of the i^th node. You are also given a 0-indexed 2D integer array edges, where each edges[j] = [uj, vj, timej] indicates that there is an undirected edge between the nodes uj and vj, and it takes timej seconds to travel between the two nodes. Finally, you are given an integer maxTime.\nA valid path in the graph is any path that starts at node 0, ends at node 0, and takes at most maxTime seconds to complete. You may visit the same node multiple times. The quality of a valid path is the sum of the values of the unique nodes visited in the path (each node's value is added at most once to the sum).\nReturn the maximum quality of a valid path.\nNote: There are at most four edges connected to each node.", + "examples": [ + "Example 1:\nInput: values = [0,32,10,43], edges = [[0,1,10],[1,2,15],[0,3,10]], maxTime = 49\nOutput: 75\nExplanation:\nOne possible path is 0 -> 1 -> 0 -> 3 -> 0. The total time taken is 10 + 10 + 10 + 10 = 40 <= 49.\nThe nodes visited are 0, 1, and 3, giving a maximal path quality of 0 + 32 + 43 = 75.", + "Example 2:\nInput: values = [5,10,15,20], edges = [[0,1,10],[1,2,10],[0,3,10]], maxTime = 30\nOutput: 25\nExplanation:\nOne possible path is 0 -> 3 -> 0. The total time taken is 10 + 10 = 20 <= 30.\nThe nodes visited are 0 and 3, giving a maximal path quality of 5 + 20 = 25.", + "Example 3:\nInput: values = [1,2,3,4], edges = [[0,1,10],[1,2,11],[2,3,12],[1,3,13]], maxTime = 50\nOutput: 7\nExplanation:\nOne possible path is 0 -> 1 -> 3 -> 1 -> 0. The total time taken is 10 + 13 + 13 + 10 = 46 <= 50.\nThe nodes visited are 0, 1, and 3, giving a maximal path quality of 1 + 2 + 4 = 7." + ], + "constraints": "Constraints:\n\nn == values.length\n1 <= n <= 1000\n0 <= values[i] <= 10^8\n0 <= edges.length <= 2000\nedges[j].length == 3 \n0 <= uj < vj <= n - 1\n10 <= timej, maxTime <= 100\nAll the pairs [uj, vj] are unique.\nThere are at most four edges connected to each node.\nThe graph may not be connected.", + "tags": [ + "Array", + "Backtracking", + "Graph" + ], + "title-slug": "maximum-path-quality-of-a-graph" + }, + { + "leetcode-id": 2068, + "title": "Check Whether Two Strings are Almost Equivalent", + "difficulty": 1, + "description": "Two strings word1 and word2 are considered almost equivalent if the differences between the frequencies of each letter from 'a' to 'z' between word1 and word2 is at most 3.\nGiven two strings word1 and word2, each of length n, return true if word1 and word2 are almost equivalent, or false otherwise.\nThe frequency of a letter x is the number of times it occurs in the string.", + "examples": [ + "Example 1:\nInput: word1 = \"aaaa\", word2 = \"bccb\"\nOutput: false\nExplanation: There are 4 'a's in \"aaaa\" but 0 'a's in \"bccb\".\nThe difference is 4, which is more than the allowed 3.", + "Example 2:\nInput: word1 = \"abcdeef\", word2 = \"abaaacc\"\nOutput: true\nExplanation: The differences between the frequencies of each letter in word1 and word2 are at most 3:\n- 'a' appears 1 time in word1 and 4 times in word2. The difference is 3.\n- 'b' appears 1 time in word1 and 1 time in word2. The difference is 0.\n- 'c' appears 1 time in word1 and 2 times in word2. The difference is 1.\n- 'd' appears 1 time in word1 and 0 times in word2. The difference is 1.\n- 'e' appears 2 times in word1 and 0 times in word2. The difference is 2.\n- 'f' appears 1 time in word1 and 0 times in word2. The difference is 1.", + "Example 3:\nInput: word1 = \"cccddabba\", word2 = \"babababab\"\nOutput: true\nExplanation: The differences between the frequencies of each letter in word1 and word2 are at most 3:\n- 'a' appears 2 times in word1 and 4 times in word2. The difference is 2.\n- 'b' appears 2 times in word1 and 5 times in word2. The difference is 3.\n- 'c' appears 3 times in word1 and 0 times in word2. The difference is 3.\n- 'd' appears 2 times in word1 and 0 times in word2. The difference is 2." + ], + "constraints": "Constraints:\n\nn == word1.length == word2.length\n1 <= n <= 100\nword1 and word2 consist only of lowercase English letters.", + "tags": [ + "Hash Table", + "String", + "Counting" + ], + "title-slug": "check-whether-two-strings-are-almost-equivalent" + }, + { + "leetcode-id": 2069, + "title": "Walking Robot Simulation II", + "difficulty": 2, + "description": "A width x height grid is on an XY-plane with the bottom-left cell at (0, 0) and the top-right cell at (width - 1, height - 1). The grid is aligned with the four cardinal directions (\"North\", \"East\", \"South\", and \"West\"). A robot is initially at cell (0, 0) facing direction \"East\".\nThe robot can be instructed to move for a specific number of steps. For each step, it does the following.\n\nAttempts to move forward one cell in the direction it is facing.\nIf the cell the robot is moving to is out of bounds, the robot instead turns 90 degrees counterclockwise and retries the step.\n\nAfter the robot finishes moving the number of steps required, it stops and awaits the next instruction.\nImplement the Robot class:\n\nRobot(int width, int height) Initializes the width x height grid with the robot at (0, 0) facing \"East\".\nvoid step(int num) Instructs the robot to move forward num steps.\nint[] getPos() Returns the current cell the robot is at, as an array of length 2, [x, y].\nString getDir() Returns the current direction of the robot, \"North\", \"East\", \"South\", or \"West\".", + "examples": [ + "Example 1:\nInput\n[\"Robot\", \"step\", \"step\", \"getPos\", \"getDir\", \"step\", \"step\", \"step\", \"getPos\", \"getDir\"]\n[[6, 3], [2], [2], [], [], [2], [1], [4], [], []]\nOutput\n[null, null, null, [4, 0], \"East\", null, null, null, [1, 2], \"West\"]\n\nExplanation\nRobot robot = new Robot(6, 3); // Initialize the grid and the robot at (0, 0) facing East.\nrobot.step(2); // It moves two steps East to (2, 0), and faces East.\nrobot.step(2); // It moves two steps East to (4, 0), and faces East.\nrobot.getPos(); // return [4, 0]\nrobot.getDir(); // return \"East\"\nrobot.step(2); // It moves one step East to (5, 0), and faces East.\n // Moving the next step East would be out of bounds, so it turns and faces North.\n // Then, it moves one step North to (5, 1), and faces North.\nrobot.step(1); // It moves one step North to (5, 2), and faces North (not West).\nrobot.step(4); // Moving the next step North would be out of bounds, so it turns and faces West.\n // Then, it moves four steps West to (1, 2), and faces West.\nrobot.getPos(); // return [1, 2]\nrobot.getDir(); // return \"West\"" + ], + "constraints": "Constraints:\n\n2 <= width, height <= 100\n1 <= num <= 10^5\nAt most 10^4 calls in total will be made to step, getPos, and getDir.", + "tags": [ + "Design", + "Simulation" + ], + "title-slug": "walking-robot-simulation-ii" + }, + { + "leetcode-id": 2070, + "title": "Most Beautiful Item for Each Query", + "difficulty": 2, + "description": "You are given a 2D integer array items where items[i] = [pricei, beautyi] denotes the price and beauty of an item respectively.\nYou are also given a 0-indexed integer array queries. For each queries[j], you want to determine the maximum beauty of an item whose price is less than or equal to queries[j]. If no such item exists, then the answer to this query is 0.\nReturn an array answer of the same length as queries where answer[j] is the answer to the j^th query.", + "examples": [ + "Example 1:\nInput: items = [[1,2],[3,2],[2,4],[5,6],[3,5]], queries = [1,2,3,4,5,6]\nOutput: [2,4,5,5,6,6]\nExplanation:\n- For queries[0]=1, [1,2] is the only item which has price <= 1. Hence, the answer for this query is 2.\n- For queries[1]=2, the items which can be considered are [1,2] and [2,4]. \n The maximum beauty among them is 4.\n- For queries[2]=3 and queries[3]=4, the items which can be considered are [1,2], [3,2], [2,4], and [3,5].\n The maximum beauty among them is 5.\n- For queries[4]=5 and queries[5]=6, all items can be considered.\n Hence, the answer for them is the maximum beauty of all items, i.e., 6.", + "Example 2:\nInput: items = [[1,2],[1,2],[1,3],[1,4]], queries = [1]\nOutput: [4]\nExplanation: \nThe price of every item is equal to 1, so we choose the item with the maximum beauty 4. \nNote that multiple items can have the same price and/or beauty.", + "Example 3:\nInput: items = [[10,1000]], queries = [5]\nOutput: [0]\nExplanation:\nNo item has a price less than or equal to 5, so no item can be chosen.\nHence, the answer to the query is 0." + ], + "constraints": "Constraints:\n\n1 <= items.length, queries.length <= 10^5\nitems[i].length == 2\n1 <= pricei, beautyi, queries[j] <= 10^9", + "tags": [ + "Array", + "Binary Search", + "Sorting" + ], + "title-slug": "most-beautiful-item-for-each-query" + }, + { + "leetcode-id": 2071, + "title": "Maximum Number of Tasks You Can Assign", + "difficulty": 3, + "description": "You have n tasks and m workers. Each task has a strength requirement stored in a 0-indexed integer array tasks, with the i^th task requiring tasks[i] strength to complete. The strength of each worker is stored in a 0-indexed integer array workers, with the j^th worker having workers[j] strength. Each worker can only be assigned to a single task and must have a strength greater than or equal to the task's strength requirement (i.e., workers[j] >= tasks[i]).\nAdditionally, you have pills magical pills that will increase a worker's strength by strength. You can decide which workers receive the magical pills, however, you may only give each worker at most one magical pill.\nGiven the 0-indexed integer arrays tasks and workers and the integers pills and strength, return the maximum number of tasks that can be completed.", + "examples": [ + "Example 1:\nInput: tasks = [3,2,1], workers = [0,3,3], pills = 1, strength = 1\nOutput: 3\nExplanation:\nWe can assign the magical pill and tasks as follows:\n- Give the magical pill to worker 0.\n- Assign worker 0 to task 2 (0 + 1 >= 1)\n- Assign worker 1 to task 1 (3 >= 2)\n- Assign worker 2 to task 0 (3 >= 3)", + "Example 2:\nInput: tasks = [5,4], workers = [0,0,0], pills = 1, strength = 5\nOutput: 1\nExplanation:\nWe can assign the magical pill and tasks as follows:\n- Give the magical pill to worker 0.\n- Assign worker 0 to task 0 (0 + 5 >= 5)", + "Example 3:\nInput: tasks = [10,15,30], workers = [0,10,10,10,10], pills = 3, strength = 10\nOutput: 2\nExplanation:\nWe can assign the magical pills and tasks as follows:\n- Give the magical pill to worker 0 and worker 1.\n- Assign worker 0 to task 0 (0 + 10 >= 10)\n- Assign worker 1 to task 1 (10 + 10 >= 15)\nThe last pill is not given because it will not make any worker strong enough for the last task." + ], + "constraints": "Constraints:\n\nn == tasks.length\nm == workers.length\n1 <= n, m <= 5 * 10^4\n0 <= pills <= m\n0 <= tasks[i], workers[j], strength <= 10^9", + "tags": [ + "Array", + "Binary Search", + "Greedy", + "Queue", + "Sorting", + "Monotonic Queue" + ], + "title-slug": "maximum-number-of-tasks-you-can-assign" + }, + { + "leetcode-id": 2073, + "title": "Time Needed to Buy Tickets", + "difficulty": 1, + "description": "There are n people in a line queuing to buy tickets, where the 0^th person is at the front of the line and the (n - 1)^th person is at the back of the line.\nYou are given a 0-indexed integer array tickets of length n where the number of tickets that the i^th person would like to buy is tickets[i].\nEach person takes exactly 1 second to buy a ticket. A person can only buy 1 ticket at a time and has to go back to the end of the line (which happens instantaneously) in order to buy more tickets. If a person does not have any tickets left to buy, the person will leave the line.\nReturn the time taken for the person at position k\u00a0(0-indexed)\u00a0to finish buying tickets.", + "examples": [ + "Example 1:\nInput: tickets = [2,3,2], k = 2\nOutput: 6\nExplanation: \n- In the first pass, everyone in the line buys a ticket and the line becomes [1, 2, 1].\n- In the second pass, everyone in the line buys a ticket and the line becomes [0, 1, 0].\nThe person at\u00a0position 2 has successfully bought 2 tickets and it took 3 + 3 = 6 seconds.", + "Example 2:\nInput: tickets = [5,1,1,1], k = 0\nOutput: 8\nExplanation:\n- In the first pass, everyone in the line buys a ticket and the line becomes [4, 0, 0, 0].\n- In the next 4 passes, only the person in position 0 is buying tickets.\nThe person at\u00a0position 0 has successfully bought 5 tickets and it took 4 + 1 + 1 + 1 + 1 = 8 seconds." + ], + "constraints": "Constraints:\n\nn == tickets.length\n1 <= n <= 100\n1 <= tickets[i] <= 100\n0 <= k < n", + "tags": [ + "Array", + "Queue", + "Simulation" + ], + "title-slug": "time-needed-to-buy-tickets" + }, + { + "leetcode-id": 2074, + "title": "Reverse Nodes in Even Length Groups", + "difficulty": 2, + "description": "You are given the head of a linked list.\nThe nodes in the linked list are sequentially assigned to non-empty groups whose lengths form the sequence of the natural numbers (1, 2, 3, 4, ...). The length of a group is the number of nodes assigned to it. In other words,\n\nThe 1^st node is assigned to the first group.\nThe 2^nd and the 3^rd nodes are assigned to the second group.\nThe 4^th, 5^th, and 6^th nodes are assigned to the third group, and so on.\n\nNote that the length of the last group may be less than or equal to 1 + the length of the second to last group.\nReverse the nodes in each group with an even length, and return the head of the modified linked list.", + "examples": [ + "Example 1:\nInput: head = [5,2,6,3,9,1,7,3,8,4]\nOutput: [5,6,2,3,9,1,4,8,3,7]\nExplanation:\n- The length of the first group is 1, which is odd, hence no reversal occurs.\n- The length of the second group is 2, which is even, hence the nodes are reversed.\n- The length of the third group is 3, which is odd, hence no reversal occurs.\n- The length of the last group is 4, which is even, hence the nodes are reversed.", + "Example 2:\nInput: head = [1,1,0,6]\nOutput: [1,0,1,6]\nExplanation:\n- The length of the first group is 1. No reversal occurs.\n- The length of the second group is 2. The nodes are reversed.\n- The length of the last group is 1. No reversal occurs.", + "Example 3:\nInput: head = [1,1,0,6,5]\nOutput: [1,0,1,5,6]\nExplanation:\n- The length of the first group is 1. No reversal occurs.\n- The length of the second group is 2. The nodes are reversed.\n- The length of the last group is 2. The nodes are reversed." + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [1, 10^5].\n0 <= Node.val <= 10^5", + "tags": [ + "Linked List" + ], + "title-slug": "reverse-nodes-in-even-length-groups" + }, + { + "leetcode-id": 2075, + "title": "Decode the Slanted Ciphertext", + "difficulty": 2, + "description": "A string originalText is encoded using a slanted transposition cipher to a string encodedText with the help of a matrix having a fixed number of rows rows.\noriginalText is placed first in a top-left to bottom-right manner.\n\nThe blue cells are filled first, followed by the red cells, then the yellow cells, and so on, until we reach the end of originalText. The arrow indicates the order in which the cells are filled. All empty cells are filled with ' '. The number of columns is chosen such that the rightmost column will not be empty after filling in originalText.\nencodedText is then formed by appending all characters of the matrix in a row-wise fashion.\n\nThe characters in the blue cells are appended first to encodedText, then the red cells, and so on, and finally the yellow cells. The arrow indicates the order in which the cells are accessed.\nFor example, if originalText = \"cipher\" and rows = 3, then we encode it in the following manner:\n\nThe blue arrows depict how originalText is placed in the matrix, and the red arrows denote the order in which encodedText is formed. In the above example, encodedText = \"ch ie pr\".\nGiven the encoded string encodedText and number of rows rows, return the original string originalText.\nNote: originalText does not have any trailing spaces ' '. The test cases are generated such that there is only one possible originalText.", + "examples": [ + "Example 1:\nInput: encodedText = \"ch ie pr\", rows = 3\nOutput: \"cipher\"\nExplanation: This is the same example described in the problem description.", + "Example 2:\nInput: encodedText = \"iveo eed l te olc\", rows = 4\nOutput: \"i love leetcode\"\nExplanation: The figure above denotes the matrix that was used to encode originalText. \nThe blue arrows show how we can find originalText from encodedText.", + "Example 3:\nInput: encodedText = \"coding\", rows = 1\nOutput: \"coding\"\nExplanation: Since there is only 1 row, both originalText and encodedText are the same." + ], + "constraints": "Constraints:\n\n0 <= encodedText.length <= 10^6\nencodedText consists of lowercase English letters and ' ' only.\nencodedText is a valid encoding of some originalText that does not have trailing spaces.\n1 <= rows <= 1000\nThe testcases are generated such that there is only one possible originalText.", + "tags": [ + "String", + "Simulation" + ], + "title-slug": "decode-the-slanted-ciphertext" + }, + { + "leetcode-id": 2076, + "title": "Process Restricted Friend Requests", + "difficulty": 3, + "description": "You are given an integer n indicating the number of people in a network. Each person is labeled from 0 to n - 1.\nYou are also given a 0-indexed 2D integer array restrictions, where restrictions[i] = [xi, yi] means that person xi and person yi cannot become friends, either directly or indirectly through other people.\nInitially, no one is friends with each other. You are given a list of friend requests as a 0-indexed 2D integer array requests, where requests[j] = [uj, vj] is a friend request between person uj and person vj.\nA friend request is successful if uj and vj can be friends. Each friend request is processed in the given order (i.e., requests[j] occurs before requests[j + 1]), and upon a successful request, uj and vj become direct friends for all future friend requests.\nReturn a boolean array result, where each result[j] is true if the j^th friend request is successful or false if it is not.\nNote: If uj and vj are already direct friends, the request is still successful.", + "examples": [ + "Example 1:\nInput: n = 3, restrictions = [[0,1]], requests = [[0,2],[2,1]]\nOutput: [true,false]\nExplanation:\nRequest 0: Person 0 and person 2 can be friends, so they become direct friends. \nRequest 1: Person 2 and person 1 cannot be friends since person 0 and person 1 would be indirect friends (1--2--0).", + "Example 2:\nInput: n = 3, restrictions = [[0,1]], requests = [[1,2],[0,2]]\nOutput: [true,false]\nExplanation:\nRequest 0: Person 1 and person 2 can be friends, so they become direct friends.\nRequest 1: Person 0 and person 2 cannot be friends since person 0 and person 1 would be indirect friends (0--2--1).", + "Example 3:\nInput: n = 5, restrictions = [[0,1],[1,2],[2,3]], requests = [[0,4],[1,2],[3,1],[3,4]]\nOutput: [true,false,true,false]\nExplanation:\nRequest 0: Person 0 and person 4 can be friends, so they become direct friends.\nRequest 1: Person 1 and person 2 cannot be friends since they are directly restricted.\nRequest 2: Person 3 and person 1 can be friends, so they become direct friends.\nRequest 3: Person 3 and person 4 cannot be friends since person 0 and person 1 would be indirect friends (0--4--3--1)." + ], + "constraints": "Constraints:\n\n2 <= n <= 1000\n0 <= restrictions.length <= 1000\nrestrictions[i].length == 2\n0 <= xi, yi <= n - 1\nxi != yi\n1 <= requests.length <= 1000\nrequests[j].length == 2\n0 <= uj, vj <= n - 1\nuj != vj", + "tags": [ + "Union Find", + "Graph" + ], + "title-slug": "process-restricted-friend-requests" + }, + { + "leetcode-id": 2078, + "title": "Two Furthest Houses With Different Colors", + "difficulty": 1, + "description": "There are n houses evenly lined up on the street, and each house is beautifully painted. You are given a 0-indexed integer array colors of length n, where colors[i] represents the color of the i^th house.\nReturn the maximum distance between two houses with different colors.\nThe distance between the i^th and j^th houses is abs(i - j), where abs(x) is the absolute value of x.", + "examples": [ + "Example 1:\nInput: colors = [1,1,1,6,1,1,1]\nOutput: 3\nExplanation: In the above image, color 1 is blue, and color 6 is red.\nThe furthest two houses with different colors are house 0 and house 3.\nHouse 0 has color 1, and house 3 has color 6. The distance between them is abs(0 - 3) = 3.\nNote that houses 3 and 6 can also produce the optimal answer.", + "Example 2:\nInput: colors = [1,8,3,8,3]\nOutput: 4\nExplanation: In the above image, color 1 is blue, color 8 is yellow, and color 3 is green.\nThe furthest two houses with different colors are house 0 and house 4.\nHouse 0 has color 1, and house 4 has color 3. The distance between them is abs(0 - 4) = 4.", + "Example 3:\nInput: colors = [0,1]\nOutput: 1\nExplanation: The furthest two houses with different colors are house 0 and house 1.\nHouse 0 has color 0, and house 1 has color 1. The distance between them is abs(0 - 1) = 1." + ], + "constraints": "Constraints:\n\nn ==\u00a0colors.length\n2 <= n <= 100\n0 <= colors[i] <= 100\nTest data are generated such that at least two houses have different colors.", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "two-furthest-houses-with-different-colors" + }, + { + "leetcode-id": 2079, + "title": "Watering Plants", + "difficulty": 2, + "description": "You want to water n plants in your garden with a watering can. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the i^th plant is located at x = i. There is a river at x = -1 that you can refill your watering can at.\nEach plant needs a specific amount of water. You will water the plants in the following way:\n\nWater the plants in order from left to right.\nAfter watering the current plant, if you do not have enough water to completely water the next plant, return to the river to fully refill the watering can.\nYou cannot refill the watering can early.\n\nYou are initially at the river (i.e., x = -1). It takes one step to move one unit on the x-axis.\nGiven a 0-indexed integer array plants of n integers, where plants[i] is the amount of water the i^th plant needs, and an integer capacity representing the watering can capacity, return the number of steps needed to water all the plants.", + "examples": [ + "Example 1:\nInput: plants = [2,2,3,3], capacity = 5\nOutput: 14\nExplanation: Start at the river with a full watering can:\n- Walk to plant 0 (1 step) and water it. Watering can has 3 units of water.\n- Walk to plant 1 (1 step) and water it. Watering can has 1 unit of water.\n- Since you cannot completely water plant 2, walk back to the river to refill (2 steps).\n- Walk to plant 2 (3 steps) and water it. Watering can has 2 units of water.\n- Since you cannot completely water plant 3, walk back to the river to refill (3 steps).\n- Walk to plant 3 (4 steps) and water it.\nSteps needed = 1 + 1 + 2 + 3 + 3 + 4 = 14.", + "Example 2:\nInput: plants = [1,1,1,4,2,3], capacity = 4\nOutput: 30\nExplanation: Start at the river with a full watering can:\n- Water plants 0, 1, and 2 (3 steps). Return to river (3 steps).\n- Water plant 3 (4 steps). Return to river (4 steps).\n- Water plant 4 (5 steps). Return to river (5 steps).\n- Water plant 5 (6 steps).\nSteps needed = 3 + 3 + 4 + 4 + 5 + 5 + 6 = 30.", + "Example 3:\nInput: plants = [7,7,7,7,7,7,7], capacity = 8\nOutput: 49\nExplanation: You have to refill before watering each plant.\nSteps needed = 1 + 1 + 2 + 2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 = 49." + ], + "constraints": "Constraints:\n\nn == plants.length\n1 <= n <= 1000\n1 <= plants[i] <= 10^6\nmax(plants[i]) <= capacity <= 10^9", + "tags": [ + "Array" + ], + "title-slug": "watering-plants" + }, + { + "leetcode-id": 2080, + "title": "Range Frequency Queries", + "difficulty": 2, + "description": "Design a data structure to find the frequency of a given value in a given subarray.\nThe frequency of a value in a subarray is the number of occurrences of that value in the subarray.\nImplement the RangeFreqQuery class:\n\nRangeFreqQuery(int[] arr) Constructs an instance of the class with the given 0-indexed integer array arr.\nint query(int left, int right, int value) Returns the frequency of value in the subarray arr[left...right].\n\nA subarray is a contiguous sequence of elements within an array. arr[left...right] denotes the subarray that contains the elements of nums between indices left and right (inclusive).", + "examples": [ + "Example 1:\nInput\n[\"RangeFreqQuery\", \"query\", \"query\"]\n[[[12, 33, 4, 56, 22, 2, 34, 33, 22, 12, 34, 56]], [1, 2, 4], [0, 11, 33]]\nOutput\n[null, 1, 2]\n\nExplanation\nRangeFreqQuery rangeFreqQuery = new RangeFreqQuery([12, 33, 4, 56, 22, 2, 34, 33, 22, 12, 34, 56]);\nrangeFreqQuery.query(1, 2, 4); // return 1. The value 4 occurs 1 time in the subarray [33, 4]\nrangeFreqQuery.query(0, 11, 33); // return 2. The value 33 occurs 2 times in the whole array." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^5\n1 <= arr[i], value <= 10^4\n0 <= left <= right < arr.length\nAt most 10^5 calls will be made to query", + "tags": [ + "Array", + "Hash Table", + "Binary Search", + "Design", + "Segment Tree" + ], + "title-slug": "range-frequency-queries" + }, + { + "leetcode-id": 2081, + "title": "Sum of k-Mirror Numbers", + "difficulty": 3, + "description": "A k-mirror number is a positive integer without leading zeros that reads the same both forward and backward in base-10 as well as in base-k.\n\nFor example, 9 is a 2-mirror number. The representation of 9 in base-10 and base-2 are 9 and 1001 respectively, which read the same both forward and backward.\nOn the contrary, 4 is not a 2-mirror number. The representation of 4 in base-2 is 100, which does not read the same both forward and backward.\n\nGiven the base k and the number n, return the sum of the n smallest k-mirror numbers.", + "examples": [ + "Example 1:\nInput: k = 2, n = 5\nOutput: 25\nExplanation:\nThe 5 smallest 2-mirror numbers and their representations in base-2 are listed as follows:\n base-10 base-2\n 1 1\n 3 11\n 5 101\n 7 111\n 9 1001\nTheir sum = 1 + 3 + 5 + 7 + 9 = 25.", + "Example 2:\nInput: k = 3, n = 7\nOutput: 499\nExplanation:\nThe 7 smallest 3-mirror numbers are and their representations in base-3 are listed as follows:\n base-10 base-3\n 1 1\n 2 2\n 4 11\n 8 22\n 121 11111\n 151 12121\n 212 21212\nTheir sum = 1 + 2 + 4 + 8 + 121 + 151 + 212 = 499.", + "Example 3:\nInput: k = 7, n = 17\nOutput: 20379000\nExplanation: The 17 smallest 7-mirror numbers are:\n1, 2, 3, 4, 5, 6, 8, 121, 171, 242, 292, 16561, 65656, 2137312, 4602064, 6597956, 6958596" + ], + "constraints": "Constraints:\n\n2 <= k <= 9\n1 <= n <= 30", + "tags": [ + "Math", + "Enumeration" + ], + "title-slug": "sum-of-k-mirror-numbers" + }, + { + "leetcode-id": 2085, + "title": "Count Common Words With One Occurrence", + "difficulty": 1, + "description": "Given two string arrays words1 and words2, return the number of strings that appear exactly once in each\u00a0of the two arrays.", + "examples": [ + "Example 1:\nInput: words1 = [\"leetcode\",\"is\",\"amazing\",\"as\",\"is\"], words2 = [\"amazing\",\"leetcode\",\"is\"]\nOutput: 2\nExplanation:\n- \"leetcode\" appears exactly once in each of the two arrays. We count this string.\n- \"amazing\" appears exactly once in each of the two arrays. We count this string.\n- \"is\" appears in each of the two arrays, but there are 2 occurrences of it in words1. We do not count this string.\n- \"as\" appears once in words1, but does not appear in words2. We do not count this string.\nThus, there are 2 strings that appear exactly once in each of the two arrays.", + "Example 2:\nInput: words1 = [\"b\",\"bb\",\"bbb\"], words2 = [\"a\",\"aa\",\"aaa\"]\nOutput: 0\nExplanation: There are no strings that appear in each of the two arrays.", + "Example 3:\nInput: words1 = [\"a\",\"ab\"], words2 = [\"a\",\"a\",\"a\",\"ab\"]\nOutput: 1\nExplanation: The only string that appears exactly once in each of the two arrays is \"ab\"." + ], + "constraints": "Constraints:\n\n1 <= words1.length, words2.length <= 1000\n1 <= words1[i].length, words2[j].length <= 30\nwords1[i] and words2[j] consists only of lowercase English letters.", + "tags": [ + "Array", + "Hash Table", + "String", + "Counting" + ], + "title-slug": "count-common-words-with-one-occurrence" + }, + { + "leetcode-id": 2086, + "title": "Minimum Number of Food Buckets to Feed the Hamsters", + "difficulty": 2, + "description": "You are given a 0-indexed string hamsters where hamsters[i] is either:\n\n'H' indicating that there is a hamster at index i, or\n'.' indicating that index i is empty.\n\nYou will add some number of food buckets at the empty indices in order to feed the hamsters. A hamster can be fed if there is at least one food bucket to its left or to its right. More formally, a hamster at index i can be fed if you place a food bucket at index i - 1 and/or at index i + 1.\nReturn the minimum number of food buckets you should place at empty indices to feed all the hamsters or -1 if it is impossible to feed all of them.", + "examples": [ + "Example 1:\nInput: hamsters = \"H..H\"\nOutput: 2\nExplanation: We place two food buckets at indices 1 and 2.\nIt can be shown that if we place only one food bucket, one of the hamsters will not be fed.", + "Example 2:\nInput: hamsters = \".H.H.\"\nOutput: 1\nExplanation: We place one food bucket at index 2.", + "Example 3:\nInput: hamsters = \".HHH.\"\nOutput: -1\nExplanation: If we place a food bucket at every empty index as shown, the hamster at index 2 will not be able to eat." + ], + "constraints": "Constraints:\n\n1 <= hamsters.length <= 10^5\nhamsters[i] is either'H' or '.'.", + "tags": [ + "String", + "Dynamic Programming", + "Greedy" + ], + "title-slug": "minimum-number-of-food-buckets-to-feed-the-hamsters" + }, + { + "leetcode-id": 2087, + "title": "Minimum Cost Homecoming of a Robot in a Grid", + "difficulty": 2, + "description": "There is an m x n grid, where (0, 0) is the top-left cell and (m - 1, n - 1) is the bottom-right cell. You are given an integer array startPos where startPos = [startrow, startcol] indicates that initially, a robot is at the cell (startrow, startcol). You are also given an integer array homePos where homePos = [homerow, homecol] indicates that its home is at the cell (homerow, homecol).\nThe robot needs to go to its home. It can move one cell in four directions: left, right, up, or down, and it can not move outside the boundary. Every move incurs some cost. You are further given two 0-indexed integer arrays: rowCosts of length m and colCosts of length n.\n\nIf the robot moves up or down into a cell whose row is r, then this move costs rowCosts[r].\nIf the robot moves left or right into a cell whose column is c, then this move costs colCosts[c].\n\nReturn the minimum total cost for this robot to return home.", + "examples": [ + "Example 1:\nInput: startPos = [1, 0], homePos = [2, 3], rowCosts = [5, 4, 3], colCosts = [8, 2, 6, 7]\nOutput: 18\nExplanation: One optimal path is that:\nStarting from (1, 0)\n-> It goes down to (2, 0). This move costs rowCosts[2] = 3.\n-> It goes right to (2, 1). This move costs colCosts[1] = 2.\n-> It goes right to (2, 2). This move costs colCosts[2] = 6.\n-> It goes right to (2, 3). This move costs colCosts[3] = 7.\nThe total cost is 3 + 2 + 6 + 7 = 18", + "Example 2:\nInput: startPos = [0, 0], homePos = [0, 0], rowCosts = [5], colCosts = [26]\nOutput: 0\nExplanation: The robot is already at its home. Since no moves occur, the total cost is 0." + ], + "constraints": "Constraints:\n\nm == rowCosts.length\nn == colCosts.length\n1 <= m, n <= 10^5\n0 <= rowCosts[r], colCosts[c] <= 10^4\nstartPos.length == 2\nhomePos.length == 2\n0 <= startrow, homerow < m\n0 <= startcol, homecol < n", + "tags": [ + "Array", + "Greedy", + "Matrix" + ], + "title-slug": "minimum-cost-homecoming-of-a-robot-in-a-grid" + }, + { + "leetcode-id": 2088, + "title": "Count Fertile Pyramids in a Land", + "difficulty": 3, + "description": "A farmer has a rectangular grid of land with m rows and n columns that can be divided into unit cells. Each cell is either fertile (represented by a 1) or barren (represented by a 0). All cells outside the grid are considered barren.\nA pyramidal plot of land can be defined as a set of cells with the following criteria:\n\nThe number of cells in the set has to be greater than 1 and all cells must be fertile.\nThe apex of a pyramid is the topmost cell of the pyramid. The height of a pyramid is the number of rows it covers. Let (r, c) be the apex of the pyramid, and its height be h. Then, the plot comprises of cells (i, j) where r <= i <= r + h - 1 and c - (i - r) <= j <= c + (i - r).\n\nAn inverse pyramidal plot of land can be defined as a set of cells with similar criteria:\n\nThe number of cells in the set has to be greater than 1 and all cells must be fertile.\nThe apex of an inverse pyramid is the bottommost cell of the inverse pyramid. The height of an inverse pyramid is the number of rows it covers. Let (r, c) be the apex of the pyramid, and its height be h. Then, the plot comprises of cells (i, j) where r - h + 1 <= i <= r and c - (r - i) <= j <= c + (r - i).\n\nSome examples of valid and invalid pyramidal (and inverse pyramidal) plots are shown below. Black cells indicate fertile cells.\n\nGiven a 0-indexed m x n binary matrix grid representing the farmland, return the total number of pyramidal and inverse pyramidal plots that can be found in grid.", + "examples": [ + "Example 1:\nInput: grid = [[0,1,1,0],[1,1,1,1]]\nOutput: 2\nExplanation: The 2 possible pyramidal plots are shown in blue and red respectively.\nThere are no inverse pyramidal plots in this grid. \nHence total number of pyramidal and inverse pyramidal plots is 2 + 0 = 2.", + "Example 2:\nInput: grid = [[1,1,1],[1,1,1]]\nOutput: 2\nExplanation: The pyramidal plot is shown in blue, and the inverse pyramidal plot is shown in red. \nHence the total number of plots is 1 + 1 = 2.", + "Example 3:\nInput: grid = [[1,1,1,1,0],[1,1,1,1,1],[1,1,1,1,1],[0,1,0,0,1]]\nOutput: 13\nExplanation: There are 7 pyramidal plots, 3 of which are shown in the 2nd and 3rd figures.\nThere are 6 inverse pyramidal plots, 2 of which are shown in the last figure.\nThe total number of plots is 7 + 6 = 13." + ], + "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 1000\n1 <= m * n <= 10^5\ngrid[i][j] is either 0 or 1.", + "tags": [ + "Array", + "Dynamic Programming", + "Matrix" + ], + "title-slug": "count-fertile-pyramids-in-a-land" + }, + { + "leetcode-id": 2089, + "title": "Find Target Indices After Sorting Array", + "difficulty": 1, + "description": "You are given a 0-indexed integer array nums and a target element target.\nA target index is an index i such that nums[i] == target.\nReturn a list of the target indices of nums after sorting nums in non-decreasing order. If there are no target indices, return an empty list. The returned list must be sorted in increasing order.", + "examples": [ + "Example 1:\nInput: nums = [1,2,5,2,3], target = 2\nOutput: [1,2]\nExplanation: After sorting, nums is [1,2,2,3,5].\nThe indices where nums[i] == 2 are 1 and 2.", + "Example 2:\nInput: nums = [1,2,5,2,3], target = 3\nOutput: [3]\nExplanation: After sorting, nums is [1,2,2,3,5].\nThe index where nums[i] == 3 is 3.", + "Example 3:\nInput: nums = [1,2,5,2,3], target = 5\nOutput: [4]\nExplanation: After sorting, nums is [1,2,2,3,5].\nThe index where nums[i] == 5 is 4." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= nums[i], target <= 100", + "tags": [ + "Array", + "Binary Search", + "Sorting" + ], + "title-slug": "find-target-indices-after-sorting-array" + }, + { + "leetcode-id": 2090, + "title": "K Radius Subarray Averages", + "difficulty": 2, + "description": "You are given a 0-indexed array nums of n integers, and an integer k.\nThe k-radius average for a subarray of nums centered at some index i with the radius k is the average of all elements in nums between the indices i - k and i + k (inclusive). If there are less than k elements before or after the index i, then the k-radius average is -1.\nBuild and return an array avgs of length n where avgs[i] is the k-radius average for the subarray centered at index i.\nThe average of x elements is the sum of the x elements divided by x, using integer division. The integer division truncates toward zero, which means losing its fractional part.\n\nFor example, the average of four elements 2, 3, 1, and 5 is (2 + 3 + 1 + 5) / 4 = 11 / 4 = 2.75, which truncates to 2.", + "examples": [ + "Example 1:\nInput: nums = [7,4,3,9,1,8,5,2,6], k = 3\nOutput: [-1,-1,-1,5,4,4,-1,-1,-1]\nExplanation:\n- avg[0], avg[1], and avg[2] are -1 because there are less than k elements before each index.\n- The sum of the subarray centered at index 3 with radius 3 is: 7 + 4 + 3 + 9 + 1 + 8 + 5 = 37.\n Using integer division, avg[3] = 37 / 7 = 5.\n- For the subarray centered at index 4, avg[4] = (4 + 3 + 9 + 1 + 8 + 5 + 2) / 7 = 4.\n- For the subarray centered at index 5, avg[5] = (3 + 9 + 1 + 8 + 5 + 2 + 6) / 7 = 4.\n- avg[6], avg[7], and avg[8] are -1 because there are less than k elements after each index.", + "Example 2:\nInput: nums = [100000], k = 0\nOutput: [100000]\nExplanation:\n- The sum of the subarray centered at index 0 with radius 0 is: 100000.\n avg[0] = 100000 / 1 = 100000.", + "Example 3:\nInput: nums = [8], k = 100000\nOutput: [-1]\nExplanation: \n- avg[0] is -1 because there are less than k elements before and after index 0." + ], + "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^5\n0 <= nums[i], k <= 10^5", + "tags": [ + "Array", + "Sliding Window" + ], + "title-slug": "k-radius-subarray-averages" + }, + { + "leetcode-id": 2091, + "title": "Removing Minimum and Maximum From Array", + "difficulty": 2, + "description": "You are given a 0-indexed array of distinct integers nums.\nThere is an element in nums that has the lowest value and an element that has the highest value. We call them the minimum and maximum respectively. Your goal is to remove both these elements from the array.\nA deletion is defined as either removing an element from the front of the array or removing an element from the back of the array.\nReturn the minimum number of deletions it would take to remove both the minimum and maximum element from the array.", + "examples": [ + "Example 1:\nInput: nums = [2,10,7,5,4,1,8,6]\nOutput: 5\nExplanation: \nThe minimum element in the array is nums[5], which is 1.\nThe maximum element in the array is nums[1], which is 10.\nWe can remove both the minimum and maximum by removing 2 elements from the front and 3 elements from the back.\nThis results in 2 + 3 = 5 deletions, which is the minimum number possible.", + "Example 2:\nInput: nums = [0,-4,19,1,8,-2,-3,5]\nOutput: 3\nExplanation: \nThe minimum element in the array is nums[1], which is -4.\nThe maximum element in the array is nums[2], which is 19.\nWe can remove both the minimum and maximum by removing 3 elements from the front.\nThis results in only 3 deletions, which is the minimum number possible.", + "Example 3:\nInput: nums = [101]\nOutput: 1\nExplanation: \nThere is only one element in the array, which makes it both the minimum and maximum element.\nWe can remove it with 1 deletion." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^5 <= nums[i] <= 10^5\nThe integers in nums are distinct.", + "tags": [ + "Array", + "Greedy" + ], + "title-slug": "removing-minimum-and-maximum-from-array" + }, + { + "leetcode-id": 2092, + "title": "Find All People With Secret", + "difficulty": 3, + "description": "You are given an integer n indicating there are n people numbered from 0 to n - 1. You are also given a 0-indexed 2D integer array meetings where meetings[i] = [xi, yi, timei] indicates that person xi and person yi have a meeting at timei. A person may attend multiple meetings at the same time. Finally, you are given an integer firstPerson.\nPerson 0 has a secret and initially shares the secret with a person firstPerson at time 0. This secret is then shared every time a meeting takes place with a person that has the secret. More formally, for every meeting, if a person xi has the secret at timei, then they will share the secret with person yi, and vice versa.\nThe secrets are shared instantaneously. That is, a person may receive the secret and share it with people in other meetings within the same time frame.\nReturn a list of all the people that have the secret after all the meetings have taken place. You may return the answer in any order.", + "examples": [ + "Example 1:\nInput: n = 6, meetings = [[1,2,5],[2,3,8],[1,5,10]], firstPerson = 1\nOutput: [0,1,2,3,5]\nExplanation:\nAt time 0, person 0 shares the secret with person 1.\nAt time 5, person 1 shares the secret with person 2.\nAt time 8, person 2 shares the secret with person 3.\nAt time 10, person 1 shares the secret with person 5.\u200b\u200b\u200b\u200b\nThus, people 0, 1, 2, 3, and 5 know the secret after all the meetings.", + "Example 2:\nInput: n = 4, meetings = [[3,1,3],[1,2,2],[0,3,3]], firstPerson = 3\nOutput: [0,1,3]\nExplanation:\nAt time 0, person 0 shares the secret with person 3.\nAt time 2, neither person 1 nor person 2 know the secret.\nAt time 3, person 3 shares the secret with person 0 and person 1.\nThus, people 0, 1, and 3 know the secret after all the meetings.", + "Example 3:\nInput: n = 5, meetings = [[3,4,2],[1,2,1],[2,3,1]], firstPerson = 1\nOutput: [0,1,2,3,4]\nExplanation:\nAt time 0, person 0 shares the secret with person 1.\nAt time 1, person 1 shares the secret with person 2, and person 2 shares the secret with person 3.\nNote that person 2 can share the secret at the same time as receiving it.\nAt time 2, person 3 shares the secret with person 4.\nThus, people 0, 1, 2, 3, and 4 know the secret after all the meetings." + ], + "constraints": "Constraints:\n\n2 <= n <= 10^5\n1 <= meetings.length <= 10^5\nmeetings[i].length == 3\n0 <= xi, yi <= n - 1\nxi != yi\n1 <= timei <= 10^5\n1 <= firstPerson <= n - 1", + "tags": [ + "Depth-First Search", + "Breadth-First Search", + "Union Find", + "Graph", + "Sorting" + ], + "title-slug": "find-all-people-with-secret" + }, + { + "leetcode-id": 2094, + "title": "Finding 3-Digit Even Numbers", + "difficulty": 1, + "description": "You are given an integer array digits, where each element is a digit. The array may contain duplicates.\nYou need to find all the unique integers that follow the given requirements:\n\nThe integer consists of the concatenation of three elements from digits in any arbitrary order.\nThe integer does not have leading zeros.\nThe integer is even.\n\nFor example, if the given digits were [1, 2, 3], integers 132 and 312 follow the requirements.\nReturn a sorted array of the unique integers.", + "examples": [ + "Example 1:\nInput: digits = [2,1,3,0]\nOutput: [102,120,130,132,210,230,302,310,312,320]\nExplanation: All the possible integers that follow the requirements are in the output array. \nNotice that there are no odd integers or integers with leading zeros.", + "Example 2:\nInput: digits = [2,2,8,8,2]\nOutput: [222,228,282,288,822,828,882]\nExplanation: The same digit can be used as many times as it appears in digits. \nIn this example, the digit 8 is used twice each time in 288, 828, and 882.", + "Example 3:\nInput: digits = [3,7,5]\nOutput: []\nExplanation: No even integers can be formed using the given digits." + ], + "constraints": "Constraints:\n\n3 <= digits.length <= 100\n0 <= digits[i] <= 9", + "tags": [ + "Array", + "Hash Table", + "Sorting", + "Enumeration" + ], + "title-slug": "finding-3-digit-even-numbers" + }, + { + "leetcode-id": 2095, + "title": "Delete the Middle Node of a Linked List", + "difficulty": 2, + "description": "You are given the head of a linked list. Delete the middle node, and return the head of the modified linked list.\nThe middle node of a linked list of size n is the \u230an / 2\u230b^th node from the start using 0-based indexing, where \u230ax\u230b denotes the largest integer less than or equal to x.\n\nFor n = 1, 2, 3, 4, and 5, the middle nodes are 0, 1, 1, 2, and 2, respectively.", + "examples": [ + "Example 1:\nInput: head = [1,3,4,7,1,2,6]\nOutput: [1,3,4,1,2,6]\nExplanation:\nThe above figure represents the given linked list. The indices of the nodes are written below.\nSince n = 7, node 3 with value 7 is the middle node, which is marked in red.\nWe return the new list after removing this node.", + "Example 2:\nInput: head = [1,2,3,4]\nOutput: [1,2,4]\nExplanation:\nThe above figure represents the given linked list.\nFor n = 4, node 2 with value 3 is the middle node, which is marked in red.", + "Example 3:\nInput: head = [2,1]\nOutput: [2]\nExplanation:\nThe above figure represents the given linked list.\nFor n = 2, node 1 with value 1 is the middle node, which is marked in red.\nNode 0 with value 2 is the only node remaining after removing node 1." + ], + "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [1, 10^5].\n1 <= Node.val <= 10^5", + "tags": [ + "Linked List", + "Two Pointers" + ], + "title-slug": "delete-the-middle-node-of-a-linked-list" + }, + { + "leetcode-id": 2096, + "title": "Step-By-Step Directions From a Binary Tree Node to Another", + "difficulty": 2, + "description": "You are given the root of a binary tree with n nodes. Each node is uniquely assigned a value from 1 to n. You are also given an integer startValue representing the value of the start node s, and a different integer destValue representing the value of the destination node t.\nFind the shortest path starting from node s and ending at node t. Generate step-by-step directions of such path as a string consisting of only the uppercase letters 'L', 'R', and 'U'. Each letter indicates a specific direction:\n\n'L' means to go from a node to its left child node.\n'R' means to go from a node to its right child node.\n'U' means to go from a node to its parent node.\n\nReturn the step-by-step directions of the shortest path from node s to node t.", + "examples": [ + "Example 1:\nInput: root = [5,1,2,3,null,6,4], startValue = 3, destValue = 6\nOutput: \"UURL\"\nExplanation: The shortest path is: 3 \u2192 1 \u2192 5 \u2192 2 \u2192 6.", + "Example 2:\nInput: root = [2,1], startValue = 2, destValue = 1\nOutput: \"L\"\nExplanation: The shortest path is: 2 \u2192 1." + ], + "constraints": "Constraints:\n\nThe number of nodes in the tree is n.\n2 <= n <= 10^5\n1 <= Node.val <= n\nAll the values in the tree are unique.\n1 <= startValue, destValue <= n\nstartValue != destValue", + "tags": [ + "String", + "Tree", + "Depth-First Search", + "Binary Tree" + ], + "title-slug": "step-by-step-directions-from-a-binary-tree-node-to-another" + }, + { + "leetcode-id": 2097, + "title": "Valid Arrangement of Pairs", + "difficulty": 3, + "description": "You are given a 0-indexed 2D integer array pairs where pairs[i] = [starti, endi]. An arrangement of pairs is valid if for every index i where 1 <= i < pairs.length, we have endi-1 == starti.\nReturn any valid arrangement of pairs.\nNote: The inputs will be generated such that there exists a valid arrangement of pairs.", + "examples": [ + "Example 1:\nInput: pairs = [[5,1],[4,5],[11,9],[9,4]]\nOutput: [[11,9],[9,4],[4,5],[5,1]]\nExplanation:\nThis is a valid arrangement since endi-1 always equals starti.\nend0 = 9 == 9 = start1 \nend1 = 4 == 4 = start2\nend2 = 5 == 5 = start3", + "Example 2:\nInput: pairs = [[1,3],[3,2],[2,1]]\nOutput: [[1,3],[3,2],[2,1]]\nExplanation:\nThis is a valid arrangement since endi-1 always equals starti.\nend0 = 3 == 3 = start1\nend1 = 2 == 2 = start2\nThe arrangements [[2,1],[1,3],[3,2]] and [[3,2],[2,1],[1,3]] are also valid.", + "Example 3:\nInput: pairs = [[1,2],[1,3],[2,1]]\nOutput: [[1,2],[2,1],[1,3]]\nExplanation:\nThis is a valid arrangement since endi-1 always equals starti.\nend0 = 2 == 2 = start1\nend1 = 1 == 1 = start2" + ], + "constraints": "Constraints:\n\n1 <= pairs.length <= 10^5\npairs[i].length == 2\n0 <= starti, endi <= 10^9\nstarti != endi\nNo two pairs are exactly the same.\nThere exists a valid arrangement of pairs.", + "tags": [ + "Depth-First Search", + "Graph", + "Eulerian Circuit" + ], + "title-slug": "valid-arrangement-of-pairs" + }, + { + "leetcode-id": 2099, + "title": "Find Subsequence of Length K With the Largest Sum", + "difficulty": 1, + "description": "You are given an integer array nums and an integer k. You want to find a subsequence of nums of length k that has the largest sum.\nReturn any such subsequence as an integer array of length k.\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.", + "examples": [ + "Example 1:\nInput: nums = [2,1,3,3], k = 2\nOutput: [3,3]\nExplanation:\nThe subsequence has the largest sum of 3 + 3 = 6.", + "Example 2:\nInput: nums = [-1,-2,3,4], k = 3\nOutput: [-1,3,4]\nExplanation: \nThe subsequence has the largest sum of -1 + 3 + 4 = 6.", + "Example 3:\nInput: nums = [3,4,3,3], k = 2\nOutput: [3,4]\nExplanation:\nThe subsequence has the largest sum of 3 + 4 = 7. \nAnother possible subsequence is [4, 3]." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n-10^5\u00a0<= nums[i] <= 10^5\n1 <= k <= nums.length", + "tags": [ + "Array", + "Hash Table", + "Sorting", + "Heap (Priority Queue)" + ], + "title-slug": "find-subsequence-of-length-k-with-the-largest-sum" + }, + { + "leetcode-id": 2100, + "title": "Find Good Days to Rob the Bank", + "difficulty": 2, + "description": "You and a gang of thieves are planning on robbing a bank. You are given a 0-indexed integer array security, where security[i] is the number of guards on duty on the i^th day. The days are numbered starting from 0. You are also given an integer time.\nThe i^th day is a good day to rob the bank if:\n\nThere are at least time days before and after the i^th day,\nThe number of guards at the bank for the time days before i are non-increasing, and\nThe number of guards at the bank for the time days after i are non-decreasing.\n\nMore formally, this means day i is a good day to rob the bank if and only if security[i - time] >= security[i - time + 1] >= ... >= security[i] <= ... <= security[i + time - 1] <= security[i + time].\nReturn a list of all days (0-indexed) that are good days to rob the bank. The order that the days are returned in does not matter.", + "examples": [ + "Example 1:\nInput: security = [5,3,3,3,5,6,2], time = 2\nOutput: [2,3]\nExplanation:\nOn day 2, we have security[0] >= security[1] >= security[2] <= security[3] <= security[4].\nOn day 3, we have security[1] >= security[2] >= security[3] <= security[4] <= security[5].\nNo other days satisfy this condition, so days 2 and 3 are the only good days to rob the bank.", + "Example 2:\nInput: security = [1,1,1,1,1], time = 0\nOutput: [0,1,2,3,4]\nExplanation:\nSince time equals 0, every day is a good day to rob the bank, so return every day.", + "Example 3:\nInput: security = [1,2,3,4,5,6], time = 2\nOutput: []\nExplanation:\nNo day has 2 days before it that have a non-increasing number of guards.\nThus, no day is a good day to rob the bank, so return an empty list." + ], + "constraints": "Constraints:\n\n1 <= security.length <= 10^5\n0 <= security[i], time <= 10^5", + "tags": [ + "Array", + "Dynamic Programming", + "Prefix Sum" + ], + "title-slug": "find-good-days-to-rob-the-bank" + }, + { + "leetcode-id": 2101, + "title": "Detonate the Maximum Bombs", + "difficulty": 2, + "description": "You are given a list of bombs. The range of a bomb is defined as the area where its effect can be felt. This area is in the shape of a circle with the center as the location of the bomb.\nThe bombs are represented by a 0-indexed 2D integer array bombs where bombs[i] = [xi, yi, ri]. xi and yi denote the X-coordinate and Y-coordinate of the location of the i^th bomb, whereas ri denotes the radius of its range.\nYou may choose to detonate a single bomb. When a bomb is detonated, it will detonate all bombs that lie in its range. These bombs will further detonate the bombs that lie in their ranges.\nGiven the list of bombs, return the maximum number of bombs that can be detonated if you are allowed to detonate only one bomb.", + "examples": [ + "Example 1:\nInput: bombs = [[2,1,3],[6,1,4]]\nOutput: 2\nExplanation:\nThe above figure shows the positions and ranges of the 2 bombs.\nIf we detonate the left bomb, the right bomb will not be affected.\nBut if we detonate the right bomb, both bombs will be detonated.\nSo the maximum bombs that can be detonated is max(1, 2) = 2.", + "Example 2:\nInput: bombs = [[1,1,5],[10,10,5]]\nOutput: 1\nExplanation:\nDetonating either bomb will not detonate the other bomb, so the maximum number of bombs that can be detonated is 1.", + "Example 3:\nInput: bombs = [[1,2,3],[2,3,1],[3,4,2],[4,5,3],[5,6,4]]\nOutput: 5\nExplanation:\nThe best bomb to detonate is bomb 0 because:\n- Bomb 0 detonates bombs 1 and 2. The red circle denotes the range of bomb 0.\n- Bomb 2 detonates bomb 3. The blue circle denotes the range of bomb 2.\n- Bomb 3 detonates bomb 4. The green circle denotes the range of bomb 3.\nThus all 5 bombs are detonated." + ], + "constraints": "Constraints:\n\n1 <= bombs.length\u00a0<= 100\nbombs[i].length == 3\n1 <= xi, yi, ri <= 10^5", + "tags": [ + "Array", + "Math", + "Depth-First Search", + "Breadth-First Search", + "Graph", + "Geometry" + ], + "title-slug": "detonate-the-maximum-bombs" + }, + { + "leetcode-id": 2102, + "title": "Sequentially Ordinal Rank Tracker", + "difficulty": 3, + "description": "A scenic location is represented by its name and attractiveness score, where name is a unique string among all locations and score is an integer. Locations can be ranked from the best to the worst. The higher the score, the better the location. If the scores of two locations are equal, then the location with the lexicographically smaller name is better.\nYou are building a system that tracks the ranking of locations with the system initially starting with no locations. It supports:\n\nAdding scenic locations, one at a time.\nQuerying the i^th best location of all locations already added, where i is the number of times the system has been queried (including the current query).\n\t\nFor example, when the system is queried for the 4^th time, it returns the 4^th best location of all locations already added.\n\n\n\nNote that the test data are generated so that at any time, the number of queries does not exceed the number of locations added to the system.\nImplement the SORTracker class:\n\nSORTracker() Initializes the tracker system.\nvoid add(string name, int score) Adds a scenic location with name and score to the system.\nstring get() Queries and returns the i^th best location, where i is the number of times this method has been invoked (including this invocation).", + "examples": [ + "Example 1:\nInput\n[\"SORTracker\", \"add\", \"add\", \"get\", \"add\", \"get\", \"add\", \"get\", \"add\", \"get\", \"add\", \"get\", \"get\"]\n[[], [\"bradford\", 2], [\"branford\", 3], [], [\"alps\", 2], [], [\"orland\", 2], [], [\"orlando\", 3], [], [\"alpine\", 2], [], []]\nOutput\n[null, null, null, \"branford\", null, \"alps\", null, \"bradford\", null, \"bradford\", null, \"bradford\", \"orland\"]\n\nExplanation\nSORTracker tracker = new SORTracker(); // Initialize the tracker system.\ntracker.add(\"bradford\", 2); // Add location with name=\"bradford\" and score=2 to the system.\ntracker.add(\"branford\", 3); // Add location with name=\"branford\" and score=3 to the system.\ntracker.get(); // The sorted locations, from best to worst, are: branford, bradford.\n // Note that branford precedes bradford due to its higher score (3 > 2).\n // This is the 1^st time get() is called, so return the best location: \"branford\".\ntracker.add(\"alps\", 2); // Add location with name=\"alps\" and score=2 to the system.\ntracker.get(); // Sorted locations: branford, alps, bradford.\n // Note that alps precedes bradford even though they have the same score (2).\n // This is because \"alps\" is lexicographically smaller than \"bradford\".\n // Return the 2^nd best location \"alps\", as it is the 2^nd time get() is called.\ntracker.add(\"orland\", 2); // Add location with name=\"orland\" and score=2 to the system.\ntracker.get(); // Sorted locations: branford, alps, bradford, orland.\n // Return \"bradford\", as it is the 3^rd time get() is called.\ntracker.add(\"orlando\", 3); // Add location with name=\"orlando\" and score=3 to the system.\ntracker.get(); // Sorted locations: branford, orlando, alps, bradford, orland.\n // Return \"bradford\".\ntracker.add(\"alpine\", 2); // Add location with name=\"alpine\" and score=2 to the system.\ntracker.get(); // Sorted locations: branford, orlando, alpine, alps, bradford, orland.\n // Return \"bradford\".\ntracker.get(); // Sorted locations: branford, orlando, alpine, alps, bradford, orland.\n // Return \"orland\"." + ], + "constraints": "Constraints:\n\nname consists of lowercase English letters, and is unique among all locations.\n1 <= name.length <= 10\n1 <= score <= 10^5\nAt any time, the number of calls to get does not exceed the number of calls to add.\nAt most 4 * 10^4 calls in total will be made to add and get.", + "tags": [ + "Design", + "Heap (Priority Queue)", + "Data Stream", + "Ordered Set" + ], + "title-slug": "sequentially-ordinal-rank-tracker" + }, + { + "leetcode-id": 2103, + "title": "Rings and Rods", + "difficulty": 1, + "description": "There are n rings and each ring is either red, green, or blue. The rings are distributed across ten rods labeled from 0 to 9.\nYou are given a string rings of length 2n that describes the n rings that are placed onto the rods. Every two characters in rings forms a color-position pair that is used to describe each ring where:\n\nThe first character of the i^th pair denotes the i^th ring's color ('R', 'G', 'B').\nThe second character of the i^th pair denotes the rod that the i^th ring is placed on ('0' to '9').\n\nFor example, \"R3G2B1\" describes n == 3 rings: a red ring placed onto the rod labeled 3, a green ring placed onto the rod labeled 2, and a blue ring placed onto the rod labeled 1.\nReturn the number of rods that have all three colors of rings on them.", + "examples": [ + "Example 1:\nInput: rings = \"B0B6G0R6R0R6G9\"\nOutput: 1\nExplanation: \n- The rod labeled 0 holds 3 rings with all colors: red, green, and blue.\n- The rod labeled 6 holds 3 rings, but it only has red and blue.\n- The rod labeled 9 holds only a green ring.\nThus, the number of rods with all three colors is 1.", + "Example 2:\nInput: rings = \"B0R0G0R9R0B0G0\"\nOutput: 1\nExplanation: \n- The rod labeled 0 holds 6 rings with all colors: red, green, and blue.\n- The rod labeled 9 holds only a red ring.\nThus, the number of rods with all three colors is 1.", + "Example 3:\nInput: rings = \"G4\"\nOutput: 0\nExplanation: \nOnly one ring is given. Thus, no rods have all three colors." + ], + "constraints": "Constraints:\n\nrings.length == 2 * n\n1 <= n <= 100\nrings[i] where i is even is either 'R', 'G', or 'B' (0-indexed).\nrings[i] where i is odd is a digit from '0' to '9' (0-indexed).", + "tags": [ + "Hash Table", + "String" + ], + "title-slug": "rings-and-rods" + }, + { + "leetcode-id": 2104, + "title": "Sum of Subarray Ranges", + "difficulty": 2, + "description": "You are given an integer array nums. The range of a subarray of nums is the difference between the largest and smallest element in the subarray.\nReturn the sum of all subarray ranges of nums.\nA subarray is a contiguous non-empty sequence of elements within an array.", + "examples": [ + "Example 1:\nInput: nums = [1,2,3]\nOutput: 4\nExplanation: The 6 subarrays of nums are the following:\n[1], range = largest - smallest = 1 - 1 = 0 \n[2], range = 2 - 2 = 0\n[3], range = 3 - 3 = 0\n[1,2], range = 2 - 1 = 1\n[2,3], range = 3 - 2 = 1\n[1,2,3], range = 3 - 1 = 2\nSo the sum of all ranges is 0 + 0 + 0 + 1 + 1 + 2 = 4.", + "Example 2:\nInput: nums = [1,3,3]\nOutput: 4\nExplanation: The 6 subarrays of nums are the following:\n[1], range = largest - smallest = 1 - 1 = 0\n[3], range = 3 - 3 = 0\n[3], range = 3 - 3 = 0\n[1,3], range = 3 - 1 = 2\n[3,3], range = 3 - 3 = 0\n[1,3,3], range = 3 - 1 = 2\nSo the sum of all ranges is 0 + 0 + 0 + 2 + 0 + 2 = 4.", + "Example 3:\nInput: nums = [4,-2,-3,4,1]\nOutput: 59\nExplanation: The sum of all subarray ranges of nums is 59." + ], + "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n-10^9 <= nums[i] <= 10^9\n\n\u00a0\nFollow-up: Could you find a solution with O(n) time complexity?", + "tags": [ + "Array", + "Stack", + "Monotonic Stack" + ], + "title-slug": "sum-of-subarray-ranges" + }, + { + "leetcode-id": 2105, + "title": "Watering Plants II", + "difficulty": 2, + "description": "Alice and Bob want to water n plants in their garden. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the i^th plant is located at x = i.\nEach plant needs a specific amount of water. Alice and Bob have a watering can each, initially full. They water the plants in the following way:\n\nAlice waters the plants in order from left to right, starting from the 0^th plant. Bob waters the plants in order from right to left, starting from the (n - 1)^th plant. They begin watering the plants simultaneously.\nIt takes the same amount of time to water each plant regardless of how much water it needs.\nAlice/Bob must water the plant if they have enough in their can to fully water it. Otherwise, they first refill their can (instantaneously) then water the plant.\nIn case both Alice and Bob reach the same plant, the one with more water currently in his/her watering can should water this plant. If they have the same amount of water, then Alice should water this plant.\n\nGiven a 0-indexed integer array plants of n integers, where plants[i] is the amount of water the i^th plant needs, and two integers capacityA and capacityB representing the capacities of Alice's and Bob's watering cans respectively, return the number of times they have to refill to water all the plants.", + "examples": [ + "Example 1:\nInput: plants = [2,2,3,3], capacityA = 5, capacityB = 5\nOutput: 1\nExplanation:\n- Initially, Alice and Bob have 5 units of water each in their watering cans.\n- Alice waters plant 0, Bob waters plant 3.\n- Alice and Bob now have 3 units and 2 units of water respectively.\n- Alice has enough water for plant 1, so she waters it. Bob does not have enough water for plant 2, so he refills his can then waters it.\nSo, the total number of times they have to refill to water all the plants is 0 + 0 + 1 + 0 = 1.", + "Example 2:\nInput: plants = [2,2,3,3], capacityA = 3, capacityB = 4\nOutput: 2\nExplanation:\n- Initially, Alice and Bob have 3 units and 4 units of water in their watering cans respectively.\n- Alice waters plant 0, Bob waters plant 3.\n- Alice and Bob now have 1 unit of water each, and need to water plants 1 and 2 respectively.\n- Since neither of them have enough water for their current plants, they refill their cans and then water the plants.\nSo, the total number of times they have to refill to water all the plants is 0 + 1 + 1 + 0 = 2.", + "Example 3:\nInput: plants = [5], capacityA = 10, capacityB = 8\nOutput: 0\nExplanation:\n- There is only one plant.\n- Alice's watering can has 10 units of water, whereas Bob's can has 8 units. Since Alice has more water in her can, she waters this plant.\nSo, the total number of times they have to refill is 0." + ], + "constraints": "Constraints:\n\nn == plants.length\n1 <= n <= 10^5\n1 <= plants[i] <= 10^6\nmax(plants[i]) <= capacityA, capacityB <= 10^9", + "tags": [ + "Array", + "Two Pointers", + "Simulation" + ], + "title-slug": "watering-plants-ii" + }, + { + "leetcode-id": 2106, + "title": "Maximum Fruits Harvested After at Most K Steps", + "difficulty": 3, + "description": "Fruits are available at some positions on an infinite x-axis. You are given a 2D integer array fruits where fruits[i] = [positioni, amounti] depicts amounti fruits at the position positioni. fruits is already sorted by positioni in ascending order, and each positioni is unique.\nYou are also given an integer startPos and an integer k. Initially, you are at the position startPos. From any position, you can either walk to the left or right. It takes one step to move one unit on the x-axis, and you can walk at most k steps in total. For every position you reach, you harvest all the fruits at that position, and the fruits will disappear from that position.\nReturn the maximum total number of fruits you can harvest.", + "examples": [ + "Example 1:\nInput: fruits = [[2,8],[6,3],[8,6]], startPos = 5, k = 4\nOutput: 9\nExplanation: \nThe optimal way is to:\n- Move right to position 6 and harvest 3 fruits\n- Move right to position 8 and harvest 6 fruits\nYou moved 3 steps and harvested 3 + 6 = 9 fruits in total.", + "Example 2:\nInput: fruits = [[0,9],[4,1],[5,7],[6,2],[7,4],[10,9]], startPos = 5, k = 4\nOutput: 14\nExplanation: \nYou can move at most k = 4 steps, so you cannot reach position 0 nor 10.\nThe optimal way is to:\n- Harvest the 7 fruits at the starting position 5\n- Move left to position 4 and harvest 1 fruit\n- Move right to position 6 and harvest 2 fruits\n- Move right to position 7 and harvest 4 fruits\nYou moved 1 + 3 = 4 steps and harvested 7 + 1 + 2 + 4 = 14 fruits in total.", + "Example 3:\nInput: fruits = [[0,3],[6,4],[8,5]], startPos = 3, k = 2\nOutput: 0\nExplanation:\nYou can move at most k = 2 steps and cannot reach any position with fruits." + ], + "constraints": "Constraints:\n\n1 <= fruits.length <= 10^5\nfruits[i].length == 2\n0 <= startPos, positioni <= 2 * 10^5\npositioni-1 < positioni for any i > 0\u00a0(0-indexed)\n1 <= amounti <= 10^4\n0 <= k <= 2 * 10^5", + "tags": [ + "Array", + "Binary Search", + "Sliding Window", + "Prefix Sum" + ], + "title-slug": "maximum-fruits-harvested-after-at-most-k-steps" + }, + { + "leetcode-id": 2108, + "title": "Find First Palindromic String in the Array", + "difficulty": 1, + "description": "Given an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string \"\".\nA string is palindromic if it reads the same forward and backward.", + "examples": [ + "Example 1:\nInput: words = [\"abc\",\"car\",\"ada\",\"racecar\",\"cool\"]\nOutput: \"ada\"\nExplanation: The first string that is palindromic is \"ada\".\nNote that \"racecar\" is also palindromic, but it is not the first.", + "Example 2:\nInput: words = [\"notapalindrome\",\"racecar\"]\nOutput: \"racecar\"\nExplanation: The first and only string that is palindromic is \"racecar\".", + "Example 3:\nInput: words = [\"def\",\"ghi\"]\nOutput: \"\"\nExplanation: There are no palindromic strings, so the empty string is returned." + ], + "constraints": "Constraints:\n\n1 <= words.length <= 100\n1 <= words[i].length <= 100\nwords[i] consists only of lowercase English letters.", + "tags": [ + "Array", + "Two Pointers", + "String" + ], + "title-slug": "find-first-palindromic-string-in-the-array" + }, + { + "leetcode-id": 2109, + "title": "Adding Spaces to a String", + "difficulty": 2, + "description": "You are given a 0-indexed string s and a 0-indexed integer array spaces that describes the indices in the original string where spaces will be added. Each space should be inserted before the character at the given index.\n\nFor example, given s = \"EnjoyYourCoffee\" and spaces = [5, 9], we place spaces before 'Y' and 'C', which are at indices 5 and 9 respectively. Thus, we obtain \"Enjoy Your Coffee\".\n\nReturn the modified string after the spaces have been added.", + "examples": [ + "Example 1:\nInput: s = \"LeetcodeHelpsMeLearn\", spaces = [8,13,15]\nOutput: \"Leetcode Helps Me Learn\"\nExplanation: \nThe indices 8, 13, and 15 correspond to the underlined characters in \"LeetcodeHelpsMeLearn\".\nWe then place spaces before those characters.", + "Example 2:\nInput: s = \"icodeinpython\", spaces = [1,5,7,9]\nOutput: \"i code in py thon\"\nExplanation:\nThe indices 1, 5, 7, and 9 correspond to the underlined characters in \"icodeinpython\".\nWe then place spaces before those characters.", + "Example 3:\nInput: s = \"spacing\", spaces = [0,1,2,3,4,5,6]\nOutput: \" s p a c i n g\"\nExplanation:\nWe are also able to place spaces before the first character of the string." + ], + "constraints": "Constraints:\n\n1 <= s.length <= 3 * 10^5\ns consists only of lowercase and uppercase English letters.\n1 <= spaces.length <= 3 * 10^5\n0 <= spaces[i] <= s.length - 1\nAll the values of spaces are strictly increasing.", + "tags": [ + "Array", + "String", + "Simulation" + ], + "title-slug": "adding-spaces-to-a-string" + }, + { + "leetcode-id": 2110, + "title": "Number of Smooth Descent Periods of a Stock", + "difficulty": 2, + "description": "You are given an integer array prices representing the daily price history of a stock, where prices[i] is the stock price on the i^th day.\nA smooth descent period of a stock consists of one or more contiguous days such that the price on each day is lower than the price on the preceding day by exactly 1. The first day of the period is exempted from this rule.\nReturn the number of smooth descent periods.", + "examples": [ + "Example 1:\nInput: prices = [3,2,1,4]\nOutput: 7\nExplanation: There are 7 smooth descent periods:\n[3], [2], [1], [4], [3,2], [2,1], and [3,2,1]\nNote that a period with one day is a smooth descent period by the definition.", + "Example 2:\nInput: prices = [8,6,7,7]\nOutput: 4\nExplanation: There are 4 smooth descent periods: [8], [6], [7], and [7]\nNote that [8,6] is not a smooth descent period as 8 - 6 \u2260 1.", + "Example 3:\nInput: prices = [1]\nOutput: 1\nExplanation: There is 1 smooth descent period: [1]" + ], + "constraints": "Constraints:\n\n1 <= prices.length <= 10^5\n1 <= prices[i] <= 10^5", + "tags": [ + "Array", + "Math", + "Dynamic Programming" + ], + "title-slug": "number-of-smooth-descent-periods-of-a-stock" + }, + { + "leetcode-id": 2111, + "title": "Minimum Operations to Make the Array K-Increasing", + "difficulty": 3, + "description": "You are given a 0-indexed array arr consisting of n positive integers, and a positive integer k.\nThe array arr is called K-increasing if arr[i-k] <= arr[i] holds for every index i, where k <= i <= n-1.\n\nFor example, arr = [4, 1, 5, 2, 6, 2] is K-increasing for k = 2 because:\n\n\t\narr[0] <= arr[2] (4 <= 5)\narr[1] <= arr[3] (1 <= 2)\narr[2] <= arr[4] (5 <= 6)\narr[3] <= arr[5] (2 <= 2)\n\n\nHowever, the same arr is not K-increasing for k = 1 (because arr[0] > arr[1]) or k = 3 (because arr[0] > arr[3]).\n\nIn one operation, you can choose an index i and change arr[i] into any positive integer.\nReturn the minimum number of operations required to make the array K-increasing for the given k.", + "examples": [ + "Example 1:\nInput: arr = [5,4,3,2,1], k = 1\nOutput: 4\nExplanation:\nFor k = 1, the resultant array has to be non-decreasing.\nSome of the K-increasing arrays that can be formed are [5,6,7,8,9], [1,1,1,1,1], [2,2,3,4,4]. All of them require 4 operations.\nIt is suboptimal to change the array to, for example, [6,7,8,9,10] because it would take 5 operations.\nIt can be shown that we cannot make the array K-increasing in less than 4 operations.", + "Example 2:\nInput: arr = [4,1,5,2,6,2], k = 2\nOutput: 0\nExplanation:\nThis is the same example as the one in the problem description.\nHere, for every index i where 2 <= i <= 5, arr[i-2] <= arr[i].\nSince the given array is already K-increasing, we do not need to perform any operations.", + "Example 3:\nInput: arr = [4,1,5,2,6,2], k = 3\nOutput: 2\nExplanation:\nIndices 3 and 5 are the only ones not satisfying arr[i-3] <= arr[i] for 3 <= i <= 5.\nOne of the ways we can make the array K-increasing is by changing arr[3] to 4 and arr[5] to 5.\nThe array will now be [4,1,5,4,6,5].\nNote that there can be other ways to make the array K-increasing, but none of them require less than 2 operations." + ], + "constraints": "Constraints:\n\n1 <= arr.length <= 10^5\n1 <= arr[i], k <= arr.length", + "tags": [ + "Array", + "Binary Search" + ], + "title-slug": "minimum-operations-to-make-the-array-k-increasing" + }, + { + "leetcode-id": 2114, + "title": "Maximum Number of Words Found in Sentences", + "difficulty": 1, + "description": "A sentence is a list of words that are separated by a single space\u00a0with no leading or trailing spaces.\nYou are given an array of strings sentences, where each sentences[i] represents a single sentence.\nReturn the maximum number of words that appear in a single sentence.", + "examples": [ + "Example 1:\nInput: sentences = [\"alice and bob love leetcode\", \"i think so too\", \"this is great thanks very much\"]\nOutput: 6\nExplanation: \n- The first sentence, \"alice and bob love leetcode\", has 5 words in total.\n- The second sentence, \"i think so too\", has 4 words in total.\n- The third sentence, \"this is great thanks very much\", has 6 words in total.\nThus, the maximum number of words in a single sentence comes from the third sentence, which has 6 words.", + "Example 2:\nInput: sentences = [\"please wait\", \"continue to fight\", \"continue to win\"]\nOutput: 3\nExplanation: It is possible that multiple sentences contain the same number of words. \nIn this example, the second and third sentences (underlined) have the same number of words." + ], + "constraints": "Constraints:\n\n1 <= sentences.length <= 100\n1 <= sentences[i].length <= 100\nsentences[i] consists only of lowercase English letters and ' ' only.\nsentences[i] does not have leading or trailing spaces.\nAll the words in sentences[i] are separated by a single space.", + "tags": [ + "Array", + "String" + ], + "title-slug": "maximum-number-of-words-found-in-sentences" + }, + { + "leetcode-id": 2115, + "title": "Find All Possible Recipes from Given Supplies", + "difficulty": 2, + "description": "You have information about n different recipes. You are given a string array recipes and a 2D string array ingredients. The i^th recipe has the name recipes[i], and you can create it if you have all the needed ingredients from ingredients[i]. Ingredients to a recipe may need to be created from other recipes, i.e., ingredients[i] may contain a string that is in recipes.\nYou are also given a string array supplies containing all the ingredients that you initially have, and you have an infinite supply of all of them.\nReturn a list of all the recipes that you can create. You may return the answer in any order.\nNote that two recipes may contain each other in their ingredients.", + "examples": [ + "Example 1:\nInput: recipes = [\"bread\"], ingredients = [[\"yeast\",\"flour\"]], supplies = [\"yeast\",\"flour\",\"corn\"]\nOutput: [\"bread\"]\nExplanation:\nWe can create \"bread\" since we have the ingredients \"yeast\" and \"flour\".", + "Example 2:\nInput: recipes = [\"bread\",\"sandwich\"], ingredients = [[\"yeast\",\"flour\"],[\"bread\",\"meat\"]], supplies = [\"yeast\",\"flour\",\"meat\"]\nOutput: [\"bread\",\"sandwich\"]\nExplanation:\nWe can create \"bread\" since we have the ingredients \"yeast\" and \"flour\".\nWe can create \"sandwich\" since we have the ingredient \"meat\" and can create the ingredient \"bread\".", + "Example 3:\nInput: recipes = [\"bread\",\"sandwich\",\"burger\"], ingredients = [[\"yeast\",\"flour\"],[\"bread\",\"meat\"],[\"sandwich\",\"meat\",\"bread\"]], supplies = [\"yeast\",\"flour\",\"meat\"]\nOutput: [\"bread\",\"sandwich\",\"burger\"]\nExplanation:\nWe can create \"bread\" since we have the ingredients \"yeast\" and \"flour\".\nWe can create \"sandwich\" since we have the ingredient \"meat\" and can create the ingredient \"bread\".\nWe can create \"burger\" since we have the ingredient \"meat\" and can create the ingredients \"bread\" and \"sandwich\"." + ], + "constraints": "Constraints:\n\nn == recipes.length == ingredients.length\n1 <= n <= 100\n1 <= ingredients[i].length, supplies.length <= 100\n1 <= recipes[i].length, ingredients[i][j].length, supplies[k].length <= 10\nrecipes[i], ingredients[i][j], and supplies[k] consist only of lowercase English letters.\nAll the values of recipes and supplies\u00a0combined are unique.\nEach ingredients[i] does not contain any duplicate values.", + "tags": [ + "Array", + "Hash Table", + "String", + "Graph", + "Topological Sort" + ], + "title-slug": "find-all-possible-recipes-from-given-supplies" + }, + { + "leetcode-id": 2116, + "title": "Check if a Parentheses String Can Be Valid", + "difficulty": 2, + "description": "A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true:\n\nIt is ().\nIt can be written as AB (A concatenated with B), where A and B are valid parentheses strings.\nIt can be written as (A), where A is a valid parentheses string.\n\nYou are given a parentheses string s and a string locked, both of length n. locked is a binary string consisting only of '0's and '1's. For each index i of locked,\n\nIf locked[i] is '1', you cannot change s[i].\nBut if locked[i] is '0', you can change s[i] to either '(' or ')'.\n\nReturn true if you can make s a valid parentheses string. Otherwise, return false.", + "examples": [ + "Example 1:\nInput: s = \"))()))\", locked = \"010100\"\nOutput: true\nExplanation: locked[1] == '1' and locked[3] == '1', so we cannot change s[1] or s[3].\nWe change s[0] and s[4] to '(' while leaving s[2] and s[5] unchanged to make s valid.", + "Example 2:\nInput: s = \"()()\", locked = \"0000\"\nOutput: true\nExplanation: We do not need to make any changes because s is already valid.", + "Example 3:\nInput: s = \")\", locked = \"0\"\nOutput: false\nExplanation: locked permits us to change s[0]. \nChanging s[0] to either '(' or ')' will not make s valid." + ], + "constraints": "Constraints:\n\nn == s.length == locked.length\n1 <= n <= 10^5\ns[i] is either '(' or ')'.\nlocked[i] is either '0' or '1'.", + "tags": [ + "String", + "Stack", + "Greedy" + ], + "title-slug": "check-if-a-parentheses-string-can-be-valid" + }, + { + "leetcode-id": 2117, + "title": "Abbreviating the Product of a Range", + "difficulty": 3, + "description": "You are given two positive integers left and right with left <= right. Calculate the product of all integers in the inclusive range [left, right].\nSince the product may be very large, you will abbreviate it following these steps:\n\nCount all trailing zeros in the product and remove them. Let us denote this count as C.\n\n\t\nFor example, there are 3 trailing zeros in 1000, and there are 0 trailing zeros in 546.\n\n\nDenote the remaining number of digits in the product as d. If d > 10, then express the product as
... where 
 denotes the first 5 digits of the product, and  denotes the last 5 digits of the product after removing all trailing zeros. If d <= 10, we keep it unchanged.\n\t\nFor example, we express 1234567654321 as 12345...54321, but 1234567 is represented as 1234567.\n\n\nFinally, represent the product as a string \"
...eC\".\n\t\nFor example, 12345678987600000 will be represented as \"12345...89876e5\".\n\n\n\nReturn a string denoting the abbreviated product of all integers in the inclusive range [left, right].",
+        "examples": [
+            "Example 1:\nInput: left = 1, right = 4\nOutput: \"24e0\"\nExplanation: The product is 1 \u00d7 2 \u00d7 3 \u00d7 4 = 24.\nThere are no trailing zeros, so 24 remains the same. The abbreviation will end with \"e0\".\nSince the number of digits is 2, which is less than 10, we do not have to abbreviate it further.\nThus, the final representation is \"24e0\".",
+            "Example 2:\nInput: left = 2, right = 11\nOutput: \"399168e2\"\nExplanation: The product is 39916800.\nThere are 2 trailing zeros, which we remove to get 399168. The abbreviation will end with \"e2\".\nThe number of digits after removing the trailing zeros is 6, so we do not abbreviate it further.\nHence, the abbreviated product is \"399168e2\".",
+            "Example 3:\nInput: left = 371, right = 375\nOutput: \"7219856259e3\"\nExplanation: The product is 7219856259000."
+        ],
+        "constraints": "Constraints:\n\n1 <= left <= right <= 10^4",
+        "tags": [
+            "Math"
+        ],
+        "title-slug": "abbreviating-the-product-of-a-range"
+    },
+    {
+        "leetcode-id": 2119,
+        "title": "A Number After a Double Reversal",
+        "difficulty": 1,
+        "description": "Reversing an integer means to reverse all its digits.\n\nFor example, reversing 2021 gives 1202. Reversing 12300 gives 321 as the leading zeros are not retained.\n\nGiven an integer num, reverse num to get reversed1, then reverse reversed1 to get reversed2. Return true if reversed2 equals num. Otherwise return false.",
+        "examples": [
+            "Example 1:\nInput: num = 526\nOutput: true\nExplanation: Reverse num to get 625, then reverse 625 to get 526, which equals num.",
+            "Example 2:\nInput: num = 1800\nOutput: false\nExplanation: Reverse num to get 81, then reverse 81 to get 18, which does not equal num.",
+            "Example 3:\nInput: num = 0\nOutput: true\nExplanation: Reverse num to get 0, then reverse 0 to get 0, which equals num."
+        ],
+        "constraints": "Constraints:\n\n0 <= num <= 10^6",
+        "tags": [
+            "Math"
+        ],
+        "title-slug": "a-number-after-a-double-reversal"
+    },
+    {
+        "leetcode-id": 2120,
+        "title": "Execution of All Suffix Instructions Staying in a Grid",
+        "difficulty": 2,
+        "description": "There is an n x n grid, with the top-left cell at (0, 0) and the bottom-right cell at (n - 1, n - 1). You are given the integer n and an integer array startPos where startPos = [startrow, startcol] indicates that a robot is initially at cell (startrow, startcol).\nYou are also given a 0-indexed string s of length m where s[i] is the i^th instruction for the robot: 'L' (move left), 'R' (move right), 'U' (move up), and 'D' (move down).\nThe robot can begin executing from any i^th instruction in s. It executes the instructions one by one towards the end of s but it stops if either of these conditions is met:\n\nThe next instruction will move the robot off the grid.\nThere are no more instructions left to execute.\n\nReturn an array answer of length m where answer[i] is the number of instructions the robot can execute if the robot begins executing from the i^th instruction in s.",
+        "examples": [
+            "Example 1:\nInput: n = 3, startPos = [0,1], s = \"RRDDLU\"\nOutput: [1,5,4,3,1,0]\nExplanation: Starting from startPos and beginning execution from the i^th instruction:\n- 0^th: \"RRDDLU\". Only one instruction \"R\" can be executed before it moves off the grid.\n- 1^st:  \"RDDLU\". All five instructions can be executed while it stays in the grid and ends at (1, 1).\n- 2^nd:   \"DDLU\". All four instructions can be executed while it stays in the grid and ends at (1, 0).\n- 3^rd:    \"DLU\". All three instructions can be executed while it stays in the grid and ends at (0, 0).\n- 4^th:     \"LU\". Only one instruction \"L\" can be executed before it moves off the grid.\n- 5^th:      \"U\". If moving up, it would move off the grid.",
+            "Example 2:\nInput: n = 2, startPos = [1,1], s = \"LURD\"\nOutput: [4,1,0,0]\nExplanation:\n- 0^th: \"LURD\".\n- 1^st:  \"URD\".\n- 2^nd:   \"RD\".\n- 3^rd:    \"D\".",
+            "Example 3:\nInput: n = 1, startPos = [0,0], s = \"LRUD\"\nOutput: [0,0,0,0]\nExplanation: No matter which instruction the robot begins execution from, it would move off the grid."
+        ],
+        "constraints": "Constraints:\n\nm == s.length\n1 <= n, m <= 500\nstartPos.length == 2\n0 <= startrow, startcol < n\ns consists of 'L', 'R', 'U', and 'D'.",
+        "tags": [
+            "String",
+            "Simulation"
+        ],
+        "title-slug": "execution-of-all-suffix-instructions-staying-in-a-grid"
+    },
+    {
+        "leetcode-id": 2121,
+        "title": "Intervals Between Identical Elements",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array of n integers arr.\nThe interval between two elements in arr is defined as the absolute difference between their indices. More formally, the interval between arr[i] and arr[j] is |i - j|.\nReturn an array intervals of length n where intervals[i] is the sum of intervals between arr[i] and each element in arr with the same value as arr[i].\nNote: |x| is the absolute value of x.",
+        "examples": [
+            "Example 1:\nInput: arr = [2,1,3,1,2,3,3]\nOutput: [4,2,7,2,4,4,5]\nExplanation:\n- Index 0: Another 2 is found at index 4. |0 - 4| = 4\n- Index 1: Another 1 is found at index 3. |1 - 3| = 2\n- Index 2: Two more 3s are found at indices 5 and 6. |2 - 5| + |2 - 6| = 7\n- Index 3: Another 1 is found at index 1. |3 - 1| = 2\n- Index 4: Another 2 is found at index 0. |4 - 0| = 4\n- Index 5: Two more 3s are found at indices 2 and 6. |5 - 2| + |5 - 6| = 4\n- Index 6: Two more 3s are found at indices 2 and 5. |6 - 2| + |6 - 5| = 5",
+            "Example 2:\nInput: arr = [10,5,10,10]\nOutput: [5,0,3,4]\nExplanation:\n- Index 0: Two more 10s are found at indices 2 and 3. |0 - 2| + |0 - 3| = 5\n- Index 1: There is only one 5 in the array, so its sum of intervals to identical elements is 0.\n- Index 2: Two more 10s are found at indices 0 and 3. |2 - 0| + |2 - 3| = 3\n- Index 3: Two more 10s are found at indices 0 and 2. |3 - 0| + |3 - 2| = 4"
+        ],
+        "constraints": "Constraints:\n\nn == arr.length\n1 <= n <= 10^5\n1 <= arr[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Prefix Sum"
+        ],
+        "title-slug": "intervals-between-identical-elements"
+    },
+    {
+        "leetcode-id": 2122,
+        "title": "Recover the Original Array",
+        "difficulty": 3,
+        "description": "Alice had a 0-indexed array arr consisting of n positive integers. She chose an arbitrary positive integer k and created two new 0-indexed integer arrays lower and higher in the following manner:\n\nlower[i] = arr[i] - k, for every index i where 0 <= i < n\nhigher[i] = arr[i] + k, for every index i where 0 <= i < n\n\nUnfortunately, Alice lost all three arrays. However, she remembers the integers that were present in the arrays lower and higher, but not the array each integer belonged to. Help Alice and recover the original array.\nGiven an array nums consisting of 2n integers, where exactly n of the integers were present in lower and the remaining in higher, return the original array arr. In case the answer is not unique, return any valid array.\nNote: The test cases are generated such that there exists at least one valid array arr.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,10,6,4,8,12]\nOutput: [3,7,11]\nExplanation:\nIf arr = [3,7,11] and k = 1, we get lower = [2,6,10] and higher = [4,8,12].\nCombining lower and higher gives us [2,6,10,4,8,12], which is a permutation of nums.\nAnother valid possibility is that arr = [5,7,9] and k = 3. In that case, lower = [2,4,6] and higher = [8,10,12].",
+            "Example 2:\nInput: nums = [1,1,3,3]\nOutput: [2,2]\nExplanation:\nIf arr = [2,2] and k = 1, we get lower = [1,1] and higher = [3,3].\nCombining lower and higher gives us [1,1,3,3], which is equal to nums.\nNote that arr cannot be [1,3] because in that case, the only possible way to obtain [1,1,3,3] is with k = 0.\nThis is invalid since k must be positive.",
+            "Example 3:\nInput: nums = [5,435]\nOutput: [220]\nExplanation:\nThe only possible combination is arr = [220] and k = 215. Using them, we get lower = [5] and higher = [435]."
+        ],
+        "constraints": "Constraints:\n\n2 * n == nums.length\n1 <= n <= 1000\n1 <= nums[i] <= 10^9\nThe test cases are generated such that there exists at least one valid array arr.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sorting",
+            "Enumeration"
+        ],
+        "title-slug": "recover-the-original-array"
+    },
+    {
+        "leetcode-id": 2124,
+        "title": "Check if All A's Appears Before All B's",
+        "difficulty": 1,
+        "description": "Given a string s consisting of only the characters 'a' and 'b', return true if every 'a' appears before every 'b' in the string. Otherwise, return false.",
+        "examples": [
+            "Example 1:\nInput: s = \"aaabbb\"\nOutput: true\nExplanation:\nThe 'a's are at indices 0, 1, and 2, while the 'b's are at indices 3, 4, and 5.\nHence, every 'a' appears before every 'b' and we return true.",
+            "Example 2:\nInput: s = \"abab\"\nOutput: false\nExplanation:\nThere is an 'a' at index 2 and a 'b' at index 1.\nHence, not every 'a' appears before every 'b' and we return false.",
+            "Example 3:\nInput: s = \"bbb\"\nOutput: true\nExplanation:\nThere are no 'a's, hence, every 'a' appears before every 'b' and we return true."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 100\ns[i] is either 'a' or 'b'.",
+        "tags": [
+            "String"
+        ],
+        "title-slug": "check-if-all-as-appears-before-all-bs"
+    },
+    {
+        "leetcode-id": 2125,
+        "title": "Number of Laser Beams in a Bank",
+        "difficulty": 2,
+        "description": "Anti-theft security devices are activated inside a bank. You are given a 0-indexed binary string array bank representing the floor plan of the bank, which is an m x n 2D matrix. bank[i] represents the i^th row, consisting of '0's and '1's. '0' means the cell is empty, while'1' means the cell has a security device.\nThere is one laser beam between any two security devices if both conditions are met:\n\nThe two devices are located on two different rows: r1 and r2, where r1 < r2.\nFor each row i where r1 < i < r2, there are no security devices in the i^th row.\n\nLaser beams are independent, i.e., one beam does not interfere nor join with another.\nReturn the total number of laser beams in the bank.",
+        "examples": [
+            "Example 1:\nInput: bank = [\"011001\",\"000000\",\"010100\",\"001000\"]\nOutput: 8\nExplanation: Between each of the following device pairs, there is one beam. In total, there are 8 beams:\n * bank[0][1] -- bank[2][1]\n * bank[0][1] -- bank[2][3]\n * bank[0][2] -- bank[2][1]\n * bank[0][2] -- bank[2][3]\n * bank[0][5] -- bank[2][1]\n * bank[0][5] -- bank[2][3]\n * bank[2][1] -- bank[3][2]\n * bank[2][3] -- bank[3][2]\nNote that there is no beam between any device on the 0^th row with any on the 3^rd row.\nThis is because the 2^nd row contains security devices, which breaks the second condition.",
+            "Example 2:\nInput: bank = [\"000\",\"111\",\"000\"]\nOutput: 0\nExplanation: There does not exist two devices located on two different rows."
+        ],
+        "constraints": "Constraints:\n\nm == bank.length\nn == bank[i].length\n1 <= m, n <= 500\nbank[i][j] is either '0' or '1'.",
+        "tags": [
+            "Array",
+            "Math",
+            "String",
+            "Matrix"
+        ],
+        "title-slug": "number-of-laser-beams-in-a-bank"
+    },
+    {
+        "leetcode-id": 2126,
+        "title": "Destroying Asteroids",
+        "difficulty": 2,
+        "description": "You are given an integer mass, which represents the original mass of a planet. You are further given an integer array asteroids, where asteroids[i] is the mass of the i^th asteroid.\nYou can arrange for the planet to collide with the asteroids in any arbitrary order. If the mass of the planet is greater than or equal to the mass of the asteroid, the asteroid is destroyed and the planet gains the mass of the asteroid. Otherwise, the planet is destroyed.\nReturn true if all asteroids can be destroyed. Otherwise, return false.",
+        "examples": [
+            "Example 1:\nInput: mass = 10, asteroids = [3,9,19,5,21]\nOutput: true\nExplanation: One way to order the asteroids is [9,19,5,3,21]:\n- The planet collides with the asteroid with a mass of 9. New planet mass: 10 + 9 = 19\n- The planet collides with the asteroid with a mass of 19. New planet mass: 19 + 19 = 38\n- The planet collides with the asteroid with a mass of 5. New planet mass: 38 + 5 = 43\n- The planet collides with the asteroid with a mass of 3. New planet mass: 43 + 3 = 46\n- The planet collides with the asteroid with a mass of 21. New planet mass: 46 + 21 = 67\nAll asteroids are destroyed.",
+            "Example 2:\nInput: mass = 5, asteroids = [4,9,23,4]\nOutput: false\nExplanation: \nThe planet cannot ever gain enough mass to destroy the asteroid with a mass of 23.\nAfter the planet destroys the other asteroids, it will have a mass of 5 + 4 + 9 + 4 = 22.\nThis is less than 23, so a collision would not destroy the last asteroid."
+        ],
+        "constraints": "Constraints:\n\n1 <= mass <= 10^5\n1 <= asteroids.length <= 10^5\n1 <= asteroids[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "destroying-asteroids"
+    },
+    {
+        "leetcode-id": 2127,
+        "title": "Maximum Employees to Be Invited to a Meeting",
+        "difficulty": 3,
+        "description": "A company is organizing a meeting and has a list of n employees, waiting to be invited. They have arranged for a large circular table, capable of seating any number of employees.\nThe employees are numbered from 0 to n - 1. Each employee has a favorite person and they will attend the meeting only if they can sit next to their favorite person at the table. The favorite person of an employee is not themself.\nGiven a 0-indexed integer array favorite, where favorite[i] denotes the favorite person of the i^th employee, return the maximum number of employees that can be invited to the meeting.",
+        "examples": [
+            "Example 1:\nInput: favorite = [2,2,1,2]\nOutput: 3\nExplanation:\nThe above figure shows how the company can invite employees 0, 1, and 2, and seat them at the round table.\nAll employees cannot be invited because employee 2 cannot sit beside employees 0, 1, and 3, simultaneously.\nNote that the company can also invite employees 1, 2, and 3, and give them their desired seats.\nThe maximum number of employees that can be invited to the meeting is 3.",
+            "Example 2:\nInput: favorite = [1,2,0]\nOutput: 3\nExplanation: \nEach employee is the favorite person of at least one other employee, and the only way the company can invite them is if they invite every employee.\nThe seating arrangement will be the same as that in the figure given in example 1:\n- Employee 0 will sit between employees 2 and 1.\n- Employee 1 will sit between employees 0 and 2.\n- Employee 2 will sit between employees 1 and 0.\nThe maximum number of employees that can be invited to the meeting is 3.",
+            "Example 3:\nInput: favorite = [3,0,1,4,1]\nOutput: 4\nExplanation:\nThe above figure shows how the company will invite employees 0, 1, 3, and 4, and seat them at the round table.\nEmployee 2 cannot be invited because the two spots next to their favorite employee 1 are taken.\nSo the company leaves them out of the meeting.\nThe maximum number of employees that can be invited to the meeting is 4."
+        ],
+        "constraints": "Constraints:\n\nn == favorite.length\n2 <= n <= 10^5\n0 <= favorite[i] <=\u00a0n - 1\nfavorite[i] != i",
+        "tags": [
+            "Depth-First Search",
+            "Graph",
+            "Topological Sort"
+        ],
+        "title-slug": "maximum-employees-to-be-invited-to-a-meeting"
+    },
+    {
+        "leetcode-id": 2129,
+        "title": "Capitalize the Title",
+        "difficulty": 1,
+        "description": "You are given a string title consisting of one or more words separated by a single space, where each word consists of English letters. Capitalize the string by changing the capitalization of each word such that:\n\nIf the length of the word is 1 or 2 letters, change all letters to lowercase.\nOtherwise, change the first letter to uppercase and the remaining letters to lowercase.\n\nReturn the capitalized title.",
+        "examples": [
+            "Example 1:\nInput: title = \"capiTalIze tHe titLe\"\nOutput: \"Capitalize The Title\"\nExplanation:\nSince all the words have a length of at least 3, the first letter of each word is uppercase, and the remaining letters are lowercase.",
+            "Example 2:\nInput: title = \"First leTTeR of EACH Word\"\nOutput: \"First Letter of Each Word\"\nExplanation:\nThe word \"of\" has length 2, so it is all lowercase.\nThe remaining words have a length of at least 3, so the first letter of each remaining word is uppercase, and the remaining letters are lowercase.",
+            "Example 3:\nInput: title = \"i lOve leetcode\"\nOutput: \"i Love Leetcode\"\nExplanation:\nThe word \"i\" has length 1, so it is lowercase.\nThe remaining words have a length of at least 3, so the first letter of each remaining word is uppercase, and the remaining letters are lowercase."
+        ],
+        "constraints": "Constraints:\n\n1 <= title.length <= 100\ntitle consists of words separated by a single space without any leading or trailing spaces.\nEach word consists of uppercase and lowercase English letters and is non-empty.",
+        "tags": [
+            "String"
+        ],
+        "title-slug": "capitalize-the-title"
+    },
+    {
+        "leetcode-id": 2130,
+        "title": "Maximum Twin Sum of a Linked List",
+        "difficulty": 2,
+        "description": "In a linked list of size n, where n is even, the i^th node (0-indexed) of the linked list is known as the twin of the (n-1-i)^th node, if 0 <= i <= (n / 2) - 1.\n\nFor example, if n = 4, then node 0 is the twin of node 3, and node 1 is the twin of node 2. These are the only nodes with twins for n = 4.\n\nThe twin sum is defined as the sum of a node and its twin.\nGiven the head of a linked list with even length, return the maximum twin sum of the linked list.",
+        "examples": [
+            "Example 1:\nInput: head = [5,4,2,1]\nOutput: 6\nExplanation:\nNodes 0 and 1 are the twins of nodes 3 and 2, respectively. All have twin sum = 6.\nThere are no other nodes with twins in the linked list.\nThus, the maximum twin sum of the linked list is 6.",
+            "Example 2:\nInput: head = [4,2,2,3]\nOutput: 7\nExplanation:\nThe nodes with twins present in this linked list are:\n- Node 0 is the twin of node 3 having a twin sum of 4 + 3 = 7.\n- Node 1 is the twin of node 2 having a twin sum of 2 + 2 = 4.\nThus, the maximum twin sum of the linked list is max(7, 4) = 7.",
+            "Example 3:\nInput: head = [1,100000]\nOutput: 100001\nExplanation:\nThere is only one node with a twin in the linked list having twin sum of 1 + 100000 = 100001."
+        ],
+        "constraints": "Constraints:\n\nThe number of nodes in the list is an even integer in the range [2, 10^5].\n1 <= Node.val <= 10^5",
+        "tags": [
+            "Linked List",
+            "Two Pointers",
+            "Stack"
+        ],
+        "title-slug": "maximum-twin-sum-of-a-linked-list"
+    },
+    {
+        "leetcode-id": 2131,
+        "title": "Longest Palindrome by Concatenating Two Letter Words",
+        "difficulty": 2,
+        "description": "You are given an array of strings words. Each element of words consists of two lowercase English letters.\nCreate the longest possible palindrome by selecting some elements from words and concatenating them in any order. Each element can be selected at most once.\nReturn the length of the longest palindrome that you can create. If it is impossible to create any palindrome, return 0.\nA palindrome is a string that reads the same forward and backward.",
+        "examples": [
+            "Example 1:\nInput: words = [\"lc\",\"cl\",\"gg\"]\nOutput: 6\nExplanation: One longest palindrome is \"lc\" + \"gg\" + \"cl\" = \"lcggcl\", of length 6.\nNote that \"clgglc\" is another longest palindrome that can be created.",
+            "Example 2:\nInput: words = [\"ab\",\"ty\",\"yt\",\"lc\",\"cl\",\"ab\"]\nOutput: 8\nExplanation: One longest palindrome is \"ty\" + \"lc\" + \"cl\" + \"yt\" = \"tylcclyt\", of length 8.\nNote that \"lcyttycl\" is another longest palindrome that can be created.",
+            "Example 3:\nInput: words = [\"cc\",\"ll\",\"xx\"]\nOutput: 2\nExplanation: One longest palindrome is \"cc\", of length 2.\nNote that \"ll\" is another longest palindrome that can be created, and so is \"xx\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 10^5\nwords[i].length == 2\nwords[i] consists of lowercase English letters.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Greedy",
+            "Counting"
+        ],
+        "title-slug": "longest-palindrome-by-concatenating-two-letter-words"
+    },
+    {
+        "leetcode-id": 2132,
+        "title": "Stamping the Grid",
+        "difficulty": 3,
+        "description": "You are given an m x n binary matrix grid where each cell is either 0 (empty) or 1 (occupied).\nYou are then given stamps of size stampHeight x stampWidth. We want to fit the stamps such that they follow the given restrictions and requirements:\n\nCover all the empty cells.\nDo not cover any of the occupied cells.\nWe can put as many stamps as we want.\nStamps can overlap with each other.\nStamps are not allowed to be rotated.\nStamps must stay completely inside the grid.\n\nReturn true if it is possible to fit the stamps while following the given restrictions and requirements. Otherwise, return false.",
+        "examples": [
+            "Example 1:\nInput: grid = [[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0]], stampHeight = 4, stampWidth = 3\nOutput: true\nExplanation: We have two overlapping stamps (labeled 1 and 2 in the image) that are able to cover all the empty cells.",
+            "Example 2:\nInput: grid = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]], stampHeight = 2, stampWidth = 2 \nOutput: false \nExplanation: There is no way to fit the stamps onto all the empty cells without the stamps going outside the grid."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[r].length\n1 <= m, n <= 10^5\n1 <= m * n <= 2 * 10^5\ngrid[r][c] is either 0 or 1.\n1 <= stampHeight, stampWidth <= 10^5",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Matrix",
+            "Prefix Sum"
+        ],
+        "title-slug": "stamping-the-grid"
+    },
+    {
+        "leetcode-id": 2133,
+        "title": "Check if Every Row and Column Contains All Numbers",
+        "difficulty": 1,
+        "description": "An n x n matrix is valid if every row and every column contains all the integers from 1 to n (inclusive).\nGiven an n x n integer matrix matrix, return true if the matrix is valid. Otherwise, return false.",
+        "examples": [
+            "Example 1:\nInput: matrix = [[1,2,3],[3,1,2],[2,3,1]]\nOutput: true\nExplanation: In this case, n = 3, and every row and column contains the numbers 1, 2, and 3.\nHence, we return true.",
+            "Example 2:\nInput: matrix = [[1,1,1],[1,2,3],[1,2,3]]\nOutput: false\nExplanation: In this case, n = 3, but the first row and the first column do not contain the numbers 2 or 3.\nHence, we return false."
+        ],
+        "constraints": "Constraints:\n\nn == matrix.length == matrix[i].length\n1 <= n <= 100\n1 <= matrix[i][j] <= n",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Matrix"
+        ],
+        "title-slug": "check-if-every-row-and-column-contains-all-numbers"
+    },
+    {
+        "leetcode-id": 2134,
+        "title": "Minimum Swaps to Group All 1's Together II",
+        "difficulty": 2,
+        "description": "A swap is defined as taking two distinct positions in an array and swapping the values in them.\nA circular array is defined as an array where we consider the first element and the last element to be adjacent.\nGiven a binary circular array nums, return the minimum number of swaps required to group all 1's present in the array together at any location.",
+        "examples": [
+            "Example 1:\nInput: nums = [0,1,0,1,1,0,0]\nOutput: 1\nExplanation: Here are a few of the ways to group all the 1's together:\n[0,0,1,1,1,0,0] using 1 swap.\n[0,1,1,1,0,0,0] using 1 swap.\n[1,1,0,0,0,0,1] using 2 swaps (using the circular property of the array).\nThere is no way to group all 1's together with 0 swaps.\nThus, the minimum number of swaps required is 1.",
+            "Example 2:\nInput: nums = [0,1,1,1,0,0,1,1,0]\nOutput: 2\nExplanation: Here are a few of the ways to group all the 1's together:\n[1,1,1,0,0,0,0,1,1] using 2 swaps (using the circular property of the array).\n[1,1,1,1,1,0,0,0,0] using 2 swaps.\nThere is no way to group all 1's together with 0 or 1 swaps.\nThus, the minimum number of swaps required is 2.",
+            "Example 3:\nInput: nums = [1,1,0,0,1]\nOutput: 0\nExplanation: All the 1's are already grouped together due to the circular property of the array.\nThus, the minimum number of swaps required is 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\nnums[i] is either 0 or 1.",
+        "tags": [
+            "Array",
+            "Sliding Window"
+        ],
+        "title-slug": "minimum-swaps-to-group-all-1s-together-ii"
+    },
+    {
+        "leetcode-id": 2135,
+        "title": "Count Words Obtained After Adding a Letter",
+        "difficulty": 2,
+        "description": "You are given two 0-indexed arrays of strings startWords and targetWords. Each string consists of lowercase English letters only.\nFor each string in targetWords, check if it is possible to choose a string from startWords and perform a conversion operation on it to be equal to that from targetWords.\nThe conversion operation is described in the following two steps:\n\nAppend any lowercase letter that is not present in the string to its end.\n\n\t\nFor example, if the string is \"abc\", the letters 'd', 'e', or 'y' can be added to it, but not 'a'. If 'd' is added, the resulting string will be \"abcd\".\n\n\nRearrange the letters of the new string in any arbitrary order.\n\t\nFor example, \"abcd\" can be rearranged to \"acbd\", \"bacd\", \"cbda\", and so on. Note that it can also be rearranged to \"abcd\" itself.\n\n\n\nReturn the number of strings in targetWords that can be obtained by performing the operations on any string of startWords.\nNote that you will only be verifying if the string in targetWords can be obtained from a string in startWords by performing the operations. The strings in startWords do not actually change during this process.",
+        "examples": [
+            "Example 1:\nInput: startWords = [\"ant\",\"act\",\"tack\"], targetWords = [\"tack\",\"act\",\"acti\"]\nOutput: 2\nExplanation:\n- In order to form targetWords[0] = \"tack\", we use startWords[1] = \"act\", append 'k' to it, and rearrange \"actk\" to \"tack\".\n- There is no string in startWords that can be used to obtain targetWords[1] = \"act\".\n  Note that \"act\" does exist in startWords, but we must append one letter to the string before rearranging it.\n- In order to form targetWords[2] = \"acti\", we use startWords[1] = \"act\", append 'i' to it, and rearrange \"acti\" to \"acti\" itself.",
+            "Example 2:\nInput: startWords = [\"ab\",\"a\"], targetWords = [\"abc\",\"abcd\"]\nOutput: 1\nExplanation:\n- In order to form targetWords[0] = \"abc\", we use startWords[0] = \"ab\", add 'c' to it, and rearrange it to \"abc\".\n- There is no string in startWords that can be used to obtain targetWords[1] = \"abcd\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= startWords.length, targetWords.length <= 5 * 10^4\n1 <= startWords[i].length, targetWords[j].length <= 26\nEach string of startWords and targetWords consists of lowercase English letters only.\nNo letter occurs more than once in any string of startWords or targetWords.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Bit Manipulation",
+            "Sorting"
+        ],
+        "title-slug": "count-words-obtained-after-adding-a-letter"
+    },
+    {
+        "leetcode-id": 2136,
+        "title": "Earliest Possible Day of Full Bloom",
+        "difficulty": 3,
+        "description": "You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth of a seed. You are given two 0-indexed integer arrays plantTime and growTime, of length n each:\n\nplantTime[i] is the number of full days it takes you to plant the i^th seed. Every day, you can work on planting exactly one seed. You do not have to work on planting the same seed on consecutive days, but the planting of a seed is not complete until you have worked plantTime[i] days on planting it in total.\ngrowTime[i] is the number of full days it takes the i^th seed to grow after being completely planted. After the last day of its growth, the flower blooms and stays bloomed forever.\n\nFrom the beginning of day 0, you can plant the seeds in any order.\nReturn the earliest possible day where all seeds are blooming.",
+        "examples": [
+            "Example 1:\nInput: plantTime = [1,4,3], growTime = [2,3,1]\nOutput: 9\nExplanation: The grayed out pots represent planting days, colored pots represent growing days, and the flower represents the day it blooms.\nOne optimal way is:\nOn day 0, plant the 0^th seed. The seed grows for 2 full days and blooms on day 3.\nOn days 1, 2, 3, and 4, plant the 1^st seed. The seed grows for 3 full days and blooms on day 8.\nOn days 5, 6, and 7, plant the 2^nd seed. The seed grows for 1 full day and blooms on day 9.\nThus, on day 9, all the seeds are blooming.",
+            "Example 2:\nInput: plantTime = [1,2,3,2], growTime = [2,1,2,1]\nOutput: 9\nExplanation: The grayed out pots represent planting days, colored pots represent growing days, and the flower represents the day it blooms.\nOne optimal way is:\nOn day 1, plant the 0^th seed. The seed grows for 2 full days and blooms on day 4.\nOn days 0 and 3, plant the 1^st seed. The seed grows for 1 full day and blooms on day 5.\nOn days 2, 4, and 5, plant the 2^nd seed. The seed grows for 2 full days and blooms on day 8.\nOn days 6 and 7, plant the 3^rd seed. The seed grows for 1 full day and blooms on day 9.\nThus, on day 9, all the seeds are blooming.",
+            "Example 3:\nInput: plantTime = [1], growTime = [1]\nOutput: 2\nExplanation: On day 0, plant the 0^th seed. The seed grows for 1 full day and blooms on day 2.\nThus, on day 2, all the seeds are blooming."
+        ],
+        "constraints": "Constraints:\n\nn == plantTime.length == growTime.length\n1 <= n <= 10^5\n1 <= plantTime[i], growTime[i] <= 10^4",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "earliest-possible-day-of-full-bloom"
+    },
+    {
+        "leetcode-id": 2138,
+        "title": "Divide a String Into Groups of Size k",
+        "difficulty": 1,
+        "description": "A string s can be partitioned into groups of size k using the following procedure:\n\nThe first group consists of the first k characters of the string, the second group consists of the next k characters of the string, and so on. Each character can be a part of exactly one group.\nFor the last group, if the string does not have k characters remaining, a character fill is used to complete the group.\n\nNote that the partition is done so that after removing the fill character from the last group (if it exists) and concatenating all the groups in order, the resultant string should be s.\nGiven the string s, the size of each group k and the character fill, return a string array denoting the composition of every group s has been divided into, using the above procedure.",
+        "examples": [
+            "Example 1:\nInput: s = \"abcdefghi\", k = 3, fill = \"x\"\nOutput: [\"abc\",\"def\",\"ghi\"]\nExplanation:\nThe first 3 characters \"abc\" form the first group.\nThe next 3 characters \"def\" form the second group.\nThe last 3 characters \"ghi\" form the third group.\nSince all groups can be completely filled by characters from the string, we do not need to use fill.\nThus, the groups formed are \"abc\", \"def\", and \"ghi\".",
+            "Example 2:\nInput: s = \"abcdefghij\", k = 3, fill = \"x\"\nOutput: [\"abc\",\"def\",\"ghi\",\"jxx\"]\nExplanation:\nSimilar to the previous example, we are forming the first three groups \"abc\", \"def\", and \"ghi\".\nFor the last group, we can only use the character 'j' from the string. To complete this group, we add 'x' twice.\nThus, the 4 groups formed are \"abc\", \"def\", \"ghi\", and \"jxx\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 100\ns consists of lowercase English letters only.\n1 <= k <= 100\nfill is a lowercase English letter.",
+        "tags": [
+            "String",
+            "Simulation"
+        ],
+        "title-slug": "divide-a-string-into-groups-of-size-k"
+    },
+    {
+        "leetcode-id": 2139,
+        "title": "Minimum Moves to Reach Target Score",
+        "difficulty": 2,
+        "description": "You are playing a game with integers. You start with the integer 1 and you want to reach the integer target.\nIn one move, you can either:\n\nIncrement the current integer by one (i.e., x = x + 1).\nDouble the current integer (i.e., x = 2 * x).\n\nYou can use the increment operation any number of times, however, you can only use the double operation at most maxDoubles times.\nGiven the two integers target and maxDoubles, return the minimum number of moves needed to reach target starting with 1.",
+        "examples": [
+            "Example 1:\nInput: target = 5, maxDoubles = 0\nOutput: 4\nExplanation: Keep incrementing by 1 until you reach target.",
+            "Example 2:\nInput: target = 19, maxDoubles = 2\nOutput: 7\nExplanation: Initially, x = 1\nIncrement 3 times so x = 4\nDouble once so x = 8\nIncrement once so x = 9\nDouble again so x = 18\nIncrement once so x = 19",
+            "Example 3:\nInput: target = 10, maxDoubles = 4\nOutput: 4\nExplanation: Initially, x = 1\nIncrement once so x = 2\nDouble once so x = 4\nIncrement once so x = 5\nDouble again so x = 10"
+        ],
+        "constraints": "Constraints:\n\n1 <= target <= 10^9\n0 <= maxDoubles <= 100",
+        "tags": [
+            "Math",
+            "Greedy"
+        ],
+        "title-slug": "minimum-moves-to-reach-target-score"
+    },
+    {
+        "leetcode-id": 2140,
+        "title": "Solving Questions With Brainpower",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed 2D integer array questions where questions[i] = [pointsi, brainpoweri].\nThe array describes the questions of an exam, where you have to process the questions in order (i.e., starting from question 0) and make a decision whether to solve or skip each question. Solving question i will earn you pointsi points but you will be unable to solve each of the next brainpoweri questions. If you skip question i, you get to make the decision on the next question.\n\nFor example, given questions = [[3, 2], [4, 3], [4, 4], [2, 5]]:\n\n\t\nIf question 0 is solved, you will earn 3 points but you will be unable to solve questions 1 and 2.\nIf instead, question 0 is skipped and question 1 is solved, you will earn 4 points but you will be unable to solve questions 2 and 3.\n\n\n\nReturn the maximum points you can earn for the exam.",
+        "examples": [
+            "Example 1:\nInput: questions = [[3,2],[4,3],[4,4],[2,5]]\nOutput: 5\nExplanation: The maximum points can be earned by solving questions 0 and 3.\n- Solve question 0: Earn 3 points, will be unable to solve the next 2 questions\n- Unable to solve questions 1 and 2\n- Solve question 3: Earn 2 points\nTotal points earned: 3 + 2 = 5. There is no other way to earn 5 or more points.",
+            "Example 2:\nInput: questions = [[1,1],[2,2],[3,3],[4,4],[5,5]]\nOutput: 7\nExplanation: The maximum points can be earned by solving questions 1 and 4.\n- Skip question 0\n- Solve question 1: Earn 2 points, will be unable to solve the next 2 questions\n- Unable to solve questions 2 and 3\n- Solve question 4: Earn 5 points\nTotal points earned: 2 + 5 = 7. There is no other way to earn 7 or more points."
+        ],
+        "constraints": "Constraints:\n\n1 <= questions.length <= 10^5\nquestions[i].length == 2\n1 <= pointsi, brainpoweri <= 10^5",
+        "tags": [
+            "Array",
+            "Dynamic Programming"
+        ],
+        "title-slug": "solving-questions-with-brainpower"
+    },
+    {
+        "leetcode-id": 2141,
+        "title": "Maximum Running Time of N Computers",
+        "difficulty": 3,
+        "description": "You have n computers. You are given the integer n and a 0-indexed integer array batteries where the i^th battery can run a computer for batteries[i] minutes. You are interested in running all n computers simultaneously using the given batteries.\nInitially, you can insert at most one battery into each computer. After that and at any integer time moment, you can remove a battery from a computer and insert another battery any number of times. The inserted battery can be a totally new battery or a battery from another computer. You may assume that the removing and inserting processes take no time.\nNote that the batteries cannot be recharged.\nReturn the maximum number of minutes you can run all the n computers simultaneously.",
+        "examples": [
+            "Example 1:\nInput: n = 2, batteries = [3,3,3]\nOutput: 4\nExplanation: \nInitially, insert battery 0 into the first computer and battery 1 into the second computer.\nAfter two minutes, remove battery 1 from the second computer and insert battery 2 instead. Note that battery 1 can still run for one minute.\nAt the end of the third minute, battery 0 is drained, and you need to remove it from the first computer and insert battery 1 instead.\nBy the end of the fourth minute, battery 1 is also drained, and the first computer is no longer running.\nWe can run the two computers simultaneously for at most 4 minutes, so we return 4.",
+            "Example 2:\nInput: n = 2, batteries = [1,1,1,1]\nOutput: 2\nExplanation: \nInitially, insert battery 0 into the first computer and battery 2 into the second computer. \nAfter one minute, battery 0 and battery 2 are drained so you need to remove them and insert battery 1 into the first computer and battery 3 into the second computer. \nAfter another minute, battery 1 and battery 3 are also drained so the first and second computers are no longer running.\nWe can run the two computers simultaneously for at most 2 minutes, so we return 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= batteries.length <= 10^5\n1 <= batteries[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "maximum-running-time-of-n-computers"
+    },
+    {
+        "leetcode-id": 2144,
+        "title": "Minimum Cost of Buying Candies With Discount",
+        "difficulty": 1,
+        "description": "A shop is selling candies at a discount. For every two candies sold, the shop gives a third candy for free.\nThe customer can choose any candy to take away for free as long as the cost of the chosen candy is less than or equal to the minimum cost of the two candies bought.\n\nFor example, if there are 4 candies with costs 1, 2, 3, and 4, and the customer buys candies with costs 2 and 3, they\u00a0can take the candy with cost 1 for free, but not the candy with cost 4.\n\nGiven a 0-indexed integer array cost, where cost[i] denotes the cost of the i^th candy, return the minimum cost of buying all the candies.",
+        "examples": [
+            "Example 1:\nInput: cost = [1,2,3]\nOutput: 5\nExplanation: We buy the candies with costs 2 and 3, and take the candy with cost 1 for free.\nThe total cost of buying all candies is 2 + 3 = 5. This is the only way we can buy the candies.\nNote that we cannot buy candies with costs 1 and 3, and then take the candy with cost 2 for free.\nThe cost of the free candy has to be less than or equal to the minimum cost of the purchased candies.",
+            "Example 2:\nInput: cost = [6,5,7,9,2,2]\nOutput: 23\nExplanation: The way in which we can get the minimum cost is described below:\n- Buy candies with costs 9 and 7\n- Take the candy with cost 6 for free\n- We buy candies with costs 5 and 2\n- Take the last remaining candy with cost 2 for free\nHence, the minimum cost to buy all candies is 9 + 7 + 5 + 2 = 23.",
+            "Example 3:\nInput: cost = [5,5]\nOutput: 10\nExplanation: Since there are only 2 candies, we buy both of them. There is not a third candy we can take for free.\nHence, the minimum cost to buy all candies is 5 + 5 = 10."
+        ],
+        "constraints": "Constraints:\n\n1 <= cost.length <= 100\n1 <= cost[i] <= 100",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "minimum-cost-of-buying-candies-with-discount"
+    },
+    {
+        "leetcode-id": 2145,
+        "title": "Count the Hidden Sequences",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array of n integers differences, which describes the differences between each pair of consecutive integers of a hidden sequence of length (n + 1). More formally, call the hidden sequence hidden, then we have that differences[i] = hidden[i + 1] - hidden[i].\nYou are further given two integers lower and upper that describe the inclusive range of values [lower, upper] that the hidden sequence can contain.\n\nFor example, given differences = [1, -3, 4], lower = 1, upper = 6, the hidden sequence is a sequence of length 4 whose elements are in between 1 and 6 (inclusive).\n\n\t\n[3, 4, 1, 5] and [4, 5, 2, 6] are possible hidden sequences.\n[5, 6, 3, 7] is not possible since it contains an element greater than 6.\n[1, 2, 3, 4] is not possible since the differences are not correct.\n\n\n\nReturn the number of possible hidden sequences there are. If there are no possible sequences, return 0.",
+        "examples": [
+            "Example 1:\nInput: differences = [1,-3,4], lower = 1, upper = 6\nOutput: 2\nExplanation: The possible hidden sequences are:\n- [3, 4, 1, 5]\n- [4, 5, 2, 6]\nThus, we return 2.",
+            "Example 2:\nInput: differences = [3,-4,5,1,-2], lower = -4, upper = 5\nOutput: 4\nExplanation: The possible hidden sequences are:\n- [-3, 0, -4, 1, 2, 0]\n- [-2, 1, -3, 2, 3, 1]\n- [-1, 2, -2, 3, 4, 2]\n- [0, 3, -1, 4, 5, 3]\nThus, we return 4.",
+            "Example 3:\nInput: differences = [4,-7,2], lower = 3, upper = 6\nOutput: 0\nExplanation: There are no possible hidden sequences. Thus, we return 0."
+        ],
+        "constraints": "Constraints:\n\nn == differences.length\n1 <= n <= 10^5\n-10^5 <= differences[i] <= 10^5\n-10^5 <= lower <= upper <= 10^5",
+        "tags": [
+            "Array",
+            "Prefix Sum"
+        ],
+        "title-slug": "count-the-hidden-sequences"
+    },
+    {
+        "leetcode-id": 2146,
+        "title": "K Highest Ranked Items Within a Price Range",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed 2D integer array grid of size m x n that represents a map of the items in a shop. The integers in the grid represent the following:\n\n0 represents a wall that you cannot pass through.\n1 represents an empty cell that you can freely move to and from.\nAll other positive integers represent the price of an item in that cell. You may also freely move to and from these item cells.\n\nIt takes 1 step to travel between adjacent grid cells.\nYou are also given integer arrays pricing and start where pricing = [low, high] and start = [row, col] indicates that you start at the position (row, col) and are interested only in items with a price in the range of [low, high] (inclusive). You are further given an integer k.\nYou are interested in the positions of the k highest-ranked items whose prices are within the given price range. The rank is determined by the first of these criteria that is different:\n\nDistance, defined as the length of the shortest path from the start (shorter distance has a higher rank).\nPrice (lower price has a higher rank, but it must be in the price range).\nThe row number (smaller row number has a higher rank).\nThe column number (smaller column number has a higher rank).\n\nReturn the k highest-ranked items within the price range sorted by their rank (highest to lowest). If there are fewer than k reachable items within the price range, return all of them.",
+        "examples": [
+            "Example 1:\nInput: grid = [[1,2,0,1],[1,3,0,1],[0,2,5,1]], pricing = [2,5], start = [0,0], k = 3\nOutput: [[0,1],[1,1],[2,1]]\nExplanation: You start at (0,0).\nWith a price range of [2,5], we can take items from (0,1), (1,1), (2,1) and (2,2).\nThe ranks of these items are:\n- (0,1) with distance 1\n- (1,1) with distance 2\n- (2,1) with distance 3\n- (2,2) with distance 4\nThus, the 3 highest ranked items in the price range are (0,1), (1,1), and (2,1).",
+            "Example 2:\nInput: grid = [[1,2,0,1],[1,3,3,1],[0,2,5,1]], pricing = [2,3], start = [2,3], k = 2\nOutput: [[2,1],[1,2]]\nExplanation: You start at (2,3).\nWith a price range of [2,3], we can take items from (0,1), (1,1), (1,2) and (2,1).\nThe ranks of these items are:\n- (2,1) with distance 2, price 2\n- (1,2) with distance 2, price 3\n- (1,1) with distance 3\n- (0,1) with distance 4\nThus, the 2 highest ranked items in the price range are (2,1) and (1,2).",
+            "Example 3:\nInput: grid = [[1,1,1],[0,0,1],[2,3,4]], pricing = [2,3], start = [0,0], k = 3\nOutput: [[2,1],[2,0]]\nExplanation: You start at (0,0).\nWith a price range of [2,3], we can take items from (2,0) and (2,1). \nThe ranks of these items are: \n- (2,1) with distance 5\n- (2,0) with distance 6\nThus, the 2 highest ranked items in the price range are (2,1) and (2,0). \nNote that k = 3 but there are only 2 reachable items within the price range."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 10^5\n1 <= m * n <= 10^5\n0 <= grid[i][j] <= 10^5\npricing.length == 2\n2 <= low <= high <= 10^5\nstart.length == 2\n0 <= row <= m - 1\n0 <= col <= n - 1\ngrid[row][col] > 0\n1 <= k <= m * n",
+        "tags": [
+            "Array",
+            "Breadth-First Search",
+            "Sorting",
+            "Heap (Priority Queue)",
+            "Matrix"
+        ],
+        "title-slug": "k-highest-ranked-items-within-a-price-range"
+    },
+    {
+        "leetcode-id": 2147,
+        "title": "Number of Ways to Divide a Long Corridor",
+        "difficulty": 3,
+        "description": "Along a long library corridor, there is a line of seats and decorative plants. You are given a 0-indexed string corridor of length n consisting of letters 'S' and 'P' where each 'S' represents a seat and each 'P' represents a plant.\nOne room divider has already been installed to the left of index 0, and another to the right of index n - 1. Additional room dividers can be installed. For each position between indices i - 1 and i (1 <= i <= n - 1), at most one divider can be installed.\nDivide the corridor into non-overlapping sections, where each section has exactly two seats with any number of plants. There may be multiple ways to perform the division. Two ways are different if there is a position with a room divider installed in the first way but not in the second way.\nReturn the number of ways to divide the corridor. Since the answer may be very large, return it modulo 10^9 + 7. If there is no way, return 0.",
+        "examples": [
+            "Example 1:\nInput: corridor = \"SSPPSPS\"\nOutput: 3\nExplanation: There are 3 different ways to divide the corridor.\nThe black bars in the above image indicate the two room dividers already installed.\nNote that in each of the ways, each section has exactly two seats.",
+            "Example 2:\nInput: corridor = \"PPSPSP\"\nOutput: 1\nExplanation: There is only 1 way to divide the corridor, by not installing any additional dividers.\nInstalling any would create some section that does not have exactly two seats.",
+            "Example 3:\nInput: corridor = \"S\"\nOutput: 0\nExplanation: There is no way to divide the corridor because there will always be a section that does not have exactly two seats."
+        ],
+        "constraints": "Constraints:\n\nn == corridor.length\n1 <= n <= 10^5\ncorridor[i] is either 'S' or 'P'.",
+        "tags": [
+            "Math",
+            "String",
+            "Dynamic Programming"
+        ],
+        "title-slug": "number-of-ways-to-divide-a-long-corridor"
+    },
+    {
+        "leetcode-id": 2148,
+        "title": "Count Elements With Strictly Smaller and Greater Elements ",
+        "difficulty": 1,
+        "description": "Given an integer array nums, return the number of elements that have both a strictly smaller and a strictly greater element appear in nums.",
+        "examples": [
+            "Example 1:\nInput: nums = [11,7,2,15]\nOutput: 2\nExplanation: The element 7 has the element 2 strictly smaller than it and the element 11 strictly greater than it.\nElement 11 has element 7 strictly smaller than it and element 15 strictly greater than it.\nIn total there are 2 elements having both a strictly smaller and a strictly greater element appear in nums.",
+            "Example 2:\nInput: nums = [-3,3,3,90]\nOutput: 2\nExplanation: The element 3 has the element -3 strictly smaller than it and the element 90 strictly greater than it.\nSince there are two elements with the value 3, in total there are 2 elements having both a strictly smaller and a strictly greater element appear in nums."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 100\n-10^5 <= nums[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Sorting"
+        ],
+        "title-slug": "count-elements-with-strictly-smaller-and-greater-elements"
+    },
+    {
+        "leetcode-id": 2149,
+        "title": "Rearrange Array Elements by Sign",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers.\nYou should rearrange the elements of nums such that the modified array follows the given conditions:\n\nEvery consecutive pair of integers have opposite signs.\nFor all integers with the same sign, the order in which they were present in nums is preserved.\nThe rearranged array begins with a positive integer.\n\nReturn the modified array after rearranging the elements to satisfy the aforementioned conditions.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,1,-2,-5,2,-4]\nOutput: [3,-2,1,-5,2,-4]\nExplanation:\nThe positive integers in nums are [3,1,2]. The negative integers are [-2,-5,-4].\nThe only possible way to rearrange them such that they satisfy all conditions is [3,-2,1,-5,2,-4].\nOther ways such as [1,-2,2,-5,3,-4], [3,1,2,-2,-5,-4], [-2,3,-5,1,-4,2] are incorrect because they do not satisfy one or more conditions.",
+            "Example 2:\nInput: nums = [-1,1]\nOutput: [1,-1]\nExplanation:\n1 is the only positive integer and -1 the only negative integer in nums.\nSo nums is rearranged to [1,-1]."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 2 * 10^5\nnums.length is even\n1 <= |nums[i]| <= 10^5\nnums consists of equal number of positive and negative integers.",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Simulation"
+        ],
+        "title-slug": "rearrange-array-elements-by-sign"
+    },
+    {
+        "leetcode-id": 2150,
+        "title": "Find All Lonely Numbers in the Array",
+        "difficulty": 2,
+        "description": "You are given an integer array nums. A number x is lonely when it appears only once, and no adjacent numbers (i.e. x + 1 and x - 1) appear in the array.\nReturn all lonely numbers in nums. You may return the answer in any order.",
+        "examples": [
+            "Example 1:\nInput: nums = [10,6,5,8]\nOutput: [10,8]\nExplanation: \n- 10 is a lonely number since it appears exactly once and 9 and 11 does not appear in nums.\n- 8 is a lonely number since it appears exactly once and 7 and 9 does not appear in nums.\n- 5 is not a lonely number since 6 appears in nums and vice versa.\nHence, the lonely numbers in nums are [10, 8].\nNote that [8, 10] may also be returned.",
+            "Example 2:\nInput: nums = [1,3,5,3]\nOutput: [1,5]\nExplanation: \n- 1 is a lonely number since it appears exactly once and 0 and 2 does not appear in nums.\n- 5 is a lonely number since it appears exactly once and 4 and 6 does not appear in nums.\n- 3 is not a lonely number since it appears twice.\nHence, the lonely numbers in nums are [1, 5].\nNote that [5, 1] may also be returned."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Counting"
+        ],
+        "title-slug": "find-all-lonely-numbers-in-the-array"
+    },
+    {
+        "leetcode-id": 2151,
+        "title": "Maximum Good People Based on Statements",
+        "difficulty": 3,
+        "description": "There are two types of persons:\n\nThe good person: The person who always tells the truth.\nThe bad person: The person who might tell the truth and might lie.\n\nYou are given a 0-indexed 2D integer array statements of size n x n that represents the statements made by n people about each other. More specifically, statements[i][j] could be one of the following:\n\n0 which represents a statement made by person i that person j is a bad person.\n1 which represents a statement made by person i that person j is a good person.\n2 represents that no statement is made by person i about person j.\n\nAdditionally, no person ever makes a statement about themselves. Formally, we have that statements[i][i] = 2 for all 0 <= i < n.\nReturn the maximum number of people who can be good based on the statements made by the n people.",
+        "examples": [
+            "Example 1:\nInput: statements = [[2,1,2],[1,2,2],[2,0,2]]\nOutput: 2\nExplanation: Each person makes a single statement.\n- Person 0 states that person 1 is good.\n- Person 1 states that person 0 is good.\n- Person 2 states that person 1 is bad.\nLet's take person 2 as the key.\n- Assuming that person 2 is a good person:\n    - Based on the statement made by person 2, person 1 is a bad person.\n    - Now we know for sure that person 1 is bad and person 2 is good.\n    - Based on the statement made by person 1, and since person 1 is bad, they could be:\n        - telling the truth. There will be a contradiction in this case and this assumption is invalid.\n        - lying. In this case, person 0 is also a bad person and lied in their statement.\n    - Following that person 2 is a good person, there will be only one good person in the group.\n- Assuming that person 2 is a bad person:\n    - Based on the statement made by person 2, and since person 2 is bad, they could be:\n        - telling the truth. Following this scenario, person 0 and 1 are both bad as explained before.\n            - Following that person 2 is bad but told the truth, there will be no good persons in the group.\n        - lying. In this case person 1 is a good person.\n            - Since person 1 is a good person, person 0 is also a good person.\n            - Following that person 2 is bad and lied, there will be two good persons in the group.\nWe can see that at most 2 persons are good in the best case, so we return 2.\nNote that there is more than one way to arrive at this conclusion.",
+            "Example 2:\nInput: statements = [[2,0],[0,2]]\nOutput: 1\nExplanation: Each person makes a single statement.\n- Person 0 states that person 1 is bad.\n- Person 1 states that person 0 is bad.\nLet's take person 0 as the key.\n- Assuming that person 0 is a good person:\n    - Based on the statement made by person 0, person 1 is a bad person and was lying.\n    - Following that person 0 is a good person, there will be only one good person in the group.\n- Assuming that person 0 is a bad person:\n    - Based on the statement made by person 0, and since person 0 is bad, they could be:\n        - telling the truth. Following this scenario, person 0 and 1 are both bad.\n            - Following that person 0 is bad but told the truth, there will be no good persons in the group.\n        - lying. In this case person 1 is a good person.\n            - Following that person 0 is bad and lied, there will be only one good person in the group.\nWe can see that at most, one person is good in the best case, so we return 1.\nNote that there is more than one way to arrive at this conclusion."
+        ],
+        "constraints": "Constraints:\n\nn == statements.length == statements[i].length\n2 <= n <= 15\nstatements[i][j] is either 0, 1, or 2.\nstatements[i][i] == 2",
+        "tags": [
+            "Array",
+            "Backtracking",
+            "Bit Manipulation",
+            "Enumeration"
+        ],
+        "title-slug": "maximum-good-people-based-on-statements"
+    },
+    {
+        "leetcode-id": 2154,
+        "title": "Keep Multiplying Found Values by Two",
+        "difficulty": 1,
+        "description": "You are given an array of integers nums. You are also given an integer original which is the first number that needs to be searched for in nums.\nYou then do the following steps:\n\nIf original is found in nums, multiply it by two (i.e., set original = 2 * original).\nOtherwise, stop the process.\nRepeat this process with the new number as long as you keep finding the number.\n\nReturn the final value of original.",
+        "examples": [
+            "Example 1:\nInput: nums = [5,3,6,1,12], original = 3\nOutput: 24\nExplanation: \n- 3 is found in nums. 3 is multiplied by 2 to obtain 6.\n- 6 is found in nums. 6 is multiplied by 2 to obtain 12.\n- 12 is found in nums. 12 is multiplied by 2 to obtain 24.\n- 24 is not found in nums. Thus, 24 is returned.",
+            "Example 2:\nInput: nums = [2,7,9], original = 4\nOutput: 4\nExplanation:\n- 4 is not found in nums. Thus, 4 is returned."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i], original <= 1000",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sorting",
+            "Simulation"
+        ],
+        "title-slug": "keep-multiplying-found-values-by-two"
+    },
+    {
+        "leetcode-id": 2155,
+        "title": "All Divisions With the Highest Score of a Binary Array",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed binary array nums of length n. nums can be divided at index i (where 0 <= i <= n) into two arrays (possibly empty) numsleft and numsright:\n\nnumsleft has all the elements of nums between index 0 and i - 1 (inclusive), while numsright has all the elements of nums between index i and n - 1 (inclusive).\nIf i == 0, numsleft is empty, while numsright has all the elements of nums.\nIf i == n, numsleft has all the elements of nums, while numsright is empty.\n\nThe division score of an index i is the sum of the number of 0's in numsleft and the number of 1's in numsright.\nReturn all distinct indices that have the highest possible division score. You may return the answer in any order.",
+        "examples": [
+            "Example 1:\nInput: nums = [0,0,1,0]\nOutput: [2,4]\nExplanation: Division at index\n- 0: numsleft is []. numsright is [0,0,1,0]. The score is 0 + 1 = 1.\n- 1: numsleft is [0]. numsright is [0,1,0]. The score is 1 + 1 = 2.\n- 2: numsleft is [0,0]. numsright is [1,0]. The score is 2 + 1 = 3.\n- 3: numsleft is [0,0,1]. numsright is [0]. The score is 2 + 0 = 2.\n- 4: numsleft is [0,0,1,0]. numsright is []. The score is 3 + 0 = 3.\nIndices 2 and 4 both have the highest possible division score 3.\nNote the answer [4,2] would also be accepted.",
+            "Example 2:\nInput: nums = [0,0,0]\nOutput: [3]\nExplanation: Division at index\n- 0: numsleft is []. numsright is [0,0,0]. The score is 0 + 0 = 0.\n- 1: numsleft is [0]. numsright is [0,0]. The score is 1 + 0 = 1.\n- 2: numsleft is [0,0]. numsright is [0]. The score is 2 + 0 = 2.\n- 3: numsleft is [0,0,0]. numsright is []. The score is 3 + 0 = 3.\nOnly index 3 has the highest possible division score 3.",
+            "Example 3:\nInput: nums = [1,1]\nOutput: [0]\nExplanation: Division at index\n- 0: numsleft is []. numsright is [1,1]. The score is 0 + 2 = 2.\n- 1: numsleft is [1]. numsright is [1]. The score is 0 + 1 = 1.\n- 2: numsleft is [1,1]. numsright is []. The score is 0 + 0 = 0.\nOnly index 0 has the highest possible division score 2."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^5\nnums[i] is either 0 or 1.",
+        "tags": [
+            "Array"
+        ],
+        "title-slug": "all-divisions-with-the-highest-score-of-a-binary-array"
+    },
+    {
+        "leetcode-id": 2156,
+        "title": "Find Substring With Given Hash Value",
+        "difficulty": 3,
+        "description": "The hash of a 0-indexed string s of length k, given integers p and m, is computed using the following function:\n\nhash(s, p, m) = (val(s[0]) * p^0 + val(s[1]) * p^1 + ... + val(s[k-1]) * p^k-1) mod m.\n\nWhere val(s[i]) represents the index of s[i] in the alphabet from val('a') = 1 to val('z') = 26.\nYou are given a string s and the integers power, modulo, k, and hashValue. Return sub, the first substring of s of length k such that hash(sub, power, modulo) == hashValue.\nThe test cases will be generated such that an answer always exists.\nA substring is a contiguous non-empty sequence of characters within a string.",
+        "examples": [
+            "Example 1:\nInput: s = \"leetcode\", power = 7, modulo = 20, k = 2, hashValue = 0\nOutput: \"ee\"\nExplanation: The hash of \"ee\" can be computed to be hash(\"ee\", 7, 20) = (5 * 1 + 5 * 7) mod 20 = 40 mod 20 = 0. \n\"ee\" is the first substring of length 2 with hashValue 0. Hence, we return \"ee\".",
+            "Example 2:\nInput: s = \"fbxzaad\", power = 31, modulo = 100, k = 3, hashValue = 32\nOutput: \"fbx\"\nExplanation: The hash of \"fbx\" can be computed to be hash(\"fbx\", 31, 100) = (6 * 1 + 2 * 31 + 24 * 31^2) mod 100 = 23132 mod 100 = 32. \nThe hash of \"bxz\" can be computed to be hash(\"bxz\", 31, 100) = (2 * 1 + 24 * 31 + 26 * 31^2) mod 100 = 25732 mod 100 = 32. \n\"fbx\" is the first substring of length 3 with hashValue 32. Hence, we return \"fbx\".\nNote that \"bxz\" also has a hash of 32 but it appears later than \"fbx\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= k <= s.length <= 2 * 10^4\n1 <= power, modulo <= 10^9\n0 <= hashValue < modulo\ns consists of lowercase English letters only.\nThe test cases are generated such that an answer always exists.",
+        "tags": [
+            "String",
+            "Sliding Window",
+            "Rolling Hash",
+            "Hash Function"
+        ],
+        "title-slug": "find-substring-with-given-hash-value"
+    },
+    {
+        "leetcode-id": 2157,
+        "title": "Groups of Strings",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed array of strings words. Each string consists of lowercase English letters only. No letter occurs more than once in any string of words.\nTwo strings s1 and s2 are said to be connected if the set of letters of s2 can be obtained from the set of letters of s1 by any one of the following operations:\n\nAdding exactly one letter to the set of the letters of s1.\nDeleting exactly one letter from the set of the letters of s1.\nReplacing exactly one letter from the set of the letters of s1 with any letter, including itself.\n\nThe array words can be divided into one or more non-intersecting groups. A string belongs to a group if any one of the following is true:\n\nIt is connected to at least one other string of the group.\nIt is the only string present in the group.\n\nNote that the strings in words should be grouped in such a manner that a string belonging to a group cannot be connected to a string present in any other group. It can be proved that such an arrangement is always unique.\nReturn an array ans of size 2 where:\n\nans[0] is the maximum number of groups words can be divided into, and\nans[1] is the size of the largest group.",
+        "examples": [
+            "Example 1:\nInput: words = [\"a\",\"b\",\"ab\",\"cde\"]\nOutput: [2,3]\nExplanation:\n- words[0] can be used to obtain words[1] (by replacing 'a' with 'b'), and words[2] (by adding 'b'). So words[0] is connected to words[1] and words[2].\n- words[1] can be used to obtain words[0] (by replacing 'b' with 'a'), and words[2] (by adding 'a'). So words[1] is connected to words[0] and words[2].\n- words[2] can be used to obtain words[0] (by deleting 'b'), and words[1] (by deleting 'a'). So words[2] is connected to words[0] and words[1].\n- words[3] is not connected to any string in words.\nThus, words can be divided into 2 groups [\"a\",\"b\",\"ab\"] and [\"cde\"]. The size of the largest group is 3.",
+            "Example 2:\nInput: words = [\"a\",\"ab\",\"abc\"]\nOutput: [1,3]\nExplanation:\n- words[0] is connected to words[1].\n- words[1] is connected to words[0] and words[2].\n- words[2] is connected to words[1].\nSince all strings are connected to each other, they should be grouped together.\nThus, the size of the largest group is 3."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 2 * 10^4\n1 <= words[i].length <= 26\nwords[i] consists of lowercase English letters only.\nNo letter occurs more than once in words[i].",
+        "tags": [
+            "String",
+            "Bit Manipulation",
+            "Union Find"
+        ],
+        "title-slug": "groups-of-strings"
+    },
+    {
+        "leetcode-id": 2160,
+        "title": "Minimum Sum of Four Digit Number After Splitting Digits",
+        "difficulty": 1,
+        "description": "You are given a positive integer num consisting of exactly four digits. Split num into two new integers new1 and new2 by using the digits found in num. Leading zeros are allowed in new1 and new2, and all the digits found in num must be used.\n\nFor example, given num = 2932, you have the following digits: two 2's, one 9 and one 3. Some of the possible pairs [new1, new2] are [22, 93], [23, 92], [223, 9] and [2, 329].\n\nReturn the minimum possible sum of new1 and new2.",
+        "examples": [
+            "Example 1:\nInput: num = 2932\nOutput: 52\nExplanation: Some possible pairs [new1, new2] are [29, 23], [223, 9], etc.\nThe minimum sum can be obtained by the pair [29, 23]: 29 + 23 = 52.",
+            "Example 2:\nInput: num = 4009\nOutput: 13\nExplanation: Some possible pairs [new1, new2] are [0, 49], [490, 0], etc. \nThe minimum sum can be obtained by the pair [4, 9]: 4 + 9 = 13."
+        ],
+        "constraints": "Constraints:\n\n1000 <= num <= 9999",
+        "tags": [
+            "Math",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "minimum-sum-of-four-digit-number-after-splitting-digits"
+    },
+    {
+        "leetcode-id": 2161,
+        "title": "Partition Array According to Given Pivot",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied:\n\nEvery element less than pivot appears before every element greater than pivot.\nEvery element equal to pivot appears in between the elements less than and greater than pivot.\nThe relative order of the elements less than pivot and the elements greater than pivot is maintained.\n\t\nMore formally, consider every pi, pj where pi is the new position of the i^th element and pj is the new position of the j^th element. For elements less than pivot, if i < j and nums[i] < pivot and nums[j] < pivot, then pi < pj. Similarly for elements greater than pivot, if i < j and nums[i] > pivot and nums[j] > pivot, then pi < pj.\n\n\n\nReturn nums after the rearrangement.",
+        "examples": [
+            "Example 1:\nInput: nums = [9,12,5,10,14,3,10], pivot = 10\nOutput: [9,5,3,10,10,12,14]\nExplanation: \nThe elements 9, 5, and 3 are less than the pivot so they are on the left side of the array.\nThe elements 12 and 14 are greater than the pivot so they are on the right side of the array.\nThe relative ordering of the elements less than and greater than pivot is also maintained. [9, 5, 3] and [12, 14] are the respective orderings.",
+            "Example 2:\nInput: nums = [-3,4,3,2], pivot = 2\nOutput: [-3,2,4,3]\nExplanation: \nThe element -3 is less than the pivot so it is on the left side of the array.\nThe elements 4 and 3 are greater than the pivot so they are on the right side of the array.\nThe relative ordering of the elements less than and greater than pivot is also maintained. [-3] and [4, 3] are the respective orderings."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^6 <= nums[i] <= 10^6\npivot equals to an element of nums.",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Simulation"
+        ],
+        "title-slug": "partition-array-according-to-given-pivot"
+    },
+    {
+        "leetcode-id": 2162,
+        "title": "Minimum Cost to Set Cooking Time",
+        "difficulty": 2,
+        "description": "A generic microwave supports cooking times for:\n\nat least 1 second.\nat most 99 minutes and 99 seconds.\n\nTo set the cooking time, you push at most four digits. The microwave normalizes what you push as four digits by prepending zeroes. It interprets the first two digits as the minutes and the last two digits as the seconds. It then adds them up as the cooking time. For example,\n\nYou push 9 5 4 (three digits). It is normalized as 0954 and interpreted as 9 minutes and 54 seconds.\nYou push 0 0 0 8 (four digits). It is interpreted as 0 minutes and 8 seconds.\nYou push 8 0 9 0. It is interpreted as 80 minutes and 90 seconds.\nYou push 8 1 3 0. It is interpreted as 81 minutes and 30 seconds.\n\nYou are given integers startAt, moveCost, pushCost, and targetSeconds. Initially, your finger is on the digit startAt. Moving the finger above any specific digit costs moveCost units of fatigue. Pushing the digit below the finger once costs pushCost units of fatigue.\nThere can be multiple ways to set the microwave to cook for targetSeconds seconds but you are interested in the way with the minimum cost.\nReturn the minimum cost to set targetSeconds seconds of cooking time.\nRemember that one minute consists of 60 seconds.",
+        "examples": [
+            "Example 1:\nInput: startAt = 1, moveCost = 2, pushCost = 1, targetSeconds = 600\nOutput: 6\nExplanation: The following are the possible ways to set the cooking time.\n- 1 0 0 0, interpreted as 10 minutes and 0 seconds.\n\u00a0 The finger is already on digit 1, pushes 1 (with cost 1), moves to 0 (with cost 2), pushes 0 (with cost 1), pushes 0 (with cost 1), and pushes 0 (with cost 1).\n\u00a0 The cost is: 1 + 2 + 1 + 1 + 1 = 6. This is the minimum cost.\n- 0 9 6 0, interpreted as 9 minutes and 60 seconds. That is also 600 seconds.\n\u00a0 The finger moves to 0 (with cost 2), pushes 0 (with cost 1), moves to 9 (with cost 2), pushes 9 (with cost 1), moves to 6 (with cost 2), pushes 6 (with cost 1), moves to 0 (with cost 2), and pushes 0 (with cost 1).\n\u00a0 The cost is: 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 = 12.\n- 9 6 0, normalized as 0960 and interpreted as 9 minutes and 60 seconds.\n\u00a0 The finger moves to 9 (with cost 2), pushes 9 (with cost 1), moves to 6 (with cost 2), pushes 6 (with cost 1), moves to 0 (with cost 2), and pushes 0 (with cost 1).\n\u00a0 The cost is: 2 + 1 + 2 + 1 + 2 + 1 = 9.",
+            "Example 2:\nInput: startAt = 0, moveCost = 1, pushCost = 2, targetSeconds = 76\nOutput: 6\nExplanation: The optimal way is to push two digits: 7 6, interpreted as 76 seconds.\nThe finger moves to 7 (with cost 1), pushes 7 (with cost 2), moves to 6 (with cost 1), and pushes 6 (with cost 2). The total cost is: 1 + 2 + 1 + 2 = 6\nNote other possible ways are 0076, 076, 0116, and 116, but none of them produces the minimum cost."
+        ],
+        "constraints": "Constraints:\n\n0 <= startAt <= 9\n1 <= moveCost, pushCost <= 10^5\n1 <= targetSeconds <= 6039",
+        "tags": [
+            "Math",
+            "Enumeration"
+        ],
+        "title-slug": "minimum-cost-to-set-cooking-time"
+    },
+    {
+        "leetcode-id": 2163,
+        "title": "Minimum Difference in Sums After Removal of Elements",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed integer array nums consisting of 3 * n elements.\nYou are allowed to remove any subsequence of elements of size exactly n from nums. The remaining 2 * n elements will be divided into two equal parts:\n\nThe first n elements belonging to the first part and their sum is sumfirst.\nThe next n elements belonging to the second part and their sum is sumsecond.\n\nThe difference in sums of the two parts is denoted as sumfirst - sumsecond.\n\nFor example, if sumfirst = 3 and sumsecond = 2, their difference is 1.\nSimilarly, if sumfirst = 2 and sumsecond = 3, their difference is -1.\n\nReturn the minimum difference possible between the sums of the two parts after the removal of n elements.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,1,2]\nOutput: -1\nExplanation: Here, nums has 3 elements, so n = 1. \nThus we have to remove 1 element from nums and divide the array into two equal parts.\n- If we remove nums[0] = 3, the array will be [1,2]. The difference in sums of the two parts will be 1 - 2 = -1.\n- If we remove nums[1] = 1, the array will be [3,2]. The difference in sums of the two parts will be 3 - 2 = 1.\n- If we remove nums[2] = 2, the array will be [3,1]. The difference in sums of the two parts will be 3 - 1 = 2.\nThe minimum difference between sums of the two parts is min(-1,1,2) = -1.",
+            "Example 2:\nInput: nums = [7,9,5,8,1,3]\nOutput: 1\nExplanation: Here n = 2. So we must remove 2 elements and divide the remaining array into two parts containing two elements each.\nIf we remove nums[2] = 5 and nums[3] = 8, the resultant array will be [7,9,1,3]. The difference in sums will be (7+9) - (1+3) = 12.\nTo obtain the minimum difference, we should remove nums[1] = 9 and nums[4] = 1. The resultant array becomes [7,5,8,3]. The difference in sums of the two parts is (7+5) - (8+3) = 1.\nIt can be shown that it is not possible to obtain a difference smaller than 1."
+        ],
+        "constraints": "Constraints:\n\nnums.length == 3 * n\n1 <= n <= 10^5\n1 <= nums[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "minimum-difference-in-sums-after-removal-of-elements"
+    },
+    {
+        "leetcode-id": 2164,
+        "title": "Sort Even and Odd Indices Independently",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums. Rearrange the values of nums according to the following rules:\n\nSort the values at odd indices of nums in non-increasing order.\n\n\t\nFor example, if nums = [4,1,2,3] before this step, it becomes [4,3,2,1] after. The values at odd indices 1 and 3 are sorted in non-increasing order.\n\n\nSort the values at even indices of nums in non-decreasing order.\n\t\nFor example, if nums = [4,1,2,3] before this step, it becomes [2,1,4,3] after. The values at even indices 0 and 2 are sorted in non-decreasing order.\n\n\n\nReturn the array formed after rearranging the values of nums.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,1,2,3]\nOutput: [2,3,4,1]\nExplanation: \nFirst, we sort the values present at odd indices (1 and 3) in non-increasing order.\nSo, nums changes from [4,1,2,3] to [4,3,2,1].\nNext, we sort the values present at even indices (0 and 2) in non-decreasing order.\nSo, nums changes from [4,1,2,3] to [2,3,4,1].\nThus, the array formed after rearranging the values is [2,3,4,1].",
+            "Example 2:\nInput: nums = [2,1]\nOutput: [2,1]\nExplanation: \nSince there is exactly one odd index and one even index, no rearrangement of values takes place.\nThe resultant array formed is [2,1], which is the same as the initial array."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100",
+        "tags": [
+            "Array",
+            "Sorting"
+        ],
+        "title-slug": "sort-even-and-odd-indices-independently"
+    },
+    {
+        "leetcode-id": 2165,
+        "title": "Smallest Value of the Rearranged Number",
+        "difficulty": 2,
+        "description": "You are given an integer num. Rearrange the digits of num such that its value is minimized and it does not contain any leading zeros.\nReturn the rearranged number with minimal value.\nNote that the sign of the number does not change after rearranging the digits.",
+        "examples": [
+            "Example 1:\nInput: num = 310\nOutput: 103\nExplanation: The possible arrangements for the digits of 310 are 013, 031, 103, 130, 301, 310. \nThe arrangement with the smallest value that does not contain any leading zeros is 103.",
+            "Example 2:\nInput: num = -7605\nOutput: -7650\nExplanation: Some possible arrangements for the digits of -7605 are -7650, -6705, -5076, -0567.\nThe arrangement with the smallest value that does not contain any leading zeros is -7650."
+        ],
+        "constraints": "Constraints:\n\n-10^15 <= num <= 10^15",
+        "tags": [
+            "Math",
+            "Sorting"
+        ],
+        "title-slug": "smallest-value-of-the-rearranged-number"
+    },
+    {
+        "leetcode-id": 2166,
+        "title": "Design Bitset",
+        "difficulty": 2,
+        "description": "A Bitset is a data structure that compactly stores bits.\nImplement the Bitset class:\n\nBitset(int size) Initializes the Bitset with size bits, all of which are 0.\nvoid fix(int idx) Updates the value of the bit at the index idx to 1. If the value was already 1, no change occurs.\nvoid unfix(int idx) Updates the value of the bit at the index idx to 0. If the value was already 0, no change occurs.\nvoid flip() Flips the values of each bit in the Bitset. In other words, all bits with value 0 will now have value 1 and vice versa.\nboolean all() Checks if the value of each bit in the Bitset is 1. Returns true if it satisfies the condition, false otherwise.\nboolean one() Checks if there is at least one bit in the Bitset with value 1. Returns true if it satisfies the condition, false otherwise.\nint count() Returns the total number of bits in the Bitset which have value 1.\nString toString() Returns the current composition of the Bitset. Note that in the resultant string, the character at the i^th index should coincide with the value at the i^th bit of the Bitset.",
+        "examples": [
+            "Example 1:\nInput\n[\"Bitset\", \"fix\", \"fix\", \"flip\", \"all\", \"unfix\", \"flip\", \"one\", \"unfix\", \"count\", \"toString\"]\n[[5], [3], [1], [], [], [0], [], [], [0], [], []]\nOutput\n[null, null, null, null, false, null, null, true, null, 2, \"01010\"]\n\nExplanation\nBitset bs = new Bitset(5); // bitset = \"00000\".\nbs.fix(3);     // the value at idx = 3 is updated to 1, so bitset = \"00010\".\nbs.fix(1);     // the value at idx = 1 is updated to 1, so bitset = \"01010\". \nbs.flip();     // the value of each bit is flipped, so bitset = \"10101\". \nbs.all();      // return False, as not all values of the bitset are 1.\nbs.unfix(0);   // the value at idx = 0 is updated to 0, so bitset = \"00101\".\nbs.flip();     // the value of each bit is flipped, so bitset = \"11010\". \nbs.one();      // return True, as there is at least 1 index with value 1.\nbs.unfix(0);   // the value at idx = 0 is updated to 0, so bitset = \"01010\".\nbs.count();    // return 2, as there are 2 bits with value 1.\nbs.toString(); // return \"01010\", which is the composition of bitset."
+        ],
+        "constraints": "Constraints:\n\n1 <= size <= 10^5\n0 <= idx <= size - 1\nAt most 10^5 calls will be made in total to fix, unfix, flip, all, one, count, and toString.\nAt least one call will be made to all, one, count, or toString.\nAt most 5 calls will be made to toString.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Design"
+        ],
+        "title-slug": "design-bitset"
+    },
+    {
+        "leetcode-id": 2167,
+        "title": "Minimum Time to Remove All Cars Containing Illegal Goods",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed binary string s which represents a sequence of train cars. s[i] = '0' denotes that the i^th car does not contain illegal goods and s[i] = '1' denotes that the i^th car does contain illegal goods.\nAs the train conductor, you would like to get rid of all the cars containing illegal goods. You can do any of the following three operations any number of times:\n\nRemove a train car from the left end (i.e., remove s[0]) which takes 1 unit of time.\nRemove a train car from the right end (i.e., remove s[s.length - 1]) which takes 1 unit of time.\nRemove a train car from anywhere in the sequence which takes 2 units of time.\n\nReturn the minimum time to remove all the cars containing illegal goods.\nNote that an empty sequence of cars is considered to have no cars containing illegal goods.",
+        "examples": [
+            "Example 1:\nInput: s = \"1100101\"\nOutput: 5\nExplanation: \nOne way to remove all the cars containing illegal goods from the sequence is to\n- remove a car from the left end 2 times. Time taken is 2 * 1 = 2.\n- remove a car from the right end. Time taken is 1.\n- remove the car containing illegal goods found in the middle. Time taken is 2.\nThis obtains a total time of 2 + 1 + 2 = 5. \n\nAn alternative way is to\n- remove a car from the left end 2 times. Time taken is 2 * 1 = 2.\n- remove a car from the right end 3 times. Time taken is 3 * 1 = 3.\nThis also obtains a total time of 2 + 3 = 5.\n\n5 is the minimum time taken to remove all the cars containing illegal goods. \nThere are no other ways to remove them with less time.",
+            "Example 2:\nInput: s = \"0010\"\nOutput: 2\nExplanation:\nOne way to remove all the cars containing illegal goods from the sequence is to\n- remove a car from the left end 3 times. Time taken is 3 * 1 = 3.\nThis obtains a total time of 3.\n\nAnother way to remove all the cars containing illegal goods from the sequence is to\n- remove the car containing illegal goods found in the middle. Time taken is 2.\nThis obtains a total time of 2.\n\nAnother way to remove all the cars containing illegal goods from the sequence is to \n- remove a car from the right end 2 times. Time taken is 2 * 1 = 2. \nThis obtains a total time of 2.\n\n2 is the minimum time taken to remove all the cars containing illegal goods. \nThere are no other ways to remove them with less time."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 2 * 10^5\ns[i] is either '0' or '1'.",
+        "tags": [
+            "String",
+            "Dynamic Programming"
+        ],
+        "title-slug": "minimum-time-to-remove-all-cars-containing-illegal-goods"
+    },
+    {
+        "leetcode-id": 2169,
+        "title": "Count Operations to Obtain Zero",
+        "difficulty": 1,
+        "description": "You are given two non-negative integers num1 and num2.\nIn one operation, if num1 >= num2, you must subtract num2 from num1, otherwise subtract num1 from num2.\n\nFor example, if num1 = 5 and num2 = 4, subtract num2 from num1, thus obtaining num1 = 1 and num2 = 4. However, if num1 = 4 and num2 = 5, after one operation, num1 = 4 and num2 = 1.\n\nReturn the number of operations required to make either num1 = 0 or num2 = 0.",
+        "examples": [
+            "Example 1:\nInput: num1 = 2, num2 = 3\nOutput: 3\nExplanation: \n- Operation 1: num1 = 2, num2 = 3. Since num1 < num2, we subtract num1 from num2 and get num1 = 2, num2 = 3 - 2 = 1.\n- Operation 2: num1 = 2, num2 = 1. Since num1 > num2, we subtract num2 from num1.\n- Operation 3: num1 = 1, num2 = 1. Since num1 == num2, we subtract num2 from num1.\nNow num1 = 0 and num2 = 1. Since num1 == 0, we do not need to perform any further operations.\nSo the total number of operations required is 3.",
+            "Example 2:\nInput: num1 = 10, num2 = 10\nOutput: 1\nExplanation: \n- Operation 1: num1 = 10, num2 = 10. Since num1 == num2, we subtract num2 from num1 and get num1 = 10 - 10 = 0.\nNow num1 = 0 and num2 = 10. Since num1 == 0, we are done.\nSo the total number of operations required is 1."
+        ],
+        "constraints": "Constraints:\n\n0 <= num1, num2 <= 10^5",
+        "tags": [
+            "Math",
+            "Simulation"
+        ],
+        "title-slug": "count-operations-to-obtain-zero"
+    },
+    {
+        "leetcode-id": 2170,
+        "title": "Minimum Operations to Make the Array Alternating",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array nums consisting of n positive integers.\nThe array nums is called alternating if:\n\nnums[i - 2] == nums[i], where 2 <= i <= n - 1.\nnums[i - 1] != nums[i], where 1 <= i <= n - 1.\n\nIn one operation, you can choose an index i and change nums[i] into any positive integer.\nReturn the minimum number of operations required to make the array alternating.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,1,3,2,4,3]\nOutput: 3\nExplanation:\nOne way to make the array alternating is by converting it to [3,1,3,1,3,1].\nThe number of operations required in this case is 3.\nIt can be proven that it is not possible to make the array alternating in less than 3 operations.",
+            "Example 2:\nInput: nums = [1,2,2,2,2]\nOutput: 2\nExplanation:\nOne way to make the array alternating is by converting it to [1,2,1,2,1].\nThe number of operations required in this case is 2.\nNote that the array cannot be converted to [2,2,2,2,2] because in this case nums[0] == nums[1] which violates the conditions of an alternating array."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Greedy",
+            "Counting"
+        ],
+        "title-slug": "minimum-operations-to-make-the-array-alternating"
+    },
+    {
+        "leetcode-id": 2171,
+        "title": "Removing Minimum Number of Magic Beans",
+        "difficulty": 2,
+        "description": "You are given an array of positive integers beans, where each integer represents the number of magic beans found in a particular magic bag.\nRemove any number of beans (possibly none) from each bag such that the number of beans in each remaining non-empty bag (still containing at least one bean) is equal. Once a bean has been removed from a bag, you are not allowed to return it to any of the bags.\nReturn the minimum number of magic beans that you have to remove.",
+        "examples": [
+            "Example 1:\nInput: beans = [4,1,6,5]\nOutput: 4\nExplanation: \n- We remove 1 bean from the bag with only 1 bean.\n  This results in the remaining bags: [4,0,6,5]\n- Then we remove 2 beans from the bag with 6 beans.\n  This results in the remaining bags: [4,0,4,5]\n- Then we remove 1 bean from the bag with 5 beans.\n  This results in the remaining bags: [4,0,4,4]\nWe removed a total of 1 + 2 + 1 = 4 beans to make the remaining non-empty bags have an equal number of beans.\nThere are no other solutions that remove 4 beans or fewer.",
+            "Example 2:\nInput: beans = [2,10,3,2]\nOutput: 7\nExplanation:\n- We remove 2 beans from one of the bags with 2 beans.\n  This results in the remaining bags: [0,10,3,2]\n- Then we remove 2 beans from the other bag with 2 beans.\n  This results in the remaining bags: [0,10,3,0]\n- Then we remove 3 beans from the bag with 3 beans. \n  This results in the remaining bags: [0,10,0,0]\nWe removed a total of 2 + 2 + 3 = 7 beans to make the remaining non-empty bags have an equal number of beans.\nThere are no other solutions that removes 7 beans or fewer."
+        ],
+        "constraints": "Constraints:\n\n1 <= beans.length <= 10^5\n1 <= beans[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Sorting",
+            "Prefix Sum"
+        ],
+        "title-slug": "removing-minimum-number-of-magic-beans"
+    },
+    {
+        "leetcode-id": 2172,
+        "title": "Maximum AND Sum of Array",
+        "difficulty": 3,
+        "description": "You are given an integer array nums of length n and an integer numSlots such that 2 * numSlots >= n. There are numSlots slots numbered from 1 to numSlots.\nYou have to place all n integers into the slots such that each slot contains at most two numbers. The AND sum of a given placement is the sum of the bitwise AND of every number with its respective slot number.\n\nFor example, the AND sum of placing the numbers [1, 3] into slot 1 and [4, 6] into slot 2 is equal to (1 AND 1) + (3 AND 1) + (4 AND 2) + (6 AND 2) = 1 + 1 + 0 + 2 = 4.\n\nReturn the maximum possible AND sum of nums given numSlots slots.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,3,4,5,6], numSlots = 3\nOutput: 9\nExplanation: One possible placement is [1, 4] into slot 1, [2, 6] into slot 2, and [3, 5] into slot 3. \nThis gives the maximum AND sum of (1 AND 1) + (4 AND 1) + (2 AND 2) + (6 AND 2) + (3 AND 3) + (5 AND 3) = 1 + 0 + 2 + 2 + 3 + 1 = 9.",
+            "Example 2:\nInput: nums = [1,3,10,4,7,1], numSlots = 9\nOutput: 24\nExplanation: One possible placement is [1, 1] into slot 1, [3] into slot 3, [4] into slot 4, [7] into slot 7, and [10] into slot 9.\nThis gives the maximum AND sum of (1 AND 1) + (1 AND 1) + (3 AND 3) + (4 AND 4) + (7 AND 7) + (10 AND 9) = 1 + 1 + 3 + 4 + 7 + 8 = 24.\nNote that slots 2, 5, 6, and 8 are empty which is permitted."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length\n1 <= numSlots <= 9\n1 <= n <= 2 * numSlots\n1 <= nums[i] <= 15",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Bit Manipulation",
+            "Bitmask"
+        ],
+        "title-slug": "maximum-and-sum-of-array"
+    },
+    {
+        "leetcode-id": 2176,
+        "title": "Count Equal and Divisible Pairs in an Array",
+        "difficulty": 1,
+        "description": "Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) where 0 <= i < j < n, such that nums[i] == nums[j] and (i * j) is divisible by k.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,1,2,2,2,1,3], k = 2\nOutput: 4\nExplanation:\nThere are 4 pairs that meet all the requirements:\n- nums[0] == nums[6], and 0 * 6 == 0, which is divisible by 2.\n- nums[2] == nums[3], and 2 * 3 == 6, which is divisible by 2.\n- nums[2] == nums[4], and 2 * 4 == 8, which is divisible by 2.\n- nums[3] == nums[4], and 3 * 4 == 12, which is divisible by 2.",
+            "Example 2:\nInput: nums = [1,2,3,4], k = 1\nOutput: 0\nExplanation: Since no value in nums is repeated, there are no pairs (i,j) that meet all the requirements."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= nums[i], k <= 100",
+        "tags": [
+            "Array"
+        ],
+        "title-slug": "count-equal-and-divisible-pairs-in-an-array"
+    },
+    {
+        "leetcode-id": 2177,
+        "title": "Find Three Consecutive Integers That Sum to a Given Number",
+        "difficulty": 2,
+        "description": "Given an integer num, return three consecutive integers (as a sorted array) that sum to num. If num cannot be expressed as the sum of three consecutive integers, return an empty array.",
+        "examples": [
+            "Example 1:\nInput: num = 33\nOutput: [10,11,12]\nExplanation: 33 can be expressed as 10 + 11 + 12 = 33.\n10, 11, 12 are 3 consecutive integers, so we return [10, 11, 12].",
+            "Example 2:\nInput: num = 4\nOutput: []\nExplanation: There is no way to express 4 as the sum of 3 consecutive integers."
+        ],
+        "constraints": "Constraints:\n\n0 <= num <= 10^15",
+        "tags": [
+            "Math",
+            "Simulation"
+        ],
+        "title-slug": "find-three-consecutive-integers-that-sum-to-a-given-number"
+    },
+    {
+        "leetcode-id": 2178,
+        "title": "Maximum Split of Positive Even Integers",
+        "difficulty": 2,
+        "description": "You are given an integer finalSum. Split it into a sum of a maximum number of unique positive even integers.\n\nFor example, given finalSum = 12, the following splits are valid (unique positive even integers summing up to finalSum): (12), (2 + 10), (2 + 4 + 6), and (4 + 8). Among them, (2 + 4 + 6) contains the maximum number of integers. Note that finalSum cannot be split into (2 + 2 + 4 + 4) as all the numbers should be unique.\n\nReturn a list of integers that represent a valid split containing a maximum number of integers. If no valid split exists for finalSum, return an empty list. You may return the integers in any order.",
+        "examples": [
+            "Example 1:\nInput: finalSum = 12\nOutput: [2,4,6]\nExplanation: The following are valid splits: (12), (2 + 10), (2 + 4 + 6), and (4 + 8).\n(2 + 4 + 6) has the maximum number of integers, which is 3. Thus, we return [2,4,6].\nNote that [2,6,4], [6,2,4], etc. are also accepted.",
+            "Example 2:\nInput: finalSum = 7\nOutput: []\nExplanation: There are no valid splits for the given finalSum.\nThus, we return an empty array.",
+            "Example 3:\nInput: finalSum = 28\nOutput: [6,8,2,12]\nExplanation: The following are valid splits: (2 + 26), (6 + 8 + 2 + 12), and (4 + 24). \n(6 + 8 + 2 + 12) has the maximum number of integers, which is 4. Thus, we return [6,8,2,12].\nNote that [10,2,4,12], [6,2,4,16], etc. are also accepted."
+        ],
+        "constraints": "Constraints:\n\n1 <= finalSum <= 10^10",
+        "tags": [
+            "Math",
+            "Backtracking",
+            "Greedy"
+        ],
+        "title-slug": "maximum-split-of-positive-even-integers"
+    },
+    {
+        "leetcode-id": 2179,
+        "title": "Count Good Triplets in an Array",
+        "difficulty": 3,
+        "description": "You are given two 0-indexed arrays nums1 and nums2 of length n, both of which are permutations of [0, 1, ..., n - 1].\nA good triplet is a set of 3 distinct values which are present in increasing order by position both in nums1 and nums2. In other words, if we consider pos1v as the index of the value v in nums1 and pos2v as the index of the value v in nums2, then a good triplet will be a set (x, y, z) where 0 <= x, y, z <= n - 1, such that pos1x < pos1y < pos1z and pos2x < pos2y < pos2z.\nReturn the total number of good triplets.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [2,0,1,3], nums2 = [0,1,2,3]\nOutput: 1\nExplanation: \nThere are 4 triplets (x,y,z) such that pos1x < pos1y < pos1z. They are (2,0,1), (2,0,3), (2,1,3), and (0,1,3). \nOut of those triplets, only the triplet (0,1,3) satisfies pos2x < pos2y < pos2z. Hence, there is only 1 good triplet.",
+            "Example 2:\nInput: nums1 = [4,0,1,3,2], nums2 = [4,1,0,2,3]\nOutput: 4\nExplanation: The 4 good triplets are (4,0,3), (4,0,2), (4,1,3), and (4,1,2)."
+        ],
+        "constraints": "Constraints:\n\nn == nums1.length == nums2.length\n3 <= n <= 10^5\n0 <= nums1[i], nums2[i] <= n - 1\nnums1 and nums2 are permutations of [0, 1, ..., n - 1].",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Divide and Conquer",
+            "Binary Indexed Tree",
+            "Segment Tree",
+            "Merge Sort",
+            "Ordered Set"
+        ],
+        "title-slug": "count-good-triplets-in-an-array"
+    },
+    {
+        "leetcode-id": 2180,
+        "title": "Count Integers With Even Digit Sum",
+        "difficulty": 1,
+        "description": "Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are even.\nThe digit sum of a positive integer is the sum of all its digits.",
+        "examples": [
+            "Example 1:\nInput: num = 4\nOutput: 2\nExplanation:\nThe only integers less than or equal to 4 whose digit sums are even are 2 and 4.",
+            "Example 2:\nInput: num = 30\nOutput: 14\nExplanation:\nThe 14 integers less than or equal to 30 whose digit sums are even are\n2, 4, 6, 8, 11, 13, 15, 17, 19, 20, 22, 24, 26, and 28."
+        ],
+        "constraints": "Constraints:\n\n1 <= num <= 1000",
+        "tags": [
+            "Math",
+            "Simulation"
+        ],
+        "title-slug": "count-integers-with-even-digit-sum"
+    },
+    {
+        "leetcode-id": 2181,
+        "title": "Merge Nodes in Between Zeros",
+        "difficulty": 2,
+        "description": "You are given the head of a linked list, which contains a series of integers separated by 0's. The beginning and end of the linked list will have Node.val == 0.\nFor every two consecutive 0's, merge all the nodes lying in between them into a single node whose value is the sum of all the merged nodes. The modified list should not contain any 0's.\nReturn the head of the modified linked list.",
+        "examples": [
+            "Example 1:\nInput: head = [0,3,1,0,4,5,2,0]\nOutput: [4,11]\nExplanation: \nThe above figure represents the given linked list. The modified list contains\n- The sum of the nodes marked in green: 3 + 1 = 4.\n- The sum of the nodes marked in red: 4 + 5 + 2 = 11.",
+            "Example 2:\nInput: head = [0,1,0,3,0,2,2,0]\nOutput: [1,3,4]\nExplanation: \nThe above figure represents the given linked list. The modified list contains\n- The sum of the nodes marked in green: 1 = 1.\n- The sum of the nodes marked in red: 3 = 3.\n- The sum of the nodes marked in yellow: 2 + 2 = 4."
+        ],
+        "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [3, 2 * 10^5].\n0 <= Node.val <= 1000\nThere are no two consecutive nodes with Node.val == 0.\nThe beginning and end of the linked list have Node.val == 0.",
+        "tags": [
+            "Linked List",
+            "Simulation"
+        ],
+        "title-slug": "merge-nodes-in-between-zeros"
+    },
+    {
+        "leetcode-id": 2182,
+        "title": "Construct String With Repeat Limit",
+        "difficulty": 2,
+        "description": "You are given a string s and an integer repeatLimit. Construct a new string repeatLimitedString using the characters of s such that no letter appears more than repeatLimit times in a row. You do not have to use all characters from s.\nReturn the lexicographically largest repeatLimitedString possible.\nA string a is lexicographically larger than a string b if in the first position where a and b differ, string a has a letter that appears later in the alphabet than the corresponding letter in b. If the first min(a.length, b.length) characters do not differ, then the longer string is the lexicographically larger one.",
+        "examples": [
+            "Example 1:\nInput: s = \"cczazcc\", repeatLimit = 3\nOutput: \"zzcccac\"\nExplanation: We use all of the characters from s to construct the repeatLimitedString \"zzcccac\".\nThe letter 'a' appears at most 1 time in a row.\nThe letter 'c' appears at most 3 times in a row.\nThe letter 'z' appears at most 2 times in a row.\nHence, no letter appears more than repeatLimit times in a row and the string is a valid repeatLimitedString.\nThe string is the lexicographically largest repeatLimitedString possible so we return \"zzcccac\".\nNote that the string \"zzcccca\" is lexicographically larger but the letter 'c' appears more than 3 times in a row, so it is not a valid repeatLimitedString.",
+            "Example 2:\nInput: s = \"aababab\", repeatLimit = 2\nOutput: \"bbabaa\"\nExplanation: We use only some of the characters from s to construct the repeatLimitedString \"bbabaa\". \nThe letter 'a' appears at most 2 times in a row.\nThe letter 'b' appears at most 2 times in a row.\nHence, no letter appears more than repeatLimit times in a row and the string is a valid repeatLimitedString.\nThe string is the lexicographically largest repeatLimitedString possible so we return \"bbabaa\".\nNote that the string \"bbabaaa\" is lexicographically larger but the letter 'a' appears more than 2 times in a row, so it is not a valid repeatLimitedString."
+        ],
+        "constraints": "Constraints:\n\n1 <= repeatLimit <= s.length <= 10^5\ns consists of lowercase English letters.",
+        "tags": [
+            "String",
+            "Greedy",
+            "Heap (Priority Queue)",
+            "Counting"
+        ],
+        "title-slug": "construct-string-with-repeat-limit"
+    },
+    {
+        "leetcode-id": 2183,
+        "title": "Count Array Pairs Divisible by K",
+        "difficulty": 3,
+        "description": "Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) such that:\n\n0 <= i < j <= n - 1 and\nnums[i] * nums[j] is divisible by k.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,3,4,5], k = 2\nOutput: 7\nExplanation: \nThe 7 pairs of indices whose corresponding products are divisible by 2 are\n(0, 1), (0, 3), (1, 2), (1, 3), (1, 4), (2, 3), and (3, 4).\nTheir products are 2, 4, 6, 8, 10, 12, and 20 respectively.\nOther pairs such as (0, 2) and (2, 4) have products 3 and 15 respectively, which are not divisible by 2.",
+            "Example 2:\nInput: nums = [1,2,3,4], k = 5\nOutput: 0\nExplanation: There does not exist any pair of indices whose corresponding product is divisible by 5."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i], k <= 10^5",
+        "tags": [
+            "Array",
+            "Math",
+            "Number Theory"
+        ],
+        "title-slug": "count-array-pairs-divisible-by-k"
+    },
+    {
+        "leetcode-id": 2185,
+        "title": "Counting Words With a Given Prefix",
+        "difficulty": 1,
+        "description": "You are given an array of strings words and a string pref.\nReturn the number of strings in words that contain pref as a prefix.\nA prefix of a string s is any leading contiguous substring of s.",
+        "examples": [
+            "Example 1:\nInput: words = [\"pay\",\"attention\",\"practice\",\"attend\"], pref = \"at\"\nOutput: 2\nExplanation: The 2 strings that contain \"at\" as a prefix are: \"attention\" and \"attend\".",
+            "Example 2:\nInput: words = [\"leetcode\",\"win\",\"loops\",\"success\"], pref = \"code\"\nOutput: 0\nExplanation: There are no strings that contain \"code\" as a prefix."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 100\n1 <= words[i].length, pref.length <= 100\nwords[i] and pref consist of lowercase English letters.",
+        "tags": [
+            "Array",
+            "String"
+        ],
+        "title-slug": "counting-words-with-a-given-prefix"
+    },
+    {
+        "leetcode-id": 2186,
+        "title": "Minimum Number of Steps to Make Two Strings Anagram II",
+        "difficulty": 2,
+        "description": "You are given two strings s and t. In one step, you can append any character to either s or t.\nReturn the minimum number of steps to make s and t anagrams of each other.\nAn anagram of a string is a string that contains the same characters with a different (or the same) ordering.",
+        "examples": [
+            "Example 1:\nInput: s = \"leetcode\", t = \"coats\"\nOutput: 7\nExplanation: \n- In 2 steps, we can append the letters in \"as\" onto s = \"leetcode\", forming s = \"leetcodeas\".\n- In 5 steps, we can append the letters in \"leede\" onto t = \"coats\", forming t = \"coatsleede\".\n\"leetcodeas\" and \"coatsleede\" are now anagrams of each other.\nWe used a total of 2 + 5 = 7 steps.\nIt can be shown that there is no way to make them anagrams of each other with less than 7 steps.",
+            "Example 2:\nInput: s = \"night\", t = \"thing\"\nOutput: 0\nExplanation: The given strings are already anagrams of each other. Thus, we do not need any further steps."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length, t.length <= 2 * 10^5\ns and t consist of lowercase English letters.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Counting"
+        ],
+        "title-slug": "minimum-number-of-steps-to-make-two-strings-anagram-ii"
+    },
+    {
+        "leetcode-id": 2187,
+        "title": "Minimum Time to Complete Trips",
+        "difficulty": 2,
+        "description": "You are given an array time where time[i] denotes the time taken by the i^th bus to complete one trip.\nEach bus can make multiple trips successively; that is, the next trip can start immediately after completing the current trip. Also, each bus operates independently; that is, the trips of one bus do not influence the trips of any other bus.\nYou are also given an integer totalTrips, which denotes the number of trips all buses should make in total. Return the minimum time required for all buses to complete at least totalTrips trips.",
+        "examples": [
+            "Example 1:\nInput: time = [1,2,3], totalTrips = 5\nOutput: 3\nExplanation:\n- At time t = 1, the number of trips completed by each bus are [1,0,0]. \n  The total number of trips completed is 1 + 0 + 0 = 1.\n- At time t = 2, the number of trips completed by each bus are [2,1,0]. \n  The total number of trips completed is 2 + 1 + 0 = 3.\n- At time t = 3, the number of trips completed by each bus are [3,1,1]. \n  The total number of trips completed is 3 + 1 + 1 = 5.\nSo the minimum time needed for all buses to complete at least 5 trips is 3.",
+            "Example 2:\nInput: time = [2], totalTrips = 1\nOutput: 2\nExplanation:\nThere is only one bus, and it will complete its first trip at t = 2.\nSo the minimum time needed to complete 1 trip is 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= time.length <= 10^5\n1 <= time[i], totalTrips <= 10^7",
+        "tags": [
+            "Array",
+            "Binary Search"
+        ],
+        "title-slug": "minimum-time-to-complete-trips"
+    },
+    {
+        "leetcode-id": 2188,
+        "title": "Minimum Time to Finish the Race",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed 2D integer array tires where tires[i] = [fi, ri] indicates that the i^th tire can finish its x^th successive lap in fi * ri^(x-1) seconds.\n\nFor example, if fi = 3 and ri = 2, then the tire would finish its 1^st lap in 3 seconds, its 2^nd lap in 3 * 2 = 6 seconds, its 3^rd lap in 3 * 2^2 = 12 seconds, etc.\n\nYou are also given an integer changeTime and an integer numLaps.\nThe race consists of numLaps laps and you may start the race with any tire. You have an unlimited supply of each tire and after every lap, you may change to any given tire (including the current tire type) if you wait changeTime seconds.\nReturn the minimum time to finish the race.",
+        "examples": [
+            "Example 1:\nInput: tires = [[2,3],[3,4]], changeTime = 5, numLaps = 4\nOutput: 21\nExplanation: \nLap 1: Start with tire 0 and finish the lap in 2 seconds.\nLap 2: Continue with tire 0 and finish the lap in 2 * 3 = 6 seconds.\nLap 3: Change tires to a new tire 0 for 5 seconds and then finish the lap in another 2 seconds.\nLap 4: Continue with tire 0 and finish the lap in 2 * 3 = 6 seconds.\nTotal time = 2 + 6 + 5 + 2 + 6 = 21 seconds.\nThe minimum time to complete the race is 21 seconds.",
+            "Example 2:\nInput: tires = [[1,10],[2,2],[3,4]], changeTime = 6, numLaps = 5\nOutput: 25\nExplanation: \nLap 1: Start with tire 1 and finish the lap in 2 seconds.\nLap 2: Continue with tire 1 and finish the lap in 2 * 2 = 4 seconds.\nLap 3: Change tires to a new tire 1 for 6 seconds and then finish the lap in another 2 seconds.\nLap 4: Continue with tire 1 and finish the lap in 2 * 2 = 4 seconds.\nLap 5: Change tires to tire 0 for 6 seconds then finish the lap in another 1 second.\nTotal time = 2 + 4 + 6 + 2 + 4 + 6 + 1 = 25 seconds.\nThe minimum time to complete the race is 25 seconds."
+        ],
+        "constraints": "Constraints:\n\n1 <= tires.length <= 10^5\ntires[i].length == 2\n1 <= fi, changeTime <= 10^5\n2 <= ri <= 10^5\n1 <= numLaps <= 1000",
+        "tags": [
+            "Array",
+            "Dynamic Programming"
+        ],
+        "title-slug": "minimum-time-to-finish-the-race"
+    },
+    {
+        "leetcode-id": 2190,
+        "title": "Most Frequent Number Following Key In an Array",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums. You are also given an integer key, which is present in nums.\nFor every unique integer target in nums, count the number of times target immediately follows an occurrence of key in nums. In other words, count the number of indices i such that:\n\n0 <= i <= nums.length - 2,\nnums[i] == key and,\nnums[i + 1] == target.\n\nReturn the target with the maximum count. The test cases will be generated such that the target with maximum count is unique.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,100,200,1,100], key = 1\nOutput: 100\nExplanation: For target = 100, there are 2 occurrences at indices 1 and 4 which follow an occurrence of key.\nNo other integers follow an occurrence of key, so we return 100.",
+            "Example 2:\nInput: nums = [2,2,2,2,3], key = 2\nOutput: 2\nExplanation: For target = 2, there are 3 occurrences at indices 1, 2, and 3 which follow an occurrence of key.\nFor target = 3, there is only one occurrence at index 4 which follows an occurrence of key.\ntarget = 2 has the maximum number of occurrences following an occurrence of key, so we return 2."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 1000\n1 <= nums[i] <= 1000\nThe test cases will be generated such that the answer is unique.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Counting"
+        ],
+        "title-slug": "most-frequent-number-following-key-in-an-array"
+    },
+    {
+        "leetcode-id": 2191,
+        "title": "Sort the Jumbled Numbers",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array mapping which represents the mapping rule of a shuffled decimal system. mapping[i] = j means digit i should be mapped to digit j in this system.\nThe mapped value of an integer is the new integer obtained by replacing each occurrence of digit i in the integer with mapping[i] for all 0 <= i <= 9.\nYou are also given another integer array nums. Return the array nums sorted in non-decreasing order based on the mapped values of its elements.\nNotes:\n\nElements with the same mapped values should appear in the same relative order as in the input.\nThe elements of nums should only be sorted based on their mapped values and not be replaced by them.",
+        "examples": [
+            "Example 1:\nInput: mapping = [8,9,4,0,2,1,3,5,7,6], nums = [991,338,38]\nOutput: [338,38,991]\nExplanation: \nMap the number 991 as follows:\n1. mapping[9] = 6, so all occurrences of the digit 9 will become 6.\n2. mapping[1] = 9, so all occurrences of the digit 1 will become 9.\nTherefore, the mapped value of 991 is 669.\n338 maps to 007, or 7 after removing the leading zeros.\n38 maps to 07, which is also 7 after removing leading zeros.\nSince 338 and 38 share the same mapped value, they should remain in the same relative order, so 338 comes before 38.\nThus, the sorted array is [338,38,991].",
+            "Example 2:\nInput: mapping = [0,1,2,3,4,5,6,7,8,9], nums = [789,456,123]\nOutput: [123,456,789]\nExplanation: 789 maps to 789, 456 maps to 456, and 123 maps to 123. Thus, the sorted array is [123,456,789]."
+        ],
+        "constraints": "Constraints:\n\nmapping.length == 10\n0 <= mapping[i] <= 9\nAll the values of mapping[i] are unique.\n1 <= nums.length <= 3 * 10^4\n0 <= nums[i] < 10^9",
+        "tags": [
+            "Array",
+            "Sorting"
+        ],
+        "title-slug": "sort-the-jumbled-numbers"
+    },
+    {
+        "leetcode-id": 2192,
+        "title": "All Ancestors of a Node in a Directed Acyclic Graph",
+        "difficulty": 2,
+        "description": "You are given a positive integer n representing the number of nodes of a Directed Acyclic Graph (DAG). The nodes are numbered from 0 to n - 1 (inclusive).\nYou are also given a 2D integer array edges, where edges[i] = [fromi, toi] denotes that there is a unidirectional edge from fromi to toi in the graph.\nReturn a list answer, where answer[i] is the list of ancestors of the i^th node, sorted in ascending order.\nA node u is an ancestor of another node v if u can reach v via a set of edges.",
+        "examples": [
+            "Example 1:\nInput: n = 8, edgeList = [[0,3],[0,4],[1,3],[2,4],[2,7],[3,5],[3,6],[3,7],[4,6]]\nOutput: [[],[],[],[0,1],[0,2],[0,1,3],[0,1,2,3,4],[0,1,2,3]]\nExplanation:\nThe above diagram represents the input graph.\n- Nodes 0, 1, and 2 do not have any ancestors.\n- Node 3 has two ancestors 0 and 1.\n- Node 4 has two ancestors 0 and 2.\n- Node 5 has three ancestors 0, 1, and 3.\n- Node 6 has five ancestors 0, 1, 2, 3, and 4.\n- Node 7 has four ancestors 0, 1, 2, and 3.",
+            "Example 2:\nInput: n = 5, edgeList = [[0,1],[0,2],[0,3],[0,4],[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]\nOutput: [[],[0],[0,1],[0,1,2],[0,1,2,3]]\nExplanation:\nThe above diagram represents the input graph.\n- Node 0 does not have any ancestor.\n- Node 1 has one ancestor 0.\n- Node 2 has two ancestors 0 and 1.\n- Node 3 has three ancestors 0, 1, and 2.\n- Node 4 has four ancestors 0, 1, 2, and 3."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 1000\n0 <= edges.length <= min(2000, n * (n - 1) / 2)\nedges[i].length == 2\n0 <= fromi, toi <= n - 1\nfromi != toi\nThere are no duplicate edges.\nThe graph is directed and acyclic.",
+        "tags": [
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Graph",
+            "Topological Sort"
+        ],
+        "title-slug": "all-ancestors-of-a-node-in-a-directed-acyclic-graph"
+    },
+    {
+        "leetcode-id": 2193,
+        "title": "Minimum Number of Moves to Make Palindrome",
+        "difficulty": 3,
+        "description": "You are given a string s consisting only of lowercase English letters.\nIn one move, you can select any two adjacent characters of s and swap them.\nReturn the minimum number of moves needed to make s a palindrome.\nNote that the input will be generated such that s can always be converted to a palindrome.",
+        "examples": [
+            "Example 1:\nInput: s = \"aabb\"\nOutput: 2\nExplanation:\nWe can obtain two palindromes from s, \"abba\" and \"baab\". \n- We can obtain \"abba\" from s in 2 moves: \"aabb\" -> \"abab\" -> \"abba\".\n- We can obtain \"baab\" from s in 2 moves: \"aabb\" -> \"abab\" -> \"baab\".\nThus, the minimum number of moves needed to make s a palindrome is 2.",
+            "Example 2:\nInput: s = \"letelt\"\nOutput: 2\nExplanation:\nOne of the palindromes we can obtain from s in 2 moves is \"lettel\".\nOne of the ways we can obtain it is \"letelt\" -> \"letetl\" -> \"lettel\".\nOther palindromes such as \"tleelt\" can also be obtained in 2 moves.\nIt can be shown that it is not possible to obtain a palindrome in less than 2 moves."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 2000\ns consists only of lowercase English letters.\ns can be converted to a palindrome using a finite number of moves.",
+        "tags": [
+            "Two Pointers",
+            "String",
+            "Greedy",
+            "Binary Indexed Tree"
+        ],
+        "title-slug": "minimum-number-of-moves-to-make-palindrome"
+    },
+    {
+        "leetcode-id": 2194,
+        "title": "Cells in a Range on an Excel Sheet",
+        "difficulty": 1,
+        "description": "A cell (r, c) of an excel sheet is represented as a string \"\" where:\n\n denotes the column number c of the cell. It is represented by alphabetical letters.\n\n\t\nFor example, the 1^st column is denoted by 'A', the 2^nd by 'B', the 3^rd by 'C', and so on.\n\n\n is the row number r of the cell. The r^th row is represented by the integer r.\n\nYou are given a string s\u00a0in\u00a0the format \":\", where  represents the column c1,  represents the row r1,  represents the column c2, and  represents the row r2, such that r1 <= r2 and c1 <= c2.\nReturn the list of cells (x, y) such that r1 <= x <= r2 and c1 <= y <= c2. The cells should be represented as\u00a0strings in the format mentioned above and be sorted in non-decreasing order first by columns and then by rows.",
+        "examples": [
+            "Example 1:\nInput: s = \"K1:L2\"\nOutput: [\"K1\",\"K2\",\"L1\",\"L2\"]\nExplanation:\nThe above diagram shows the cells which should be present in the list.\nThe red arrows denote the order in which the cells should be presented.",
+            "Example 2:\nInput: s = \"A1:F1\"\nOutput: [\"A1\",\"B1\",\"C1\",\"D1\",\"E1\",\"F1\"]\nExplanation:\nThe above diagram shows the cells which should be present in the list.\nThe red arrow denotes the order in which the cells should be presented."
+        ],
+        "constraints": "Constraints:\n\ns.length == 5\n'A' <= s[0] <= s[3] <= 'Z'\n'1' <= s[1] <= s[4] <= '9'\ns consists of uppercase English letters, digits and ':'.",
+        "tags": [
+            "String"
+        ],
+        "title-slug": "cells-in-a-range-on-an-excel-sheet"
+    },
+    {
+        "leetcode-id": 2195,
+        "title": "Append K Integers With Minimal Sum",
+        "difficulty": 2,
+        "description": "You are given an integer array nums and an integer k. Append k unique positive integers that do not appear in nums to nums such that the resulting total sum is minimum.\nReturn the sum of the k integers appended to nums.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,4,25,10,25], k = 2\nOutput: 5\nExplanation: The two unique positive integers that do not appear in nums which we append are 2 and 3.\nThe resulting sum of nums is 1 + 4 + 25 + 10 + 25 + 2 + 3 = 70, which is the minimum.\nThe sum of the two integers appended is 2 + 3 = 5, so we return 5.",
+            "Example 2:\nInput: nums = [5,6], k = 6\nOutput: 25\nExplanation: The six unique positive integers that do not appear in nums which we append are 1, 2, 3, 4, 7, and 8.\nThe resulting sum of nums is 5 + 6 + 1 + 2 + 3 + 4 + 7 + 8 = 36, which is the minimum. \nThe sum of the six integers appended is 1 + 2 + 3 + 4 + 7 + 8 = 25, so we return 25."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\n1 <= k <= 10^8",
+        "tags": [
+            "Array",
+            "Math",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "append-k-integers-with-minimal-sum"
+    },
+    {
+        "leetcode-id": 2196,
+        "title": "Create Binary Tree From Descriptions",
+        "difficulty": 2,
+        "description": "You are given a 2D integer array descriptions where descriptions[i] = [parenti, childi, isLefti] indicates that parenti is the parent of childi in a binary tree of unique values. Furthermore,\n\nIf isLefti == 1, then childi is the left child of parenti.\nIf isLefti == 0, then childi is the right child of parenti.\n\nConstruct the binary tree described by descriptions and return its root.\nThe test cases will be generated such that the binary tree is valid.",
+        "examples": [
+            "Example 1:\nInput: descriptions = [[20,15,1],[20,17,0],[50,20,1],[50,80,0],[80,19,1]]\nOutput: [50,20,80,15,17,19]\nExplanation: The root node is the node with value 50 since it has no parent.\nThe resulting binary tree is shown in the diagram.",
+            "Example 2:\nInput: descriptions = [[1,2,1],[2,3,0],[3,4,1]]\nOutput: [1,2,null,null,3,4]\nExplanation: The root node is the node with value 1 since it has no parent.\nThe resulting binary tree is shown in the diagram."
+        ],
+        "constraints": "Constraints:\n\n1 <= descriptions.length <= 10^4\ndescriptions[i].length == 3\n1 <= parenti, childi <= 10^5\n0 <= isLefti <= 1\nThe binary tree described by descriptions is valid.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Tree",
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Binary Tree"
+        ],
+        "title-slug": "create-binary-tree-from-descriptions"
+    },
+    {
+        "leetcode-id": 2197,
+        "title": "Replace Non-Coprime Numbers in Array",
+        "difficulty": 3,
+        "description": "You are given an array of integers nums. Perform the following steps:\n\nFind any two adjacent numbers in nums that are non-coprime.\nIf no such numbers are found, stop the process.\nOtherwise, delete the two numbers and replace them with their LCM (Least Common Multiple).\nRepeat this process as long as you keep finding two adjacent non-coprime numbers.\n\nReturn the final modified array. It can be shown that replacing adjacent non-coprime numbers in any arbitrary order will lead to the same result.\nThe test cases are generated such that the values in the final array are less than or equal to 10^8.\nTwo values x and y are non-coprime if GCD(x, y) > 1 where GCD(x, y) is the Greatest Common Divisor of x and y.",
+        "examples": [
+            "Example 1:\nInput: nums = [6,4,3,2,7,6,2]\nOutput: [12,7,6]\nExplanation: \n- (6, 4) are non-coprime with LCM(6, 4) = 12. Now, nums = [12,3,2,7,6,2].\n- (12, 3) are non-coprime with LCM(12, 3) = 12. Now, nums = [12,2,7,6,2].\n- (12, 2) are non-coprime with LCM(12, 2) = 12. Now, nums = [12,7,6,2].\n- (6, 2) are non-coprime with LCM(6, 2) = 6. Now, nums = [12,7,6].\nThere are no more adjacent non-coprime numbers in nums.\nThus, the final modified array is [12,7,6].\nNote that there are other ways to obtain the same resultant array.",
+            "Example 2:\nInput: nums = [2,2,1,1,3,3,3]\nOutput: [2,1,1,3]\nExplanation: \n- (3, 3) are non-coprime with LCM(3, 3) = 3. Now, nums = [2,2,1,1,3,3].\n- (3, 3) are non-coprime with LCM(3, 3) = 3. Now, nums = [2,2,1,1,3].\n- (2, 2) are non-coprime with LCM(2, 2) = 2. Now, nums = [2,1,1,3].\nThere are no more adjacent non-coprime numbers in nums.\nThus, the final modified array is [2,1,1,3].\nNote that there are other ways to obtain the same resultant array."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^5\nThe test cases are generated such that the values in the final array are less than or equal to 10^8.",
+        "tags": [
+            "Array",
+            "Math",
+            "Stack",
+            "Number Theory"
+        ],
+        "title-slug": "replace-non-coprime-numbers-in-array"
+    },
+    {
+        "leetcode-id": 2200,
+        "title": "Find All K-Distant Indices in an Array",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums and two integers key and k. A k-distant index is an index i of nums for which there exists at least one index j such that |i - j| <= k and nums[j] == key.\nReturn a list of all k-distant indices sorted in increasing order.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,4,9,1,3,9,5], key = 9, k = 1\nOutput: [1,2,3,4,5,6]\nExplanation: Here, nums[2] == key and nums[5] == key.\n- For index 0, |0 - 2| > k and |0 - 5| > k, so there is no j where |0 - j| <= k and nums[j] == key. Thus, 0 is not a k-distant index.\n- For index 1, |1 - 2| <= k and nums[2] == key, so 1 is a k-distant index.\n- For index 2, |2 - 2| <= k and nums[2] == key, so 2 is a k-distant index.\n- For index 3, |3 - 2| <= k and nums[2] == key, so 3 is a k-distant index.\n- For index 4, |4 - 5| <= k and nums[5] == key, so 4 is a k-distant index.\n- For index 5, |5 - 5| <= k and nums[5] == key, so 5 is a k-distant index.\n- For index 6, |6 - 5| <= k and nums[5] == key, so 6 is a k-distant index.\nThus, we return [1,2,3,4,5,6] which is sorted in increasing order.",
+            "Example 2:\nInput: nums = [2,2,2,2,2], key = 2, k = 2\nOutput: [0,1,2,3,4]\nExplanation: For all indices i in nums, there exists some index j such that |i - j| <= k and nums[j] == key, so every index is a k-distant index. \nHence, we return [0,1,2,3,4]."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 1000\nkey is an integer from the array nums.\n1 <= k <= nums.length",
+        "tags": [
+            "Array"
+        ],
+        "title-slug": "find-all-k-distant-indices-in-an-array"
+    },
+    {
+        "leetcode-id": 2201,
+        "title": "Count Artifacts That Can Be Extracted",
+        "difficulty": 2,
+        "description": "There is an n x n 0-indexed grid with some artifacts buried in it. You are given the integer n and a 0-indexed 2D integer array artifacts describing the positions of the rectangular artifacts where artifacts[i] = [r1i, c1i, r2i, c2i] denotes that the i^th artifact is buried in the subgrid where:\n\n(r1i, c1i) is the coordinate of the top-left cell of the i^th artifact and\n(r2i, c2i) is the coordinate of the bottom-right cell of the i^th artifact.\n\nYou will excavate some cells of the grid and remove all the mud from them. If the cell has a part of an artifact buried underneath, it will be uncovered. If all the parts of an artifact are uncovered, you can extract it.\nGiven a 0-indexed 2D integer array dig where dig[i] = [ri, ci] indicates that you will excavate the cell (ri, ci), return the number of artifacts that you can extract.\nThe test cases are generated such that:\n\nNo two artifacts overlap.\nEach artifact only covers at most 4 cells.\nThe entries of dig are unique.",
+        "examples": [
+            "Example 1:\nInput: n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1]]\nOutput: 1\nExplanation: \nThe different colors represent different artifacts. Excavated cells are labeled with a 'D' in the grid.\nThere is 1 artifact that can be extracted, namely the red artifact.\nThe blue artifact has one part in cell (1,1) which remains uncovered, so we cannot extract it.\nThus, we return 1.",
+            "Example 2:\nInput: n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1],[1,1]]\nOutput: 2\nExplanation: Both the red and blue artifacts have all parts uncovered (labeled with a 'D') and can be extracted, so we return 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 1000\n1 <= artifacts.length, dig.length <= min(n^2, 10^5)\nartifacts[i].length == 4\ndig[i].length == 2\n0 <= r1i, c1i, r2i, c2i, ri, ci <= n - 1\nr1i <= r2i\nc1i <= c2i\nNo two artifacts will overlap.\nThe number of cells covered by an artifact is at most 4.\nThe entries of dig are unique.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Simulation"
+        ],
+        "title-slug": "count-artifacts-that-can-be-extracted"
+    },
+    {
+        "leetcode-id": 2202,
+        "title": "Maximize the Topmost Element After K Moves",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums representing the contents of a pile, where nums[0] is the topmost element of the pile.\nIn one move, you can perform either of the following:\n\nIf the pile is not empty, remove the topmost element of the pile.\nIf there are one or more removed elements, add any one of them back onto the pile. This element becomes the new topmost element.\n\nYou are also given an integer k, which denotes the total number of moves to be made.\nReturn the maximum value of the topmost element of the pile possible after exactly k moves. In case it is not possible to obtain a non-empty pile after k moves, return -1.",
+        "examples": [
+            "Example 1:\nInput: nums = [5,2,2,4,0,6], k = 4\nOutput: 5\nExplanation:\nOne of the ways we can end with 5 at the top of the pile after 4 moves is as follows:\n- Step 1: Remove the topmost element = 5. The pile becomes [2,2,4,0,6].\n- Step 2: Remove the topmost element = 2. The pile becomes [2,4,0,6].\n- Step 3: Remove the topmost element = 2. The pile becomes [4,0,6].\n- Step 4: Add 5 back onto the pile. The pile becomes [5,4,0,6].\nNote that this is not the only way to end with 5 at the top of the pile. It can be shown that 5 is the largest answer possible after 4 moves.",
+            "Example 2:\nInput: nums = [2], k = 1\nOutput: -1\nExplanation: \nIn the first move, our only option is to pop the topmost element of the pile.\nSince it is not possible to obtain a non-empty pile after one move, we return -1."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i], k <= 10^9",
+        "tags": [
+            "Array",
+            "Greedy"
+        ],
+        "title-slug": "maximize-the-topmost-element-after-k-moves"
+    },
+    {
+        "leetcode-id": 2203,
+        "title": "Minimum Weighted Subgraph With the Required Paths",
+        "difficulty": 3,
+        "description": "You are given an integer n denoting the number of nodes of a weighted directed graph. The nodes are numbered from 0 to n - 1.\nYou are also given a 2D integer array edges where edges[i] = [fromi, toi, weighti] denotes that there exists a directed edge from fromi to toi with weight weighti.\nLastly, you are given three distinct integers src1, src2, and dest denoting three distinct nodes of the graph.\nReturn the minimum weight of a subgraph of the graph such that it is possible to reach dest from both src1 and src2 via a set of edges of this subgraph. In case such a subgraph does not exist, return -1.\nA subgraph is a graph whose vertices and edges are subsets of the original graph. The weight of a subgraph is the sum of weights of its constituent edges.",
+        "examples": [
+            "Example 1:\nInput: n = 6, edges = [[0,2,2],[0,5,6],[1,0,3],[1,4,5],[2,1,1],[2,3,3],[2,3,4],[3,4,2],[4,5,1]], src1 = 0, src2 = 1, dest = 5\nOutput: 9\nExplanation:\nThe above figure represents the input graph.\nThe blue edges represent one of the subgraphs that yield the optimal answer.\nNote that the subgraph [[1,0,3],[0,5,6]] also yields the optimal answer. It is not possible to get a subgraph with less weight satisfying all the constraints.",
+            "Example 2:\nInput: n = 3, edges = [[0,1,1],[2,1,1]], src1 = 0, src2 = 1, dest = 2\nOutput: -1\nExplanation:\nThe above figure represents the input graph.\nIt can be seen that there does not exist any path from node 1 to node 2, hence there are no subgraphs satisfying all the constraints."
+        ],
+        "constraints": "Constraints:\n\n3 <= n <= 10^5\n0 <= edges.length <= 10^5\nedges[i].length == 3\n0 <= fromi, toi, src1, src2, dest <= n - 1\nfromi != toi\nsrc1, src2, and dest are pairwise distinct.\n1 <= weight[i] <= 10^5",
+        "tags": [
+            "Graph",
+            "Shortest Path"
+        ],
+        "title-slug": "minimum-weighted-subgraph-with-the-required-paths"
+    },
+    {
+        "leetcode-id": 2206,
+        "title": "Divide Array Into Equal Pairs",
+        "difficulty": 1,
+        "description": "You are given an integer array nums consisting of 2 * n integers.\nYou need to divide nums into n pairs such that:\n\nEach element belongs to exactly one pair.\nThe elements present in a pair are equal.\n\nReturn true if nums can be divided into n pairs, otherwise return false.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,2,3,2,2,2]\nOutput: true\nExplanation: \nThere are 6 elements in nums, so they should be divided into 6 / 2 = 3 pairs.\nIf nums is divided into the pairs (2, 2), (3, 3), and (2, 2), it will satisfy all the conditions.",
+            "Example 2:\nInput: nums = [1,2,3,4]\nOutput: false\nExplanation: \nThere is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy every condition."
+        ],
+        "constraints": "Constraints:\n\nnums.length == 2 * n\n1 <= n <= 500\n1 <= nums[i] <= 500",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Bit Manipulation",
+            "Counting"
+        ],
+        "title-slug": "divide-array-into-equal-pairs"
+    },
+    {
+        "leetcode-id": 2207,
+        "title": "Maximize Number of Subsequences in a String",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed string text and another 0-indexed string pattern of length 2, both of which consist of only lowercase English letters.\nYou can add either pattern[0] or pattern[1] anywhere in text exactly once. Note that the character can be added even at the beginning or at the end of text.\nReturn the maximum number of times pattern can occur as a subsequence of the modified text.\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.",
+        "examples": [
+            "Example 1:\nInput: text = \"abdcdbc\", pattern = \"ac\"\nOutput: 4\nExplanation:\nIf we add pattern[0] = 'a' in between text[1] and text[2], we get \"abadcdbc\". Now, the number of times \"ac\" occurs as a subsequence is 4.\nSome other strings which have 4 subsequences \"ac\" after adding a character to text are \"aabdcdbc\" and \"abdacdbc\".\nHowever, strings such as \"abdcadbc\", \"abdccdbc\", and \"abdcdbcc\", although obtainable, have only 3 subsequences \"ac\" and are thus suboptimal.\nIt can be shown that it is not possible to get more than 4 subsequences \"ac\" by adding only one character.",
+            "Example 2:\nInput: text = \"aabb\", pattern = \"ab\"\nOutput: 6\nExplanation:\nSome of the strings which can be obtained from text and have 6 subsequences \"ab\" are \"aaabb\", \"aaabb\", and \"aabbb\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= text.length <= 10^5\npattern.length == 2\ntext and pattern consist only of lowercase English letters.",
+        "tags": [
+            "String",
+            "Greedy",
+            "Prefix Sum"
+        ],
+        "title-slug": "maximize-number-of-subsequences-in-a-string"
+    },
+    {
+        "leetcode-id": 2208,
+        "title": "Minimum Operations to Halve Array Sum",
+        "difficulty": 2,
+        "description": "You are given an array nums of positive integers. In one operation, you can choose any number from nums and reduce it to exactly half the number. (Note that you may choose this reduced number in future operations.)\nReturn the minimum number of operations to reduce the sum of nums by at least half.",
+        "examples": [
+            "Example 1:\nInput: nums = [5,19,8,1]\nOutput: 3\nExplanation: The initial sum of nums is equal to 5 + 19 + 8 + 1 = 33.\nThe following is one of the ways to reduce the sum by at least half:\nPick the number 19 and reduce it to 9.5.\nPick the number 9.5 and reduce it to 4.75.\nPick the number 8 and reduce it to 4.\nThe final array is [5, 4.75, 4, 1] with a total sum of 5 + 4.75 + 4 + 1 = 14.75. \nThe sum of nums has been reduced by 33 - 14.75 = 18.25, which is at least half of the initial sum, 18.25 >= 33/2 = 16.5.\nOverall, 3 operations were used so we return 3.\nIt can be shown that we cannot reduce the sum by at least half in less than 3 operations.",
+            "Example 2:\nInput: nums = [3,8,20]\nOutput: 3\nExplanation: The initial sum of nums is equal to 3 + 8 + 20 = 31.\nThe following is one of the ways to reduce the sum by at least half:\nPick the number 20 and reduce it to 10.\nPick the number 10 and reduce it to 5.\nPick the number 3 and reduce it to 1.5.\nThe final array is [1.5, 8, 5] with a total sum of 1.5 + 8 + 5 = 14.5. \nThe sum of nums has been reduced by 31 - 14.5 = 16.5, which is at least half of the initial sum, 16.5 >= 31/2 = 15.5.\nOverall, 3 operations were used so we return 3.\nIt can be shown that we cannot reduce the sum by at least half in less than 3 operations."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^7",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "minimum-operations-to-halve-array-sum"
+    },
+    {
+        "leetcode-id": 2209,
+        "title": "Minimum White Tiles After Covering With Carpets",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed binary string floor, which represents the colors of tiles on a floor:\n\nfloor[i] = '0' denotes that the i^th tile of the floor is colored black.\nOn the other hand, floor[i] = '1' denotes that the i^th tile of the floor is colored white.\n\nYou are also given numCarpets and carpetLen. You have numCarpets black carpets, each of length carpetLen tiles. Cover the tiles with the given carpets such that the number of white tiles still visible is minimum. Carpets may overlap one another.\nReturn the minimum number of white tiles still visible.",
+        "examples": [
+            "Example 1:\nInput: floor = \"10110101\", numCarpets = 2, carpetLen = 2\nOutput: 2\nExplanation: \nThe figure above shows one way of covering the tiles with the carpets such that only 2 white tiles are visible.\nNo other way of covering the tiles with the carpets can leave less than 2 white tiles visible.",
+            "Example 2:\nInput: floor = \"11111\", numCarpets = 2, carpetLen = 3\nOutput: 0\nExplanation: \nThe figure above shows one way of covering the tiles with the carpets such that no white tiles are visible.\nNote that the carpets are able to overlap one another."
+        ],
+        "constraints": "Constraints:\n\n1 <= carpetLen <= floor.length <= 1000\nfloor[i] is either '0' or '1'.\n1 <= numCarpets <= 1000",
+        "tags": [
+            "String",
+            "Dynamic Programming",
+            "Prefix Sum"
+        ],
+        "title-slug": "minimum-white-tiles-after-covering-with-carpets"
+    },
+    {
+        "leetcode-id": 2210,
+        "title": "Count Hills and Valleys in an Array",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums. An index i is part of a hill in nums if the closest non-equal neighbors of i are smaller than nums[i]. Similarly, an index i is part of a valley in nums if the closest non-equal neighbors of i are larger than nums[i]. Adjacent indices i and j are part of the same hill or valley if nums[i] == nums[j].\nNote that for an index to be part of a hill or valley, it must have a non-equal neighbor on both the left and right of the index.\nReturn the number of hills and valleys in nums.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,4,1,1,6,5]\nOutput: 3\nExplanation:\nAt index 0: There is no non-equal neighbor of 2 on the left, so index 0 is neither a hill nor a valley.\nAt index 1: The closest non-equal neighbors of 4 are 2 and 1. Since 4 > 2 and 4 > 1, index 1 is a hill. \nAt index 2: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 2 is a valley.\nAt index 3: The closest non-equal neighbors of 1 are 4 and 6. Since 1 < 4 and 1 < 6, index 3 is a valley, but note that it is part of the same valley as index 2.\nAt index 4: The closest non-equal neighbors of 6 are 1 and 5. Since 6 > 1 and 6 > 5, index 4 is a hill.\nAt index 5: There is no non-equal neighbor of 5 on the right, so index 5 is neither a hill nor a valley. \nThere are 3 hills and valleys so we return 3.",
+            "Example 2:\nInput: nums = [6,6,5,5,4,1]\nOutput: 0\nExplanation:\nAt index 0: There is no non-equal neighbor of 6 on the left, so index 0 is neither a hill nor a valley.\nAt index 1: There is no non-equal neighbor of 6 on the left, so index 1 is neither a hill nor a valley.\nAt index 2: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 2 is neither a hill nor a valley.\nAt index 3: The closest non-equal neighbors of 5 are 6 and 4. Since 5 < 6 and 5 > 4, index 3 is neither a hill nor a valley.\nAt index 4: The closest non-equal neighbors of 4 are 5 and 1. Since 4 < 5 and 4 > 1, index 4 is neither a hill nor a valley.\nAt index 5: There is no non-equal neighbor of 1 on the right, so index 5 is neither a hill nor a valley.\nThere are 0 hills and valleys so we return 0."
+        ],
+        "constraints": "Constraints:\n\n3 <= nums.length <= 100\n1 <= nums[i] <= 100",
+        "tags": [
+            "Array"
+        ],
+        "title-slug": "count-hills-and-valleys-in-an-array"
+    },
+    {
+        "leetcode-id": 2211,
+        "title": "Count Collisions on a Road",
+        "difficulty": 2,
+        "description": "There are n cars on an infinitely long road. The cars are numbered from 0 to n - 1 from left to right and each car is present at a unique point.\nYou are given a 0-indexed string directions of length n. directions[i] can be either 'L', 'R', or 'S' denoting whether the i^th car is moving towards the left, towards the right, or staying at its current point respectively. Each moving car has the same speed.\nThe number of collisions can be calculated as follows:\n\nWhen two cars moving in opposite directions collide with each other, the number of collisions increases by 2.\nWhen a moving car collides with a stationary car, the number of collisions increases by 1.\n\nAfter a collision, the cars involved can no longer move and will stay at the point where they collided. Other than that, cars cannot change their state or direction of motion.\nReturn the total number of collisions that will happen on the road.",
+        "examples": [
+            "Example 1:\nInput: directions = \"RLRSLL\"\nOutput: 5\nExplanation:\nThe collisions that will happen on the road are:\n- Cars 0 and 1 will collide with each other. Since they are moving in opposite directions, the number of collisions becomes 0 + 2 = 2.\n- Cars 2 and 3 will collide with each other. Since car 3 is stationary, the number of collisions becomes 2 + 1 = 3.\n- Cars 3 and 4 will collide with each other. Since car 3 is stationary, the number of collisions becomes 3 + 1 = 4.\n- Cars 4 and 5 will collide with each other. After car 4 collides with car 3, it will stay at the point of collision and get hit by car 5. The number of collisions becomes 4 + 1 = 5.\nThus, the total number of collisions that will happen on the road is 5.",
+            "Example 2:\nInput: directions = \"LLRR\"\nOutput: 0\nExplanation:\nNo cars will collide with each other. Thus, the total number of collisions that will happen on the road is 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= directions.length <= 10^5\ndirections[i] is either 'L', 'R', or 'S'.",
+        "tags": [
+            "String",
+            "Stack"
+        ],
+        "title-slug": "count-collisions-on-a-road"
+    },
+    {
+        "leetcode-id": 2212,
+        "title": "Maximum Points in an Archery Competition",
+        "difficulty": 2,
+        "description": "Alice and Bob are opponents in an archery competition. The competition has set the following rules:\n\nAlice first shoots numArrows arrows and then Bob shoots numArrows arrows.\nThe points are then calculated as follows:\n\t\nThe target has integer scoring sections ranging from 0 to 11 inclusive.\nFor each section of the target with score k (in between 0 to 11), say Alice and Bob have shot ak and bk arrows on that section respectively. If ak >= bk, then Alice takes k points. If ak < bk, then Bob takes k points.\nHowever, if ak == bk == 0, then nobody takes k points.\n\n\n\n\n\nFor example, if Alice and Bob both shot 2 arrows on the section with score 11, then Alice takes 11 points. On the other hand, if Alice shot 0 arrows on the section with score 11 and Bob shot 2 arrows on that same section, then Bob takes 11 points.\n\n\nYou are given the integer numArrows and an integer array aliceArrows of size 12, which represents the number of arrows Alice shot on each scoring section from 0 to 11. Now, Bob wants to maximize the total number of points he can obtain.\nReturn the array bobArrows which represents the number of arrows Bob shot on each scoring section from 0 to 11. The sum of the values in bobArrows should equal numArrows.\nIf there are multiple ways for Bob to earn the maximum total points, return any one of them.",
+        "examples": [
+            "Example 1:\nInput: numArrows = 9, aliceArrows = [1,1,0,1,0,0,2,1,0,1,2,0]\nOutput: [0,0,0,0,1,1,0,0,1,2,3,1]\nExplanation: The table above shows how the competition is scored. \nBob earns a total point of 4 + 5 + 8 + 9 + 10 + 11 = 47.\nIt can be shown that Bob cannot obtain a score higher than 47 points.",
+            "Example 2:\nInput: numArrows = 3, aliceArrows = [0,0,1,0,0,0,0,0,0,0,0,2]\nOutput: [0,0,0,0,0,0,0,0,1,1,1,0]\nExplanation: The table above shows how the competition is scored.\nBob earns a total point of 8 + 9 + 10 = 27.\nIt can be shown that Bob cannot obtain a score higher than 27 points."
+        ],
+        "constraints": "Constraints:\n\n1 <= numArrows <= 10^5\naliceArrows.length == bobArrows.length == 12\n0 <= aliceArrows[i], bobArrows[i] <= numArrows\nsum(aliceArrows[i]) == numArrows",
+        "tags": [
+            "Array",
+            "Backtracking",
+            "Bit Manipulation",
+            "Enumeration"
+        ],
+        "title-slug": "maximum-points-in-an-archery-competition"
+    },
+    {
+        "leetcode-id": 2213,
+        "title": "Longest Substring of One Repeating Character",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed string s. You are also given a 0-indexed string queryCharacters of length k and a 0-indexed array of integer indices queryIndices of length k, both of which are used to describe k queries.\nThe i^th query updates the character in s at index queryIndices[i] to the character queryCharacters[i].\nReturn an array lengths of length k where lengths[i] is the length of the longest substring of s consisting of only one repeating character after the i^th query is performed.",
+        "examples": [
+            "Example 1:\nInput: s = \"babacc\", queryCharacters = \"bcb\", queryIndices = [1,3,3]\nOutput: [3,3,4]\nExplanation: \n- 1^st query updates s = \"bbbacc\". The longest substring consisting of one repeating character is \"bbb\" with length 3.\n- 2^nd query updates s = \"bbbccc\". \n  The longest substring consisting of one repeating character can be \"bbb\" or \"ccc\" with length 3.\n- 3^rd query updates s = \"bbbbcc\". The longest substring consisting of one repeating character is \"bbbb\" with length 4.\nThus, we return [3,3,4].",
+            "Example 2:\nInput: s = \"abyzz\", queryCharacters = \"aa\", queryIndices = [2,1]\nOutput: [2,3]\nExplanation:\n- 1^st query updates s = \"abazz\". The longest substring consisting of one repeating character is \"zz\" with length 2.\n- 2^nd query updates s = \"aaazz\". The longest substring consisting of one repeating character is \"aaa\" with length 3.\nThus, we return [2,3]."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of lowercase English letters.\nk == queryCharacters.length == queryIndices.length\n1 <= k <= 10^5\nqueryCharacters consists of lowercase English letters.\n0 <= queryIndices[i] < s.length",
+        "tags": [
+            "Array",
+            "String",
+            "Segment Tree",
+            "Ordered Set"
+        ],
+        "title-slug": "longest-substring-of-one-repeating-character"
+    },
+    {
+        "leetcode-id": 2215,
+        "title": "Find the Difference of Two Arrays",
+        "difficulty": 1,
+        "description": "Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where:\n\nanswer[0] is a list of all distinct integers in nums1 which are not present in nums2.\nanswer[1] is a list of all distinct integers in nums2 which are not present in nums1.\n\nNote that the integers in the lists may be returned in any order.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [1,2,3], nums2 = [2,4,6]\nOutput: [[1,3],[4,6]]\nExplanation:\nFor nums1, nums1[1] = 2 is present at index 0 of nums2, whereas nums1[0] = 1 and nums1[2] = 3 are not present in nums2. Therefore, answer[0] = [1,3].\nFor nums2, nums2[0] = 2 is present at index 1 of nums1, whereas nums2[1] = 4 and nums2[2] = 6 are not present in nums2. Therefore, answer[1] = [4,6].",
+            "Example 2:\nInput: nums1 = [1,2,3,3], nums2 = [1,1,2,2]\nOutput: [[3],[]]\nExplanation:\nFor nums1, nums1[2] and nums1[3] are not present in nums2. Since nums1[2] == nums1[3], their value is only included once and answer[0] = [3].\nEvery integer in nums2 is present in nums1. Therefore, answer[1] = []."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 1000\n-1000 <= nums1[i], nums2[i] <= 1000",
+        "tags": [
+            "Array",
+            "Hash Table"
+        ],
+        "title-slug": "find-the-difference-of-two-arrays"
+    },
+    {
+        "leetcode-id": 2216,
+        "title": "Minimum Deletions to Make Array Beautiful",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums. The array nums is beautiful if:\n\nnums.length is even.\nnums[i] != nums[i + 1] for all i % 2 == 0.\n\nNote that an empty array is considered beautiful.\nYou can delete any number of elements from nums. When you delete an element, all the elements to the right of the deleted element will be shifted one unit to the left to fill the gap created and all the elements to the left of the deleted element will remain unchanged.\nReturn the minimum number of elements to delete from nums to make it beautiful.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,1,2,3,5]\nOutput: 1\nExplanation: You can delete either nums[0] or nums[1] to make nums = [1,2,3,5] which is beautiful. It can be proven you need at least 1 deletion to make nums beautiful.",
+            "Example 2:\nInput: nums = [1,1,2,2,3,3]\nOutput: 2\nExplanation: You can delete nums[0] and nums[5] to make nums = [1,2,2,3] which is beautiful. It can be proven you need at least 2 deletions to make nums beautiful."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Stack",
+            "Greedy"
+        ],
+        "title-slug": "minimum-deletions-to-make-array-beautiful"
+    },
+    {
+        "leetcode-id": 2217,
+        "title": "Find Palindrome With Fixed Length",
+        "difficulty": 2,
+        "description": "Given an integer array queries and a positive integer intLength, return an array answer where answer[i] is either the queries[i]^th smallest positive palindrome of length intLength or -1 if no such palindrome exists.\nA palindrome is a number that reads the same backwards and forwards. Palindromes cannot have leading zeros.",
+        "examples": [
+            "Example 1:\nInput: queries = [1,2,3,4,5,90], intLength = 3\nOutput: [101,111,121,131,141,999]\nExplanation:\nThe first few palindromes of length 3 are:\n101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, ...\nThe 90^th palindrome of length 3 is 999.",
+            "Example 2:\nInput: queries = [2,4,6], intLength = 4\nOutput: [1111,1331,1551]\nExplanation:\nThe first six palindromes of length 4 are:\n1001, 1111, 1221, 1331, 1441, and 1551."
+        ],
+        "constraints": "Constraints:\n\n1 <= queries.length <= 5 * 10^4\n1 <= queries[i] <= 10^9\n1 <= intLength\u00a0<= 15",
+        "tags": [
+            "Array",
+            "Math"
+        ],
+        "title-slug": "find-palindrome-with-fixed-length"
+    },
+    {
+        "leetcode-id": 2218,
+        "title": "Maximum Value of K Coins From Piles",
+        "difficulty": 3,
+        "description": "There are n piles of coins on a table. Each pile consists of a positive number of coins of assorted denominations.\nIn one move, you can choose any coin on top of any pile, remove it, and add it to your wallet.\nGiven a list piles, where piles[i] is a list of integers denoting the composition of the i^th pile from top to bottom, and a positive integer k, return the maximum total value of coins you can have in your wallet if you choose exactly k coins optimally.",
+        "examples": [
+            "Example 1:\nInput: piles = [[1,100,3],[7,8,9]], k = 2\nOutput: 101\nExplanation:\nThe above diagram shows the different ways we can choose k coins.\nThe maximum total we can obtain is 101.",
+            "Example 2:\nInput: piles = [[100],[100],[100],[100],[100],[100],[1,1,1,1,1,1,700]], k = 7\nOutput: 706\nExplanation:\nThe maximum total can be obtained if we choose all coins from the last pile."
+        ],
+        "constraints": "Constraints:\n\nn == piles.length\n1 <= n <= 1000\n1 <= piles[i][j] <= 10^5\n1 <= k <= sum(piles[i].length) <= 2000",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Prefix Sum"
+        ],
+        "title-slug": "maximum-value-of-k-coins-from-piles"
+    },
+    {
+        "leetcode-id": 2220,
+        "title": "Minimum Bit Flips to Convert Number",
+        "difficulty": 1,
+        "description": "A bit flip of a number x is choosing a bit in the binary representation of x and flipping it from either 0 to 1 or 1 to 0.\n\nFor example, for x = 7, the binary representation is 111 and we may choose any bit (including any leading zeros not shown) and flip it. We can flip the first bit from the right to get 110, flip the second bit from the right to get 101, flip the fifth bit from the right (a leading zero) to get 10111, etc.\n\nGiven two integers start and goal, return the minimum number of bit flips to convert start to goal.",
+        "examples": [
+            "Example 1:\nInput: start = 10, goal = 7\nOutput: 3\nExplanation: The binary representation of 10 and 7 are 1010 and 0111 respectively. We can convert 10 to 7 in 3 steps:\n- Flip the first bit from the right: 1010 -> 1011.\n- Flip the third bit from the right: 1011 -> 1111.\n- Flip the fourth bit from the right: 1111 -> 0111.\nIt can be shown we cannot convert 10 to 7 in less than 3 steps. Hence, we return 3.",
+            "Example 2:\nInput: start = 3, goal = 4\nOutput: 3\nExplanation: The binary representation of 3 and 4 are 011 and 100 respectively. We can convert 3 to 4 in 3 steps:\n- Flip the first bit from the right: 011 -> 010.\n- Flip the second bit from the right: 010 -> 000.\n- Flip the third bit from the right: 000 -> 100.\nIt can be shown we cannot convert 3 to 4 in less than 3 steps. Hence, we return 3."
+        ],
+        "constraints": "Constraints:\n\n0 <= start, goal <= 10^9",
+        "tags": [
+            "Bit Manipulation"
+        ],
+        "title-slug": "minimum-bit-flips-to-convert-number"
+    },
+    {
+        "leetcode-id": 2221,
+        "title": "Find Triangular Sum of an Array",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums, where nums[i] is a digit between 0 and 9 (inclusive).\nThe triangular sum of nums is the value of the only element present in nums after the following process terminates:\n\nLet nums comprise of n elements. If n == 1, end the process. Otherwise, create a new 0-indexed integer array newNums of length n - 1.\nFor each index i, where 0 <= i <\u00a0n - 1, assign the value of newNums[i] as (nums[i] + nums[i+1]) % 10, where % denotes modulo operator.\nReplace the array nums with newNums.\nRepeat the entire process starting from step 1.\n\nReturn the triangular sum of nums.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,3,4,5]\nOutput: 8\nExplanation:\nThe above diagram depicts the process from which we obtain the triangular sum of the array.",
+            "Example 2:\nInput: nums = [5]\nOutput: 5\nExplanation:\nSince there is only one element in nums, the triangular sum is the value of that element itself."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n0 <= nums[i] <= 9",
+        "tags": [
+            "Array",
+            "Math",
+            "Simulation",
+            "Combinatorics"
+        ],
+        "title-slug": "find-triangular-sum-of-an-array"
+    },
+    {
+        "leetcode-id": 2222,
+        "title": "Number of Ways to Select Buildings",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed binary string s which represents the types of buildings along a street where:\n\ns[i] = '0' denotes that the i^th building is an office and\ns[i] = '1' denotes that the i^th building is a restaurant.\n\nAs a city official, you would like to select 3 buildings for random inspection. However, to ensure variety, no two consecutive buildings out of the selected buildings can be of the same type.\n\nFor example, given s = \"001101\", we cannot select the 1^st, 3^rd, and 5^th buildings as that would form \"011\" which is not allowed due to having two consecutive buildings of the same type.\n\nReturn the number of valid ways to select 3 buildings.",
+        "examples": [
+            "Example 1:\nInput: s = \"001101\"\nOutput: 6\nExplanation: \nThe following sets of indices selected are valid:\n- [0,2,4] from \"001101\" forms \"010\"\n- [0,3,4] from \"001101\" forms \"010\"\n- [1,2,4] from \"001101\" forms \"010\"\n- [1,3,4] from \"001101\" forms \"010\"\n- [2,4,5] from \"001101\" forms \"101\"\n- [3,4,5] from \"001101\" forms \"101\"\nNo other selection is valid. Thus, there are 6 total ways.",
+            "Example 2:\nInput: s = \"11100\"\nOutput: 0\nExplanation: It can be shown that there are no valid selections."
+        ],
+        "constraints": "Constraints:\n\n3 <= s.length <= 10^5\ns[i] is either '0' or '1'.",
+        "tags": [
+            "String",
+            "Dynamic Programming",
+            "Prefix Sum"
+        ],
+        "title-slug": "number-of-ways-to-select-buildings"
+    },
+    {
+        "leetcode-id": 2223,
+        "title": "Sum of Scores of Built Strings",
+        "difficulty": 3,
+        "description": "You are building a string s of length n one character at a time, prepending each new character to the front of the string. The strings are labeled from 1 to n, where the string with length i is labeled si.\n\nFor example, for s = \"abaca\", s1 == \"a\", s2 == \"ca\", s3 == \"aca\", etc.\n\nThe score of si is the length of the longest common prefix between si and sn (Note that s == sn).\nGiven the final string s, return the sum of the score of every si.",
+        "examples": [
+            "Example 1:\nInput: s = \"babab\"\nOutput: 9\nExplanation:\nFor s1 == \"b\", the longest common prefix is \"b\" which has a score of 1.\nFor s2 == \"ab\", there is no common prefix so the score is 0.\nFor s3 == \"bab\", the longest common prefix is \"bab\" which has a score of 3.\nFor s4 == \"abab\", there is no common prefix so the score is 0.\nFor s5 == \"babab\", the longest common prefix is \"babab\" which has a score of 5.\nThe sum of the scores is 1 + 0 + 3 + 0 + 5 = 9, so we return 9.",
+            "Example 2:\nInput: s = \"azbazbzaz\"\nOutput: 14\nExplanation: \nFor s2 == \"az\", the longest common prefix is \"az\" which has a score of 2.\nFor s6 == \"azbzaz\", the longest common prefix is \"azb\" which has a score of 3.\nFor s9 == \"azbazbzaz\", the longest common prefix is \"azbazbzaz\" which has a score of 9.\nFor all other si, the score is 0.\nThe sum of the scores is 2 + 3 + 9 = 14, so we return 14."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of lowercase English letters.",
+        "tags": [
+            "String",
+            "Binary Search",
+            "Rolling Hash",
+            "Suffix Array",
+            "String Matching",
+            "Hash Function"
+        ],
+        "title-slug": "sum-of-scores-of-built-strings"
+    },
+    {
+        "leetcode-id": 2224,
+        "title": "Minimum Number of Operations to Convert Time",
+        "difficulty": 1,
+        "description": "You are given two strings current and correct representing two 24-hour times.\n24-hour times are formatted as \"HH:MM\", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59.\nIn one operation you can increase the time current by 1, 5, 15, or 60 minutes. You can perform this operation any number of times.\nReturn the minimum number of operations needed to convert current to correct.",
+        "examples": [
+            "Example 1:\nInput: current = \"02:30\", correct = \"04:35\"\nOutput: 3\nExplanation:\nWe can convert current to correct in 3 operations as follows:\n- Add 60 minutes to current. current becomes \"03:30\".\n- Add 60 minutes to current. current becomes \"04:30\".\n- Add 5 minutes to current. current becomes \"04:35\".\nIt can be proven that it is not possible to convert current to correct in fewer than 3 operations.",
+            "Example 2:\nInput: current = \"11:00\", correct = \"11:01\"\nOutput: 1\nExplanation: We only have to add one minute to current, so the minimum number of operations needed is 1."
+        ],
+        "constraints": "Constraints:\n\ncurrent and correct are in the format \"HH:MM\"\ncurrent <= correct",
+        "tags": [
+            "String",
+            "Greedy"
+        ],
+        "title-slug": "minimum-number-of-operations-to-convert-time"
+    },
+    {
+        "leetcode-id": 2225,
+        "title": "Find Players With Zero or One Losses",
+        "difficulty": 2,
+        "description": "You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match.\nReturn a list answer of size 2 where:\n\nanswer[0] is a list of all players that have not lost any matches.\nanswer[1] is a list of all players that have lost exactly one match.\n\nThe values in the two lists should be returned in increasing order.\nNote:\n\nYou should only consider the players that have played at least one match.\nThe testcases will be generated such that no two matches will have the same outcome.",
+        "examples": [
+            "Example 1:\nInput: matches = [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]\nOutput: [[1,2,10],[4,5,7,8]]\nExplanation:\nPlayers 1, 2, and 10 have not lost any matches.\nPlayers 4, 5, 7, and 8 each have lost one match.\nPlayers 3, 6, and 9 each have lost two matches.\nThus, answer[0] = [1,2,10] and answer[1] = [4,5,7,8].",
+            "Example 2:\nInput: matches = [[2,3],[1,3],[5,4],[6,4]]\nOutput: [[1,2,5,6],[]]\nExplanation:\nPlayers 1, 2, 5, and 6 have not lost any matches.\nPlayers 3 and 4 each have lost two matches.\nThus, answer[0] = [1,2,5,6] and answer[1] = []."
+        ],
+        "constraints": "Constraints:\n\n1 <= matches.length <= 10^5\nmatches[i].length == 2\n1 <= winneri, loseri <= 10^5\nwinneri != loseri\nAll matches[i] are unique.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sorting",
+            "Counting"
+        ],
+        "title-slug": "find-players-with-zero-or-one-losses"
+    },
+    {
+        "leetcode-id": 2226,
+        "title": "Maximum Candies Allocated to K Children",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array candies. Each element in the array denotes a pile of candies of size candies[i]. You can divide each pile into any number of sub piles, but you cannot merge two piles together.\nYou are also given an integer k. You should allocate piles of candies to k children such that each child gets the same number of candies. Each child can take at most one pile of candies and some piles of candies may go unused.\nReturn the maximum number of candies each child can get.",
+        "examples": [
+            "Example 1:\nInput: candies = [5,8,6], k = 3\nOutput: 5\nExplanation: We can divide candies[1] into 2 piles of size 5 and 3, and candies[2] into 2 piles of size 5 and 1. We now have five piles of candies of sizes 5, 5, 3, 5, and 1. We can allocate the 3 piles of size 5 to 3 children. It can be proven that each child cannot receive more than 5 candies.",
+            "Example 2:\nInput: candies = [2,5], k = 11\nOutput: 0\nExplanation: There are 11 children but only 7 candies in total, so it is impossible to ensure each child receives at least one candy. Thus, each child gets no candy and the answer is 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= candies.length <= 10^5\n1 <= candies[i] <= 10^7\n1 <= k <= 10^12",
+        "tags": [
+            "Array",
+            "Binary Search"
+        ],
+        "title-slug": "maximum-candies-allocated-to-k-children"
+    },
+    {
+        "leetcode-id": 2227,
+        "title": "Encrypt and Decrypt Strings",
+        "difficulty": 3,
+        "description": "You are given a character array keys containing unique characters and a string array values containing strings of length 2. You are also given another string array dictionary that contains all permitted original strings after decryption. You should implement a data structure that can encrypt or decrypt a 0-indexed string.\nA string is encrypted with the following process:\n\nFor each character c in the string, we find the index i satisfying keys[i] == c in keys.\nReplace c with values[i] in the string.\n\nNote that in case a character of the string is not present in keys, the encryption process cannot be carried out, and an empty string \"\" is returned.\nA string is decrypted with the following process:\n\nFor each substring s of length 2 occurring at an even index in the string, we find an i such that values[i] == s. If there are multiple valid i, we choose any one of them. This means a string could have multiple possible strings it can decrypt to.\nReplace s with keys[i] in the string.\n\nImplement the Encrypter class:\n\nEncrypter(char[] keys, String[] values, String[] dictionary) Initializes the Encrypter class with keys, values, and dictionary.\nString encrypt(String word1) Encrypts word1 with the encryption process described above and returns the encrypted string.\nint decrypt(String word2) Returns the number of possible strings word2 could decrypt to that also appear in dictionary.",
+        "examples": [
+            "Example 1:\nInput\n[\"Encrypter\", \"encrypt\", \"decrypt\"]\n[[['a', 'b', 'c', 'd'], [\"ei\", \"zf\", \"ei\", \"am\"], [\"abcd\", \"acbd\", \"adbc\", \"badc\", \"dacb\", \"cadb\", \"cbda\", \"abad\"]], [\"abcd\"], [\"eizfeiam\"]]\nOutput\n[null, \"eizfeiam\", 2]\n\nExplanation\nEncrypter encrypter = new Encrypter([['a', 'b', 'c', 'd'], [\"ei\", \"zf\", \"ei\", \"am\"], [\"abcd\", \"acbd\", \"adbc\", \"badc\", \"dacb\", \"cadb\", \"cbda\", \"abad\"]);\nencrypter.encrypt(\"abcd\"); // return \"eizfeiam\". \n\u00a0                          // 'a' maps to \"ei\", 'b' maps to \"zf\", 'c' maps to \"ei\", and 'd' maps to \"am\".\nencrypter.decrypt(\"eizfeiam\"); // return 2. \n                              // \"ei\" can map to 'a' or 'c', \"zf\" maps to 'b', and \"am\" maps to 'd'. \n                              // Thus, the possible strings after decryption are \"abad\", \"cbad\", \"abcd\", and \"cbcd\". \n                              // 2 of those strings, \"abad\" and \"abcd\", appear in dictionary, so the answer is 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= keys.length == values.length <= 26\nvalues[i].length == 2\n1 <= dictionary.length <= 100\n1 <= dictionary[i].length <= 100\nAll keys[i] and dictionary[i] are unique.\n1 <= word1.length <= 2000\n1 <= word2.length <= 200\nAll word1[i] appear in keys.\nword2.length is even.\nkeys, values[i], dictionary[i], word1, and word2 only contain lowercase English letters.\nAt most 200 calls will be made to encrypt and decrypt in total.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Design",
+            "Trie"
+        ],
+        "title-slug": "encrypt-and-decrypt-strings"
+    },
+    {
+        "leetcode-id": 2231,
+        "title": "Largest Number After Digit Swaps by Parity",
+        "difficulty": 1,
+        "description": "You are given a positive integer num. You may swap any two digits of num that have the same parity (i.e. both odd digits or both even digits).\nReturn the largest possible value of num after any number of swaps.",
+        "examples": [
+            "Example 1:\nInput: num = 1234\nOutput: 3412\nExplanation: Swap the digit 3 with the digit 1, this results in the number 3214.\nSwap the digit 2 with the digit 4, this results in the number 3412.\nNote that there may be other sequences of swaps but it can be shown that 3412 is the largest possible number.\nAlso note that we may not swap the digit 4 with the digit 1 since they are of different parities.",
+            "Example 2:\nInput: num = 65875\nOutput: 87655\nExplanation: Swap the digit 8 with the digit 6, this results in the number 85675.\nSwap the first digit 5 with the digit 7, this results in the number 87655.\nNote that there may be other sequences of swaps but it can be shown that 87655 is the largest possible number."
+        ],
+        "constraints": "Constraints:\n\n1 <= num <= 10^9",
+        "tags": [
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "largest-number-after-digit-swaps-by-parity"
+    },
+    {
+        "leetcode-id": 2232,
+        "title": "Minimize Result by Adding Parentheses to Expression",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed string expression of the form \"+\" where  and  represent positive integers.\nAdd a pair of parentheses to expression such that after the addition of parentheses, expression is a valid mathematical expression and evaluates to the smallest possible value. The left parenthesis must be added to the left of '+' and the right parenthesis must be added to the right of '+'.\nReturn expression after adding a pair of parentheses such that expression evaluates to the smallest possible value. If there are multiple answers that yield the same result, return any of them.\nThe input has been generated such that the original value of expression, and the value of expression after adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer.",
+        "examples": [
+            "Example 1:\nInput: expression = \"247+38\"\nOutput: \"2(47+38)\"\nExplanation: The expression evaluates to 2 * (47 + 38) = 2 * 85 = 170.\nNote that \"2(4)7+38\" is invalid because the right parenthesis must be to the right of the '+'.\nIt can be shown that 170 is the smallest possible value.",
+            "Example 2:\nInput: expression = \"12+34\"\nOutput: \"1(2+3)4\"\nExplanation: The expression evaluates to 1 * (2 + 3) * 4 = 1 * 5 * 4 = 20.",
+            "Example 3:\nInput: expression = \"999+999\"\nOutput: \"(999+999)\"\nExplanation: The expression evaluates to 999 + 999 = 1998."
+        ],
+        "constraints": "Constraints:\n\n3 <= expression.length <= 10\nexpression consists of digits from '1' to '9' and '+'.\nexpression starts and ends with digits.\nexpression contains exactly one '+'.\nThe original value of expression, and the value of expression after adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer.",
+        "tags": [
+            "String",
+            "Enumeration"
+        ],
+        "title-slug": "minimize-result-by-adding-parentheses-to-expression"
+    },
+    {
+        "leetcode-id": 2233,
+        "title": "Maximum Product After K Increments",
+        "difficulty": 2,
+        "description": "You are given an array of non-negative integers nums and an integer k. In one operation, you may choose any element from nums and increment it by 1.\nReturn the maximum product of nums after at most k operations. Since the answer may be very large, return it modulo 10^9 + 7. Note that you should maximize the product before taking the modulo.",
+        "examples": [
+            "Example 1:\nInput: nums = [0,4], k = 5\nOutput: 20\nExplanation: Increment the first number 5 times.\nNow nums = [5, 4], with a product of 5 * 4 = 20.\nIt can be shown that 20 is maximum product possible, so we return 20.\nNote that there may be other ways to increment nums to have the maximum product.",
+            "Example 2:\nInput: nums = [6,3,3,2], k = 2\nOutput: 216\nExplanation: Increment the second number 1 time and increment the fourth number 1 time.\nNow nums = [6, 4, 3, 3], with a product of 6 * 4 * 3 * 3 = 216.\nIt can be shown that 216 is maximum product possible, so we return 216.\nNote that there may be other ways to increment nums to have the maximum product."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length, k <= 10^5\n0 <= nums[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "maximum-product-after-k-increments"
+    },
+    {
+        "leetcode-id": 2234,
+        "title": "Maximum Total Beauty of the Gardens",
+        "difficulty": 3,
+        "description": "Alice is a caretaker of n gardens and she wants to plant flowers to maximize the total beauty of all her gardens.\nYou are given a 0-indexed integer array flowers of size n, where flowers[i] is the number of flowers already planted in the i^th garden. Flowers that are already planted cannot be removed. You are then given another integer newFlowers, which is the maximum number of flowers that Alice can additionally plant. You are also given the integers target, full, and partial.\nA garden is considered complete if it has at least target flowers. The total beauty of the gardens is then determined as the sum of the following:\n\nThe number of complete gardens multiplied by full.\nThe minimum number of flowers in any of the incomplete gardens multiplied by partial. If there are no incomplete gardens, then this value will be 0.\n\nReturn the maximum total beauty that Alice can obtain after planting at most newFlowers flowers.",
+        "examples": [
+            "Example 1:\nInput: flowers = [1,3,1,1], newFlowers = 7, target = 6, full = 12, partial = 1\nOutput: 14\nExplanation: Alice can plant\n- 2 flowers in the 0^th garden\n- 3 flowers in the 1^st garden\n- 1 flower in the 2^nd garden\n- 1 flower in the 3^rd garden\nThe gardens will then be [3,6,2,2]. She planted a total of 2 + 3 + 1 + 1 = 7 flowers.\nThere is 1 garden that is complete.\nThe minimum number of flowers in the incomplete gardens is 2.\nThus, the total beauty is 1 * 12 + 2 * 1 = 12 + 2 = 14.\nNo other way of planting flowers can obtain a total beauty higher than 14.",
+            "Example 2:\nInput: flowers = [2,4,5,3], newFlowers = 10, target = 5, full = 2, partial = 6\nOutput: 30\nExplanation: Alice can plant\n- 3 flowers in the 0^th garden\n- 0 flowers in the 1^st garden\n- 0 flowers in the 2^nd garden\n- 2 flowers in the 3^rd garden\nThe gardens will then be [5,4,5,5]. She planted a total of 3 + 0 + 0 + 2 = 5 flowers.\nThere are 3 gardens that are complete.\nThe minimum number of flowers in the incomplete gardens is 4.\nThus, the total beauty is 3 * 2 + 4 * 6 = 6 + 24 = 30.\nNo other way of planting flowers can obtain a total beauty higher than 30.\nNote that Alice could make all the gardens complete but in this case, she would obtain a lower total beauty."
+        ],
+        "constraints": "Constraints:\n\n1 <= flowers.length <= 10^5\n1 <= flowers[i], target <= 10^5\n1 <= newFlowers <= 10^10\n1 <= full, partial <= 10^5",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Binary Search",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "maximum-total-beauty-of-the-gardens"
+    },
+    {
+        "leetcode-id": 2235,
+        "title": "Add Two Integers",
+        "difficulty": 1,
+        "description": "Given two integers num1 and num2, return the sum of the two integers.",
+        "examples": [
+            "Example 1:\nInput: num1 = 12, num2 = 5\nOutput: 17\nExplanation: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.",
+            "Example 2:\nInput: num1 = -10, num2 = 4\nOutput: -6\nExplanation: num1 + num2 = -6, so -6 is returned."
+        ],
+        "constraints": "Constraints:\n\n-100 <= num1, num2 <= 100",
+        "tags": [
+            "Math"
+        ],
+        "title-slug": "add-two-integers"
+    },
+    {
+        "leetcode-id": 2236,
+        "title": "Root Equals Sum of Children",
+        "difficulty": 1,
+        "description": "You are given the root of a binary tree that consists of exactly 3 nodes: the root, its left child, and its right child.\nReturn true if the value of the root is equal to the sum of the values of its two children, or false otherwise.",
+        "examples": [
+            "Example 1:\nInput: root = [10,4,6]\nOutput: true\nExplanation: The values of the root, its left child, and its right child are 10, 4, and 6, respectively.\n10 is equal to 4 + 6, so we return true.",
+            "Example 2:\nInput: root = [5,3,1]\nOutput: false\nExplanation: The values of the root, its left child, and its right child are 5, 3, and 1, respectively.\n5 is not equal to 3 + 1, so we return false."
+        ],
+        "constraints": "Constraints:\n\nThe tree consists only of the root, its left child, and its right child.\n-100 <= Node.val <= 100",
+        "tags": [
+            "Tree",
+            "Binary Tree"
+        ],
+        "title-slug": "root-equals-sum-of-children"
+    },
+    {
+        "leetcode-id": 2239,
+        "title": "Find Closest Number to Zero",
+        "difficulty": 1,
+        "description": "Given an integer array nums of size n, return the number with the value closest to 0 in nums. If there are multiple answers, return the number with the largest value.",
+        "examples": [
+            "Example 1:\nInput: nums = [-4,-2,1,4,8]\nOutput: 1\nExplanation:\nThe distance from -4 to 0 is |-4| = 4.\nThe distance from -2 to 0 is |-2| = 2.\nThe distance from 1 to 0 is |1| = 1.\nThe distance from 4 to 0 is |4| = 4.\nThe distance from 8 to 0 is |8| = 8.\nThus, the closest number to 0 in the array is 1.",
+            "Example 2:\nInput: nums = [2,-1,1]\nOutput: 1\nExplanation: 1 and -1 are both the closest numbers to 0, so 1 being larger is returned."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 1000\n-10^5 <= nums[i] <= 10^5",
+        "tags": [
+            "Array"
+        ],
+        "title-slug": "find-closest-number-to-zero"
+    },
+    {
+        "leetcode-id": 2240,
+        "title": "Number of Ways to Buy Pens and Pencils",
+        "difficulty": 2,
+        "description": "You are given an integer total indicating the amount of money you have. You are also given two integers cost1 and cost2 indicating the price of a pen and pencil respectively. You can spend part or all of your money to buy multiple quantities (or none) of each kind of writing utensil.\nReturn the number of distinct ways you can buy some number of pens and pencils.",
+        "examples": [
+            "Example 1:\nInput: total = 20, cost1 = 10, cost2 = 5\nOutput: 9\nExplanation: The price of a pen is 10 and the price of a pencil is 5.\n- If you buy 0 pens, you can buy 0, 1, 2, 3, or 4 pencils.\n- If you buy 1 pen, you can buy 0, 1, or 2 pencils.\n- If you buy 2 pens, you cannot buy any pencils.\nThe total number of ways to buy pens and pencils is 5 + 3 + 1 = 9.",
+            "Example 2:\nInput: total = 5, cost1 = 10, cost2 = 10\nOutput: 1\nExplanation: The price of both pens and pencils are 10, which cost more than total, so you cannot buy any writing utensils. Therefore, there is only 1 way: buy 0 pens and 0 pencils."
+        ],
+        "constraints": "Constraints:\n\n1 <= total, cost1, cost2 <= 10^6",
+        "tags": [
+            "Math",
+            "Enumeration"
+        ],
+        "title-slug": "number-of-ways-to-buy-pens-and-pencils"
+    },
+    {
+        "leetcode-id": 2241,
+        "title": "Design an ATM Machine",
+        "difficulty": 2,
+        "description": "There is an ATM machine that stores banknotes of 5 denominations: 20, 50, 100, 200, and 500 dollars. Initially the ATM is empty. The user can use the machine to deposit or withdraw any amount of money.\nWhen withdrawing, the machine prioritizes using banknotes of larger values.\n\nFor example, if you want to withdraw $300 and there are 2 $50 banknotes, 1 $100 banknote, and 1 $200 banknote, then the machine will use the $100 and $200 banknotes.\nHowever, if you try to withdraw $600 and there are 3 $200 banknotes and 1 $500 banknote, then the withdraw request will be rejected because the machine will first try to use the $500 banknote and then be unable to use banknotes to complete the remaining $100. Note that the machine is not allowed to use the $200 banknotes instead of the $500 banknote.\n\nImplement the ATM class:\n\nATM() Initializes the ATM object.\nvoid deposit(int[] banknotesCount) Deposits new banknotes in the order $20, $50, $100, $200, and $500.\nint[] withdraw(int amount) Returns an array of length 5 of the number of banknotes that will be handed to the user in the order $20, $50, $100, $200, and $500, and update the number of banknotes in the ATM after withdrawing. Returns [-1] if it is not possible (do not withdraw any banknotes in this case).",
+        "examples": [
+            "Example 1:\nInput\n[\"ATM\", \"deposit\", \"withdraw\", \"deposit\", \"withdraw\", \"withdraw\"]\n[[], [[0,0,1,2,1]], [600], [[0,1,0,1,1]], [600], [550]]\nOutput\n[null, null, [0,0,1,0,1], null, [-1], [0,1,0,0,1]]\n\nExplanation\nATM atm = new ATM();\natm.deposit([0,0,1,2,1]); // Deposits 1 $100 banknote, 2 $200 banknotes,\n                          // and 1 $500 banknote.\natm.withdraw(600);        // Returns [0,0,1,0,1]. The machine uses 1 $100 banknote\n                          // and 1 $500 banknote. The banknotes left over in the\n                          // machine are [0,0,0,2,0].\natm.deposit([0,1,0,1,1]); // Deposits 1 $50, $200, and $500 banknote.\n                          // The banknotes in the machine are now [0,1,0,3,1].\natm.withdraw(600);        // Returns [-1]. The machine will try to use a $500 banknote\n                          // and then be unable to complete the remaining $100,\n                          // so the withdraw request will be rejected.\n                          // Since the request is rejected, the number of banknotes\n                          // in the machine is not modified.\natm.withdraw(550);        // Returns [0,1,0,0,1]. The machine uses 1 $50 banknote\n                          // and 1 $500 banknote."
+        ],
+        "constraints": "Constraints:\n\nbanknotesCount.length == 5\n0 <= banknotesCount[i] <= 10^9\n1 <= amount <= 10^9\nAt most 5000 calls in total will be made to withdraw and deposit.\nAt least one call will be made to each function withdraw and deposit.",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Design"
+        ],
+        "title-slug": "design-an-atm-machine"
+    },
+    {
+        "leetcode-id": 2242,
+        "title": "Maximum Score of a Node Sequence",
+        "difficulty": 3,
+        "description": "There is an undirected graph with n nodes, numbered from 0 to n - 1.\nYou are given a 0-indexed integer array scores of length n where scores[i] denotes the score of node i. You are also given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.\nA node sequence is valid if it meets the following conditions:\n\nThere is an edge connecting every pair of adjacent nodes in the sequence.\nNo node appears more than once in the sequence.\n\nThe score of a node sequence is defined as the sum of the scores of the nodes in the sequence.\nReturn the maximum score of a valid node sequence with a length of 4. If no such sequence exists, return -1.",
+        "examples": [
+            "Example 1:\nInput: scores = [5,2,9,8,4], edges = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]\nOutput: 24\nExplanation: The figure above shows the graph and the chosen node sequence [0,1,2,3].\nThe score of the node sequence is 5 + 2 + 9 + 8 = 24.\nIt can be shown that no other node sequence has a score of more than 24.\nNote that the sequences [3,1,2,0] and [1,0,2,3] are also valid and have a score of 24.\nThe sequence [0,3,2,4] is not valid since no edge connects nodes 0 and 3.",
+            "Example 2:\nInput: scores = [9,20,6,4,11,12], edges = [[0,3],[5,3],[2,4],[1,3]]\nOutput: -1\nExplanation: The figure above shows the graph.\nThere are no valid node sequences of length 4, so we return -1."
+        ],
+        "constraints": "Constraints:\n\nn == scores.length\n4 <= n <= 5 * 10^4\n1 <= scores[i] <= 10^8\n0 <= edges.length <= 5 * 10^4\nedges[i].length == 2\n0 <= ai, bi <= n - 1\nai != bi\nThere are no duplicate edges.",
+        "tags": [
+            "Array",
+            "Graph",
+            "Sorting",
+            "Enumeration"
+        ],
+        "title-slug": "maximum-score-of-a-node-sequence"
+    },
+    {
+        "leetcode-id": 2243,
+        "title": "Calculate Digit Sum of a String",
+        "difficulty": 1,
+        "description": "You are given a string s consisting of digits and an integer k.\nA round can be completed if the length of s is greater than k. In one round, do the following:\n\nDivide s into consecutive groups of size k such that the first k characters are in the first group, the next k characters are in the second group, and so on. Note that the size of the last group can be smaller than k.\nReplace each group of s with a string representing the sum of all its digits. For example, \"346\" is replaced with \"13\" because 3 + 4 + 6 = 13.\nMerge consecutive groups together to form a new string. If the length of the string is greater than k, repeat from step 1.\n\nReturn s after all rounds have been completed.",
+        "examples": [
+            "Example 1:\nInput: s = \"11111222223\", k = 3\nOutput: \"135\"\nExplanation: \n- For the first round, we divide s into groups of size 3: \"111\", \"112\", \"222\", and \"23\".\n  \u200b\u200b\u200b\u200b\u200bThen we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5. \n\u00a0 So, s becomes \"3\" + \"4\" + \"6\" + \"5\" = \"3465\" after the first round.\n- For the second round, we divide s into \"346\" and \"5\".\n\u00a0 Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5. \n\u00a0 So, s becomes \"13\" + \"5\" = \"135\" after second round. \nNow, s.length <= k, so we return \"135\" as the answer.",
+            "Example 2:\nInput: s = \"00000000\", k = 3\nOutput: \"000\"\nExplanation: \nWe divide s into \"000\", \"000\", and \"00\".\nThen we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0. \ns becomes \"0\" + \"0\" + \"0\" = \"000\", whose length is equal to k, so we return \"000\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 100\n2 <= k <= 100\ns consists of digits only.",
+        "tags": [
+            "String",
+            "Simulation"
+        ],
+        "title-slug": "calculate-digit-sum-of-a-string"
+    },
+    {
+        "leetcode-id": 2244,
+        "title": "Minimum Rounds to Complete All Tasks",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level.\nReturn the minimum rounds required to complete all the tasks, or -1 if it is not possible to complete all the tasks.",
+        "examples": [
+            "Example 1:\nInput: tasks = [2,2,3,3,2,4,4,4,4,4]\nOutput: 4\nExplanation: To complete all the tasks, a possible plan is:\n- In the first round, you complete 3 tasks of difficulty level 2. \n- In the second round, you complete 2 tasks of difficulty level 3. \n- In the third round, you complete 3 tasks of difficulty level 4. \n- In the fourth round, you complete 2 tasks of difficulty level 4.  \nIt can be shown that all the tasks cannot be completed in fewer than 4 rounds, so the answer is 4.",
+            "Example 2:\nInput: tasks = [2,3,3]\nOutput: -1\nExplanation: There is only 1 task of difficulty level 2, but in each round, you can only complete either 2 or 3 tasks of the same difficulty level. Hence, you cannot complete all the tasks, and the answer is -1."
+        ],
+        "constraints": "Constraints:\n\n1 <= tasks.length <= 10^5\n1 <= tasks[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Greedy",
+            "Counting"
+        ],
+        "title-slug": "minimum-rounds-to-complete-all-tasks"
+    },
+    {
+        "leetcode-id": 2245,
+        "title": "Maximum Trailing Zeros in a Cornered Path",
+        "difficulty": 2,
+        "description": "You are given a 2D integer array grid of size m x n, where each cell contains a positive integer.\nA cornered path is defined as a set of adjacent cells with at most one turn. More specifically, the path should exclusively move either horizontally or vertically up to the turn (if there is one), without returning to a previously visited cell. After the turn, the path will then move exclusively in the alternate direction: move vertically if it moved horizontally, and vice versa, also without returning to a previously visited cell.\nThe product of a path is defined as the product of all the values in the path.\nReturn the maximum number of trailing zeros in the product of a cornered path found in grid.\nNote:\n\nHorizontal movement means moving in either the left or right direction.\nVertical movement means moving in either the up or down direction.",
+        "examples": [
+            "Example 1:\nInput: grid = [[23,17,15,3,20],[8,1,20,27,11],[9,4,6,2,21],[40,9,1,10,6],[22,7,4,5,3]]\nOutput: 3\nExplanation: The grid on the left shows a valid cornered path.\nIt has a product of 15 * 20 * 6 * 1 * 10 = 18000 which has 3 trailing zeros.\nIt can be shown that this is the maximum trailing zeros in the product of a cornered path.\n\nThe grid in the middle is not a cornered path as it has more than one turn.\nThe grid on the right is not a cornered path as it requires a return to a previously visited cell.",
+            "Example 2:\nInput: grid = [[4,3,2],[7,6,1],[8,8,8]]\nOutput: 0\nExplanation: The grid is shown in the figure above.\nThere are no cornered paths in the grid that result in a product with a trailing zero."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 10^5\n1 <= m * n <= 10^5\n1 <= grid[i][j] <= 1000",
+        "tags": [
+            "Array",
+            "Matrix",
+            "Prefix Sum"
+        ],
+        "title-slug": "maximum-trailing-zeros-in-a-cornered-path"
+    },
+    {
+        "leetcode-id": 2246,
+        "title": "Longest Path With Different Adjacent Characters",
+        "difficulty": 3,
+        "description": "You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.\nYou are also given a string s of length n, where s[i] is the character assigned to node i.\nReturn the length of the longest path in the tree such that no pair of adjacent nodes on the path have the same character assigned to them.",
+        "examples": [
+            "Example 1:\nInput: parent = [-1,0,0,1,1,2], s = \"abacbe\"\nOutput: 3\nExplanation: The longest path where each two adjacent nodes have different characters in the tree is the path: 0 -> 1 -> 3. The length of this path is 3, so 3 is returned.\nIt can be proven that there is no longer path that satisfies the conditions.",
+            "Example 2:\nInput: parent = [-1,0,0,0], s = \"aabc\"\nOutput: 3\nExplanation: The longest path where each two adjacent nodes have different characters is the path: 2 -> 0 -> 3. The length of this path is 3, so 3 is returned."
+        ],
+        "constraints": "Constraints:\n\nn == parent.length == s.length\n1 <= n <= 10^5\n0 <= parent[i] <= n - 1 for all i >= 1\nparent[0] == -1\nparent represents a valid tree.\ns consists of only lowercase English letters.",
+        "tags": [
+            "Array",
+            "String",
+            "Tree",
+            "Depth-First Search",
+            "Graph",
+            "Topological Sort"
+        ],
+        "title-slug": "longest-path-with-different-adjacent-characters"
+    },
+    {
+        "leetcode-id": 2248,
+        "title": "Intersection of Multiple Arrays",
+        "difficulty": 1,
+        "description": "Given a 2D integer array nums where nums[i] is a non-empty array of distinct positive integers, return the list of integers that are present in each array of nums sorted in ascending order.",
+        "examples": [
+            "Example 1:\nInput: nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]\nOutput: [3,4]\nExplanation: \nThe only integers present in each of nums[0] = [3,1,2,4,5], nums[1] = [1,2,3,4], and nums[2] = [3,4,5,6] are 3 and 4, so we return [3,4].",
+            "Example 2:\nInput: nums = [[1,2,3],[4,5,6]]\nOutput: []\nExplanation: \nThere does not exist any integer present both in nums[0] and nums[1], so we return an empty list []."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= sum(nums[i].length) <= 1000\n1 <= nums[i][j] <= 1000\nAll the values of nums[i] are unique.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Counting"
+        ],
+        "title-slug": "intersection-of-multiple-arrays"
+    },
+    {
+        "leetcode-id": 2249,
+        "title": "Count Lattice Points Inside a Circle",
+        "difficulty": 2,
+        "description": "Given a 2D integer array circles where circles[i] = [xi, yi, ri] represents the center (xi, yi) and radius ri of the i^th circle drawn on a grid, return the number of lattice points that are present inside at least one circle.\nNote:\n\nA lattice point is a point with integer coordinates.\nPoints that lie on the circumference of a circle are also considered to be inside it.",
+        "examples": [
+            "Example 1:\nInput: circles = [[2,2,1]]\nOutput: 5\nExplanation:\nThe figure above shows the given circle.\nThe lattice points present inside the circle are (1, 2), (2, 1), (2, 2), (2, 3), and (3, 2) and are shown in green.\nOther points such as (1, 1) and (1, 3), which are shown in red, are not considered inside the circle.\nHence, the number of lattice points present inside at least one circle is 5.",
+            "Example 2:\nInput: circles = [[2,2,2],[3,4,1]]\nOutput: 16\nExplanation:\nThe figure above shows the given circles.\nThere are exactly 16 lattice points which are present inside at least one circle. \nSome of them are (0, 2), (2, 0), (2, 4), (3, 2), and (4, 4)."
+        ],
+        "constraints": "Constraints:\n\n1 <= circles.length <= 200\ncircles[i].length == 3\n1 <= xi, yi <= 100\n1 <= ri <= min(xi, yi)",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Math",
+            "Geometry",
+            "Enumeration"
+        ],
+        "title-slug": "count-lattice-points-inside-a-circle"
+    },
+    {
+        "leetcode-id": 2250,
+        "title": "Count Number of Rectangles Containing Each Point",
+        "difficulty": 2,
+        "description": "You are given a 2D integer array rectangles where rectangles[i] = [li, hi] indicates that i^th rectangle has a length of li and a height of hi. You are also given a 2D integer array points where points[j] = [xj, yj] is a point with coordinates (xj, yj).\nThe i^th rectangle has its bottom-left corner point at the coordinates (0, 0) and its top-right corner point at (li, hi).\nReturn an integer array count of length points.length where count[j] is the number of rectangles that contain the j^th point.\nThe i^th rectangle contains the j^th point if 0 <= xj <= li and 0 <= yj <= hi. Note that points that lie on the edges of a rectangle are also considered to be contained by that rectangle.",
+        "examples": [
+            "Example 1:\nInput: rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]]\nOutput: [2,1]\nExplanation: \nThe first rectangle contains no points.\nThe second rectangle contains only the point (2, 1).\nThe third rectangle contains the points (2, 1) and (1, 4).\nThe number of rectangles that contain the point (2, 1) is 2.\nThe number of rectangles that contain the point (1, 4) is 1.\nTherefore, we return [2, 1].",
+            "Example 2:\nInput: rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]]\nOutput: [1,3]\nExplanation:\nThe first rectangle contains only the point (1, 1).\nThe second rectangle contains only the point (1, 1).\nThe third rectangle contains the points (1, 3) and (1, 1).\nThe number of rectangles that contain the point (1, 3) is 1.\nThe number of rectangles that contain the point (1, 1) is 3.\nTherefore, we return [1, 3]."
+        ],
+        "constraints": "Constraints:\n\n1 <= rectangles.length, points.length <= 5 * 10^4\nrectangles[i].length == points[j].length == 2\n1 <= li, xj <= 10^9\n1 <= hi, yj <= 100\nAll the rectangles are unique.\nAll the points are unique.",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Binary Indexed Tree",
+            "Sorting"
+        ],
+        "title-slug": "count-number-of-rectangles-containing-each-point"
+    },
+    {
+        "leetcode-id": 2251,
+        "title": "Number of Flowers in Full Bloom",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed 2D integer array flowers, where flowers[i] = [starti, endi] means the i^th flower will be in full bloom from starti to endi (inclusive). You are also given a 0-indexed integer array people of size n, where people[i] is the time that the i^th person will arrive to see the flowers.\nReturn an integer array answer of size n, where answer[i] is the number of flowers that are in full bloom when the i^th person arrives.",
+        "examples": [
+            "Example 1:\nInput: flowers = [[1,6],[3,7],[9,12],[4,13]], poeple = [2,3,7,11]\nOutput: [1,2,2,2]\nExplanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.\nFor each person, we return the number of flowers in full bloom during their arrival.",
+            "Example 2:\nInput: flowers = [[1,10],[3,3]], poeple = [3,3,2]\nOutput: [2,2,1]\nExplanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.\nFor each person, we return the number of flowers in full bloom during their arrival."
+        ],
+        "constraints": "Constraints:\n\n1 <= flowers.length <= 5 * 10^4\nflowers[i].length == 2\n1 <= starti <= endi <= 10^9\n1 <= people.length <= 5 * 10^4\n1 <= people[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Binary Search",
+            "Sorting",
+            "Prefix Sum",
+            "Ordered Set"
+        ],
+        "title-slug": "number-of-flowers-in-full-bloom"
+    },
+    {
+        "leetcode-id": 2255,
+        "title": "Count Prefixes of a Given String",
+        "difficulty": 1,
+        "description": "You are given a string array words and a string s, where words[i] and s comprise only of lowercase English letters.\nReturn the number of strings in words that are a prefix of s.\nA prefix of a string is a substring that occurs at the beginning of the string. A substring is a contiguous sequence of characters within a string.",
+        "examples": [
+            "Example 1:\nInput: words = [\"a\",\"b\",\"c\",\"ab\",\"bc\",\"abc\"], s = \"abc\"\nOutput: 3\nExplanation:\nThe strings in words which are a prefix of s = \"abc\" are:\n\"a\", \"ab\", and \"abc\".\nThus the number of strings in words which are a prefix of s is 3.",
+            "Example 2:\nInput: words = [\"a\",\"a\"], s = \"aa\"\nOutput: 2\nExplanation:\nBoth of the strings are a prefix of s. \nNote that the same string can occur multiple times in words, and it should be counted each time."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 1000\n1 <= words[i].length, s.length <= 10\nwords[i] and s consist of lowercase English letters only.",
+        "tags": [
+            "Array",
+            "String"
+        ],
+        "title-slug": "count-prefixes-of-a-given-string"
+    },
+    {
+        "leetcode-id": 2256,
+        "title": "Minimum Average Difference",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums of length n.\nThe average difference of the index i is the absolute difference between the average of the first i + 1 elements of nums and the average of the last n - i - 1 elements. Both averages should be rounded down to the nearest integer.\nReturn the index with the minimum average difference. If there are multiple such indices, return the smallest one.\nNote:\n\nThe absolute difference of two numbers is the absolute value of their difference.\nThe average of n elements is the sum of the n elements divided (integer division) by n.\nThe average of 0 elements is considered to be 0.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,5,3,9,5,3]\nOutput: 3\nExplanation:\n- The average difference of index 0 is: |2 / 1 - (5 + 3 + 9 + 5 + 3) / 5| = |2 / 1 - 25 / 5| = |2 - 5| = 3.\n- The average difference of index 1 is: |(2 + 5) / 2 - (3 + 9 + 5 + 3) / 4| = |7 / 2 - 20 / 4| = |3 - 5| = 2.\n- The average difference of index 2 is: |(2 + 5 + 3) / 3 - (9 + 5 + 3) / 3| = |10 / 3 - 17 / 3| = |3 - 5| = 2.\n- The average difference of index 3 is: |(2 + 5 + 3 + 9) / 4 - (5 + 3) / 2| = |19 / 4 - 8 / 2| = |4 - 4| = 0.\n- The average difference of index 4 is: |(2 + 5 + 3 + 9 + 5) / 5 - 3 / 1| = |24 / 5 - 3 / 1| = |4 - 3| = 1.\n- The average difference of index 5 is: |(2 + 5 + 3 + 9 + 5 + 3) / 6 - 0| = |27 / 6 - 0| = |4 - 0| = 4.\nThe average difference of index 3 is the minimum average difference so return 3.",
+            "Example 2:\nInput: nums = [0]\nOutput: 0\nExplanation:\nThe only index is 0 so return 0.\nThe average difference of index 0 is: |0 / 1 - 0| = |0 - 0| = 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Prefix Sum"
+        ],
+        "title-slug": "minimum-average-difference"
+    },
+    {
+        "leetcode-id": 2257,
+        "title": "Count Unguarded Cells in the Grid",
+        "difficulty": 2,
+        "description": "You are given two integers m and n representing a 0-indexed m x n grid. You are also given two 2D integer arrays guards and walls where guards[i] = [rowi, coli] and walls[j] = [rowj, colj] represent the positions of the i^th guard and j^th wall respectively.\nA guard can see every cell in the four cardinal directions (north, east, south, or west) starting from their position unless obstructed by a wall or another guard. A cell is guarded if there is at least one guard that can see it.\nReturn the number of unoccupied cells that are not guarded.",
+        "examples": [
+            "Example 1:\nInput: m = 4, n = 6, guards = [[0,0],[1,1],[2,3]], walls = [[0,1],[2,2],[1,4]]\nOutput: 7\nExplanation: The guarded and unguarded cells are shown in red and green respectively in the above diagram.\nThere are a total of 7 unguarded cells, so we return 7.",
+            "Example 2:\nInput: m = 3, n = 3, guards = [[1,1]], walls = [[0,1],[1,0],[2,1],[1,2]]\nOutput: 4\nExplanation: The unguarded cells are shown in green in the above diagram.\nThere are a total of 4 unguarded cells, so we return 4."
+        ],
+        "constraints": "Constraints:\n\n1 <= m, n <= 10^5\n2 <= m * n <= 10^5\n1 <= guards.length, walls.length <= 5 * 10^4\n2 <= guards.length + walls.length <= m * n\nguards[i].length == walls[j].length == 2\n0 <= rowi, rowj < m\n0 <= coli, colj < n\nAll the positions in guards and walls are unique.",
+        "tags": [
+            "Array",
+            "Matrix",
+            "Simulation"
+        ],
+        "title-slug": "count-unguarded-cells-in-the-grid"
+    },
+    {
+        "leetcode-id": 2258,
+        "title": "Escape the Spreading Fire",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed 2D integer array grid of size m x n which represents a field. Each cell has one of three values:\n\n0 represents grass,\n1 represents fire,\n2 represents a wall that you and fire cannot pass through.\n\nYou are situated in the top-left cell, (0, 0), and you want to travel to the safehouse at the bottom-right cell, (m - 1, n - 1). Every minute, you may move to an adjacent grass cell. After your move, every fire cell will spread to all adjacent cells that are not walls.\nReturn the maximum number of minutes that you can stay in your initial position before moving while still safely reaching the safehouse. If this is impossible, return -1. If you can always reach the safehouse regardless of the minutes stayed, return 10^9.\nNote that even if the fire spreads to the safehouse immediately after you have reached it, it will be counted as safely reaching the safehouse.\nA cell is adjacent to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).",
+        "examples": [
+            "Example 1:\nInput: grid = [[0,2,0,0,0,0,0],[0,0,0,2,2,1,0],[0,2,0,0,1,2,0],[0,0,2,2,2,0,2],[0,0,0,0,0,0,0]]\nOutput: 3\nExplanation: The figure above shows the scenario where you stay in the initial position for 3 minutes.\nYou will still be able to safely reach the safehouse.\nStaying for more than 3 minutes will not allow you to safely reach the safehouse.",
+            "Example 2:\nInput: grid = [[0,0,0,0],[0,1,2,0],[0,2,0,0]]\nOutput: -1\nExplanation: The figure above shows the scenario where you immediately move towards the safehouse.\nFire will spread to any cell you move towards and it is impossible to safely reach the safehouse.\nThus, -1 is returned.",
+            "Example 3:\nInput: grid = [[0,0,0],[2,2,0],[1,2,0]]\nOutput: 1000000000\nExplanation: The figure above shows the initial grid.\nNotice that the fire is contained by walls and you will always be able to safely reach the safehouse.\nThus, 10^9 is returned."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n2 <= m, n <= 300\n4 <= m * n <= 2 * 10^4\ngrid[i][j] is either 0, 1, or 2.\ngrid[0][0] == grid[m - 1][n - 1] == 0",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Breadth-First Search",
+            "Matrix"
+        ],
+        "title-slug": "escape-the-spreading-fire"
+    },
+    {
+        "leetcode-id": 2259,
+        "title": "Remove Digit From Number to Maximize Result",
+        "difficulty": 1,
+        "description": "You are given a string number representing a positive integer and a character digit.\nReturn the resulting string after removing exactly one occurrence of digit from number such that the value of the resulting string in decimal form is maximized. The test cases are generated such that digit occurs at least once in number.",
+        "examples": [
+            "Example 1:\nInput: number = \"123\", digit = \"3\"\nOutput: \"12\"\nExplanation: There is only one '3' in \"123\". After removing '3', the result is \"12\".",
+            "Example 2:\nInput: number = \"1231\", digit = \"1\"\nOutput: \"231\"\nExplanation: We can remove the first '1' to get \"231\" or remove the second '1' to get \"123\".\nSince 231 > 123, we return \"231\".",
+            "Example 3:\nInput: number = \"551\", digit = \"5\"\nOutput: \"51\"\nExplanation: We can remove either the first or second '5' from \"551\".\nBoth result in the string \"51\"."
+        ],
+        "constraints": "Constraints:\n\n2 <= number.length <= 100\nnumber consists of digits from '1' to '9'.\ndigit is a digit from '1' to '9'.\ndigit occurs at least once in number.",
+        "tags": [
+            "String",
+            "Greedy",
+            "Enumeration"
+        ],
+        "title-slug": "remove-digit-from-number-to-maximize-result"
+    },
+    {
+        "leetcode-id": 2260,
+        "title": "Minimum Consecutive Cards to Pick Up",
+        "difficulty": 2,
+        "description": "You are given an integer array cards where cards[i] represents the value of the i^th card. A pair of cards are matching if the cards have the same value.\nReturn the minimum number of consecutive cards you have to pick up to have a pair of matching cards among the picked cards. If it is impossible to have matching cards, return -1.",
+        "examples": [
+            "Example 1:\nInput: cards = [3,4,2,3,4,7]\nOutput: 4\nExplanation: We can pick up the cards [3,4,2,3] which contain a matching pair of cards with value 3. Note that picking up the cards [4,2,3,4] is also optimal.",
+            "Example 2:\nInput: cards = [1,0,5,3]\nOutput: -1\nExplanation: There is no way to pick up a set of consecutive cards that contain a pair of matching cards."
+        ],
+        "constraints": "Constraints:\n\n1 <= cards.length <= 10^5\n0 <= cards[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sliding Window"
+        ],
+        "title-slug": "minimum-consecutive-cards-to-pick-up"
+    },
+    {
+        "leetcode-id": 2261,
+        "title": "K Divisible Elements Subarrays",
+        "difficulty": 2,
+        "description": "Given an integer array nums and two integers k and p, return the number of distinct subarrays, which have at most k elements that are divisible by p.\nTwo arrays nums1 and nums2 are said to be distinct if:\n\nThey are of different lengths, or\nThere exists at least one index i where nums1[i] != nums2[i].\n\nA subarray is defined as a non-empty contiguous sequence of elements in an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,3,3,2,2], k = 2, p = 2\nOutput: 11\nExplanation:\nThe elements at indices 0, 3, and 4 are divisible by p = 2.\nThe 11 distinct subarrays which have at most k = 2 elements divisible by 2 are:\n[2], [2,3], [2,3,3], [2,3,3,2], [3], [3,3], [3,3,2], [3,3,2,2], [3,2], [3,2,2], and [2,2].\nNote that the subarrays [2] and [3] occur more than once in nums, but they should each be counted only once.\nThe subarray [2,3,3,2,2] should not be counted because it has 3 elements that are divisible by 2.",
+            "Example 2:\nInput: nums = [1,2,3,4], k = 4, p = 1\nOutput: 10\nExplanation:\nAll element of nums are divisible by p = 1.\nAlso, every subarray of nums will have at most 4 elements that are divisible by 1.\nSince all subarrays are distinct, the total number of subarrays satisfying all the constraints is 10."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 200\n1 <= nums[i], p <= 200\n1 <= k <= nums.length\n\n\u00a0\nFollow up:\nCan you solve this problem in O(n^2) time complexity?",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Trie",
+            "Rolling Hash",
+            "Hash Function",
+            "Enumeration"
+        ],
+        "title-slug": "k-divisible-elements-subarrays"
+    },
+    {
+        "leetcode-id": 2262,
+        "title": "Total Appeal of A String",
+        "difficulty": 3,
+        "description": "The appeal of a string is the number of distinct characters found in the string.\n\nFor example, the appeal of \"abbca\" is 3 because it has 3 distinct characters: 'a', 'b', and 'c'.\n\nGiven a string s, return the total appeal of all of its substrings.\nA substring is a contiguous sequence of characters within a string.",
+        "examples": [
+            "Example 1:\nInput: s = \"abbca\"\nOutput: 28\nExplanation: The following are the substrings of \"abbca\":\n- Substrings of length 1: \"a\", \"b\", \"b\", \"c\", \"a\" have an appeal of 1, 1, 1, 1, and 1 respectively. The sum is 5.\n- Substrings of length 2: \"ab\", \"bb\", \"bc\", \"ca\" have an appeal of 2, 1, 2, and 2 respectively. The sum is 7.\n- Substrings of length 3: \"abb\", \"bbc\", \"bca\" have an appeal of 2, 2, and 3 respectively. The sum is 7.\n- Substrings of length 4: \"abbc\", \"bbca\" have an appeal of 3 and 3 respectively. The sum is 6.\n- Substrings of length 5: \"abbca\" has an appeal of 3. The sum is 3.\nThe total sum is 5 + 7 + 7 + 6 + 3 = 28.",
+            "Example 2:\nInput: s = \"code\"\nOutput: 20\nExplanation: The following are the substrings of \"code\":\n- Substrings of length 1: \"c\", \"o\", \"d\", \"e\" have an appeal of 1, 1, 1, and 1 respectively. The sum is 4.\n- Substrings of length 2: \"co\", \"od\", \"de\" have an appeal of 2, 2, and 2 respectively. The sum is 6.\n- Substrings of length 3: \"cod\", \"ode\" have an appeal of 3 and 3 respectively. The sum is 6.\n- Substrings of length 4: \"code\" has an appeal of 4. The sum is 4.\nThe total sum is 4 + 6 + 6 + 4 = 20."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of lowercase English letters.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Dynamic Programming"
+        ],
+        "title-slug": "total-appeal-of-a-string"
+    },
+    {
+        "leetcode-id": 2264,
+        "title": "Largest 3-Same-Digit Number in String",
+        "difficulty": 1,
+        "description": "You are given a string num representing a large integer. An integer is good if it meets the following conditions:\n\nIt is a substring of num with length 3.\nIt consists of only one unique digit.\n\nReturn the maximum good integer as a string or an empty string \"\" if no such integer exists.\nNote:\n\nA substring is a contiguous sequence of characters within a string.\nThere may be leading zeroes in num or a good integer.",
+        "examples": [
+            "Example 1:\nInput: num = \"6777133339\"\nOutput: \"777\"\nExplanation: There are two distinct good integers: \"777\" and \"333\".\n\"777\" is the largest, so we return \"777\".",
+            "Example 2:\nInput: num = \"2300019\"\nOutput: \"000\"\nExplanation: \"000\" is the only good integer.",
+            "Example 3:\nInput: num = \"42352338\"\nOutput: \"\"\nExplanation: No substring of length 3 consists of only one unique digit. Therefore, there are no good integers."
+        ],
+        "constraints": "Constraints:\n\n3 <= num.length <= 1000\nnum only consists of digits.",
+        "tags": [
+            "String"
+        ],
+        "title-slug": "largest-3-same-digit-number-in-string"
+    },
+    {
+        "leetcode-id": 2265,
+        "title": "Count Nodes Equal to Average of Subtree",
+        "difficulty": 2,
+        "description": "Given the root of a binary tree, return the number of nodes where the value of the node is equal to the average of the values in its subtree.\nNote:\n\nThe average of n elements is the sum of the n elements divided by n and rounded down to the nearest integer.\nA subtree of root is a tree consisting of root and all of its descendants.",
+        "examples": [
+            "Example 1:\nInput: root = [4,8,5,0,1,null,6]\nOutput: 5\nExplanation: \nFor the node with value 4: The average of its subtree is (4 + 8 + 5 + 0 + 1 + 6) / 6 = 24 / 6 = 4.\nFor the node with value 5: The average of its subtree is (5 + 6) / 2 = 11 / 2 = 5.\nFor the node with value 0: The average of its subtree is 0 / 1 = 0.\nFor the node with value 1: The average of its subtree is 1 / 1 = 1.\nFor the node with value 6: The average of its subtree is 6 / 1 = 6.",
+            "Example 2:\nInput: root = [1]\nOutput: 1\nExplanation: For the node with value 1: The average of its subtree is 1 / 1 = 1."
+        ],
+        "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 1000].\n0 <= Node.val <= 1000",
+        "tags": [
+            "Tree",
+            "Depth-First Search",
+            "Binary Tree"
+        ],
+        "title-slug": "count-nodes-equal-to-average-of-subtree"
+    },
+    {
+        "leetcode-id": 2266,
+        "title": "Count Number of Texts",
+        "difficulty": 2,
+        "description": "Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below.\n\nIn order to add a letter, Alice has to press the key of the corresponding digit i times, where i is the position of the letter in the key.\n\nFor example, to add the letter 's', Alice has to press '7' four times. Similarly, to add the letter 'k', Alice has to press '5' twice.\nNote that the digits '0' and '1' do not map to any letters, so Alice does not use them.\n\nHowever, due to an error in transmission, Bob did not receive Alice's text message but received a string of pressed keys instead.\n\nFor example, when Alice sent the message \"bob\", Bob received the string \"2266622\".\n\nGiven a string pressedKeys representing the string received by Bob, return the total number of possible text messages Alice could have sent.\nSince the answer may be very large, return it modulo 10^9 + 7.",
+        "examples": [
+            "Example 1:\nInput: pressedKeys = \"22233\"\nOutput: 8\nExplanation:\nThe possible text messages Alice could have sent are:\n\"aaadd\", \"abdd\", \"badd\", \"cdd\", \"aaae\", \"abe\", \"bae\", and \"ce\".\nSince there are 8 possible messages, we return 8.",
+            "Example 2:\nInput: pressedKeys = \"222222222222222222222222222222222222\"\nOutput: 82876089\nExplanation:\nThere are 2082876103 possible text messages Alice could have sent.\nSince we need to return the answer modulo 10^9 + 7, we return 2082876103 % (10^9 + 7) = 82876089."
+        ],
+        "constraints": "Constraints:\n\n1 <= pressedKeys.length <= 10^5\npressedKeys only consists of digits from '2' - '9'.",
+        "tags": [
+            "Hash Table",
+            "Math",
+            "String",
+            "Dynamic Programming"
+        ],
+        "title-slug": "count-number-of-texts"
+    },
+    {
+        "leetcode-id": 2267,
+        "title": " Check if There Is a Valid Parentheses String Path",
+        "difficulty": 3,
+        "description": "A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true:\n\nIt is ().\nIt can be written as AB (A concatenated with B), where A and B are valid parentheses strings.\nIt can be written as (A), where A is a valid parentheses string.\n\nYou are given an m x n matrix of parentheses grid. A valid parentheses string path in the grid is a path satisfying all of the following conditions:\n\nThe path starts from the upper left cell (0, 0).\nThe path ends at the bottom-right cell (m - 1, n - 1).\nThe path only ever moves down or right.\nThe resulting parentheses string formed by the path is valid.\n\nReturn true if there exists a valid parentheses string path in the grid. Otherwise, return false.",
+        "examples": [
+            "Example 1:\nInput: grid = [[\"(\",\"(\",\"(\"],[\")\",\"(\",\")\"],[\"(\",\"(\",\")\"],[\"(\",\"(\",\")\"]]\nOutput: true\nExplanation: The above diagram shows two possible paths that form valid parentheses strings.\nThe first path shown results in the valid parentheses string \"()(())\".\nThe second path shown results in the valid parentheses string \"((()))\".\nNote that there may be other valid parentheses string paths.",
+            "Example 2:\nInput: grid = [[\")\",\")\"],[\"(\",\"(\"]]\nOutput: false\nExplanation: The two possible paths form the parentheses strings \"))(\" and \")((\". Since neither of them are valid parentheses strings, we return false."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 100\ngrid[i][j] is either '(' or ')'.",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Matrix"
+        ],
+        "title-slug": "check-if-there-is-a-valid-parentheses-string-path"
+    },
+    {
+        "leetcode-id": 2269,
+        "title": "Find the K-Beauty of a Number",
+        "difficulty": 1,
+        "description": "The k-beauty of an integer num is defined as the number of substrings of num when it is read as a string that meet the following conditions:\n\nIt has a length of k.\nIt is a divisor of num.\n\nGiven integers num and k, return the k-beauty of num.\nNote:\n\nLeading zeros are allowed.\n0 is not a divisor of any value.\n\nA substring is a contiguous sequence of characters in a string.",
+        "examples": [
+            "Example 1:\nInput: num = 240, k = 2\nOutput: 2\nExplanation: The following are the substrings of num of length k:\n- \"24\" from \"240\": 24 is a divisor of 240.\n- \"40\" from \"240\": 40 is a divisor of 240.\nTherefore, the k-beauty is 2.",
+            "Example 2:\nInput: num = 430043, k = 2\nOutput: 2\nExplanation: The following are the substrings of num of length k:\n- \"43\" from \"430043\": 43 is a divisor of 430043.\n- \"30\" from \"430043\": 30 is not a divisor of 430043.\n- \"00\" from \"430043\": 0 is not a divisor of 430043.\n- \"04\" from \"430043\": 4 is not a divisor of 430043.\n- \"43\" from \"430043\": 43 is a divisor of 430043.\nTherefore, the k-beauty is 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= num <= 10^9\n1 <= k <= num.length (taking num as a string)",
+        "tags": [
+            "Math",
+            "String",
+            "Sliding Window"
+        ],
+        "title-slug": "find-the-k-beauty-of-a-number"
+    },
+    {
+        "leetcode-id": 2270,
+        "title": "Number of Ways to Split Array",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums of length n.\nnums contains a valid split at index i if the following are true:\n\nThe sum of the first i + 1 elements is greater than or equal to the sum of the last n - i - 1 elements.\nThere is at least one element to the right of i. That is, 0 <= i < n - 1.\n\nReturn the number of valid splits in nums.",
+        "examples": [
+            "Example 1:\nInput: nums = [10,4,-8,7]\nOutput: 2\nExplanation: \nThere are three ways of splitting nums into two non-empty parts:\n- Split nums at index 0. Then, the first part is [10], and its sum is 10. The second part is [4,-8,7], and its sum is 3. Since 10 >= 3, i = 0 is a valid split.\n- Split nums at index 1. Then, the first part is [10,4], and its sum is 14. The second part is [-8,7], and its sum is -1. Since 14 >= -1, i = 1 is a valid split.\n- Split nums at index 2. Then, the first part is [10,4,-8], and its sum is 6. The second part is [7], and its sum is 7. Since 6 < 7, i = 2 is not a valid split.\nThus, the number of valid splits in nums is 2.",
+            "Example 2:\nInput: nums = [2,3,1,0]\nOutput: 2\nExplanation: \nThere are two valid splits in nums:\n- Split nums at index 1. Then, the first part is [2,3], and its sum is 5. The second part is [1,0], and its sum is 1. Since 5 >= 1, i = 1 is a valid split. \n- Split nums at index 2. Then, the first part is [2,3,1], and its sum is 6. The second part is [0], and its sum is 0. Since 6 >= 0, i = 2 is a valid split."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 10^5\n-10^5 <= nums[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Prefix Sum"
+        ],
+        "title-slug": "number-of-ways-to-split-array"
+    },
+    {
+        "leetcode-id": 2271,
+        "title": "Maximum White Tiles Covered by a Carpet",
+        "difficulty": 2,
+        "description": "You are given a 2D integer array tiles where tiles[i] = [li, ri] represents that every tile j in the range li <= j <= ri is colored white.\nYou are also given an integer carpetLen, the length of a single carpet that can be placed anywhere.\nReturn the maximum number of white tiles that can be covered by the carpet.",
+        "examples": [
+            "Example 1:\nInput: tiles = [[1,5],[10,11],[12,18],[20,25],[30,32]], carpetLen = 10\nOutput: 9\nExplanation: Place the carpet starting on tile 10. \nIt covers 9 white tiles, so we return 9.\nNote that there may be other places where the carpet covers 9 white tiles.\nIt can be shown that the carpet cannot cover more than 9 white tiles.",
+            "Example 2:\nInput: tiles = [[10,11],[1,1]], carpetLen = 2\nOutput: 2\nExplanation: Place the carpet starting on tile 10. \nIt covers 2 white tiles, so we return 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= tiles.length <= 5 * 10^4\ntiles[i].length == 2\n1 <= li <= ri <= 10^9\n1 <= carpetLen <= 10^9\nThe tiles are non-overlapping.",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Greedy",
+            "Sorting",
+            "Prefix Sum"
+        ],
+        "title-slug": "maximum-white-tiles-covered-by-a-carpet"
+    },
+    {
+        "leetcode-id": 2272,
+        "title": "Substring With Largest Variance",
+        "difficulty": 3,
+        "description": "The variance of a string is defined as the largest difference between the number of occurrences of any 2 characters present in the string. Note the two characters may or may not be the same.\nGiven a string s consisting of lowercase English letters only, return the largest variance possible among all substrings of s.\nA substring is a contiguous sequence of characters within a string.",
+        "examples": [
+            "Example 1:\nInput: s = \"aababbb\"\nOutput: 3\nExplanation:\nAll possible variances along with their respective substrings are listed below:\n- Variance 0 for substrings \"a\", \"aa\", \"ab\", \"abab\", \"aababb\", \"ba\", \"b\", \"bb\", and \"bbb\".\n- Variance 1 for substrings \"aab\", \"aba\", \"abb\", \"aabab\", \"ababb\", \"aababbb\", and \"bab\".\n- Variance 2 for substrings \"aaba\", \"ababbb\", \"abbb\", and \"babb\".\n- Variance 3 for substring \"babbb\".\nSince the largest possible variance is 3, we return it.",
+            "Example 2:\nInput: s = \"abcde\"\nOutput: 0\nExplanation:\nNo letter occurs more than once in s, so the variance of every substring is 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^4\ns consists of lowercase English letters.",
+        "tags": [
+            "Array",
+            "Dynamic Programming"
+        ],
+        "title-slug": "substring-with-largest-variance"
+    },
+    {
+        "leetcode-id": 2273,
+        "title": "Find Resultant Array After Removing Anagrams",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed string array words, where words[i] consists of lowercase English letters.\nIn one operation, select any index i such that 0 < i < words.length and words[i - 1] and words[i] are anagrams, and delete words[i] from words. Keep performing this operation as long as you can select an index that satisfies the conditions.\nReturn words after performing all operations. It can be shown that selecting the indices for each operation in any arbitrary order will lead to the same result.\nAn Anagram is a word or phrase formed by rearranging the letters of a different word or phrase using all the original letters exactly once. For example, \"dacb\" is an anagram of \"abdc\".",
+        "examples": [
+            "Example 1:\nInput: words = [\"abba\",\"baba\",\"bbaa\",\"cd\",\"cd\"]\nOutput: [\"abba\",\"cd\"]\nExplanation:\nOne of the ways we can obtain the resultant array is by using the following operations:\n- Since words[2] = \"bbaa\" and words[1] = \"baba\" are anagrams, we choose index 2 and delete words[2].\n  Now words = [\"abba\",\"baba\",\"cd\",\"cd\"].\n- Since words[1] = \"baba\" and words[0] = \"abba\" are anagrams, we choose index 1 and delete words[1].\n  Now words = [\"abba\",\"cd\",\"cd\"].\n- Since words[2] = \"cd\" and words[1] = \"cd\" are anagrams, we choose index 2 and delete words[2].\n  Now words = [\"abba\",\"cd\"].\nWe can no longer perform any operations, so [\"abba\",\"cd\"] is the final answer.",
+            "Example 2:\nInput: words = [\"a\",\"b\",\"c\",\"d\",\"e\"]\nOutput: [\"a\",\"b\",\"c\",\"d\",\"e\"]\nExplanation:\nNo two adjacent strings in words are anagrams of each other, so no operations are performed."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 100\n1 <= words[i].length <= 10\nwords[i] consists of lowercase English letters.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Sorting"
+        ],
+        "title-slug": "find-resultant-array-after-removing-anagrams"
+    },
+    {
+        "leetcode-id": 2274,
+        "title": "Maximum Consecutive Floors Without Special Floors",
+        "difficulty": 2,
+        "description": "Alice manages a company and has rented some floors of a building as office space. Alice has decided some of these floors should be special floors, used for relaxation only.\nYou are given two integers bottom and top, which denote that Alice has rented all the floors from bottom to top (inclusive). You are also given the integer array special, where special[i] denotes a special floor that Alice has designated for relaxation.\nReturn the maximum number of consecutive floors without a special floor.",
+        "examples": [
+            "Example 1:\nInput: bottom = 2, top = 9, special = [4,6]\nOutput: 3\nExplanation: The following are the ranges (inclusive) of consecutive floors without a special floor:\n- (2, 3) with a total amount of 2 floors.\n- (5, 5) with a total amount of 1 floor.\n- (7, 9) with a total amount of 3 floors.\nTherefore, we return the maximum number which is 3 floors.",
+            "Example 2:\nInput: bottom = 6, top = 8, special = [7,6,8]\nOutput: 0\nExplanation: Every floor rented is a special floor, so we return 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= special.length <= 10^5\n1 <= bottom <= special[i] <= top <= 10^9\nAll the values of special are unique.",
+        "tags": [
+            "Array",
+            "Sorting"
+        ],
+        "title-slug": "maximum-consecutive-floors-without-special-floors"
+    },
+    {
+        "leetcode-id": 2275,
+        "title": "Largest Combination With Bitwise AND Greater Than Zero",
+        "difficulty": 2,
+        "description": "The bitwise AND of an array nums is the bitwise AND of all integers in nums.\n\nFor example, for nums = [1, 5, 3], the bitwise AND is equal to 1 & 5 & 3 = 1.\nAlso, for nums = [7], the bitwise AND is 7.\n\nYou are given an array of positive integers candidates. Evaluate the bitwise AND of every combination of numbers of candidates. Each number in candidates may only be used once in each combination.\nReturn the size of the largest combination of candidates with a bitwise AND greater than 0.",
+        "examples": [
+            "Example 1:\nInput: candidates = [16,17,71,62,12,24,14]\nOutput: 4\nExplanation: The combination [16,17,62,24] has a bitwise AND of 16 & 17 & 62 & 24 = 16 > 0.\nThe size of the combination is 4.\nIt can be shown that no combination with a size greater than 4 has a bitwise AND greater than 0.\nNote that more than one combination may have the largest size.\nFor example, the combination [62,12,24,14] has a bitwise AND of 62 & 12 & 24 & 14 = 8 > 0.",
+            "Example 2:\nInput: candidates = [8,8]\nOutput: 2\nExplanation: The largest combination [8,8] has a bitwise AND of 8 & 8 = 8 > 0.\nThe size of the combination is 2, so we return 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= candidates.length <= 10^5\n1 <= candidates[i] <= 10^7",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Bit Manipulation",
+            "Counting"
+        ],
+        "title-slug": "largest-combination-with-bitwise-and-greater-than-zero"
+    },
+    {
+        "leetcode-id": 2276,
+        "title": "Count Integers in Intervals",
+        "difficulty": 3,
+        "description": "Given an empty set of intervals, implement a data structure that can:\n\nAdd an interval to the set of intervals.\nCount the number of integers that are present in at least one interval.\n\nImplement the CountIntervals class:\n\nCountIntervals() Initializes the object with an empty set of intervals.\nvoid add(int left, int right) Adds the interval [left, right] to the set of intervals.\nint count() Returns the number of integers that are present in at least one interval.\n\nNote that an interval [left, right] denotes all the integers x where left <= x <= right.",
+        "examples": [
+            "Example 1:\nInput\n[\"CountIntervals\", \"add\", \"add\", \"count\", \"add\", \"count\"]\n[[], [2, 3], [7, 10], [], [5, 8], []]\nOutput\n[null, null, null, 6, null, 8]\n\nExplanation\nCountIntervals countIntervals = new CountIntervals(); // initialize the object with an empty set of intervals. \ncountIntervals.add(2, 3);  // add [2, 3] to the set of intervals.\ncountIntervals.add(7, 10); // add [7, 10] to the set of intervals.\ncountIntervals.count();    // return 6\n                           // the integers 2 and 3 are present in the interval [2, 3].\n                           // the integers 7, 8, 9, and 10 are present in the interval [7, 10].\ncountIntervals.add(5, 8);  // add [5, 8] to the set of intervals.\ncountIntervals.count();    // return 8\n                           // the integers 2 and 3 are present in the interval [2, 3].\n                           // the integers 5 and 6 are present in the interval [5, 8].\n                           // the integers 7 and 8 are present in the intervals [5, 8] and [7, 10].\n                           // the integers 9 and 10 are present in the interval [7, 10]."
+        ],
+        "constraints": "Constraints:\n\n1 <= left <= right <= 10^9\nAt most 10^5 calls in total will be made to add and count.\nAt least one call will be made to count.",
+        "tags": [
+            "Design",
+            "Segment Tree",
+            "Ordered Set"
+        ],
+        "title-slug": "count-integers-in-intervals"
+    },
+    {
+        "leetcode-id": 2278,
+        "title": "Percentage of Letter in String",
+        "difficulty": 1,
+        "description": "Given a string s and a character letter, return the percentage of characters in s that equal letter rounded down to the nearest whole percent.",
+        "examples": [
+            "Example 1:\nInput: s = \"foobar\", letter = \"o\"\nOutput: 33\nExplanation:\nThe percentage of characters in s that equal the letter 'o' is 2 / 6 * 100% = 33% when rounded down, so we return 33.",
+            "Example 2:\nInput: s = \"jjjj\", letter = \"k\"\nOutput: 0\nExplanation:\nThe percentage of characters in s that equal the letter 'k' is 0%, so we return 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 100\ns consists of lowercase English letters.\nletter is a lowercase English letter.",
+        "tags": [
+            "String"
+        ],
+        "title-slug": "percentage-of-letter-in-string"
+    },
+    {
+        "leetcode-id": 2279,
+        "title": "Maximum Bags With Full Capacity of Rocks",
+        "difficulty": 2,
+        "description": "You have n bags numbered from 0 to n - 1. You are given two 0-indexed integer arrays capacity and rocks. The i^th bag can hold a maximum of capacity[i] rocks and currently contains rocks[i] rocks. You are also given an integer additionalRocks, the number of additional rocks you can place in any of the bags.\nReturn the maximum number of bags that could have full capacity after placing the additional rocks in some bags.",
+        "examples": [
+            "Example 1:\nInput: capacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2\nOutput: 3\nExplanation:\nPlace 1 rock in bag 0 and 1 rock in bag 1.\nThe number of rocks in each bag are now [2,3,4,4].\nBags 0, 1, and 2 have full capacity.\nThere are 3 bags at full capacity, so we return 3.\nIt can be shown that it is not possible to have more than 3 bags at full capacity.\nNote that there may be other ways of placing the rocks that result in an answer of 3.",
+            "Example 2:\nInput: capacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100\nOutput: 3\nExplanation:\nPlace 8 rocks in bag 0 and 2 rocks in bag 2.\nThe number of rocks in each bag are now [10,2,2].\nBags 0, 1, and 2 have full capacity.\nThere are 3 bags at full capacity, so we return 3.\nIt can be shown that it is not possible to have more than 3 bags at full capacity.\nNote that we did not use all of the additional rocks."
+        ],
+        "constraints": "Constraints:\n\nn == capacity.length == rocks.length\n1 <= n <= 5 * 10^4\n1 <= capacity[i] <= 10^9\n0 <= rocks[i] <= capacity[i]\n1 <= additionalRocks <= 10^9",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "maximum-bags-with-full-capacity-of-rocks"
+    },
+    {
+        "leetcode-id": 2280,
+        "title": "Minimum Lines to Represent a Line Chart",
+        "difficulty": 2,
+        "description": "You are given a 2D integer array stockPrices where stockPrices[i] = [dayi, pricei] indicates the price of the stock on day dayi is pricei. A line chart is created from the array by plotting the points on an XY plane with the X-axis representing the day and the Y-axis representing the price and connecting adjacent points. One such example is shown below:\n\nReturn the minimum number of lines needed to represent the line chart.",
+        "examples": [
+            "Example 1:\nInput: stockPrices = [[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]]\nOutput: 3\nExplanation:\nThe diagram above represents the input, with the X-axis representing the day and Y-axis representing the price.\nThe following 3 lines can be drawn to represent the line chart:\n- Line 1 (in red) from (1,7) to (4,4) passing through (1,7), (2,6), (3,5), and (4,4).\n- Line 2 (in blue) from (4,4) to (5,4).\n- Line 3 (in green) from (5,4) to (8,1) passing through (5,4), (6,3), (7,2), and (8,1).\nIt can be shown that it is not possible to represent the line chart using less than 3 lines.",
+            "Example 2:\nInput: stockPrices = [[3,4],[1,2],[7,8],[2,3]]\nOutput: 1\nExplanation:\nAs shown in the diagram above, the line chart can be represented with a single line."
+        ],
+        "constraints": "Constraints:\n\n1 <= stockPrices.length <= 10^5\nstockPrices[i].length == 2\n1 <= dayi, pricei <= 10^9\nAll dayi are distinct.",
+        "tags": [
+            "Array",
+            "Math",
+            "Geometry",
+            "Sorting",
+            "Number Theory"
+        ],
+        "title-slug": "minimum-lines-to-represent-a-line-chart"
+    },
+    {
+        "leetcode-id": 2281,
+        "title": "Sum of Total Strength of Wizards",
+        "difficulty": 3,
+        "description": "As the ruler of a kingdom, you have an army of wizards at your command.\nYou are given a 0-indexed integer array strength, where strength[i] denotes the strength of the i^th wizard. For a contiguous group of wizards (i.e. the wizards' strengths form a subarray of strength), the total strength is defined as the product of the following two values:\n\nThe strength of the weakest wizard in the group.\nThe total of all the individual strengths of the wizards in the group.\n\nReturn the sum of the total strengths of all contiguous groups of wizards. Since the answer may be very large, return it modulo 10^9 + 7.\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: strength = [1,3,1,2]\nOutput: 44\nExplanation: The following are all the contiguous groups of wizards:\n- [1] from [1,3,1,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1\n- [3] from [1,3,1,2] has a total strength of min([3]) * sum([3]) = 3 * 3 = 9\n- [1] from [1,3,1,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1\n- [2] from [1,3,1,2] has a total strength of min([2]) * sum([2]) = 2 * 2 = 4\n- [1,3] from [1,3,1,2] has a total strength of min([1,3]) * sum([1,3]) = 1 * 4 = 4\n- [3,1] from [1,3,1,2] has a total strength of min([3,1]) * sum([3,1]) = 1 * 4 = 4\n- [1,2] from [1,3,1,2] has a total strength of min([1,2]) * sum([1,2]) = 1 * 3 = 3\n- [1,3,1] from [1,3,1,2] has a total strength of min([1,3,1]) * sum([1,3,1]) = 1 * 5 = 5\n- [3,1,2] from [1,3,1,2] has a total strength of min([3,1,2]) * sum([3,1,2]) = 1 * 6 = 6\n- [1,3,1,2] from [1,3,1,2] has a total strength of min([1,3,1,2]) * sum([1,3,1,2]) = 1 * 7 = 7\nThe sum of all the total strengths is 1 + 9 + 1 + 4 + 4 + 4 + 3 + 5 + 6 + 7 = 44.",
+            "Example 2:\nInput: strength = [5,4,6]\nOutput: 213\nExplanation: The following are all the contiguous groups of wizards: \n- [5] from [5,4,6] has a total strength of min([5]) * sum([5]) = 5 * 5 = 25\n- [4] from [5,4,6] has a total strength of min([4]) * sum([4]) = 4 * 4 = 16\n- [6] from [5,4,6] has a total strength of min([6]) * sum([6]) = 6 * 6 = 36\n- [5,4] from [5,4,6] has a total strength of min([5,4]) * sum([5,4]) = 4 * 9 = 36\n- [4,6] from [5,4,6] has a total strength of min([4,6]) * sum([4,6]) = 4 * 10 = 40\n- [5,4,6] from [5,4,6] has a total strength of min([5,4,6]) * sum([5,4,6]) = 4 * 15 = 60\nThe sum of all the total strengths is 25 + 16 + 36 + 36 + 40 + 60 = 213."
+        ],
+        "constraints": "Constraints:\n\n1 <= strength.length <= 10^5\n1 <= strength[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Stack",
+            "Monotonic Stack",
+            "Prefix Sum"
+        ],
+        "title-slug": "sum-of-total-strength-of-wizards"
+    },
+    {
+        "leetcode-id": 2283,
+        "title": "Check if Number Has Equal Digit Count and Digit Value",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed string num of length n consisting of digits.\nReturn true if for every index i in the range 0 <= i < n, the digit i occurs num[i] times in num, otherwise return false.",
+        "examples": [
+            "Example 1:\nInput: num = \"1210\"\nOutput: true\nExplanation:\nnum[0] = '1'. The digit 0 occurs once in num.\nnum[1] = '2'. The digit 1 occurs twice in num.\nnum[2] = '1'. The digit 2 occurs once in num.\nnum[3] = '0'. The digit 3 occurs zero times in num.\nThe condition holds true for every index in \"1210\", so return true.",
+            "Example 2:\nInput: num = \"030\"\nOutput: false\nExplanation:\nnum[0] = '0'. The digit 0 should occur zero times, but actually occurs twice in num.\nnum[1] = '3'. The digit 1 should occur three times, but actually occurs zero times in num.\nnum[2] = '0'. The digit 2 occurs zero times in num.\nThe indices 0 and 1 both violate the condition, so return false."
+        ],
+        "constraints": "Constraints:\n\nn == num.length\n1 <= n <= 10\nnum consists of digits.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Counting"
+        ],
+        "title-slug": "check-if-number-has-equal-digit-count-and-digit-value"
+    },
+    {
+        "leetcode-id": 2284,
+        "title": "Sender With Largest Word Count",
+        "difficulty": 2,
+        "description": "You have a chat log of n messages. You are given two string arrays messages and senders where messages[i] is a message sent by senders[i].\nA message is list of words that are separated by a single space with no leading or trailing spaces. The word count of a sender is the total number of words sent by the sender. Note that a sender may send more than one message.\nReturn the sender with the largest word count. If there is more than one sender with the largest word count, return the one with the lexicographically largest name.\nNote:\n\nUppercase letters come before lowercase letters in lexicographical order.\n\"Alice\" and \"alice\" are distinct.",
+        "examples": [
+            "Example 1:\nInput: messages = [\"Hello userTwooo\",\"Hi userThree\",\"Wonderful day Alice\",\"Nice day userThree\"], senders = [\"Alice\",\"userTwo\",\"userThree\",\"Alice\"]\nOutput: \"Alice\"\nExplanation: Alice sends a total of 2 + 3 = 5 words.\nuserTwo sends a total of 2 words.\nuserThree sends a total of 3 words.\nSince Alice has the largest word count, we return \"Alice\".",
+            "Example 2:\nInput: messages = [\"How is leetcode for everyone\",\"Leetcode is useful for practice\"], senders = [\"Bob\",\"Charlie\"]\nOutput: \"Charlie\"\nExplanation: Bob sends a total of 5 words.\nCharlie sends a total of 5 words.\nSince there is a tie for the largest word count, we return the sender with the lexicographically larger name, Charlie."
+        ],
+        "constraints": "Constraints:\n\nn == messages.length == senders.length\n1 <= n <= 10^4\n1 <= messages[i].length <= 100\n1 <= senders[i].length <= 10\nmessages[i] consists of uppercase and lowercase English letters and ' '.\nAll the words in messages[i] are separated by a single space.\nmessages[i] does not have leading or trailing spaces.\nsenders[i] consists of uppercase and lowercase English letters only.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Counting"
+        ],
+        "title-slug": "sender-with-largest-word-count"
+    },
+    {
+        "leetcode-id": 2285,
+        "title": "Maximum Total Importance of Roads",
+        "difficulty": 2,
+        "description": "You are given an integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1.\nYou are also given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connecting cities ai and bi.\nYou need to assign each city with an integer value from 1 to n, where each value can only be used once. The importance of a road is then defined as the sum of the values of the two cities it connects.\nReturn the maximum total importance of all roads possible after assigning the values optimally.",
+        "examples": [
+            "Example 1:\nInput: n = 5, roads = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]\nOutput: 43\nExplanation: The figure above shows the country and the assigned values of [2,4,5,3,1].\n- The road (0,1) has an importance of 2 + 4 = 6.\n- The road (1,2) has an importance of 4 + 5 = 9.\n- The road (2,3) has an importance of 5 + 3 = 8.\n- The road (0,2) has an importance of 2 + 5 = 7.\n- The road (1,3) has an importance of 4 + 3 = 7.\n- The road (2,4) has an importance of 5 + 1 = 6.\nThe total importance of all roads is 6 + 9 + 8 + 7 + 7 + 6 = 43.\nIt can be shown that we cannot obtain a greater total importance than 43.",
+            "Example 2:\nInput: n = 5, roads = [[0,3],[2,4],[1,3]]\nOutput: 20\nExplanation: The figure above shows the country and the assigned values of [4,3,2,5,1].\n- The road (0,3) has an importance of 4 + 5 = 9.\n- The road (2,4) has an importance of 2 + 1 = 3.\n- The road (1,3) has an importance of 3 + 5 = 8.\nThe total importance of all roads is 9 + 3 + 8 = 20.\nIt can be shown that we cannot obtain a greater total importance than 20."
+        ],
+        "constraints": "Constraints:\n\n2 <= n <= 5 * 10^4\n1 <= roads.length <= 5 * 10^4\nroads[i].length == 2\n0 <= ai, bi <= n - 1\nai != bi\nThere are no duplicate roads.",
+        "tags": [
+            "Greedy",
+            "Graph",
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "maximum-total-importance-of-roads"
+    },
+    {
+        "leetcode-id": 2286,
+        "title": "Booking Concert Tickets in Groups",
+        "difficulty": 3,
+        "description": "A concert hall has n rows numbered from 0 to n - 1, each with m seats, numbered from 0 to m - 1. You need to design a ticketing system that can allocate seats in the following cases:\n\nIf a group of k spectators can sit together in a row.\nIf every member of a group of k spectators can get a seat. They may or may not sit together.\n\nNote that the spectators are very picky. Hence:\n\nThey will book seats only if each member of their group can get a seat with row number less than or equal to maxRow. maxRow can vary from group to group.\nIn case there are multiple rows to choose from, the row with the smallest number is chosen. If there are multiple seats to choose in the same row, the seat with the smallest number is chosen.\n\nImplement the BookMyShow class:\n\nBookMyShow(int n, int m) Initializes the object with n as number of rows and m as number of seats per row.\nint[] gather(int k, int maxRow) Returns an array of length 2 denoting the row and seat number (respectively) of the first seat being allocated to the k members of the group, who must sit together. In other words, it returns the smallest possible r and c such that all [c, c + k - 1] seats are valid and empty in row r, and r <= maxRow. Returns [] in case it is not possible to allocate seats to the group.\nboolean scatter(int k, int maxRow) Returns true if all k members of the group can be allocated seats in rows 0 to maxRow, who may or may not sit together. If the seats can be allocated, it allocates k seats to the group with the smallest row numbers, and the smallest possible seat numbers in each row. Otherwise, returns false.",
+        "examples": [
+            "Example 1:\nInput\n[\"BookMyShow\", \"gather\", \"gather\", \"scatter\", \"scatter\"]\n[[2, 5], [4, 0], [2, 0], [5, 1], [5, 1]]\nOutput\n[null, [0, 0], [], true, false]\n\nExplanation\nBookMyShow bms = new BookMyShow(2, 5); // There are 2 rows with 5 seats each \nbms.gather(4, 0); // return [0, 0]\n                  // The group books seats [0, 3] of row 0. \nbms.gather(2, 0); // return []\n                  // There is only 1 seat left in row 0,\n                  // so it is not possible to book 2 consecutive seats. \nbms.scatter(5, 1); // return True\n                   // The group books seat 4 of row 0 and seats [0, 3] of row 1. \nbms.scatter(5, 1); // return False\n                   // There is only one seat left in the hall."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 5 * 10^4\n1 <= m, k <= 10^9\n0 <= maxRow <= n - 1\nAt most 5 * 10^4 calls in total will be made to gather and scatter.",
+        "tags": [
+            "Binary Search",
+            "Design",
+            "Binary Indexed Tree",
+            "Segment Tree"
+        ],
+        "title-slug": "booking-concert-tickets-in-groups"
+    },
+    {
+        "leetcode-id": 2287,
+        "title": "Rearrange Characters to Make Target String",
+        "difficulty": 1,
+        "description": "You are given two 0-indexed strings s and target. You can take some letters from s and rearrange them to form new strings.\nReturn the maximum number of copies of target that can be formed by taking letters from s and rearranging them.",
+        "examples": [
+            "Example 1:\nInput: s = \"ilovecodingonleetcode\", target = \"code\"\nOutput: 2\nExplanation:\nFor the first copy of \"code\", take the letters at indices 4, 5, 6, and 7.\nFor the second copy of \"code\", take the letters at indices 17, 18, 19, and 20.\nThe strings that are formed are \"ecod\" and \"code\" which can both be rearranged into \"code\".\nWe can make at most two copies of \"code\", so we return 2.",
+            "Example 2:\nInput: s = \"abcba\", target = \"abc\"\nOutput: 1\nExplanation:\nWe can make one copy of \"abc\" by taking the letters at indices 0, 1, and 2.\nWe can make at most one copy of \"abc\", so we return 1.\nNote that while there is an extra 'a' and 'b' at indices 3 and 4, we cannot reuse the letter 'c' at index 2, so we cannot make a second copy of \"abc\".",
+            "Example 3:\nInput: s = \"abbaccaddaeea\", target = \"aaaaa\"\nOutput: 1\nExplanation:\nWe can make one copy of \"aaaaa\" by taking the letters at indices 0, 3, 6, 9, and 12.\nWe can make at most one copy of \"aaaaa\", so we return 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 100\n1 <= target.length <= 10\ns and target consist of lowercase English letters.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Counting"
+        ],
+        "title-slug": "rearrange-characters-to-make-target-string"
+    },
+    {
+        "leetcode-id": 2288,
+        "title": "Apply Discount to Prices",
+        "difficulty": 2,
+        "description": "A sentence is a string of single-space separated words where each word can contain digits, lowercase letters, and the dollar sign '$'. A word represents a price if it is a sequence of digits preceded by a dollar sign.\n\nFor example, \"$100\", \"$23\", and \"$6\" represent prices while \"100\", \"$\", and \"$1e5\" do not.\n\nYou are given a string sentence representing a sentence and an integer discount. For each word representing a price, apply a discount of discount% on the price and update the word in the sentence. All updated prices should be represented with exactly two decimal places.\nReturn a string representing the modified sentence.\nNote that all prices will contain at most 10 digits.",
+        "examples": [
+            "Example 1:\nInput: sentence = \"there are $1 $2 and 5$ candies in the shop\", discount = 50\nOutput: \"there are $0.50 $1.00 and 5$ candies in the shop\"\nExplanation: \nThe words which represent prices are \"$1\" and \"$2\". \n- A 50% discount on \"$1\" yields \"$0.50\", so \"$1\" is replaced by \"$0.50\".\n- A 50% discount on \"$2\" yields \"$1\". Since we need to have exactly 2 decimal places after a price, we replace \"$2\" with \"$1.00\".",
+            "Example 2:\nInput: sentence = \"1 2 $3 4 $5 $6 7 8$ $9 $10$\", discount = 100\nOutput: \"1 2 $0.00 4 $0.00 $0.00 7 8$ $0.00 $10$\"\nExplanation: \nApplying a 100% discount on any price will result in 0.\nThe words representing prices are \"$3\", \"$5\", \"$6\", and \"$9\".\nEach of them is replaced by \"$0.00\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= sentence.length <= 10^5\nsentence consists of lowercase English letters, digits, ' ', and '$'.\nsentence does not have leading or trailing spaces.\nAll words in sentence are separated by a single space.\nAll prices will be positive numbers without leading zeros.\nAll prices will have at most 10 digits.\n0 <= discount <= 100",
+        "tags": [
+            "String"
+        ],
+        "title-slug": "apply-discount-to-prices"
+    },
+    {
+        "leetcode-id": 2289,
+        "title": "Steps to Make Array Non-decreasing",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i - 1] > nums[i] for all 0 < i < nums.length.\nReturn the number of steps performed until nums becomes a non-decreasing array.",
+        "examples": [
+            "Example 1:\nInput: nums = [5,3,4,4,7,3,6,11,8,5,11]\nOutput: 3\nExplanation: The following are the steps performed:\n- Step 1: [5,3,4,4,7,3,6,11,8,5,11] becomes [5,4,4,7,6,11,11]\n- Step 2: [5,4,4,7,6,11,11] becomes [5,4,7,11,11]\n- Step 3: [5,4,7,11,11] becomes [5,7,11,11]\n[5,7,11,11] is a non-decreasing array. Therefore, we return 3.",
+            "Example 2:\nInput: nums = [4,5,7,7,13]\nOutput: 0\nExplanation: nums is already a non-decreasing array. Therefore, we return 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Linked List",
+            "Stack",
+            "Monotonic Stack"
+        ],
+        "title-slug": "steps-to-make-array-non-decreasing"
+    },
+    {
+        "leetcode-id": 2290,
+        "title": "Minimum Obstacle Removal to Reach Corner",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed 2D integer array grid of size m x n. Each cell has one of two values:\n\n0 represents an empty cell,\n1 represents an obstacle that may be removed.\n\nYou can move up, down, left, or right from and to an empty cell.\nReturn the minimum number of obstacles to remove so you can move from the upper left corner (0, 0) to the lower right corner (m - 1, n - 1).",
+        "examples": [
+            "Example 1:\nInput: grid = [[0,1,1],[1,1,0],[1,1,0]]\nOutput: 2\nExplanation: We can remove the obstacles at (0, 1) and (0, 2) to create a path from (0, 0) to (2, 2).\nIt can be shown that we need to remove at least 2 obstacles, so we return 2.\nNote that there may be other ways to remove 2 obstacles to create a path.",
+            "Example 2:\nInput: grid = [[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]]\nOutput: 0\nExplanation: We can move from (0, 0) to (2, 4) without removing any obstacles, so we return 0."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 10^5\n2 <= m * n <= 10^5\ngrid[i][j] is either 0 or 1.\ngrid[0][0] == grid[m - 1][n - 1] == 0",
+        "tags": [
+            "Array",
+            "Breadth-First Search",
+            "Graph",
+            "Heap (Priority Queue)",
+            "Matrix",
+            "Shortest Path"
+        ],
+        "title-slug": "minimum-obstacle-removal-to-reach-corner"
+    },
+    {
+        "leetcode-id": 2293,
+        "title": "Min Max Game",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums whose length is a power of 2.\nApply the following algorithm on nums:\n\nLet n be the length of nums. If n == 1, end the process. Otherwise, create a new 0-indexed integer array newNums of length n / 2.\nFor every even index i where 0 <= i < n / 2, assign the value of newNums[i] as min(nums[2 * i], nums[2 * i + 1]).\nFor every odd index i where 0 <= i < n / 2, assign the value of newNums[i] as max(nums[2 * i], nums[2 * i + 1]).\nReplace the array nums with newNums.\nRepeat the entire process starting from step 1.\n\nReturn the last number that remains in nums after applying the algorithm.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,5,2,4,8,2,2]\nOutput: 1\nExplanation: The following arrays are the results of applying the algorithm repeatedly.\nFirst: nums = [1,5,4,2]\nSecond: nums = [1,4]\nThird: nums = [1]\n1 is the last remaining number, so we return 1.",
+            "Example 2:\nInput: nums = [3]\nOutput: 3\nExplanation: 3 is already the last remaining number, so we return 3."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1024\n1 <= nums[i] <= 10^9\nnums.length is a power of 2.",
+        "tags": [
+            "Array",
+            "Simulation"
+        ],
+        "title-slug": "min-max-game"
+    },
+    {
+        "leetcode-id": 2294,
+        "title": "Partition Array Such That Maximum Difference Is K",
+        "difficulty": 2,
+        "description": "You are given an integer array nums and an integer k. You may partition nums into one or more subsequences such that each element in nums appears in exactly one of the subsequences.\nReturn the minimum number of subsequences needed such that the difference between the maximum and minimum values in each subsequence is at most k.\nA subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,6,1,2,5], k = 2\nOutput: 2\nExplanation:\nWe can partition nums into the two subsequences [3,1,2] and [6,5].\nThe difference between the maximum and minimum value in the first subsequence is 3 - 1 = 2.\nThe difference between the maximum and minimum value in the second subsequence is 6 - 5 = 1.\nSince two subsequences were created, we return 2. It can be shown that 2 is the minimum number of subsequences needed.",
+            "Example 2:\nInput: nums = [1,2,3], k = 1\nOutput: 2\nExplanation:\nWe can partition nums into the two subsequences [1,2] and [3].\nThe difference between the maximum and minimum value in the first subsequence is 2 - 1 = 1.\nThe difference between the maximum and minimum value in the second subsequence is 3 - 3 = 0.\nSince two subsequences were created, we return 2. Note that another optimal solution is to partition nums into the two subsequences [1] and [2,3].",
+            "Example 3:\nInput: nums = [2,2,4,5], k = 0\nOutput: 3\nExplanation:\nWe can partition nums into the three subsequences [2,2], [4], and [5].\nThe difference between the maximum and minimum value in the first subsequences is 2 - 2 = 0.\nThe difference between the maximum and minimum value in the second subsequences is 4 - 4 = 0.\nThe difference between the maximum and minimum value in the third subsequences is 5 - 5 = 0.\nSince three subsequences were created, we return 3. It can be shown that 3 is the minimum number of subsequences needed."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^5\n0 <= k <= 10^5",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "partition-array-such-that-maximum-difference-is-k"
+    },
+    {
+        "leetcode-id": 2295,
+        "title": "Replace Elements in an Array",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array nums that consists of n distinct positive integers. Apply m operations to this array, where in the i^th operation you replace the number operations[i][0] with operations[i][1].\nIt is guaranteed that in the i^th operation:\n\noperations[i][0] exists in nums.\noperations[i][1] does not exist in nums.\n\nReturn the array obtained after applying all the operations.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,4,6], operations = [[1,3],[4,7],[6,1]]\nOutput: [3,2,7,1]\nExplanation: We perform the following operations on nums:\n- Replace the number 1 with 3. nums becomes [3,2,4,6].\n- Replace the number 4 with 7. nums becomes [3,2,7,6].\n- Replace the number 6 with 1. nums becomes [3,2,7,1].\nWe return the final array [3,2,7,1].",
+            "Example 2:\nInput: nums = [1,2], operations = [[1,3],[2,1],[3,2]]\nOutput: [2,1]\nExplanation: We perform the following operations to nums:\n- Replace the number 1 with 3. nums becomes [3,2].\n- Replace the number 2 with 1. nums becomes [3,1].\n- Replace the number 3 with 2. nums becomes [2,1].\nWe return the array [2,1]."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length\nm == operations.length\n1 <= n, m <= 10^5\nAll the values of nums are distinct.\noperations[i].length == 2\n1 <= nums[i], operations[i][0], operations[i][1] <= 10^6\noperations[i][0] will exist in nums when applying the i^th operation.\noperations[i][1] will not exist in nums when applying the i^th operation.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Simulation"
+        ],
+        "title-slug": "replace-elements-in-an-array"
+    },
+    {
+        "leetcode-id": 2296,
+        "title": "Design a Text Editor",
+        "difficulty": 3,
+        "description": "Design a text editor with a cursor that can do the following:\n\nAdd text to where the cursor is.\nDelete text from where the cursor is (simulating the backspace key).\nMove the cursor either left or right.\n\nWhen deleting text, only characters to the left of the cursor will be deleted. The cursor will also remain within the actual text and cannot be moved beyond it. More formally, we have that 0 <= cursor.position <= currentText.length always holds.\nImplement the TextEditor class:\n\nTextEditor() Initializes the object with empty text.\nvoid addText(string text) Appends text to where the cursor is. The cursor ends to the right of text.\nint deleteText(int k) Deletes k characters to the left of the cursor. Returns the number of characters actually deleted.\nstring cursorLeft(int k) Moves the cursor to the left k times. Returns the last min(10, len) characters to the left of the cursor, where len is the number of characters to the left of the cursor.\nstring cursorRight(int k) Moves the cursor to the right k times. Returns the last min(10, len) characters to the left of the cursor, where len is the number of characters to the left of the cursor.",
+        "examples": [
+            "Example 1:\nInput\n[\"TextEditor\", \"addText\", \"deleteText\", \"addText\", \"cursorRight\", \"cursorLeft\", \"deleteText\", \"cursorLeft\", \"cursorRight\"]\n[[], [\"leetcode\"], [4], [\"practice\"], [3], [8], [10], [2], [6]]\nOutput\n[null, null, 4, null, \"etpractice\", \"leet\", 4, \"\", \"practi\"]\n\nExplanation\nTextEditor textEditor = new TextEditor(); // The current text is \"|\". (The '|' character represents the cursor)\ntextEditor.addText(\"leetcode\"); // The current text is \"leetcode|\".\ntextEditor.deleteText(4); // return 4\n                          // The current text is \"leet|\". \n                          // 4 characters were deleted.\ntextEditor.addText(\"practice\"); // The current text is \"leetpractice|\". \ntextEditor.cursorRight(3); // return \"etpractice\"\n                           // The current text is \"leetpractice|\". \n                           // The cursor cannot be moved beyond the actual text and thus did not move.\n                           // \"etpractice\" is the last 10 characters to the left of the cursor.\ntextEditor.cursorLeft(8); // return \"leet\"\n                          // The current text is \"leet|practice\".\n                          // \"leet\" is the last min(10, 4) = 4 characters to the left of the cursor.\ntextEditor.deleteText(10); // return 4\n                           // The current text is \"|practice\".\n                           // Only 4 characters were deleted.\ntextEditor.cursorLeft(2); // return \"\"\n                          // The current text is \"|practice\".\n                          // The cursor cannot be moved beyond the actual text and thus did not move. \n                          // \"\" is the last min(10, 0) = 0 characters to the left of the cursor.\ntextEditor.cursorRight(6); // return \"practi\"\n                           // The current text is \"practi|ce\".\n                           // \"practi\" is the last min(10, 6) = 6 characters to the left of the cursor."
+        ],
+        "constraints": "Constraints:\n\n1 <= text.length, k <= 40\ntext consists of lowercase English letters.\nAt most 2 * 10^4 calls in total will be made to addText, deleteText, cursorLeft and cursorRight.\n\n\u00a0\nFollow-up: Could you find a solution with time complexity of O(k) per call?",
+        "tags": [
+            "Linked List",
+            "String",
+            "Stack",
+            "Design",
+            "Simulation",
+            "Doubly-Linked List"
+        ],
+        "title-slug": "design-a-text-editor"
+    },
+    {
+        "leetcode-id": 2299,
+        "title": "Strong Password Checker II",
+        "difficulty": 1,
+        "description": "A password is said to be strong if it satisfies all the following criteria:\n\nIt has at least 8 characters.\nIt contains at least one lowercase letter.\nIt contains at least one uppercase letter.\nIt contains at least one digit.\nIt contains at least one special character. The special characters are the characters in the following string: \"!@#$%^&*()-+\".\nIt does not contain 2 of the same character in adjacent positions (i.e., \"aab\" violates this condition, but \"aba\" does not).\n\nGiven a string password, return true if it is a strong password. Otherwise, return false.",
+        "examples": [
+            "Example 1:\nInput: password = \"IloveLe3tcode!\"\nOutput: true\nExplanation: The password meets all the requirements. Therefore, we return true.",
+            "Example 2:\nInput: password = \"Me+You--IsMyDream\"\nOutput: false\nExplanation: The password does not contain a digit and also contains 2 of the same character in adjacent positions. Therefore, we return false.",
+            "Example 3:\nInput: password = \"1aB!\"\nOutput: false\nExplanation: The password does not meet the length requirement. Therefore, we return false."
+        ],
+        "constraints": "Constraints:\n\n1 <= password.length <= 100\npassword consists of letters, digits, and special characters: \"!@#$%^&*()-+\".",
+        "tags": [
+            "String"
+        ],
+        "title-slug": "strong-password-checker-ii"
+    },
+    {
+        "leetcode-id": 2300,
+        "title": "Successful Pairs of Spells and Potions",
+        "difficulty": 2,
+        "description": "You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the i^th spell and potions[j] represents the strength of the j^th potion.\nYou are also given an integer success. A spell and potion pair is considered successful if the product of their strengths is at least success.\nReturn an integer array pairs of length n where pairs[i] is the number of potions that will form a successful pair with the i^th spell.",
+        "examples": [
+            "Example 1:\nInput: spells = [5,1,3], potions = [1,2,3,4,5], success = 7\nOutput: [4,0,3]\nExplanation:\n- 0^th spell: 5 * [1,2,3,4,5] = [5,10,15,20,25]. 4 pairs are successful.\n- 1^st spell: 1 * [1,2,3,4,5] = [1,2,3,4,5]. 0 pairs are successful.\n- 2^nd spell: 3 * [1,2,3,4,5] = [3,6,9,12,15]. 3 pairs are successful.\nThus, [4,0,3] is returned.",
+            "Example 2:\nInput: spells = [3,1,2], potions = [8,5,8], success = 16\nOutput: [2,0,2]\nExplanation:\n- 0^th spell: 3 * [8,5,8] = [24,15,24]. 2 pairs are successful.\n- 1^st spell: 1 * [8,5,8] = [8,5,8]. 0 pairs are successful. \n- 2^nd spell: 2 * [8,5,8] = [16,10,16]. 2 pairs are successful. \nThus, [2,0,2] is returned."
+        ],
+        "constraints": "Constraints:\n\nn == spells.length\nm == potions.length\n1 <= n, m <= 10^5\n1 <= spells[i], potions[i] <= 10^5\n1 <= success <= 10^10",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Binary Search",
+            "Sorting"
+        ],
+        "title-slug": "successful-pairs-of-spells-and-potions"
+    },
+    {
+        "leetcode-id": 2301,
+        "title": "Match Substring After Replacement",
+        "difficulty": 3,
+        "description": "You are given two strings s and sub. You are also given a 2D character array mappings where mappings[i] = [oldi, newi] indicates that you may perform the following operation any number of times:\n\nReplace a character oldi of sub with newi.\n\nEach character in sub cannot be replaced more than once.\nReturn true if it is possible to make sub a substring of s by replacing zero or more characters according to mappings. Otherwise, return false.\nA substring is a contiguous non-empty sequence of characters within a string.",
+        "examples": [
+            "Example 1:\nInput: s = \"fool3e7bar\", sub = \"leet\", mappings = [[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"]]\nOutput: true\nExplanation: Replace the first 'e' in sub with '3' and 't' in sub with '7'.\nNow sub = \"l3e7\" is a substring of s, so we return true.",
+            "Example 2:\nInput: s = \"fooleetbar\", sub = \"f00l\", mappings = [[\"o\",\"0\"]]\nOutput: false\nExplanation: The string \"f00l\" is not a substring of s and no replacements can be made.\nNote that we cannot replace '0' with 'o'.",
+            "Example 3:\nInput: s = \"Fool33tbaR\", sub = \"leetd\", mappings = [[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"],[\"d\",\"b\"],[\"p\",\"b\"]]\nOutput: true\nExplanation: Replace the first and second 'e' in sub with '3' and 'd' in sub with 'b'.\nNow sub = \"l33tb\" is a substring of s, so we return true."
+        ],
+        "constraints": "Constraints:\n\n1 <= sub.length <= s.length <= 5000\n0 <= mappings.length <= 1000\nmappings[i].length == 2\noldi != newi\ns and sub consist of uppercase and lowercase English letters and digits.\noldi and newi are either uppercase or lowercase English letters or digits.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "String Matching"
+        ],
+        "title-slug": "match-substring-after-replacement"
+    },
+    {
+        "leetcode-id": 2302,
+        "title": "Count Subarrays With Score Less Than K",
+        "difficulty": 3,
+        "description": "The score of an array is defined as the product of its sum and its length.\n\nFor example, the score of [1, 2, 3, 4, 5] is (1 + 2 + 3 + 4 + 5) * 5 = 75.\n\nGiven a positive integer array nums and an integer k, return the number of non-empty subarrays of nums whose score is strictly less than k.\nA subarray is a contiguous sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,1,4,3,5], k = 10\nOutput: 6\nExplanation:\nThe 6 subarrays having scores less than 10 are:\n- [2] with score 2 * 1 = 2.\n- [1] with score 1 * 1 = 1.\n- [4] with score 4 * 1 = 4.\n- [3] with score 3 * 1 = 3. \n- [5] with score 5 * 1 = 5.\n- [2,1] with score (2 + 1) * 2 = 6.\nNote that subarrays such as [1,4] and [4,3,5] are not considered because their scores are 10 and 36 respectively, while we need scores strictly less than 10.",
+            "Example 2:\nInput: nums = [1,1,1], k = 5\nOutput: 5\nExplanation:\nEvery subarray except [1,1,1] has a score less than 5.\n[1,1,1] has a score (1 + 1 + 1) * 3 = 9, which is greater than 5.\nThus, there are 5 subarrays having scores less than 5."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^5\n1 <= k <= 10^15",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Sliding Window",
+            "Prefix Sum"
+        ],
+        "title-slug": "count-subarrays-with-score-less-than-k"
+    },
+    {
+        "leetcode-id": 2303,
+        "title": "Calculate Amount Paid in Taxes",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed 2D integer array brackets where brackets[i] = [upperi, percenti] means that the i^th tax bracket has an upper bound of upperi and is taxed at a rate of percenti. The brackets are sorted by upper bound (i.e. upperi-1 < upperi for 0 < i < brackets.length).\nTax is calculated as follows:\n\nThe first upper0 dollars earned are taxed at a rate of percent0.\nThe next upper1 - upper0 dollars earned are taxed at a rate of percent1.\nThe next upper2 - upper1 dollars earned are taxed at a rate of percent2.\nAnd so on.\n\nYou are given an integer income representing the amount of money you earned. Return the amount of money that you have to pay in taxes. Answers within 10^-5 of the actual answer will be accepted.",
+        "examples": [
+            "Example 1:\nInput: brackets = [[3,50],[7,10],[12,25]], income = 10\nOutput: 2.65000\nExplanation:\nBased on your income, you have 3 dollars in the 1^st tax bracket, 4 dollars in the 2^nd tax bracket, and 3 dollars in the 3^rd tax bracket.\nThe tax rate for the three tax brackets is 50%, 10%, and 25%, respectively.\nIn total, you pay $3 * 50% + $4 * 10% + $3 * 25% = $2.65 in taxes.",
+            "Example 2:\nInput: brackets = [[1,0],[4,25],[5,50]], income = 2\nOutput: 0.25000\nExplanation:\nBased on your income, you have 1 dollar in the 1^st tax bracket and 1 dollar in the 2^nd tax bracket.\nThe tax rate for the two tax brackets is 0% and 25%, respectively.\nIn total, you pay $1 * 0% + $1 * 25% = $0.25 in taxes.",
+            "Example 3:\nInput: brackets = [[2,50]], income = 0\nOutput: 0.00000\nExplanation:\nYou have no income to tax, so you have to pay a total of $0 in taxes."
+        ],
+        "constraints": "Constraints:\n\n1 <= brackets.length <= 100\n1 <= upperi <= 1000\n0 <= percenti <= 100\n0 <= income <= 1000\nupperi is sorted in ascending order.\nAll the values of upperi are unique.\nThe upper bound of the last tax bracket is greater than or equal to income.",
+        "tags": [
+            "Array",
+            "Simulation"
+        ],
+        "title-slug": "calculate-amount-paid-in-taxes"
+    },
+    {
+        "leetcode-id": 2304,
+        "title": "Minimum Path Cost in a Grid",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed m x n integer matrix grid consisting of distinct integers from 0 to m * n - 1. You can move in this matrix from a cell to any other cell in the next row. That is, if you are in cell (x, y) such that x < m - 1, you can move to any of the cells (x + 1, 0), (x + 1, 1), ..., (x + 1, n - 1). Note that it is not possible to move from cells in the last row.\nEach possible move has a cost given by a 0-indexed 2D array moveCost of size (m * n) x n, where moveCost[i][j] is the cost of moving from a cell with value i to a cell in column j of the next row. The cost of moving from cells in the last row of grid can be ignored.\nThe cost of a path in grid is the sum of all values of cells visited plus the sum of costs of all the moves made. Return the minimum cost of a path that starts from any cell in the first row and ends at any cell in the last row.",
+        "examples": [
+            "Example 1:\nInput: grid = [[5,3],[4,0],[2,1]], moveCost = [[9,8],[1,5],[10,12],[18,6],[2,4],[14,3]]\nOutput: 17\nExplanation: The path with the minimum possible cost is the path 5 -> 0 -> 1.\n- The sum of the values of cells visited is 5 + 0 + 1 = 6.\n- The cost of moving from 5 to 0 is 3.\n- The cost of moving from 0 to 1 is 8.\nSo the total cost of the path is 6 + 3 + 8 = 17.",
+            "Example 2:\nInput: grid = [[5,1,2],[4,0,3]], moveCost = [[12,10,15],[20,23,8],[21,7,1],[8,1,13],[9,10,25],[5,3,2]]\nOutput: 6\nExplanation: The path with the minimum possible cost is the path 2 -> 3.\n- The sum of the values of cells visited is 2 + 3 = 5.\n- The cost of moving from 2 to 3 is 1.\nSo the total cost of this path is 5 + 1 = 6."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n2 <= m, n <= 50\ngrid consists of distinct integers from 0 to m * n - 1.\nmoveCost.length == m * n\nmoveCost[i].length == n\n1 <= moveCost[i][j] <= 100",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Matrix"
+        ],
+        "title-slug": "minimum-path-cost-in-a-grid"
+    },
+    {
+        "leetcode-id": 2305,
+        "title": "Fair Distribution of Cookies",
+        "difficulty": 2,
+        "description": "You are given an integer array cookies, where cookies[i] denotes the number of cookies in the i^th bag. You are also given an integer k that denotes the number of children to distribute all the bags of cookies to. All the cookies in the same bag must go to the same child and cannot be split up.\nThe unfairness of a distribution is defined as the maximum total cookies obtained by a single child in the distribution.\nReturn the minimum unfairness of all distributions.",
+        "examples": [
+            "Example 1:\nInput: cookies = [8,15,10,20,8], k = 2\nOutput: 31\nExplanation: One optimal distribution is [8,15,8] and [10,20]\n- The 1^st child receives [8,15,8] which has a total of 8 + 15 + 8 = 31 cookies.\n- The 2^nd child receives [10,20] which has a total of 10 + 20 = 30 cookies.\nThe unfairness of the distribution is max(31,30) = 31.\nIt can be shown that there is no distribution with an unfairness less than 31.",
+            "Example 2:\nInput: cookies = [6,1,3,2,2,4,1,2], k = 3\nOutput: 7\nExplanation: One optimal distribution is [6,1], [3,2,2], and [4,1,2]\n- The 1^st child receives [6,1] which has a total of 6 + 1 = 7 cookies.\n- The 2^nd child receives [3,2,2] which has a total of 3 + 2 + 2 = 7 cookies.\n- The 3^rd child receives [4,1,2] which has a total of 4 + 1 + 2 = 7 cookies.\nThe unfairness of the distribution is max(7,7,7) = 7.\nIt can be shown that there is no distribution with an unfairness less than 7."
+        ],
+        "constraints": "Constraints:\n\n2 <= cookies.length <= 8\n1 <= cookies[i] <= 10^5\n2 <= k <= cookies.length",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Backtracking",
+            "Bit Manipulation",
+            "Bitmask"
+        ],
+        "title-slug": "fair-distribution-of-cookies"
+    },
+    {
+        "leetcode-id": 2306,
+        "title": "Naming a Company",
+        "difficulty": 3,
+        "description": "You are given an array of strings ideas that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:\n\nChoose 2 distinct names from ideas, call them ideaA and ideaB.\nSwap the first letters of ideaA and ideaB with each other.\nIf both of the new names are not found in the original ideas, then the name ideaA ideaB (the concatenation of ideaA and ideaB, separated by a space) is a valid company name.\nOtherwise, it is not a valid name.\n\nReturn the number of distinct valid names for the company.",
+        "examples": [
+            "Example 1:\nInput: ideas = [\"coffee\",\"donuts\",\"time\",\"toffee\"]\nOutput: 6\nExplanation: The following selections are valid:\n- (\"coffee\", \"donuts\"): The company name created is \"doffee conuts\".\n- (\"donuts\", \"coffee\"): The company name created is \"conuts doffee\".\n- (\"donuts\", \"time\"): The company name created is \"tonuts dime\".\n- (\"donuts\", \"toffee\"): The company name created is \"tonuts doffee\".\n- (\"time\", \"donuts\"): The company name created is \"dime tonuts\".\n- (\"toffee\", \"donuts\"): The company name created is \"doffee tonuts\".\nTherefore, there are a total of 6 distinct company names.\n\nThe following are some examples of invalid selections:\n- (\"coffee\", \"time\"): The name \"toffee\" formed after swapping already exists in the original array.\n- (\"time\", \"toffee\"): Both names are still the same after swapping and exist in the original array.\n- (\"coffee\", \"toffee\"): Both names formed after swapping already exist in the original array.",
+            "Example 2:\nInput: ideas = [\"lack\",\"back\"]\nOutput: 0\nExplanation: There are no valid selections. Therefore, 0 is returned."
+        ],
+        "constraints": "Constraints:\n\n2 <= ideas.length <= 5 * 10^4\n1 <= ideas[i].length <= 10\nideas[i] consists of lowercase English letters.\nAll the strings in ideas are unique.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Bit Manipulation",
+            "Enumeration"
+        ],
+        "title-slug": "naming-a-company"
+    },
+    {
+        "leetcode-id": 2309,
+        "title": "Greatest English Letter in Upper and Lower Case",
+        "difficulty": 1,
+        "description": "Given a string of English letters s, return the greatest English letter which occurs as both a lowercase and uppercase letter in s. The returned letter should be in uppercase. If no such letter exists, return an empty string.\nAn English letter b is greater than another letter a if b appears after a in the English alphabet.",
+        "examples": [
+            "Example 1:\nInput: s = \"lEeTcOdE\"\nOutput: \"E\"\nExplanation:\nThe letter 'E' is the only letter to appear in both lower and upper case.",
+            "Example 2:\nInput: s = \"arRAzFif\"\nOutput: \"R\"\nExplanation:\nThe letter 'R' is the greatest letter to appear in both lower and upper case.\nNote that 'A' and 'F' also appear in both lower and upper case, but 'R' is greater than 'F' or 'A'.",
+            "Example 3:\nInput: s = \"AbCdEfGhIjK\"\nOutput: \"\"\nExplanation:\nThere is no letter that appears in both lower and upper case."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns consists of lowercase and uppercase English letters.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Enumeration"
+        ],
+        "title-slug": "greatest-english-letter-in-upper-and-lower-case"
+    },
+    {
+        "leetcode-id": 2310,
+        "title": "Sum of Numbers With Units Digit K",
+        "difficulty": 2,
+        "description": "Given two integers num and k, consider a set of positive integers with the following properties:\n\nThe units digit of each integer is k.\nThe sum of the integers is num.\n\nReturn the minimum possible size of such a set, or -1 if no such set exists.\nNote:\n\nThe set can contain multiple instances of the same integer, and the sum of an empty set is considered 0.\nThe units digit of a number is the rightmost digit of the number.",
+        "examples": [
+            "Example 1:\nInput: num = 58, k = 9\nOutput: 2\nExplanation:\nOne valid set is [9,49], as the sum is 58 and each integer has a units digit of 9.\nAnother valid set is [19,39].\nIt can be shown that 2 is the minimum possible size of a valid set.",
+            "Example 2:\nInput: num = 37, k = 2\nOutput: -1\nExplanation: It is not possible to obtain a sum of 37 using only integers that have a units digit of 2.",
+            "Example 3:\nInput: num = 0, k = 7\nOutput: 0\nExplanation: The sum of an empty set is considered 0."
+        ],
+        "constraints": "Constraints:\n\n0 <= num <= 3000\n0 <= k <= 9",
+        "tags": [
+            "Math",
+            "Dynamic Programming",
+            "Greedy",
+            "Enumeration"
+        ],
+        "title-slug": "sum-of-numbers-with-units-digit-k"
+    },
+    {
+        "leetcode-id": 2311,
+        "title": "Longest Binary Subsequence Less Than or Equal to K",
+        "difficulty": 2,
+        "description": "You are given a binary string s and a positive integer k.\nReturn the length of the longest subsequence of s that makes up a binary number less than or equal to k.\nNote:\n\nThe subsequence can contain leading zeroes.\nThe empty string is considered to be equal to 0.\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.",
+        "examples": [
+            "Example 1:\nInput: s = \"1001010\", k = 5\nOutput: 5\nExplanation: The longest subsequence of s that makes up a binary number less than or equal to 5 is \"00010\", as this number is equal to 2 in decimal.\nNote that \"00100\" and \"00101\" are also possible, which are equal to 4 and 5 in decimal, respectively.\nThe length of this subsequence is 5, so 5 is returned.",
+            "Example 2:\nInput: s = \"00101001\", k = 1\nOutput: 6\nExplanation: \"000001\" is the longest subsequence of s that makes up a binary number less than or equal to 1, as this number is equal to 1 in decimal.\nThe length of this subsequence is 6, so 6 is returned."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns[i] is either '0' or '1'.\n1 <= k <= 10^9",
+        "tags": [
+            "String",
+            "Dynamic Programming",
+            "Greedy",
+            "Memoization"
+        ],
+        "title-slug": "longest-binary-subsequence-less-than-or-equal-to-k"
+    },
+    {
+        "leetcode-id": 2312,
+        "title": "Selling Pieces of Wood",
+        "difficulty": 3,
+        "description": "You are given two integers m and n that represent the height and width of a rectangular piece of wood. You are also given a 2D integer array prices, where prices[i] = [hi, wi, pricei] indicates you can sell a rectangular piece of wood of height hi and width wi for pricei dollars.\nTo cut a piece of wood, you must make a vertical or horizontal cut across the entire height or width of the piece to split it into two smaller pieces. After cutting a piece of wood into some number of smaller pieces, you can sell pieces according to prices. You may sell multiple pieces of the same shape, and you do not have to sell all the shapes. The grain of the wood makes a difference, so you cannot rotate a piece to swap its height and width.\nReturn the maximum money you can earn after cutting an m x n piece of wood.\nNote that you can cut the piece of wood as many times as you want.",
+        "examples": [
+            "Example 1:\nInput: m = 3, n = 5, prices = [[1,4,2],[2,2,7],[2,1,3]]\nOutput: 19\nExplanation: The diagram above shows a possible scenario. It consists of:\n- 2 pieces of wood shaped 2 x 2, selling for a price of 2 * 7 = 14.\n- 1 piece of wood shaped 2 x 1, selling for a price of 1 * 3 = 3.\n- 1 piece of wood shaped 1 x 4, selling for a price of 1 * 2 = 2.\nThis obtains a total of 14 + 3 + 2 = 19 money earned.\nIt can be shown that 19 is the maximum amount of money that can be earned.",
+            "Example 2:\nInput: m = 4, n = 6, prices = [[3,2,10],[1,4,2],[4,1,3]]\nOutput: 32\nExplanation: The diagram above shows a possible scenario. It consists of:\n- 3 pieces of wood shaped 3 x 2, selling for a price of 3 * 10 = 30.\n- 1 piece of wood shaped 1 x 4, selling for a price of 1 * 2 = 2.\nThis obtains a total of 30 + 2 = 32 money earned.\nIt can be shown that 32 is the maximum amount of money that can be earned.\nNotice that we cannot rotate the 1 x 4 piece of wood to obtain a 4 x 1 piece of wood."
+        ],
+        "constraints": "Constraints:\n\n1 <= m, n <= 200\n1 <= prices.length <= 2 * 10^4\nprices[i].length == 3\n1 <= hi <= m\n1 <= wi <= n\n1 <= pricei <= 10^6\nAll the shapes of wood (hi, wi) are pairwise distinct.",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Memoization"
+        ],
+        "title-slug": "selling-pieces-of-wood"
+    },
+    {
+        "leetcode-id": 2315,
+        "title": "Count Asterisks",
+        "difficulty": 1,
+        "description": "You are given a string s, where every two consecutive vertical bars '|' are grouped into a pair. In other words, the 1^st and 2^nd '|' make a pair, the 3^rd and 4^th '|' make a pair, and so forth.\nReturn the number of '*' in s, excluding the '*' between each pair of '|'.\nNote that each '|' will belong to exactly one pair.",
+        "examples": [
+            "Example 1:\nInput: s = \"l|*e*et|c**o|*de|\"\nOutput: 2\nExplanation: The considered characters are underlined: \"l|*e*et|c**o|*de|\".\nThe characters between the first and second '|' are excluded from the answer.\nAlso, the characters between the third and fourth '|' are excluded from the answer.\nThere are 2 asterisks considered. Therefore, we return 2.",
+            "Example 2:\nInput: s = \"iamprogrammer\"\nOutput: 0\nExplanation: In this example, there are no asterisks in s. Therefore, we return 0.",
+            "Example 3:\nInput: s = \"yo|uar|e**|b|e***au|tifu|l\"\nOutput: 5\nExplanation: The considered characters are underlined: \"yo|uar|e**|b|e***au|tifu|l\". There are 5 asterisks considered. Therefore, we return 5."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns consists of lowercase English letters, vertical bars '|', and asterisks '*'.\ns contains an even number of vertical bars '|'.",
+        "tags": [
+            "String"
+        ],
+        "title-slug": "count-asterisks"
+    },
+    {
+        "leetcode-id": 2316,
+        "title": "Count Unreachable Pairs of Nodes in an Undirected Graph",
+        "difficulty": 2,
+        "description": "You are given an integer n. There is an undirected graph with n nodes, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.\nReturn the number of pairs of different nodes that are unreachable from each other.",
+        "examples": [
+            "Example 1:\nInput: n = 3, edges = [[0,1],[0,2],[1,2]]\nOutput: 0\nExplanation: There are no pairs of nodes that are unreachable from each other. Therefore, we return 0.",
+            "Example 2:\nInput: n = 7, edges = [[0,2],[0,5],[2,4],[1,6],[5,4]]\nOutput: 14\nExplanation: There are 14 pairs of nodes that are unreachable from each other:\n[[0,1],[0,3],[0,6],[1,2],[1,3],[1,4],[1,5],[2,3],[2,6],[3,4],[3,5],[3,6],[4,6],[5,6]].\nTherefore, we return 14."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^5\n0 <= edges.length <= 2 * 10^5\nedges[i].length == 2\n0 <= ai, bi < n\nai != bi\nThere are no repeated edges.",
+        "tags": [
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Union Find",
+            "Graph"
+        ],
+        "title-slug": "count-unreachable-pairs-of-nodes-in-an-undirected-graph"
+    },
+    {
+        "leetcode-id": 2317,
+        "title": "Maximum XOR After Operations ",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums. In one operation, select any non-negative integer x and an index i, then update nums[i] to be equal to nums[i] AND (nums[i] XOR x).\nNote that AND is the bitwise AND operation and XOR is the bitwise XOR operation.\nReturn the maximum possible bitwise XOR of all elements of nums after applying the operation any number of times.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,2,4,6]\nOutput: 7\nExplanation: Apply the operation with x = 4 and i = 3, num[3] = 6 AND (6 XOR 4) = 6 AND 2 = 2.\nNow, nums = [3, 2, 4, 2] and the bitwise XOR of all the elements = 3 XOR 2 XOR 4 XOR 2 = 7.\nIt can be shown that 7 is the maximum possible bitwise XOR.\nNote that other operations may be used to achieve a bitwise XOR of 7.",
+            "Example 2:\nInput: nums = [1,2,3,9,2]\nOutput: 11\nExplanation: Apply the operation zero times.\nThe bitwise XOR of all the elements = 1 XOR 2 XOR 3 XOR 9 XOR 2 = 11.\nIt can be shown that 11 is the maximum possible bitwise XOR."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^8",
+        "tags": [
+            "Array",
+            "Math",
+            "Bit Manipulation"
+        ],
+        "title-slug": "maximum-xor-after-operations"
+    },
+    {
+        "leetcode-id": 2318,
+        "title": "Number of Distinct Roll Sequences",
+        "difficulty": 3,
+        "description": "You are given an integer n. You roll a fair 6-sided dice n times. Determine the total number of distinct sequences of rolls possible such that the following conditions are satisfied:\n\nThe greatest common divisor of any adjacent values in the sequence is equal to 1.\nThere is at least a gap of 2 rolls between equal valued rolls. More formally, if the value of the i^th roll is equal to the value of the j^th roll, then abs(i - j) > 2.\n\nReturn the total number of distinct sequences possible. Since the answer may be very large, return it modulo 10^9 + 7.\nTwo sequences are considered distinct if at least one element is different.",
+        "examples": [
+            "Example 1:\nInput: n = 4\nOutput: 184\nExplanation: Some of the possible sequences are (1, 2, 3, 4), (6, 1, 2, 3), (1, 2, 3, 1), etc.\nSome invalid sequences are (1, 2, 1, 3), (1, 2, 3, 6).\n(1, 2, 1, 3) is invalid since the first and third roll have an equal value and abs(1 - 3) = 2 (i and j are 1-indexed).\n(1, 2, 3, 6) is invalid since the greatest common divisor of 3 and 6 = 3.\nThere are a total of 184 distinct sequences possible, so we return 184.",
+            "Example 2:\nInput: n = 2\nOutput: 22\nExplanation: Some of the possible sequences are (1, 2), (2, 1), (3, 2).\nSome invalid sequences are (3, 6), (2, 4) since the greatest common divisor is not equal to 1.\nThere are a total of 22 distinct sequences possible, so we return 22."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^4",
+        "tags": [
+            "Dynamic Programming",
+            "Memoization"
+        ],
+        "title-slug": "number-of-distinct-roll-sequences"
+    },
+    {
+        "leetcode-id": 2319,
+        "title": "Check if Matrix Is X-Matrix",
+        "difficulty": 1,
+        "description": "A square matrix is said to be an X-Matrix if both of the following conditions hold:\n\nAll the elements in the diagonals of the matrix are non-zero.\nAll other elements are 0.\n\nGiven a 2D integer array grid of size n x n representing a square matrix, return true if grid is an X-Matrix. Otherwise, return false.",
+        "examples": [
+            "Example 1:\nInput: grid = [[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]]\nOutput: true\nExplanation: Refer to the diagram above. \nAn X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0.\nThus, grid is an X-Matrix.",
+            "Example 2:\nInput: grid = [[5,7,0],[0,3,1],[0,5,0]]\nOutput: false\nExplanation: Refer to the diagram above.\nAn X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0.\nThus, grid is not an X-Matrix."
+        ],
+        "constraints": "Constraints:\n\nn == grid.length == grid[i].length\n3 <= n <= 100\n0 <= grid[i][j] <= 10^5",
+        "tags": [
+            "Array",
+            "Matrix"
+        ],
+        "title-slug": "check-if-matrix-is-x-matrix"
+    },
+    {
+        "leetcode-id": 2320,
+        "title": "Count Number of Ways to Place Houses",
+        "difficulty": 2,
+        "description": "There is a street with n * 2 plots, where there are n plots on each side of the street. The plots on each side are numbered from 1 to n. On each plot, a house can be placed.\nReturn the number of ways houses can be placed such that no two houses are adjacent to each other on the same side of the street. Since the answer may be very large, return it modulo 10^9 + 7.\nNote that if a house is placed on the i^th plot on one side of the street, a house can also be placed on the i^th plot on the other side of the street.",
+        "examples": [
+            "Example 1:\nInput: n = 1\nOutput: 4\nExplanation: \nPossible arrangements:\n1. All plots are empty.\n2. A house is placed on one side of the street.\n3. A house is placed on the other side of the street.\n4. Two houses are placed, one on each side of the street.",
+            "Example 2:\nInput: n = 2\nOutput: 9\nExplanation: The 9 possible arrangements are shown in the diagram above."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^4",
+        "tags": [
+            "Dynamic Programming"
+        ],
+        "title-slug": "count-number-of-ways-to-place-houses"
+    },
+    {
+        "leetcode-id": 2321,
+        "title": "Maximum Score Of Spliced Array",
+        "difficulty": 3,
+        "description": "You are given two 0-indexed integer arrays nums1 and nums2, both of length n.\nYou can choose two integers left and right where 0 <= left <= right < n and swap the subarray nums1[left...right] with the subarray nums2[left...right].\n\nFor example, if nums1 = [1,2,3,4,5] and nums2 = [11,12,13,14,15] and you choose left = 1 and right = 2, nums1 becomes [1,12,13,4,5] and nums2 becomes [11,2,3,14,15].\n\nYou may choose to apply the mentioned operation once or not do anything.\nThe score of the arrays is the maximum of sum(nums1) and sum(nums2), where sum(arr) is the sum of all the elements in the array arr.\nReturn the maximum possible score.\nA subarray is a contiguous sequence of elements within an array. arr[left...right] denotes the subarray that contains the elements of nums between indices left and right (inclusive).",
+        "examples": [
+            "Example 1:\nInput: nums1 = [60,60,60], nums2 = [10,90,10]\nOutput: 210\nExplanation: Choosing left = 1 and right = 1, we have nums1 = [60,90,60] and nums2 = [10,60,10].\nThe score is max(sum(nums1), sum(nums2)) = max(210, 80) = 210.",
+            "Example 2:\nInput: nums1 = [20,40,20,70,30], nums2 = [50,20,50,40,20]\nOutput: 220\nExplanation: Choosing left = 3, right = 4, we have nums1 = [20,40,20,40,20] and nums2 = [50,20,50,70,30].\nThe score is max(sum(nums1), sum(nums2)) = max(140, 220) = 220.",
+            "Example 3:\nInput: nums1 = [7,11,13], nums2 = [1,1,1]\nOutput: 31\nExplanation: We choose not to swap any subarray.\nThe score is max(sum(nums1), sum(nums2)) = max(31, 3) = 31."
+        ],
+        "constraints": "Constraints:\n\nn == nums1.length == nums2.length\n1 <= n <= 10^5\n1 <= nums1[i], nums2[i] <= 10^4",
+        "tags": [
+            "Array",
+            "Dynamic Programming"
+        ],
+        "title-slug": "maximum-score-of-spliced-array"
+    },
+    {
+        "leetcode-id": 2322,
+        "title": "Minimum Score After Removals on a Tree",
+        "difficulty": 3,
+        "description": "There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.\nYou are given a 0-indexed integer array nums of length n where nums[i] represents the value of the i^th node. You are also given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\nRemove two distinct edges of the tree to form three connected components. For a pair of removed edges, the following steps are defined:\n\nGet the XOR of all the values of the nodes for each of the three components respectively.\nThe difference between the largest XOR value and the smallest XOR value is the score of the pair.\n\n\nFor example, say the three components have the node values: [4,5,7], [1,9], and [3,3,3]. The three XOR values are 4 ^ 5 ^ 7 = 6, 1 ^ 9 = 8, and 3 ^ 3 ^ 3 = 3. The largest XOR value is 8 and the smallest XOR value is 3. The score is then 8 - 3 = 5.\n\nReturn the minimum score of any possible pair of edge removals on the given tree.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,5,5,4,11], edges = [[0,1],[1,2],[1,3],[3,4]]\nOutput: 9\nExplanation: The diagram above shows a way to make a pair of removals.\n- The 1^st component has nodes [1,3,4] with values [5,4,11]. Its XOR value is 5 ^ 4 ^ 11 = 10.\n- The 2^nd component has node [0] with value [1]. Its XOR value is 1 = 1.\n- The 3^rd component has node [2] with value [5]. Its XOR value is 5 = 5.\nThe score is the difference between the largest and smallest XOR value which is 10 - 1 = 9.\nIt can be shown that no other pair of removals will obtain a smaller score than 9.",
+            "Example 2:\nInput: nums = [5,5,2,4,4,2], edges = [[0,1],[1,2],[5,2],[4,3],[1,3]]\nOutput: 0\nExplanation: The diagram above shows a way to make a pair of removals.\n- The 1^st component has nodes [3,4] with values [4,4]. Its XOR value is 4 ^ 4 = 0.\n- The 2^nd component has nodes [1,0] with values [5,5]. Its XOR value is 5 ^ 5 = 0.\n- The 3^rd component has nodes [2,5] with values [2,2]. Its XOR value is 2 ^ 2 = 0.\nThe score is the difference between the largest and smallest XOR value which is 0 - 0 = 0.\nWe cannot obtain a smaller score than 0."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length\n3 <= n <= 1000\n1 <= nums[i] <= 10^8\nedges.length == n - 1\nedges[i].length == 2\n0 <= ai, bi < n\nai != bi\nedges represents a valid tree.",
+        "tags": [
+            "Array",
+            "Bit Manipulation",
+            "Tree",
+            "Depth-First Search"
+        ],
+        "title-slug": "minimum-score-after-removals-on-a-tree"
+    },
+    {
+        "leetcode-id": 2325,
+        "title": "Decode the Message",
+        "difficulty": 1,
+        "description": "You are given the strings key and message, which represent a cipher key and a secret message, respectively. The steps to decode message are as follows:\n\nUse the first appearance of all 26 lowercase English letters in key as the order of the substitution table.\nAlign the substitution table with the regular English alphabet.\nEach letter in message is then substituted using the table.\nSpaces ' ' are transformed to themselves.\n\n\nFor example, given key = \"happy boy\" (actual key would have at least one instance of each letter in the alphabet), we have the partial substitution table of ('h' -> 'a', 'a' -> 'b', 'p' -> 'c', 'y' -> 'd', 'b' -> 'e', 'o' -> 'f').\n\nReturn the decoded message.",
+        "examples": [
+            "Example 1:\nInput: key = \"the quick brown fox jumps over the lazy dog\", message = \"vkbs bs t suepuv\"\nOutput: \"this is a secret\"\nExplanation: The diagram above shows the substitution table.\nIt is obtained by taking the first appearance of each letter in \"the quick brown fox jumps over the lazy dog\".",
+            "Example 2:\nInput: key = \"eljuxhpwnyrdgtqkviszcfmabo\", message = \"zwx hnfx lqantp mnoeius ycgk vcnjrdb\"\nOutput: \"the five boxing wizards jump quickly\"\nExplanation: The diagram above shows the substitution table.\nIt is obtained by taking the first appearance of each letter in \"eljuxhpwnyrdgtqkviszcfmabo\"."
+        ],
+        "constraints": "Constraints:\n\n26 <= key.length <= 2000\nkey consists of lowercase English letters and ' '.\nkey contains every letter in the English alphabet ('a' to 'z') at least once.\n1 <= message.length <= 2000\nmessage consists of lowercase English letters and ' '.",
+        "tags": [
+            "Hash Table",
+            "String"
+        ],
+        "title-slug": "decode-the-message"
+    },
+    {
+        "leetcode-id": 2326,
+        "title": "Spiral Matrix IV",
+        "difficulty": 2,
+        "description": "You are given two integers m and n, which represent the dimensions of a matrix.\nYou are also given the head of a linked list of integers.\nGenerate an m x n matrix that contains the integers in the linked list presented in spiral order (clockwise), starting from the top-left of the matrix. If there are remaining empty spaces, fill them with -1.\nReturn the generated matrix.",
+        "examples": [
+            "Example 1:\nInput: m = 3, n = 5, head = [3,0,2,6,8,1,7,9,4,2,5,5,0]\nOutput: [[3,0,2,6,8],[5,0,-1,-1,1],[5,2,4,9,7]]\nExplanation: The diagram above shows how the values are printed in the matrix.\nNote that the remaining spaces in the matrix are filled with -1.",
+            "Example 2:\nInput: m = 1, n = 4, head = [0,1,2]\nOutput: [[0,1,2,-1]]\nExplanation: The diagram above shows how the values are printed from left to right in the matrix.\nThe last space in the matrix is set to -1."
+        ],
+        "constraints": "Constraints:\n\n1 <= m, n <= 10^5\n1 <= m * n <= 10^5\nThe number of nodes in the list is in the range [1, m * n].\n0 <= Node.val <= 1000",
+        "tags": [
+            "Array",
+            "Linked List",
+            "Matrix",
+            "Simulation"
+        ],
+        "title-slug": "spiral-matrix-iv"
+    },
+    {
+        "leetcode-id": 2327,
+        "title": "Number of People Aware of a Secret",
+        "difficulty": 2,
+        "description": "On day 1, one person discovers a secret.\nYou are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the secret. You are also given an integer forget, which means that each person will forget the secret forget days after discovering it. A person cannot share the secret on the same day they forgot it, or on any day afterwards.\nGiven an integer n, return the number of people who know the secret at the end of day n. Since the answer may be very large, return it modulo 10^9 + 7.",
+        "examples": [
+            "Example 1:\nInput: n = 6, delay = 2, forget = 4\nOutput: 5\nExplanation:\nDay 1: Suppose the first person is named A. (1 person)\nDay 2: A is the only person who knows the secret. (1 person)\nDay 3: A shares the secret with a new person, B. (2 people)\nDay 4: A shares the secret with a new person, C. (3 people)\nDay 5: A forgets the secret, and B shares the secret with a new person, D. (3 people)\nDay 6: B shares the secret with E, and C shares the secret with F. (5 people)",
+            "Example 2:\nInput: n = 4, delay = 1, forget = 3\nOutput: 6\nExplanation:\nDay 1: The first person is named A. (1 person)\nDay 2: A shares the secret with B. (2 people)\nDay 3: A and B share the secret with 2 new people, C and D. (4 people)\nDay 4: A forgets the secret. B, C, and D share the secret with 3 new people. (6 people)"
+        ],
+        "constraints": "Constraints:\n\n2 <= n <= 1000\n1 <= delay < forget <= n",
+        "tags": [
+            "Dynamic Programming",
+            "Queue",
+            "Simulation"
+        ],
+        "title-slug": "number-of-people-aware-of-a-secret"
+    },
+    {
+        "leetcode-id": 2328,
+        "title": "Number of Increasing Paths in a Grid",
+        "difficulty": 3,
+        "description": "You are given an m x n integer matrix grid, where you can move from a cell to any adjacent cell in all 4 directions.\nReturn the number of strictly increasing paths in the grid such that you can start from any cell and end at any cell. Since the answer may be very large, return it modulo 10^9 + 7.\nTwo paths are considered different if they do not have exactly the same sequence of visited cells.",
+        "examples": [
+            "Example 1:\nInput: grid = [[1,1],[3,4]]\nOutput: 8\nExplanation: The strictly increasing paths are:\n- Paths with length 1: [1], [1], [3], [4].\n- Paths with length 2: [1 -> 3], [1 -> 4], [3 -> 4].\n- Paths with length 3: [1 -> 3 -> 4].\nThe total number of paths is 4 + 3 + 1 = 8.",
+            "Example 2:\nInput: grid = [[1],[2]]\nOutput: 3\nExplanation: The strictly increasing paths are:\n- Paths with length 1: [1], [2].\n- Paths with length 2: [1 -> 2].\nThe total number of paths is 2 + 1 = 3."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 1000\n1 <= m * n <= 10^5\n1 <= grid[i][j] <= 10^5",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Graph",
+            "Topological Sort",
+            "Memoization",
+            "Matrix"
+        ],
+        "title-slug": "number-of-increasing-paths-in-a-grid"
+    },
+    {
+        "leetcode-id": 2331,
+        "title": "Evaluate Boolean Binary Tree",
+        "difficulty": 1,
+        "description": "You are given the root of a full binary tree with the following properties:\n\nLeaf nodes have either the value 0 or 1, where 0 represents False and 1 represents True.\nNon-leaf nodes have either the value 2 or 3, where 2 represents the boolean OR and 3 represents the boolean AND.\n\nThe evaluation of a node is as follows:\n\nIf the node is a leaf node, the evaluation is the value of the node, i.e. True or False.\nOtherwise, evaluate the node's two children and apply the boolean operation of its value with the children's evaluations.\n\nReturn the boolean result of evaluating the root node.\nA full binary tree is a binary tree where each node has either 0 or 2 children.\nA leaf node is a node that has zero children.",
+        "examples": [
+            "Example 1:\nInput: root = [2,1,3,null,null,0,1]\nOutput: true\nExplanation: The above diagram illustrates the evaluation process.\nThe AND node evaluates to False AND True = False.\nThe OR node evaluates to True OR False = True.\nThe root node evaluates to True, so we return true.",
+            "Example 2:\nInput: root = [0]\nOutput: false\nExplanation: The root node is a leaf node and it evaluates to false, so we return false."
+        ],
+        "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 1000].\n0 <= Node.val <= 3\nEvery node has either 0 or 2 children.\nLeaf nodes have a value of 0 or 1.\nNon-leaf nodes have a value of 2 or 3.",
+        "tags": [
+            "Tree",
+            "Depth-First Search",
+            "Binary Tree"
+        ],
+        "title-slug": "evaluate-boolean-binary-tree"
+    },
+    {
+        "leetcode-id": 2332,
+        "title": "The Latest Time to Catch a Bus",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array buses of length n, where buses[i] represents the departure time of the i^th bus. You are also given a 0-indexed integer array passengers of length m, where passengers[j] represents the arrival time of the j^th passenger. All bus departure times are unique. All passenger arrival times are unique.\nYou are given an integer capacity, which represents the maximum number of passengers that can get on each bus.\nWhen a passenger arrives, they will wait in line for the next available bus. You can get on a bus that departs at x minutes if you arrive at y minutes where y <= x, and the bus is not full. Passengers with the earliest arrival times get on the bus first.\nMore formally when a bus arrives, either:\n\nIf capacity or fewer passengers are waiting for a bus, they will all get on the bus, or\nThe capacity passengers with the earliest arrival times will get on the bus.\n\nReturn the latest time you may arrive at the bus station to catch a bus. You cannot arrive at the same time as another passenger.\nNote: The arrays buses and passengers are not necessarily sorted.",
+        "examples": [
+            "Example 1:\nInput: buses = [10,20], passengers = [2,17,18,19], capacity = 2\nOutput: 16\nExplanation: Suppose you arrive at time 16.\nAt time 10, the first bus departs with the 0^th passenger. \nAt time 20, the second bus departs with you and the 1^st passenger.\nNote that you may not arrive at the same time as another passenger, which is why you must arrive before the 1^st passenger to catch the bus.",
+            "Example 2:\nInput: buses = [20,30,10], passengers = [19,13,26,4,25,11,21], capacity = 2\nOutput: 20\nExplanation: Suppose you arrive at time 20.\nAt time 10, the first bus departs with the 3^rd passenger. \nAt time 20, the second bus departs with the 5^th and 1^st passengers.\nAt time 30, the third bus departs with the 0^th passenger and you.\nNotice if you had arrived any later, then the 6^th passenger would have taken your seat on the third bus."
+        ],
+        "constraints": "Constraints:\n\nn == buses.length\nm == passengers.length\n1 <= n, m, capacity <= 10^5\n2 <= buses[i], passengers[i] <= 10^9\nEach element in buses is unique.\nEach element in passengers is unique.",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Binary Search",
+            "Sorting"
+        ],
+        "title-slug": "the-latest-time-to-catch-a-bus"
+    },
+    {
+        "leetcode-id": 2333,
+        "title": "Minimum Sum of Squared Difference",
+        "difficulty": 2,
+        "description": "You are given two positive 0-indexed integer arrays nums1 and nums2, both of length n.\nThe sum of squared difference of arrays nums1 and nums2 is defined as the sum of (nums1[i] - nums2[i])^2 for each 0 <= i < n.\nYou are also given two positive integers k1 and k2. You can modify any of the elements of nums1 by +1 or -1 at most k1 times. Similarly, you can modify any of the elements of nums2 by +1 or -1 at most k2 times.\nReturn the minimum sum of squared difference after modifying array nums1 at most k1 times and modifying array nums2 at most k2 times.\nNote: You are allowed to modify the array elements to become negative integers.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [1,2,3,4], nums2 = [2,10,20,19], k1 = 0, k2 = 0\nOutput: 579\nExplanation: The elements in nums1 and nums2 cannot be modified because k1 = 0 and k2 = 0. \nThe sum of square difference will be: (1 - 2)^2 + (2 - 10)^2 + (3 - 20)^2 + (4 - 19)^2\u00a0= 579.",
+            "Example 2:\nInput: nums1 = [1,4,10,12], nums2 = [5,8,6,9], k1 = 1, k2 = 1\nOutput: 43\nExplanation: One way to obtain the minimum sum of square difference is: \n- Increase nums1[0] once.\n- Increase nums2[2] once.\nThe minimum of the sum of square difference will be: \n(2 - 5)^2 + (4 - 8)^2 + (10 - 7)^2 + (12 - 9)^2\u00a0= 43.\nNote that, there are other ways to obtain the minimum of the sum of square difference, but there is no way to obtain a sum smaller than 43."
+        ],
+        "constraints": "Constraints:\n\nn == nums1.length == nums2.length\n1 <= n <= 10^5\n0 <= nums1[i], nums2[i] <= 10^5\n0 <= k1, k2 <= 10^9",
+        "tags": [
+            "Array",
+            "Math",
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "minimum-sum-of-squared-difference"
+    },
+    {
+        "leetcode-id": 2334,
+        "title": "Subarray With Elements Greater Than Varying Threshold",
+        "difficulty": 3,
+        "description": "You are given an integer array nums and an integer threshold.\nFind any subarray of nums of length k such that every element in the subarray is greater than threshold / k.\nReturn the size of any such subarray. If there is no such subarray, return -1.\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,4,3,1], threshold = 6\nOutput: 3\nExplanation: The subarray [3,4,3] has a size of 3, and every element is greater than 6 / 3 = 2.\nNote that this is the only valid subarray.",
+            "Example 2:\nInput: nums = [6,5,6,5,8], threshold = 7\nOutput: 1\nExplanation: The subarray [8] has a size of 1, and 8 > 7 / 1 = 7. So 1 is returned.\nNote that the subarray [6,5] has a size of 2, and every element is greater than 7 / 2 = 3.5. \nSimilarly, the subarrays [6,5,6], [6,5,6,5], [6,5,6,5,8] also satisfy the given conditions.\nTherefore, 2, 3, 4, or 5 may also be returned."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i], threshold <= 10^9",
+        "tags": [
+            "Array",
+            "Stack",
+            "Union Find",
+            "Monotonic Stack"
+        ],
+        "title-slug": "subarray-with-elements-greater-than-varying-threshold"
+    },
+    {
+        "leetcode-id": 2335,
+        "title": "Minimum Amount of Time to Fill Cups",
+        "difficulty": 1,
+        "description": "You have a water dispenser that can dispense cold, warm, and hot water. Every second, you can either fill up 2 cups with different types of water, or 1 cup of any type of water.\nYou are given a 0-indexed integer array amount of length 3 where amount[0], amount[1], and amount[2] denote the number of cold, warm, and hot water cups you need to fill respectively. Return the minimum number of seconds needed to fill up all the cups.",
+        "examples": [
+            "Example 1:\nInput: amount = [1,4,2]\nOutput: 4\nExplanation: One way to fill up the cups is:\nSecond 1: Fill up a cold cup and a warm cup.\nSecond 2: Fill up a warm cup and a hot cup.\nSecond 3: Fill up a warm cup and a hot cup.\nSecond 4: Fill up a warm cup.\nIt can be proven that 4 is the minimum number of seconds needed.",
+            "Example 2:\nInput: amount = [5,4,4]\nOutput: 7\nExplanation: One way to fill up the cups is:\nSecond 1: Fill up a cold cup, and a hot cup.\nSecond 2: Fill up a cold cup, and a warm cup.\nSecond 3: Fill up a cold cup, and a warm cup.\nSecond 4: Fill up a warm cup, and a hot cup.\nSecond 5: Fill up a cold cup, and a hot cup.\nSecond 6: Fill up a cold cup, and a warm cup.\nSecond 7: Fill up a hot cup.",
+            "Example 3:\nInput: amount = [5,0,0]\nOutput: 5\nExplanation: Every second, we fill up a cold cup."
+        ],
+        "constraints": "Constraints:\n\namount.length == 3\n0 <= amount[i] <= 100",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "minimum-amount-of-time-to-fill-cups"
+    },
+    {
+        "leetcode-id": 2336,
+        "title": "Smallest Number in Infinite Set",
+        "difficulty": 2,
+        "description": "You have a set which contains all positive integers [1, 2, 3, 4, 5, ...].\nImplement the SmallestInfiniteSet class:\n\nSmallestInfiniteSet() Initializes the SmallestInfiniteSet object to contain all positive integers.\nint popSmallest() Removes and returns the smallest integer contained in the infinite set.\nvoid addBack(int num) Adds a positive integer num back into the infinite set, if it is not already in the infinite set.",
+        "examples": [
+            "Example 1:\nInput\n[\"SmallestInfiniteSet\", \"addBack\", \"popSmallest\", \"popSmallest\", \"popSmallest\", \"addBack\", \"popSmallest\", \"popSmallest\", \"popSmallest\"]\n[[], [2], [], [], [], [1], [], [], []]\nOutput\n[null, null, 1, 2, 3, null, 1, 4, 5]\n\nExplanation\nSmallestInfiniteSet smallestInfiniteSet = new SmallestInfiniteSet();\nsmallestInfiniteSet.addBack(2);    // 2 is already in the set, so no change is made.\nsmallestInfiniteSet.popSmallest(); // return 1, since 1 is the smallest number, and remove it from the set.\nsmallestInfiniteSet.popSmallest(); // return 2, and remove it from the set.\nsmallestInfiniteSet.popSmallest(); // return 3, and remove it from the set.\nsmallestInfiniteSet.addBack(1);    // 1 is added back to the set.\nsmallestInfiniteSet.popSmallest(); // return 1, since 1 was added back to the set and\n                                   // is the smallest number, and remove it from the set.\nsmallestInfiniteSet.popSmallest(); // return 4, and remove it from the set.\nsmallestInfiniteSet.popSmallest(); // return 5, and remove it from the set."
+        ],
+        "constraints": "Constraints:\n\n1 <= num <= 1000\nAt most 1000 calls will be made in total to popSmallest and addBack.",
+        "tags": [
+            "Hash Table",
+            "Design",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "smallest-number-in-infinite-set"
+    },
+    {
+        "leetcode-id": 2337,
+        "title": "Move Pieces to Obtain a String",
+        "difficulty": 2,
+        "description": "You are given two strings start and target, both of length n. Each string consists only of the characters 'L', 'R', and '_' where:\n\nThe characters 'L' and 'R' represent pieces, where a piece 'L' can move to the left only if there is a blank space directly to its left, and a piece 'R' can move to the right only if there is a blank space directly to its right.\nThe character '_' represents a blank space that can be occupied by any of the 'L' or 'R' pieces.\n\nReturn true if it is possible to obtain the string target by moving the pieces of the string start any number of times. Otherwise, return false.",
+        "examples": [
+            "Example 1:\nInput: start = \"_L__R__R_\", target = \"L______RR\"\nOutput: true\nExplanation: We can obtain the string target from start by doing the following moves:\n- Move the first piece one step to the left, start becomes equal to \"L___R__R_\".\n- Move the last piece one step to the right, start becomes equal to \"L___R___R\".\n- Move the second piece three steps to the right, start becomes equal to \"L______RR\".\nSince it is possible to get the string target from start, we return true.",
+            "Example 2:\nInput: start = \"R_L_\", target = \"__LR\"\nOutput: false\nExplanation: The 'R' piece in the string start can move one step to the right to obtain \"_RL_\".\nAfter that, no pieces can move anymore, so it is impossible to obtain the string target from start.",
+            "Example 3:\nInput: start = \"_R\", target = \"R_\"\nOutput: false\nExplanation: The piece in the string start can move only to the right, so it is impossible to obtain the string target from start."
+        ],
+        "constraints": "Constraints:\n\nn == start.length == target.length\n1 <= n <= 10^5\nstart and target consist of the characters 'L', 'R', and '_'.",
+        "tags": [
+            "Two Pointers",
+            "String"
+        ],
+        "title-slug": "move-pieces-to-obtain-a-string"
+    },
+    {
+        "leetcode-id": 2338,
+        "title": "Count the Number of Ideal Arrays",
+        "difficulty": 3,
+        "description": "You are given two integers n and maxValue, which are used to describe an ideal array.\nA 0-indexed integer array arr of length n is considered ideal if the following conditions hold:\n\nEvery arr[i] is a value from 1 to maxValue, for 0 <= i < n.\nEvery arr[i] is divisible by arr[i - 1], for 0 < i < n.\n\nReturn the number of distinct ideal arrays of length n. Since the answer may be very large, return it modulo 10^9 + 7.",
+        "examples": [
+            "Example 1:\nInput: n = 2, maxValue = 5\nOutput: 10\nExplanation: The following are the possible ideal arrays:\n- Arrays starting with the value 1 (5 arrays): [1,1], [1,2], [1,3], [1,4], [1,5]\n- Arrays starting with the value 2 (2 arrays): [2,2], [2,4]\n- Arrays starting with the value 3 (1 array): [3,3]\n- Arrays starting with the value 4 (1 array): [4,4]\n- Arrays starting with the value 5 (1 array): [5,5]\nThere are a total of 5 + 2 + 1 + 1 + 1 = 10 distinct ideal arrays.",
+            "Example 2:\nInput: n = 5, maxValue = 3\nOutput: 11\nExplanation: The following are the possible ideal arrays:\n- Arrays starting with the value 1 (9 arrays): \n   - With no other distinct values (1 array): [1,1,1,1,1] \n   - With 2^nd distinct value 2 (4 arrays): [1,1,1,1,2], [1,1,1,2,2], [1,1,2,2,2], [1,2,2,2,2]\n   - With 2^nd distinct value 3 (4 arrays): [1,1,1,1,3], [1,1,1,3,3], [1,1,3,3,3], [1,3,3,3,3]\n- Arrays starting with the value 2 (1 array): [2,2,2,2,2]\n- Arrays starting with the value 3 (1 array): [3,3,3,3,3]\nThere are a total of 9 + 1 + 1 = 11 distinct ideal arrays."
+        ],
+        "constraints": "Constraints:\n\n2 <= n <= 10^4\n1 <= maxValue <= 10^4",
+        "tags": [
+            "Math",
+            "Dynamic Programming",
+            "Combinatorics",
+            "Number Theory"
+        ],
+        "title-slug": "count-the-number-of-ideal-arrays"
+    },
+    {
+        "leetcode-id": 2341,
+        "title": "Maximum Number of Pairs in Array",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums. In one operation, you may do the following:\n\nChoose two integers in nums that are equal.\nRemove both integers from nums, forming a pair.\n\nThe operation is done on nums as many times as possible.\nReturn a 0-indexed integer array answer of size 2 where answer[0] is the number of pairs that are formed and answer[1] is the number of leftover integers in nums after doing the operation as many times as possible.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,2,1,3,2,2]\nOutput: [3,1]\nExplanation:\nForm a pair with nums[0] and nums[3] and remove them from nums. Now, nums = [3,2,3,2,2].\nForm a pair with nums[0] and nums[2] and remove them from nums. Now, nums = [2,2,2].\nForm a pair with nums[0] and nums[1] and remove them from nums. Now, nums = [2].\nNo more pairs can be formed. A total of 3 pairs have been formed, and there is 1 number leftover in nums.",
+            "Example 2:\nInput: nums = [1,1]\nOutput: [1,0]\nExplanation: Form a pair with nums[0] and nums[1] and remove them from nums. Now, nums = [].\nNo more pairs can be formed. A total of 1 pair has been formed, and there are 0 numbers leftover in nums.",
+            "Example 3:\nInput: nums = [0]\nOutput: [0,1]\nExplanation: No pairs can be formed, and there is 1 number leftover in nums."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 100\n0 <= nums[i] <= 100",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Counting"
+        ],
+        "title-slug": "maximum-number-of-pairs-in-array"
+    },
+    {
+        "leetcode-id": 2342,
+        "title": "Max Sum of a Pair With Equal Sum of Digits",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array nums consisting of positive integers. You can choose two indices i and j, such that i != j, and the sum of digits of the number nums[i] is equal to that of nums[j].\nReturn the maximum value of nums[i] + nums[j] that you can obtain over all possible indices i and j that satisfy the conditions.",
+        "examples": [
+            "Example 1:\nInput: nums = [18,43,36,13,7]\nOutput: 54\nExplanation: The pairs (i, j) that satisfy the conditions are:\n- (0, 2), both numbers have a sum of digits equal to 9, and their sum is 18 + 36 = 54.\n- (1, 4), both numbers have a sum of digits equal to 7, and their sum is 43 + 7 = 50.\nSo the maximum sum that we can obtain is 54.",
+            "Example 2:\nInput: nums = [10,12,19,14]\nOutput: -1\nExplanation: There are no two numbers that satisfy the conditions, so we return -1."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "max-sum-of-a-pair-with-equal-sum-of-digits"
+    },
+    {
+        "leetcode-id": 2343,
+        "title": "Query Kth Smallest Trimmed Number",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array of strings nums, where each string is of equal length and consists of only digits.\nYou are also given a 0-indexed 2D integer array queries where queries[i] = [ki, trimi]. For each queries[i], you need to:\n\nTrim each number in nums to its rightmost trimi digits.\nDetermine the index of the ki^th smallest trimmed number in nums. If two trimmed numbers are equal, the number with the lower index is considered to be smaller.\nReset each number in nums to its original length.\n\nReturn an array answer of the same length as queries, where answer[i] is the answer to the i^th query.\nNote:\n\nTo trim to the rightmost x digits means to keep removing the leftmost digit, until only x digits remain.\nStrings in nums may contain leading zeros.",
+        "examples": [
+            "Example 1:\nInput: nums = [\"102\",\"473\",\"251\",\"814\"], queries = [[1,1],[2,3],[4,2],[1,2]]\nOutput: [2,2,1,0]\nExplanation:\n1. After trimming to the last digit, nums = [\"2\",\"3\",\"1\",\"4\"]. The smallest number is 1 at index 2.\n2. Trimmed to the last 3 digits, nums is unchanged. The 2^nd smallest number is 251 at index 2.\n3. Trimmed to the last 2 digits, nums = [\"02\",\"73\",\"51\",\"14\"]. The 4^th smallest number is 73.\n4. Trimmed to the last 2 digits, the smallest number is 2 at index 0.\n   Note that the trimmed number \"02\" is evaluated as 2.",
+            "Example 2:\nInput: nums = [\"24\",\"37\",\"96\",\"04\"], queries = [[2,1],[2,2]]\nOutput: [3,0]\nExplanation:\n1. Trimmed to the last digit, nums = [\"4\",\"7\",\"6\",\"4\"]. The 2^nd smallest number is 4 at index 3.\n   There are two occurrences of 4, but the one at index 0 is considered smaller than the one at index 3.\n2. Trimmed to the last 2 digits, nums is unchanged. The 2^nd smallest number is 24."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= nums[i].length <= 100\nnums[i] consists of only digits.\nAll nums[i].length are equal.\n1 <= queries.length <= 100\nqueries[i].length == 2\n1 <= ki <= nums.length\n1 <= trimi <= nums[i].length\n\n\u00a0\nFollow up: Could you use the Radix Sort Algorithm to solve this problem? What will be the complexity of that solution?",
+        "tags": [
+            "Array",
+            "String",
+            "Divide and Conquer",
+            "Sorting",
+            "Heap (Priority Queue)",
+            "Radix Sort",
+            "Quickselect"
+        ],
+        "title-slug": "query-kth-smallest-trimmed-number"
+    },
+    {
+        "leetcode-id": 2344,
+        "title": "Minimum Deletions to Make Array Divisible",
+        "difficulty": 3,
+        "description": "You are given two positive integer arrays nums and numsDivide. You can delete any number of elements from nums.\nReturn the minimum number of deletions such that the smallest element in nums divides all the elements of numsDivide. If this is not possible, return -1.\nNote that an integer x divides y if y % x == 0.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,3,2,4,3], numsDivide = [9,6,9,3,15]\nOutput: 2\nExplanation: \nThe smallest element in [2,3,2,4,3] is 2, which does not divide all the elements of numsDivide.\nWe use 2 deletions to delete the elements in nums that are equal to 2 which makes nums = [3,4,3].\nThe smallest element in [3,4,3] is 3, which divides all the elements of numsDivide.\nIt can be shown that 2 is the minimum number of deletions needed.",
+            "Example 2:\nInput: nums = [4,3,6], numsDivide = [8,2,6,10]\nOutput: -1\nExplanation: \nWe want the smallest element in nums to divide all the elements of numsDivide.\nThere is no way to delete elements from nums to allow this."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length, numsDivide.length <= 10^5\n1 <= nums[i], numsDivide[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Math",
+            "Sorting",
+            "Heap (Priority Queue)",
+            "Number Theory"
+        ],
+        "title-slug": "minimum-deletions-to-make-array-divisible"
+    },
+    {
+        "leetcode-id": 2347,
+        "title": "Best Poker Hand",
+        "difficulty": 1,
+        "description": "You are given an integer array ranks and a character array suits. You have 5 cards where the i^th card has a rank of ranks[i] and a suit of suits[i].\nThe following are the types of poker hands you can make from best to worst:\n\n\"Flush\": Five cards of the same suit.\n\"Three of a Kind\": Three cards of the same rank.\n\"Pair\": Two cards of the same rank.\n\"High Card\": Any single card.\n\nReturn a string representing the best type of poker hand you can make with the given cards.\nNote that the return values are case-sensitive.",
+        "examples": [
+            "Example 1:\nInput: ranks = [13,2,3,1,9], suits = [\"a\",\"a\",\"a\",\"a\",\"a\"]\nOutput: \"Flush\"\nExplanation: The hand with all the cards consists of 5 cards with the same suit, so we have a \"Flush\".",
+            "Example 2:\nInput: ranks = [4,4,2,4,4], suits = [\"d\",\"a\",\"a\",\"b\",\"c\"]\nOutput: \"Three of a Kind\"\nExplanation: The hand with the first, second, and fourth card consists of 3 cards with the same rank, so we have a \"Three of a Kind\".\nNote that we could also make a \"Pair\" hand but \"Three of a Kind\" is a better hand.\nAlso note that other cards could be used to make the \"Three of a Kind\" hand.",
+            "Example 3:\nInput: ranks = [10,10,2,12,9], suits = [\"a\",\"b\",\"c\",\"a\",\"d\"]\nOutput: \"Pair\"\nExplanation: The hand with the first and second card consists of 2 cards with the same rank, so we have a \"Pair\".\nNote that we cannot make a \"Flush\" or a \"Three of a Kind\"."
+        ],
+        "constraints": "Constraints:\n\nranks.length == suits.length == 5\n1 <= ranks[i] <= 13\n'a' <= suits[i] <= 'd'\nNo two cards have the same rank and suit.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Counting"
+        ],
+        "title-slug": "best-poker-hand"
+    },
+    {
+        "leetcode-id": 2348,
+        "title": "Number of Zero-Filled Subarrays",
+        "difficulty": 2,
+        "description": "Given an integer array nums, return the number of subarrays filled with 0.\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,0,0,2,0,0,4]\nOutput: 6\nExplanation: \nThere are 4 occurrences of [0] as a subarray.\nThere are 2 occurrences of [0,0] as a subarray.\nThere is no occurrence of a subarray with a size more than 2 filled with 0. Therefore, we return 6.",
+            "Example 2:\nInput: nums = [0,0,0,2,0,0]\nOutput: 9\nExplanation:\nThere are 5 occurrences of [0] as a subarray.\nThere are 3 occurrences of [0,0] as a subarray.\nThere is 1 occurrence of [0,0,0] as a subarray.\nThere is no occurrence of a subarray with a size more than 3 filled with 0. Therefore, we return 9.",
+            "Example 3:\nInput: nums = [2,10,2019]\nOutput: 0\nExplanation: There is no subarray filled with 0. Therefore, we return 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^9 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Math"
+        ],
+        "title-slug": "number-of-zero-filled-subarrays"
+    },
+    {
+        "leetcode-id": 2349,
+        "title": "Design a Number Container System",
+        "difficulty": 2,
+        "description": "Design a number container system that can do the following:\n\nInsert or Replace a number at the given index in the system.\nReturn the smallest index for the given number in the system.\n\nImplement the NumberContainers class:\n\nNumberContainers() Initializes the number container system.\nvoid change(int index, int number) Fills the container at index with the number. If there is already a number at that index, replace it.\nint find(int number) Returns the smallest index for the given number, or -1 if there is no index that is filled by number in the system.",
+        "examples": [
+            "Example 1:\nInput\n[\"NumberContainers\", \"find\", \"change\", \"change\", \"change\", \"change\", \"find\", \"change\", \"find\"]\n[[], [10], [2, 10], [1, 10], [3, 10], [5, 10], [10], [1, 20], [10]]\nOutput\n[null, -1, null, null, null, null, 1, null, 2]\n\nExplanation\nNumberContainers nc = new NumberContainers();\nnc.find(10); // There is no index that is filled with number 10. Therefore, we return -1.\nnc.change(2, 10); // Your container at index 2 will be filled with number 10.\nnc.change(1, 10); // Your container at index 1 will be filled with number 10.\nnc.change(3, 10); // Your container at index 3 will be filled with number 10.\nnc.change(5, 10); // Your container at index 5 will be filled with number 10.\nnc.find(10); // Number 10 is at the indices 1, 2, 3, and 5. Since the smallest index that is filled with 10 is 1, we return 1.\nnc.change(1, 20); // Your container at index 1 will be filled with number 20. Note that index 1 was filled with 10 and then replaced with 20. \nnc.find(10); // Number 10 is at the indices 2, 3, and 5. The smallest index that is filled with 10 is 2. Therefore, we return 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= index, number <= 10^9\nAt most 10^5 calls will be made in total to change and find.",
+        "tags": [
+            "Hash Table",
+            "Design",
+            "Heap (Priority Queue)",
+            "Ordered Set"
+        ],
+        "title-slug": "design-a-number-container-system"
+    },
+    {
+        "leetcode-id": 2350,
+        "title": "Shortest Impossible Sequence of Rolls",
+        "difficulty": 3,
+        "description": "You are given an integer array rolls of length n and an integer k. You roll a k sided dice numbered from 1 to k, n times, where the result of the i^th roll is rolls[i].\nReturn the length of the shortest sequence of rolls that cannot be taken from rolls.\nA sequence of rolls of length len is the result of rolling a k sided dice len times.\nNote that the sequence taken does not have to be consecutive as long as it is in order.",
+        "examples": [
+            "Example 1:\nInput: rolls = [4,2,1,2,3,3,2,4,1], k = 4\nOutput: 3\nExplanation: Every sequence of rolls of length 1, [1], [2], [3], [4], can be taken from rolls.\nEvery sequence of rolls of length 2, [1, 1], [1, 2], ..., [4, 4], can be taken from rolls.\nThe sequence [1, 4, 2] cannot be taken from rolls, so we return 3.\nNote that there are other sequences that cannot be taken from rolls.",
+            "Example 2:\nInput: rolls = [1,1,2,2], k = 2\nOutput: 2\nExplanation: Every sequence of rolls of length 1, [1], [2], can be taken from rolls.\nThe sequence [2, 1] cannot be taken from rolls, so we return 2.\nNote that there are other sequences that cannot be taken from rolls but [2, 1] is the shortest.",
+            "Example 3:\nInput: rolls = [1,1,3,2,2,2,3,3], k = 4\nOutput: 1\nExplanation: The sequence [4] cannot be taken from rolls, so we return 1.\nNote that there are other sequences that cannot be taken from rolls but [4] is the shortest."
+        ],
+        "constraints": "Constraints:\n\nn == rolls.length\n1 <= n <= 10^5\n1 <= rolls[i] <= k <= 10^5",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Greedy"
+        ],
+        "title-slug": "shortest-impossible-sequence-of-rolls"
+    },
+    {
+        "leetcode-id": 2351,
+        "title": "First Letter to Appear Twice",
+        "difficulty": 1,
+        "description": "Given a string s consisting of lowercase English letters, return the first letter to appear twice.\nNote:\n\nA letter a appears twice before another letter b if the second occurrence of a is before the second occurrence of b.\ns will contain at least one letter that appears twice.",
+        "examples": [
+            "Example 1:\nInput: s = \"abccbaacz\"\nOutput: \"c\"\nExplanation:\nThe letter 'a' appears on the indexes 0, 5 and 6.\nThe letter 'b' appears on the indexes 1 and 4.\nThe letter 'c' appears on the indexes 2, 3 and 7.\nThe letter 'z' appears on the index 8.\nThe letter 'c' is the first letter to appear twice, because out of all the letters the index of its second occurrence is the smallest.",
+            "Example 2:\nInput: s = \"abcdd\"\nOutput: \"d\"\nExplanation:\nThe only letter that appears twice is 'd' so we return 'd'."
+        ],
+        "constraints": "Constraints:\n\n2 <= s.length <= 100\ns consists of lowercase English letters.\ns has at least one repeated letter.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Counting"
+        ],
+        "title-slug": "first-letter-to-appear-twice"
+    },
+    {
+        "leetcode-id": 2352,
+        "title": "Equal Row and Column Pairs",
+        "difficulty": 2,
+        "description": "Given a 0-indexed n x n integer matrix grid, return the number of pairs (ri, cj) such that row ri and column cj are equal.\nA row and column pair is considered equal if they contain the same elements in the same order (i.e., an equal array).",
+        "examples": [
+            "Example 1:\nInput: grid = [[3,2,1],[1,7,6],[2,7,7]]\nOutput: 1\nExplanation: There is 1 equal row and column pair:\n- (Row 2, Column 1): [2,7,7]",
+            "Example 2:\nInput: grid = [[3,1,2,2],[1,4,4,5],[2,4,2,2],[2,4,2,2]]\nOutput: 3\nExplanation: There are 3 equal row and column pairs:\n- (Row 0, Column 0): [3,1,2,2]\n- (Row 2, Column 2): [2,4,2,2]\n- (Row 3, Column 2): [2,4,2,2]"
+        ],
+        "constraints": "Constraints:\n\nn == grid.length == grid[i].length\n1 <= n <= 200\n1 <= grid[i][j] <= 10^5",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Matrix",
+            "Simulation"
+        ],
+        "title-slug": "equal-row-and-column-pairs"
+    },
+    {
+        "leetcode-id": 2353,
+        "title": "Design a Food Rating System",
+        "difficulty": 2,
+        "description": "Design a food rating system that can do the following:\n\nModify the rating of a food item listed in the system.\nReturn the highest-rated food item for a type of cuisine in the system.\n\nImplement the FoodRatings class:\n\nFoodRatings(String[] foods, String[] cuisines, int[] ratings) Initializes the system. The food items are described by foods, cuisines and ratings, all of which have a length of n.\n\n\t\nfoods[i] is the name of the i^th food,\ncuisines[i] is the type of cuisine of the i^th food, and\nratings[i] is the initial rating of the i^th food.\n\n\nvoid changeRating(String food, int newRating) Changes the rating of the food item with the name food.\nString highestRated(String cuisine) Returns the name of the food item that has the highest rating for the given type of cuisine. If there is a tie, return the item with the lexicographically smaller name.\n\nNote that a string x is lexicographically smaller than string y if x comes before y in dictionary order, that is, either x is a prefix of y, or if i is the first position such that x[i] != y[i], then x[i] comes before y[i] in alphabetic order.",
+        "examples": [
+            "Example 1:\nInput\n[\"FoodRatings\", \"highestRated\", \"highestRated\", \"changeRating\", \"highestRated\", \"changeRating\", \"highestRated\"]\n[[[\"kimchi\", \"miso\", \"sushi\", \"moussaka\", \"ramen\", \"bulgogi\"], [\"korean\", \"japanese\", \"japanese\", \"greek\", \"japanese\", \"korean\"], [9, 12, 8, 15, 14, 7]], [\"korean\"], [\"japanese\"], [\"sushi\", 16], [\"japanese\"], [\"ramen\", 16], [\"japanese\"]]\nOutput\n[null, \"kimchi\", \"ramen\", null, \"sushi\", null, \"ramen\"]\n\nExplanation\nFoodRatings foodRatings = new FoodRatings([\"kimchi\", \"miso\", \"sushi\", \"moussaka\", \"ramen\", \"bulgogi\"], [\"korean\", \"japanese\", \"japanese\", \"greek\", \"japanese\", \"korean\"], [9, 12, 8, 15, 14, 7]);\nfoodRatings.highestRated(\"korean\"); // return \"kimchi\"\n                                    // \"kimchi\" is the highest rated korean food with a rating of 9.\nfoodRatings.highestRated(\"japanese\"); // return \"ramen\"\n                                      // \"ramen\" is the highest rated japanese food with a rating of 14.\nfoodRatings.changeRating(\"sushi\", 16); // \"sushi\" now has a rating of 16.\nfoodRatings.highestRated(\"japanese\"); // return \"sushi\"\n                                      // \"sushi\" is the highest rated japanese food with a rating of 16.\nfoodRatings.changeRating(\"ramen\", 16); // \"ramen\" now has a rating of 16.\nfoodRatings.highestRated(\"japanese\"); // return \"ramen\"\n                                      // Both \"sushi\" and \"ramen\" have a rating of 16.\n                                      // However, \"ramen\" is lexicographically smaller than \"sushi\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 2 * 10^4\nn == foods.length == cuisines.length == ratings.length\n1 <= foods[i].length, cuisines[i].length <= 10\nfoods[i], cuisines[i] consist of lowercase English letters.\n1 <= ratings[i] <= 10^8\nAll the strings in foods are distinct.\nfood will be the name of a food item in the system across all calls to changeRating.\ncuisine will be a type of cuisine of at least one food item in the system across all calls to highestRated.\nAt most 2 * 10^4 calls in total will be made to changeRating and highestRated.",
+        "tags": [
+            "Hash Table",
+            "Design",
+            "Heap (Priority Queue)",
+            "Ordered Set"
+        ],
+        "title-slug": "design-a-food-rating-system"
+    },
+    {
+        "leetcode-id": 2354,
+        "title": "Number of Excellent Pairs",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed positive integer array nums and a positive integer k.\nA pair of numbers (num1, num2) is called excellent if the following conditions are satisfied:\n\nBoth the numbers num1 and num2 exist in the array nums.\nThe sum of the number of set bits in num1 OR num2 and num1 AND num2 is greater than or equal to k, where OR is the bitwise OR operation and AND is the bitwise AND operation.\n\nReturn the number of distinct excellent pairs.\nTwo pairs (a, b) and (c, d) are considered distinct if either a != c or b != d. For example, (1, 2) and (2, 1) are distinct.\nNote that a pair (num1, num2) such that num1 == num2 can also be excellent if you have at least one occurrence of num1 in the array.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,3,1], k = 3\nOutput: 5\nExplanation: The excellent pairs are the following:\n- (3, 3). (3 AND 3) and (3 OR 3) are both equal to (11) in binary. The total number of set bits is 2 + 2 = 4, which is greater than or equal to k = 3.\n- (2, 3) and (3, 2). (2 AND 3) is equal to (10) in binary, and (2 OR 3) is equal to (11) in binary. The total number of set bits is 1 + 2 = 3.\n- (1, 3) and (3, 1). (1 AND 3) is equal to (01) in binary, and (1 OR 3) is equal to (11) in binary. The total number of set bits is 1 + 2 = 3.\nSo the number of excellent pairs is 5.",
+            "Example 2:\nInput: nums = [5,1,1], k = 10\nOutput: 0\nExplanation: There are no excellent pairs for this array."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\n1 <= k <= 60",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Binary Search",
+            "Bit Manipulation"
+        ],
+        "title-slug": "number-of-excellent-pairs"
+    },
+    {
+        "leetcode-id": 2357,
+        "title": "Make Array Zero by Subtracting Equal Amounts",
+        "difficulty": 1,
+        "description": "You are given a non-negative integer array nums. In one operation, you must:\n\nChoose a positive integer x such that x is less than or equal to the smallest non-zero element in nums.\nSubtract x from every positive element in nums.\n\nReturn the minimum number of operations to make every element in nums equal to 0.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,5,0,3,5]\nOutput: 3\nExplanation:\nIn the first operation, choose x = 1. Now, nums = [0,4,0,2,4].\nIn the second operation, choose x = 2. Now, nums = [0,2,0,0,2].\nIn the third operation, choose x = 2. Now, nums = [0,0,0,0,0].",
+            "Example 2:\nInput: nums = [0]\nOutput: 0\nExplanation: Each element in nums is already 0 so no operations are needed."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 100\n0 <= nums[i] <= 100",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Greedy",
+            "Sorting",
+            "Heap (Priority Queue)",
+            "Simulation"
+        ],
+        "title-slug": "make-array-zero-by-subtracting-equal-amounts"
+    },
+    {
+        "leetcode-id": 2358,
+        "title": "Maximum Number of Groups Entering a Competition",
+        "difficulty": 2,
+        "description": "You are given a positive integer array grades which represents the grades of students in a university. You would like to enter all these students into a competition in ordered non-empty groups, such that the ordering meets the following conditions:\n\nThe sum of the grades of students in the i^th group is less than the sum of the grades of students in the (i + 1)^th group, for all groups (except the last).\nThe total number of students in the i^th group is less than the total number of students in the (i + 1)^th group, for all groups (except the last).\n\nReturn the maximum number of groups that can be formed.",
+        "examples": [
+            "Example 1:\nInput: grades = [10,6,12,7,3,5]\nOutput: 3\nExplanation: The following is a possible way to form 3 groups of students:\n- 1^st group has the students with grades = [12]. Sum of grades: 12. Student count: 1\n- 2^nd group has the students with grades = [6,7]. Sum of grades: 6 + 7 = 13. Student count: 2\n- 3^rd group has the students with grades = [10,3,5]. Sum of grades: 10 + 3 + 5 = 18. Student count: 3\nIt can be shown that it is not possible to form more than 3 groups.",
+            "Example 2:\nInput: grades = [8,8]\nOutput: 1\nExplanation: We can only form 1 group, since forming 2 groups would lead to an equal number of students in both groups."
+        ],
+        "constraints": "Constraints:\n\n1 <= grades.length <= 10^5\n1 <= grades[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Math",
+            "Binary Search",
+            "Greedy"
+        ],
+        "title-slug": "maximum-number-of-groups-entering-a-competition"
+    },
+    {
+        "leetcode-id": 2359,
+        "title": "Find Closest Node to Given Two Nodes",
+        "difficulty": 2,
+        "description": "You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge.\nThe graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no outgoing edge from i, then edges[i] == -1.\nYou are also given two integers node1 and node2.\nReturn the index of the node that can be reached from both node1 and node2, such that the maximum between the distance from node1 to that node, and from node2 to that node is minimized. If there are multiple answers, return the node with the smallest index, and if no possible answer exists, return -1.\nNote that edges may contain cycles.",
+        "examples": [
+            "Example 1:\nInput: edges = [2,2,3,-1], node1 = 0, node2 = 1\nOutput: 2\nExplanation: The distance from node 0 to node 2 is 1, and the distance from node 1 to node 2 is 1.\nThe maximum of those two distances is 1. It can be proven that we cannot get a node with a smaller maximum distance than 1, so we return node 2.",
+            "Example 2:\nInput: edges = [1,2,-1], node1 = 0, node2 = 2\nOutput: 2\nExplanation: The distance from node 0 to node 2 is 2, and the distance from node 2 to itself is 0.\nThe maximum of those two distances is 2. It can be proven that we cannot get a node with a smaller maximum distance than 2, so we return node 2."
+        ],
+        "constraints": "Constraints:\n\nn == edges.length\n2 <= n <= 10^5\n-1 <= edges[i] < n\nedges[i] != i\n0 <= node1, node2 < n",
+        "tags": [
+            "Depth-First Search",
+            "Graph"
+        ],
+        "title-slug": "find-closest-node-to-given-two-nodes"
+    },
+    {
+        "leetcode-id": 2360,
+        "title": "Longest Cycle in a Graph",
+        "difficulty": 3,
+        "description": "You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge.\nThe graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no outgoing edge from node i, then edges[i] == -1.\nReturn the length of the longest cycle in the graph. If no cycle exists, return -1.\nA cycle is a path that starts and ends at the same node.",
+        "examples": [
+            "Example 1:\nInput: edges = [3,3,4,2,3]\nOutput: 3\nExplanation: The longest cycle in the graph is the cycle: 2 -> 4 -> 3 -> 2.\nThe length of this cycle is 3, so 3 is returned.",
+            "Example 2:\nInput: edges = [2,-1,3,1]\nOutput: -1\nExplanation: There are no cycles in this graph."
+        ],
+        "constraints": "Constraints:\n\nn == edges.length\n2 <= n <= 10^5\n-1 <= edges[i] < n\nedges[i] != i",
+        "tags": [
+            "Depth-First Search",
+            "Graph",
+            "Topological Sort"
+        ],
+        "title-slug": "longest-cycle-in-a-graph"
+    },
+    {
+        "leetcode-id": 2363,
+        "title": "Merge Similar Items",
+        "difficulty": 1,
+        "description": "You are given two 2D integer arrays, items1 and items2, representing two sets of items. Each array items has the following properties:\n\nitems[i] = [valuei, weighti] where valuei represents the value and weighti represents the weight of the i^th item.\nThe value of each item in items is unique.\n\nReturn a 2D integer array ret where ret[i] = [valuei, weighti], with weighti being the sum of weights of all items with value valuei.\nNote: ret should be returned in ascending order by value.",
+        "examples": [
+            "Example 1:\nInput: items1 = [[1,1],[4,5],[3,8]], items2 = [[3,1],[1,5]]\nOutput: [[1,6],[3,9],[4,5]]\nExplanation: \nThe item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 5, total weight = 1 + 5 = 6.\nThe item with value = 3 occurs in items1 with weight = 8 and in items2 with weight = 1, total weight = 8 + 1 = 9.\nThe item with value = 4 occurs in items1 with weight = 5, total weight = 5.  \nTherefore, we return [[1,6],[3,9],[4,5]].",
+            "Example 2:\nInput: items1 = [[1,1],[3,2],[2,3]], items2 = [[2,1],[3,2],[1,3]]\nOutput: [[1,4],[2,4],[3,4]]\nExplanation: \nThe item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 3, total weight = 1 + 3 = 4.\nThe item with value = 2 occurs in items1 with weight = 3 and in items2 with weight = 1, total weight = 3 + 1 = 4.\nThe item with value = 3 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4.\nTherefore, we return [[1,4],[2,4],[3,4]].",
+            "Example 3:\nInput: items1 = [[1,3],[2,2]], items2 = [[7,1],[2,2],[1,4]]\nOutput: [[1,7],[2,4],[7,1]]\nExplanation:\nThe item with value = 1 occurs in items1 with weight = 3 and in items2 with weight = 4, total weight = 3 + 4 = 7. \nThe item with value = 2 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4. \nThe item with value = 7 occurs in items2 with weight = 1, total weight = 1.\nTherefore, we return [[1,7],[2,4],[7,1]]."
+        ],
+        "constraints": "Constraints:\n\n1 <= items1.length, items2.length <= 1000\nitems1[i].length == items2[i].length == 2\n1 <= valuei, weighti <= 1000\nEach valuei in items1 is unique.\nEach valuei in items2 is unique.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sorting",
+            "Ordered Set"
+        ],
+        "title-slug": "merge-similar-items"
+    },
+    {
+        "leetcode-id": 2364,
+        "title": "Count Number of Bad Pairs",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums. A pair of indices (i, j) is a bad pair if i < j and j - i != nums[j] - nums[i].\nReturn the total number of bad pairs in nums.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,1,3,3]\nOutput: 5\nExplanation: The pair (0, 1) is a bad pair since 1 - 0 != 1 - 4.\nThe pair (0, 2) is a bad pair since 2 - 0 != 3 - 4, 2 != -1.\nThe pair (0, 3) is a bad pair since 3 - 0 != 3 - 4, 3 != -1.\nThe pair (1, 2) is a bad pair since 2 - 1 != 3 - 1, 1 != 2.\nThe pair (2, 3) is a bad pair since 3 - 2 != 3 - 3, 1 != 0.\nThere are a total of 5 bad pairs, so we return 5.",
+            "Example 2:\nInput: nums = [1,2,3,4,5]\nOutput: 0\nExplanation: There are no bad pairs."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Hash Table"
+        ],
+        "title-slug": "count-number-of-bad-pairs"
+    },
+    {
+        "leetcode-id": 2365,
+        "title": "Task Scheduler II",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array of positive integers tasks, representing tasks that need to be completed in order, where tasks[i] represents the type of the i^th task.\nYou are also given a positive integer space, which represents the minimum number of days that must pass after the completion of a task before another task of the same type can be performed.\nEach day, until all tasks have been completed, you must either:\n\nComplete the next task from tasks, or\nTake a break.\n\nReturn the minimum number of days needed to complete all tasks.",
+        "examples": [
+            "Example 1:\nInput: tasks = [1,2,1,2,3,1], space = 3\nOutput: 9\nExplanation:\nOne way to complete all tasks in 9 days is as follows:\nDay 1: Complete the 0th task.\nDay 2: Complete the 1st task.\nDay 3: Take a break.\nDay 4: Take a break.\nDay 5: Complete the 2nd task.\nDay 6: Complete the 3rd task.\nDay 7: Take a break.\nDay 8: Complete the 4th task.\nDay 9: Complete the 5th task.\nIt can be shown that the tasks cannot be completed in less than 9 days.",
+            "Example 2:\nInput: tasks = [5,8,8,5], space = 2\nOutput: 6\nExplanation:\nOne way to complete all tasks in 6 days is as follows:\nDay 1: Complete the 0th task.\nDay 2: Complete the 1st task.\nDay 3: Take a break.\nDay 4: Take a break.\nDay 5: Complete the 2nd task.\nDay 6: Complete the 3rd task.\nIt can be shown that the tasks cannot be completed in less than 6 days."
+        ],
+        "constraints": "Constraints:\n\n1 <= tasks.length <= 10^5\n1 <= tasks[i] <= 10^9\n1 <= space <= tasks.length",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Simulation"
+        ],
+        "title-slug": "task-scheduler-ii"
+    },
+    {
+        "leetcode-id": 2366,
+        "title": "Minimum Replacements to Sort the Array",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed integer array nums. In one operation you can replace any element of the array with any two elements that sum to it.\n\nFor example, consider nums = [5,6,7]. In one operation, we can replace nums[1] with 2 and 4 and convert nums to [5,2,4,7].\n\nReturn the minimum number of operations to make an array that is sorted in non-decreasing order.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,9,3]\nOutput: 2\nExplanation: Here are the steps to sort the array in non-decreasing order:\n- From [3,9,3], replace the 9 with 3 and 6 so the array becomes [3,3,6,3]\n- From [3,3,6,3], replace the 6 with 3 and 3 so the array becomes [3,3,3,3,3]\nThere are 2 steps to sort the array in non-decreasing order. Therefore, we return 2.",
+            "Example 2:\nInput: nums = [1,2,3,4,5]\nOutput: 0\nExplanation: The array is already in non-decreasing order. Therefore, we return 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Math",
+            "Greedy"
+        ],
+        "title-slug": "minimum-replacements-to-sort-the-array"
+    },
+    {
+        "leetcode-id": 2367,
+        "title": "Number of Arithmetic Triplets",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions are met:\n\ni < j < k,\nnums[j] - nums[i] == diff, and\nnums[k] - nums[j] == diff.\n\nReturn the number of unique arithmetic triplets.",
+        "examples": [
+            "Example 1:\nInput: nums = [0,1,4,6,7,10], diff = 3\nOutput: 2\nExplanation:\n(1, 2, 4) is an arithmetic triplet because both 7 - 4 == 3 and 4 - 1 == 3.\n(2, 4, 5) is an arithmetic triplet because both 10 - 7 == 3 and 7 - 4 == 3.",
+            "Example 2:\nInput: nums = [4,5,6,7,8,9], diff = 2\nOutput: 2\nExplanation:\n(0, 2, 4) is an arithmetic triplet because both 8 - 6 == 2 and 6 - 4 == 2.\n(1, 3, 5) is an arithmetic triplet because both 9 - 7 == 2 and 7 - 5 == 2."
+        ],
+        "constraints": "Constraints:\n\n3 <= nums.length <= 200\n0 <= nums[i] <= 200\n1 <= diff <= 50\nnums is strictly increasing.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Two Pointers",
+            "Enumeration"
+        ],
+        "title-slug": "number-of-arithmetic-triplets"
+    },
+    {
+        "leetcode-id": 2368,
+        "title": "Reachable Nodes With Restrictions",
+        "difficulty": 2,
+        "description": "There is an undirected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.\nYou are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given an integer array restricted which represents restricted nodes.\nReturn the maximum number of nodes you can reach from node 0 without visiting a restricted node.\nNote that node 0 will not be a restricted node.",
+        "examples": [
+            "Example 1:\nInput: n = 7, edges = [[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]], restricted = [4,5]\nOutput: 4\nExplanation: The diagram above shows the tree.\nWe have that [0,1,2,3] are the only nodes that can be reached from node 0 without visiting a restricted node.",
+            "Example 2:\nInput: n = 7, edges = [[0,1],[0,2],[0,5],[0,4],[3,2],[6,5]], restricted = [4,2,1]\nOutput: 3\nExplanation: The diagram above shows the tree.\nWe have that [0,5,6] are the only nodes that can be reached from node 0 without visiting a restricted node."
+        ],
+        "constraints": "Constraints:\n\n2 <= n <= 10^5\nedges.length == n - 1\nedges[i].length == 2\n0 <= ai, bi < n\nai != bi\nedges represents a valid tree.\n1 <= restricted.length < n\n1 <= restricted[i] < n\nAll the values of restricted are unique.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Tree",
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Graph"
+        ],
+        "title-slug": "reachable-nodes-with-restrictions"
+    },
+    {
+        "leetcode-id": 2369,
+        "title": "Check if There is a Valid Partition For The Array",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums. You have to partition the array into one or more contiguous subarrays.\nWe call a partition of the array valid if each of the obtained subarrays satisfies one of the following conditions:\n\nThe subarray consists of exactly 2, equal elements. For example, the subarray [2,2] is good.\nThe subarray consists of exactly 3, equal elements. For example, the subarray [4,4,4] is good.\nThe subarray consists of exactly 3 consecutive increasing elements, that is, the difference between adjacent elements is 1. For example, the subarray [3,4,5] is good, but the subarray [1,3,5] is not.\n\nReturn true if the array has at least one valid partition. Otherwise, return false.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,4,4,5,6]\nOutput: true\nExplanation: The array can be partitioned into the subarrays [4,4] and [4,5,6].\nThis partition is valid, so we return true.",
+            "Example 2:\nInput: nums = [1,1,1,2]\nOutput: false\nExplanation: There is no valid partition for this array."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 10^5\n1 <= nums[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Dynamic Programming"
+        ],
+        "title-slug": "check-if-there-is-a-valid-partition-for-the-array"
+    },
+    {
+        "leetcode-id": 2370,
+        "title": "Longest Ideal Subsequence",
+        "difficulty": 2,
+        "description": "You are given a string s consisting of lowercase letters and an integer k. We call a string t ideal if the following conditions are satisfied:\n\nt is a subsequence of the string s.\nThe absolute difference in the alphabet order of every two adjacent letters in t is less than or equal to k.\n\nReturn the length of the longest ideal string.\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.\nNote that the alphabet order is not cyclic. For example, the absolute difference in the alphabet order of 'a' and 'z' is 25, not 1.",
+        "examples": [
+            "Example 1:\nInput: s = \"acfgbd\", k = 2\nOutput: 4\nExplanation: The longest ideal string is \"acbd\". The length of this string is 4, so 4 is returned.\nNote that \"acfgbd\" is not ideal because 'c' and 'f' have a difference of 3 in alphabet order.",
+            "Example 2:\nInput: s = \"abcd\", k = 3\nOutput: 4\nExplanation: The longest ideal string is \"abcd\". The length of this string is 4, so 4 is returned."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^5\n0 <= k <= 25\ns consists of lowercase English letters.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Dynamic Programming"
+        ],
+        "title-slug": "longest-ideal-subsequence"
+    },
+    {
+        "leetcode-id": 2373,
+        "title": "Largest Local Values in a Matrix",
+        "difficulty": 1,
+        "description": "You are given an n x n integer matrix grid.\nGenerate an integer matrix maxLocal of size (n - 2) x (n - 2) such that:\n\nmaxLocal[i][j] is equal to the largest value of the 3 x 3 matrix in grid centered around row i + 1 and column j + 1.\n\nIn other words, we want to find the largest value in every contiguous 3 x 3 matrix in grid.\nReturn the generated matrix.",
+        "examples": [
+            "Example 1:\nInput: grid = [[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]\nOutput: [[9,9],[8,6]]\nExplanation: The diagram above shows the original matrix and the generated matrix.\nNotice that each value in the generated matrix corresponds to the largest value of a contiguous 3 x 3 matrix in grid.",
+            "Example 2:\nInput: grid = [[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]]\nOutput: [[2,2,2],[2,2,2],[2,2,2]]\nExplanation: Notice that the 2 is contained within every contiguous 3 x 3 matrix in grid."
+        ],
+        "constraints": "Constraints:\n\nn == grid.length == grid[i].length\n3 <= n <= 100\n1 <= grid[i][j] <= 100",
+        "tags": [
+            "Array",
+            "Matrix"
+        ],
+        "title-slug": "largest-local-values-in-a-matrix"
+    },
+    {
+        "leetcode-id": 2374,
+        "title": "Node With Highest Edge Score",
+        "difficulty": 2,
+        "description": "You are given a directed graph with n nodes labeled from 0 to n - 1, where each node has exactly one outgoing edge.\nThe graph is represented by a given 0-indexed integer array edges of length n, where edges[i] indicates that there is a directed edge from node i to node edges[i].\nThe edge score of a node i is defined as the sum of the labels of all the nodes that have an edge pointing to i.\nReturn the node with the highest edge score. If multiple nodes have the same edge score, return the node with the smallest index.",
+        "examples": [
+            "Example 1:\nInput: edges = [1,0,0,0,0,7,7,5]\nOutput: 7\nExplanation:\n- The nodes 1, 2, 3 and 4 have an edge pointing to node 0. The edge score of node 0 is 1 + 2 + 3 + 4 = 10.\n- The node 0 has an edge pointing to node 1. The edge score of node 1 is 0.\n- The node 7 has an edge pointing to node 5. The edge score of node 5 is 7.\n- The nodes 5 and 6 have an edge pointing to node 7. The edge score of node 7 is 5 + 6 = 11.\nNode 7 has the highest edge score so return 7.",
+            "Example 2:\nInput: edges = [2,0,0,2]\nOutput: 0\nExplanation:\n- The nodes 1 and 2 have an edge pointing to node 0. The edge score of node 0 is 1 + 2 = 3.\n- The nodes 0 and 3 have an edge pointing to node 2. The edge score of node 2 is 0 + 3 = 3.\nNodes 0 and 2 both have an edge score of 3. Since node 0 has a smaller index, we return 0."
+        ],
+        "constraints": "Constraints:\n\nn == edges.length\n2 <= n <= 10^5\n0 <= edges[i] < n\nedges[i] != i",
+        "tags": [
+            "Hash Table",
+            "Graph"
+        ],
+        "title-slug": "node-with-highest-edge-score"
+    },
+    {
+        "leetcode-id": 2375,
+        "title": "Construct Smallest Number From DI String",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed string pattern of length n consisting of the characters 'I' meaning increasing and 'D' meaning decreasing.\nA 0-indexed string num of length n + 1 is created using the following conditions:\n\nnum consists of the digits '1' to '9', where each digit is used at most once.\nIf pattern[i] == 'I', then num[i] < num[i + 1].\nIf pattern[i] == 'D', then num[i] > num[i + 1].\n\nReturn the lexicographically smallest possible string num that meets the conditions.",
+        "examples": [
+            "Example 1:\nInput: pattern = \"IIIDIDDD\"\nOutput: \"123549876\"\nExplanation:\nAt indices 0, 1, 2, and 4 we must have that num[i] < num[i+1].\nAt indices 3, 5, 6, and 7 we must have that num[i] > num[i+1].\nSome possible values of num are \"245639871\", \"135749862\", and \"123849765\".\nIt can be proven that \"123549876\" is the smallest possible num that meets the conditions.\nNote that \"123414321\" is not possible because the digit '1' is used more than once.",
+            "Example 2:\nInput: pattern = \"DDD\"\nOutput: \"4321\"\nExplanation:\nSome possible values of num are \"9876\", \"7321\", and \"8742\".\nIt can be proven that \"4321\" is the smallest possible num that meets the conditions."
+        ],
+        "constraints": "Constraints:\n\n1 <= pattern.length <= 8\npattern consists of only the letters 'I' and 'D'.",
+        "tags": [
+            "String",
+            "Backtracking",
+            "Stack",
+            "Greedy"
+        ],
+        "title-slug": "construct-smallest-number-from-di-string"
+    },
+    {
+        "leetcode-id": 2376,
+        "title": "Count Special Integers",
+        "difficulty": 3,
+        "description": "We call a positive integer special if all of its digits are distinct.\nGiven a positive integer n, return the number of special integers that belong to the interval [1, n].",
+        "examples": [
+            "Example 1:\nInput: n = 20\nOutput: 19\nExplanation: All the integers from 1 to 20, except 11, are special. Thus, there are 19 special integers.",
+            "Example 2:\nInput: n = 5\nOutput: 5\nExplanation: All the integers from 1 to 5 are special.",
+            "Example 3:\nInput: n = 135\nOutput: 110\nExplanation: There are 110 integers from 1 to 135 that are special.\nSome of the integers that are not special are: 22, 114, and 131."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 2 * 10^9",
+        "tags": [
+            "Math",
+            "Dynamic Programming"
+        ],
+        "title-slug": "count-special-integers"
+    },
+    {
+        "leetcode-id": 2379,
+        "title": "Minimum Recolors to Get K Consecutive Black Blocks",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the i^th block. The characters 'W' and 'B' denote the colors white and black, respectively.\nYou are also given an integer k, which is the desired number of consecutive black blocks.\nIn one operation, you can recolor a white block such that it becomes a black block.\nReturn the minimum number of operations needed such that there is at least one occurrence of k consecutive black blocks.",
+        "examples": [
+            "Example 1:\nInput: blocks = \"WBBWWBBWBW\", k = 7\nOutput: 3\nExplanation:\nOne way to achieve 7 consecutive black blocks is to recolor the 0th, 3rd, and 4th blocks\nso that blocks = \"BBBBBBBWBW\". \nIt can be shown that there is no way to achieve 7 consecutive black blocks in less than 3 operations.\nTherefore, we return 3.",
+            "Example 2:\nInput: blocks = \"WBWBBBW\", k = 2\nOutput: 0\nExplanation:\nNo changes need to be made, since 2 consecutive black blocks already exist.\nTherefore, we return 0."
+        ],
+        "constraints": "Constraints:\n\nn == blocks.length\n1 <= n <= 100\nblocks[i] is either 'W' or 'B'.\n1 <= k <= n",
+        "tags": [
+            "String",
+            "Sliding Window"
+        ],
+        "title-slug": "minimum-recolors-to-get-k-consecutive-black-blocks"
+    },
+    {
+        "leetcode-id": 2380,
+        "title": "Time Needed to Rearrange a Binary String",
+        "difficulty": 2,
+        "description": "You are given a binary string s. In one second, all occurrences of \"01\" are simultaneously replaced with \"10\". This process repeats until no occurrences of \"01\" exist.\nReturn the number of seconds needed to complete this process.",
+        "examples": [
+            "Example 1:\nInput: s = \"0110101\"\nOutput: 4\nExplanation: \nAfter one second, s becomes \"1011010\".\nAfter another second, s becomes \"1101100\".\nAfter the third second, s becomes \"1110100\".\nAfter the fourth second, s becomes \"1111000\".\nNo occurrence of \"01\" exists any longer, and the process needed 4 seconds to complete,\nso we return 4.",
+            "Example 2:\nInput: s = \"11100\"\nOutput: 0\nExplanation:\nNo occurrence of \"01\" exists in s, and the processes needed 0 seconds to complete,\nso we return 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns[i] is either '0' or '1'.\n\n\u00a0\nFollow up:\nCan you solve this problem in O(n) time complexity?",
+        "tags": [
+            "String",
+            "Dynamic Programming",
+            "Simulation"
+        ],
+        "title-slug": "time-needed-to-rearrange-a-binary-string"
+    },
+    {
+        "leetcode-id": 2381,
+        "title": "Shifting Letters II",
+        "difficulty": 2,
+        "description": "You are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [starti, endi, directioni]. For every i, shift the characters in s from the index starti to the index endi (inclusive) forward if directioni = 1, or shift the characters backward if directioni = 0.\nShifting a character forward means replacing it with the next letter in the alphabet (wrapping around so that 'z' becomes 'a'). Similarly, shifting a character backward means replacing it with the previous letter in the alphabet (wrapping around so that 'a' becomes 'z').\nReturn the final string after all such shifts to s are applied.",
+        "examples": [
+            "Example 1:\nInput: s = \"abc\", shifts = [[0,1,0],[1,2,1],[0,2,1]]\nOutput: \"ace\"\nExplanation: Firstly, shift the characters from index 0 to index 1 backward. Now s = \"zac\".\nSecondly, shift the characters from index 1 to index 2 forward. Now s = \"zbd\".\nFinally, shift the characters from index 0 to index 2 forward. Now s = \"ace\".",
+            "Example 2:\nInput: s = \"dztz\", shifts = [[0,0,0],[1,1,1]]\nOutput: \"catz\"\nExplanation: Firstly, shift the characters from index 0 to index 0 backward. Now s = \"cztz\".\nFinally, shift the characters from index 1 to index 1 forward. Now s = \"catz\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length, shifts.length <= 5 * 10^4\nshifts[i].length == 3\n0 <= starti <= endi < s.length\n0 <= directioni <= 1\ns consists of lowercase English letters.",
+        "tags": [
+            "Array",
+            "String",
+            "Prefix Sum"
+        ],
+        "title-slug": "shifting-letters-ii"
+    },
+    {
+        "leetcode-id": 2382,
+        "title": "Maximum Segment Sum After Removals",
+        "difficulty": 3,
+        "description": "You are given two 0-indexed integer arrays nums and removeQueries, both of length n. For the i^th query, the element in nums at the index removeQueries[i] is removed, splitting nums into different segments.\nA segment is a contiguous sequence of positive integers in nums. A segment sum is the sum of every element in a segment.\nReturn an integer array answer, of length n, where answer[i] is the maximum segment sum after applying the i^th removal.\nNote: The same index will not be removed more than once.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,5,6,1], removeQueries = [0,3,2,4,1]\nOutput: [14,7,2,2,0]\nExplanation: Using 0 to indicate a removed element, the answer is as follows:\nQuery 1: Remove the 0th element, nums becomes [0,2,5,6,1] and the maximum segment sum is 14 for segment [2,5,6,1].\nQuery 2: Remove the 3rd element, nums becomes [0,2,5,0,1] and the maximum segment sum is 7 for segment [2,5].\nQuery 3: Remove the 2nd element, nums becomes [0,2,0,0,1] and the maximum segment sum is 2 for segment [2]. \nQuery 4: Remove the 4th element, nums becomes [0,2,0,0,0] and the maximum segment sum is 2 for segment [2]. \nQuery 5: Remove the 1st element, nums becomes [0,0,0,0,0] and the maximum segment sum is 0, since there are no segments.\nFinally, we return [14,7,2,2,0].",
+            "Example 2:\nInput: nums = [3,2,11,1], removeQueries = [3,2,1,0]\nOutput: [16,5,3,0]\nExplanation: Using 0 to indicate a removed element, the answer is as follows:\nQuery 1: Remove the 3rd element, nums becomes [3,2,11,0] and the maximum segment sum is 16 for segment [3,2,11].\nQuery 2: Remove the 2nd element, nums becomes [3,2,0,0] and the maximum segment sum is 5 for segment [3,2].\nQuery 3: Remove the 1st element, nums becomes [3,0,0,0] and the maximum segment sum is 3 for segment [3].\nQuery 4: Remove the 0th element, nums becomes [0,0,0,0] and the maximum segment sum is 0, since there are no segments.\nFinally, we return [16,5,3,0]."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length == removeQueries.length\n1 <= n <= 10^5\n1 <= nums[i] <= 10^9\n0 <= removeQueries[i] < n\nAll the values of removeQueries are unique.",
+        "tags": [
+            "Array",
+            "Union Find",
+            "Prefix Sum",
+            "Ordered Set"
+        ],
+        "title-slug": "maximum-segment-sum-after-removals"
+    },
+    {
+        "leetcode-id": 2383,
+        "title": "Minimum Hours of Training to Win a Competition",
+        "difficulty": 1,
+        "description": "You are entering a competition, and are given two positive integers initialEnergy and initialExperience denoting your initial energy and initial experience respectively.\nYou are also given two 0-indexed integer arrays energy and experience, both of length n.\nYou will face n opponents in order. The energy and experience of the i^th opponent is denoted by energy[i] and experience[i] respectively. When you face an opponent, you need to have both strictly greater experience and energy to defeat them and move to the next opponent if available.\nDefeating the i^th opponent increases your experience by experience[i], but decreases your energy by energy[i].\nBefore starting the competition, you can train for some number of hours. After each hour of training, you can either choose to increase your initial experience by one, or increase your initial energy by one.\nReturn the minimum number of training hours required to defeat all n opponents.",
+        "examples": [
+            "Example 1:\nInput: initialEnergy = 5, initialExperience = 3, energy = [1,4,3,2], experience = [2,6,3,1]\nOutput: 8\nExplanation: You can increase your energy to 11 after 6 hours of training, and your experience to 5 after 2 hours of training.\nYou face the opponents in the following order:\n- You have more energy and experience than the 0^th opponent so you win.\n  Your energy becomes 11 - 1 = 10, and your experience becomes 5 + 2 = 7.\n- You have more energy and experience than the 1^st opponent so you win.\n  Your energy becomes 10 - 4 = 6, and your experience becomes 7 + 6 = 13.\n- You have more energy and experience than the 2^nd opponent so you win.\n  Your energy becomes 6 - 3 = 3, and your experience becomes 13 + 3 = 16.\n- You have more energy and experience than the 3^rd opponent so you win.\n  Your energy becomes 3 - 2 = 1, and your experience becomes 16 + 1 = 17.\nYou did a total of 6 + 2 = 8 hours of training before the competition, so we return 8.\nIt can be proven that no smaller answer exists.",
+            "Example 2:\nInput: initialEnergy = 2, initialExperience = 4, energy = [1], experience = [3]\nOutput: 0\nExplanation: You do not need any additional energy or experience to win the competition, so we return 0."
+        ],
+        "constraints": "Constraints:\n\nn == energy.length == experience.length\n1 <= n <= 100\n1 <= initialEnergy, initialExperience, energy[i], experience[i] <= 100",
+        "tags": [
+            "Array",
+            "Greedy"
+        ],
+        "title-slug": "minimum-hours-of-training-to-win-a-competition"
+    },
+    {
+        "leetcode-id": 2384,
+        "title": "Largest Palindromic Number",
+        "difficulty": 2,
+        "description": "You are given a string num consisting of digits only.\nReturn the largest palindromic integer (in the form of a string) that can be formed using digits taken from num. It should not contain leading zeroes.\nNotes:\n\nYou do not need to use all the digits of num, but you must use at least one digit.\nThe digits can be reordered.",
+        "examples": [
+            "Example 1:\nInput: num = \"444947137\"\nOutput: \"7449447\"\nExplanation: \nUse the digits \"4449477\" from \"444947137\" to form the palindromic integer \"7449447\".\nIt can be shown that \"7449447\" is the largest palindromic integer that can be formed.",
+            "Example 2:\nInput: num = \"00009\"\nOutput: \"9\"\nExplanation: \nIt can be shown that \"9\" is the largest palindromic integer that can be formed.\nNote that the integer returned should not contain leading zeroes."
+        ],
+        "constraints": "Constraints:\n\n1 <= num.length <= 10^5\nnum consists of digits.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Greedy"
+        ],
+        "title-slug": "largest-palindromic-number"
+    },
+    {
+        "leetcode-id": 2385,
+        "title": "Amount of Time for Binary Tree to Be Infected",
+        "difficulty": 2,
+        "description": "You are given the root of a binary tree with unique values, and an integer start. At minute 0, an infection starts from the node with value start.\nEach minute, a node becomes infected if:\n\nThe node is currently uninfected.\nThe node is adjacent to an infected node.\n\nReturn the number of minutes needed for the entire tree to be infected.",
+        "examples": [
+            "Example 1:\nInput: root = [1,5,3,null,4,10,6,9,2], start = 3\nOutput: 4\nExplanation: The following nodes are infected during:\n- Minute 0: Node 3\n- Minute 1: Nodes 1, 10 and 6\n- Minute 2: Node 5\n- Minute 3: Node 4\n- Minute 4: Nodes 9 and 2\nIt takes 4 minutes for the whole tree to be infected so we return 4.",
+            "Example 2:\nInput: root = [1], start = 1\nOutput: 0\nExplanation: At minute 0, the only node in the tree is infected so we return 0."
+        ],
+        "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^5].\n1 <= Node.val <= 10^5\nEach node has a unique value.\nA node with a value of start exists in the tree.",
+        "tags": [
+            "Tree",
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Binary Tree"
+        ],
+        "title-slug": "amount-of-time-for-binary-tree-to-be-infected"
+    },
+    {
+        "leetcode-id": 2386,
+        "title": "Find the K-Sum of an Array",
+        "difficulty": 3,
+        "description": "You are given an integer array nums and a positive integer k. You can choose any subsequence of the array and sum all of its elements together.\nWe define the K-Sum of the array as the k^th largest subsequence sum that can be obtained (not necessarily distinct).\nReturn the K-Sum of the array.\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.\nNote that the empty subsequence is considered to have a sum of 0.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,4,-2], k = 5\nOutput: 2\nExplanation: All the possible subsequence sums that we can obtain are the following sorted in decreasing order:\n- 6, 4, 4, 2, 2, 0, 0, -2.\nThe 5-Sum of the array is 2.",
+            "Example 2:\nInput: nums = [1,-2,3,4,-10,12], k = 16\nOutput: 10\nExplanation: The 16-Sum of the array is 10."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^5\n-10^9 <= nums[i] <= 10^9\n1 <= k <= min(2000, 2^n)",
+        "tags": [
+            "Array",
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "find-the-k-sum-of-an-array"
+    },
+    {
+        "leetcode-id": 2389,
+        "title": "Longest Subsequence With Limited Sum",
+        "difficulty": 1,
+        "description": "You are given an integer array nums of length n, and an integer array queries of length m.\nReturn an array answer of length m where answer[i] is the maximum size of a subsequence that you can take from nums such that the sum of its elements is less than or equal to queries[i].\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,5,2,1], queries = [3,10,21]\nOutput: [2,3,4]\nExplanation: We answer the queries as follows:\n- The subsequence [2,1] has a sum less than or equal to 3. It can be proven that 2 is the maximum size of such a subsequence, so answer[0] = 2.\n- The subsequence [4,5,1] has a sum less than or equal to 10. It can be proven that 3 is the maximum size of such a subsequence, so answer[1] = 3.\n- The subsequence [4,5,2,1] has a sum less than or equal to 21. It can be proven that 4 is the maximum size of such a subsequence, so answer[2] = 4.",
+            "Example 2:\nInput: nums = [2,3,4,5], queries = [1]\nOutput: [0]\nExplanation: The empty subsequence is the only subsequence that has a sum less than or equal to 1, so answer[0] = 0."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length\nm == queries.length\n1 <= n, m <= 1000\n1 <= nums[i], queries[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Greedy",
+            "Sorting",
+            "Prefix Sum"
+        ],
+        "title-slug": "longest-subsequence-with-limited-sum"
+    },
+    {
+        "leetcode-id": 2390,
+        "title": "Removing Stars From a String",
+        "difficulty": 2,
+        "description": "You are given a string s, which contains stars *.\nIn one operation, you can:\n\nChoose a star in s.\nRemove the closest non-star character to its left, as well as remove the star itself.\n\nReturn the string after all stars have been removed.\nNote:\n\nThe input will be generated such that the operation is always possible.\nIt can be shown that the resulting string will always be unique.",
+        "examples": [
+            "Example 1:\nInput: s = \"leet**cod*e\"\nOutput: \"lecoe\"\nExplanation: Performing the removals from left to right:\n- The closest character to the 1^st star is 't' in \"leet**cod*e\". s becomes \"lee*cod*e\".\n- The closest character to the 2^nd star is 'e' in \"lee*cod*e\". s becomes \"lecod*e\".\n- The closest character to the 3^rd star is 'd' in \"lecod*e\". s becomes \"lecoe\".\nThere are no more stars, so we return \"lecoe\".",
+            "Example 2:\nInput: s = \"erase*****\"\nOutput: \"\"\nExplanation: The entire string is removed, so we return an empty string."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of lowercase English letters and stars *.\nThe operation above can be performed on s.",
+        "tags": [
+            "String",
+            "Stack",
+            "Simulation"
+        ],
+        "title-slug": "removing-stars-from-a-string"
+    },
+    {
+        "leetcode-id": 2391,
+        "title": "Minimum Amount of Time to Collect Garbage",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the i^th house. garbage[i] consists only of the characters 'M', 'P' and 'G' representing one unit of metal, paper and glass garbage respectively. Picking up one unit of any type of garbage takes 1 minute.\nYou are also given a 0-indexed integer array travel where travel[i] is the number of minutes needed to go from house i to house i + 1.\nThere are three garbage trucks in the city, each responsible for picking up one type of garbage. Each garbage truck starts at house 0 and must visit each house in order; however, they do not need to visit every house.\nOnly one garbage truck may be used at any given moment. While one truck is driving or picking up garbage, the other two trucks cannot do anything.\nReturn the minimum number of minutes needed to pick up all the garbage.",
+        "examples": [
+            "Example 1:\nInput: garbage = [\"G\",\"P\",\"GP\",\"GG\"], travel = [2,4,3]\nOutput: 21\nExplanation:\nThe paper garbage truck:\n1. Travels from house 0 to house 1\n2. Collects the paper garbage at house 1\n3. Travels from house 1 to house 2\n4. Collects the paper garbage at house 2\nAltogether, it takes 8 minutes to pick up all the paper garbage.\nThe glass garbage truck:\n1. Collects the glass garbage at house 0\n2. Travels from house 0 to house 1\n3. Travels from house 1 to house 2\n4. Collects the glass garbage at house 2\n5. Travels from house 2 to house 3\n6. Collects the glass garbage at house 3\nAltogether, it takes 13 minutes to pick up all the glass garbage.\nSince there is no metal garbage, we do not need to consider the metal garbage truck.\nTherefore, it takes a total of 8 + 13 = 21 minutes to collect all the garbage.",
+            "Example 2:\nInput: garbage = [\"MMM\",\"PGM\",\"GP\"], travel = [3,10]\nOutput: 37\nExplanation:\nThe metal garbage truck takes 7 minutes to pick up all the metal garbage.\nThe paper garbage truck takes 15 minutes to pick up all the paper garbage.\nThe glass garbage truck takes 15 minutes to pick up all the glass garbage.\nIt takes a total of 7 + 15 + 15 = 37 minutes to collect all the garbage."
+        ],
+        "constraints": "Constraints:\n\n2 <= garbage.length <= 10^5\ngarbage[i] consists of only the letters 'M', 'P', and 'G'.\n1 <= garbage[i].length <= 10\ntravel.length == garbage.length - 1\n1 <= travel[i] <= 100",
+        "tags": [
+            "Array",
+            "String",
+            "Prefix Sum"
+        ],
+        "title-slug": "minimum-amount-of-time-to-collect-garbage"
+    },
+    {
+        "leetcode-id": 2392,
+        "title": "Build a Matrix With Conditions",
+        "difficulty": 3,
+        "description": "You are given a positive integer k. You are also given:\n\na 2D integer array rowConditions of size n where rowConditions[i] = [abovei, belowi], and\na 2D integer array colConditions of size m where colConditions[i] = [lefti, righti].\n\nThe two arrays contain integers from 1 to k.\nYou have to build a k x k matrix that contains each of the numbers from 1 to k exactly once. The remaining cells should have the value 0.\nThe matrix should also satisfy the following conditions:\n\nThe number abovei should appear in a row that is strictly above the row at which the number belowi appears for all i from 0 to n - 1.\nThe number lefti should appear in a column that is strictly left of the column at which the number righti appears for all i from 0 to m - 1.\n\nReturn any matrix that satisfies the conditions. If no answer exists, return an empty matrix.",
+        "examples": [
+            "Example 1:\nInput: k = 3, rowConditions = [[1,2],[3,2]], colConditions = [[2,1],[3,2]]\nOutput: [[3,0,0],[0,0,1],[0,2,0]]\nExplanation: The diagram above shows a valid example of a matrix that satisfies all the conditions.\nThe row conditions are the following:\n- Number 1 is in row 1, and number 2 is in row 2, so 1 is above 2 in the matrix.\n- Number 3 is in row 0, and number 2 is in row 2, so 3 is above 2 in the matrix.\nThe column conditions are the following:\n- Number 2 is in column 1, and number 1 is in column 2, so 2 is left of 1 in the matrix.\n- Number 3 is in column 0, and number 2 is in column 1, so 3 is left of 2 in the matrix.\nNote that there may be multiple correct answers.",
+            "Example 2:\nInput: k = 3, rowConditions = [[1,2],[2,3],[3,1],[2,3]], colConditions = [[2,1]]\nOutput: []\nExplanation: From the first two conditions, 3 has to be below 1 but the third conditions needs 3 to be above 1 to be satisfied.\nNo matrix can satisfy all the conditions, so we return the empty matrix."
+        ],
+        "constraints": "Constraints:\n\n2 <= k <= 400\n1 <= rowConditions.length, colConditions.length <= 10^4\nrowConditions[i].length == colConditions[i].length == 2\n1 <= abovei, belowi, lefti, righti <= k\nabovei != belowi\nlefti != righti",
+        "tags": [
+            "Array",
+            "Graph",
+            "Topological Sort",
+            "Matrix"
+        ],
+        "title-slug": "build-a-matrix-with-conditions"
+    },
+    {
+        "leetcode-id": 2395,
+        "title": "Find Subarrays With Equal Sum",
+        "difficulty": 1,
+        "description": "Given a 0-indexed integer array nums, determine whether there exist two subarrays of length 2 with equal sum. Note that the two subarrays must begin at different indices.\nReturn true if these subarrays exist, and false otherwise.\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,2,4]\nOutput: true\nExplanation: The subarrays with elements [4,2] and [2,4] have the same sum of 6.",
+            "Example 2:\nInput: nums = [1,2,3,4,5]\nOutput: false\nExplanation: No two subarrays of size 2 have the same sum.",
+            "Example 3:\nInput: nums = [0,0,0]\nOutput: true\nExplanation: The subarrays [nums[0],nums[1]] and [nums[1],nums[2]] have the same sum of 0. \nNote that even though the subarrays have the same content, the two subarrays are considered different because they are in different positions in the original array."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 1000\n-10^9 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Hash Table"
+        ],
+        "title-slug": "find-subarrays-with-equal-sum"
+    },
+    {
+        "leetcode-id": 2396,
+        "title": "Strictly Palindromic Number",
+        "difficulty": 2,
+        "description": "An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic.\nGiven an integer n, return true if n is strictly palindromic and false otherwise.\nA string is palindromic if it reads the same forward and backward.",
+        "examples": [
+            "Example 1:\nInput: n = 9\nOutput: false\nExplanation: In base 2: 9 = 1001 (base 2), which is palindromic.\nIn base 3: 9 = 100 (base 3), which is not palindromic.\nTherefore, 9 is not strictly palindromic so we return false.\nNote that in bases 4, 5, 6, and 7, n = 9 is also not palindromic.",
+            "Example 2:\nInput: n = 4\nOutput: false\nExplanation: We only consider base 2: 4 = 100 (base 2), which is not palindromic.\nTherefore, we return false."
+        ],
+        "constraints": "Constraints:\n\n4 <= n <= 10^5",
+        "tags": [
+            "Math",
+            "Two Pointers",
+            "Brainteaser"
+        ],
+        "title-slug": "strictly-palindromic-number"
+    },
+    {
+        "leetcode-id": 2397,
+        "title": "Maximum Rows Covered by Columns",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed m x n binary matrix matrix and an integer numSelect, which denotes the number of distinct columns you must select from matrix.\nLet us consider s = {c1, c2, ...., cnumSelect} as the set of columns selected by you. A row row is covered by s if:\n\nFor each cell matrix[row][col] (0 <= col <= n - 1) where matrix[row][col] == 1, col is present in s or,\nNo cell in row has a value of 1.\n\nYou need to choose numSelect columns such that the number of rows that are covered is maximized.\nReturn the maximum number of rows that can be covered by a set of numSelect columns.",
+        "examples": [
+            "Example 1:\nInput: matrix = [[0,0,0],[1,0,1],[0,1,1],[0,0,1]], numSelect = 2\nOutput: 3\nExplanation: One possible way to cover 3 rows is shown in the diagram above.\nWe choose s = {0, 2}.\n- Row 0 is covered because it has no occurrences of 1.\n- Row 1 is covered because the columns with value 1, i.e. 0 and 2 are present in s.\n- Row 2 is not covered because matrix[2][1] == 1 but 1 is not present in s.\n- Row 3 is covered because matrix[2][2] == 1 and 2 is present in s.\nThus, we can cover three rows.\nNote that s = {1, 2} will also cover 3 rows, but it can be shown that no more than three rows can be covered.",
+            "Example 2:\nInput: matrix = [[1],[0]], numSelect = 1\nOutput: 2\nExplanation: Selecting the only column will result in both rows being covered since the entire matrix is selected.\nTherefore, we return 2."
+        ],
+        "constraints": "Constraints:\n\nm == matrix.length\nn == matrix[i].length\n1 <= m, n <= 12\nmatrix[i][j] is either 0 or 1.\n1 <= numSelect\u00a0<= n",
+        "tags": [
+            "Array",
+            "Backtracking",
+            "Bit Manipulation",
+            "Matrix",
+            "Enumeration"
+        ],
+        "title-slug": "maximum-rows-covered-by-columns"
+    },
+    {
+        "leetcode-id": 2398,
+        "title": "Maximum Number of Robots Within Budget",
+        "difficulty": 3,
+        "description": "You have n robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts, both of length n. The i^th robot costs chargeTimes[i] units to charge and costs runningCosts[i] units to run. You are also given an integer budget.\nThe total cost of running k chosen robots is equal to max(chargeTimes) + k * sum(runningCosts), where max(chargeTimes) is the largest charge cost among the k robots and sum(runningCosts) is the sum of running costs among the k robots.\nReturn the maximum number of consecutive robots you can run such that the total cost does not exceed budget.",
+        "examples": [
+            "Example 1:\nInput: chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25\nOutput: 3\nExplanation: \nIt is possible to run all individual and consecutive pairs of robots within budget.\nTo obtain answer 3, consider the first 3 robots. The total cost will be max(3,6,1) + 3 * sum(2,1,3) = 6 + 3 * 6 = 24 which is less than 25.\nIt can be shown that it is not possible to run more than 3 consecutive robots within budget, so we return 3.",
+            "Example 2:\nInput: chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19\nOutput: 0\nExplanation: No robot can be run that does not exceed the budget, so we return 0."
+        ],
+        "constraints": "Constraints:\n\nchargeTimes.length == runningCosts.length == n\n1 <= n <= 5 * 10^4\n1 <= chargeTimes[i], runningCosts[i] <= 10^5\n1 <= budget <= 10^15",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Queue",
+            "Sliding Window",
+            "Heap (Priority Queue)",
+            "Prefix Sum"
+        ],
+        "title-slug": "maximum-number-of-robots-within-budget"
+    },
+    {
+        "leetcode-id": 2399,
+        "title": "Check Distances Between Same Letters",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed string s consisting of only lowercase English letters, where each letter in s appears exactly twice. You are also given a 0-indexed integer array distance of length 26.\nEach letter in the alphabet is numbered from 0 to 25 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, ... , 'z' -> 25).\nIn a well-spaced string, the number of letters between the two occurrences of the i^th letter is distance[i]. If the i^th letter does not appear in s, then distance[i] can be ignored.\nReturn true if s is a well-spaced string, otherwise return false.",
+        "examples": [
+            "Example 1:\nInput: s = \"abaccb\", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\nOutput: true\nExplanation:\n- 'a' appears at indices 0 and 2 so it satisfies distance[0] = 1.\n- 'b' appears at indices 1 and 5 so it satisfies distance[1] = 3.\n- 'c' appears at indices 3 and 4 so it satisfies distance[2] = 0.\nNote that distance[3] = 5, but since 'd' does not appear in s, it can be ignored.\nReturn true because s is a well-spaced string.",
+            "Example 2:\nInput: s = \"aa\", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\nOutput: false\nExplanation:\n- 'a' appears at indices 0 and 1 so there are zero letters between them.\nBecause distance[0] = 1, s is not a well-spaced string."
+        ],
+        "constraints": "Constraints:\n\n2 <= s.length <= 52\ns consists only of lowercase English letters.\nEach letter appears in s exactly twice.\ndistance.length == 26\n0 <= distance[i] <= 50",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String"
+        ],
+        "title-slug": "check-distances-between-same-letters"
+    },
+    {
+        "leetcode-id": 2400,
+        "title": "Number of Ways to Reach a Position After Exactly k Steps",
+        "difficulty": 2,
+        "description": "You are given two positive integers startPos and endPos. Initially, you are standing at position startPos on an infinite number line. With one step, you can move either one position to the left, or one position to the right.\nGiven a positive integer k, return the number of different ways to reach the position endPos starting from startPos, such that you perform exactly k steps. Since the answer may be very large, return it modulo 10^9 + 7.\nTwo ways are considered different if the order of the steps made is not exactly the same.\nNote that the number line includes negative integers.",
+        "examples": [
+            "Example 1:\nInput: startPos = 1, endPos = 2, k = 3\nOutput: 3\nExplanation: We can reach position 2 from 1 in exactly 3 steps in three ways:\n- 1 -> 2 -> 3 -> 2.\n- 1 -> 2 -> 1 -> 2.\n- 1 -> 0 -> 1 -> 2.\nIt can be proven that no other way is possible, so we return 3.",
+            "Example 2:\nInput: startPos = 2, endPos = 5, k = 10\nOutput: 0\nExplanation: It is impossible to reach position 5 from position 2 in exactly 10 steps."
+        ],
+        "constraints": "Constraints:\n\n1 <= startPos, endPos, k <= 1000",
+        "tags": [
+            "Math",
+            "Dynamic Programming",
+            "Combinatorics"
+        ],
+        "title-slug": "number-of-ways-to-reach-a-position-after-exactly-k-steps"
+    },
+    {
+        "leetcode-id": 2401,
+        "title": "Longest Nice Subarray",
+        "difficulty": 2,
+        "description": "You are given an array nums consisting of positive integers.\nWe call a subarray of nums nice if the bitwise AND of every pair of elements that are in different positions in the subarray is equal to 0.\nReturn the length of the longest nice subarray.\nA subarray is a contiguous part of an array.\nNote that subarrays of length 1 are always considered nice.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,8,48,10]\nOutput: 3\nExplanation: The longest nice subarray is [3,8,48]. This subarray satisfies the conditions:\n- 3 AND 8 = 0.\n- 3 AND 48 = 0.\n- 8 AND 48 = 0.\nIt can be proven that no longer nice subarray can be obtained, so we return 3.",
+            "Example 2:\nInput: nums = [3,1,5,11,13]\nOutput: 1\nExplanation: The length of the longest nice subarray is 1. Any subarray of length 1 can be chosen."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Bit Manipulation",
+            "Sliding Window"
+        ],
+        "title-slug": "longest-nice-subarray"
+    },
+    {
+        "leetcode-id": 2402,
+        "title": "Meeting Rooms III",
+        "difficulty": 3,
+        "description": "You are given an integer n. There are n rooms numbered from 0 to n - 1.\nYou are given a 2D integer array meetings where meetings[i] = [starti, endi] means that a meeting will be held during the half-closed time interval [starti, endi). All the values of starti are unique.\nMeetings are allocated to rooms in the following manner:\n\nEach meeting will take place in the unused room with the lowest number.\nIf there are no available rooms, the meeting will be delayed until a room becomes free. The delayed meeting should have the same duration as the original meeting.\nWhen a room becomes unused, meetings that have an earlier original start time should be given the room.\n\nReturn the number of the room that held the most meetings. If there are multiple rooms, return the room with the lowest number.\nA half-closed interval [a, b) is the interval between a and b including a and not including b.",
+        "examples": [
+            "Example 1:\nInput: n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]]\nOutput: 0\nExplanation:\n- At time 0, both rooms are not being used. The first meeting starts in room 0.\n- At time 1, only room 1 is not being used. The second meeting starts in room 1.\n- At time 2, both rooms are being used. The third meeting is delayed.\n- At time 3, both rooms are being used. The fourth meeting is delayed.\n- At time 5, the meeting in room 1 finishes. The third meeting starts in room 1 for the time period [5,10).\n- At time 10, the meetings in both rooms finish. The fourth meeting starts in room 0 for the time period [10,11).\nBoth rooms 0 and 1 held 2 meetings, so we return 0.",
+            "Example 2:\nInput: n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]]\nOutput: 1\nExplanation:\n- At time 1, all three rooms are not being used. The first meeting starts in room 0.\n- At time 2, rooms 1 and 2 are not being used. The second meeting starts in room 1.\n- At time 3, only room 2 is not being used. The third meeting starts in room 2.\n- At time 4, all three rooms are being used. The fourth meeting is delayed.\n- At time 5, the meeting in room 2 finishes. The fourth meeting starts in room 2 for the time period [5,10).\n- At time 6, all three rooms are being used. The fifth meeting is delayed.\n- At time 10, the meetings in rooms 1 and 2 finish. The fifth meeting starts in room 1 for the time period [10,12).\nRoom 0 held 1 meeting while rooms 1 and 2 each held 2 meetings, so we return 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 100\n1 <= meetings.length <= 10^5\nmeetings[i].length == 2\n0 <= starti < endi <= 5 * 10^5\nAll the values of starti are unique.",
+        "tags": [
+            "Array",
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "meeting-rooms-iii"
+    },
+    {
+        "leetcode-id": 2404,
+        "title": "Most Frequent Even Element",
+        "difficulty": 1,
+        "description": "Given an integer array nums, return the most frequent even element.\nIf there is a tie, return the smallest one. If there is no such element, return -1.",
+        "examples": [
+            "Example 1:\nInput: nums = [0,1,2,2,4,4,1]\nOutput: 2\nExplanation:\nThe even elements are 0, 2, and 4. Of these, 2 and 4 appear the most.\nWe return the smallest one, which is 2.",
+            "Example 2:\nInput: nums = [4,4,4,9,2,4]\nOutput: 4\nExplanation: 4 is the even element appears the most.",
+            "Example 3:\nInput: nums = [29,47,21,41,13,37,25,7]\nOutput: -1\nExplanation: There is no even element."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 2000\n0 <= nums[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Counting"
+        ],
+        "title-slug": "most-frequent-even-element"
+    },
+    {
+        "leetcode-id": 2405,
+        "title": "Optimal Partition of String",
+        "difficulty": 2,
+        "description": "Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once.\nReturn the minimum number of substrings in such a partition.\nNote that each character should belong to exactly one substring in a partition.",
+        "examples": [
+            "Example 1:\nInput: s = \"abacaba\"\nOutput: 4\nExplanation:\nTwo possible partitions are (\"a\",\"ba\",\"cab\",\"a\") and (\"ab\",\"a\",\"ca\",\"ba\").\nIt can be shown that 4 is the minimum number of substrings needed.",
+            "Example 2:\nInput: s = \"ssssss\"\nOutput: 6\nExplanation:\nThe only valid partition is (\"s\",\"s\",\"s\",\"s\",\"s\",\"s\")."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of only English lowercase letters.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Greedy"
+        ],
+        "title-slug": "optimal-partition-of-string"
+    },
+    {
+        "leetcode-id": 2406,
+        "title": "Divide Intervals Into Minimum Number of Groups",
+        "difficulty": 2,
+        "description": "You are given a 2D integer array intervals where intervals[i] = [lefti, righti] represents the inclusive interval [lefti, righti].\nYou have to divide the intervals into one or more groups such that each interval is in exactly one group, and no two intervals that are in the same group intersect each other.\nReturn the minimum number of groups you need to make.\nTwo intervals intersect if there is at least one common number between them. For example, the intervals [1, 5] and [5, 8] intersect.",
+        "examples": [
+            "Example 1:\nInput: intervals = [[5,10],[6,8],[1,5],[2,3],[1,10]]\nOutput: 3\nExplanation: We can divide the intervals into the following groups:\n- Group 1: [1, 5], [6, 8].\n- Group 2: [2, 3], [5, 10].\n- Group 3: [1, 10].\nIt can be proven that it is not possible to divide the intervals into fewer than 3 groups.",
+            "Example 2:\nInput: intervals = [[1,3],[5,6],[8,10],[11,13]]\nOutput: 1\nExplanation: None of the intervals overlap, so we can put all of them in one group."
+        ],
+        "constraints": "Constraints:\n\n1 <= intervals.length <= 10^5\nintervals[i].length == 2\n1 <= lefti <= righti <= 10^6",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Greedy",
+            "Sorting",
+            "Heap (Priority Queue)",
+            "Prefix Sum"
+        ],
+        "title-slug": "divide-intervals-into-minimum-number-of-groups"
+    },
+    {
+        "leetcode-id": 2407,
+        "title": "Longest Increasing Subsequence II",
+        "difficulty": 3,
+        "description": "You are given an integer array nums and an integer k.\nFind the longest subsequence of nums that meets the following requirements:\n\nThe subsequence is strictly increasing and\nThe difference between adjacent elements in the subsequence is at most k.\n\nReturn the length of the longest subsequence that meets the requirements.\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,2,1,4,3,4,5,8,15], k = 3\nOutput: 5\nExplanation:\nThe longest subsequence that meets the requirements is [1,3,4,5,8].\nThe subsequence has a length of 5, so we return 5.\nNote that the subsequence [1,3,4,5,8,15] does not meet the requirements because 15 - 8 = 7 is larger than 3.",
+            "Example 2:\nInput: nums = [7,4,5,1,8,12,4,7], k = 5\nOutput: 4\nExplanation:\nThe longest subsequence that meets the requirements is [4,5,8,12].\nThe subsequence has a length of 4, so we return 4.",
+            "Example 3:\nInput: nums = [1,5], k = 1\nOutput: 1\nExplanation:\nThe longest subsequence that meets the requirements is [1].\nThe subsequence has a length of 1, so we return 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i], k <= 10^5",
+        "tags": [
+            "Array",
+            "Divide and Conquer",
+            "Dynamic Programming",
+            "Binary Indexed Tree",
+            "Segment Tree",
+            "Queue",
+            "Monotonic Queue"
+        ],
+        "title-slug": "longest-increasing-subsequence-ii"
+    },
+    {
+        "leetcode-id": 2409,
+        "title": "Count Days Spent Together",
+        "difficulty": 1,
+        "description": "Alice and Bob are traveling to Rome for separate business meetings.\nYou are given 4 strings arriveAlice, leaveAlice, arriveBob, and leaveBob. Alice will be in the city from the dates arriveAlice to leaveAlice (inclusive), while Bob will be in the city from the dates arriveBob to leaveBob (inclusive). Each will be a 5-character string in the format \"MM-DD\", corresponding to the month and day of the date.\nReturn the total number of days that Alice and Bob are in Rome together.\nYou can assume that all dates occur in the same calendar year, which is not a leap year. Note that the number of days per month can be represented as: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].",
+        "examples": [
+            "Example 1:\nInput: arriveAlice = \"08-15\", leaveAlice = \"08-18\", arriveBob = \"08-16\", leaveBob = \"08-19\"\nOutput: 3\nExplanation: Alice will be in Rome from August 15 to August 18. Bob will be in Rome from August 16 to August 19. They are both in Rome together on August 16th, 17th, and 18th, so the answer is 3.",
+            "Example 2:\nInput: arriveAlice = \"10-01\", leaveAlice = \"10-31\", arriveBob = \"11-01\", leaveBob = \"12-31\"\nOutput: 0\nExplanation: There is no day when Alice and Bob are in Rome together, so we return 0."
+        ],
+        "constraints": "Constraints:\n\nAll dates are provided in the format \"MM-DD\".\nAlice and Bob's arrival dates are earlier than or equal to their leaving dates.\nThe given dates are valid dates of a non-leap year.",
+        "tags": [
+            "Math",
+            "String"
+        ],
+        "title-slug": "count-days-spent-together"
+    },
+    {
+        "leetcode-id": 2410,
+        "title": "Maximum Matching of Players With Trainers",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array players, where players[i] represents the ability of the i^th player. You are also given a 0-indexed integer array trainers, where trainers[j] represents the training capacity of the j^th trainer.\nThe i^th player can match with the j^th trainer if the player's ability is less than or equal to the trainer's training capacity. Additionally, the i^th player can be matched with at most one trainer, and the j^th trainer can be matched with at most one player.\nReturn the maximum number of matchings between players and trainers that satisfy these conditions.",
+        "examples": [
+            "Example 1:\nInput: players = [4,7,9], trainers = [8,2,5,8]\nOutput: 2\nExplanation:\nOne of the ways we can form two matchings is as follows:\n- players[0] can be matched with trainers[0] since 4 <= 8.\n- players[1] can be matched with trainers[3] since 7 <= 8.\nIt can be proven that 2 is the maximum number of matchings that can be formed.",
+            "Example 2:\nInput: players = [1,1,1], trainers = [10]\nOutput: 1\nExplanation:\nThe trainer can be matched with any of the 3 players.\nEach player can only be matched with one trainer, so the maximum answer is 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= players.length, trainers.length <= 10^5\n1 <= players[i], trainers[j] <= 10^9",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "maximum-matching-of-players-with-trainers"
+    },
+    {
+        "leetcode-id": 2411,
+        "title": "Smallest Subarrays With Maximum Bitwise OR",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array nums of length n, consisting of non-negative integers. For each index i from 0 to n - 1, you must determine the size of the minimum sized non-empty subarray of nums starting at i (inclusive) that has the maximum possible bitwise OR.\n\nIn other words, let Bij be the bitwise OR of the subarray nums[i...j]. You need to find the smallest subarray starting at i, such that bitwise OR of this subarray is equal to max(Bik) where i <= k <= n - 1.\n\nThe bitwise OR of an array is the bitwise OR of all the numbers in it.\nReturn an integer array answer of size n where answer[i] is the length of the minimum sized subarray starting at i with maximum bitwise OR.\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,0,2,1,3]\nOutput: [3,3,2,2,1]\nExplanation:\nThe maximum possible bitwise OR starting at any index is 3. \n- Starting at index 0, the shortest subarray that yields it is [1,0,2].\n- Starting at index 1, the shortest subarray that yields the maximum bitwise OR is [0,2,1].\n- Starting at index 2, the shortest subarray that yields the maximum bitwise OR is [2,1].\n- Starting at index 3, the shortest subarray that yields the maximum bitwise OR is [1,3].\n- Starting at index 4, the shortest subarray that yields the maximum bitwise OR is [3].\nTherefore, we return [3,3,2,2,1].",
+            "Example 2:\nInput: nums = [1,2]\nOutput: [2,1]\nExplanation:\nStarting at index 0, the shortest subarray that yields the maximum bitwise OR is of length 2.\nStarting at index 1, the shortest subarray that yields the maximum bitwise OR is of length 1.\nTherefore, we return [2,1]."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^5\n0 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Bit Manipulation",
+            "Sliding Window"
+        ],
+        "title-slug": "smallest-subarrays-with-maximum-bitwise-or"
+    },
+    {
+        "leetcode-id": 2412,
+        "title": "Minimum Money Required Before Transactions",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed 2D integer array transactions, where transactions[i] = [costi, cashbacki].\nThe array describes transactions, where each transaction must be completed exactly once in some order. At any given moment, you have a certain amount of money. In order to complete transaction i, money >= costi must hold true. After performing a transaction, money becomes money - costi + cashbacki.\nReturn the minimum amount of money required before any transaction so that all of the transactions can be completed regardless of the order of the transactions.",
+        "examples": [
+            "Example 1:\nInput: transactions = [[2,1],[5,0],[4,2]]\nOutput: 10\nExplanation:\nStarting with money = 10, the transactions can be performed in any order.\nIt can be shown that starting with money < 10 will fail to complete all transactions in some order.",
+            "Example 2:\nInput: transactions = [[3,0],[0,3]]\nOutput: 3\nExplanation:\n- If transactions are in the order [[3,0],[0,3]], the minimum money required to complete the transactions is 3.\n- If transactions are in the order [[0,3],[3,0]], the minimum money required to complete the transactions is 0.\nThus, starting with money = 3, the transactions can be performed in any order."
+        ],
+        "constraints": "Constraints:\n\n1 <= transactions.length <= 10^5\ntransactions[i].length == 2\n0 <= costi, cashbacki <= 10^9",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "minimum-money-required-before-transactions"
+    },
+    {
+        "leetcode-id": 2413,
+        "title": "Smallest Even Multiple",
+        "difficulty": 1,
+        "description": "Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.",
+        "examples": [
+            "Example 1:\nInput: n = 5\nOutput: 10\nExplanation: The smallest multiple of both 5 and 2 is 10.",
+            "Example 2:\nInput: n = 6\nOutput: 6\nExplanation: The smallest multiple of both 6 and 2 is 6. Note that a number is a multiple of itself."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 150",
+        "tags": [
+            "Math",
+            "Number Theory"
+        ],
+        "title-slug": "smallest-even-multiple"
+    },
+    {
+        "leetcode-id": 2414,
+        "title": "Length of the Longest Alphabetical Continuous Substring",
+        "difficulty": 2,
+        "description": "An alphabetical continuous string is a string consisting of consecutive letters in the alphabet. In other words, it is any substring of the string \"abcdefghijklmnopqrstuvwxyz\".\n\nFor example, \"abc\" is an alphabetical continuous string, while \"acb\" and \"za\" are not.\n\nGiven a string s consisting of lowercase letters only, return the length of the longest alphabetical continuous substring.",
+        "examples": [
+            "Example 1:\nInput: s = \"abacaba\"\nOutput: 2\nExplanation: There are 4 distinct continuous substrings: \"a\", \"b\", \"c\" and \"ab\".\n\"ab\" is the longest continuous substring.",
+            "Example 2:\nInput: s = \"abcde\"\nOutput: 5\nExplanation: \"abcde\" is the longest continuous substring."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of only English lowercase letters.",
+        "tags": [
+            "String"
+        ],
+        "title-slug": "length-of-the-longest-alphabetical-continuous-substring"
+    },
+    {
+        "leetcode-id": 2415,
+        "title": "Reverse Odd Levels of Binary Tree",
+        "difficulty": 2,
+        "description": "Given the root of a perfect binary tree, reverse the node values at each odd level of the tree.\n\nFor example, suppose the node values at level 3 are [2,1,3,4,7,11,29,18], then it should become [18,29,11,7,4,3,1,2].\n\nReturn the root of the reversed tree.\nA binary tree is perfect if all parent nodes have two children and all leaves are on the same level.\nThe level of a node is the number of edges along the path between it and the root node.",
+        "examples": [
+            "Example 1:\nInput: root = [2,3,5,8,13,21,34]\nOutput: [2,5,3,8,13,21,34]\nExplanation: \nThe tree has only one odd level.\nThe nodes at level 1 are 3, 5 respectively, which are reversed and become 5, 3.",
+            "Example 2:\nInput: root = [7,13,11]\nOutput: [7,11,13]\nExplanation: \nThe nodes at level 1 are 13, 11, which are reversed and become 11, 13.",
+            "Example 3:\nInput: root = [0,1,2,0,0,0,0,1,1,1,1,2,2,2,2]\nOutput: [0,2,1,0,0,0,0,2,2,2,2,1,1,1,1]\nExplanation: \nThe odd levels have non-zero values.\nThe nodes at level 1 were 1, 2, and are 2, 1 after the reversal.\nThe nodes at level 3 were 1, 1, 1, 1, 2, 2, 2, 2, and are 2, 2, 2, 2, 1, 1, 1, 1 after the reversal."
+        ],
+        "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 2^14].\n0 <= Node.val <= 10^5\nroot is a perfect binary tree.",
+        "tags": [
+            "Tree",
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Binary Tree"
+        ],
+        "title-slug": "reverse-odd-levels-of-binary-tree"
+    },
+    {
+        "leetcode-id": 2416,
+        "title": "Sum of Prefix Scores of Strings",
+        "difficulty": 3,
+        "description": "You are given an array words of size n consisting of non-empty strings.\nWe define the score of a string word as the number of strings words[i] such that word is a prefix of words[i].\n\nFor example, if words = [\"a\", \"ab\", \"abc\", \"cab\"], then the score of \"ab\" is 2, since \"ab\" is a prefix of both \"ab\" and \"abc\".\n\nReturn an array answer of size n where answer[i] is the sum of scores of every non-empty prefix of words[i].\nNote that a string is considered as a prefix of itself.",
+        "examples": [
+            "Example 1:\nInput: words = [\"abc\",\"ab\",\"bc\",\"b\"]\nOutput: [5,4,3,2]\nExplanation: The answer for each string is the following:\n- \"abc\" has 3 prefixes: \"a\", \"ab\", and \"abc\".\n- There are 2 strings with the prefix \"a\", 2 strings with the prefix \"ab\", and 1 string with the prefix \"abc\".\nThe total is answer[0] = 2 + 2 + 1 = 5.\n- \"ab\" has 2 prefixes: \"a\" and \"ab\".\n- There are 2 strings with the prefix \"a\", and 2 strings with the prefix \"ab\".\nThe total is answer[1] = 2 + 2 = 4.\n- \"bc\" has 2 prefixes: \"b\" and \"bc\".\n- There are 2 strings with the prefix \"b\", and 1 string with the prefix \"bc\".\nThe total is answer[2] = 2 + 1 = 3.\n- \"b\" has 1 prefix: \"b\".\n- There are 2 strings with the prefix \"b\".\nThe total is answer[3] = 2.",
+            "Example 2:\nInput: words = [\"abcd\"]\nOutput: [4]\nExplanation:\n\"abcd\" has 4 prefixes: \"a\", \"ab\", \"abc\", and \"abcd\".\nEach prefix has a score of one, so the total is answer[0] = 1 + 1 + 1 + 1 = 4."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 1000\n1 <= words[i].length <= 1000\nwords[i] consists of lowercase English letters.",
+        "tags": [
+            "Array",
+            "String",
+            "Trie",
+            "Counting"
+        ],
+        "title-slug": "sum-of-prefix-scores-of-strings"
+    },
+    {
+        "leetcode-id": 2418,
+        "title": "Sort the People",
+        "difficulty": 1,
+        "description": "You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n.\nFor each index i, names[i] and heights[i] denote the name and height of the i^th person.\nReturn names sorted in descending order by the people's heights.",
+        "examples": [
+            "Example 1:\nInput: names = [\"Mary\",\"John\",\"Emma\"], heights = [180,165,170]\nOutput: [\"Mary\",\"Emma\",\"John\"]\nExplanation: Mary is the tallest, followed by Emma and John.",
+            "Example 2:\nInput: names = [\"Alice\",\"Bob\",\"Bob\"], heights = [155,185,150]\nOutput: [\"Bob\",\"Alice\",\"Bob\"]\nExplanation: The first Bob is the tallest, followed by Alice and the second Bob."
+        ],
+        "constraints": "Constraints:\n\nn == names.length == heights.length\n1 <= n <= 10^3\n1 <= names[i].length <= 20\n1 <= heights[i] <= 10^5\nnames[i] consists of lower and upper case English letters.\nAll the values of heights are distinct.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Sorting"
+        ],
+        "title-slug": "sort-the-people"
+    },
+    {
+        "leetcode-id": 2419,
+        "title": "Longest Subarray With Maximum Bitwise AND",
+        "difficulty": 2,
+        "description": "You are given an integer array nums of size n.\nConsider a non-empty subarray from nums that has the maximum possible bitwise AND.\n\nIn other words, let k be the maximum value of the bitwise AND of any subarray of nums. Then, only subarrays with a bitwise AND equal to k should be considered.\n\nReturn the length of the longest such subarray.\nThe bitwise AND of an array is the bitwise AND of all the numbers in it.\nA subarray is a contiguous sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,3,3,2,2]\nOutput: 2\nExplanation:\nThe maximum possible bitwise AND of a subarray is 3.\nThe longest subarray with that value is [3,3], so we return 2.",
+            "Example 2:\nInput: nums = [1,2,3,4]\nOutput: 1\nExplanation:\nThe maximum possible bitwise AND of a subarray is 4.\nThe longest subarray with that value is [4], so we return 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Bit Manipulation",
+            "Brainteaser"
+        ],
+        "title-slug": "longest-subarray-with-maximum-bitwise-and"
+    },
+    {
+        "leetcode-id": 2420,
+        "title": "Find All Good Indices",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums of size n and a positive integer k.\nWe call an index i in the range k <= i < n - k good if the following conditions are satisfied:\n\nThe k elements that are just before the index i are in non-increasing order.\nThe k elements that are just after the index i are in non-decreasing order.\n\nReturn an array of all good indices sorted in increasing order.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,1,1,1,3,4,1], k = 2\nOutput: [2,3]\nExplanation: There are two good indices in the array:\n- Index 2. The subarray [2,1] is in non-increasing order, and the subarray [1,3] is in non-decreasing order.\n- Index 3. The subarray [1,1] is in non-increasing order, and the subarray [3,4] is in non-decreasing order.\nNote that the index 4 is not good because [4,1] is not non-decreasing.",
+            "Example 2:\nInput: nums = [2,1,1,2], k = 2\nOutput: []\nExplanation: There are no good indices in this array."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length\n3 <= n <= 10^5\n1 <= nums[i] <= 10^6\n1 <= k <= n / 2",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Prefix Sum"
+        ],
+        "title-slug": "find-all-good-indices"
+    },
+    {
+        "leetcode-id": 2421,
+        "title": "Number of Good Paths",
+        "difficulty": 3,
+        "description": "There is a tree (i.e. a connected, undirected graph with no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges.\nYou are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the i^th node. You are also given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.\nA good path is a simple path that satisfies the following conditions:\n\nThe starting node and the ending node have the same value.\nAll nodes between the starting node and the ending node have values less than or equal to the starting node (i.e. the starting node's value should be the maximum value along the path).\n\nReturn the number of distinct good paths.\nNote that a path and its reverse are counted as the same path. For example, 0 -> 1 is considered to be the same as 1 -> 0. A single node is also considered as a valid path.",
+        "examples": [
+            "Example 1:\nInput: vals = [1,3,2,1,3], edges = [[0,1],[0,2],[2,3],[2,4]]\nOutput: 6\nExplanation: There are 5 good paths consisting of a single node.\nThere is 1 additional good path: 1 -> 0 -> 2 -> 4.\n(The reverse path 4 -> 2 -> 0 -> 1 is treated as the same as 1 -> 0 -> 2 -> 4.)\nNote that 0 -> 2 -> 3 is not a good path because vals[2] > vals[0].",
+            "Example 2:\nInput: vals = [1,1,2,2,3], edges = [[0,1],[1,2],[2,3],[2,4]]\nOutput: 7\nExplanation: There are 5 good paths consisting of a single node.\nThere are 2 additional good paths: 0 -> 1 and 2 -> 3.",
+            "Example 3:\nInput: vals = [1], edges = []\nOutput: 1\nExplanation: The tree consists of only one node, so there is one good path."
+        ],
+        "constraints": "Constraints:\n\nn == vals.length\n1 <= n <= 3 * 10^4\n0 <= vals[i] <= 10^5\nedges.length == n - 1\nedges[i].length == 2\n0 <= ai, bi < n\nai != bi\nedges represents a valid tree.",
+        "tags": [
+            "Array",
+            "Tree",
+            "Union Find",
+            "Graph"
+        ],
+        "title-slug": "number-of-good-paths"
+    },
+    {
+        "leetcode-id": 2423,
+        "title": "Remove Letter To Equalize Frequency",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed string word, consisting of lowercase English letters. You need to select one index and remove the letter at that index from word so that the frequency of every letter present in word is equal.\nReturn true if it is possible to remove one letter so that the frequency of all letters in word are equal, and false otherwise.\nNote:\n\nThe frequency of a letter x is the number of times it occurs in the string.\nYou must remove exactly one letter and cannot chose to do nothing.",
+        "examples": [
+            "Example 1:\nInput: word = \"abcc\"\nOutput: true\nExplanation: Select index 3 and delete it: word becomes \"abc\" and each character has a frequency of 1.",
+            "Example 2:\nInput: word = \"aazz\"\nOutput: false\nExplanation: We must delete a character, so either the frequency of \"a\" is 1 and the frequency of \"z\" is 2, or vice versa. It is impossible to make all present letters have equal frequency."
+        ],
+        "constraints": "Constraints:\n\n2 <= word.length <= 100\nword consists of lowercase English letters only.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Counting"
+        ],
+        "title-slug": "remove-letter-to-equalize-frequency"
+    },
+    {
+        "leetcode-id": 2424,
+        "title": "Longest Uploaded Prefix",
+        "difficulty": 2,
+        "description": "You are given a stream of n videos, each represented by a distinct number from 1 to n that you need to \"upload\" to a server. You need to implement a data structure that calculates the length of the longest uploaded prefix at various points in the upload process.\nWe consider i to be an uploaded prefix if all videos in the range 1 to i (inclusive) have been uploaded to the server. The longest uploaded prefix is the maximum value of i that satisfies this definition.\n\nImplement the LUPrefix class:\n\nLUPrefix(int n) Initializes the object for a stream of n videos.\nvoid upload(int video) Uploads video to the server.\nint longest() Returns the length of the longest uploaded prefix defined above.",
+        "examples": [
+            "Example 1:\nInput\n[\"LUPrefix\", \"upload\", \"longest\", \"upload\", \"longest\", \"upload\", \"longest\"]\n[[4], [3], [], [1], [], [2], []]\nOutput\n[null, null, 0, null, 1, null, 3]\n\nExplanation\nLUPrefix server = new LUPrefix(4);   // Initialize a stream of 4 videos.\nserver.upload(3);                    // Upload video 3.\nserver.longest();                    // Since video 1 has not been uploaded yet, there is no prefix.\n                                     // So, we return 0.\nserver.upload(1);                    // Upload video 1.\nserver.longest();                    // The prefix [1] is the longest uploaded prefix, so we return 1.\nserver.upload(2);                    // Upload video 2.\nserver.longest();                    // The prefix [1,2,3] is the longest uploaded prefix, so we return 3."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^5\n1 <= video <= n\nAll values of video are distinct.\nAt most 2 * 10^5 calls in total will be made to upload and longest.\nAt least one call will be made to longest.",
+        "tags": [
+            "Binary Search",
+            "Union Find",
+            "Design",
+            "Binary Indexed Tree",
+            "Segment Tree",
+            "Heap (Priority Queue)",
+            "Ordered Set"
+        ],
+        "title-slug": "longest-uploaded-prefix"
+    },
+    {
+        "leetcode-id": 2425,
+        "title": "Bitwise XOR of All Pairings",
+        "difficulty": 2,
+        "description": "You are given two 0-indexed arrays, nums1 and nums2, consisting of non-negative integers. There exists another array, nums3, which contains the bitwise XOR of all pairings of integers between nums1 and nums2 (every integer in nums1 is paired with every integer in nums2 exactly once).\nReturn the bitwise XOR of all integers in nums3.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [2,1,3], nums2 = [10,2,5,0]\nOutput: 13\nExplanation:\nA possible nums3 array is [8,0,7,2,11,3,4,1,9,1,6,3].\nThe bitwise XOR of all these numbers is 13, so we return 13.",
+            "Example 2:\nInput: nums1 = [1,2], nums2 = [3,4]\nOutput: 0\nExplanation:\nAll possible pairs of bitwise XORs are nums1[0] ^ nums2[0], nums1[0] ^ nums2[1], nums1[1] ^ nums2[0],\nand nums1[1] ^ nums2[1].\nThus, one possible nums3 array is [2,5,1,6].\n2 ^ 5 ^ 1 ^ 6 = 0, so we return 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 10^5\n0 <= nums1[i], nums2[j] <= 10^9",
+        "tags": [
+            "Array",
+            "Bit Manipulation",
+            "Brainteaser"
+        ],
+        "title-slug": "bitwise-xor-of-all-pairings"
+    },
+    {
+        "leetcode-id": 2426,
+        "title": "Number of Pairs Satisfying Inequality",
+        "difficulty": 3,
+        "description": "You are given two 0-indexed integer arrays nums1 and nums2, each of size n, and an integer diff. Find the number of pairs (i, j) such that:\n\n0 <= i < j <= n - 1 and\nnums1[i] - nums1[j] <= nums2[i] - nums2[j] + diff.\n\nReturn the number of pairs that satisfy the conditions.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [3,2,5], nums2 = [2,2,1], diff = 1\nOutput: 3\nExplanation:\nThere are 3 pairs that satisfy the conditions:\n1. i = 0, j = 1: 3 - 2 <= 2 - 2 + 1. Since i < j and 1 <= 1, this pair satisfies the conditions.\n2. i = 0, j = 2: 3 - 5 <= 2 - 1 + 1. Since i < j and -2 <= 2, this pair satisfies the conditions.\n3. i = 1, j = 2: 2 - 5 <= 2 - 1 + 1. Since i < j and -3 <= 2, this pair satisfies the conditions.\nTherefore, we return 3.",
+            "Example 2:\nInput: nums1 = [3,-1], nums2 = [-2,2], diff = -1\nOutput: 0\nExplanation:\nSince there does not exist any pair that satisfies the conditions, we return 0."
+        ],
+        "constraints": "Constraints:\n\nn == nums1.length == nums2.length\n2 <= n <= 10^5\n-10^4 <= nums1[i], nums2[i] <= 10^4\n-10^4 <= diff <= 10^4",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Divide and Conquer",
+            "Binary Indexed Tree",
+            "Segment Tree",
+            "Merge Sort",
+            "Ordered Set"
+        ],
+        "title-slug": "number-of-pairs-satisfying-inequality"
+    },
+    {
+        "leetcode-id": 2427,
+        "title": "Number of Common Factors",
+        "difficulty": 1,
+        "description": "Given two positive integers a and b, return the number of common factors of a and b.\nAn integer x is a common factor of a and b if x divides both a and b.",
+        "examples": [
+            "Example 1:\nInput: a = 12, b = 6\nOutput: 4\nExplanation: The common factors of 12 and 6 are 1, 2, 3, 6.",
+            "Example 2:\nInput: a = 25, b = 30\nOutput: 2\nExplanation: The common factors of 25 and 30 are 1, 5."
+        ],
+        "constraints": "Constraints:\n\n1 <= a, b <= 1000",
+        "tags": [
+            "Math",
+            "Enumeration",
+            "Number Theory"
+        ],
+        "title-slug": "number-of-common-factors"
+    },
+    {
+        "leetcode-id": 2428,
+        "title": "Maximum Sum of an Hourglass",
+        "difficulty": 2,
+        "description": "You are given an m x n integer matrix grid.\nWe define an hourglass as a part of the matrix with the following form:\n\nReturn the maximum sum of the elements of an hourglass.\nNote that an hourglass cannot be rotated and must be entirely contained within the matrix.",
+        "examples": [
+            "Example 1:\nInput: grid = [[6,2,1,3],[4,2,1,5],[9,2,8,7],[4,1,2,9]]\nOutput: 30\nExplanation: The cells shown above represent the hourglass with the maximum sum: 6 + 2 + 1 + 2 + 9 + 2 + 8 = 30.",
+            "Example 2:\nInput: grid = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: 35\nExplanation: There is only one hourglass in the matrix, with the sum: 1 + 2 + 3 + 5 + 7 + 8 + 9 = 35."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n3 <= m, n <= 150\n0 <= grid[i][j] <= 10^6",
+        "tags": [
+            "Array",
+            "Matrix",
+            "Prefix Sum"
+        ],
+        "title-slug": "maximum-sum-of-an-hourglass"
+    },
+    {
+        "leetcode-id": 2429,
+        "title": "Minimize XOR",
+        "difficulty": 2,
+        "description": "Given two positive integers num1 and num2, find the positive integer x such that:\n\nx has the same number of set bits as num2, and\nThe value x XOR num1 is minimal.\n\nNote that XOR is the bitwise XOR operation.\nReturn the integer x. The test cases are generated such that x is uniquely determined.\nThe number of set bits of an integer is the number of 1's in its binary representation.",
+        "examples": [
+            "Example 1:\nInput: num1 = 3, num2 = 5\nOutput: 3\nExplanation:\nThe binary representations of num1 and num2 are 0011 and 0101, respectively.\nThe integer 3 has the same number of set bits as num2, and the value 3 XOR 3 = 0 is minimal.",
+            "Example 2:\nInput: num1 = 1, num2 = 12\nOutput: 3\nExplanation:\nThe binary representations of num1 and num2 are 0001 and 1100, respectively.\nThe integer 3 has the same number of set bits as num2, and the value 3 XOR 1 = 2 is minimal."
+        ],
+        "constraints": "Constraints:\n\n1 <= num1, num2 <= 10^9",
+        "tags": [
+            "Greedy",
+            "Bit Manipulation"
+        ],
+        "title-slug": "minimize-xor"
+    },
+    {
+        "leetcode-id": 2430,
+        "title": "Maximum Deletions on a String",
+        "difficulty": 3,
+        "description": "You are given a string s consisting of only lowercase English letters. In one operation, you can:\n\nDelete the entire string s, or\nDelete the first i letters of s if the first i letters of s are equal to the following i letters in s, for any i in the range 1 <= i <= s.length / 2.\n\nFor example, if s = \"ababc\", then in one operation, you could delete the first two letters of s to get \"abc\", since the first two letters of s and the following two letters of s are both equal to \"ab\".\nReturn the maximum number of operations needed to delete all of s.",
+        "examples": [
+            "Example 1:\nInput: s = \"abcabcdabc\"\nOutput: 2\nExplanation:\n- Delete the first 3 letters (\"abc\") since the next 3 letters are equal. Now, s = \"abcdabc\".\n- Delete all the letters.\nWe used 2 operations so return 2. It can be proven that 2 is the maximum number of operations needed.\nNote that in the second operation we cannot delete \"abc\" again because the next occurrence of \"abc\" does not happen in the next 3 letters.",
+            "Example 2:\nInput: s = \"aaabaab\"\nOutput: 4\nExplanation:\n- Delete the first letter (\"a\") since the next letter is equal. Now, s = \"aabaab\".\n- Delete the first 3 letters (\"aab\") since the next 3 letters are equal. Now, s = \"aab\".\n- Delete the first letter (\"a\") since the next letter is equal. Now, s = \"ab\".\n- Delete all the letters.\nWe used 4 operations so return 4. It can be proven that 4 is the maximum number of operations needed.",
+            "Example 3:\nInput: s = \"aaaaa\"\nOutput: 5\nExplanation: In each operation, we can delete the first letter of s."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 4000\ns consists only of lowercase English letters.",
+        "tags": [
+            "String",
+            "Dynamic Programming",
+            "Rolling Hash",
+            "String Matching",
+            "Hash Function"
+        ],
+        "title-slug": "maximum-deletions-on-a-string"
+    },
+    {
+        "leetcode-id": 2432,
+        "title": "The Employee That Worked on the Longest Task",
+        "difficulty": 1,
+        "description": "There are n employees, each with a unique id from 0 to n - 1.\nYou are given a 2D integer array logs where logs[i] = [idi, leaveTimei] where:\n\nidi is the id of the employee that worked on the i^th task, and\nleaveTimei is the time at which the employee finished the i^th task. All the values leaveTimei are unique.\n\nNote that the i^th task starts the moment right after the (i - 1)^th task ends, and the 0^th task starts at time 0.\nReturn the id of the employee that worked the task with the longest time. If there is a tie between two or more employees, return the smallest id among them.",
+        "examples": [
+            "Example 1:\nInput: n = 10, logs = [[0,3],[2,5],[0,9],[1,15]]\nOutput: 1\nExplanation: \nTask 0 started at 0 and ended at 3 with 3 units of times.\nTask 1 started at 3 and ended at 5 with 2 units of times.\nTask 2 started at 5 and ended at 9 with 4 units of times.\nTask 3 started at 9 and ended at 15 with 6 units of times.\nThe task with the longest time is task 3 and the employee with id 1 is the one that worked on it, so we return 1.",
+            "Example 2:\nInput: n = 26, logs = [[1,1],[3,7],[2,12],[7,17]]\nOutput: 3\nExplanation: \nTask 0 started at 0 and ended at 1 with 1 unit of times.\nTask 1 started at 1 and ended at 7 with 6 units of times.\nTask 2 started at 7 and ended at 12 with 5 units of times.\nTask 3 started at 12 and ended at 17 with 5 units of times.\nThe tasks with the longest time is task 1. The employee that worked on it is 3, so we return 3.",
+            "Example 3:\nInput: n = 2, logs = [[0,10],[1,20]]\nOutput: 0\nExplanation: \nTask 0 started at 0 and ended at 10 with 10 units of times.\nTask 1 started at 10 and ended at 20 with 10 units of times.\nThe tasks with the longest time are tasks 0 and 1. The employees that worked on them are 0 and 1, so we return the smallest id 0."
+        ],
+        "constraints": "Constraints:\n\n2 <= n <= 500\n1 <= logs.length <= 500\nlogs[i].length == 2\n0 <= idi <= n - 1\n1 <= leaveTimei <= 500\nidi != idi+1\nleaveTimei are sorted in a strictly increasing order.",
+        "tags": [
+            "Array"
+        ],
+        "title-slug": "the-employee-that-worked-on-the-longest-task"
+    },
+    {
+        "leetcode-id": 2433,
+        "title": "Find The Original Array of Prefix Xor",
+        "difficulty": 2,
+        "description": "You are given an integer array pref of size n. Find and return the array arr of size n that satisfies:\n\npref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i].\n\nNote that ^ denotes the bitwise-xor operation.\nIt can be proven that the answer is unique.",
+        "examples": [
+            "Example 1:\nInput: pref = [5,2,0,3,1]\nOutput: [5,7,2,3,2]\nExplanation: From the array [5,7,2,3,2] we have the following:\n- pref[0] = 5.\n- pref[1] = 5 ^ 7 = 2.\n- pref[2] = 5 ^ 7 ^ 2 = 0.\n- pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3.\n- pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.",
+            "Example 2:\nInput: pref = [13]\nOutput: [13]\nExplanation: We have pref[0] = arr[0] = 13."
+        ],
+        "constraints": "Constraints:\n\n1 <= pref.length <= 10^5\n0 <= pref[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Bit Manipulation"
+        ],
+        "title-slug": "find-the-original-array-of-prefix-xor"
+    },
+    {
+        "leetcode-id": 2434,
+        "title": "Using a Robot to Print the Lexicographically Smallest String",
+        "difficulty": 2,
+        "description": "You are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty:\n\nRemove the first character of a string s and give it to the robot. The robot will append this character to the string t.\nRemove the last character of a string t and give it to the robot. The robot will write this character on paper.\n\nReturn the lexicographically smallest string that can be written on the paper.",
+        "examples": [
+            "Example 1:\nInput: s = \"zza\"\nOutput: \"azz\"\nExplanation: Let p denote the written string.\nInitially p=\"\", s=\"zza\", t=\"\".\nPerform first operation three times p=\"\", s=\"\", t=\"zza\".\nPerform second operation three times p=\"azz\", s=\"\", t=\"\".",
+            "Example 2:\nInput: s = \"bac\"\nOutput: \"abc\"\nExplanation: Let p denote the written string.\nPerform first operation twice p=\"\", s=\"c\", t=\"ba\". \nPerform second operation twice p=\"ab\", s=\"c\", t=\"\". \nPerform first operation p=\"ab\", s=\"\", t=\"c\". \nPerform second operation p=\"abc\", s=\"\", t=\"\".",
+            "Example 3:\nInput: s = \"bdda\"\nOutput: \"addb\"\nExplanation: Let p denote the written string.\nInitially p=\"\", s=\"bdda\", t=\"\".\nPerform first operation four times p=\"\", s=\"\", t=\"bdda\".\nPerform second operation four times p=\"addb\", s=\"\", t=\"\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of only English lowercase letters.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Stack",
+            "Greedy"
+        ],
+        "title-slug": "using-a-robot-to-print-the-lexicographically-smallest-string"
+    },
+    {
+        "leetcode-id": 2435,
+        "title": "Paths in Matrix Whose Sum Is Divisible by K",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed m x n integer matrix grid and an integer k. You are currently at position (0, 0) and you want to reach position (m - 1, n - 1) moving only down or right.\nReturn the number of paths where the sum of the elements on the path is divisible by k. Since the answer may be very large, return it modulo 10^9 + 7.",
+        "examples": [
+            "Example 1:\nInput: grid = [[5,2,4],[3,0,5],[0,7,2]], k = 3\nOutput: 2\nExplanation: There are two paths where the sum of the elements on the path is divisible by k.\nThe first path highlighted in red has a sum of 5 + 2 + 4 + 5 + 2 = 18 which is divisible by 3.\nThe second path highlighted in blue has a sum of 5 + 3 + 0 + 5 + 2 = 15 which is divisible by 3.",
+            "Example 2:\nInput: grid = [[0,0]], k = 5\nOutput: 1\nExplanation: The path highlighted in red has a sum of 0 + 0 = 0 which is divisible by 5.",
+            "Example 3:\nInput: grid = [[7,3,4,9],[2,3,6,2],[2,3,7,0]], k = 1\nOutput: 10\nExplanation: Every integer is divisible by 1 so the sum of the elements on every possible path is divisible by k."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 5 * 10^4\n1 <= m * n <= 5 * 10^4\n0 <= grid[i][j] <= 100\n1 <= k <= 50",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Matrix"
+        ],
+        "title-slug": "paths-in-matrix-whose-sum-is-divisible-by-k"
+    },
+    {
+        "leetcode-id": 2437,
+        "title": "Number of Valid Clock Times",
+        "difficulty": 1,
+        "description": "You are given a string of length 5 called time, representing the current time on a digital clock in the format \"hh:mm\". The earliest possible time is \"00:00\" and the latest possible time is \"23:59\".\nIn the string time, the digits represented by the ?\u00a0symbol are unknown, and must be replaced with a digit from 0 to 9.\nReturn an integer answer, the number of valid clock times that can be created by replacing every ?\u00a0with a digit from 0 to 9.",
+        "examples": [
+            "Example 1:\nInput: time = \"?5:00\"\nOutput: 2\nExplanation: We can replace the ? with either a 0 or 1, producing \"05:00\" or \"15:00\". Note that we cannot replace it with a 2, since the time \"25:00\" is invalid. In total, we have two choices.",
+            "Example 2:\nInput: time = \"0?:0?\"\nOutput: 100\nExplanation: Each ? can be replaced by any digit from 0 to 9, so we have 100 total choices.",
+            "Example 3:\nInput: time = \"??:??\"\nOutput: 1440\nExplanation: There are 24 possible choices for the hours, and 60 possible choices for the minutes. In total, we have 24 * 60 = 1440 choices."
+        ],
+        "constraints": "Constraints:\n\ntime is a valid string of length 5 in the format \"hh:mm\".\n\"00\" <= hh <= \"23\"\n\"00\" <= mm <= \"59\"\nSome of the digits might be replaced with '?' and need to be replaced with digits from 0 to 9.",
+        "tags": [
+            "String",
+            "Enumeration"
+        ],
+        "title-slug": "number-of-valid-clock-times"
+    },
+    {
+        "leetcode-id": 2438,
+        "title": "Range Product Queries of Powers",
+        "difficulty": 2,
+        "description": "Given a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is sorted in non-decreasing order, and there is only one way to form the array.\nYou are also given a 0-indexed 2D integer array queries, where queries[i] = [lefti, righti]. Each queries[i] represents a query where you have to find the product of all powers[j] with lefti <= j <= righti.\nReturn an array answers, equal in length to queries, where answers[i] is the answer to the i^th query. Since the answer to the i^th query may be too large, each answers[i] should be returned modulo 10^9 + 7.",
+        "examples": [
+            "Example 1:\nInput: n = 15, queries = [[0,1],[2,2],[0,3]]\nOutput: [2,4,64]\nExplanation:\nFor n = 15, powers = [1,2,4,8]. It can be shown that powers cannot be a smaller size.\nAnswer to 1st query: powers[0] * powers[1] = 1 * 2 = 2.\nAnswer to 2nd query: powers[2] = 4.\nAnswer to 3rd query: powers[0] * powers[1] * powers[2] * powers[3] = 1 * 2 * 4 * 8 = 64.\nEach answer modulo 10^9 + 7 yields the same answer, so [2,4,64] is returned.",
+            "Example 2:\nInput: n = 2, queries = [[0,0]]\nOutput: [2]\nExplanation:\nFor n = 2, powers = [2].\nThe answer to the only query is powers[0] = 2. The answer modulo 10^9 + 7 is the same, so [2] is returned."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^9\n1 <= queries.length <= 10^5\n0 <= starti <= endi < powers.length",
+        "tags": [
+            "Array",
+            "Bit Manipulation",
+            "Prefix Sum"
+        ],
+        "title-slug": "range-product-queries-of-powers"
+    },
+    {
+        "leetcode-id": 2439,
+        "title": "Minimize Maximum of Array",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array nums comprising of n non-negative integers.\nIn one operation, you must:\n\nChoose an integer i such that 1 <= i < n and nums[i] > 0.\nDecrease nums[i] by 1.\nIncrease nums[i - 1] by 1.\n\nReturn the minimum possible value of the maximum integer of nums after performing any number of operations.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,7,1,6]\nOutput: 5\nExplanation:\nOne set of optimal operations is as follows:\n1. Choose i = 1, and nums becomes [4,6,1,6].\n2. Choose i = 3, and nums becomes [4,6,2,5].\n3. Choose i = 1, and nums becomes [5,5,2,5].\nThe maximum integer of nums is 5. It can be shown that the maximum number cannot be less than 5.\nTherefore, we return 5.",
+            "Example 2:\nInput: nums = [10,1]\nOutput: 10\nExplanation:\nIt is optimal to leave nums as is, and since 10 is the maximum value, we return 10."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length\n2 <= n <= 10^5\n0 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Dynamic Programming",
+            "Greedy",
+            "Prefix Sum"
+        ],
+        "title-slug": "minimize-maximum-of-array"
+    },
+    {
+        "leetcode-id": 2440,
+        "title": "Create Components With Same Value",
+        "difficulty": 3,
+        "description": "There is an undirected tree with n nodes labeled from 0 to n - 1.\nYou are given a 0-indexed integer array nums of length n where nums[i] represents the value of the i^th node. You are also given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\nYou are allowed to delete some edges, splitting the tree into multiple connected components. Let the value of a component be the sum of all nums[i] for which node i is in the component.\nReturn the maximum number of edges you can delete, such that every connected component in the tree has the same value.",
+        "examples": [
+            "Example 1:\nInput: nums = [6,2,2,2,6], edges = [[0,1],[1,2],[1,3],[3,4]] \nOutput: 2 \nExplanation: The above figure shows how we can delete the edges [0,1] and [3,4]. The created components are nodes [0], [1,2,3] and [4]. The sum of the values in each component equals 6. It can be proven that no better deletion exists, so the answer is 2.",
+            "Example 2:\nInput: nums = [2], edges = []\nOutput: 0\nExplanation: There are no edges to be deleted."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 2 * 10^4\nnums.length == n\n1 <= nums[i] <= 50\nedges.length == n - 1\nedges[i].length == 2\n0 <= edges[i][0], edges[i][1] <= n - 1\nedges represents a valid tree.",
+        "tags": [
+            "Array",
+            "Math",
+            "Tree",
+            "Depth-First Search",
+            "Enumeration"
+        ],
+        "title-slug": "create-components-with-same-value"
+    },
+    {
+        "leetcode-id": 2441,
+        "title": "Largest Positive Integer That Exists With Its Negative",
+        "difficulty": 1,
+        "description": "Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array.\nReturn the positive integer k. If there is no such integer, return -1.",
+        "examples": [
+            "Example 1:\nInput: nums = [-1,2,-3,3]\nOutput: 3\nExplanation: 3 is the only valid k we can find in the array.",
+            "Example 2:\nInput: nums = [-1,10,6,7,-7,1]\nOutput: 7\nExplanation: Both 1 and 7 have their corresponding negative values in the array. 7 has a larger value.",
+            "Example 3:\nInput: nums = [-10,8,6,7,-2,-3]\nOutput: -1\nExplanation: There is no a single valid k, we return -1."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n-1000 <= nums[i] <= 1000\nnums[i] != 0",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Two Pointers",
+            "Sorting"
+        ],
+        "title-slug": "largest-positive-integer-that-exists-with-its-negative"
+    },
+    {
+        "leetcode-id": 2442,
+        "title": "Count Number of Distinct Integers After Reverse Operations",
+        "difficulty": 2,
+        "description": "You are given an array nums consisting of positive integers.\nYou have to take each integer in the array, reverse its digits, and add it to the end of the array. You should apply this operation to the original integers in nums.\nReturn the number of distinct integers in the final array.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,13,10,12,31]\nOutput: 6\nExplanation: After including the reverse of each number, the resulting array is [1,13,10,12,31,1,31,1,21,13].\nThe reversed integers that were added to the end of the array are underlined. Note that for the integer 10, after reversing it, it becomes 01 which is just 1.\nThe number of distinct integers in this array is 6 (The numbers 1, 10, 12, 13, 21, and 31).",
+            "Example 2:\nInput: nums = [2,2,2]\nOutput: 1\nExplanation: After including the reverse of each number, the resulting array is [2,2,2,2,2,2].\nThe number of distinct integers in this array is 1 (The number 2)."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Math"
+        ],
+        "title-slug": "count-number-of-distinct-integers-after-reverse-operations"
+    },
+    {
+        "leetcode-id": 2443,
+        "title": "Sum of Number and Its Reverse",
+        "difficulty": 2,
+        "description": "Given a non-negative integer num, return true if num can be expressed as the sum of any non-negative integer and its reverse, or false otherwise.",
+        "examples": [
+            "Example 1:\nInput: num = 443\nOutput: true\nExplanation: 172 + 271 = 443 so we return true.",
+            "Example 2:\nInput: num = 63\nOutput: false\nExplanation: 63 cannot be expressed as the sum of a non-negative integer and its reverse so we return false.",
+            "Example 3:\nInput: num = 181\nOutput: true\nExplanation: 140 + 041 = 181 so we return true. Note that when a number is reversed, there may be leading zeros."
+        ],
+        "constraints": "Constraints:\n\n0 <= num <= 10^5",
+        "tags": [
+            "Math",
+            "Enumeration"
+        ],
+        "title-slug": "sum-of-number-and-its-reverse"
+    },
+    {
+        "leetcode-id": 2444,
+        "title": "Count Subarrays With Fixed Bounds",
+        "difficulty": 3,
+        "description": "You are given an integer array nums and two integers minK and maxK.\nA fixed-bound subarray of nums is a subarray that satisfies the following conditions:\n\nThe minimum value in the subarray is equal to minK.\nThe maximum value in the subarray is equal to maxK.\n\nReturn the number of fixed-bound subarrays.\nA subarray is a contiguous part of an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,5,2,7,5], minK = 1, maxK = 5\nOutput: 2\nExplanation: The fixed-bound subarrays are [1,3,5] and [1,3,5,2].",
+            "Example 2:\nInput: nums = [1,1,1,1], minK = 1, maxK = 1\nOutput: 10\nExplanation: Every subarray of nums is a fixed-bound subarray. There are 10 possible subarrays."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 10^5\n1 <= nums[i], minK, maxK <= 10^6",
+        "tags": [
+            "Array",
+            "Queue",
+            "Sliding Window",
+            "Monotonic Queue"
+        ],
+        "title-slug": "count-subarrays-with-fixed-bounds"
+    },
+    {
+        "leetcode-id": 2446,
+        "title": "Determine if Two Events Have Conflict",
+        "difficulty": 1,
+        "description": "You are given two arrays of strings that represent two inclusive events that happened on the same day, event1 and event2, where:\n\nevent1 = [startTime1, endTime1] and\nevent2 = [startTime2, endTime2].\n\nEvent times are valid 24 hours format in the form of HH:MM.\nA conflict happens when two events have some non-empty intersection (i.e., some moment is common to both events).\nReturn true if there is a conflict between two events. Otherwise, return false.",
+        "examples": [
+            "Example 1:\nInput: event1 = [\"01:15\",\"02:00\"], event2 = [\"02:00\",\"03:00\"]\nOutput: true\nExplanation: The two events intersect at time 2:00.",
+            "Example 2:\nInput: event1 = [\"01:00\",\"02:00\"], event2 = [\"01:20\",\"03:00\"]\nOutput: true\nExplanation: The two events intersect starting from 01:20 to 02:00.",
+            "Example 3:\nInput: event1 = [\"10:00\",\"11:00\"], event2 = [\"14:00\",\"15:00\"]\nOutput: false\nExplanation: The two events do not intersect."
+        ],
+        "constraints": "Constraints:\n\nevnet1.length == event2.length == 2.\nevent1[i].length == event2[i].length == 5\nstartTime1 <= endTime1\nstartTime2 <= endTime2\nAll the event times follow the HH:MM format.",
+        "tags": [
+            "Array",
+            "String"
+        ],
+        "title-slug": "determine-if-two-events-have-conflict"
+    },
+    {
+        "leetcode-id": 2447,
+        "title": "Number of Subarrays With GCD Equal to K",
+        "difficulty": 2,
+        "description": "Given an integer array nums and an integer k, return the number of subarrays of nums where the greatest common divisor of the subarray's elements is k.\nA subarray is a contiguous non-empty sequence of elements within an array.\nThe greatest common divisor of an array is the largest integer that evenly divides all the array elements.",
+        "examples": [
+            "Example 1:\nInput: nums = [9,3,1,2,6,3], k = 3\nOutput: 4\nExplanation: The subarrays of nums where 3 is the greatest common divisor of all the subarray's elements are:\n- [9,3,1,2,6,3]\n- [9,3,1,2,6,3]\n- [9,3,1,2,6,3]\n- [9,3,1,2,6,3]",
+            "Example 2:\nInput: nums = [4], k = 7\nOutput: 0\nExplanation: There are no subarrays of nums where 7 is the greatest common divisor of all the subarray's elements."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i], k <= 10^9",
+        "tags": [
+            "Array",
+            "Math",
+            "Number Theory"
+        ],
+        "title-slug": "number-of-subarrays-with-gcd-equal-to-k"
+    },
+    {
+        "leetcode-id": 2448,
+        "title": "Minimum Cost to Make Array Equal",
+        "difficulty": 3,
+        "description": "You are given two 0-indexed arrays nums and cost consisting each of n positive integers.\nYou can do the following operation any number of times:\n\nIncrease or decrease any element of the array nums by 1.\n\nThe cost of doing one operation on the i^th element is cost[i].\nReturn the minimum total cost such that all the elements of the array nums become equal.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,5,2], cost = [2,3,1,14]\nOutput: 8\nExplanation: We can make all the elements equal to 2 in the following way:\n- Increase the 0^th element one time. The cost is 2.\n- Decrease the 1^st element one time. The cost is 3.\n- Decrease the 2^nd element three times. The cost is 1 + 1 + 1 = 3.\nThe total cost is 2 + 3 + 3 = 8.\nIt can be shown that we cannot make the array equal with a smaller cost.",
+            "Example 2:\nInput: nums = [2,2,2,2,2], cost = [4,2,8,1,3]\nOutput: 0\nExplanation: All the elements are already equal, so no operations are needed."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length == cost.length\n1 <= n <= 10^5\n1 <= nums[i], cost[i] <= 10^6\nTest cases are generated in a way that the output doesn't exceed\u00a02^53-1",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Greedy",
+            "Sorting",
+            "Prefix Sum"
+        ],
+        "title-slug": "minimum-cost-to-make-array-equal"
+    },
+    {
+        "leetcode-id": 2449,
+        "title": "Minimum Number of Operations to Make Arrays Similar",
+        "difficulty": 3,
+        "description": "You are given two positive integer arrays nums and target, of the same length.\nIn one operation, you can choose any two distinct indices i and j where 0 <= i, j < nums.length and:\n\nset nums[i] = nums[i] + 2 and\nset nums[j] = nums[j] - 2.\n\nTwo arrays are considered to be similar if the frequency of each element is the same.\nReturn the minimum number of operations required to make nums similar to target. The test cases are generated such that nums can always be similar to target.",
+        "examples": [
+            "Example 1:\nInput: nums = [8,12,6], target = [2,14,10]\nOutput: 2\nExplanation: It is possible to make nums similar to target in two operations:\n- Choose i = 0 and j = 2, nums = [10,12,4].\n- Choose i = 1 and j = 2, nums = [10,14,2].\nIt can be shown that 2 is the minimum number of operations needed.",
+            "Example 2:\nInput: nums = [1,2,5], target = [4,1,3]\nOutput: 1\nExplanation: We can make nums similar to target in one operation:\n- Choose i = 1 and j = 2, nums = [1,4,3].",
+            "Example 3:\nInput: nums = [1,1,1,1,1], target = [1,1,1,1,1]\nOutput: 0\nExplanation: The array nums is already similiar to target."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length == target.length\n1 <= n <= 10^5\n1 <= nums[i], target[i] <= 10^6\nIt is possible to make nums similar to target.",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "minimum-number-of-operations-to-make-arrays-similar"
+    },
+    {
+        "leetcode-id": 2451,
+        "title": "Odd String Difference",
+        "difficulty": 1,
+        "description": "You are given an array of equal-length strings words. Assume that the length of each string is n.\nEach string words[i] can be converted into a difference integer array difference[i] of length n - 1 where difference[i][j] = words[i][j+1] - words[i][j] where 0 <= j <= n - 2. Note that the difference between two letters is the difference between their positions in the alphabet i.e.\u00a0the position of 'a' is 0, 'b' is 1, and 'z' is 25.\n\nFor example, for the string \"acb\", the difference integer array is [2 - 0, 1 - 2] = [2, -1].\n\nAll the strings in words have the same difference integer array, except one. You should find that string.\nReturn the string in words that has different difference integer array.",
+        "examples": [
+            "Example 1:\nInput: words = [\"adc\",\"wzy\",\"abc\"]\nOutput: \"abc\"\nExplanation: \n- The difference integer array of \"adc\" is [3 - 0, 2 - 3] = [3, -1].\n- The difference integer array of \"wzy\" is [25 - 22, 24 - 25]= [3, -1].\n- The difference integer array of \"abc\" is [1 - 0, 2 - 1] = [1, 1]. \nThe odd array out is [1, 1], so we return the corresponding string, \"abc\".",
+            "Example 2:\nInput: words = [\"aaa\",\"bob\",\"ccc\",\"ddd\"]\nOutput: \"bob\"\nExplanation: All the integer arrays are [0, 0] except for \"bob\", which corresponds to [13, -13]."
+        ],
+        "constraints": "Constraints:\n\n3 <= words.length <= 100\nn == words[i].length\n2 <= n <= 20\nwords[i] consists of lowercase English letters.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String"
+        ],
+        "title-slug": "odd-string-difference"
+    },
+    {
+        "leetcode-id": 2452,
+        "title": "Words Within Two Edits of Dictionary",
+        "difficulty": 2,
+        "description": "You are given two string arrays, queries and dictionary. All words in each array comprise of lowercase English letters and have the same length.\nIn one edit you can take a word from queries, and change any letter in it to any other letter. Find all words from queries that, after a maximum of two edits, equal some word from dictionary.\nReturn a list of all words from queries, that match with some word from dictionary after a maximum of two edits. Return the words in the same order they appear in queries.",
+        "examples": [
+            "Example 1:\nInput: queries = [\"word\",\"note\",\"ants\",\"wood\"], dictionary = [\"wood\",\"joke\",\"moat\"]\nOutput: [\"word\",\"note\",\"wood\"]\nExplanation:\n- Changing the 'r' in \"word\" to 'o' allows it to equal the dictionary word \"wood\".\n- Changing the 'n' to 'j' and the 't' to 'k' in \"note\" changes it to \"joke\".\n- It would take more than 2 edits for \"ants\" to equal a dictionary word.\n- \"wood\" can remain unchanged (0 edits) and match the corresponding dictionary word.\nThus, we return [\"word\",\"note\",\"wood\"].",
+            "Example 2:\nInput: queries = [\"yes\"], dictionary = [\"not\"]\nOutput: []\nExplanation:\nApplying any two edits to \"yes\" cannot make it equal to \"not\". Thus, we return an empty array."
+        ],
+        "constraints": "Constraints:\n\n1 <= queries.length, dictionary.length <= 100\nn == queries[i].length == dictionary[j].length\n1 <= n <= 100\nAll queries[i] and dictionary[j] are composed of lowercase English letters.",
+        "tags": [
+            "Array",
+            "String"
+        ],
+        "title-slug": "words-within-two-edits-of-dictionary"
+    },
+    {
+        "leetcode-id": 2453,
+        "title": "Destroy Sequential Targets",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array nums consisting of positive integers, representing targets on a number line. You are also given an integer space.\nYou have a machine which can destroy targets. Seeding the machine with some nums[i] allows it to destroy all targets with values that can be represented as nums[i] + c * space, where c is any non-negative integer. You want to destroy the maximum number of targets in nums.\nReturn the minimum value of nums[i] you can seed the machine with to destroy the maximum number of targets.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,7,8,1,1,5], space = 2\nOutput: 1\nExplanation: If we seed the machine with nums[3], then we destroy all targets equal to 1,3,5,7,9,... \nIn this case, we would destroy 5 total targets (all except for nums[2]). \nIt is impossible to destroy more than 5 targets, so we return nums[3].",
+            "Example 2:\nInput: nums = [1,3,5,2,4,6], space = 2\nOutput: 1\nExplanation: Seeding the machine with nums[0], or nums[3] destroys 3 targets. \nIt is not possible to destroy more than 3 targets.\nSince nums[0] is the minimal integer that can destroy 3 targets, we return 1.",
+            "Example 3:\nInput: nums = [6,2,5], space = 100\nOutput: 2\nExplanation: Whatever initial seed we select, we can only destroy 1 target. The minimal seed is nums[1]."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\n1 <= space <=\u00a010^9",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Counting"
+        ],
+        "title-slug": "destroy-sequential-targets"
+    },
+    {
+        "leetcode-id": 2454,
+        "title": "Next Greater Element IV",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed array of non-negative integers nums. For each integer in nums, you must find its respective second greater integer.\nThe second greater integer of nums[i] is nums[j] such that:\n\nj > i\nnums[j] > nums[i]\nThere exists exactly one index k such that nums[k] > nums[i] and i < k < j.\n\nIf there is no such nums[j], the second greater integer is considered to be -1.\n\nFor example, in the array [1, 2, 4, 3], the second greater integer of 1 is 4, 2 is 3,\u00a0and that of 3 and 4 is -1.\n\nReturn an integer array answer, where answer[i] is the second greater integer of nums[i].",
+        "examples": [
+            "Example 1:\nInput: nums = [2,4,0,9,6]\nOutput: [9,6,6,-1,-1]\nExplanation:\n0th index: 4 is the first integer greater than 2, and 9 is the second integer greater than 2, to the right of 2.\n1st index: 9 is the first, and 6 is the second integer greater than 4, to the right of 4.\n2nd index: 9 is the first, and 6 is the second integer greater than 0, to the right of 0.\n3rd index: There is no integer greater than 9 to its right, so the second greater integer is considered to be -1.\n4th index: There is no integer greater than 6 to its right, so the second greater integer is considered to be -1.\nThus, we return [9,6,6,-1,-1].",
+            "Example 2:\nInput: nums = [3,3]\nOutput: [-1,-1]\nExplanation:\nWe return [-1,-1] since neither integer has any integer greater than it."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Stack",
+            "Sorting",
+            "Heap (Priority Queue)",
+            "Monotonic Stack"
+        ],
+        "title-slug": "next-greater-element-iv"
+    },
+    {
+        "leetcode-id": 2455,
+        "title": "Average Value of Even Numbers That Are Divisible by Three",
+        "difficulty": 1,
+        "description": "Given an integer array nums of positive integers, return the average value of all even integers that are divisible by 3.\nNote that the average of n elements is the sum of the n elements divided by n and rounded down to the nearest integer.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,6,10,12,15]\nOutput: 9\nExplanation: 6 and 12 are even numbers that are divisible by 3. (6 + 12) / 2 = 9.",
+            "Example 2:\nInput: nums = [1,2,4,7,10]\nOutput: 0\nExplanation: There is no single number that satisfies the requirement, so return 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 1000",
+        "tags": [
+            "Array",
+            "Math"
+        ],
+        "title-slug": "average-value-of-even-numbers-that-are-divisible-by-three"
+    },
+    {
+        "leetcode-id": 2456,
+        "title": "Most Popular Video Creator",
+        "difficulty": 2,
+        "description": "You are given two string arrays creators and ids, and an integer array views, all of length n. The i^th video on a platform was created by creator[i], has an id of ids[i], and has views[i] views.\nThe popularity of a creator is the sum of the number of views on all of the creator's videos. Find the creator with the highest popularity and the id of their most viewed video.\n\nIf multiple creators have the highest popularity, find all of them.\nIf multiple videos have the highest view count for a creator, find the lexicographically smallest id.\n\nReturn a 2D array of strings answer where answer[i] = [creatori, idi] means that creatori has the highest popularity and idi is the id of their most popular video. The answer can be returned in any order.",
+        "examples": [
+            "Example 1:\nInput: creators = [\"alice\",\"bob\",\"alice\",\"chris\"], ids = [\"one\",\"two\",\"three\",\"four\"], views = [5,10,5,4]\nOutput: [[\"alice\",\"one\"],[\"bob\",\"two\"]]\nExplanation:\nThe popularity of alice is 5 + 5 = 10.\nThe popularity of bob is 10.\nThe popularity of chris is 4.\nalice and bob are the most popular creators.\nFor bob, the video with the highest view count is \"two\".\nFor alice, the videos with the highest view count are \"one\" and \"three\". Since \"one\" is lexicographically smaller than \"three\", it is included in the answer.",
+            "Example 2:\nInput: creators = [\"alice\",\"alice\",\"alice\"], ids = [\"a\",\"b\",\"c\"], views = [1,2,2]\nOutput: [[\"alice\",\"b\"]]\nExplanation:\nThe videos with id \"b\" and \"c\" have the highest view count.\nSince \"b\" is lexicographically smaller than \"c\", it is included in the answer."
+        ],
+        "constraints": "Constraints:\n\nn == creators.length == ids.length == views.length\n1 <= n <= 10^5\n1 <= creators[i].length, ids[i].length <= 5\ncreators[i] and ids[i] consist only of lowercase English letters.\n0 <= views[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "most-popular-video-creator"
+    },
+    {
+        "leetcode-id": 2457,
+        "title": "Minimum Addition to Make Integer Beautiful",
+        "difficulty": 2,
+        "description": "You are given two positive integers n and target.\nAn integer is considered beautiful if the sum of its digits is less than or equal to target.\nReturn the minimum non-negative integer x such that n + x is beautiful. The input will be generated such that it is always possible to make n beautiful.",
+        "examples": [
+            "Example 1:\nInput: n = 16, target = 6\nOutput: 4\nExplanation: Initially n is 16 and its digit sum is 1 + 6 = 7. After adding 4, n becomes 20 and digit sum becomes 2 + 0 = 2. It can be shown that we can not make n beautiful with adding non-negative integer less than 4.",
+            "Example 2:\nInput: n = 467, target = 6\nOutput: 33\nExplanation: Initially n is 467 and its digit sum is 4 + 6 + 7 = 17. After adding 33, n becomes 500 and digit sum becomes 5 + 0 + 0 = 5. It can be shown that we can not make n beautiful with adding non-negative integer less than 33.",
+            "Example 3:\nInput: n = 1, target = 1\nOutput: 0\nExplanation: Initially n is 1 and its digit sum is 1, which is already smaller than or equal to target."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^12\n1 <= target <= 150\nThe input will be generated such that it is always possible to make n beautiful.",
+        "tags": [
+            "Math",
+            "Greedy"
+        ],
+        "title-slug": "minimum-addition-to-make-integer-beautiful"
+    },
+    {
+        "leetcode-id": 2458,
+        "title": "Height of Binary Tree After Subtree Removal Queries",
+        "difficulty": 3,
+        "description": "You are given the root of a binary tree with n nodes. Each node is assigned a unique value from 1 to n. You are also given an array queries of size m.\nYou have to perform m independent queries on the tree where in the i^th query you do the following:\n\nRemove the subtree rooted at the node with the value queries[i] from the tree. It is guaranteed that queries[i] will not be equal to the value of the root.\n\nReturn an array answer of size m where answer[i] is the height of the tree after performing the i^th query.\nNote:\n\nThe queries are independent, so the tree returns to its initial state after each query.\nThe height of a tree is the number of edges in the longest simple path from the root to some node in the tree.",
+        "examples": [
+            "Example 1:\nInput: root = [1,3,4,2,null,6,5,null,null,null,null,null,7], queries = [4]\nOutput: [2]\nExplanation: The diagram above shows the tree after removing the subtree rooted at node with value 4.\nThe height of the tree is 2 (The path 1 -> 3 -> 2).",
+            "Example 2:\nInput: root = [5,8,9,2,1,3,7,4,6], queries = [3,2,4,8]\nOutput: [3,2,3,2]\nExplanation: We have the following queries:\n- Removing the subtree rooted at node with value 3. The height of the tree becomes 3 (The path 5 -> 8 -> 2 -> 4).\n- Removing the subtree rooted at node with value 2. The height of the tree becomes 2 (The path 5 -> 8 -> 1).\n- Removing the subtree rooted at node with value 4. The height of the tree becomes 3 (The path 5 -> 8 -> 2 -> 6).\n- Removing the subtree rooted at node with value 8. The height of the tree becomes 2 (The path 5 -> 9 -> 3)."
+        ],
+        "constraints": "Constraints:\n\nThe number of nodes in the tree is n.\n2 <= n <= 10^5\n1 <= Node.val <= n\nAll the values in the tree are unique.\nm == queries.length\n1 <= m <= min(n, 10^4)\n1 <= queries[i] <= n\nqueries[i] != root.val",
+        "tags": [
+            "Array",
+            "Tree",
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Binary Tree"
+        ],
+        "title-slug": "height-of-binary-tree-after-subtree-removal-queries"
+    },
+    {
+        "leetcode-id": 2460,
+        "title": "Apply Operations to an Array",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed array nums of size n consisting of non-negative integers.\nYou need to apply n - 1 operations to this array where, in the i^th operation (0-indexed), you will apply the following on the i^th element of nums:\n\nIf nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. Otherwise, you skip this operation.\n\nAfter performing all the operations, shift all the 0's to the end of the array.\n\nFor example, the array [1,0,2,0,0,1] after shifting all its 0's to the end, is [1,2,1,0,0,0].\n\nReturn the resulting array.\nNote that the operations are applied sequentially, not all at once.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,2,1,1,0]\nOutput: [1,4,2,0,0,0]\nExplanation: We do the following operations:\n- i = 0: nums[0] and nums[1] are not equal, so we skip this operation.\n- i = 1: nums[1] and nums[2] are equal, we multiply nums[1] by 2 and change nums[2] to 0. The array becomes [1,4,0,1,1,0].\n- i = 2: nums[2] and nums[3] are not equal, so we skip this operation.\n- i = 3: nums[3] and nums[4] are equal, we multiply nums[3] by 2 and change nums[4] to 0. The array becomes [1,4,0,2,0,0].\n- i = 4: nums[4] and nums[5] are equal, we multiply nums[4] by 2 and change nums[5] to 0. The array becomes [1,4,0,2,0,0].\nAfter that, we shift the 0's to the end, which gives the array [1,4,2,0,0,0].",
+            "Example 2:\nInput: nums = [0,1]\nOutput: [1,0]\nExplanation: No operation can be applied, we just shift the 0 to the end."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 2000\n0 <= nums[i] <= 1000",
+        "tags": [
+            "Array",
+            "Simulation"
+        ],
+        "title-slug": "apply-operations-to-an-array"
+    },
+    {
+        "leetcode-id": 2461,
+        "title": "Maximum Sum of Distinct Subarrays With Length K",
+        "difficulty": 2,
+        "description": "You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that meet the following conditions:\n\nThe length of the subarray is k, and\nAll the elements of the subarray are distinct.\n\nReturn the maximum subarray sum of all the subarrays that meet the conditions. If no subarray meets the conditions, return 0.\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,5,4,2,9,9,9], k = 3\nOutput: 15\nExplanation: The subarrays of nums with length 3 are:\n- [1,5,4] which meets the requirements and has a sum of 10.\n- [5,4,2] which meets the requirements and has a sum of 11.\n- [4,2,9] which meets the requirements and has a sum of 15.\n- [2,9,9] which does not meet the requirements because the element 9 is repeated.\n- [9,9,9] which does not meet the requirements because the element 9 is repeated.\nWe return 15 because it is the maximum subarray sum of all the subarrays that meet the conditions",
+            "Example 2:\nInput: nums = [4,4,4], k = 3\nOutput: 0\nExplanation: The subarrays of nums with length 3 are:\n- [4,4,4] which does not meet the requirements because the element 4 is repeated.\nWe return 0 because no subarrays meet the conditions."
+        ],
+        "constraints": "Constraints:\n\n1 <= k <= nums.length <= 10^5\n1 <= nums[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sliding Window"
+        ],
+        "title-slug": "maximum-sum-of-distinct-subarrays-with-length-k"
+    },
+    {
+        "leetcode-id": 2462,
+        "title": "Total Cost to Hire K Workers",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the i^th worker.\nYou are also given two integers k and candidates. We want to hire exactly k workers according to the following rules:\n\nYou will run k sessions and hire exactly one worker in each session.\nIn each hiring session, choose the worker with the lowest cost from either the first candidates workers or the last candidates workers. Break the tie by the smallest index.\n\t\nFor example, if costs = [3,2,7,7,1,2] and candidates = 2, then in the first hiring session, we will choose the 4^th worker because they have the lowest cost [3,2,7,7,1,2].\nIn the second hiring session, we will choose 1^st worker because they have the same lowest cost as 4^th worker but they have the smallest index [3,2,7,7,2]. Please note that the indexing may be changed in the process.\n\n\nIf there are fewer than candidates workers remaining, choose the worker with the lowest cost among them. Break the tie by the smallest index.\nA worker can only be chosen once.\n\nReturn the total cost to hire exactly k workers.",
+        "examples": [
+            "Example 1:\nInput: costs = [17,12,10,2,7,2,11,20,8], k = 3, candidates = 4\nOutput: 11\nExplanation: We hire 3 workers in total. The total cost is initially 0.\n- In the first hiring round we choose the worker from [17,12,10,2,7,2,11,20,8]. The lowest cost is 2, and we break the tie by the smallest index, which is 3. The total cost = 0 + 2 = 2.\n- In the second hiring round we choose the worker from [17,12,10,7,2,11,20,8]. The lowest cost is 2 (index 4). The total cost = 2 + 2 = 4.\n- In the third hiring round we choose the worker from [17,12,10,7,11,20,8]. The lowest cost is 7 (index 3). The total cost = 4 + 7 = 11. Notice that the worker with index 3 was common in the first and last four workers.\nThe total hiring cost is 11.",
+            "Example 2:\nInput: costs = [1,2,4,1], k = 3, candidates = 3\nOutput: 4\nExplanation: We hire 3 workers in total. The total cost is initially 0.\n- In the first hiring round we choose the worker from [1,2,4,1]. The lowest cost is 1, and we break the tie by the smallest index, which is 0. The total cost = 0 + 1 = 1. Notice that workers with index 1 and 2 are common in the first and last 3 workers.\n- In the second hiring round we choose the worker from [2,4,1]. The lowest cost is 1 (index 2). The total cost = 1 + 1 = 2.\n- In the third hiring round there are less than three candidates. We choose the worker from the remaining workers [2,4]. The lowest cost is 2 (index 0). The total cost = 2 + 2 = 4.\nThe total hiring cost is 4."
+        ],
+        "constraints": "Constraints:\n\n1 <= costs.length <= 10^5 \n1 <= costs[i] <= 10^5\n1 <= k, candidates <= costs.length",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Heap (Priority Queue)",
+            "Simulation"
+        ],
+        "title-slug": "total-cost-to-hire-k-workers"
+    },
+    {
+        "leetcode-id": 2463,
+        "title": "Minimum Total Distance Traveled",
+        "difficulty": 3,
+        "description": "There are some robots and factories on the X-axis. You are given an integer array robot where robot[i] is the position of the i^th robot. You are also given a 2D integer array factory where factory[j] = [positionj, limitj] indicates that positionj is the position of the j^th factory and that the j^th factory can repair at most limitj robots.\nThe positions of each robot are unique. The positions of each factory are also unique. Note that a robot can be in the same position as a factory initially.\nAll the robots are initially broken; they keep moving in one direction. The direction could be the negative or the positive direction of the X-axis. When a robot reaches a factory that did not reach its limit, the factory repairs the robot, and it stops moving.\nAt any moment, you can set the initial direction of moving for some robot. Your target is to minimize the total distance traveled by all the robots.\nReturn the minimum total distance traveled by all the robots. The test cases are generated such that all the robots can be repaired.\nNote that\n\nAll robots move at the same speed.\nIf two robots move in the same direction, they will never collide.\nIf two robots move in opposite directions and they meet at some point, they do not collide. They cross each other.\nIf a robot passes by a factory that reached its limits, it crosses it as if it does not exist.\nIf the robot moved from a position x to a position y, the distance it moved is |y - x|.",
+        "examples": [
+            "Example 1:\nInput: robot = [0,4,6], factory = [[2,2],[6,2]]\nOutput: 4\nExplanation: As shown in the figure:\n- The first robot at position 0 moves in the positive direction. It will be repaired at the first factory.\n- The second robot at position 4 moves in the negative direction. It will be repaired at the first factory.\n- The third robot at position 6 will be repaired at the second factory. It does not need to move.\nThe limit of the first factory is 2, and it fixed 2 robots.\nThe limit of the second factory is 2, and it fixed 1 robot.\nThe total distance is |2 - 0| + |2 - 4| + |6 - 6| = 4. It can be shown that we cannot achieve a better total distance than 4.",
+            "Example 2:\nInput: robot = [1,-1], factory = [[-2,1],[2,1]]\nOutput: 2\nExplanation: As shown in the figure:\n- The first robot at position 1 moves in the positive direction. It will be repaired at the second factory.\n- The second robot at position -1 moves in the negative direction. It will be repaired at the first factory.\nThe limit of the first factory is 1, and it fixed 1 robot.\nThe limit of the second factory is 1, and it fixed 1 robot.\nThe total distance is |2 - 1| + |(-2) - (-1)| = 2. It can be shown that we cannot achieve a better total distance than 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= robot.length, factory.length <= 100\nfactory[j].length == 2\n-10^9 <= robot[i], positionj <= 10^9\n0 <= limitj <= robot.length\nThe input will be generated such that it is always possible to repair every robot.",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Sorting"
+        ],
+        "title-slug": "minimum-total-distance-traveled"
+    },
+    {
+        "leetcode-id": 2465,
+        "title": "Number of Distinct Averages",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums of even length.\nAs long as nums is not empty, you must repetitively:\n\nFind the minimum number in nums and remove it.\nFind the maximum number in nums and remove it.\nCalculate the average of the two removed numbers.\n\nThe average of two numbers a and b is (a + b) / 2.\n\nFor example, the average of 2 and 3 is (2 + 3) / 2 = 2.5.\n\nReturn the number of distinct averages calculated using the above process.\nNote that when there is a tie for a minimum or maximum number, any can be removed.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,1,4,0,3,5]\nOutput: 2\nExplanation:\n1. Remove 0 and 5, and the average is (0 + 5) / 2 = 2.5. Now, nums = [4,1,4,3].\n2. Remove 1 and 4. The average is (1 + 4) / 2 = 2.5, and nums = [4,3].\n3. Remove 3 and 4, and the average is (3 + 4) / 2 = 3.5.\nSince there are 2 distinct numbers among 2.5, 2.5, and 3.5, we return 2.",
+            "Example 2:\nInput: nums = [1,100]\nOutput: 1\nExplanation:\nThere is only one average to be calculated after removing 1 and 100, so we return 1."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 100\nnums.length is even.\n0 <= nums[i] <= 100",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Two Pointers",
+            "Sorting"
+        ],
+        "title-slug": "number-of-distinct-averages"
+    },
+    {
+        "leetcode-id": 2466,
+        "title": "Count Ways To Build Good Strings",
+        "difficulty": 2,
+        "description": "Given the integers zero, one, low, and high, we can construct a string by starting with an empty string, and then at each step perform either of the following:\n\nAppend the character '0' zero times.\nAppend the character '1' one times.\n\nThis can be performed any number of times.\nA good string is a string constructed by the above process having a length between low and high (inclusive).\nReturn the number of different good strings that can be constructed satisfying these properties. Since the answer can be large, return it modulo 10^9 + 7.",
+        "examples": [
+            "Example 1:\nInput: low = 3, high = 3, zero = 1, one = 1\nOutput: 8\nExplanation: \nOne possible valid good string is \"011\". \nIt can be constructed as follows: \"\" -> \"0\" -> \"01\" -> \"011\". \nAll binary strings from \"000\" to \"111\" are good strings in this example.",
+            "Example 2:\nInput: low = 2, high = 3, zero = 1, one = 2\nOutput: 5\nExplanation: The good strings are \"00\", \"11\", \"000\", \"110\", and \"011\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= low\u00a0<= high\u00a0<= 10^5\n1 <= zero, one <= low",
+        "tags": [
+            "Dynamic Programming"
+        ],
+        "title-slug": "count-ways-to-build-good-strings"
+    },
+    {
+        "leetcode-id": 2467,
+        "title": "Most Profitable Path in a Tree",
+        "difficulty": 2,
+        "description": "There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\nAt every node i, there is a gate. You are also given an array of even integers amount, where amount[i] represents:\n\nthe price needed to open the gate at node i, if amount[i] is negative, or,\nthe cash reward obtained on opening the gate at node i, otherwise.\n\nThe game goes on as follows:\n\nInitially, Alice is at node 0 and Bob is at node bob.\nAt every second, Alice and Bob each move to an adjacent node. Alice moves towards some leaf node, while Bob moves towards node 0.\nFor every node along their path, Alice and Bob either spend money to open the gate at that node, or accept the reward. Note that:\n\t\nIf the gate is already open, no price will be required, nor will there be any cash reward.\nIf Alice and Bob reach the node simultaneously, they share the price/reward for opening the gate there. In other words, if the price to open the gate is c, then both Alice and Bob pay\u00a0c / 2 each. Similarly, if the reward at the gate is c, both of them receive c / 2 each.\n\n\nIf Alice reaches a leaf node, she stops moving. Similarly, if Bob reaches node 0, he stops moving. Note that these events are independent of each other.\n\nReturn the maximum net income Alice can have if she travels towards the optimal leaf node.",
+        "examples": [
+            "Example 1:\nInput: edges = [[0,1],[1,2],[1,3],[3,4]], bob = 3, amount = [-2,4,2,-4,6]\nOutput: 6\nExplanation: \nThe above diagram represents the given tree. The game goes as follows:\n- Alice is initially on node 0, Bob on node 3. They open the gates of their respective nodes.\n  Alice's net income is now -2.\n- Both Alice and Bob move to node 1. \n\u00a0 Since they reach here simultaneously, they open the gate together and share the reward.\n\u00a0 Alice's net income becomes -2 + (4 / 2) = 0.\n- Alice moves on to node 3. Since Bob already opened its gate, Alice's income remains unchanged.\n\u00a0 Bob moves on to node 0, and stops moving.\n- Alice moves on to node 4 and opens the gate there. Her net income becomes 0 + 6 = 6.\nNow, neither Alice nor Bob can make any further moves, and the game ends.\nIt is not possible for Alice to get a higher net income.",
+            "Example 2:\nInput: edges = [[0,1]], bob = 1, amount = [-7280,2350]\nOutput: -7280\nExplanation: \nAlice follows the path 0->1 whereas Bob follows the path 1->0.\nThus, Alice opens the gate at node 0 only. Hence, her net income is -7280."
+        ],
+        "constraints": "Constraints:\n\n2 <= n <= 10^5\nedges.length == n - 1\nedges[i].length == 2\n0 <= ai, bi < n\nai != bi\nedges represents a valid tree.\n1 <= bob < n\namount.length == n\namount[i] is an even integer in the range [-10^4, 10^4].",
+        "tags": [
+            "Array",
+            "Tree",
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Graph"
+        ],
+        "title-slug": "most-profitable-path-in-a-tree"
+    },
+    {
+        "leetcode-id": 2468,
+        "title": "Split Message Based on Limit",
+        "difficulty": 3,
+        "description": "You are given a string, message, and a positive integer, limit.\nYou must split message into one or more parts based on limit. Each resulting part should have the suffix \"\", where \"b\" is to be replaced with the total number of parts and \"a\" is to be replaced with the index of the part, starting from 1 and going up to b. Additionally, the length of each resulting part (including its suffix) should be equal to limit, except for the last part whose length can be at most limit.\nThe resulting parts should be formed such that when their suffixes are removed and they are all concatenated in order, they should be equal to message. Also, the result should contain as few parts as possible.\nReturn the parts message would be split into as an array of strings. If it is impossible to split message as required, return an empty array.",
+        "examples": [
+            "Example 1:\nInput: message = \"this is really a very awesome message\", limit = 9\nOutput: [\"thi<1/14>\",\"s i<2/14>\",\"s r<3/14>\",\"eal<4/14>\",\"ly <5/14>\",\"a v<6/14>\",\"ery<7/14>\",\" aw<8/14>\",\"eso<9/14>\",\"me<10/14>\",\" m<11/14>\",\"es<12/14>\",\"sa<13/14>\",\"ge<14/14>\"]\nExplanation:\nThe first 9 parts take 3 characters each from the beginning of message.\nThe next 5 parts take 2 characters each to finish splitting message. \nIn this example, each part, including the last, has length 9. \nIt can be shown it is not possible to split message into less than 14 parts.",
+            "Example 2:\nInput: message = \"short message\", limit = 15\nOutput: [\"short mess<1/2>\",\"age<2/2>\"]\nExplanation:\nUnder the given constraints, the string can be split into two parts: \n- The first part comprises of the first 10 characters, and has a length 15.\n- The next part comprises of the last 3 characters, and has a length 8."
+        ],
+        "constraints": "Constraints:\n\n1 <= message.length <= 10^4\nmessage consists only of lowercase English letters and ' '.\n1 <= limit <= 10^4",
+        "tags": [
+            "String",
+            "Binary Search"
+        ],
+        "title-slug": "split-message-based-on-limit"
+    },
+    {
+        "leetcode-id": 2469,
+        "title": "Convert the Temperature",
+        "difficulty": 1,
+        "description": "You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius.\nYou should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit].\nReturn the array ans. Answers within 10^-5 of the actual answer will be accepted.\nNote that:\n\nKelvin = Celsius + 273.15\nFahrenheit = Celsius * 1.80 + 32.00",
+        "examples": [
+            "Example 1:\nInput: celsius = 36.50\nOutput: [309.65000,97.70000]\nExplanation: Temperature at 36.50 Celsius converted in Kelvin is 309.65 and converted in Fahrenheit is 97.70.",
+            "Example 2:\nInput: celsius = 122.11\nOutput: [395.26000,251.79800]\nExplanation: Temperature at 122.11 Celsius converted in Kelvin is 395.26 and converted in Fahrenheit is 251.798."
+        ],
+        "constraints": "Constraints:\n\n0 <= celsius <= 1000",
+        "tags": [
+            "Math"
+        ],
+        "title-slug": "convert-the-temperature"
+    },
+    {
+        "leetcode-id": 2470,
+        "title": "Number of Subarrays With LCM Equal to K",
+        "difficulty": 2,
+        "description": "Given an integer array nums and an integer k, return the number of subarrays of nums where the least common multiple of the subarray's elements is k.\nA subarray is a contiguous non-empty sequence of elements within an array.\nThe least common multiple of an array is the smallest positive integer that is divisible by all the array elements.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,6,2,7,1], k = 6\nOutput: 4\nExplanation: The subarrays of nums where 6 is the least common multiple of all the subarray's elements are:\n- [3,6,2,7,1]\n- [3,6,2,7,1]\n- [3,6,2,7,1]\n- [3,6,2,7,1]",
+            "Example 2:\nInput: nums = [3], k = 2\nOutput: 0\nExplanation: There are no subarrays of nums where 2 is the least common multiple of all the subarray's elements."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i], k <= 1000",
+        "tags": [
+            "Array",
+            "Math",
+            "Number Theory"
+        ],
+        "title-slug": "number-of-subarrays-with-lcm-equal-to-k"
+    },
+    {
+        "leetcode-id": 2471,
+        "title": "Minimum Number of Operations to Sort a Binary Tree by Level",
+        "difficulty": 2,
+        "description": "You are given the root of a binary tree with unique values.\nIn one operation, you can choose any two nodes at the same level and swap their values.\nReturn the minimum number of operations needed to make the values at each level sorted in a strictly increasing order.\nThe level of a node is the number of edges along the path between it and the root node.",
+        "examples": [
+            "Example 1:\nInput: root = [1,4,3,7,6,8,5,null,null,null,null,9,null,10]\nOutput: 3\nExplanation:\n- Swap 4 and 3. The 2^nd level becomes [3,4].\n- Swap 7 and 5. The 3^rd level becomes [5,6,8,7].\n- Swap 8 and 7. The 3^rd level becomes [5,6,7,8].\nWe used 3 operations so return 3.\nIt can be proven that 3 is the minimum number of operations needed.",
+            "Example 2:\nInput: root = [1,3,2,7,6,5,4]\nOutput: 3\nExplanation:\n- Swap 3 and 2. The 2^nd level becomes [2,3].\n- Swap 7 and 4. The 3^rd level becomes [4,6,5,7].\n- Swap 6 and 5. The 3^rd level becomes [4,5,6,7].\nWe used 3 operations so return 3.\nIt can be proven that 3 is the minimum number of operations needed.",
+            "Example 3:\nInput: root = [1,2,3,4,5,6]\nOutput: 0\nExplanation: Each level is already sorted in increasing order so return 0."
+        ],
+        "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^5].\n1 <= Node.val <= 10^5\nAll the values of the tree are unique.",
+        "tags": [
+            "Tree",
+            "Breadth-First Search",
+            "Binary Tree"
+        ],
+        "title-slug": "minimum-number-of-operations-to-sort-a-binary-tree-by-level"
+    },
+    {
+        "leetcode-id": 2472,
+        "title": "Maximum Number of Non-overlapping Palindrome Substrings",
+        "difficulty": 3,
+        "description": "You are given a string s and a positive integer k.\nSelect a set of non-overlapping substrings from the string s that satisfy the following conditions:\n\nThe length of each substring is at least k.\nEach substring is a palindrome.\n\nReturn the maximum number of substrings in an optimal selection.\nA substring is a contiguous sequence of characters within a string.",
+        "examples": [
+            "Example 1:\nInput: s = \"abaccdbbd\", k = 3\nOutput: 2\nExplanation: We can select the substrings underlined in s = \"abaccdbbd\". Both \"aba\" and \"dbbd\" are palindromes and have a length of at least k = 3.\nIt can be shown that we cannot find a selection with more than two valid substrings.",
+            "Example 2:\nInput: s = \"adbcda\", k = 2\nOutput: 0\nExplanation: There is no palindrome substring of length at least 2 in the string."
+        ],
+        "constraints": "Constraints:\n\n1 <= k <= s.length <= 2000\ns consists of lowercase English letters.",
+        "tags": [
+            "String",
+            "Dynamic Programming"
+        ],
+        "title-slug": "maximum-number-of-non-overlapping-palindrome-substrings"
+    },
+    {
+        "leetcode-id": 2475,
+        "title": "Number of Unequal Triplets in Array",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed array of positive integers nums. Find the number of triplets (i, j, k) that meet the following conditions:\n\n0 <= i < j < k < nums.length\nnums[i], nums[j], and nums[k] are pairwise distinct.\n\t\nIn other words, nums[i] != nums[j], nums[i] != nums[k], and nums[j] != nums[k].\n\n\n\nReturn the number of triplets that meet the conditions.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,4,2,4,3]\nOutput: 3\nExplanation: The following triplets meet the conditions:\n- (0, 2, 4) because 4 != 2 != 3\n- (1, 2, 4) because 4 != 2 != 3\n- (2, 3, 4) because 2 != 4 != 3\nSince there are 3 triplets, we return 3.\nNote that (2, 0, 4) is not a valid triplet because 2 > 0.",
+            "Example 2:\nInput: nums = [1,1,1,1,1]\nOutput: 0\nExplanation: No triplets meet the conditions so we return 0."
+        ],
+        "constraints": "Constraints:\n\n3 <= nums.length <= 100\n1 <= nums[i] <= 1000",
+        "tags": [
+            "Array",
+            "Hash Table"
+        ],
+        "title-slug": "number-of-unequal-triplets-in-array"
+    },
+    {
+        "leetcode-id": 2476,
+        "title": "Closest Nodes Queries in a Binary Search Tree",
+        "difficulty": 2,
+        "description": "You are given the root of a binary search tree and an array queries of size n consisting of positive integers.\nFind a 2D array answer of size n where answer[i] = [mini, maxi]:\n\nmini is the largest value in the tree that is smaller than or equal to queries[i]. If a such value does not exist, add -1 instead.\nmaxi is the smallest value in the tree that is greater than or equal to queries[i]. If a such value does not exist, add -1 instead.\n\nReturn the array answer.",
+        "examples": [
+            "Example 1:\nInput: root = [6,2,13,1,4,9,15,null,null,null,null,null,null,14], queries = [2,5,16]\nOutput: [[2,2],[4,6],[15,-1]]\nExplanation: We answer the queries in the following way:\n- The largest number that is smaller or equal than 2 in the tree is 2, and the smallest number that is greater or equal than 2 is still 2. So the answer for the first query is [2,2].\n- The largest number that is smaller or equal than 5 in the tree is 4, and the smallest number that is greater or equal than 5 is 6. So the answer for the second query is [4,6].\n- The largest number that is smaller or equal than 16 in the tree is 15, and the smallest number that is greater or equal than 16 does not exist. So the answer for the third query is [15,-1].",
+            "Example 2:\nInput: root = [4,null,9], queries = [3]\nOutput: [[-1,4]]\nExplanation: The largest number that is smaller or equal to 3 in the tree does not exist, and the smallest number that is greater or equal to 3 is 4. So the answer for the query is [-1,4]."
+        ],
+        "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [2, 10^5].\n1 <= Node.val <= 10^6\nn == queries.length\n1 <= n <= 10^5\n1 <= queries[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Tree",
+            "Depth-First Search",
+            "Binary Tree"
+        ],
+        "title-slug": "closest-nodes-queries-in-a-binary-search-tree"
+    },
+    {
+        "leetcode-id": 2477,
+        "title": "Minimum Fuel Cost to Report to the Capital",
+        "difficulty": 2,
+        "description": "There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of n cities numbered from 0 to n - 1 and exactly n - 1 roads. The capital city is city 0. You are given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connecting cities ai and bi.\nThere is a meeting for the representatives of each city. The meeting is in the capital city.\nThere is a car in each city. You are given an integer seats that indicates the number of seats in each car.\nA representative can use the car in their city to travel or change the car and ride with another representative. The cost of traveling between two cities is one liter of fuel.\nReturn the minimum number of liters of fuel to reach the capital city.",
+        "examples": [
+            "Example 1:\nInput: roads = [[0,1],[0,2],[0,3]], seats = 5\nOutput: 3\nExplanation: \n- Representative1 goes directly to the capital with 1 liter of fuel.\n- Representative2 goes directly to the capital with 1 liter of fuel.\n- Representative3 goes directly to the capital with 1 liter of fuel.\nIt costs 3 liters of fuel at minimum. \nIt can be proven that 3 is the minimum number of liters of fuel needed.",
+            "Example 2:\nInput: roads = [[3,1],[3,2],[1,0],[0,4],[0,5],[4,6]], seats = 2\nOutput: 7\nExplanation: \n- Representative2 goes directly to city 3 with 1 liter of fuel.\n- Representative2 and representative3 go together to city 1 with 1 liter of fuel.\n- Representative2 and representative3 go together to the capital with 1 liter of fuel.\n- Representative1 goes directly to the capital with 1 liter of fuel.\n- Representative5 goes directly to the capital with 1 liter of fuel.\n- Representative6 goes directly to city 4 with 1 liter of fuel.\n- Representative4 and representative6 go together to the capital with 1 liter of fuel.\nIt costs 7 liters of fuel at minimum. \nIt can be proven that 7 is the minimum number of liters of fuel needed.",
+            "Example 3:\nInput: roads = [], seats = 1\nOutput: 0\nExplanation: No representatives need to travel to the capital city."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^5\nroads.length == n - 1\nroads[i].length == 2\n0 <= ai, bi < n\nai != bi\nroads represents a valid tree.\n1 <= seats <= 10^5",
+        "tags": [
+            "Tree",
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Graph"
+        ],
+        "title-slug": "minimum-fuel-cost-to-report-to-the-capital"
+    },
+    {
+        "leetcode-id": 2478,
+        "title": "Number of Beautiful Partitions",
+        "difficulty": 3,
+        "description": "You are given a string s that consists of the digits '1' to '9' and two integers k and minLength.\nA partition of s is called beautiful if:\n\ns is partitioned into k non-intersecting substrings.\nEach substring has a length of at least minLength.\nEach substring starts with a prime digit and ends with a non-prime digit. Prime digits are '2', '3', '5', and '7', and the rest of the digits are non-prime.\n\nReturn the number of beautiful partitions of s. Since the answer may be very large, return it modulo 10^9 + 7.\nA substring is a contiguous sequence of characters within a string.",
+        "examples": [
+            "Example 1:\nInput: s = \"23542185131\", k = 3, minLength = 2\nOutput: 3\nExplanation: There exists three ways to create a beautiful partition:\n\"2354 | 218 | 5131\"\n\"2354 | 21851 | 31\"\n\"2354218 | 51 | 31\"",
+            "Example 2:\nInput: s = \"23542185131\", k = 3, minLength = 3\nOutput: 1\nExplanation: There exists one way to create a beautiful partition: \"2354 | 218 | 5131\".",
+            "Example 3:\nInput: s = \"3312958\", k = 3, minLength = 1\nOutput: 1\nExplanation: There exists one way to create a beautiful partition: \"331 | 29 | 58\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= k, minLength <= s.length <= 1000\ns consists of the digits '1' to '9'.",
+        "tags": [
+            "String",
+            "Dynamic Programming"
+        ],
+        "title-slug": "number-of-beautiful-partitions"
+    },
+    {
+        "leetcode-id": 2481,
+        "title": "Minimum Cuts to Divide a Circle",
+        "difficulty": 1,
+        "description": "A valid cut in a circle can be:\n\nA cut that is represented by a straight line that touches two points on the edge of the circle and passes through its center, or\nA cut that is represented by a straight line that touches one point on the edge of the circle and its center.\n\nSome valid and invalid cuts are shown in the figures below.\n\nGiven the integer n, return the minimum number of cuts needed to divide a circle into n equal slices.",
+        "examples": [
+            "Example 1:\nInput: n = 4\nOutput: 2\nExplanation: \nThe above figure shows how cutting the circle twice through the middle divides it into 4 equal slices.",
+            "Example 2:\nInput: n = 3\nOutput: 3\nExplanation:\nAt least 3 cuts are needed to divide the circle into 3 equal slices. \nIt can be shown that less than 3 cuts cannot result in 3 slices of equal size and shape.\nAlso note that the first cut will not divide the circle into distinct parts."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 100",
+        "tags": [
+            "Math",
+            "Geometry"
+        ],
+        "title-slug": "minimum-cuts-to-divide-a-circle"
+    },
+    {
+        "leetcode-id": 2482,
+        "title": "Difference Between Ones and Zeros in Row and Column",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed m x n binary matrix grid.\nA 0-indexed m x n difference matrix diff is created with the following procedure:\n\nLet the number of ones in the i^th row be onesRowi.\nLet the number of ones in the j^th column be onesColj.\nLet the number of zeros in the i^th row be zerosRowi.\nLet the number of zeros in the j^th column be zerosColj.\ndiff[i][j] = onesRowi + onesColj - zerosRowi - zerosColj\n\nReturn the difference matrix diff.",
+        "examples": [
+            "Example 1:\nInput: grid = [[0,1,1],[1,0,1],[0,0,1]]\nOutput: [[0,0,4],[0,0,4],[-2,-2,2]]\nExplanation:\n- diff[0][0] = onesRow0 + onesCol0 - zerosRow0 - zerosCol0 = 2 + 1 - 1 - 2 = 0 \n- diff[0][1] = onesRow0 + onesCol1 - zerosRow0 - zerosCol1 = 2 + 1 - 1 - 2 = 0 \n- diff[0][2] = onesRow0 + onesCol2 - zerosRow0 - zerosCol2 = 2 + 3 - 1 - 0 = 4 \n- diff[1][0] = onesRow1 + onesCol0 - zerosRow1 - zerosCol0 = 2 + 1 - 1 - 2 = 0 \n- diff[1][1] = onesRow1 + onesCol1 - zerosRow1 - zerosCol1 = 2 + 1 - 1 - 2 = 0 \n- diff[1][2] = onesRow1 + onesCol2 - zerosRow1 - zerosCol2 = 2 + 3 - 1 - 0 = 4 \n- diff[2][0] = onesRow2 + onesCol0 - zerosRow2 - zerosCol0 = 1 + 1 - 2 - 2 = -2\n- diff[2][1] = onesRow2 + onesCol1 - zerosRow2 - zerosCol1 = 1 + 1 - 2 - 2 = -2\n- diff[2][2] = onesRow2 + onesCol2 - zerosRow2 - zerosCol2 = 1 + 3 - 2 - 0 = 2",
+            "Example 2:\nInput: grid = [[1,1,1],[1,1,1]]\nOutput: [[5,5,5],[5,5,5]]\nExplanation:\n- diff[0][0] = onesRow0 + onesCol0 - zerosRow0 - zerosCol0 = 3 + 2 - 0 - 0 = 5\n- diff[0][1] = onesRow0 + onesCol1 - zerosRow0 - zerosCol1 = 3 + 2 - 0 - 0 = 5\n- diff[0][2] = onesRow0 + onesCol2 - zerosRow0 - zerosCol2 = 3 + 2 - 0 - 0 = 5\n- diff[1][0] = onesRow1 + onesCol0 - zerosRow1 - zerosCol0 = 3 + 2 - 0 - 0 = 5\n- diff[1][1] = onesRow1 + onesCol1 - zerosRow1 - zerosCol1 = 3 + 2 - 0 - 0 = 5\n- diff[1][2] = onesRow1 + onesCol2 - zerosRow1 - zerosCol2 = 3 + 2 - 0 - 0 = 5"
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 10^5\n1 <= m * n <= 10^5\ngrid[i][j] is either 0 or 1.",
+        "tags": [
+            "Array",
+            "Matrix",
+            "Simulation"
+        ],
+        "title-slug": "difference-between-ones-and-zeros-in-row-and-column"
+    },
+    {
+        "leetcode-id": 2483,
+        "title": "Minimum Penalty for a Shop",
+        "difficulty": 2,
+        "description": "You are given the customer visit log of a shop represented by a 0-indexed string customers consisting only of characters 'N' and 'Y':\n\nif the i^th character is 'Y', it means that customers come at the i^th hour\nwhereas 'N' indicates that no customers come at the i^th hour.\n\nIf the shop closes at the j^th hour (0 <= j <= n), the penalty is calculated as follows:\n\nFor every hour when the shop is open and no customers come, the penalty increases by 1.\nFor every hour when the shop is closed and customers come, the penalty increases by 1.\n\nReturn the earliest hour at which the shop must be closed to incur a minimum penalty.\nNote that if a shop closes at the j^th hour, it means the shop is closed at the hour j.",
+        "examples": [
+            "Example 1:\nInput: customers = \"YYNY\"\nOutput: 2\nExplanation: \n- Closing the shop at the 0^th hour incurs in 1+1+0+1 = 3 penalty.\n- Closing the shop at the 1^st hour incurs in 0+1+0+1 = 2 penalty.\n- Closing the shop at the 2^nd hour incurs in 0+0+0+1 = 1 penalty.\n- Closing the shop at the 3^rd hour incurs in 0+0+1+1 = 2 penalty.\n- Closing the shop at the 4^th hour incurs in 0+0+1+0 = 1 penalty.\nClosing the shop at 2^nd or 4^th hour gives a minimum penalty. Since 2 is earlier, the optimal closing time is 2.",
+            "Example 2:\nInput: customers = \"NNNNN\"\nOutput: 0\nExplanation: It is best to close the shop at the 0^th hour as no customers arrive.",
+            "Example 3:\nInput: customers = \"YYYY\"\nOutput: 4\nExplanation: It is best to close the shop at the 4^th hour as customers arrive at each hour."
+        ],
+        "constraints": "Constraints:\n\n1 <= customers.length <= 10^5\ncustomers consists only of characters 'Y' and 'N'.",
+        "tags": [
+            "String",
+            "Prefix Sum"
+        ],
+        "title-slug": "minimum-penalty-for-a-shop"
+    },
+    {
+        "leetcode-id": 2484,
+        "title": "Count Palindromic Subsequences",
+        "difficulty": 3,
+        "description": "Given a string of digits s, return the number of palindromic subsequences of s having length 5. Since the answer may be very large, return it modulo 10^9 + 7.\nNote:\n\nA string is palindromic if it reads the same forward and backward.\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.",
+        "examples": [
+            "Example 1:\nInput: s = \"103301\"\nOutput: 2\nExplanation: \nThere are 6 possible subsequences of length 5: \"10330\",\"10331\",\"10301\",\"10301\",\"13301\",\"03301\". \nTwo of them (both equal to \"10301\") are palindromic.",
+            "Example 2:\nInput: s = \"0000000\"\nOutput: 21\nExplanation: All 21 subsequences are \"00000\", which is palindromic.",
+            "Example 3:\nInput: s = \"9999900000\"\nOutput: 2\nExplanation: The only two palindromic subsequences are \"99999\" and \"00000\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^4\ns consists of digits.",
+        "tags": [
+            "String",
+            "Dynamic Programming"
+        ],
+        "title-slug": "count-palindromic-subsequences"
+    },
+    {
+        "leetcode-id": 2485,
+        "title": "Find the Pivot Integer",
+        "difficulty": 1,
+        "description": "Given a positive integer n, find the pivot integer x such that:\n\nThe sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively.\n\nReturn the pivot integer x. If no such integer exists, return -1. It is guaranteed that there will be at most one pivot index for the given input.",
+        "examples": [
+            "Example 1:\nInput: n = 8\nOutput: 6\nExplanation: 6 is the pivot integer since: 1 + 2 + 3 + 4 + 5 + 6 = 6 + 7 + 8 = 21.",
+            "Example 2:\nInput: n = 1\nOutput: 1\nExplanation: 1 is the pivot integer since: 1 = 1.",
+            "Example 3:\nInput: n = 4\nOutput: -1\nExplanation: It can be proved that no such integer exist."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 1000",
+        "tags": [
+            "Math",
+            "Prefix Sum"
+        ],
+        "title-slug": "find-the-pivot-integer"
+    },
+    {
+        "leetcode-id": 2486,
+        "title": "Append Characters to String to Make Subsequence",
+        "difficulty": 2,
+        "description": "You are given two strings s and t consisting of only lowercase English letters.\nReturn the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s.\nA subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.",
+        "examples": [
+            "Example 1:\nInput: s = \"coaching\", t = \"coding\"\nOutput: 4\nExplanation: Append the characters \"ding\" to the end of s so that s = \"coachingding\".\nNow, t is a subsequence of s (\"coachingding\").\nIt can be shown that appending any 3 characters to the end of s will never make t a subsequence.",
+            "Example 2:\nInput: s = \"abcde\", t = \"a\"\nOutput: 0\nExplanation: t is already a subsequence of s (\"abcde\").",
+            "Example 3:\nInput: s = \"z\", t = \"abcde\"\nOutput: 5\nExplanation: Append the characters \"abcde\" to the end of s so that s = \"zabcde\".\nNow, t is a subsequence of s (\"zabcde\").\nIt can be shown that appending any 4 characters to the end of s will never make t a subsequence."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length, t.length <= 10^5\ns and t consist only of lowercase English letters.",
+        "tags": [
+            "Two Pointers",
+            "String",
+            "Greedy"
+        ],
+        "title-slug": "append-characters-to-string-to-make-subsequence"
+    },
+    {
+        "leetcode-id": 2487,
+        "title": "Remove Nodes From Linked List",
+        "difficulty": 2,
+        "description": "You are given the head of a linked list.\nRemove every node which has a node with a greater value anywhere to the right side of it.\nReturn the head of the modified linked list.",
+        "examples": [
+            "Example 1:\nInput: head = [5,2,13,3,8]\nOutput: [13,8]\nExplanation: The nodes that should be removed are 5, 2 and 3.\n- Node 13 is to the right of node 5.\n- Node 13 is to the right of node 2.\n- Node 8 is to the right of node 3.",
+            "Example 2:\nInput: head = [1,1,1,1]\nOutput: [1,1,1,1]\nExplanation: Every node has value 1, so no nodes are removed."
+        ],
+        "constraints": "Constraints:\n\nThe number of the nodes in the given list is in the range [1, 10^5].\n1 <= Node.val <= 10^5",
+        "tags": [
+            "Linked List",
+            "Stack",
+            "Recursion",
+            "Monotonic Stack"
+        ],
+        "title-slug": "remove-nodes-from-linked-list"
+    },
+    {
+        "leetcode-id": 2488,
+        "title": "Count Subarrays With Median K",
+        "difficulty": 3,
+        "description": "You are given an array nums of size n consisting of distinct integers from 1 to n and a positive integer k.\nReturn the number of non-empty subarrays in nums that have a median equal to k.\nNote:\n\nThe median of an array is the middle element after sorting the array in ascending order. If the array is of even length, the median is the left middle element.\n\n\t\nFor example, the median of [2,3,1,4] is 2, and the median of [8,4,3,5,1] is 4.\n\n\nA subarray is a contiguous part of an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,2,1,4,5], k = 4\nOutput: 3\nExplanation: The subarrays that have a median equal to 4 are: [4], [4,5] and [1,4,5].",
+            "Example 2:\nInput: nums = [2,3,1], k = 3\nOutput: 1\nExplanation: [3] is the only subarray that has a median equal to 3."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^5\n1 <= nums[i], k <= n\nThe integers in nums are distinct.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Prefix Sum"
+        ],
+        "title-slug": "count-subarrays-with-median-k"
+    },
+    {
+        "leetcode-id": 2490,
+        "title": "Circular Sentence",
+        "difficulty": 1,
+        "description": "A sentence is a list of words that are separated by a single space with no leading or trailing spaces.\n\nFor example, \"Hello World\", \"HELLO\", \"hello world hello world\" are all sentences.\n\nWords consist of only uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different.\nA sentence is circular if:\n\nThe last character of a word is equal to the first character of the next word.\nThe last character of the last word is equal to the first character of the first word.\n\nFor example, \"leetcode exercises sound delightful\", \"eetcode\", \"leetcode eats soul\" are all circular sentences. However, \"Leetcode is cool\", \"happy Leetcode\", \"Leetcode\" and \"I like Leetcode\" are not circular sentences.\nGiven a string sentence, return true if it is circular. Otherwise, return false.",
+        "examples": [
+            "Example 1:\nInput: sentence = \"leetcode exercises sound delightful\"\nOutput: true\nExplanation: The words in sentence are [\"leetcode\", \"exercises\", \"sound\", \"delightful\"].\n- leetcode's\u00a0last character is equal to exercises's first character.\n- exercises's\u00a0last character is equal to sound's first character.\n- sound's\u00a0last character is equal to delightful's first character.\n- delightful's\u00a0last character is equal to leetcode's first character.\nThe sentence is circular.",
+            "Example 2:\nInput: sentence = \"eetcode\"\nOutput: true\nExplanation: The words in sentence are [\"eetcode\"].\n- eetcode's\u00a0last character is equal to eetcode's first character.\nThe sentence is circular.",
+            "Example 3:\nInput: sentence = \"Leetcode is cool\"\nOutput: false\nExplanation: The words in sentence are [\"Leetcode\", \"is\", \"cool\"].\n- Leetcode's\u00a0last character is not equal to is's first character.\nThe sentence is not circular."
+        ],
+        "constraints": "Constraints:\n\n1 <= sentence.length <= 500\nsentence consist of only lowercase and uppercase English letters and spaces.\nThe words in sentence are separated by a single space.\nThere are no leading or trailing spaces.",
+        "tags": [
+            "String"
+        ],
+        "title-slug": "circular-sentence"
+    },
+    {
+        "leetcode-id": 2491,
+        "title": "Divide Players Into Teams of Equal Skill",
+        "difficulty": 2,
+        "description": "You are given a positive integer array skill of even length n where skill[i] denotes the skill of the i^th player. Divide the players into n / 2 teams of size 2 such that the total skill of each team is equal.\nThe chemistry of a team is equal to the product of the skills of the players on that team.\nReturn the sum of the chemistry of all the teams, or return -1 if there is no way to divide the players into teams such that the total skill of each team is equal.",
+        "examples": [
+            "Example 1:\nInput: skill = [3,2,5,1,3,4]\nOutput: 22\nExplanation: \nDivide the players into the following teams: (1, 5), (2, 4), (3, 3), where each team has a total skill of 6.\nThe sum of the chemistry of all the teams is: 1 * 5 + 2 * 4 + 3 * 3 = 5 + 8 + 9 = 22.",
+            "Example 2:\nInput: skill = [3,4]\nOutput: 12\nExplanation: \nThe two players form a team with a total skill of 7.\nThe chemistry of the team is 3 * 4 = 12.",
+            "Example 3:\nInput: skill = [1,1,2,3]\nOutput: -1\nExplanation: \nThere is no way to divide the players into teams such that the total skill of each team is equal."
+        ],
+        "constraints": "Constraints:\n\n2 <= skill.length <= 10^5\nskill.length is even.\n1 <= skill[i] <= 1000",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Two Pointers",
+            "Sorting"
+        ],
+        "title-slug": "divide-players-into-teams-of-equal-skill"
+    },
+    {
+        "leetcode-id": 2492,
+        "title": "Minimum Score of a Path Between Two Cities",
+        "difficulty": 2,
+        "description": "You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [ai, bi, distancei] indicates that there is a bidirectional road between cities ai and bi with a distance equal to distancei. The cities graph is not necessarily connected.\nThe score of a path between two cities is defined as the minimum distance of a road in this path.\nReturn the minimum possible score of a path between cities 1 and n.\nNote:\n\nA path is a sequence of roads between two cities.\nIt is allowed for a path to contain the same road multiple times, and you can visit cities 1 and n multiple times along the path.\nThe test cases are generated such that there is at least one path between 1 and n.",
+        "examples": [
+            "Example 1:\nInput: n = 4, roads = [[1,2,9],[2,3,6],[2,4,5],[1,4,7]]\nOutput: 5\nExplanation: The path from city 1 to 4 with the minimum score is: 1 -> 2 -> 4. The score of this path is min(9,5) = 5.\nIt can be shown that no other path has less score.",
+            "Example 2:\nInput: n = 4, roads = [[1,2,2],[1,3,4],[3,4,7]]\nOutput: 2\nExplanation: The path from city 1 to 4 with the minimum score is: 1 -> 2 -> 1 -> 3 -> 4. The score of this path is min(2,2,4,7) = 2."
+        ],
+        "constraints": "Constraints:\n\n2 <= n <= 10^5\n1 <= roads.length <= 10^5\nroads[i].length == 3\n1 <= ai, bi <= n\nai != bi\n1 <= distancei <= 10^4\nThere are no repeated edges.\nThere is at least one path between 1 and n.",
+        "tags": [
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Union Find",
+            "Graph"
+        ],
+        "title-slug": "minimum-score-of-a-path-between-two-cities"
+    },
+    {
+        "leetcode-id": 2493,
+        "title": "Divide Nodes Into the Maximum Number of Groups",
+        "difficulty": 3,
+        "description": "You are given a positive integer n representing the number of nodes in an undirected graph. The nodes are labeled from 1 to n.\nYou are also given a 2D integer array edges, where edges[i] = [ai, bi] indicates that there is a bidirectional edge between nodes ai and bi. Notice that the given graph may be disconnected.\nDivide the nodes of the graph into m groups (1-indexed) such that:\n\nEach node in the graph belongs to exactly one group.\nFor every pair of nodes in the graph that are connected by an edge [ai, bi], if ai belongs to the group with index x, and bi belongs to the group with index y, then |y - x| = 1.\n\nReturn the maximum number of groups (i.e., maximum m) into which you can divide the nodes. Return -1 if it is impossible to group the nodes with the given conditions.",
+        "examples": [
+            "Example 1:\nInput: n = 6, edges = [[1,2],[1,4],[1,5],[2,6],[2,3],[4,6]]\nOutput: 4\nExplanation: As shown in the image we:\n- Add node 5 to the first group.\n- Add node 1 to the second group.\n- Add nodes 2 and 4 to the third group.\n- Add nodes 3 and 6 to the fourth group.\nWe can see that every edge is satisfied.\nIt can be shown that that if we create a fifth group and move any node from the third or fourth group to it, at least on of the edges will not be satisfied.",
+            "Example 2:\nInput: n = 3, edges = [[1,2],[2,3],[3,1]]\nOutput: -1\nExplanation: If we add node 1 to the first group, node 2 to the second group, and node 3 to the third group to satisfy the first two edges, we can see that the third edge will not be satisfied.\nIt can be shown that no grouping is possible."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 500\n1 <= edges.length <= 10^4\nedges[i].length == 2\n1 <= ai, bi <= n\nai != bi\nThere is at most one edge between any pair of vertices.",
+        "tags": [
+            "Breadth-First Search",
+            "Union Find",
+            "Graph"
+        ],
+        "title-slug": "divide-nodes-into-the-maximum-number-of-groups"
+    },
+    {
+        "leetcode-id": 2496,
+        "title": "Maximum Value of a String in an Array",
+        "difficulty": 1,
+        "description": "The value of an alphanumeric string can be defined as:\n\nThe numeric representation of the string in base 10, if it comprises of digits only.\nThe length of the string, otherwise.\n\nGiven an array strs of alphanumeric strings, return the maximum value of any string in strs.",
+        "examples": [
+            "Example 1:\nInput: strs = [\"alic3\",\"bob\",\"3\",\"4\",\"00000\"]\nOutput: 5\nExplanation: \n- \"alic3\" consists of both letters and digits, so its value is its length, i.e. 5.\n- \"bob\" consists only of letters, so its value is also its length, i.e. 3.\n- \"3\" consists only of digits, so its value is its numeric equivalent, i.e. 3.\n- \"4\" also consists only of digits, so its value is 4.\n- \"00000\" consists only of digits, so its value is 0.\nHence, the maximum value is 5, of \"alic3\".",
+            "Example 2:\nInput: strs = [\"1\",\"01\",\"001\",\"0001\"]\nOutput: 1\nExplanation: \nEach string in the array has value 1. Hence, we return 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= strs.length <= 100\n1 <= strs[i].length <= 9\nstrs[i] consists of only lowercase English letters and digits.",
+        "tags": [
+            "Array",
+            "String"
+        ],
+        "title-slug": "maximum-value-of-a-string-in-an-array"
+    },
+    {
+        "leetcode-id": 2497,
+        "title": "Maximum Star Sum of a Graph",
+        "difficulty": 2,
+        "description": "There is an undirected graph consisting of n nodes numbered from 0 to n - 1. You are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the i^th node.\nYou are also given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting nodes ai and bi.\nA star graph is a subgraph of the given graph having a center node containing 0 or more neighbors. In other words, it is a subset of edges of the given graph such that there exists a common node for all edges.\nThe image below shows star graphs with 3 and 4 neighbors respectively, centered at the blue node.\n\nThe star sum is the sum of the values of all the nodes present in the star graph.\nGiven an integer k, return the maximum star sum of a star graph containing at most k edges.",
+        "examples": [
+            "Example 1:\nInput: vals = [1,2,3,4,10,-10,-20], edges = [[0,1],[1,2],[1,3],[3,4],[3,5],[3,6]], k = 2\nOutput: 16\nExplanation: The above diagram represents the input graph.\nThe star graph with the maximum star sum is denoted by blue. It is centered at 3 and includes its neighbors 1 and 4.\nIt can be shown it is not possible to get a star graph with a sum greater than 16.",
+            "Example 2:\nInput: vals = [-5], edges = [], k = 0\nOutput: -5\nExplanation: There is only one possible star graph, which is node 0 itself.\nHence, we return -5."
+        ],
+        "constraints": "Constraints:\n\nn == vals.length\n1 <= n <= 10^5\n-10^4 <= vals[i] <= 10^4\n0 <= edges.length <= min(n * (n - 1) / 2, 10^5)\nedges[i].length == 2\n0 <= ai, bi <= n - 1\nai != bi\n0 <= k <= n - 1",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Graph",
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "maximum-star-sum-of-a-graph"
+    },
+    {
+        "leetcode-id": 2498,
+        "title": "Frog Jump II",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array stones sorted in strictly increasing order representing the positions of stones in a river.\nA frog, initially on the first stone, wants to travel to the last stone and then return to the first stone. However, it can jump to any stone at most once.\nThe length of a jump is the absolute difference between the position of the stone the frog is currently on and the position of the stone to which the frog jumps.\n\nMore formally, if the frog is at stones[i] and is jumping to stones[j], the length of the jump is |stones[i] - stones[j]|.\n\nThe cost of a path is the maximum length of a jump among all jumps in the path.\nReturn the minimum cost of a path for the frog.",
+        "examples": [
+            "Example 1:\nInput: stones = [0,2,5,6,7]\nOutput: 5\nExplanation: The above figure represents one of the optimal paths the frog can take.\nThe cost of this path is 5, which is the maximum length of a jump.\nSince it is not possible to achieve a cost of less than 5, we return it.",
+            "Example 2:\nInput: stones = [0,3,9]\nOutput: 9\nExplanation: \nThe frog can jump directly to the last stone and come back to the first stone. \nIn this case, the length of each jump will be 9. The cost for the path will be max(9, 9) = 9.\nIt can be shown that this is the minimum achievable cost."
+        ],
+        "constraints": "Constraints:\n\n2 <= stones.length <= 10^5\n0 <= stones[i] <= 10^9\nstones[0] == 0\nstones is sorted in a strictly increasing order.",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Greedy"
+        ],
+        "title-slug": "frog-jump-ii"
+    },
+    {
+        "leetcode-id": 2499,
+        "title": "Minimum Total Cost to Make Arrays Unequal",
+        "difficulty": 3,
+        "description": "You are given two 0-indexed integer arrays nums1 and nums2, of equal length n.\nIn one operation, you can swap the values of any two indices of nums1. The cost of this operation is the sum of the indices.\nFind the minimum total cost of performing the given operation any number of times such that nums1[i] != nums2[i] for all 0 <= i <= n - 1 after performing all the operations.\nReturn the minimum total cost such that nums1 and nums2 satisfy the above condition. In case it is not possible, return -1.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [1,2,3,4,5], nums2 = [1,2,3,4,5]\nOutput: 10\nExplanation: \nOne of the ways we can perform the operations is:\n- Swap values at indices 0 and 3, incurring cost = 0 + 3 = 3. Now, nums1 = [4,2,3,1,5]\n- Swap values at indices 1 and 2, incurring cost = 1 + 2 = 3. Now, nums1 = [4,3,2,1,5].\n- Swap values at indices 0 and 4, incurring cost = 0 + 4 = 4. Now, nums1 =[5,3,2,1,4].\nWe can see that for each index i, nums1[i] != nums2[i]. The cost required here is 10.\nNote that there are other ways to swap values, but it can be proven that it is not possible to obtain a cost less than 10.",
+            "Example 2:\nInput: nums1 = [2,2,2,1,3], nums2 = [1,2,2,3,3]\nOutput: 10\nExplanation: \nOne of the ways we can perform the operations is:\n- Swap values at indices 2 and 3, incurring cost = 2 + 3 = 5. Now, nums1 = [2,2,1,2,3].\n- Swap values at indices 1 and 4, incurring cost = 1 + 4 = 5. Now, nums1 = [2,3,1,2,2].\nThe total cost needed here is 10, which is the minimum possible.",
+            "Example 3:\nInput: nums1 = [1,2,2], nums2 = [1,2,2]\nOutput: -1\nExplanation: \nIt can be shown that it is not possible to satisfy the given conditions irrespective of the number of operations we perform.\nHence, we return -1."
+        ],
+        "constraints": "Constraints:\n\nn == nums1.length == nums2.length\n1 <= n <= 10^5\n1 <= nums1[i], nums2[i] <= n",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Greedy",
+            "Counting"
+        ],
+        "title-slug": "minimum-total-cost-to-make-arrays-unequal"
+    },
+    {
+        "leetcode-id": 2500,
+        "title": "Delete Greatest Value in Each Row",
+        "difficulty": 1,
+        "description": "You are given an m x n matrix grid consisting of positive integers.\nPerform the following operation until grid becomes empty:\n\nDelete the element with the greatest value from each row. If multiple such elements exist, delete any of them.\nAdd the maximum of deleted elements to the answer.\n\nNote that the number of columns decreases by one after each operation.\nReturn the answer after performing the operations described above.",
+        "examples": [
+            "Example 1:\nInput: grid = [[1,2,4],[3,3,1]]\nOutput: 8\nExplanation: The diagram above shows the removed values in each step.\n- In the first operation, we remove 4 from the first row and 3 from the second row (notice that, there are two cells with value 3 and we can remove any of them). We add 4 to the answer.\n- In the second operation, we remove 2 from the first row and 3 from the second row. We add 3 to the answer.\n- In the third operation, we remove 1 from the first row and 1 from the second row. We add 1 to the answer.\nThe final answer = 4 + 3 + 1 = 8.",
+            "Example 2:\nInput: grid = [[10]]\nOutput: 10\nExplanation: The diagram above shows the removed values in each step.\n- In the first operation, we remove 10 from the first row. We add 10 to the answer.\nThe final answer = 10."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 50\n1 <= grid[i][j] <= 100",
+        "tags": [
+            "Array",
+            "Sorting",
+            "Heap (Priority Queue)",
+            "Matrix",
+            "Simulation"
+        ],
+        "title-slug": "delete-greatest-value-in-each-row"
+    },
+    {
+        "leetcode-id": 2501,
+        "title": "Longest Square Streak in an Array",
+        "difficulty": 2,
+        "description": "You are given an integer array nums. A subsequence of nums is called a square streak if:\n\nThe length of the subsequence is at least 2, and\nafter sorting the subsequence, each element (except the first element) is the square of the previous number.\n\nReturn the length of the longest square streak in nums, or return -1 if there is no square streak.\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,3,6,16,8,2]\nOutput: 3\nExplanation: Choose the subsequence [4,16,2]. After sorting it, it becomes [2,4,16].\n- 4 = 2 * 2.\n- 16 = 4 * 4.\nTherefore, [4,16,2] is a square streak.\nIt can be shown that every subsequence of length 4 is not a square streak.",
+            "Example 2:\nInput: nums = [2,3,5,6,7]\nOutput: -1\nExplanation: There is no square streak in nums so return -1."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 10^5\n2 <= nums[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Binary Search",
+            "Dynamic Programming",
+            "Sorting"
+        ],
+        "title-slug": "longest-square-streak-in-an-array"
+    },
+    {
+        "leetcode-id": 2502,
+        "title": "Design Memory Allocator",
+        "difficulty": 2,
+        "description": "You are given an integer n representing the size of a 0-indexed memory array. All memory units are initially free.\nYou have a memory allocator with the following functionalities:\n\nAllocate a block of size consecutive free memory units and assign it the id mID.\nFree all memory units with the given id mID.\n\nNote that:\n\nMultiple blocks can be allocated to the same mID.\nYou should free all the memory units with mID, even if they were allocated in different blocks.\n\nImplement the Allocator class:\n\nAllocator(int n) Initializes an Allocator object with a memory array of size n.\nint allocate(int size, int mID) Find the leftmost block of size consecutive free memory units and allocate it with the id mID. Return the block's first index. If such a block does not exist, return -1.\nint free(int mID) Free all memory units with the id mID. Return the number of memory units you have freed.",
+        "examples": [
+            "Example 1:\nInput\n[\"Allocator\", \"allocate\", \"allocate\", \"allocate\", \"free\", \"allocate\", \"allocate\", \"allocate\", \"free\", \"allocate\", \"free\"]\n[[10], [1, 1], [1, 2], [1, 3], [2], [3, 4], [1, 1], [1, 1], [1], [10, 2], [7]]\nOutput\n[null, 0, 1, 2, 1, 3, 1, 6, 3, -1, 0]\n\nExplanation\nAllocator loc = new Allocator(10); // Initialize a memory array of size 10. All memory units are initially free.\nloc.allocate(1, 1); // The leftmost block's first index is 0. The memory array becomes [1,_,_,_,_,_,_,_,_,_]. We return 0.\nloc.allocate(1, 2); // The leftmost block's first index is 1. The memory array becomes [1,2,_,_,_,_,_,_,_,_]. We return 1.\nloc.allocate(1, 3); // The leftmost block's first index is 2. The memory array becomes [1,2,3,_,_,_,_,_,_,_]. We return 2.\nloc.free(2); // Free all memory units with mID 2. The memory array becomes [1,_, 3,_,_,_,_,_,_,_]. We return 1 since there is only 1 unit with mID 2.\nloc.allocate(3, 4); // The leftmost block's first index is 3. The memory array becomes [1,_,3,4,4,4,_,_,_,_]. We return 3.\nloc.allocate(1, 1); // The leftmost block's first index is 1. The memory array becomes [1,1,3,4,4,4,_,_,_,_]. We return 1.\nloc.allocate(1, 1); // The leftmost block's first index is 6. The memory array becomes [1,1,3,4,4,4,1,_,_,_]. We return 6.\nloc.free(1); // Free all memory units with mID 1. The memory array becomes [_,_,3,4,4,4,_,_,_,_]. We return 3 since there are 3 units with mID 1.\nloc.allocate(10, 2); // We can not find any free block with 10 consecutive free memory units, so we return -1.\nloc.free(7); // Free all memory units with mID 7. The memory array remains the same since there is no memory unit with mID 7. We return 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= n, size, mID <= 1000\nAt most 1000 calls will be made to allocate and free.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Design",
+            "Simulation"
+        ],
+        "title-slug": "design-memory-allocator"
+    },
+    {
+        "leetcode-id": 2503,
+        "title": "Maximum Number of Points From Grid Queries",
+        "difficulty": 3,
+        "description": "You are given an m x n integer matrix grid and an array queries of size k.\nFind an array answer of size k such that for each integer queries[i] you start in the top left cell of the matrix and repeat the following process:\n\nIf queries[i] is strictly greater than the value of the current cell that you are in, then you get one point if it is your first time visiting this cell, and you can move to any adjacent cell in all 4 directions: up, down, left, and right.\nOtherwise, you do not get any points, and you end this process.\n\nAfter the process, answer[i] is the maximum number of points you can get. Note that for each query you are allowed to visit the same cell multiple times.\nReturn the resulting array answer.",
+        "examples": [
+            "Example 1:\nInput: grid = [[1,2,3],[2,5,7],[3,5,1]], queries = [5,6,2]\nOutput: [5,8,1]\nExplanation: The diagrams above show which cells we visit to get points for each query.",
+            "Example 2:\nInput: grid = [[5,2,1],[1,1,2]], queries = [3]\nOutput: [0]\nExplanation: We can not get any points because the value of the top left cell is already greater than or equal to 3."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n2 <= m, n <= 1000\n4 <= m * n <= 10^5\nk == queries.length\n1 <= k <= 10^4\n1 <= grid[i][j], queries[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Breadth-First Search",
+            "Union Find",
+            "Sorting",
+            "Heap (Priority Queue)",
+            "Matrix"
+        ],
+        "title-slug": "maximum-number-of-points-from-grid-queries"
+    },
+    {
+        "leetcode-id": 2506,
+        "title": "Count Pairs Of Similar Strings",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed string array words.\nTwo strings are similar if they consist of the same characters.\n\nFor example, \"abca\" and \"cba\" are similar since both consist of characters 'a', 'b', and 'c'.\nHowever, \"abacba\" and \"bcfd\" are not similar since they do not consist of the same characters.\n\nReturn the number of pairs (i, j) such that 0 <= i < j <= word.length - 1 and the two strings words[i] and words[j] are similar.",
+        "examples": [
+            "Example 1:\nInput: words = [\"aba\",\"aabb\",\"abcd\",\"bac\",\"aabc\"]\nOutput: 2\nExplanation: There are 2 pairs that satisfy the conditions:\n- i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'. \n- i = 3 and j = 4 : both words[3] and words[4] only consist of characters 'a', 'b', and 'c'.",
+            "Example 2:\nInput: words = [\"aabb\",\"ab\",\"ba\"]\nOutput: 3\nExplanation: There are 3 pairs that satisfy the conditions:\n- i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'. \n- i = 0 and j = 2 : both words[0] and words[2] only consist of characters 'a' and 'b'.\n- i = 1 and j = 2 : both words[1] and words[2] only consist of characters 'a' and 'b'.",
+            "Example 3:\nInput: words = [\"nba\",\"cba\",\"dba\"]\nOutput: 0\nExplanation: Since there does not exist any pair that satisfies the conditions, we return 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 100\n1 <= words[i].length <= 100\nwords[i] consist of only lowercase English letters.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String"
+        ],
+        "title-slug": "count-pairs-of-similar-strings"
+    },
+    {
+        "leetcode-id": 2507,
+        "title": "Smallest Value After Replacing With Sum of Prime Factors",
+        "difficulty": 2,
+        "description": "You are given a positive integer n.\nContinuously replace n with the sum of its prime factors.\n\nNote that if a prime factor divides n multiple times, it should be included in the sum as many times as it divides n.\n\nReturn the smallest value n will take on.",
+        "examples": [
+            "Example 1:\nInput: n = 15\nOutput: 5\nExplanation: Initially, n = 15.\n15 = 3 * 5, so replace n with 3 + 5 = 8.\n8 = 2 * 2 * 2, so replace n with 2 + 2 + 2 = 6.\n6 = 2 * 3, so replace n with 2 + 3 = 5.\n5 is the smallest value n will take on.",
+            "Example 2:\nInput: n = 3\nOutput: 3\nExplanation: Initially, n = 3.\n3 is the smallest value n will take on."
+        ],
+        "constraints": "Constraints:\n\n2 <= n <= 10^5",
+        "tags": [
+            "Math",
+            "Number Theory"
+        ],
+        "title-slug": "smallest-value-after-replacing-with-sum-of-prime-factors"
+    },
+    {
+        "leetcode-id": 2508,
+        "title": "Add Edges to Make Degrees of All Nodes Even",
+        "difficulty": 3,
+        "description": "There is an undirected graph consisting of n nodes numbered from 1 to n. You are given the integer n and a 2D array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi. The graph can be disconnected.\nYou can add at most two additional edges (possibly none) to this graph so that there are no repeated edges and no self-loops.\nReturn true if it is possible to make the degree of each node in the graph even, otherwise return false.\nThe degree of a node is the number of edges connected to it.",
+        "examples": [
+            "Example 1:\nInput: n = 5, edges = [[1,2],[2,3],[3,4],[4,2],[1,4],[2,5]]\nOutput: true\nExplanation: The above diagram shows a valid way of adding an edge.\nEvery node in the resulting graph is connected to an even number of edges.",
+            "Example 2:\nInput: n = 4, edges = [[1,2],[3,4]]\nOutput: true\nExplanation: The above diagram shows a valid way of adding two edges.",
+            "Example 3:\nInput: n = 4, edges = [[1,2],[1,3],[1,4]]\nOutput: false\nExplanation: It is not possible to obtain a valid graph with adding at most 2 edges."
+        ],
+        "constraints": "Constraints:\n\n3 <= n <= 10^5\n2 <= edges.length <= 10^5\nedges[i].length == 2\n1 <= ai, bi <= n\nai != bi\nThere are no repeated edges.",
+        "tags": [
+            "Hash Table",
+            "Graph"
+        ],
+        "title-slug": "add-edges-to-make-degrees-of-all-nodes-even"
+    },
+    {
+        "leetcode-id": 2509,
+        "title": "Cycle Length Queries in a Tree",
+        "difficulty": 3,
+        "description": "You are given an integer n. There is a complete binary tree with 2^n - 1 nodes. The root of that tree is the node with the value 1, and every node with a value val in the range [1, 2^n - 1 - 1] has two children where:\n\nThe left node has the value 2 * val, and\nThe right node has the value 2 * val + 1.\n\nYou are also given a 2D integer array queries of length m, where queries[i] = [ai, bi]. For each query, solve the following problem:\n\nAdd an edge between the nodes with values ai and bi.\nFind the length of the cycle in the graph.\nRemove the added edge between nodes with values ai and bi.\n\nNote that:\n\nA cycle is a path that starts and ends at the same node, and each edge in the path is visited only once.\nThe length of a cycle is the number of edges visited in the cycle.\nThere could be multiple edges between two nodes in the tree after adding the edge of the query.\n\nReturn an array answer of length m where answer[i] is the answer to the i^th query.",
+        "examples": [
+            "Example 1:\nInput: n = 3, queries = [[5,3],[4,7],[2,3]]\nOutput: [4,5,3]\nExplanation: The diagrams above show the tree of 2^3 - 1 nodes. Nodes colored in red describe the nodes in the cycle after adding the edge.\n- After adding the edge between nodes 3 and 5, the graph contains a cycle of nodes [5,2,1,3]. Thus answer to the first query is 4. We delete the added edge and process the next query.\n- After adding the edge between nodes 4 and 7, the graph contains a cycle of nodes [4,2,1,3,7]. Thus answer to the second query is 5. We delete the added edge and process the next query.\n- After adding the edge between nodes 2 and 3, the graph contains a cycle of nodes [2,1,3]. Thus answer to the third query is 3. We delete the added edge.",
+            "Example 2:\nInput: n = 2, queries = [[1,2]]\nOutput: [2]\nExplanation: The diagram above shows the tree of 2^2 - 1 nodes. Nodes colored in red describe the nodes in the cycle after adding the edge.\n- After adding the edge between nodes 1 and 2, the graph contains a cycle of nodes [2,1]. Thus answer for the first query is 2. We delete the added edge."
+        ],
+        "constraints": "Constraints:\n\n2 <= n <= 30\nm == queries.length\n1 <= m <= 10^5\nqueries[i].length == 2\n1 <= ai, bi <= 2^n - 1\nai != bi",
+        "tags": [
+            "Tree",
+            "Binary Tree"
+        ],
+        "title-slug": "cycle-length-queries-in-a-tree"
+    },
+    {
+        "leetcode-id": 2511,
+        "title": "Maximum Enemy Forts That Can Be Captured",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array forts of length n representing the positions of several forts. forts[i] can be -1, 0, or 1 where:\n\n-1 represents there is no fort at the i^th position.\n0 indicates there is an enemy fort at the i^th position.\n1 indicates the fort at the i^th the position is under your command.\n\nNow you have decided to move your army from one of your forts at position i to an empty position j such that:\n\n0 <= i, j <= n - 1\nThe army travels over enemy forts only. Formally, for all k where min(i,j) < k < max(i,j), forts[k] == 0.\n\nWhile moving the army, all the enemy forts that come in the way are captured.\nReturn the maximum number of enemy forts that can be captured. In case it is impossible to move your army, or you do not have any fort under your command, return 0.",
+        "examples": [
+            "Example 1:\nInput: forts = [1,0,0,-1,0,0,0,0,1]\nOutput: 4\nExplanation:\n- Moving the army from position 0 to position 3 captures 2 enemy forts, at 1 and 2.\n- Moving the army from position 8 to position 3 captures 4 enemy forts.\nSince 4 is the maximum number of enemy forts that can be captured, we return 4.",
+            "Example 2:\nInput: forts = [0,0,1,-1]\nOutput: 0\nExplanation: Since no enemy fort can be captured, 0 is returned."
+        ],
+        "constraints": "Constraints:\n\n1 <= forts.length <= 1000\n-1 <= forts[i] <= 1",
+        "tags": [
+            "Array",
+            "Two Pointers"
+        ],
+        "title-slug": "maximum-enemy-forts-that-can-be-captured"
+    },
+    {
+        "leetcode-id": 2512,
+        "title": "Reward Top K Students",
+        "difficulty": 2,
+        "description": "You are given two string arrays positive_feedback and negative_feedback, containing the words denoting positive and negative feedback, respectively. Note that no word is both positive and negative.\nInitially every student has 0 points. Each positive word in a feedback report increases the points of a student by 3, whereas each negative word decreases the points by 1.\nYou are given n feedback reports, represented by a 0-indexed string array report\u00a0and a 0-indexed integer array student_id, where student_id[i] represents the ID of the student who has received the feedback report report[i]. The ID of each student is unique.\nGiven an integer k, return the top k students after ranking them in non-increasing order by their points. In case more than one student has the same points, the one with the lower ID ranks higher.",
+        "examples": [
+            "Example 1:\nInput: positive_feedback = [\"smart\",\"brilliant\",\"studious\"], negative_feedback = [\"not\"], report = [\"this student is studious\",\"the student is smart\"], student_id = [1,2], k = 2\nOutput: [1,2]\nExplanation: \nBoth the students have 1 positive feedback and 3 points but since student 1 has a lower ID he ranks higher.",
+            "Example 2:\nInput: positive_feedback = [\"smart\",\"brilliant\",\"studious\"], negative_feedback = [\"not\"], report = [\"this student is not studious\",\"the student is smart\"], student_id = [1,2], k = 2\nOutput: [2,1]\nExplanation: \n- The student with ID 1 has 1 positive feedback and 1 negative feedback, so he has 3-1=2 points. \n- The student with ID 2 has 1 positive feedback, so he has 3 points. \nSince student 2 has more points, [2,1] is returned."
+        ],
+        "constraints": "Constraints:\n\n1 <= positive_feedback.length, negative_feedback.length <= 10^4\n1 <= positive_feedback[i].length, negative_feedback[j].length <= 100\nBoth positive_feedback[i] and negative_feedback[j] consists of lowercase English letters.\nNo word is present in both positive_feedback and negative_feedback.\nn == report.length == student_id.length\n1 <= n <= 10^4\nreport[i] consists of lowercase English letters and spaces ' '.\nThere is a single space between consecutive words of report[i].\n1 <= report[i].length <= 100\n1 <= student_id[i] <= 10^9\nAll the values of student_id[i] are unique.\n1 <= k <= n",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "reward-top-k-students"
+    },
+    {
+        "leetcode-id": 2513,
+        "title": "Minimize the Maximum of Two Arrays",
+        "difficulty": 2,
+        "description": "We have two arrays arr1 and arr2 which are initially empty. You need to add positive integers to them such that they satisfy all the following conditions:\n\narr1 contains uniqueCnt1 distinct positive integers, each of which is not divisible by divisor1.\narr2 contains uniqueCnt2 distinct positive integers, each of which is not divisible by divisor2.\nNo integer is present in both arr1 and arr2.\n\nGiven divisor1, divisor2, uniqueCnt1, and uniqueCnt2, return the minimum possible maximum integer that can be present in either array.",
+        "examples": [
+            "Example 1:\nInput: divisor1 = 2, divisor2 = 7, uniqueCnt1 = 1, uniqueCnt2 = 3\nOutput: 4\nExplanation: \nWe can distribute the first 4 natural numbers into arr1 and arr2.\narr1 = [1] and arr2 = [2,3,4].\nWe can see that both arrays satisfy all the conditions.\nSince the maximum value is 4, we return it.",
+            "Example 2:\nInput: divisor1 = 3, divisor2 = 5, uniqueCnt1 = 2, uniqueCnt2 = 1\nOutput: 3\nExplanation: \nHere arr1 = [1,2], and arr2 = [3] satisfy all conditions.\nSince the maximum value is 3, we return it.",
+            "Example 3:\nInput: divisor1 = 2, divisor2 = 4, uniqueCnt1 = 8, uniqueCnt2 = 2\nOutput: 15\nExplanation: \nHere, the final possible arrays can be arr1 = [1,3,5,7,9,11,13,15], and arr2 = [2,6].\nIt can be shown that it is not possible to obtain a lower maximum satisfying all conditions."
+        ],
+        "constraints": "Constraints:\n\n2 <= divisor1, divisor2 <= 10^5\n1 <= uniqueCnt1, uniqueCnt2 < 10^9\n2 <= uniqueCnt1 + uniqueCnt2 <= 10^9",
+        "tags": [
+            "Math",
+            "Binary Search",
+            "Number Theory"
+        ],
+        "title-slug": "minimize-the-maximum-of-two-arrays"
+    },
+    {
+        "leetcode-id": 2514,
+        "title": "Count Anagrams",
+        "difficulty": 3,
+        "description": "You are given a string s containing one or more words. Every consecutive pair of words is separated by a single space ' '.\nA string t is an anagram of string s if the i^th word of t is a permutation of the i^th word of s.\n\nFor example, \"acb dfe\" is an anagram of \"abc def\", but \"def cab\"\u00a0and \"adc bef\" are not.\n\nReturn the number of distinct anagrams of s. Since the answer may be very large, return it modulo 10^9 + 7.",
+        "examples": [
+            "Example 1:\nInput: s = \"too hot\"\nOutput: 18\nExplanation: Some of the anagrams of the given string are \"too hot\", \"oot hot\", \"oto toh\", \"too toh\", and \"too oht\".",
+            "Example 2:\nInput: s = \"aa\"\nOutput: 1\nExplanation: There is only one anagram possible for the given string."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of lowercase English letters and spaces ' '.\nThere is single space between consecutive words.",
+        "tags": [
+            "Hash Table",
+            "Math",
+            "String",
+            "Combinatorics",
+            "Counting"
+        ],
+        "title-slug": "count-anagrams"
+    },
+    {
+        "leetcode-id": 2515,
+        "title": "Shortest Distance to Target String in a Circular Array",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed circular string array words and a string target. A circular array means that the array's end connects to the array's beginning.\n\nFormally, the next element of words[i] is words[(i + 1) % n] and the previous element of words[i] is words[(i - 1 + n) % n], where n is the length of words.\n\nStarting from startIndex, you can move to either the next word or the previous word with 1 step at a time.\nReturn the shortest distance needed to reach the string target. If the string target does not exist in words, return -1.",
+        "examples": [
+            "Example 1:\nInput: words = [\"hello\",\"i\",\"am\",\"leetcode\",\"hello\"], target = \"hello\", startIndex = 1\nOutput: 1\nExplanation: We start from index 1 and can reach \"hello\" by\n- moving 3 units to the right to reach index 4.\n- moving 2 units to the left to reach index 4.\n- moving 4 units to the right to reach index 0.\n- moving 1 unit to the left to reach index 0.\nThe shortest distance to reach \"hello\" is 1.",
+            "Example 2:\nInput: words = [\"a\",\"b\",\"leetcode\"], target = \"leetcode\", startIndex = 0\nOutput: 1\nExplanation: We start from index 0 and can reach \"leetcode\" by\n- moving 2 units to the right to reach index 3.\n- moving 1 unit to the left to reach index 3.\nThe shortest distance to reach \"leetcode\" is 1.",
+            "Example 3:\nInput: words = [\"i\",\"eat\",\"leetcode\"], target = \"ate\", startIndex = 0\nOutput: -1\nExplanation: Since \"ate\" does not exist in words, we return -1."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 100\n1 <= words[i].length <= 100\nwords[i] and target consist of only lowercase English letters.\n0 <= startIndex < words.length",
+        "tags": [
+            "Array",
+            "String"
+        ],
+        "title-slug": "shortest-distance-to-target-string-in-a-circular-array"
+    },
+    {
+        "leetcode-id": 2516,
+        "title": "Take K of Each Character From Left and Right",
+        "difficulty": 2,
+        "description": "You are given a string s consisting of the characters 'a', 'b', and 'c' and a non-negative integer k. Each minute, you may take either the leftmost character of s, or the rightmost character of s.\nReturn the minimum number of minutes needed for you to take at least k of each character, or return -1 if it is not possible to take k of each character.",
+        "examples": [
+            "Example 1:\nInput: s = \"aabaaaacaabc\", k = 2\nOutput: 8\nExplanation: \nTake three characters from the left of s. You now have two 'a' characters, and one 'b' character.\nTake five characters from the right of s. You now have four 'a' characters, two 'b' characters, and two 'c' characters.\nA total of 3 + 5 = 8 minutes is needed.\nIt can be proven that 8 is the minimum number of minutes needed.",
+            "Example 2:\nInput: s = \"a\", k = 1\nOutput: -1\nExplanation: It is not possible to take one 'b' or 'c' so return -1."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists of only the letters 'a', 'b', and 'c'.\n0 <= k <= s.length",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Sliding Window"
+        ],
+        "title-slug": "take-k-of-each-character-from-left-and-right"
+    },
+    {
+        "leetcode-id": 2517,
+        "title": "Maximum Tastiness of Candy Basket",
+        "difficulty": 2,
+        "description": "You are given an array of positive integers price where price[i] denotes the price of the i^th candy and a positive integer k.\nThe store sells baskets of k distinct candies. The tastiness of a candy basket is the smallest absolute difference of the prices of any two candies in the basket.\nReturn the maximum tastiness of a candy basket.",
+        "examples": [
+            "Example 1:\nInput: price = [13,5,1,8,21,2], k = 3\nOutput: 8\nExplanation: Choose the candies with the prices [13,5,21].\nThe tastiness of the candy basket is: min(|13 - 5|, |13 - 21|, |5 - 21|) = min(8, 8, 16) = 8.\nIt can be proven that 8 is the maximum tastiness that can be achieved.",
+            "Example 2:\nInput: price = [1,3,1], k = 2\nOutput: 2\nExplanation: Choose the candies with the prices [1,3].\nThe tastiness of the candy basket is: min(|1 - 3|) = min(2) = 2.\nIt can be proven that 2 is the maximum tastiness that can be achieved.",
+            "Example 3:\nInput: price = [7,7,7,7], k = 2\nOutput: 0\nExplanation: Choosing any two distinct candies from the candies we have will result in a tastiness of 0."
+        ],
+        "constraints": "Constraints:\n\n2 <= k <= price.length <= 10^5\n1 <= price[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Sorting"
+        ],
+        "title-slug": "maximum-tastiness-of-candy-basket"
+    },
+    {
+        "leetcode-id": 2518,
+        "title": "Number of Great Partitions",
+        "difficulty": 3,
+        "description": "You are given an array nums consisting of positive integers and an integer k.\nPartition the array into two ordered groups such that each element is in exactly one group. A partition is called great if the sum of elements of each group is greater than or equal to k.\nReturn the number of distinct great partitions. Since the answer may be too large, return it modulo 10^9 + 7.\nTwo partitions are considered distinct if some element nums[i] is in different groups in the two partitions.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,3,4], k = 4\nOutput: 6\nExplanation: The great partitions are: ([1,2,3], [4]), ([1,3], [2,4]), ([1,4], [2,3]), ([2,3], [1,4]), ([2,4], [1,3]) and ([4], [1,2,3]).",
+            "Example 2:\nInput: nums = [3,3,3], k = 4\nOutput: 0\nExplanation: There are no great partitions for this array.",
+            "Example 3:\nInput: nums = [6,6], k = 2\nOutput: 2\nExplanation: We can either put nums[0] in the first partition or in the second partition.\nThe great partitions will be ([6], [6]) and ([6], [6])."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length, k <= 1000\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Dynamic Programming"
+        ],
+        "title-slug": "number-of-great-partitions"
+    },
+    {
+        "leetcode-id": 2520,
+        "title": "Count the Digits That Divide a Number",
+        "difficulty": 1,
+        "description": "Given an integer num, return the number of digits in num that divide num.\nAn integer val divides nums if nums % val == 0.",
+        "examples": [
+            "Example 1:\nInput: num = 7\nOutput: 1\nExplanation: 7 divides itself, hence the answer is 1.",
+            "Example 2:\nInput: num = 121\nOutput: 2\nExplanation: 121 is divisible by 1, but not 2. Since 1 occurs twice as a digit, we return 2.",
+            "Example 3:\nInput: num = 1248\nOutput: 4\nExplanation: 1248 is divisible by all of its digits, hence the answer is 4."
+        ],
+        "constraints": "Constraints:\n\n1 <= num <= 10^9\nnum does not contain 0 as one of its digits.",
+        "tags": [
+            "Math"
+        ],
+        "title-slug": "count-the-digits-that-divide-a-number"
+    },
+    {
+        "leetcode-id": 2521,
+        "title": "Distinct Prime Factors of Product of Array",
+        "difficulty": 2,
+        "description": "Given an array of positive integers nums, return the number of distinct prime factors in the product of the elements of nums.\nNote that:\n\nA number greater than 1 is called prime if it is divisible by only 1 and itself.\nAn integer val1 is a factor of another integer val2 if val2 / val1 is an integer.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,4,3,7,10,6]\nOutput: 4\nExplanation:\nThe product of all the elements in nums is: 2 * 4 * 3 * 7 * 10 * 6 = 10080 = 2^5 * 3^2 * 5 * 7.\nThere are 4 distinct prime factors so we return 4.",
+            "Example 2:\nInput: nums = [2,4,8,16]\nOutput: 1\nExplanation:\nThe product of all the elements in nums is: 2 * 4 * 8 * 16 = 1024 = 2^10.\nThere is 1 distinct prime factor so we return 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^4\n2 <= nums[i] <= 1000",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Math",
+            "Number Theory"
+        ],
+        "title-slug": "distinct-prime-factors-of-product-of-array"
+    },
+    {
+        "leetcode-id": 2522,
+        "title": "Partition String Into Substrings With Values at Most K",
+        "difficulty": 2,
+        "description": "You are given a string s consisting of digits from 1 to 9 and an integer k.\nA partition of a string s is called good if:\n\nEach digit of s is part of exactly one substring.\nThe value of each substring is less than or equal to k.\n\nReturn the minimum number of substrings in a good partition of s. If no good partition of s exists, return -1.\nNote that:\n\nThe value of a string is its result when interpreted as an integer. For example, the value of \"123\" is 123 and the value of \"1\" is 1.\nA substring is a contiguous sequence of characters within a string.",
+        "examples": [
+            "Example 1:\nInput: s = \"165462\", k = 60\nOutput: 4\nExplanation: We can partition the string into substrings \"16\", \"54\", \"6\", and \"2\". Each substring has a value less than or equal to k = 60.\nIt can be shown that we cannot partition the string into less than 4 substrings.",
+            "Example 2:\nInput: s = \"238182\", k = 5\nOutput: -1\nExplanation: There is no good partition for this string."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns[i] is a digit from '1' to '9'.\n1 <= k <= 10^9\n\n\u00a0\n.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0; \n}\n.spoiler {overflow:hidden;}\n.spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;}\n.spoilerbutton[value=\"Show Message\"] + .spoiler > div {margin-top:-500%;}\n.spoilerbutton[value=\"Hide Message\"] + .spoiler {padding:5px;}",
+        "tags": [
+            "String",
+            "Dynamic Programming",
+            "Greedy"
+        ],
+        "title-slug": "partition-string-into-substrings-with-values-at-most-k"
+    },
+    {
+        "leetcode-id": 2523,
+        "title": "Closest Prime Numbers in Range",
+        "difficulty": 2,
+        "description": "Given two positive integers left and right, find the two integers num1 and num2 such that:\n\nleft <= nums1 < nums2 <= right .\nnums1 and nums2 are both prime numbers.\nnums2 - nums1 is the minimum amongst all other pairs satisfying the above conditions.\n\nReturn the positive integer array ans = [nums1, nums2]. If there are multiple pairs satisfying these conditions, return the one with the minimum nums1 value or [-1, -1] if such numbers do not exist.\nA number greater than 1 is called prime if it is only divisible by 1 and itself.",
+        "examples": [
+            "Example 1:\nInput: left = 10, right = 19\nOutput: [11,13]\nExplanation: The prime numbers between 10 and 19 are 11, 13, 17, and 19.\nThe closest gap between any pair is 2, which can be achieved by [11,13] or [17,19].\nSince 11 is smaller than 17, we return the first pair.",
+            "Example 2:\nInput: left = 4, right = 6\nOutput: [-1,-1]\nExplanation: There exists only one prime number in the given range, so the conditions cannot be satisfied."
+        ],
+        "constraints": "Constraints:\n\n1 <= left <= right <= 10^6\n\n\u00a0\n.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0;\u00a0\n}\n.spoiler {overflow:hidden;}\n.spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;}\n.spoilerbutton[value=\"Show Message\"] + .spoiler > div {margin-top:-500%;}\n.spoilerbutton[value=\"Hide Message\"] + .spoiler {padding:5px;}",
+        "tags": [
+            "Math",
+            "Number Theory"
+        ],
+        "title-slug": "closest-prime-numbers-in-range"
+    },
+    {
+        "leetcode-id": 2525,
+        "title": "Categorize Box According to Criteria",
+        "difficulty": 1,
+        "description": "Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box.\n\nThe box is \"Bulky\" if:\n\n\t\nAny of the dimensions of the box is greater or equal to 10^4.\nOr, the volume of the box is greater or equal to 10^9.\n\n\nIf the mass of the box is greater or equal to 100, it is \"Heavy\".\nIf the box is both \"Bulky\" and \"Heavy\", then its category is \"Both\".\nIf the box is neither \"Bulky\" nor \"Heavy\", then its category is \"Neither\".\nIf the box is \"Bulky\" but not \"Heavy\", then its category is \"Bulky\".\nIf the box is \"Heavy\" but not \"Bulky\", then its category is \"Heavy\".\n\nNote that the volume of the box is the product of its length, width and height.",
+        "examples": [
+            "Example 1:\nInput: length = 1000, width = 35, height = 700, mass = 300\nOutput: \"Heavy\"\nExplanation: \nNone of the dimensions of the box is greater or equal to 10^4. \nIts volume = 24500000 <= 10^9. So it cannot be categorized as \"Bulky\".\nHowever mass >= 100, so the box is \"Heavy\".\nSince the box is not \"Bulky\" but \"Heavy\", we return \"Heavy\".",
+            "Example 2:\nInput: length = 200, width = 50, height = 800, mass = 50\nOutput: \"Neither\"\nExplanation: \nNone of the dimensions of the box is greater or equal to 10^4.\nIts volume = 8 * 10^6 <= 10^9. So it cannot be categorized as \"Bulky\".\nIts mass is also less than 100, so it cannot be categorized as \"Heavy\" either. \nSince its neither of the two above categories, we return \"Neither\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= length, width, height <= 10^5\n1 <= mass <= 10^3",
+        "tags": [
+            "Math"
+        ],
+        "title-slug": "categorize-box-according-to-criteria"
+    },
+    {
+        "leetcode-id": 2526,
+        "title": "Find Consecutive Integers from a Data Stream",
+        "difficulty": 2,
+        "description": "For a stream of integers, implement a data structure that checks if the last k integers parsed in the stream are equal to value.\nImplement the DataStream class:\n\nDataStream(int value, int k) Initializes the object with an empty integer stream and the two integers value and k.\nboolean consec(int num) Adds num to the stream of integers. Returns true if the last k integers are equal to value, and false otherwise. If there are less than k integers, the condition does not hold true, so returns false.",
+        "examples": [
+            "Example 1:\nInput\n[\"DataStream\", \"consec\", \"consec\", \"consec\", \"consec\"]\n[[4, 3], [4], [4], [4], [3]]\nOutput\n[null, false, false, true, false]\n\nExplanation\nDataStream dataStream = new DataStream(4, 3); //value = 4, k = 3 \ndataStream.consec(4); // Only 1 integer is parsed, so returns False. \ndataStream.consec(4); // Only 2 integers are parsed.\n                      // Since 2 is less than k, returns False. \ndataStream.consec(4); // The 3 integers parsed are all equal to value, so returns True. \ndataStream.consec(3); // The last k integers parsed in the stream are [4,4,3].\n                      // Since 3 is not equal to value, it returns False."
+        ],
+        "constraints": "Constraints:\n\n1 <= value, num <= 10^9\n1 <= k <= 10^5\nAt most 10^5 calls will be made to consec.",
+        "tags": [
+            "Hash Table",
+            "Design",
+            "Queue",
+            "Counting",
+            "Data Stream"
+        ],
+        "title-slug": "find-consecutive-integers-from-a-data-stream"
+    },
+    {
+        "leetcode-id": 2527,
+        "title": "Find Xor-Beauty of Array",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums.\nThe effective value of three indices i, j, and k is defined as ((nums[i] | nums[j]) & nums[k]).\nThe xor-beauty of the array is the XORing of the effective values of all the possible triplets of indices (i, j, k) where 0 <= i, j, k < n.\nReturn the xor-beauty of nums.\nNote that:\n\nval1 | val2 is bitwise OR of val1 and val2.\nval1 & val2 is bitwise AND of val1 and val2.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,4]\nOutput: 5\nExplanation: \nThe triplets and their corresponding effective values are listed below:\n- (0,0,0) with effective value ((1 | 1) & 1) = 1\n- (0,0,1) with effective value ((1 | 1) & 4) = 0\n- (0,1,0) with effective value ((1 | 4) & 1) = 1\n- (0,1,1) with effective value ((1 | 4) & 4) = 4\n- (1,0,0) with effective value ((4 | 1) & 1) = 1\n- (1,0,1) with effective value ((4 | 1) & 4) = 4\n- (1,1,0) with effective value ((4 | 4) & 1) = 0\n- (1,1,1) with effective value ((4 | 4) & 4) = 4 \nXor-beauty of array will be bitwise XOR of all beauties = 1 ^ 0 ^ 1 ^ 4 ^ 1 ^ 4 ^ 0 ^ 4 = 5.",
+            "Example 2:\nInput: nums = [15,45,20,2,34,35,5,44,32,30]\nOutput: 34\nExplanation: The xor-beauty of the given array is 34."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length\u00a0<= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Math",
+            "Bit Manipulation"
+        ],
+        "title-slug": "find-xor-beauty-of-array"
+    },
+    {
+        "leetcode-id": 2528,
+        "title": "Maximize the Minimum Powered City",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed integer array stations of length n, where stations[i] represents the number of power stations in the i^th city.\nEach power station can provide power to every city in a fixed range. In other words, if the range is denoted by r, then a power station at city i can provide power to all cities j such that |i - j| <= r and 0 <= i, j <= n - 1.\n\nNote that |x| denotes absolute value. For example, |7 - 5| = 2 and |3 - 10| = 7.\n\nThe power of a city is the total number of power stations it is being provided power from.\nThe government has sanctioned building k more power stations, each of which can be built in any city, and have the same range as the pre-existing ones.\nGiven the two integers r and k, return the maximum possible minimum power of a city, if the additional power stations are built optimally.\nNote that you can build the k power stations in multiple cities.",
+        "examples": [
+            "Example 1:\nInput: stations = [1,2,4,5,0], r = 1, k = 2\nOutput: 5\nExplanation: \nOne of the optimal ways is to install both the power stations at city 1. \nSo stations will become [1,4,4,5,0].\n- City 0 is provided by 1 + 4 = 5 power stations.\n- City 1 is provided by 1 + 4 + 4 = 9 power stations.\n- City 2 is provided by 4 + 4 + 5 = 13 power stations.\n- City 3 is provided by 5 + 4 = 9 power stations.\n- City 4 is provided by 5 + 0 = 5 power stations.\nSo the minimum power of a city is 5.\nSince it is not possible to obtain a larger power, we return 5.",
+            "Example 2:\nInput: stations = [4,4,4,4], r = 0, k = 3\nOutput: 4\nExplanation: \nIt can be proved that we cannot make the minimum power of a city greater than 4."
+        ],
+        "constraints": "Constraints:\n\nn == stations.length\n1 <= n <= 10^5\n0 <= stations[i] <= 10^5\n0 <= r\u00a0<= n - 1\n0 <= k\u00a0<= 10^9",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Greedy",
+            "Queue",
+            "Sliding Window",
+            "Prefix Sum"
+        ],
+        "title-slug": "maximize-the-minimum-powered-city"
+    },
+    {
+        "leetcode-id": 2529,
+        "title": "Maximum Count of Positive Integer and Negative Integer",
+        "difficulty": 1,
+        "description": "Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers.\n\nIn other words, if the number of positive integers in nums is pos and the number of negative integers is neg, then return the maximum of pos and neg.\n\nNote that 0 is neither positive nor negative.",
+        "examples": [
+            "Example 1:\nInput: nums = [-2,-1,-1,1,2,3]\nOutput: 3\nExplanation: There are 3 positive integers and 3 negative integers. The maximum count among them is 3.",
+            "Example 2:\nInput: nums = [-3,-2,-1,0,0,1,2]\nOutput: 3\nExplanation: There are 2 positive integers and 3 negative integers. The maximum count among them is 3.",
+            "Example 3:\nInput: nums = [5,20,66,1314]\nOutput: 4\nExplanation: There are 4 positive integers and 0 negative integers. The maximum count among them is 4."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 2000\n-2000 <= nums[i] <= 2000\nnums is sorted in a non-decreasing order.\n\n\u00a0\nFollow up: Can you solve the problem in O(log(n)) time complexity?",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Counting"
+        ],
+        "title-slug": "maximum-count-of-positive-integer-and-negative-integer"
+    },
+    {
+        "leetcode-id": 2530,
+        "title": "Maximal Score After Applying K Operations",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums and an integer k. You have a starting score of 0.\nIn one operation:\n\nchoose an index i such that 0 <= i < nums.length,\nincrease your score by nums[i], and\nreplace nums[i] with ceil(nums[i] / 3).\n\nReturn the maximum possible score you can attain after applying exactly k operations.\nThe ceiling function ceil(val) is the least integer greater than or equal to val.",
+        "examples": [
+            "Example 1:\nInput: nums = [10,10,10,10,10], k = 5\nOutput: 50\nExplanation: Apply the operation to each array element exactly once. The final score is 10 + 10 + 10 + 10 + 10 = 50.",
+            "Example 2:\nInput: nums = [1,10,3,3,3], k = 3\nOutput: 17\nExplanation: You can do the following operations:\nOperation 1: Select i = 1, so nums becomes [1,4,3,3,3]. Your score increases by 10.\nOperation 2: Select i = 1, so nums becomes [1,2,3,3,3]. Your score increases by 4.\nOperation 3: Select i = 2, so nums becomes [1,1,1,3,3]. Your score increases by 3.\nThe final score is 10 + 4 + 3 = 17."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length, k <= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "maximal-score-after-applying-k-operations"
+    },
+    {
+        "leetcode-id": 2531,
+        "title": "Make Number of Distinct Characters Equal",
+        "difficulty": 2,
+        "description": "You are given two 0-indexed strings word1 and word2.\nA move consists of choosing two indices i and j such that 0 <= i < word1.length and 0 <= j < word2.length and swapping word1[i] with word2[j].\nReturn true if it is possible to get the number of distinct characters in word1 and word2 to be equal with exactly one move. Return false otherwise.",
+        "examples": [
+            "Example 1:\nInput: word1 = \"ac\", word2 = \"b\"\nOutput: false\nExplanation: Any pair of swaps would yield two distinct characters in the first string, and one in the second string.",
+            "Example 2:\nInput: word1 = \"abcc\", word2 = \"aab\"\nOutput: true\nExplanation: We swap index 2 of the first string with index 0 of the second string. The resulting strings are word1 = \"abac\" and word2 = \"cab\", which both have 3 distinct characters.",
+            "Example 3:\nInput: word1 = \"abcde\", word2 = \"fghij\"\nOutput: true\nExplanation: Both resulting strings will have 5 distinct characters, regardless of which indices we swap."
+        ],
+        "constraints": "Constraints:\n\n1 <= word1.length, word2.length <= 10^5\nword1 and word2 consist of only lowercase English letters.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Counting"
+        ],
+        "title-slug": "make-number-of-distinct-characters-equal"
+    },
+    {
+        "leetcode-id": 2532,
+        "title": "Time to Cross a Bridge",
+        "difficulty": 3,
+        "description": "There are k workers who want to move n boxes from an old warehouse to a new one. You are given the two integers n and k, and a 2D integer array time of size k x 4 where time[i] = [leftToRighti, pickOldi, rightToLefti, putNewi].\nThe warehouses are separated by a river and connected by a bridge. The old warehouse is on the right bank of the river, and the new warehouse is on the left bank of the river. Initially, all k workers are waiting on the left side of the bridge. To move the boxes, the i^th worker (0-indexed) can :\n\nCross the bridge from the left bank (new warehouse) to the right bank (old warehouse) in leftToRighti minutes.\nPick a box from the old warehouse and return to the bridge in pickOldi minutes. Different workers can pick up their boxes simultaneously.\nCross the bridge from the right bank (old warehouse) to the left bank (new warehouse) in rightToLefti minutes.\nPut the box in the new warehouse and return to the bridge in putNewi minutes. Different workers can put their boxes simultaneously.\n\nA worker i is less efficient than a worker j if either condition is met:\n\nleftToRighti + rightToLefti > leftToRightj + rightToLeftj\nleftToRighti + rightToLefti == leftToRightj + rightToLeftj and i > j\n\nThe following rules regulate the movement of the workers through the bridge :\n\nIf a worker x reaches the bridge while another worker y is crossing the bridge, x waits at their side of the bridge.\nIf the bridge is free, the worker waiting on the right side of the bridge gets to cross the bridge. If more than one worker is waiting on the right side, the one with the lowest efficiency crosses first.\nIf the bridge is free and no worker is waiting on the right side, and at least one box remains at the old warehouse, the worker on the left side of the river gets to cross the bridge. If more than one worker is waiting on the left side, the one with the lowest efficiency crosses first.\n\nReturn the instance of time at which the last worker reaches the left bank of the river after all n boxes have been put in the new warehouse.",
+        "examples": [
+            "Example 1:\nInput: n = 1, k = 3, time = [[1,1,2,1],[1,1,3,1],[1,1,4,1]]\nOutput: 6\nExplanation: \nFrom 0 to 1: worker 2 crosses the bridge from the left bank to the right bank.\nFrom 1 to 2: worker 2 picks up a box from the old warehouse.\nFrom 2 to 6: worker 2 crosses the bridge from the right bank to the left bank.\nFrom 6 to 7: worker 2 puts a box at the new warehouse.\nThe whole process ends after 7 minutes. We return 6 because the problem asks for the instance of time at which the last worker reaches the left bank.",
+            "Example 2:\nInput: n = 3, k = 2, time = [[1,9,1,8],[10,10,10,10]]\nOutput: 50\nExplanation: \nFrom 0 \u00a0to 10: worker 1 crosses the bridge from the left bank to the right bank.\nFrom 10 to 20: worker 1 picks up a box from the old warehouse.\nFrom 10 to 11: worker 0 crosses the bridge from the left bank to the right bank.\nFrom 11 to 20: worker 0 picks up a box from the old warehouse.\nFrom 20 to 30: worker 1 crosses the bridge from the right bank to the left bank.\nFrom 30 to 40: worker 1 puts a box at the new warehouse.\nFrom 30 to 31: worker 0 crosses the bridge from the right bank to the left bank.\nFrom 31 to 39: worker 0 puts a box at the new warehouse.\nFrom 39 to 40: worker 0 crosses the bridge from the left bank to the right bank.\nFrom 40 to 49: worker 0 picks up a box from the old warehouse.\nFrom 49 to 50: worker 0 crosses the bridge from the right bank to the left bank.\nFrom 50 to 58: worker 0 puts a box at the new warehouse.\nThe whole process ends after 58 minutes. We return 50 because the problem asks for the instance of time at which the last worker reaches the left bank."
+        ],
+        "constraints": "Constraints:\n\n1 <= n, k <= 10^4\ntime.length == k\ntime[i].length == 4\n1 <= leftToRighti, pickOldi, rightToLefti, putNewi <= 1000",
+        "tags": [
+            "Array",
+            "Heap (Priority Queue)",
+            "Simulation"
+        ],
+        "title-slug": "time-to-cross-a-bridge"
+    },
+    {
+        "leetcode-id": 2535,
+        "title": "Difference Between Element Sum and Digit Sum of an Array",
+        "difficulty": 1,
+        "description": "You are given a positive integer array nums.\n\nThe element sum is the sum of all the elements in nums.\nThe digit sum is the sum of all the digits (not necessarily distinct) that appear in nums.\n\nReturn the absolute difference between the element sum and digit sum of nums.\nNote that the absolute difference between two integers x and y is defined as |x - y|.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,15,6,3]\nOutput: 9\nExplanation: \nThe element sum of nums is 1 + 15 + 6 + 3 = 25.\nThe digit sum of nums is 1 + 1 + 5 + 6 + 3 = 16.\nThe absolute difference between the element sum and digit sum is |25 - 16| = 9.",
+            "Example 2:\nInput: nums = [1,2,3,4]\nOutput: 0\nExplanation:\nThe element sum of nums is 1 + 2 + 3 + 4 = 10.\nThe digit sum of nums is 1 + 2 + 3 + 4 = 10.\nThe absolute difference between the element sum and digit sum is |10 - 10| = 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 2000\n1 <= nums[i] <= 2000",
+        "tags": [
+            "Array",
+            "Math"
+        ],
+        "title-slug": "difference-between-element-sum-and-digit-sum-of-an-array"
+    },
+    {
+        "leetcode-id": 2536,
+        "title": "Increment Submatrices by One",
+        "difficulty": 2,
+        "description": "You are given a positive integer n, indicating that we initially have an n x n\u00a00-indexed integer matrix mat filled with zeroes.\nYou are also given a 2D integer array query. For each query[i] = [row1i, col1i, row2i, col2i], you should do the following operation:\n\nAdd 1 to every element in the submatrix with the top left corner (row1i, col1i) and the bottom right corner (row2i, col2i). That is, add 1 to mat[x][y] for all row1i <= x <= row2i and col1i <= y <= col2i.\n\nReturn the matrix mat after performing every query.",
+        "examples": [
+            "Example 1:\nInput: n = 3, queries = [[1,1,2,2],[0,0,1,1]]\nOutput: [[1,1,0],[1,2,1],[0,1,1]]\nExplanation: The diagram above shows the initial matrix, the matrix after the first query, and the matrix after the second query.\n- In the first query, we add 1 to every element in the submatrix with the top left corner (1, 1) and bottom right corner (2, 2).\n- In the second query, we add 1 to every element in the submatrix with the top left corner (0, 0) and bottom right corner (1, 1).",
+            "Example 2:\nInput: n = 2, queries = [[0,0,1,1]]\nOutput: [[1,1],[1,1]]\nExplanation: The diagram above shows the initial matrix and the matrix after the first query.\n- In the first query we add 1 to every element in the matrix."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 500\n1 <= queries.length <= 10^4\n0 <= row1i <= row2i < n\n0 <= col1i <= col2i < n",
+        "tags": [
+            "Array",
+            "Matrix",
+            "Prefix Sum"
+        ],
+        "title-slug": "increment-submatrices-by-one"
+    },
+    {
+        "leetcode-id": 2537,
+        "title": "Count the Number of Good Subarrays",
+        "difficulty": 2,
+        "description": "Given an integer array nums and an integer k, return the number of good subarrays of nums.\nA subarray arr is good if it there are at least k pairs of indices (i, j) such that i < j and arr[i] == arr[j].\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,1,1,1,1], k = 10\nOutput: 1\nExplanation: The only good subarray is the array nums itself.",
+            "Example 2:\nInput: nums = [3,1,4,3,2,2,4], k = 2\nOutput: 4\nExplanation: There are 4 different good subarrays:\n- [3,1,4,3,2,2] that has 2 pairs.\n- [3,1,4,3,2,2,4] that has 3 pairs.\n- [1,4,3,2,2,4] that has 2 pairs.\n- [4,3,2,2,4] that has 2 pairs."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i], k <= 10^9",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sliding Window"
+        ],
+        "title-slug": "count-the-number-of-good-subarrays"
+    },
+    {
+        "leetcode-id": 2538,
+        "title": "Difference Between Maximum and Minimum Price Sum",
+        "difficulty": 3,
+        "description": "There exists an undirected and initially unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\nEach node has an associated price. You are given an integer array price, where price[i] is the price of the i^th node.\nThe price sum of a given path is the sum of the prices of all nodes lying on that path.\nThe tree can be rooted at any node root of your choice. The incurred cost after choosing root is the difference between the maximum and minimum price sum amongst all paths starting at root.\nReturn the maximum possible cost amongst all possible root choices.",
+        "examples": [
+            "Example 1:\nInput: n = 6, edges = [[0,1],[1,2],[1,3],[3,4],[3,5]], price = [9,8,7,6,10,5]\nOutput: 24\nExplanation: The diagram above denotes the tree after rooting it at node 2. The first part (colored in red) shows the path with the maximum price sum. The second part (colored in blue) shows the path with the minimum price sum.\n- The first path contains nodes [2,1,3,4]: the prices are [7,8,6,10], and the sum of the prices is 31.\n- The second path contains the node [2] with the price [7].\nThe difference between the maximum and minimum price sum is 24. It can be proved that 24 is the maximum cost.",
+            "Example 2:\nInput: n = 3, edges = [[0,1],[1,2]], price = [1,1,1]\nOutput: 2\nExplanation: The diagram above denotes the tree after rooting it at node 0. The first part (colored in red) shows the path with the maximum price sum. The second part (colored in blue) shows the path with the minimum price sum.\n- The first path contains nodes [0,1,2]: the prices are [1,1,1], and the sum of the prices is 3.\n- The second path contains node [0] with a price [1].\nThe difference between the maximum and minimum price sum is 2. It can be proved that 2 is the maximum cost."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^5\nedges.length == n - 1\n0 <= ai, bi <= n - 1\nedges represents a valid tree.\nprice.length == n\n1 <= price[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Tree",
+            "Depth-First Search"
+        ],
+        "title-slug": "difference-between-maximum-and-minimum-price-sum"
+    },
+    {
+        "leetcode-id": 2540,
+        "title": "Minimum Common Value",
+        "difficulty": 1,
+        "description": "Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1.\nNote that an integer is said to be common to nums1 and nums2 if both arrays have at least one occurrence of that integer.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [1,2,3], nums2 = [2,4]\nOutput: 2\nExplanation: The smallest element common to both arrays is 2, so we return 2.",
+            "Example 2:\nInput: nums1 = [1,2,3,6], nums2 = [2,3,4,5]\nOutput: 2\nExplanation: There are two common elements in the array 2 and 3 out of which 2 is the smallest, so 2 is returned."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 10^5\n1 <= nums1[i], nums2[j] <= 10^9\nBoth nums1 and nums2 are sorted in non-decreasing order.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Two Pointers",
+            "Binary Search"
+        ],
+        "title-slug": "minimum-common-value"
+    },
+    {
+        "leetcode-id": 2541,
+        "title": "Minimum Operations to Make Array Equal II",
+        "difficulty": 2,
+        "description": "You are given two integer arrays nums1 and nums2 of equal length n and an integer k. You can perform the following operation on nums1:\n\nChoose two indexes i and j and increment nums1[i] by k and decrement nums1[j] by k. In other words, nums1[i] = nums1[i] + k and nums1[j] = nums1[j] - k.\n\nnums1 is said to be equal to nums2 if for all indices i such that 0 <= i < n, nums1[i] == nums2[i].\nReturn the minimum number of operations required to make nums1 equal to nums2. If it is impossible to make them equal, return -1.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [4,3,1,4], nums2 = [1,3,7,1], k = 3\nOutput: 2\nExplanation: In 2 operations, we can transform nums1 to nums2.\n1^st operation: i = 2, j = 0. After applying the operation, nums1 = [1,3,4,4].\n2^nd operation: i = 2, j = 3. After applying the operation, nums1 = [1,3,7,1].\nOne can prove that it is impossible to make arrays equal in fewer operations.",
+            "Example 2:\nInput: nums1 = [3,8,5,2], nums2 = [2,4,1,6], k = 1\nOutput: -1\nExplanation: It can be proved that it is impossible to make the two arrays equal."
+        ],
+        "constraints": "Constraints:\n\nn == nums1.length == nums2.length\n2 <= n <= 10^5\n0 <= nums1[i], nums2[j] <= 10^9\n0 <= k <= 10^5",
+        "tags": [
+            "Array",
+            "Math",
+            "Greedy"
+        ],
+        "title-slug": "minimum-operations-to-make-array-equal-ii"
+    },
+    {
+        "leetcode-id": 2542,
+        "title": "Maximum Subsequence Score",
+        "difficulty": 2,
+        "description": "You are given two 0-indexed integer arrays nums1 and nums2 of equal length n and a positive integer k. You must choose a subsequence of indices from nums1 of length k.\nFor chosen indices i0, i1, ..., ik - 1, your score is defined as:\n\nThe sum of the selected elements from nums1 multiplied with the minimum of the selected elements from nums2.\nIt can defined simply as: (nums1[i0] + nums1[i1] +...+ nums1[ik - 1]) * min(nums2[i0] , nums2[i1], ... ,nums2[ik - 1]).\n\nReturn the maximum possible score.\nA subsequence of indices of an array is a set that can be derived from the set {0, 1, ..., n-1} by deleting some or no elements.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [1,3,3,2], nums2 = [2,1,3,4], k = 3\nOutput: 12\nExplanation: \nThe four possible subsequence scores are:\n- We choose the indices 0, 1, and 2 with score = (1+3+3) * min(2,1,3) = 7.\n- We choose the indices 0, 1, and 3 with score = (1+3+2) * min(2,1,4) = 6. \n- We choose the indices 0, 2, and 3 with score = (1+3+2) * min(2,3,4) = 12. \n- We choose the indices 1, 2, and 3 with score = (3+3+2) * min(1,3,4) = 8.\nTherefore, we return the max score, which is 12.",
+            "Example 2:\nInput: nums1 = [4,2,3,1,1], nums2 = [7,5,10,9,6], k = 1\nOutput: 30\nExplanation: \nChoosing index 2 is optimal: nums1[2] * nums2[2] = 3 * 10 = 30 is the maximum possible score."
+        ],
+        "constraints": "Constraints:\n\nn == nums1.length == nums2.length\n1 <= n <= 10^5\n0 <= nums1[i], nums2[j] <= 10^5\n1 <= k <= n",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "maximum-subsequence-score"
+    },
+    {
+        "leetcode-id": 2543,
+        "title": "Check if Point Is Reachable",
+        "difficulty": 3,
+        "description": "There exists an infinitely large grid. You are currently at point (1, 1), and you need to reach the point (targetX, targetY) using a finite number of steps.\nIn one step, you can move from point (x, y) to any one of the following points:\n\n(x, y - x)\n(x - y, y)\n(2 * x, y)\n(x, 2 * y)\n\nGiven two integers targetX and targetY representing the X-coordinate and Y-coordinate of your final position, return true if you can reach the point from (1, 1) using some number of steps, and false otherwise.",
+        "examples": [
+            "Example 1:\nInput: targetX = 6, targetY = 9\nOutput: false\nExplanation: It is impossible to reach (6,9) from (1,1) using any sequence of moves, so false is returned.",
+            "Example 2:\nInput: targetX = 4, targetY = 7\nOutput: true\nExplanation: You can follow the path (1,1) -> (1,2) -> (1,4) -> (1,8) -> (1,7) -> (2,7) -> (4,7)."
+        ],
+        "constraints": "Constraints:\n\n1 <= targetX, targetY\u00a0<= 10^9",
+        "tags": [
+            "Math",
+            "Number Theory"
+        ],
+        "title-slug": "check-if-point-is-reachable"
+    },
+    {
+        "leetcode-id": 2544,
+        "title": "Alternating Digit Sum",
+        "difficulty": 1,
+        "description": "You are given a positive integer n. Each digit of n has a sign according to the following rules:\n\nThe most significant digit is assigned a positive sign.\nEach other digit has an opposite sign to its adjacent digits.\n\nReturn the sum of all digits with their corresponding sign.",
+        "examples": [
+            "Example 1:\nInput: n = 521\nOutput: 4\nExplanation: (+5) + (-2) + (+1) = 4.",
+            "Example 2:\nInput: n = 111\nOutput: 1\nExplanation: (+1) + (-1) + (+1) = 1.",
+            "Example 3:\nInput: n = 886996\nOutput: 0\nExplanation: (+8) + (-8) + (+6) + (-9) + (+9) + (-6) = 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^9\n\n\u00a0\n.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0; \n}\n.spoiler {overflow:hidden;}\n.spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;}\n.spoilerbutton[value=\"Show Message\"] + .spoiler > div {margin-top:-500%;}\n.spoilerbutton[value=\"Hide Message\"] + .spoiler {padding:5px;}",
+        "tags": [
+            "Math"
+        ],
+        "title-slug": "alternating-digit-sum"
+    },
+    {
+        "leetcode-id": 2545,
+        "title": "Sort the Students by Their Kth Score",
+        "difficulty": 2,
+        "description": "There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denotes the score the i^th student got in the j^th exam. The matrix score contains distinct integers only.\nYou are also given an integer k. Sort the students (i.e., the rows of the matrix) by their scores in the k^th\u00a0(0-indexed) exam from the highest to the lowest.\nReturn the matrix after sorting it.",
+        "examples": [
+            "Example 1:\nInput: score = [[10,6,9,1],[7,5,11,2],[4,8,3,15]], k = 2\nOutput: [[7,5,11,2],[10,6,9,1],[4,8,3,15]]\nExplanation: In the above diagram, S denotes the student, while E denotes the exam.\n- The student with index 1 scored 11 in exam 2, which is the highest score, so they got first place.\n- The student with index 0 scored 9 in exam 2, which is the second highest score, so they got second place.\n- The student with index 2 scored 3 in exam 2, which is the lowest score, so they got third place.",
+            "Example 2:\nInput: score = [[3,4],[5,6]], k = 0\nOutput: [[5,6],[3,4]]\nExplanation: In the above diagram, S denotes the student, while E denotes the exam.\n- The student with index 1 scored 5 in exam 0, which is the highest score, so they got first place.\n- The student with index 0 scored 3 in exam 0, which is the lowest score, so they got second place."
+        ],
+        "constraints": "Constraints:\n\nm == score.length\nn == score[i].length\n1 <= m, n <= 250\n1 <= score[i][j] <= 10^5\nscore consists of distinct integers.\n0 <= k < n",
+        "tags": [
+            "Array",
+            "Sorting",
+            "Matrix"
+        ],
+        "title-slug": "sort-the-students-by-their-kth-score"
+    },
+    {
+        "leetcode-id": 2546,
+        "title": "Apply Bitwise Operations to Make Strings Equal",
+        "difficulty": 2,
+        "description": "You are given two 0-indexed binary strings s and target of the same length n. You can do the following operation on s any number of times:\n\nChoose two different indices i and j where 0 <= i, j < n.\nSimultaneously, replace s[i] with (s[i] OR s[j]) and s[j] with (s[i] XOR s[j]).\n\nFor example, if s = \"0110\", you can choose i = 0 and j = 2, then simultaneously replace s[0] with (s[0] OR s[2] = 0 OR 1 = 1), and s[2] with (s[0] XOR s[2] = 0 XOR 1 = 1), so we will have s = \"1110\".\nReturn true if you can make the string s equal to target, or false otherwise.",
+        "examples": [
+            "Example 1:\nInput: s = \"1010\", target = \"0110\"\nOutput: true\nExplanation: We can do the following operations:\n- Choose i = 2 and j = 0. We have now s = \"0010\".\n- Choose i = 2 and j = 1. We have now s = \"0110\".\nSince we can make s equal to target, we return true.",
+            "Example 2:\nInput: s = \"11\", target = \"00\"\nOutput: false\nExplanation: It is not possible to make s equal to target with any number of operations."
+        ],
+        "constraints": "Constraints:\n\nn == s.length == target.length\n2 <= n <= 10^5\ns and target consist of only the digits 0 and 1.",
+        "tags": [
+            "String",
+            "Bit Manipulation"
+        ],
+        "title-slug": "apply-bitwise-operations-to-make-strings-equal"
+    },
+    {
+        "leetcode-id": 2547,
+        "title": "Minimum Cost to Split an Array",
+        "difficulty": 3,
+        "description": "You are given an integer array nums and an integer k.\nSplit the array into some number of non-empty subarrays. The cost of a split is the sum of the importance value of each subarray in the split.\nLet trimmed(subarray) be the version of the subarray where all numbers which appear only once are removed.\n\nFor example, trimmed([3,1,2,4,3,4]) = [3,4,3,4].\n\nThe importance value of a subarray is k + trimmed(subarray).length.\n\nFor example, if a subarray is [1,2,3,3,3,4,4], then trimmed([1,2,3,3,3,4,4]) = [3,3,3,4,4].The importance value of this subarray will be k + 5.\n\nReturn the minimum possible cost of a split of nums.\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,1,2,1,3,3], k = 2\nOutput: 8\nExplanation: We split nums to have two subarrays: [1,2], [1,2,1,3,3].\nThe importance value of [1,2] is 2 + (0) = 2.\nThe importance value of [1,2,1,3,3] is 2 + (2 + 2) = 6.\nThe cost of the split is 2 + 6 = 8. It can be shown that this is the minimum possible cost among all the possible splits.",
+            "Example 2:\nInput: nums = [1,2,1,2,1], k = 2\nOutput: 6\nExplanation: We split nums to have two subarrays: [1,2], [1,2,1].\nThe importance value of [1,2] is 2 + (0) = 2.\nThe importance value of [1,2,1] is 2 + (2) = 4.\nThe cost of the split is 2 + 4 = 6. It can be shown that this is the minimum possible cost among all the possible splits.",
+            "Example 3:\nInput: nums = [1,2,1,2,1], k = 5\nOutput: 10\nExplanation: We split nums to have one subarray: [1,2,1,2,1].\nThe importance value of [1,2,1,2,1] is 5 + (3 + 2) = 10.\nThe cost of the split is 10. It can be shown that this is the minimum possible cost among all the possible splits."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n0 <= nums[i] < nums.length\n1 <= k <= 10^9\n\n\u00a0\n.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0;\u00a0\n}\n.spoiler {overflow:hidden;}\n.spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;}\n.spoilerbutton[value=\"Show Message\"] + .spoiler > div {margin-top:-500%;}\n.spoilerbutton[value=\"Hide Message\"] + .spoiler {padding:5px;}",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Dynamic Programming",
+            "Counting"
+        ],
+        "title-slug": "minimum-cost-to-split-an-array"
+    },
+    {
+        "leetcode-id": 2549,
+        "title": "Count Distinct Numbers on Board",
+        "difficulty": 1,
+        "description": "You are given a positive integer n, that is initially placed on a board. Every day, for 10^9 days, you perform the following procedure:\n\nFor each number x present on the board, find all numbers 1 <= i <= n such that x % i == 1.\nThen, place those numbers on the board.\n\nReturn the number of distinct integers present on the board after 10^9 days have elapsed.\nNote:\n\nOnce a number is placed on the board, it will remain on it until the end.\n%\u00a0stands\u00a0for the modulo operation. For example,\u00a014 % 3 is 2.",
+        "examples": [
+            "Example 1:\nInput: n = 5\nOutput: 4\nExplanation: Initially, 5 is present on the board. \nThe next day, 2 and 4 will be added since 5 % 2 == 1 and 5 % 4 == 1. \nAfter that day, 3 will be added to the board because 4 % 3 == 1. \nAt the end of a billion days, the distinct numbers on the board will be 2, 3, 4, and 5.",
+            "Example 2:\nInput: n = 3\nOutput: 2\nExplanation: \nSince 3 % 2 == 1, 2 will be added to the board. \nAfter a billion days, the only two distinct numbers on the board are 2 and 3."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 100",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Math",
+            "Simulation"
+        ],
+        "title-slug": "count-distinct-numbers-on-board"
+    },
+    {
+        "leetcode-id": 2550,
+        "title": "Count Collisions of Monkeys on a Polygon",
+        "difficulty": 2,
+        "description": "There is a regular convex polygon with n vertices. The vertices are labeled from 0 to n - 1 in a clockwise direction, and each vertex has exactly one monkey. The following figure shows a convex polygon of 6 vertices.\n\nEach monkey moves simultaneously to a neighboring vertex. A neighboring vertex for a vertex i can be:\n\nthe vertex (i + 1) % n in the clockwise direction, or\nthe vertex (i - 1 + n) % n in the counter-clockwise direction.\n\nA collision happens if at least two monkeys reside on the same vertex after the movement or intersect\u00a0on an edge.\nReturn the number of ways the monkeys can move so that at least one collision  happens. Since the answer may be very large, return it modulo 10^9 + 7.\nNote that each monkey can only move once.",
+        "examples": [
+            "Example 1:\nInput: n = 3\nOutput: 6\nExplanation: There are 8 total possible movements.\nTwo ways such that they collide at some point are:\n- Monkey 1 moves in a clockwise direction; monkey 2 moves in an anticlockwise direction; monkey 3 moves in a clockwise direction. Monkeys 1 and 2 collide.\n- Monkey 1 moves in an anticlockwise direction; monkey 2 moves in an anticlockwise direction; monkey 3 moves in a clockwise direction. Monkeys 1 and 3 collide.\nIt can be shown 6 total movements result in a collision.",
+            "Example 2:\nInput: n = 4\nOutput: 14\nExplanation: It can be shown that there are 14 ways for the monkeys to collide."
+        ],
+        "constraints": "Constraints:\n\n3 <= n <= 10^9",
+        "tags": [
+            "Math",
+            "Recursion"
+        ],
+        "title-slug": "count-collisions-of-monkeys-on-a-polygon"
+    },
+    {
+        "leetcode-id": 2551,
+        "title": "Put Marbles in Bags",
+        "difficulty": 3,
+        "description": "You have k bags. You are given a 0-indexed integer array weights where weights[i] is the weight of the i^th marble. You are also given the integer k.\nDivide the marbles into the k bags according to the following rules:\n\nNo bag is empty.\nIf the i^th marble and j^th marble are in a bag, then all marbles with an index between the i^th and j^th indices should also be in that same bag.\nIf a bag consists of all the marbles with an index from i to j inclusively, then the cost of the bag is weights[i] + weights[j].\n\nThe score after distributing the marbles is the sum of the costs of all the k bags.\nReturn the difference between the maximum and minimum scores among marble distributions.",
+        "examples": [
+            "Example 1:\nInput: weights = [1,3,5,1], k = 2\nOutput: 4\nExplanation: \nThe distribution [1],[3,5,1] results in the minimal score of (1+1) + (3+1) = 6. \nThe distribution [1,3],[5,1], results in the maximal score of (1+3) + (5+1) = 10. \nThus, we return their difference 10 - 6 = 4.",
+            "Example 2:\nInput: weights = [1, 3], k = 2\nOutput: 0\nExplanation: The only distribution possible is [1],[3]. \nSince both the maximal and minimal score are the same, we return 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= k <= weights.length <= 10^5\n1 <= weights[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "put-marbles-in-bags"
+    },
+    {
+        "leetcode-id": 2552,
+        "title": "Count Increasing Quadruplets",
+        "difficulty": 3,
+        "description": "Given a 0-indexed integer array nums of size n containing all numbers from 1 to n, return the number of increasing quadruplets.\nA quadruplet (i, j, k, l) is increasing if:\n\n0 <= i < j < k < l < n, and\nnums[i] < nums[k] < nums[j] < nums[l].",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,2,4,5]\nOutput: 2\nExplanation: \n- When i = 0, j = 1, k = 2, and l = 3, nums[i] < nums[k] < nums[j] < nums[l].\n- When i = 0, j = 1, k = 2, and l = 4, nums[i] < nums[k] < nums[j] < nums[l]. \nThere are no other quadruplets, so we return 2.",
+            "Example 2:\nInput: nums = [1,2,3,4]\nOutput: 0\nExplanation: There exists only one quadruplet with i = 0, j = 1, k = 2, l = 3, but since nums[j] < nums[k], we return 0."
+        ],
+        "constraints": "Constraints:\n\n4 <= nums.length <= 4000\n1 <= nums[i] <= nums.length\nAll the integers of nums are unique. nums is a permutation.",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Binary Indexed Tree",
+            "Enumeration",
+            "Prefix Sum"
+        ],
+        "title-slug": "count-increasing-quadruplets"
+    },
+    {
+        "leetcode-id": 2553,
+        "title": "Separate the Digits in an Array",
+        "difficulty": 1,
+        "description": "Given an array of positive integers nums, return an array answer that consists of the digits of each integer in nums after separating them in the same order they appear in nums.\nTo separate the digits of an integer is to get all the digits it has in the same order.\n\nFor example, for the integer 10921, the separation of its digits is [1,0,9,2,1].",
+        "examples": [
+            "Example 1:\nInput: nums = [13,25,83,77]\nOutput: [1,3,2,5,8,3,7,7]\nExplanation: \n- The separation of 13 is [1,3].\n- The separation of 25 is [2,5].\n- The separation of 83 is [8,3].\n- The separation of 77 is [7,7].\nanswer = [1,3,2,5,8,3,7,7]. Note that answer contains the separations in the same order.",
+            "Example 2:\nInput: nums = [7,1,3,9]\nOutput: [7,1,3,9]\nExplanation: The separation of each integer in nums is itself.\nanswer = [7,1,3,9]."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Simulation"
+        ],
+        "title-slug": "separate-the-digits-in-an-array"
+    },
+    {
+        "leetcode-id": 2554,
+        "title": "Maximum Number of Integers to Choose From a Range I",
+        "difficulty": 2,
+        "description": "You are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules:\n\nThe chosen integers have to be in the range [1, n].\nEach integer can be chosen at most once.\nThe chosen integers should not be in the array banned.\nThe sum of the chosen integers should not exceed maxSum.\n\nReturn the maximum number of integers you can choose following the mentioned rules.",
+        "examples": [
+            "Example 1:\nInput: banned = [1,6,5], n = 5, maxSum = 6\nOutput: 2\nExplanation: You can choose the integers 2 and 4.\n2 and 4 are from the range [1, 5], both did not appear in banned, and their sum is 6, which did not exceed maxSum.",
+            "Example 2:\nInput: banned = [1,2,3,4,5,6,7], n = 8, maxSum = 1\nOutput: 0\nExplanation: You cannot choose any integer while following the mentioned conditions.",
+            "Example 3:\nInput: banned = [11], n = 7, maxSum = 50\nOutput: 7\nExplanation: You can choose the integers 1, 2, 3, 4, 5, 6, and 7.\nThey are from the range [1, 7], all did not appear in banned, and their sum is 28, which did not exceed maxSum."
+        ],
+        "constraints": "Constraints:\n\n1 <= banned.length <= 10^4\n1 <= banned[i], n <= 10^4\n1 <= maxSum <= 10^9",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Binary Search",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "maximum-number-of-integers-to-choose-from-a-range-i"
+    },
+    {
+        "leetcode-id": 2555,
+        "title": "Maximize Win From Two Segments",
+        "difficulty": 2,
+        "description": "There are some prizes on the X-axis. You are given an integer array prizePositions that is sorted in non-decreasing order, where prizePositions[i] is the position of the i^th prize. There could be different prizes at the same position on the line. You are also given an integer k.\nYou are allowed to select two segments with integer endpoints. The length of each segment must be k. You will collect all prizes whose position falls within at least one of the two selected segments (including the endpoints of the segments). The two selected segments may intersect.\n\nFor example if k = 2, you can choose segments [1, 3] and [2, 4], and you will win any prize i that satisfies 1 <= prizePositions[i] <= 3 or 2 <= prizePositions[i] <= 4.\n\nReturn the maximum number of prizes you can win if you choose the two segments optimally.",
+        "examples": [
+            "Example 1:\nInput: prizePositions = [1,1,2,2,3,3,5], k = 2\nOutput: 7\nExplanation: In this example, you can win all 7 prizes by selecting two segments [1, 3] and [3, 5].",
+            "Example 2:\nInput: prizePositions = [1,2,3,4], k = 0\nOutput: 2\nExplanation: For this example, one choice for the segments is [3, 3] and [4, 4], and you will be able to get 2 prizes."
+        ],
+        "constraints": "Constraints:\n\n1 <= prizePositions.length <= 10^5\n1 <= prizePositions[i] <= 10^9\n0 <= k <= 10^9 \nprizePositions is sorted in non-decreasing order.\n\n\u00a0\n.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0; \n}\n.spoiler {overflow:hidden;}\n.spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;}\n.spoilerbutton[value=\"Show Message\"] + .spoiler > div {margin-top:-500%;}\n.spoilerbutton[value=\"Hide Message\"] + .spoiler {padding:5px;}",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Sliding Window"
+        ],
+        "title-slug": "maximize-win-from-two-segments"
+    },
+    {
+        "leetcode-id": 2556,
+        "title": "Disconnect Path in a Binary Matrix by at Most One Flip",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed m x n binary matrix grid. You can move from a cell (row, col) to any of the cells (row + 1, col) or (row, col + 1) that has the value 1.\u00a0The matrix is disconnected if there is no path from (0, 0) to (m - 1, n - 1).\nYou can flip the value of at most one (possibly none) cell. You cannot flip the cells (0, 0) and (m - 1, n - 1).\nReturn true if it is possible to make the matrix disconnect or false otherwise.\nNote that flipping a cell changes its value from 0 to 1 or from 1 to 0.",
+        "examples": [
+            "Example 1:\nInput: grid = [[1,1,1],[1,0,0],[1,1,1]]\nOutput: true\nExplanation: We can change the cell shown in the diagram above. There is no path from (0, 0) to (2, 2) in the resulting grid.",
+            "Example 2:\nInput: grid = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: false\nExplanation: It is not possible to change at most one cell such that there is not path from (0, 0) to (2, 2)."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 1000\n1 <= m * n <= 10^5\ngrid[i][j] is either 0 or 1.\ngrid[0][0] == grid[m - 1][n - 1] == 1",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Matrix"
+        ],
+        "title-slug": "disconnect-path-in-a-binary-matrix-by-at-most-one-flip"
+    },
+    {
+        "leetcode-id": 2558,
+        "title": "Take Gifts From the Richest Pile",
+        "difficulty": 1,
+        "description": "You are given an integer array gifts denoting the number of gifts in various piles. Every second, you do the following:\n\nChoose the pile with the maximum number of gifts.\nIf there is more than one pile with the maximum number of gifts, choose any.\nLeave behind the floor of the square root of the number of gifts in the pile. Take the rest of the gifts.\n\nReturn the number of gifts remaining after k seconds.",
+        "examples": [
+            "Example 1:\nInput: gifts = [25,64,9,4,100], k = 4\nOutput: 29\nExplanation: \nThe gifts are taken in the following way:\n- In the first second, the last pile is chosen and 10 gifts are left behind.\n- Then the second pile is chosen and 8 gifts are left behind.\n- After that the first pile is chosen and 5 gifts are left behind.\n- Finally, the last pile is chosen again and 3 gifts are left behind.\nThe final remaining gifts are [5,8,9,4,3], so the total number of gifts remaining is 29.",
+            "Example 2:\nInput: gifts = [1,1,1,1], k = 4\nOutput: 4\nExplanation: \nIn this case, regardless which pile you choose, you have to leave behind 1 gift in each pile. \nThat is, you can't take any pile with you. \nSo, the total gifts remaining are 4."
+        ],
+        "constraints": "Constraints:\n\n1 <= gifts.length <= 10^3\n1 <= gifts[i] <= 10^9\n1 <= k <= 10^3",
+        "tags": [
+            "Array",
+            "Heap (Priority Queue)",
+            "Simulation"
+        ],
+        "title-slug": "take-gifts-from-the-richest-pile"
+    },
+    {
+        "leetcode-id": 2559,
+        "title": "Count Vowel Strings in Ranges",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array of strings words and a 2D array of integers queries.\nEach query queries[i] = [li, ri] asks us to find the number of strings present in the range li to ri (both inclusive) of words that start and end with a vowel.\nReturn an array ans of size queries.length, where ans[i] is the answer to the i^th query.\nNote that the vowel letters are 'a', 'e', 'i', 'o', and 'u'.",
+        "examples": [
+            "Example 1:\nInput: words = [\"aba\",\"bcb\",\"ece\",\"aa\",\"e\"], queries = [[0,2],[1,4],[1,1]]\nOutput: [2,3,0]\nExplanation: The strings starting and ending with a vowel are \"aba\", \"ece\", \"aa\" and \"e\".\nThe answer to the query [0,2] is 2 (strings \"aba\" and \"ece\").\nto query [1,4] is 3 (strings \"ece\", \"aa\", \"e\").\nto query [1,1] is 0.\nWe return [2,3,0].",
+            "Example 2:\nInput: words = [\"a\",\"e\",\"i\"], queries = [[0,2],[0,1],[2,2]]\nOutput: [3,2,1]\nExplanation: Every string satisfies the conditions, so we return [3,2,1]."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 10^5\n1 <= words[i].length <= 40\nwords[i] consists only of lowercase English letters.\nsum(words[i].length) <= 3 * 10^5\n1 <= queries.length <= 10^5\n0 <= li <= ri <\u00a0words.length",
+        "tags": [
+            "Array",
+            "String",
+            "Prefix Sum"
+        ],
+        "title-slug": "count-vowel-strings-in-ranges"
+    },
+    {
+        "leetcode-id": 2560,
+        "title": "House Robber IV",
+        "difficulty": 2,
+        "description": "There are several consecutive houses along a street, each of which has some money inside. There is also a robber, who wants to steal money from the homes, but he refuses to steal from adjacent homes.\nThe capability of the robber is the maximum amount of money he steals from one house of all the houses he robbed.\nYou are given an integer array nums representing how much money is stashed in each house. More formally, the i^th house from the left has nums[i] dollars.\nYou are also given an integer k, representing the minimum number of houses the robber will steal from. It is always possible to steal at least k houses.\nReturn the minimum capability of the robber out of all the possible ways to steal at least k houses.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,3,5,9], k = 2\nOutput: 5\nExplanation: \nThere are three ways to rob at least 2 houses:\n- Rob the houses at indices 0 and 2. Capability is max(nums[0], nums[2]) = 5.\n- Rob the houses at indices 0 and 3. Capability is max(nums[0], nums[3]) = 9.\n- Rob the houses at indices 1 and 3. Capability is max(nums[1], nums[3]) = 9.\nTherefore, we return min(5, 9, 9) = 5.",
+            "Example 2:\nInput: nums = [2,7,9,3,1], k = 2\nOutput: 2\nExplanation: There are 7 ways to rob the houses. The way which leads to minimum capability is to rob the house at index 0 and 4. Return max(nums[0], nums[4]) = 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\n1 <= k <= (nums.length + 1)/2",
+        "tags": [
+            "Array",
+            "Binary Search"
+        ],
+        "title-slug": "house-robber-iv"
+    },
+    {
+        "leetcode-id": 2561,
+        "title": "Rearranging Fruits",
+        "difficulty": 3,
+        "description": "You have two fruit baskets containing n fruits each. You are given two 0-indexed integer arrays basket1 and basket2 representing the cost of fruit in each basket. You want to make both baskets equal. To do so, you can use the following operation as many times as you want:\n\nChose two indices i and j, and swap the ith\u00a0fruit of basket1 with the jth\u00a0fruit of basket2.\nThe cost of the swap is min(basket1[i],basket2[j]).\n\nTwo baskets are considered equal if sorting them according to the fruit cost makes them exactly the same baskets.\nReturn the minimum cost to make both the baskets equal or -1 if impossible.",
+        "examples": [
+            "Example 1:\nInput: basket1 = [4,2,2,2], basket2 = [1,4,1,2]\nOutput: 1\nExplanation: Swap index 1 of basket1 with index 0 of basket2, which has cost 1. Now basket1 = [4,1,2,2] and basket2 = [2,4,1,2]. Rearranging both the arrays makes them equal.",
+            "Example 2:\nInput: basket1 = [2,3,4,1], basket2 = [3,2,5,1]\nOutput: -1\nExplanation: It can be shown that it is impossible to make both the baskets equal."
+        ],
+        "constraints": "Constraints:\n\nbasket1.length == basket2.length\n1 <= basket1.length <= 10^5\n1 <= basket1[i],basket2[i]\u00a0<= 10^9",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Greedy"
+        ],
+        "title-slug": "rearranging-fruits"
+    },
+    {
+        "leetcode-id": 2562,
+        "title": "Find the Array Concatenation Value",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums.\nThe concatenation of two numbers is the number formed by concatenating their numerals.\n\nFor example, the concatenation of 15, 49 is 1549.\n\nThe concatenation value of nums is initially equal to 0. Perform this operation until nums becomes empty:\n\nIf there exists more than one number in nums, pick the first element and last element in nums respectively and add the value of their concatenation to the concatenation value of nums, then delete the first and last element from nums.\nIf one element exists, add its value to the concatenation value of nums, then delete it.\n\nReturn the concatenation value of the nums.",
+        "examples": [
+            "Example 1:\nInput: nums = [7,52,2,4]\nOutput: 596\nExplanation: Before performing any operation, nums is [7,52,2,4] and concatenation value is 0.\n - In the first operation:\nWe pick the first element, 7, and the last element, 4.\nTheir concatenation is 74, and we add it to the concatenation value, so it becomes equal to 74.\nThen we delete them from nums, so nums becomes equal to [52,2].\n - In the second operation:\nWe pick the first element, 52, and the last element, 2.\nTheir concatenation is 522, and we add it to the concatenation value, so it becomes equal to 596.\nThen we delete them from the nums, so nums becomes empty.\nSince the concatenation value is 596 so the answer is 596.",
+            "Example 2:\nInput: nums = [5,14,13,8,12]\nOutput: 673\nExplanation: Before performing any operation, nums is [5,14,13,8,12] and concatenation value is 0.\n - In the first operation:\nWe pick the first element, 5, and the last element, 12.\nTheir concatenation is 512, and we add it to the concatenation value, so it becomes equal to 512.\nThen we delete them from the nums, so nums becomes equal to [14,13,8].\n - In the second operation:\nWe pick the first element, 14, and the last element, 8.\nTheir concatenation is 148, and we add it to the concatenation value, so it becomes equal to 660.\nThen we delete them from the nums, so nums becomes equal to [13].\n - In the third operation:\nnums has only one element, so we pick 13 and add it to the concatenation value, so it becomes equal to 673.\nThen we delete it from nums, so nums become empty.\nSince the concatenation value is 673 so the answer is 673."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 10^4\n\n\u00a0\n.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0;\u00a0\n}\n.spoiler {overflow:hidden;}\n.spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;}\n.spoilerbutton[value=\"Show Message\"] + .spoiler > div {margin-top:-500%;}\n.spoilerbutton[value=\"Hide Message\"] + .spoiler {padding:5px;}",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Simulation"
+        ],
+        "title-slug": "find-the-array-concatenation-value"
+    },
+    {
+        "leetcode-id": 2563,
+        "title": "Count the Number of Fair Pairs",
+        "difficulty": 2,
+        "description": "Given a 0-indexed integer array nums of size n and two integers lower and upper, return the number of fair pairs.\nA pair (i, j) is fair if:\n\n0 <= i < j < n, and\nlower <= nums[i] + nums[j] <= upper",
+        "examples": [
+            "Example 1:\nInput: nums = [0,1,7,4,4,5], lower = 3, upper = 6\nOutput: 6\nExplanation: There are 6 fair pairs: (0,3), (0,4), (0,5), (1,3), (1,4), and (1,5).",
+            "Example 2:\nInput: nums = [1,7,9,2,5], lower = 11, upper = 11\nOutput: 1\nExplanation: There is a single fair pair: (2,3)."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\nnums.length == n\n-10^9\u00a0<= nums[i] <= 10^9\n-10^9\u00a0<= lower <= upper <= 10^9",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Binary Search",
+            "Sorting"
+        ],
+        "title-slug": "count-the-number-of-fair-pairs"
+    },
+    {
+        "leetcode-id": 2564,
+        "title": "Substring XOR Queries",
+        "difficulty": 2,
+        "description": "You are given a binary string s, and a 2D integer array queries where queries[i] = [firsti, secondi].\nFor the i^th query, find the shortest substring of s whose decimal value, val, yields secondi when bitwise XORed with firsti. In other words, val ^ firsti == secondi.\nThe answer to the i^th query is the endpoints (0-indexed) of the substring [lefti, righti] or [-1, -1] if no such substring exists. If there are multiple answers, choose the one with the minimum lefti.\nReturn an array ans where ans[i] = [lefti, righti] is the answer to the i^th query.\nA substring is a contiguous non-empty sequence of characters within a string.",
+        "examples": [
+            "Example 1:\nInput: s = \"101101\", queries = [[0,5],[1,2]]\nOutput: [[0,2],[2,3]]\nExplanation: For the first query the substring in range [0,2] is \"101\" which has a decimal value of 5, and 5 ^ 0 = 5, hence the answer to the first query is [0,2]. In the second query, the substring in range [2,3] is \"11\", and has a decimal value of 3, and 3 ^ 1 = 2.\u00a0So, [2,3] is returned for the second query.",
+            "Example 2:\nInput: s = \"0101\", queries = [[12,8]]\nOutput: [[-1,-1]]\nExplanation: In this example there is no substring that answers the query, hence [-1,-1] is returned.",
+            "Example 3:\nInput: s = \"1\", queries = [[4,5]]\nOutput: [[0,0]]\nExplanation: For this example, the substring in range [0,0] has a decimal value of 1, and 1 ^ 4 = 5. So, the answer is [0,0]."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^4\ns[i] is either '0' or '1'.\n1 <= queries.length <= 10^5\n0 <= firsti, secondi <= 10^9",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Bit Manipulation"
+        ],
+        "title-slug": "substring-xor-queries"
+    },
+    {
+        "leetcode-id": 2565,
+        "title": "Subsequence With the Minimum Score",
+        "difficulty": 3,
+        "description": "You are given two strings s and t.\nYou are allowed to remove any number of characters from the string t.\nThe score of the string is 0 if no characters are removed from the string t, otherwise:\n\nLet left be the minimum index among all removed characters.\nLet right be the maximum index among all removed characters.\n\nThen the score of the string is right - left + 1.\nReturn the minimum possible score to make t\u00a0a subsequence of s.\nA subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., \"ace\" is a subsequence of \"abcde\" while \"aec\" is not).",
+        "examples": [
+            "Example 1:\nInput: s = \"abacaba\", t = \"bzaa\"\nOutput: 1\nExplanation: In this example, we remove the character \"z\" at index 1 (0-indexed).\nThe string t becomes \"baa\" which is a subsequence of the string \"abacaba\" and the score is 1 - 1 + 1 = 1.\nIt can be proven that 1 is the minimum score that we can achieve.",
+            "Example 2:\nInput: s = \"cde\", t = \"xyz\"\nOutput: 3\nExplanation: In this example, we remove characters \"x\", \"y\" and \"z\" at indices 0, 1, and 2 (0-indexed).\nThe string t becomes \"\" which is a subsequence of the string \"cde\" and the score is 2 - 0 + 1 = 3.\nIt can be proven that 3 is the minimum score that we can achieve."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length, t.length <= 10^5\ns and t consist of only lowercase English letters.",
+        "tags": [
+            "Two Pointers",
+            "String",
+            "Binary Search"
+        ],
+        "title-slug": "subsequence-with-the-minimum-score"
+    },
+    {
+        "leetcode-id": 2566,
+        "title": "Maximum Difference by Remapping a Digit",
+        "difficulty": 1,
+        "description": "You are given an integer num. You know that Danny Mittal will sneakily remap one of the 10 possible digits (0 to 9) to another digit.\nReturn the difference between the maximum and minimum\u00a0values Danny can make by remapping\u00a0exactly one digit in num.\nNotes:\n\nWhen Danny remaps a digit d1\u00a0to another digit d2, Danny replaces all occurrences of d1\u00a0in num\u00a0with d2.\nDanny can remap a digit to itself, in which case num\u00a0does not change.\nDanny can remap different digits for obtaining minimum and maximum values respectively.\nThe resulting number after remapping can contain leading zeroes.\nWe mentioned \"Danny Mittal\" to congratulate him on being in the top 10 in Weekly Contest 326.",
+        "examples": [
+            "Example 1:\nInput: num = 11891\nOutput: 99009\nExplanation: \nTo achieve the maximum value, Danny can remap the digit 1 to the digit 9 to yield 99899.\nTo achieve the minimum value, Danny can remap the digit 1 to the digit 0, yielding 890.\nThe difference between these two numbers is 99009.",
+            "Example 2:\nInput: num = 90\nOutput: 99\nExplanation:\nThe maximum value that can be returned by the function is 99 (if 0 is replaced by 9) and the minimum value that can be returned by the function is 0 (if 9 is replaced by 0).\nThus, we return 99."
+        ],
+        "constraints": "Constraints:\n\n1 <= num <= 10^8",
+        "tags": [
+            "Math",
+            "Greedy"
+        ],
+        "title-slug": "maximum-difference-by-remapping-a-digit"
+    },
+    {
+        "leetcode-id": 2567,
+        "title": "Minimum Score by Changing Two Elements",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums.\n\nThe low score of nums is the minimum value of |nums[i]\u00a0- nums[j]| over all 0 <= i < j < nums.length.\nThe high score of\u00a0nums is the maximum value of |nums[i]\u00a0- nums[j]| over all 0 <= i < j < nums.length.\nThe score of nums is the sum of the high and low scores of nums.\n\nTo minimize the score of nums, we can change the value of at most two elements of nums.\nReturn the minimum possible score after changing\u00a0the value of at most two elements of nums.\nNote that |x| denotes the absolute value of x.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,4,3]\nOutput: 0\nExplanation: Change value of nums[1] and nums[2] to 1 so that nums becomes [1,1,1]. Now, the value of |nums[i] - nums[j]| is always equal to 0, so we return 0 + 0 = 0.",
+            "Example 2:\nInput: nums = [1,4,7,8,5]\nOutput: 3\nExplanation: Change nums[0] and nums[1] to be 6. Now nums becomes [6,6,7,8,5].\nOur low score is achieved when i = 0 and j = 1, in which case |nums[i] - nums[j]| = |6 - 6| = 0.\nOur high score is achieved when i = 3 and j = 4, in which case |nums[i] - nums[j]| = |8 - 5| = 3.\nThe sum of our high and low score is 3, which we can prove to be minimal."
+        ],
+        "constraints": "Constraints:\n\n3 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "minimum-score-by-changing-two-elements"
+    },
+    {
+        "leetcode-id": 2568,
+        "title": "Minimum Impossible OR",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed\u00a0integer array nums.\nWe say that an integer x is expressible from nums if there exist some integers 0 <= index1 < index2 < ... < indexk < nums.length for which nums[index1] | nums[index2] | ... | nums[indexk] = x. In other words, an integer is expressible if it can be written as the bitwise OR of some subsequence of nums.\nReturn the minimum positive non-zero integer\u00a0that is not expressible from nums.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,1]\nOutput: 4\nExplanation: 1 and 2 are already present in the array. We know that 3 is expressible, since nums[0] | nums[1] = 2 | 1 = 3. Since 4 is not expressible, we return 4.",
+            "Example 2:\nInput: nums = [5,3,2]\nOutput: 1\nExplanation: We can show that 1 is the smallest number that is not expressible."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Bit Manipulation",
+            "Brainteaser"
+        ],
+        "title-slug": "minimum-impossible-or"
+    },
+    {
+        "leetcode-id": 2569,
+        "title": "Handling Sum Queries After Update",
+        "difficulty": 3,
+        "description": "You are given two 0-indexed arrays nums1 and nums2 and a 2D array queries of queries. There are three types of queries:\n\nFor a query of type 1, queries[i]\u00a0= [1, l, r]. Flip the values from 0 to 1 and from 1 to 0 in nums1\u00a0from index l to index r. Both l and r are 0-indexed.\nFor a query of type 2, queries[i]\u00a0= [2, p, 0]. For every index 0 <= i < n, set\u00a0nums2[i] =\u00a0nums2[i]\u00a0+ nums1[i]\u00a0* p.\nFor a query of type 3, queries[i]\u00a0= [3, 0, 0]. Find the sum of the elements in nums2.\n\nReturn an array containing all the answers to the third type\u00a0queries.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [1,0,1], nums2 = [0,0,0], queries = [[1,1,1],[2,1,0],[3,0,0]]\nOutput: [3]\nExplanation: After the first query nums1 becomes [1,1,1]. After the second query, nums2 becomes [1,1,1], so the answer to the third query is 3. Thus, [3] is returned.",
+            "Example 2:\nInput: nums1 = [1], nums2 = [5], queries = [[2,0,0],[3,0,0]]\nOutput: [5]\nExplanation: After the first query, nums2 remains [5], so the answer to the second query is 5. Thus, [5] is returned."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums1.length,nums2.length <= 10^5\nnums1.length = nums2.length\n1 <= queries.length <= 10^5\nqueries[i].length = 3\n0 <= l <= r <= nums1.length - 1\n0 <= p <= 10^6\n0 <= nums1[i] <= 1\n0 <= nums2[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Segment Tree"
+        ],
+        "title-slug": "handling-sum-queries-after-update"
+    },
+    {
+        "leetcode-id": 2570,
+        "title": "Merge Two 2D Arrays by Summing Values",
+        "difficulty": 1,
+        "description": "You are given two 2D integer arrays nums1 and nums2.\n\nnums1[i] = [idi, vali]\u00a0indicate that the number with the id idi has a value equal to vali.\nnums2[i] = [idi, vali]\u00a0indicate that the number with the id idi has a value equal to vali.\n\nEach array contains unique ids and is sorted in ascending order by id.\nMerge the two arrays into one array that is sorted in ascending order by id, respecting the following conditions:\n\nOnly ids that appear in at least one of the two arrays should be included in the resulting array.\nEach id should be included only once and its value should be the sum of the values of this id in the two arrays. If the id does not exist in one of the two arrays then its value in that array is considered to be 0.\n\nReturn the resulting array. The returned array must be sorted in ascending order by id.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [[1,2],[2,3],[4,5]], nums2 = [[1,4],[3,2],[4,1]]\nOutput: [[1,6],[2,3],[3,2],[4,6]]\nExplanation: The resulting array contains the following:\n- id = 1, the value of this id is 2 + 4 = 6.\n- id = 2, the value of this id is 3.\n- id = 3, the value of this id is 2.\n- id = 4, the value of this id is 5 + 1 = 6.",
+            "Example 2:\nInput: nums1 = [[2,4],[3,6],[5,5]], nums2 = [[1,3],[4,3]]\nOutput: [[1,3],[2,4],[3,6],[4,3],[5,5]]\nExplanation: There are no common ids, so we just include each id with its value in the resulting list."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 200\nnums1[i].length == nums2[j].length == 2\n1 <= idi, vali <= 1000\nBoth arrays contain unique ids.\nBoth arrays are in\u00a0strictly ascending order by id.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Two Pointers"
+        ],
+        "title-slug": "merge-two-2d-arrays-by-summing-values"
+    },
+    {
+        "leetcode-id": 2571,
+        "title": "Minimum Operations to Reduce an Integer to 0",
+        "difficulty": 2,
+        "description": "You are given a positive integer n, you can do the following operation any number of times:\n\nAdd or subtract a power of 2 from n.\n\nReturn the minimum number of operations to make n equal to 0.\nA number x is power of 2 if x == 2^i\u00a0where i >= 0.",
+        "examples": [
+            "Example 1:\nInput: n = 39\nOutput: 3\nExplanation: We can do the following operations:\n- Add 2^0 = 1 to n, so now n = 40.\n- Subtract 2^3 = 8 from n, so now n = 32.\n- Subtract 2^5 = 32 from n, so now n = 0.\nIt can be shown that 3 is the minimum number of operations we need to make n equal to 0.",
+            "Example 2:\nInput: n = 54\nOutput: 3\nExplanation: We can do the following operations:\n- Add 2^1 = 2 to n, so now n = 56.\n- Add 2^3 = 8 to n, so now n = 64.\n- Subtract 2^6 = 64 from n, so now n = 0.\nSo the minimum number of operations is 3."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^5",
+        "tags": [
+            "Dynamic Programming",
+            "Greedy",
+            "Bit Manipulation"
+        ],
+        "title-slug": "minimum-operations-to-reduce-an-integer-to-0"
+    },
+    {
+        "leetcode-id": 2572,
+        "title": "Count the Number of Square-Free Subsets",
+        "difficulty": 2,
+        "description": "You are given a positive integer 0-indexed\u00a0array nums.\nA subset of the array nums is square-free if the product of its elements is a square-free integer.\nA square-free integer is an integer that is divisible by no square number other than 1.\nReturn the number of square-free non-empty subsets of the array nums. Since the answer may be too large, return it modulo 10^9 + 7.\nA non-empty\u00a0subset of nums is an array that can be obtained by deleting some (possibly none but not all) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,4,4,5]\nOutput: 3\nExplanation: There are 3 square-free subsets in this example:\n- The subset consisting of the 0^th element [3]. The product of its elements is 3, which is a square-free integer.\n- The subset consisting of the 3^rd element [5]. The product of its elements is 5, which is a square-free integer.\n- The subset consisting of 0^th and 3^rd elements [3,5]. The product of its elements is 15, which is a square-free integer.\nIt can be proven that there are no more than 3 square-free subsets in the given array.",
+            "Example 2:\nInput: nums = [1]\nOutput: 1\nExplanation: There is 1 square-free subset in this example:\n- The subset consisting of the 0^th element [1]. The product of its elements is 1, which is a square-free integer.\nIt can be proven that there is no more than 1 square-free subset in the given array."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length\u00a0<= 1000\n1 <= nums[i] <= 30",
+        "tags": [
+            "Array",
+            "Math",
+            "Dynamic Programming",
+            "Bit Manipulation",
+            "Bitmask"
+        ],
+        "title-slug": "count-the-number-of-square-free-subsets"
+    },
+    {
+        "leetcode-id": 2573,
+        "title": "Find the String with LCP",
+        "difficulty": 3,
+        "description": "We define the lcp matrix of any 0-indexed string word of n lowercase English letters as an n x n grid such that:\n\nlcp[i][j] is equal to the length of the longest common prefix between the substrings word[i,n-1] and word[j,n-1].\n\nGiven an\u00a0n x n matrix lcp, return the alphabetically smallest string word that corresponds to lcp. If there is no such string, return an empty string.\nA string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b. For example, \"aabd\" is lexicographically smaller than \"aaca\" because the first position they differ is at the third letter, and 'b' comes before 'c'.",
+        "examples": [
+            "Example 1:\nInput: lcp = [[4,0,2,0],[0,3,0,1],[2,0,2,0],[0,1,0,1]]\nOutput: \"abab\"\nExplanation: lcp corresponds to any 4 letter string with two alternating letters. The lexicographically smallest of them is \"abab\".",
+            "Example 2:\nInput: lcp = [[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,1]]\nOutput: \"aaaa\"\nExplanation: lcp corresponds to any 4 letter string with a single distinct letter. The lexicographically smallest of them is \"aaaa\".",
+            "Example 3:\nInput: lcp = [[4,3,2,1],[3,3,2,1],[2,2,2,1],[1,1,1,3]]\nOutput: \"\"\nExplanation: lcp[3][3] cannot be equal to 3 since word[3,...,3] consists of only a single letter; Thus, no answer exists."
+        ],
+        "constraints": "Constraints:\n\n1 <= n ==\u00a0lcp.length == lcp[i].length\u00a0<= 1000\n0 <= lcp[i][j] <= n",
+        "tags": [
+            "Array",
+            "String",
+            "Dynamic Programming",
+            "Greedy",
+            "Union Find",
+            "Matrix"
+        ],
+        "title-slug": "find-the-string-with-lcp"
+    },
+    {
+        "leetcode-id": 2574,
+        "title": "Left and Right Sum Differences",
+        "difficulty": 1,
+        "description": "Given a 0-indexed integer array nums, find a 0-indexed integer array answer where:\n\nanswer.length == nums.length.\nanswer[i] = |leftSum[i] - rightSum[i]|.\n\nWhere:\n\nleftSum[i] is the sum of elements to the left of the index i in the array nums. If there is no such element, leftSum[i] = 0.\nrightSum[i] is the sum of elements to the right of the index i in the array nums. If there is no such element, rightSum[i] = 0.\n\nReturn the array answer.",
+        "examples": [
+            "Example 1:\nInput: nums = [10,4,8,3]\nOutput: [15,1,11,22]\nExplanation: The array leftSum is [0,10,14,22] and the array rightSum is [15,11,3,0].\nThe array answer is [|0 - 15|,|10 - 11|,|14 - 3|,|22 - 0|] = [15,1,11,22].",
+            "Example 2:\nInput: nums = [1]\nOutput: [0]\nExplanation: The array leftSum is [0] and the array rightSum is [0].\nThe array answer is [|0 - 0|] = [0]."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Prefix Sum"
+        ],
+        "title-slug": "left-and-right-sum-differences"
+    },
+    {
+        "leetcode-id": 2575,
+        "title": "Find the Divisibility Array of a String",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed string word of length n\u00a0consisting of digits, and a positive integer\u00a0m.\nThe divisibility array div of word is an integer array of length n such that:\n\ndiv[i] = 1 if the\u00a0numeric value\u00a0of\u00a0word[0,...,i] is divisible by m, or\ndiv[i] = 0 otherwise.\n\nReturn the divisibility array of word.",
+        "examples": [
+            "Example 1:\nInput: word = \"998244353\", m = 3\nOutput: [1,1,0,0,0,1,1,0,0]\nExplanation: There are only 4 prefixes that are divisible by 3: \"9\", \"99\", \"998244\", and \"9982443\".",
+            "Example 2:\nInput: word = \"1010\", m = 10\nOutput: [0,1,0,1]\nExplanation: There are only 2 prefixes that are divisible by 10: \"10\", and \"1010\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^5\nword.length == n\nword consists of digits from 0\u00a0to 9\n1 <= m <= 10^9",
+        "tags": [
+            "Array",
+            "Math",
+            "String"
+        ],
+        "title-slug": "find-the-divisibility-array-of-a-string"
+    },
+    {
+        "leetcode-id": 2576,
+        "title": "Find the Maximum Number of Marked Indices",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums.\nInitially, all of the indices are unmarked. You are allowed to make this operation any number of times:\n\nPick two different unmarked indices i and j such that 2 * nums[i] <= nums[j], then mark i and j.\n\nReturn the maximum possible number of marked indices in nums using the above operation any number of times.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,5,2,4]\nOutput: 2\nExplanation: In the first operation: pick i = 2 and j = 1, the operation is allowed because 2 * nums[2] <= nums[1]. Then mark index 2 and 1.\nIt can be shown that there's no other valid operation so the answer is 2.",
+            "Example 2:\nInput: nums = [9,2,5,4]\nOutput: 4\nExplanation: In the first operation: pick i = 3 and j = 0, the operation is allowed because 2 * nums[3] <= nums[0]. Then mark index 3 and 0.\nIn the second operation: pick i = 1 and j = 2, the operation is allowed because 2 * nums[1] <= nums[2]. Then mark index 1 and 2.\nSince there is no other operation, the answer is 4.",
+            "Example 3:\nInput: nums = [7,6,8]\nOutput: 0\nExplanation: There is no valid operation to do, so the answer is 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\n\n\u00a0\n.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0; \n}\n.spoiler {overflow:hidden;}\n.spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;}\n.spoilerbutton[value=\"Show Message\"] + .spoiler > div {margin-top:-500%;}\n.spoilerbutton[value=\"Hide Message\"] + .spoiler {padding:5px;}",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Binary Search",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "find-the-maximum-number-of-marked-indices"
+    },
+    {
+        "leetcode-id": 2577,
+        "title": "Minimum Time to Visit a Cell In a Grid",
+        "difficulty": 3,
+        "description": "You are given a m x n matrix grid consisting of non-negative integers where grid[row][col] represents the minimum time required to be able to visit the cell (row, col), which means you can visit the cell (row, col) only when the time you visit it is greater than or equal to grid[row][col].\nYou are standing in the top-left cell of the matrix in the 0^th second, and you must move to any adjacent cell in the four directions: up, down, left, and right. Each move you make takes 1 second.\nReturn the minimum time required in which you can visit the bottom-right cell of the matrix. If you cannot visit the bottom-right cell, then return -1.",
+        "examples": [
+            "Example 1:\nInput: grid = [[0,1,3,2],[5,1,2,5],[4,3,8,6]]\nOutput: 7\nExplanation: One of the paths that we can take is the following:\n- at t = 0, we are on the cell (0,0).\n- at t = 1, we move to the cell (0,1). It is possible because grid[0][1] <= 1.\n- at t = 2, we move to the cell (1,1). It is possible because grid[1][1] <= 2.\n- at t = 3, we move to the cell (1,2). It is possible because grid[1][2] <= 3.\n- at t = 4, we move to the cell (1,1). It is possible because grid[1][1] <= 4.\n- at t = 5, we move to the cell (1,2). It is possible because grid[1][2] <= 5.\n- at t = 6, we move to the cell (1,3). It is possible because grid[1][3] <= 6.\n- at t = 7, we move to the cell (2,3). It is possible because grid[2][3] <= 7.\nThe final time is 7. It can be shown that it is the minimum time possible.",
+            "Example 2:\nInput: grid = [[0,2,4],[3,2,1],[1,0,4]]\nOutput: -1\nExplanation: There is no path from the top left to the bottom-right cell."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n2 <= m, n <= 1000\n4 <= m * n <= 10^5\n0 <= grid[i][j] <= 10^5\ngrid[0][0] == 0\n\n\u00a0\n.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0; \n}\n.spoiler {overflow:hidden;}\n.spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;}\n.spoilerbutton[value=\"Show Message\"] + .spoiler > div {margin-top:-500%;}\n.spoilerbutton[value=\"Hide Message\"] + .spoiler {padding:5px;}",
+        "tags": [
+            "Array",
+            "Breadth-First Search",
+            "Graph",
+            "Heap (Priority Queue)",
+            "Matrix",
+            "Shortest Path"
+        ],
+        "title-slug": "minimum-time-to-visit-a-cell-in-a-grid"
+    },
+    {
+        "leetcode-id": 2578,
+        "title": "Split With Minimum Sum",
+        "difficulty": 1,
+        "description": "Given a positive integer num, split it into two non-negative integers num1 and num2 such that:\n\nThe concatenation of num1 and num2 is a permutation of num.\n\n\t\nIn other words, the sum of the number of occurrences of each digit in num1 and num2 is equal to the number of occurrences of that digit in num.\n\n\nnum1 and num2 can contain leading zeros.\n\nReturn the minimum possible sum of num1 and num2.\nNotes:\n\nIt is guaranteed that num does not contain any leading zeros.\nThe order of occurrence of the digits in num1 and num2 may differ from the order of occurrence of num.",
+        "examples": [
+            "Example 1:\nInput: num = 4325\nOutput: 59\nExplanation: We can split 4325 so that num1 is 24 and num2 is 35, giving a sum of 59. We can prove that 59 is indeed the minimal possible sum.",
+            "Example 2:\nInput: num = 687\nOutput: 75\nExplanation: We can split 687 so that num1 is 68 and num2 is 7, which would give an optimal sum of 75."
+        ],
+        "constraints": "Constraints:\n\n10 <= num <= 10^9",
+        "tags": [
+            "Math",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "split-with-minimum-sum"
+    },
+    {
+        "leetcode-id": 2579,
+        "title": "Count Total Number of Colored Cells",
+        "difficulty": 2,
+        "description": "There exists an infinitely large two-dimensional grid of uncolored unit cells. You are given a positive integer n, indicating that you must do the following routine for n minutes:\n\nAt the first minute, color any arbitrary unit cell blue.\nEvery minute thereafter, color blue every uncolored cell that touches a blue cell.\n\nBelow is a pictorial representation of the state of the grid after minutes 1, 2, and 3.\n\nReturn the number of colored cells at the end of n minutes.",
+        "examples": [
+            "Example 1:\nInput: n = 1\nOutput: 1\nExplanation: After 1 minute, there is only 1 blue cell, so we return 1.",
+            "Example 2:\nInput: n = 2\nOutput: 5\nExplanation: After 2 minutes, there are 4 colored cells on the boundary and 1 in the center, so we return 5."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^5",
+        "tags": [
+            "Math"
+        ],
+        "title-slug": "count-total-number-of-colored-cells"
+    },
+    {
+        "leetcode-id": 2580,
+        "title": "Count Ways to Group Overlapping Ranges",
+        "difficulty": 2,
+        "description": "You are given a 2D integer array ranges where ranges[i] = [starti, endi] denotes that all integers between starti and endi (both inclusive) are contained in the i^th range.\nYou are to split ranges into two (possibly empty) groups such that:\n\nEach range belongs to exactly one group.\nAny two overlapping ranges must belong to the same group.\n\nTwo ranges are said to be overlapping\u00a0if there exists at least one integer that is present in both ranges.\n\nFor example, [1, 3] and [2, 5] are overlapping because 2 and 3 occur in both ranges.\n\nReturn the total number of ways to split ranges into two groups. Since the answer may be very large, return it modulo 10^9 + 7.",
+        "examples": [
+            "Example 1:\nInput: ranges = [[6,10],[5,15]]\nOutput: 2\nExplanation: \nThe two ranges are overlapping, so they must be in the same group.\nThus, there are two possible ways:\n- Put both the ranges together in group 1.\n- Put both the ranges together in group 2.",
+            "Example 2:\nInput: ranges = [[1,3],[10,20],[2,5],[4,8]]\nOutput: 4\nExplanation: \nRanges [1,3], and [2,5] are overlapping. So, they must be in the same group.\nAgain, ranges [2,5] and [4,8] are also overlapping. So, they must also be in the same group. \nThus, there are four possible ways to group them:\n- All the ranges in group 1.\n- All the ranges in group 2.\n- Ranges [1,3], [2,5], and [4,8] in group 1 and [10,20] in group 2.\n- Ranges [1,3], [2,5], and [4,8] in group 2 and [10,20] in group 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= ranges.length <= 10^5\nranges[i].length == 2\n0 <= starti <= endi <= 10^9",
+        "tags": [
+            "Array",
+            "Sorting"
+        ],
+        "title-slug": "count-ways-to-group-overlapping-ranges"
+    },
+    {
+        "leetcode-id": 2581,
+        "title": "Count Number of Possible Root Nodes",
+        "difficulty": 3,
+        "description": "Alice has an undirected tree with n nodes labeled from 0 to n - 1. The tree is represented as a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\nAlice wants Bob to find the root of the tree. She allows Bob to make several guesses about her tree. In one guess, he does the following:\n\nChooses two distinct integers u and v such that there exists an edge [u, v] in the tree.\nHe tells Alice that u is the parent of v in the tree.\n\nBob's guesses are represented by a 2D integer array guesses where guesses[j] = [uj, vj] indicates Bob guessed uj to be the parent of vj.\nAlice being lazy, does not reply to each of Bob's guesses, but just says that at least k of his guesses are true.\nGiven the 2D integer arrays edges, guesses and the integer k, return the number of possible nodes that can be the root of Alice's tree. If there is no such tree, return 0.",
+        "examples": [
+            "Example 1:\nInput: edges = [[0,1],[1,2],[1,3],[4,2]], guesses = [[1,3],[0,1],[1,0],[2,4]], k = 3\nOutput: 3\nExplanation: \nRoot = 0, correct guesses = [1,3], [0,1], [2,4]\nRoot = 1, correct guesses = [1,3], [1,0], [2,4]\nRoot = 2, correct guesses = [1,3], [1,0], [2,4]\nRoot = 3, correct guesses = [1,0], [2,4]\nRoot = 4, correct guesses = [1,3], [1,0]\nConsidering 0, 1, or 2 as root node leads to 3 correct guesses.",
+            "Example 2:\nInput: edges = [[0,1],[1,2],[2,3],[3,4]], guesses = [[1,0],[3,4],[2,1],[3,2]], k = 1\nOutput: 5\nExplanation: \nRoot = 0, correct guesses = [3,4]\nRoot = 1, correct guesses = [1,0], [3,4]\nRoot = 2, correct guesses = [1,0], [2,1], [3,4]\nRoot = 3, correct guesses = [1,0], [2,1], [3,2], [3,4]\nRoot = 4, correct guesses = [1,0], [2,1], [3,2]\nConsidering any node as root will give at least 1 correct guess."
+        ],
+        "constraints": "Constraints:\n\nedges.length == n - 1\n2 <= n <= 10^5\n1 <= guesses.length <= 10^5\n0 <= ai, bi, uj, vj <= n - 1\nai != bi\nuj != vj\nedges represents a valid tree.\nguesses[j] is an edge of the tree.\nguesses is unique.\n0 <= k <= guesses.length",
+        "tags": [
+            "Hash Table",
+            "Dynamic Programming",
+            "Tree",
+            "Depth-First Search"
+        ],
+        "title-slug": "count-number-of-possible-root-nodes"
+    },
+    {
+        "leetcode-id": 2582,
+        "title": "Pass the Pillow",
+        "difficulty": 1,
+        "description": "There are n people standing in a line labeled from 1 to n. The first person in the line is holding a pillow initially. Every second, the person holding the pillow passes it to the next person standing in the line. Once the pillow reaches the end of the line, the direction changes, and people continue passing the pillow in the opposite direction.\n\nFor example, once the pillow reaches the n^th person they pass it to the n - 1^th person, then to the n - 2^th person and so on.\n\nGiven the two positive integers n and time, return the index of the person holding the pillow after time seconds.",
+        "examples": [
+            "Example 1:\nInput: n = 4, time = 5\nOutput: 2\nExplanation: People pass the pillow in the following way: 1 -> 2 -> 3 -> 4 -> 3 -> 2.\nAfer five seconds, the pillow is given to the 2^nd person.",
+            "Example 2:\nInput: n = 3, time = 2\nOutput: 3\nExplanation: People pass the pillow in the following way: 1 -> 2 -> 3.\nAfer two seconds, the pillow is given to the 3^r^d person."
+        ],
+        "constraints": "Constraints:\n\n2 <= n <= 1000\n1 <= time <= 1000",
+        "tags": [
+            "Math",
+            "Simulation"
+        ],
+        "title-slug": "pass-the-pillow"
+    },
+    {
+        "leetcode-id": 2583,
+        "title": "Kth Largest Sum in a Binary Tree",
+        "difficulty": 2,
+        "description": "You are given the root of a binary tree and a positive integer k.\nThe level sum in the tree is the sum of the values of the nodes that are on the same level.\nReturn the k^th largest level sum in the tree (not necessarily distinct). If there are fewer than k levels in the tree, return -1.\nNote that two nodes are on the same level if they have the same distance from the root.",
+        "examples": [
+            "Example 1:\nInput: root = [5,8,9,2,1,3,7,4,6], k = 2\nOutput: 13\nExplanation: The level sums are the following:\n- Level 1: 5.\n- Level 2: 8 + 9 = 17.\n- Level 3: 2 + 1 + 3 + 7 = 13.\n- Level 4: 4 + 6 = 10.\nThe 2^nd largest level sum is 13.",
+            "Example 2:\nInput: root = [1,2,null,3], k = 1\nOutput: 3\nExplanation: The largest level sum is 3."
+        ],
+        "constraints": "Constraints:\n\nThe number of nodes in the tree is n.\n2 <= n <= 10^5\n1 <= Node.val <= 10^6\n1 <= k <= n",
+        "tags": [
+            "Binary Search",
+            "Tree",
+            "Breadth-First Search"
+        ],
+        "title-slug": "kth-largest-sum-in-a-binary-tree"
+    },
+    {
+        "leetcode-id": 2584,
+        "title": "Split the Array to Make Coprime Products",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed integer array nums of length n.\nA split at an index i where 0 <= i <= n - 2 is called valid if the product of the first i + 1 elements and the product of the remaining elements are coprime.\n\nFor example, if nums = [2, 3, 3], then a split at the index i = 0 is valid because 2 and 9 are coprime, while a split at the index i = 1 is not valid because 6 and 3 are not coprime. A split at the index i = 2 is not valid because i == n - 1.\n\nReturn the smallest index i at which the array can be split validly or -1 if there is no such split.\nTwo values val1 and val2 are coprime if gcd(val1, val2) == 1 where gcd(val1, val2) is the greatest common divisor of val1 and val2.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,7,8,15,3,5]\nOutput: 2\nExplanation: The table above shows the values of the product of the first i + 1 elements, the remaining elements, and their gcd at each index i.\nThe only valid split is at index 2.",
+            "Example 2:\nInput: nums = [4,7,15,8,3,5]\nOutput: -1\nExplanation: The table above shows the values of the product of the first i + 1 elements, the remaining elements, and their gcd at each index i.\nThere is no valid split."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length\n1 <= n <= 10^4\n1 <= nums[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Math",
+            "Number Theory"
+        ],
+        "title-slug": "split-the-array-to-make-coprime-products"
+    },
+    {
+        "leetcode-id": 2585,
+        "title": "Number of Ways to Earn Points",
+        "difficulty": 3,
+        "description": "There is a test that has n types of questions. You are given an integer target and a 0-indexed 2D integer array types where types[i] = [counti, marksi] indicates that there are counti questions of the i^th type, and each one of them is worth marksi points.\n\n\nReturn the number of ways you can earn exactly target points in the exam. Since the answer may be too large, return it modulo 10^9 + 7.\nNote that questions of the same type are indistinguishable.\n\nFor example, if there are 3 questions of the same type, then solving the 1^st and 2^nd questions is the same as solving the 1^st and 3^rd questions, or the 2^nd and 3^rd questions.",
+        "examples": [
+            "Example 1:\nInput: target = 6, types = [[6,1],[3,2],[2,3]]\nOutput: 7\nExplanation: You can earn 6 points in one of the seven ways:\n- Solve 6 questions of the 0^th type: 1 + 1 + 1 + 1 + 1 + 1 = 6\n- Solve 4 questions of the 0^th type and 1 question of the 1^st type: 1 + 1 + 1 + 1 + 2 = 6\n- Solve 2 questions of the 0^th type and 2 questions of the 1^st type: 1 + 1 + 2 + 2 = 6\n- Solve 3 questions of the 0^th type and 1 question of the 2^nd type: 1 + 1 + 1 + 3 = 6\n- Solve 1 question of the 0^th type, 1 question of the 1^st type and 1 question of the 2^nd type: 1 + 2 + 3 = 6\n- Solve 3 questions of the 1^st type: 2 + 2 + 2 = 6\n- Solve 2 questions of the 2^nd type: 3 + 3 = 6",
+            "Example 2:\nInput: target = 5, types = [[50,1],[50,2],[50,5]]\nOutput: 4\nExplanation: You can earn 5 points in one of the four ways:\n- Solve 5 questions of the 0^th type: 1 + 1 + 1 + 1 + 1 = 5\n- Solve 3 questions of the 0^th type and 1 question of the 1^st type: 1 + 1 + 1 + 2 = 5\n- Solve 1 questions of the 0^th type and 2 questions of the 1^st type: 1 + 2 + 2 = 5\n- Solve 1 question of the 2^nd type: 5",
+            "Example 3:\nInput: target = 18, types = [[6,1],[3,2],[2,3]]\nOutput: 1\nExplanation: You can only earn 18 points by answering all questions."
+        ],
+        "constraints": "Constraints:\n\n1 <= target <= 1000\nn == types.length\n1 <= n <= 50\ntypes[i].length == 2\n1 <= counti, marksi <= 50",
+        "tags": [
+            "Array",
+            "Dynamic Programming"
+        ],
+        "title-slug": "number-of-ways-to-earn-points"
+    },
+    {
+        "leetcode-id": 2586,
+        "title": "Count the Number of Vowel Strings in Range",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed array of string words and two integers left and right.\nA string is called a vowel string if it starts with a vowel character and ends with a vowel character where vowel characters are 'a', 'e', 'i', 'o', and 'u'.\nReturn the number of vowel strings words[i] where i belongs to the inclusive range [left, right].",
+        "examples": [
+            "Example 1:\nInput: words = [\"are\",\"amy\",\"u\"], left = 0, right = 2\nOutput: 2\nExplanation: \n- \"are\" is a vowel string because it starts with 'a' and ends with 'e'.\n- \"amy\" is not a vowel string because it does not end with a vowel.\n- \"u\" is a vowel string because it starts with 'u' and ends with 'u'.\nThe number of vowel strings in the mentioned range is 2.",
+            "Example 2:\nInput: words = [\"hey\",\"aeo\",\"mu\",\"ooo\",\"artro\"], left = 1, right = 4\nOutput: 3\nExplanation: \n- \"aeo\" is a vowel string because it starts with 'a' and ends with 'o'.\n- \"mu\" is not a vowel string because it does not start with a vowel.\n- \"ooo\" is a vowel string because it starts with 'o' and ends with 'o'.\n- \"artro\" is a vowel string because it starts with 'a' and ends with 'o'.\nThe number of vowel strings in the mentioned range is 3."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 1000\n1 <= words[i].length <= 10\nwords[i] consists of only lowercase English letters.\n0 <= left <= right < words.length",
+        "tags": [
+            "Array",
+            "String"
+        ],
+        "title-slug": "count-the-number-of-vowel-strings-in-range"
+    },
+    {
+        "leetcode-id": 2587,
+        "title": "Rearrange Array to Maximize Prefix Score",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums. You can rearrange the elements of nums to any order (including the given order).\nLet prefix be the array containing the prefix sums of nums after rearranging it. In other words, prefix[i] is the sum of the elements from 0 to i in nums after rearranging it. The score of nums is the number of positive integers in the array prefix.\nReturn the maximum score you can achieve.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,-1,0,1,-3,3,-3]\nOutput: 6\nExplanation: We can rearrange the array into nums = [2,3,1,-1,-3,0,-3].\nprefix = [2,5,6,5,2,2,-1], so the score is 6.\nIt can be shown that 6 is the maximum score we can obtain.",
+            "Example 2:\nInput: nums = [-2,-3,0]\nOutput: 0\nExplanation: Any rearrangement of the array will result in a score of 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^6 <= nums[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Sorting",
+            "Prefix Sum"
+        ],
+        "title-slug": "rearrange-array-to-maximize-prefix-score"
+    },
+    {
+        "leetcode-id": 2588,
+        "title": "Count the Number of Beautiful Subarrays",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums. In one operation, you can:\n\nChoose two different indices i and j such that 0 <= i, j < nums.length.\nChoose a non-negative integer k such that the k^th bit (0-indexed) in the binary representation of nums[i] and nums[j] is 1.\nSubtract 2^k from nums[i] and nums[j].\n\nA subarray is beautiful if it is possible to make all of its elements equal to 0 after applying the above operation any number of times.\nReturn the number of beautiful subarrays in the array nums.\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,3,1,2,4]\nOutput: 2\nExplanation: There are 2 beautiful subarrays in nums: [4,3,1,2,4] and [4,3,1,2,4].\n- We can make all elements in the subarray [3,1,2] equal to 0 in the following way:\n  - Choose [3, 1, 2] and k = 1. Subtract 2^1 from both numbers. The subarray becomes [1, 1, 0].\n  - Choose [1, 1, 0] and k = 0. Subtract 2^0 from both numbers. The subarray becomes [0, 0, 0].\n- We can make all elements in the subarray [4,3,1,2,4] equal to 0 in the following way:\n  - Choose [4, 3, 1, 2, 4] and k = 2. Subtract 2^2 from both numbers. The subarray becomes [0, 3, 1, 2, 0].\n  - Choose [0, 3, 1, 2, 0] and k = 0. Subtract 2^0 from both numbers. The subarray becomes [0, 2, 0, 2, 0].\n  - Choose [0, 2, 0, 2, 0] and k = 1. Subtract 2^1 from both numbers. The subarray becomes [0, 0, 0, 0, 0].",
+            "Example 2:\nInput: nums = [1,10,4]\nOutput: 0\nExplanation: There are no beautiful subarrays in nums."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Bit Manipulation",
+            "Prefix Sum"
+        ],
+        "title-slug": "count-the-number-of-beautiful-subarrays"
+    },
+    {
+        "leetcode-id": 2589,
+        "title": "Minimum Time to Complete All Tasks",
+        "difficulty": 3,
+        "description": "There is a computer that can run an unlimited number of tasks at the same time. You are given a 2D integer array tasks where tasks[i] = [starti, endi, durationi] indicates that the i^th task should run for a total of durationi seconds (not necessarily continuous) within the inclusive time range [starti, endi].\nYou may turn on the computer only when it needs to run a task. You can also turn it off if it is idle.\nReturn the minimum time during which the computer should be turned on to complete all tasks.",
+        "examples": [
+            "Example 1:\nInput: tasks = [[2,3,1],[4,5,1],[1,5,2]]\nOutput: 2\nExplanation: \n- The first task can be run in the inclusive time range [2, 2].\n- The second task can be run in the inclusive time range [5, 5].\n- The third task can be run in the two inclusive time ranges [2, 2] and [5, 5].\nThe computer will be on for a total of 2 seconds.",
+            "Example 2:\nInput: tasks = [[1,3,2],[2,5,3],[5,6,2]]\nOutput: 4\nExplanation: \n- The first task can be run in the inclusive time range [2, 3].\n- The second task can be run in the inclusive time ranges [2, 3] and [5, 5].\n- The third task can be run in the two inclusive time range [5, 6].\nThe computer will be on for a total of 4 seconds."
+        ],
+        "constraints": "Constraints:\n\n1 <= tasks.length <= 2000\ntasks[i].length == 3\n1 <= starti, endi <= 2000\n1 <= durationi <= endi - starti + 1",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Stack",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "minimum-time-to-complete-all-tasks"
+    },
+    {
+        "leetcode-id": 2591,
+        "title": "Distribute Money to Maximum Children",
+        "difficulty": 1,
+        "description": "You are given an integer money denoting the amount of money (in dollars) that you have and another integer children denoting the number of children that you must distribute the money to.\nYou have to distribute the money according to the following rules:\n\nAll money must be distributed.\nEveryone must receive at least 1 dollar.\nNobody receives 4 dollars.\n\nReturn the maximum number of children who may receive exactly 8 dollars if you distribute the money according to the aforementioned rules. If there is no way to distribute the money, return -1.",
+        "examples": [
+            "Example 1:\nInput: money = 20, children = 3\nOutput: 1\nExplanation: \nThe maximum number of children with 8 dollars will be 1. One of the ways to distribute the money is:\n- 8 dollars to the first child.\n- 9 dollars to the second child. \n- 3 dollars to the third child.\nIt can be proven that no distribution exists such that number of children getting 8 dollars is greater than 1.",
+            "Example 2:\nInput: money = 16, children = 2\nOutput: 2\nExplanation: Each child can be given 8 dollars."
+        ],
+        "constraints": "Constraints:\n\n1 <= money <= 200\n2 <= children <= 30",
+        "tags": [
+            "Math",
+            "Greedy"
+        ],
+        "title-slug": "distribute-money-to-maximum-children"
+    },
+    {
+        "leetcode-id": 2592,
+        "title": "Maximize Greatness of an Array",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums. You are allowed to permute nums into a new array perm of your choosing.\nWe define the greatness of nums be the number of indices 0 <= i < nums.length for which perm[i] > nums[i].\nReturn the maximum possible greatness you can achieve after permuting nums.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,5,2,1,3,1]\nOutput: 4\nExplanation: One of the optimal rearrangements is perm = [2,5,1,3,3,1,1].\nAt indices = 0, 1, 3, and 4, perm[i] > nums[i]. Hence, we return 4.",
+            "Example 2:\nInput: nums = [1,2,3,4]\nOutput: 3\nExplanation: We can prove the optimal perm is [2,3,4,1].\nAt indices = 0, 1, and 2, perm[i] > nums[i]. Hence, we return 3."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "maximize-greatness-of-an-array"
+    },
+    {
+        "leetcode-id": 2593,
+        "title": "Find Score of an Array After Marking All Elements",
+        "difficulty": 2,
+        "description": "You are given an array nums consisting of positive integers.\nStarting with score = 0, apply the following algorithm:\n\nChoose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest index.\nAdd the value of the chosen integer to score.\nMark the chosen element and its two adjacent elements if they exist.\nRepeat until all the array elements are marked.\n\nReturn the score you get after applying the above algorithm.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,1,3,4,5,2]\nOutput: 7\nExplanation: We mark the elements as follows:\n- 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,1,3,4,5,2].\n- 2 is the smallest unmarked element, so we mark it and its left adjacent element: [2,1,3,4,5,2].\n- 4 is the only remaining unmarked element, so we mark it: [2,1,3,4,5,2].\nOur score is 1 + 2 + 4 = 7.",
+            "Example 2:\nInput: nums = [2,3,5,1,3,2]\nOutput: 5\nExplanation: We mark the elements as follows:\n- 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,3,5,1,3,2].\n- 2 is the smallest unmarked element, since there are two of them, we choose the left-most one, so we mark the one at index 0 and its right adjacent element: [2,3,5,1,3,2].\n- 2 is the only remaining unmarked element, so we mark it: [2,3,5,1,3,2].\nOur score is 1 + 2 + 2 = 5."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Sorting",
+            "Heap (Priority Queue)",
+            "Simulation"
+        ],
+        "title-slug": "find-score-of-an-array-after-marking-all-elements"
+    },
+    {
+        "leetcode-id": 2594,
+        "title": "Minimum Time to Repair Cars",
+        "difficulty": 2,
+        "description": "You are given an integer array ranks representing the ranks of some mechanics. ranksi is the rank of the i^th mechanic. A mechanic with a rank r can repair n cars in r * n^2 minutes.\nYou are also given an integer cars representing the total number of cars waiting in the garage to be repaired.\nReturn the minimum time taken to repair all the cars.\nNote: All the mechanics can repair the cars simultaneously.",
+        "examples": [
+            "Example 1:\nInput: ranks = [4,2,3,1], cars = 10\nOutput: 16\nExplanation: \n- The first mechanic will repair two cars. The time required is 4 * 2 * 2 = 16 minutes.\n- The second mechanic will repair two cars. The time required is 2 * 2 * 2 = 8 minutes.\n- The third mechanic will repair two cars. The time required is 3 * 2 * 2 = 12 minutes.\n- The fourth mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.\nIt can be proved that the cars cannot be repaired in less than 16 minutes.\u200b\u200b\u200b\u200b\u200b",
+            "Example 2:\nInput: ranks = [5,1,8], cars = 6\nOutput: 16\nExplanation: \n- The first mechanic will repair one car. The time required is 5 * 1 * 1 = 5 minutes.\n- The second mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.\n- The third mechanic will repair one car. The time required is 8 * 1 * 1 = 8 minutes.\nIt can be proved that the cars cannot be repaired in less than 16 minutes.\u200b\u200b\u200b\u200b\u200b"
+        ],
+        "constraints": "Constraints:\n\n1 <= ranks.length <= 10^5\n1 <= ranks[i] <= 100\n1 <= cars <= 10^6",
+        "tags": [
+            "Array",
+            "Binary Search"
+        ],
+        "title-slug": "minimum-time-to-repair-cars"
+    },
+    {
+        "leetcode-id": 2595,
+        "title": "Number of Even and Odd Bits",
+        "difficulty": 1,
+        "description": "You are given a positive integer n.\nLet even denote the number of even indices in the binary representation of n (0-indexed) with value 1.\nLet odd denote the number of odd indices in the binary representation of n (0-indexed) with value 1.\nReturn an integer array answer where answer = [even, odd].",
+        "examples": [
+            "Example 1:\nInput: n = 17\nOutput: [2,0]\nExplanation: The binary representation of 17 is 10001. \nIt contains 1 on the 0^th and 4^th indices. \nThere are 2 even and 0 odd indices.",
+            "Example 2:\nInput: n = 2\nOutput: [0,1]\nExplanation: The binary representation of 2 is 10.\nIt contains 1 on the 1^st index. \nThere are 0 even and 1 odd indices."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 1000",
+        "tags": [
+            "Bit Manipulation"
+        ],
+        "title-slug": "number-of-even-and-odd-bits"
+    },
+    {
+        "leetcode-id": 2596,
+        "title": "Check Knight Tour Configuration",
+        "difficulty": 2,
+        "description": "There is a knight on an n x n chessboard. In a valid configuration, the knight starts at the top-left cell of the board and visits every cell on the board exactly once.\nYou are given an n x n integer matrix grid consisting of distinct integers from the range [0, n * n - 1] where grid[row][col] indicates that the cell (row, col) is the grid[row][col]^th cell that the knight visited. The moves are 0-indexed.\nReturn true if grid represents a valid configuration of the knight's movements or false otherwise.\nNote that a valid knight move consists of moving two squares vertically and one square horizontally, or two squares horizontally and one square vertically. The figure below illustrates all the possible eight moves of a knight from some cell.",
+        "examples": [
+            "Example 1:\nInput: grid = [[0,11,16,5,20],[17,4,19,10,15],[12,1,8,21,6],[3,18,23,14,9],[24,13,2,7,22]]\nOutput: true\nExplanation: The above diagram represents the grid. It can be shown that it is a valid configuration.",
+            "Example 2:\nInput: grid = [[0,3,6],[5,8,1],[2,7,4]]\nOutput: false\nExplanation: The above diagram represents the grid. The 8^th move of the knight is not valid considering its position after the 7^th move."
+        ],
+        "constraints": "Constraints:\n\nn == grid.length == grid[i].length\n3 <= n <= 7\n0 <= grid[row][col] < n * n\nAll integers in grid are unique.",
+        "tags": [
+            "Array",
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Matrix",
+            "Simulation"
+        ],
+        "title-slug": "check-knight-tour-configuration"
+    },
+    {
+        "leetcode-id": 2597,
+        "title": "The Number of Beautiful Subsets",
+        "difficulty": 2,
+        "description": "You are given an array nums of positive integers and a positive integer k.\nA subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k.\nReturn the number of non-empty beautiful subsets of the array nums.\nA subset of nums is an array that can be obtained by deleting some (possibly none) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,4,6], k = 2\nOutput: 4\nExplanation: The beautiful subsets of the array nums are: [2], [4], [6], [2, 6].\nIt can be proved that there are only 4 beautiful subsets in the array [2,4,6].",
+            "Example 2:\nInput: nums = [1], k = 1\nOutput: 1\nExplanation: The beautiful subset of the array nums is [1].\nIt can be proved that there is only 1 beautiful subset in the array [1]."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 20\n1 <= nums[i], k <= 1000",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Backtracking"
+        ],
+        "title-slug": "the-number-of-beautiful-subsets"
+    },
+    {
+        "leetcode-id": 2598,
+        "title": "Smallest Missing Non-negative Integer After Operations",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums and an integer value.\nIn one operation, you can add or subtract value from any element of nums.\n\nFor example, if nums = [1,2,3] and value = 2, you can choose to subtract value from nums[0] to make nums = [-1,2,3].\n\nThe MEX (minimum excluded) of an array is the smallest missing non-negative integer in it.\n\nFor example, the MEX of [-1,2,3] is 0 while the MEX of [1,0,3] is 2.\n\nReturn the maximum MEX of nums after applying the mentioned operation any number of times.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,-10,7,13,6,8], value = 5\nOutput: 4\nExplanation: One can achieve this result by applying the following operations:\n- Add value to nums[1] twice to make nums = [1,0,7,13,6,8]\n- Subtract value from nums[2] once to make nums = [1,0,2,13,6,8]\n- Subtract value from nums[3] twice to make nums = [1,0,2,3,6,8]\nThe MEX of nums is 4. It can be shown that 4 is the maximum MEX we can achieve.",
+            "Example 2:\nInput: nums = [1,-10,7,13,6,8], value = 7\nOutput: 2\nExplanation: One can achieve this result by applying the following operation:\n- subtract value from nums[2] once to make nums = [1,-10,0,13,6,8]\nThe MEX of nums is 2. It can be shown that 2 is the maximum MEX we can achieve."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length, value <= 10^5\n-10^9 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Math",
+            "Greedy"
+        ],
+        "title-slug": "smallest-missing-non-negative-integer-after-operations"
+    },
+    {
+        "leetcode-id": 2600,
+        "title": "K Items With the Maximum Sum",
+        "difficulty": 1,
+        "description": "There is a bag that consists of items, each item\u00a0has a number 1, 0, or -1 written on it.\nYou are given four non-negative integers numOnes, numZeros, numNegOnes, and k.\nThe bag initially contains:\n\nnumOnes items with 1s written on them.\nnumZeroes items with 0s written on them.\nnumNegOnes items with -1s written on them.\n\nWe want to pick exactly k items among the available items. Return the maximum possible sum of numbers written on the items.",
+        "examples": [
+            "Example 1:\nInput: numOnes = 3, numZeros = 2, numNegOnes = 0, k = 2\nOutput: 2\nExplanation: We have a bag of items with numbers written on them {1, 1, 1, 0, 0}. We take 2 items with 1 written on them and get a sum in a total of 2.\nIt can be proven that 2 is the maximum possible sum.",
+            "Example 2:\nInput: numOnes = 3, numZeros = 2, numNegOnes = 0, k = 4\nOutput: 3\nExplanation: We have a bag of items with numbers written on them {1, 1, 1, 0, 0}. We take 3 items with 1 written on them, and 1 item with 0 written on it, and get a sum in a total of 3.\nIt can be proven that 3 is the maximum possible sum."
+        ],
+        "constraints": "Constraints:\n\n0 <= numOnes, numZeros, numNegOnes <= 50\n0 <= k <= numOnes + numZeros + numNegOnes",
+        "tags": [
+            "Math",
+            "Greedy"
+        ],
+        "title-slug": "k-items-with-the-maximum-sum"
+    },
+    {
+        "leetcode-id": 2601,
+        "title": "Prime Subtraction Operation",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums of length n.\nYou can perform the following operation as many times as you want:\n\nPick an index i that you haven\u2019t picked before, and pick a prime p strictly less than nums[i], then subtract p from nums[i].\n\nReturn true if you can make nums a strictly increasing array using the above operation and false otherwise.\nA strictly increasing array is an array whose each element is strictly greater than its preceding element.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,9,6,10]\nOutput: true\nExplanation: In the first operation: Pick i = 0 and p = 3, and then subtract 3 from nums[0], so that nums becomes [1,9,6,10].\nIn the second operation: i = 1, p = 7, subtract 7 from nums[1], so nums becomes equal to [1,2,6,10].\nAfter the second operation, nums is sorted in strictly increasing order, so the answer is true.",
+            "Example 2:\nInput: nums = [6,8,11,12]\nOutput: true\nExplanation: Initially nums is sorted in strictly increasing order, so we don't need to make any operations.",
+            "Example 3:\nInput: nums = [5,8,3]\nOutput: false\nExplanation: It can be proven that there is no way to perform operations to make nums sorted in strictly increasing order, so the answer is false."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 1000\nnums.length == n",
+        "tags": [
+            "Array",
+            "Math",
+            "Binary Search",
+            "Greedy",
+            "Number Theory"
+        ],
+        "title-slug": "prime-subtraction-operation"
+    },
+    {
+        "leetcode-id": 2602,
+        "title": "Minimum Operations to Make All Array Elements Equal",
+        "difficulty": 2,
+        "description": "You are given an array nums consisting of positive integers.\nYou are also given an integer array queries of size m. For the i^th query, you want to make all of the elements of nums equal to queries[i]. You can perform the following operation on the array any number of times:\n\nIncrease or decrease an element of the array by 1.\n\nReturn an array answer of size m where answer[i] is the minimum number of operations to make all elements of nums equal to queries[i].\nNote that after each query the array is reset to its original state.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,1,6,8], queries = [1,5]\nOutput: [14,10]\nExplanation: For the first query we can do the following operations:\n- Decrease nums[0] 2 times, so that nums = [1,1,6,8].\n- Decrease nums[2] 5 times, so that nums = [1,1,1,8].\n- Decrease nums[3] 7 times, so that nums = [1,1,1,1].\nSo the total number of operations for the first query is 2 + 5 + 7 = 14.\nFor the second query we can do the following operations:\n- Increase nums[0] 2 times, so that nums = [5,1,6,8].\n- Increase nums[1] 4 times, so that nums = [5,5,6,8].\n- Decrease nums[2] 1 time, so that nums = [5,5,5,8].\n- Decrease nums[3] 3 times, so that nums = [5,5,5,5].\nSo the total number of operations for the second query is 2 + 4 + 1 + 3 = 10.",
+            "Example 2:\nInput: nums = [2,9,6,3], queries = [10]\nOutput: [20]\nExplanation: We can increase each value in the array to 10. The total number of operations will be 8 + 1 + 4 + 7 = 20."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length\nm == queries.length\n1 <= n, m <= 10^5\n1 <= nums[i], queries[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Sorting",
+            "Prefix Sum"
+        ],
+        "title-slug": "minimum-operations-to-make-all-array-elements-equal"
+    },
+    {
+        "leetcode-id": 2603,
+        "title": "Collect Coins in a Tree",
+        "difficulty": 3,
+        "description": "There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given an integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given\u00a0an array coins of size n where coins[i] can be either 0 or 1, where 1 indicates the presence of a coin in the vertex i.\nInitially, you choose to start at any vertex in\u00a0the tree.\u00a0Then, you can perform\u00a0the following operations any number of times:\u00a0\n\nCollect all the coins that are at a distance of at most 2 from the current vertex, or\nMove to any adjacent vertex in the tree.\n\nFind the minimum number of edges you need to go through to collect all the coins and go back to the initial vertex.\nNote that if you pass an edge several times, you need to count it into the answer several times.",
+        "examples": [
+            "Example 1:\nInput: coins = [1,0,0,0,0,1], edges = [[0,1],[1,2],[2,3],[3,4],[4,5]]\nOutput: 2\nExplanation: Start at vertex 2, collect the coin at vertex 0, move to vertex 3, collect the coin at vertex 5 then move back to vertex 2.",
+            "Example 2:\nInput: coins = [0,0,0,1,1,0,0,1], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[5,6],[5,7]]\nOutput: 2\nExplanation: Start at vertex 0, collect the coins at vertices 4 and 3, move to vertex 2,  collect the coin at vertex 7, then move back to vertex 0."
+        ],
+        "constraints": "Constraints:\n\nn == coins.length\n1 <= n <= 3 * 10^4\n0 <= coins[i] <= 1\nedges.length == n - 1\nedges[i].length == 2\n0 <= ai, bi < n\nai != bi\nedges represents a valid tree.",
+        "tags": [
+            "Array",
+            "Tree",
+            "Graph",
+            "Topological Sort"
+        ],
+        "title-slug": "collect-coins-in-a-tree"
+    },
+    {
+        "leetcode-id": 2605,
+        "title": "Form Smallest Number From Two Digit Arrays",
+        "difficulty": 1,
+        "description": "Given two arrays of unique digits nums1 and nums2, return the smallest number that contains at least one digit from each array.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [4,1,3], nums2 = [5,7]\nOutput: 15\nExplanation: The number 15 contains the digit 1 from nums1 and the digit 5 from nums2. It can be proven that 15 is the smallest number we can have.",
+            "Example 2:\nInput: nums1 = [3,5,2,6], nums2 = [3,1,7]\nOutput: 3\nExplanation: The number 3 contains the digit 3 which exists in both arrays."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums1.length, nums2.length <= 9\n1 <= nums1[i], nums2[i] <= 9\nAll digits in each array are unique.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Enumeration"
+        ],
+        "title-slug": "form-smallest-number-from-two-digit-arrays"
+    },
+    {
+        "leetcode-id": 2606,
+        "title": "Find the Substring With Maximum Cost",
+        "difficulty": 2,
+        "description": "You are given a string s, a string chars of distinct characters and an integer array vals of the same length as chars.\nThe cost of the substring is the sum of the values of each character in the substring. The cost of an empty string is considered 0.\nThe value of the character is defined in the following way:\n\nIf the character is not in the string chars, then its value is its corresponding position (1-indexed) in the alphabet.\n\n\t\nFor example, the value of 'a' is 1, the value of 'b' is 2, and so on. The value of 'z' is 26.\n\n\nOtherwise, assuming i is the index where the character occurs in the string chars, then its value is vals[i].\n\nReturn the maximum cost among all substrings of the string s.",
+        "examples": [
+            "Example 1:\nInput: s = \"adaa\", chars = \"d\", vals = [-1000]\nOutput: 2\nExplanation: The value of the characters \"a\" and \"d\" is 1 and -1000 respectively.\nThe substring with the maximum cost is \"aa\" and its cost is 1 + 1 = 2.\nIt can be proven that 2 is the maximum cost.",
+            "Example 2:\nInput: s = \"abc\", chars = \"abc\", vals = [-1,-1,-1]\nOutput: 0\nExplanation: The value of the characters \"a\", \"b\" and \"c\" is -1, -1, and -1 respectively.\nThe substring with the maximum cost is the empty substring \"\" and its cost is 0.\nIt can be proven that 0 is the maximum cost."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consist of lowercase English letters.\n1 <= chars.length <= 26\nchars consist of distinct lowercase English letters.\nvals.length == chars.length\n-1000 <= vals[i] <= 1000",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Dynamic Programming"
+        ],
+        "title-slug": "find-the-substring-with-maximum-cost"
+    },
+    {
+        "leetcode-id": 2607,
+        "title": "Make K-Subarray Sums Equal",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array arr and an integer k. The array arr is circular. In other words, the first element of the array is the next element of the last element, and the last element of the array is the previous element of the first element.\nYou can do the following operation any number of times:\n\nPick any element from arr and increase or decrease it by 1.\n\nReturn the minimum number of operations such that the sum of each subarray of length k is equal.\nA subarray is a contiguous part of the array.",
+        "examples": [
+            "Example 1:\nInput: arr = [1,4,1,3], k = 2\nOutput: 1\nExplanation: we can do one operation on index 1 to make its value equal to 3.\nThe array after the operation is [1,3,1,3]\n- Subarray starts at index 0 is [1, 3], and its sum is 4 \n- Subarray starts at index 1 is [3, 1], and its sum is 4 \n- Subarray starts at index 2 is [1, 3], and its sum is 4 \n- Subarray starts at index 3 is [3, 1], and its sum is 4",
+            "Example 2:\nInput: arr = [2,5,5,7], k = 3\nOutput: 5\nExplanation: we can do three operations on index 0 to make its value equal to 5 and two operations on index 3 to make its value equal to 5.\nThe array after the operations is [5,5,5,5]\n- Subarray starts at index 0 is [5, 5, 5], and its sum is 15\n- Subarray starts at index 1 is [5, 5, 5], and its sum is 15\n- Subarray starts at index 2 is [5, 5, 5], and its sum is 15\n- Subarray starts at index 3 is [5, 5, 5], and its sum is 15"
+        ],
+        "constraints": "Constraints:\n\n1 <= k <= arr.length <= 10^5\n1 <= arr[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Math",
+            "Sorting",
+            "Number Theory"
+        ],
+        "title-slug": "make-k-subarray-sums-equal"
+    },
+    {
+        "leetcode-id": 2608,
+        "title": "Shortest Cycle in a Graph",
+        "difficulty": 3,
+        "description": "There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1. The edges in the graph are represented by a given 2D integer array edges, where edges[i] = [ui, vi] denotes an edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself.\nReturn the length of the shortest cycle in the graph. If no cycle exists, return -1.\nA cycle is a path that starts and ends at the same node, and each edge in the path is used only once.",
+        "examples": [
+            "Example 1:\nInput: n = 7, edges = [[0,1],[1,2],[2,0],[3,4],[4,5],[5,6],[6,3]]\nOutput: 3\nExplanation: The cycle with the smallest length is : 0 -> 1 -> 2 -> 0",
+            "Example 2:\nInput: n = 4, edges = [[0,1],[0,2]]\nOutput: -1\nExplanation: There are no cycles in this graph."
+        ],
+        "constraints": "Constraints:\n\n2 <= n <= 1000\n1 <= edges.length <= 1000\nedges[i].length == 2\n0 <= ui, vi < n\nui != vi\nThere are no repeated edges.",
+        "tags": [
+            "Breadth-First Search",
+            "Graph"
+        ],
+        "title-slug": "shortest-cycle-in-a-graph"
+    },
+    {
+        "leetcode-id": 2609,
+        "title": "Find the Longest Balanced Substring of a Binary String",
+        "difficulty": 1,
+        "description": "You are given a binary string s consisting only of zeroes and ones.\nA substring of s is considered balanced if all zeroes are before ones and the number of zeroes is equal to the number of ones inside the substring. Notice that the empty substring is considered a balanced substring.\nReturn the length of the longest balanced substring of s.\nA substring is a contiguous sequence of characters within a string.",
+        "examples": [
+            "Example 1:\nInput: s = \"01000111\"\nOutput: 6\nExplanation: The longest balanced substring is \"000111\", which has length 6.",
+            "Example 2:\nInput: s = \"00111\"\nOutput: 4\nExplanation: The longest balanced substring is \"0011\", which has length 4.",
+            "Example 3:\nInput: s = \"111\"\nOutput: 0\nExplanation: There is no balanced substring except the empty substring, so the answer is 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 50\n'0' <= s[i] <= '1'",
+        "tags": [
+            "String"
+        ],
+        "title-slug": "find-the-longest-balanced-substring-of-a-binary-string"
+    },
+    {
+        "leetcode-id": 2610,
+        "title": "Convert an Array Into a 2D Array With Conditions",
+        "difficulty": 2,
+        "description": "You are given an integer array nums. You need to create a 2D array from nums satisfying the following conditions:\n\nThe 2D array should contain only the elements of the array nums.\nEach row in the 2D array contains distinct integers.\nThe number of rows in the 2D array should be minimal.\n\nReturn the resulting array. If there are multiple answers, return any of them.\nNote that the 2D array can have a different number of elements on each row.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,4,1,2,3,1]\nOutput: [[1,3,4,2],[1,3],[1]]\nExplanation: We can create a 2D array that contains the following rows:\n- 1,3,4,2\n- 1,3\n- 1\nAll elements of nums were used, and each row of the 2D array contains distinct integers, so it is a valid answer.\nIt can be shown that we cannot have less than 3 rows in a valid array.",
+            "Example 2:\nInput: nums = [1,2,3,4]\nOutput: [[4,3,2,1]]\nExplanation: All elements of the array are distinct, so we can keep all of them in the first row of the 2D array."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 200\n1 <= nums[i] <= nums.length",
+        "tags": [
+            "Array",
+            "Hash Table"
+        ],
+        "title-slug": "convert-an-array-into-a-2d-array-with-conditions"
+    },
+    {
+        "leetcode-id": 2611,
+        "title": "Mice and Cheese",
+        "difficulty": 2,
+        "description": "There are two mice and n different types of cheese, each type of cheese should be eaten by exactly one mouse.\nA point of the cheese with index i (0-indexed) is:\n\nreward1[i] if the first mouse eats it.\nreward2[i] if the second mouse eats it.\n\nYou are given a positive integer array reward1, a positive integer array reward2, and a non-negative integer k.\nReturn the maximum points the mice can achieve if the first mouse eats exactly k types of cheese.",
+        "examples": [
+            "Example 1:\nInput: reward1 = [1,1,3,4], reward2 = [4,4,1,1], k = 2\nOutput: 15\nExplanation: In this example, the first mouse eats the 2^nd\u00a0(0-indexed) and the 3^rd\u00a0types of cheese, and the second mouse eats the 0^th\u00a0and the 1^st types of cheese.\nThe total points are 4 + 4 + 3 + 4 = 15.\nIt can be proven that 15 is the maximum total points that the mice can achieve.",
+            "Example 2:\nInput: reward1 = [1,1], reward2 = [1,1], k = 2\nOutput: 2\nExplanation: In this example, the first mouse eats the 0^th\u00a0(0-indexed) and 1^st\u00a0types of cheese, and the second mouse does not eat any cheese.\nThe total points are 1 + 1 = 2.\nIt can be proven that 2 is the maximum total points that the mice can achieve."
+        ],
+        "constraints": "Constraints:\n\n1 <= n == reward1.length == reward2.length <= 10^5\n1 <= reward1[i],\u00a0reward2[i] <= 1000\n0 <= k <= n",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "mice-and-cheese"
+    },
+    {
+        "leetcode-id": 2612,
+        "title": "Minimum Reverse Operations",
+        "difficulty": 3,
+        "description": "You are given an integer n and an integer p in the range [0, n - 1]. Representing a 0-indexed array arr\u00a0of length n where all positions are set to 0's, except position p which is set to 1.\nYou are also given an integer array banned containing some positions from the array. For the i^th position in banned, arr[banned[i]] = 0, and banned[i] != p.\nYou can perform multiple operations on arr. In an operation, you can choose a subarray with size k and reverse the subarray. However, the 1 in arr should never go to any of the positions in banned. In other words, after each operation arr[banned[i]] remains 0.\nReturn an array ans where for each i from [0, n - 1], ans[i] is the minimum number of reverse operations needed to bring the 1 to position i in arr, or -1 if it is impossible.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\nThe values of ans[i] are independent for all i's.\nThe reverse of an array is an array containing the values in reverse order.",
+        "examples": [
+            "Example 1:\nInput: n = 4, p = 0, banned = [1,2], k = 4\nOutput: [0,-1,-1,1]\nExplanation: In this case k = 4 so there is only one possible reverse operation we can perform, which is reversing the whole array. Initially, 1 is placed at position 0 so the amount of operations we need for position 0 is 0. We can never place a 1 on the banned positions, so the answer for positions 1 and 2 is -1. Finally, with one reverse operation we can bring the 1 to index 3, so the answer for position 3 is 1.",
+            "Example 2:\nInput: n = 5, p = 0, banned = [2,4], k = 3\nOutput: [0,-1,-1,-1,-1]\nExplanation: In this case the 1 is initially at position 0, so the answer for that position is 0. We can perform reverse operations of size 3. The 1 is currently located at position 0, so we need to reverse the subarray [0, 2] for it to leave that position, but reversing that subarray makes position 2 have a 1, which shouldn't happen. So, we can't move the 1 from position 0, making the result for all the other positions -1.",
+            "Example 3:\nInput: n = 4, p = 2, banned = [0,1,3], k = 1\nOutput: [-1,-1,0,-1]\nExplanation: In this case we can only perform reverse operations of size 1.\u00a0So the 1 never changes its position."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^5\n0 <= p <= n - 1\n0 <= banned.length <= n - 1\n0 <= banned[i] <= n - 1\n1 <= k <= n\u00a0\nbanned[i] != p\nall values in banned\u00a0are unique",
+        "tags": [
+            "Array",
+            "Breadth-First Search",
+            "Ordered Set"
+        ],
+        "title-slug": "minimum-reverse-operations"
+    },
+    {
+        "leetcode-id": 2614,
+        "title": "Prime In Diagonal",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed two-dimensional integer array nums.\nReturn the largest prime number that lies on at least one of the diagonals of nums. In case, no prime is present on any of the diagonals, return 0.\nNote that:\n\nAn integer is prime if it is greater than 1 and has no positive integer divisors other than 1 and itself.\nAn integer val is on one of the diagonals of nums if there exists an integer i for which nums[i][i] = val or an i for which nums[i][nums.length - i - 1] = val.\n\n\nIn the above diagram, one diagonal is [1,5,9] and another diagonal is [3,5,7].",
+        "examples": [
+            "Example 1:\nInput: nums = [[1,2,3],[5,6,7],[9,10,11]]\nOutput: 11\nExplanation: The numbers 1, 3, 6, 9, and 11 are the only numbers present on at least one of the diagonals. Since 11 is the largest prime, we return 11.",
+            "Example 2:\nInput: nums = [[1,2,3],[5,17,7],[9,11,10]]\nOutput: 17\nExplanation: The numbers 1, 3, 9, 10, and 17 are all present on at least one of the diagonals. 17 is the largest prime, so we return 17."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 300\nnums.length == numsi.length\n1 <= nums[i][j]\u00a0<= 4*10^6",
+        "tags": [
+            "Array",
+            "Math",
+            "Matrix",
+            "Number Theory"
+        ],
+        "title-slug": "prime-in-diagonal"
+    },
+    {
+        "leetcode-id": 2615,
+        "title": "Sum of Distances",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums. There exists an array arr of length nums.length, where arr[i] is the sum of |i - j| over all j such that nums[j] == nums[i] and j != i. If there is no such j, set arr[i] to be 0.\nReturn the array arr.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,1,1,2]\nOutput: [5,0,3,4,0]\nExplanation: \nWhen i = 0, nums[0] == nums[2] and nums[0] == nums[3]. Therefore, arr[0] = |0 - 2| + |0 - 3| = 5. \nWhen i = 1, arr[1] = 0 because there is no other index with value 3.\nWhen i = 2, nums[2] == nums[0] and nums[2] == nums[3]. Therefore, arr[2] = |2 - 0| + |2 - 3| = 3. \nWhen i = 3, nums[3] == nums[0] and nums[3] == nums[2]. Therefore, arr[3] = |3 - 0| + |3 - 2| = 4. \nWhen i = 4, arr[4] = 0 because there is no other index with value 2.",
+            "Example 2:\nInput: nums = [0,5,3]\nOutput: [0,0,0]\nExplanation: Since each element in nums is distinct, arr[i] = 0 for all i."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Prefix Sum"
+        ],
+        "title-slug": "sum-of-distances"
+    },
+    {
+        "leetcode-id": 2616,
+        "title": "Minimize the Maximum Difference of Pairs",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums and an integer p. Find p pairs of indices of nums such that the maximum difference amongst all the pairs is minimized. Also, ensure no index appears more than once amongst the p pairs.\nNote that for a pair of elements at the index i and j, the difference of this pair is |nums[i] - nums[j]|, where |x| represents the absolute value of x.\nReturn the minimum maximum difference among all p pairs. We define the maximum of an empty set to be zero.",
+        "examples": [
+            "Example 1:\nInput: nums = [10,1,2,7,1,3], p = 2\nOutput: 1\nExplanation: The first pair is formed from the indices 1 and 4, and the second pair is formed from the indices 2 and 5. \nThe maximum difference is max(|nums[1] - nums[4]|, |nums[2] - nums[5]|) = max(0, 1) = 1. Therefore, we return 1.",
+            "Example 2:\nInput: nums = [4,2,1,2], p = 1\nOutput: 0\nExplanation: Let the indices 1 and 3 form a pair. The difference of that pair is |2 - 2| = 0, which is the minimum we can attain."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 10^9\n0 <= p <= (nums.length)/2",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Greedy"
+        ],
+        "title-slug": "minimize-the-maximum-difference-of-pairs"
+    },
+    {
+        "leetcode-id": 2617,
+        "title": "Minimum Number of Visited Cells in a Grid",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed m x n integer matrix grid. Your initial position is at the top-left cell (0, 0).\nStarting from the cell (i, j), you can move to one of the following cells:\n\nCells (i, k) with j < k <= grid[i][j] + j (rightward movement), or\nCells (k, j) with i < k <= grid[i][j] + i (downward movement).\n\nReturn the minimum number of cells you need to visit to reach the bottom-right cell (m - 1, n - 1). If there is no valid path, return -1.",
+        "examples": [
+            "Example 1:\nInput: grid = [[3,4,2,1],[4,2,3,1],[2,1,0,0],[2,4,0,0]]\nOutput: 4\nExplanation: The image above shows one of the paths that visits exactly 4 cells.",
+            "Example 2:\nInput: grid = [[3,4,2,1],[4,2,1,1],[2,1,1,0],[3,4,1,0]]\nOutput: 3\nExplanation: The image above shows one of the paths that visits exactly 3 cells.",
+            "Example 3:\nInput: grid = [[2,1,0],[1,0,0]]\nOutput: -1\nExplanation: It can be proven that no path exists."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 10^5\n1 <= m * n <= 10^5\n0 <= grid[i][j] < m * n\ngrid[m - 1][n - 1] == 0",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Dynamic Programming",
+            "Stack",
+            "Union Find",
+            "Binary Indexed Tree",
+            "Segment Tree"
+        ],
+        "title-slug": "minimum-number-of-visited-cells-in-a-grid"
+    },
+    {
+        "leetcode-id": 2639,
+        "title": "Find the Width of Columns of a Grid",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed m x n integer matrix grid. The width of a column is the maximum length of its integers.\n\nFor example, if grid = [[-10], [3], [12]], the width of the only column is 3 since -10 is of length 3.\n\nReturn an integer array ans of size n where ans[i] is the width of the i^th column.\nThe length of an integer x with len digits is equal to len if x is non-negative, and len + 1 otherwise.",
+        "examples": [
+            "Example 1:\nInput: grid = [[1],[22],[333]]\nOutput: [3]\nExplanation: In the 0^th column, 333 is of length 3.",
+            "Example 2:\nInput: grid = [[-15,1,3],[15,7,12],[5,6,-2]]\nOutput: [3,1,2]\nExplanation: \nIn the 0^th column, only -15 is of length 3.\nIn the 1^st column, all integers are of length 1. \nIn the 2^nd column, both 12 and -2 are of length 2."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 100 \n-10^9 <= grid[r][c] <= 10^9",
+        "tags": [
+            "Array",
+            "Matrix"
+        ],
+        "title-slug": "find-the-width-of-columns-of-a-grid"
+    },
+    {
+        "leetcode-id": 2640,
+        "title": "Find the Score of All Prefixes of an Array",
+        "difficulty": 2,
+        "description": "We define the conversion array conver of an array arr as follows:\n\nconver[i] = arr[i] + max(arr[0..i]) where max(arr[0..i]) is the maximum value of arr[j] over 0 <= j <= i.\n\nWe also define the score of an array arr as the sum of the values of the conversion array of arr.\nGiven a 0-indexed integer array nums of length n, return an array ans of length n where ans[i] is the score of the prefix nums[0..i].",
+        "examples": [
+            "Example 1:\nInput: nums = [2,3,7,5,10]\nOutput: [4,10,24,36,56]\nExplanation: \nFor the prefix [2], the conversion array is [4] hence the score is 4\nFor the prefix [2, 3], the conversion array is [4, 6] hence the score is 10\nFor the prefix [2, 3, 7], the conversion array is [4, 6, 14] hence the score is 24\nFor the prefix [2, 3, 7, 5], the conversion array is [4, 6, 14, 12] hence the score is 36\nFor the prefix [2, 3, 7, 5, 10], the conversion array is [4, 6, 14, 12, 20] hence the score is 56",
+            "Example 2:\nInput: nums = [1,1,2,4,8,16]\nOutput: [2,4,8,16,32,64]\nExplanation: \nFor the prefix [1], the conversion array is [2] hence the score is 2\nFor the prefix [1, 1], the conversion array is [2, 2] hence the score is 4\nFor the prefix [1, 1, 2], the conversion array is [2, 2, 4] hence the score is 8\nFor the prefix [1, 1, 2, 4], the conversion array is [2, 2, 4, 8] hence the score is 16\nFor the prefix [1, 1, 2, 4, 8], the conversion array is [2, 2, 4, 8, 16] hence the score is 32\nFor the prefix [1, 1, 2, 4, 8, 16], the conversion array is [2, 2, 4, 8, 16, 32] hence the score is 64"
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Prefix Sum"
+        ],
+        "title-slug": "find-the-score-of-all-prefixes-of-an-array"
+    },
+    {
+        "leetcode-id": 2641,
+        "title": "Cousins in Binary Tree II",
+        "difficulty": 2,
+        "description": "Given the root of a binary tree, replace the value of each node in the tree with the sum of all its cousins' values.\nTwo nodes of a binary tree are cousins if they have the same depth with different parents.\nReturn the root of the modified tree.\nNote that the depth of a node is the number of edges in the path from the root node to it.",
+        "examples": [
+            "Example 1:\nInput: root = [5,4,9,1,10,null,7]\nOutput: [0,0,0,7,7,null,11]\nExplanation: The diagram above shows the initial binary tree and the binary tree after changing the value of each node.\n- Node with value 5 does not have any cousins so its sum is 0.\n- Node with value 4 does not have any cousins so its sum is 0.\n- Node with value 9 does not have any cousins so its sum is 0.\n- Node with value 1 has a cousin with value 7 so its sum is 7.\n- Node with value 10 has a cousin with value 7 so its sum is 7.\n- Node with value 7 has cousins with values 1 and 10 so its sum is 11.",
+            "Example 2:\nInput: root = [3,1,2]\nOutput: [0,0,0]\nExplanation: The diagram above shows the initial binary tree and the binary tree after changing the value of each node.\n- Node with value 3 does not have any cousins so its sum is 0.\n- Node with value 1 does not have any cousins so its sum is 0.\n- Node with value 2 does not have any cousins so its sum is 0."
+        ],
+        "constraints": "Constraints:\n\nThe number of nodes in the tree is in the range [1, 10^5].\n1 <= Node.val <= 10^4",
+        "tags": [
+            "Hash Table",
+            "Tree",
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Binary Tree"
+        ],
+        "title-slug": "cousins-in-binary-tree-ii"
+    },
+    {
+        "leetcode-id": 2642,
+        "title": "Design Graph With Shortest Path Calculator",
+        "difficulty": 3,
+        "description": "There is a directed weighted graph that consists of n nodes numbered from 0 to n - 1. The edges of the graph are initially represented by the given array edges where edges[i] = [fromi, toi, edgeCosti] meaning that there is an edge from fromi to toi with the cost edgeCosti.\nImplement the Graph class:\n\nGraph(int n, int[][] edges) initializes the object with n nodes and the given edges.\naddEdge(int[] edge) adds an edge to the list of edges where edge = [from, to, edgeCost]. It is guaranteed that there is no edge between the two nodes before adding this one.\nint shortestPath(int node1, int node2) returns the minimum cost of a path from node1 to node2. If no path exists, return -1. The cost of a path is the sum of the costs of the edges in the path.",
+        "examples": [
+            "Example 1:\nInput\n[\"Graph\", \"shortestPath\", \"shortestPath\", \"addEdge\", \"shortestPath\"]\n[[4, [[0, 2, 5], [0, 1, 2], [1, 2, 1], [3, 0, 3]]], [3, 2], [0, 3], [[1, 3, 4]], [0, 3]]\nOutput\n[null, 6, -1, null, 6]\n\nExplanation\nGraph g = new Graph(4, [[0, 2, 5], [0, 1, 2], [1, 2, 1], [3, 0, 3]]);\ng.shortestPath(3, 2); // return 6. The shortest path from 3 to 2 in the first diagram above is 3 -> 0 -> 1 -> 2 with a total cost of 3 + 2 + 1 = 6.\ng.shortestPath(0, 3); // return -1. There is no path from 0 to 3.\ng.addEdge([1, 3, 4]); // We add an edge from node 1 to node 3, and we get the second diagram above.\ng.shortestPath(0, 3); // return 6. The shortest path from 0 to 3 now is 0 -> 1 -> 3 with a total cost of 2 + 4 = 6."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 100\n0 <= edges.length <= n * (n - 1)\nedges[i].length == edge.length == 3\n0 <= fromi, toi, from, to, node1, node2 <= n - 1\n1 <= edgeCosti, edgeCost <= 10^6\nThere are no repeated edges and no self-loops in the graph at any point.\nAt most 100 calls will be made for addEdge.\nAt most 100 calls will be made for shortestPath.",
+        "tags": [
+            "Graph",
+            "Design",
+            "Heap (Priority Queue)",
+            "Shortest Path"
+        ],
+        "title-slug": "design-graph-with-shortest-path-calculator"
+    },
+    {
+        "leetcode-id": 2643,
+        "title": "Row With Maximum Ones",
+        "difficulty": 1,
+        "description": "Given a m x n binary matrix mat, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row.\nIn case there are multiple rows that have the maximum count of ones, the row with the smallest row number should be selected.\nReturn an array containing the index of the row, and the number of ones in it.",
+        "examples": [
+            "Example 1:\nInput: mat = [[0,1],[1,0]]\nOutput: [0,1]\nExplanation: Both rows have the same number of 1's. So we return the index of the smaller row, 0, and the maximum count of ones (1). So, the answer is [0,1].",
+            "Example 2:\nInput: mat = [[0,0,0],[0,1,1]]\nOutput: [1,2]\nExplanation: The row indexed 1 has the maximum count of ones (2). So we return its index, 1, and the count. So, the answer is [1,2].",
+            "Example 3:\nInput: mat = [[0,0],[1,1],[0,0]]\nOutput: [1,2]\nExplanation: The row indexed 1 has the maximum count of ones (2). So the answer is [1,2]."
+        ],
+        "constraints": "Constraints:\n\nm == mat.length\u00a0\nn == mat[i].length\u00a0\n1 <= m, n <= 100\u00a0\nmat[i][j] is either 0 or 1.",
+        "tags": [
+            "Array",
+            "Matrix"
+        ],
+        "title-slug": "row-with-maximum-ones"
+    },
+    {
+        "leetcode-id": 2644,
+        "title": "Find the Maximum Divisibility Score",
+        "difficulty": 1,
+        "description": "You are given two 0-indexed integer arrays nums and divisors.\nThe divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i].\nReturn the integer divisors[i] with the maximum divisibility score. If there is more than one integer with the maximum score, return the minimum of them.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,7,9,3,9], divisors = [5,2,3]\nOutput: 3\nExplanation: The divisibility score for every element in divisors is:\nThe divisibility score of divisors[0] is 0 since no number in nums is divisible by 5.\nThe divisibility score of divisors[1] is 1 since nums[0] is divisible by 2.\nThe divisibility score of divisors[2] is 3 since nums[2], nums[3], and nums[4] are divisible by 3.\nSince divisors[2] has the maximum divisibility score, we return it.",
+            "Example 2:\nInput: nums = [20,14,21,10], divisors = [5,7,5]\nOutput: 5\nExplanation: The divisibility score for every element in divisors is:\nThe divisibility score of divisors[0] is 2 since nums[0] and nums[3] are divisible by 5.\nThe divisibility score of divisors[1] is 2 since nums[1] and nums[2] are divisible by 7.\nThe divisibility score of divisors[2] is 2 since nums[0] and nums[3] are divisible by 5.\nSince divisors[0], divisors[1], and divisors[2] all have the maximum divisibility score, we return the minimum of them (i.e., divisors[2]).",
+            "Example 3:\nInput: nums = [12], divisors = [10,16]\nOutput: 10\nExplanation: The divisibility score for every element in divisors is:\nThe divisibility score of divisors[0] is 0 since no number in nums is divisible by 10.\nThe divisibility score of divisors[1] is 0 since no number in nums is divisible by 16.\nSince divisors[0] and divisors[1] both have the maximum divisibility score, we return the minimum of them (i.e., divisors[0])."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length, divisors.length <= 1000\n1 <= nums[i], divisors[i] <= 10^9",
+        "tags": [
+            "Array"
+        ],
+        "title-slug": "find-the-maximum-divisibility-score"
+    },
+    {
+        "leetcode-id": 2645,
+        "title": "Minimum Additions to Make Valid String",
+        "difficulty": 2,
+        "description": "Given a string word to which you can insert letters \"a\", \"b\" or \"c\" anywhere and any number of times, return the minimum number of letters that must be inserted so that word becomes valid.\nA string is called valid if it can be formed by concatenating the string \"abc\" several times.",
+        "examples": [
+            "Example 1:\nInput: word = \"b\"\nOutput: 2\nExplanation: Insert the letter \"a\" right before \"b\", and the letter \"c\" right next to \"a\" to obtain the valid string \"abc\".",
+            "Example 2:\nInput: word = \"aaa\"\nOutput: 6\nExplanation: Insert letters \"b\" and \"c\" next to each \"a\" to obtain the valid string \"abcabcabc\".",
+            "Example 3:\nInput: word = \"abc\"\nOutput: 0\nExplanation: word is already valid. No modifications are needed."
+        ],
+        "constraints": "Constraints:\n\n1 <= word.length <= 50\nword consists of letters \"a\", \"b\"\u00a0and \"c\" only.",
+        "tags": [
+            "String",
+            "Dynamic Programming",
+            "Stack",
+            "Greedy"
+        ],
+        "title-slug": "minimum-additions-to-make-valid-string"
+    },
+    {
+        "leetcode-id": 2646,
+        "title": "Minimize the Total Price of the Trips",
+        "difficulty": 3,
+        "description": "There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\nEach node has an associated price. You are given an integer array price, where price[i] is the price of the i^th node.\nThe price sum of a given path is the sum of the prices of all nodes lying on that path.\nAdditionally, you are given a 2D integer array trips, where trips[i] = [starti, endi] indicates that you start the i^th trip from the node starti and travel to the node endi by any path you like.\nBefore performing your first trip, you can choose some non-adjacent nodes and halve the prices.\nReturn the minimum total price sum to perform all the given trips.",
+        "examples": [
+            "Example 1:\nInput: n = 4, edges = [[0,1],[1,2],[1,3]], price = [2,2,10,6], trips = [[0,3],[2,1],[2,3]]\nOutput: 23\nExplanation: The diagram above denotes the tree after rooting it at node 2. The first part shows the initial tree and the second part shows the tree after choosing nodes 0, 2, and 3, and making their price half.\nFor the 1^st trip, we choose path [0,1,3]. The price sum of that path is 1 + 2 + 3 = 6.\nFor the 2^nd trip, we choose path [2,1]. The price sum of that path is 2 + 5 = 7.\nFor the 3^rd trip, we choose path [2,1,3]. The price sum of that path is 5 + 2 + 3 = 10.\nThe total price sum of all trips is 6 + 7 + 10 = 23.\nIt can be proven, that 23 is the minimum answer that we can achieve.",
+            "Example 2:\nInput: n = 2, edges = [[0,1]], price = [2,2], trips = [[0,0]]\nOutput: 1\nExplanation: The diagram above denotes the tree after rooting it at node 0. The first part shows the initial tree and the second part shows the tree after choosing node 0, and making its price half.\nFor the 1^st trip, we choose path [0]. The price sum of that path is 1.\nThe total price sum of all trips is 1. It can be proven, that 1 is the minimum answer that we can achieve."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 50\nedges.length == n - 1\n0 <= ai, bi <= n - 1\nedges represents a valid tree.\nprice.length == n\nprice[i] is an even integer.\n1 <= price[i] <= 1000\n1 <= trips.length <= 100\n0 <= starti, endi\u00a0<= n - 1",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Tree",
+            "Depth-First Search",
+            "Graph"
+        ],
+        "title-slug": "minimize-the-total-price-of-the-trips"
+    },
+    {
+        "leetcode-id": 2651,
+        "title": "Calculate Delayed Arrival Time",
+        "difficulty": 1,
+        "description": "You are given a positive integer arrivalTime denoting the arrival time of a train in hours, and another positive integer delayedTime denoting the amount of delay in hours.\nReturn the time when the train will arrive at the station.\nNote that the time in this problem is in 24-hours format.",
+        "examples": [
+            "Example 1:\nInput: arrivalTime = 15, delayedTime = 5 \nOutput: 20 \nExplanation: Arrival time of the train was 15:00 hours. It is delayed by 5 hours. Now it will reach at 15+5 = 20 (20:00 hours).",
+            "Example 2:\nInput: arrivalTime = 13, delayedTime = 11\nOutput: 0\nExplanation: Arrival time of the train was 13:00 hours. It is delayed by 11 hours. Now it will reach at 13+11=24 (Which is denoted by 00:00 in 24 hours format so return 0)."
+        ],
+        "constraints": "Constraints:\n\n1 <= arrivaltime <\u00a024\n1 <= delayedTime <= 24",
+        "tags": [
+            "Math"
+        ],
+        "title-slug": "calculate-delayed-arrival-time"
+    },
+    {
+        "leetcode-id": 2652,
+        "title": "Sum Multiples",
+        "difficulty": 1,
+        "description": "Given a positive integer n, find the sum of all integers in the range [1, n] inclusive that are divisible by 3, 5, or 7.\nReturn an integer denoting the sum of all numbers in the given range satisfying\u00a0the constraint.",
+        "examples": [
+            "Example 1:\nInput: n = 7\nOutput: 21\nExplanation: Numbers in the range [1, 7] that are divisible by 3, 5, or 7 are 3, 5, 6, 7. The sum of these numbers is 21.",
+            "Example 2:\nInput: n = 10\nOutput: 40\nExplanation: Numbers in the range [1, 10] that are divisible by 3, 5, or 7 are 3, 5, 6, 7, 9, 10. The sum of these numbers is 40.",
+            "Example 3:\nInput: n = 9\nOutput: 30\nExplanation: Numbers in the range [1, 9] that are divisible by 3, 5, or 7 are 3, 5, 6, 7, 9. The sum of these numbers is 30."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^3",
+        "tags": [
+            "Math"
+        ],
+        "title-slug": "sum-multiples"
+    },
+    {
+        "leetcode-id": 2653,
+        "title": "Sliding Subarray Beauty",
+        "difficulty": 2,
+        "description": "Given an integer array nums containing n integers, find the beauty of each subarray of size k.\nThe beauty of a subarray is the x^th smallest integer in the subarray if it is negative, or 0 if there are fewer than x negative integers.\nReturn an integer array containing n - k + 1 integers, which denote the beauty of the subarrays in order from the first index in the array.\n\n\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,-1,-3,-2,3], k = 3, x = 2\nOutput: [-1,-2,-2]\nExplanation: There are 3 subarrays with size k = 3. \nThe first subarray is [1, -1, -3] and the 2^nd smallest negative integer is -1.\u00a0\nThe second subarray is [-1, -3, -2] and the 2^nd smallest negative integer is -2.\u00a0\nThe third subarray is [-3, -2, 3]\u00a0and the 2^nd smallest negative integer is -2.",
+            "Example 2:\nInput: nums = [-1,-2,-3,-4,-5], k = 2, x = 2\nOutput: [-1,-2,-3,-4]\nExplanation: There are 4 subarrays with size k = 2.\nFor [-1, -2], the 2^nd smallest negative integer is -1.\nFor [-2, -3], the 2^nd smallest negative integer is -2.\nFor [-3, -4], the 2^nd smallest negative integer is -3.\nFor [-4, -5], the 2^nd smallest negative integer is -4.",
+            "Example 3:\nInput: nums = [-3,1,2,-3,0,-3], k = 2, x = 1\nOutput: [-3,0,-3,-3,-3]\nExplanation: There are 5 subarrays with size k = 2.\nFor [-3, 1], the 1^st smallest negative integer is -3.\nFor [1, 2], there is no negative integer so the beauty is 0.\nFor [2, -3], the 1^st smallest negative integer is -3.\nFor [-3, 0], the 1^st smallest negative integer is -3.\nFor [0, -3], the 1^st smallest negative integer is -3."
+        ],
+        "constraints": "Constraints:\n\nn == nums.length\u00a0\n1 <= n <= 10^5\n1 <= k <= n\n1 <= x <= k\u00a0\n-50\u00a0<= nums[i] <= 50",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sliding Window"
+        ],
+        "title-slug": "sliding-subarray-beauty"
+    },
+    {
+        "leetcode-id": 2654,
+        "title": "Minimum Number of Operations to Make All Array Elements Equal to 1",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed\u00a0array nums consisiting of positive integers. You can do the following operation on the array any number of times:\n\nSelect an index i such that 0 <= i < n - 1 and replace either of\u00a0nums[i] or nums[i+1] with their gcd value.\n\nReturn the minimum number of operations to make all elements of nums equal to 1. If it is impossible, return -1.\nThe gcd of two integers is the greatest common divisor of the two integers.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,6,3,4]\nOutput: 4\nExplanation: We can do the following operations:\n- Choose index i = 2 and replace nums[2] with gcd(3,4) = 1. Now we have nums = [2,6,1,4].\n- Choose index i = 1 and replace nums[1] with gcd(6,1) = 1. Now we have nums = [2,1,1,4].\n- Choose index i = 0 and replace nums[0] with gcd(2,1) = 1. Now we have nums = [1,1,1,4].\n- Choose index i = 2 and replace nums[3] with gcd(1,4) = 1. Now we have nums = [1,1,1,1].",
+            "Example 2:\nInput: nums = [2,10,6,14]\nOutput: -1\nExplanation: It can be shown that it is impossible to make all the elements equal to 1."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 50\n1 <= nums[i] <= 10^6\n\n\u00a0\nFollow-up:\nThe O(n) time complexity\u00a0solution works, but could you find an O(1) constant time complexity solution?",
+        "tags": [
+            "Array",
+            "Math",
+            "Number Theory"
+        ],
+        "title-slug": "minimum-number-of-operations-to-make-all-array-elements-equal-to-1"
+    },
+    {
+        "leetcode-id": 2656,
+        "title": "Maximum Sum With Exactly K Elements ",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums and an integer k. Your task is to perform the following operation exactly k times in order to maximize your score:\n\nSelect an element m from nums.\nRemove the selected element m from the array.\nAdd a new element with a value of m + 1 to the array.\nIncrease your score by m.\n\nReturn the maximum score you can achieve after performing the operation exactly k times.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,3,4,5], k = 3\nOutput: 18\nExplanation: We need to choose exactly 3 elements from nums to maximize the sum.\nFor the first iteration, we choose 5. Then sum is 5 and nums = [1,2,3,4,6]\nFor the second iteration, we choose 6. Then sum is 5 + 6 and nums = [1,2,3,4,7]\nFor the third iteration, we choose 7. Then sum is 5 + 6 + 7 = 18 and nums = [1,2,3,4,8]\nSo, we will return 18.\nIt can be proven, that 18 is the maximum answer that we can achieve.",
+            "Example 2:\nInput: nums = [5,5,5], k = 2\nOutput: 11\nExplanation: We need to choose exactly 2 elements from nums to maximize the sum.\nFor the first iteration, we choose 5. Then sum is 5 and nums = [5,5,6]\nFor the second iteration, we choose 6. Then sum is 5 + 6 = 11 and nums = [5,5,7]\nSo, we will return 11.\nIt can be proven, that 11 is the maximum answer that we can achieve."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100\n1 <= k <= 100\n\n\u00a0\n.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0; \n}\n.spoiler {overflow:hidden;}\n.spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;}\n.spoilerbutton[value=\"Show Message\"] + .spoiler > div {margin-top:-500%;}\n.spoilerbutton[value=\"Hide Message\"] + .spoiler {padding:5px;}",
+        "tags": [
+            "Array",
+            "Greedy"
+        ],
+        "title-slug": "maximum-sum-with-exactly-k-elements"
+    },
+    {
+        "leetcode-id": 2657,
+        "title": "Find the Prefix Common Array of Two Arrays",
+        "difficulty": 2,
+        "description": "You are given two 0-indexed integer permutations A and B of length n.\nA prefix common array of A and B is an array C such that C[i] is equal to the count of numbers that are present at or before the index i in both A and B.\nReturn the prefix common array of A and B.\nA sequence of n integers is called a\u00a0permutation if it contains all integers from 1 to n exactly once.",
+        "examples": [
+            "Example 1:\nInput: A = [1,3,2,4], B = [3,1,2,4]\nOutput: [0,2,3,4]\nExplanation: At i = 0: no number is common, so C[0] = 0.\nAt i = 1: 1 and 3 are common in A and B, so C[1] = 2.\nAt i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3.\nAt i = 3: 1, 2, 3, and 4 are common in A and B, so C[3] = 4.",
+            "Example 2:\nInput: A = [2,3,1], B = [3,1,2]\nOutput: [0,1,3]\nExplanation: At i = 0: no number is common, so C[0] = 0.\nAt i = 1: only 3 is common in A and B, so C[1] = 1.\nAt i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3."
+        ],
+        "constraints": "Constraints:\n\n1 <= A.length == B.length == n <= 50\n1 <= A[i], B[i] <= n\nIt is guaranteed that A and B are both a permutation of n integers.",
+        "tags": [
+            "Array",
+            "Hash Table"
+        ],
+        "title-slug": "find-the-prefix-common-array-of-two-arrays"
+    },
+    {
+        "leetcode-id": 2658,
+        "title": "Maximum Number of Fish in a Grid",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed 2D matrix grid of size m x n, where (r, c) represents:\n\nA land cell if grid[r][c] = 0, or\nA water cell containing grid[r][c] fish, if grid[r][c] > 0.\n\nA fisher can start at any water cell (r, c) and can do the following operations any number of times:\n\nCatch all the fish at cell (r, c), or\nMove to any adjacent water cell.\n\nReturn the maximum number of fish the fisher can catch if he chooses his starting cell optimally, or 0 if no water cell exists.\nAn adjacent cell of the cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) or (r - 1, c) if it exists.",
+        "examples": [
+            "Example 1:\nInput: grid = [[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]]\nOutput: 7\nExplanation: The fisher can start at cell (1,3) and collect 3 fish, then move to cell (2,3)\u00a0and collect 4 fish.",
+            "Example 2:\nInput: grid = [[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]]\nOutput: 1\nExplanation: The fisher can start at cells (0,0) or (3,3) and collect a single fish."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n <= 10\n0 <= grid[i][j] <= 10",
+        "tags": [
+            "Array",
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Union Find",
+            "Matrix"
+        ],
+        "title-slug": "maximum-number-of-fish-in-a-grid"
+    },
+    {
+        "leetcode-id": 2659,
+        "title": "Make Array Empty",
+        "difficulty": 3,
+        "description": "You are given an integer array nums containing distinct numbers, and you can perform the following operations until the array is empty:\n\nIf the first element has the smallest value, remove it\nOtherwise, put the first element at the end of the array.\n\nReturn an integer denoting the number of operations it takes to make nums empty.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,4,-1]\nOutput: 5\n\n\n\n\nOperation\nArray\n\n\n\n\n1\n[4, -1, 3]\n\n\n2\n[-1, 3, 4]\n\n\n3\n[3, 4]\n\n\n4\n[4]\n\n\n5\n[]",
+            "Example 2:\nInput: nums = [1,2,4,3]\nOutput: 5\n\n\n\n\nOperation\nArray\n\n\n\n\n1\n[2, 4, 3]\n\n\n2\n[4, 3]\n\n\n3\n[3, 4]\n\n\n4\n[4]\n\n\n5\n[]",
+            "Example 3:\nInput: nums = [1,2,3]\nOutput: 3\n\n\n\n\nOperation\nArray\n\n\n\n\n1\n[2, 3]\n\n\n2\n[3]\n\n\n3\n[]"
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n-10^9\u00a0<= nums[i] <= 10^9\nAll values in nums are distinct.",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Greedy",
+            "Binary Indexed Tree",
+            "Segment Tree",
+            "Sorting",
+            "Ordered Set"
+        ],
+        "title-slug": "make-array-empty"
+    },
+    {
+        "leetcode-id": 2660,
+        "title": "Determine the Winner of a Bowling Game",
+        "difficulty": 1,
+        "description": "You are given two 0-indexed integer arrays player1 and player2, that represent the number of pins that player 1 and player 2 hit in a bowling game, respectively.\nThe bowling game consists of n turns, and the number of pins in each turn is exactly 10.\nAssume a player hit xi pins in the i^th turn. The value of the i^th turn for the player is:\n\n2xi if the player hit 10 pins in any of the previous two turns.\nOtherwise, It is xi.\n\nThe score of the player is the sum of the values of their n turns.\nReturn\n\n1 if the score of player 1 is more than the score of player 2,\n2 if the score of player 2 is more than the score of player 1, and\n0 in case of a draw.",
+        "examples": [
+            "Example 1:\nInput: player1 = [4,10,7,9], player2 = [6,5,2,3]\nOutput: 1\nExplanation: The score of player1 is 4 + 10 + 2*7 + 2*9 = 46.\nThe score of player2 is 6 + 5 + 2 + 3 = 16.\nScore of player1 is more than the score of player2, so, player1 is the winner, and the answer is 1.",
+            "Example 2:\nInput: player1 = [3,5,7,6], player2 = [8,10,10,2]\nOutput: 2\nExplanation: The score of player1 is 3 + 5 + 7 + 6 = 21.\nThe score of player2 is 8 + 10 + 2*10 + 2*2 = 42.\nScore of player2 is more than the score of player1, so, player2 is the winner, and the answer is 2.",
+            "Example 3:\nInput: player1 = [2,3], player2 = [4,1]\nOutput: 0\nExplanation: The score of player1 is 2 + 3 = 5\nThe score of player2 is 4 + 1 = 5\nThe score of player1 equals to the score of player2, so, there is a draw, and the answer is 0."
+        ],
+        "constraints": "Constraints:\n\nn == player1.length == player2.length\n1 <= n <= 1000\n0 <= player1[i], player2[i] <= 10",
+        "tags": [
+            "Array",
+            "Simulation"
+        ],
+        "title-slug": "determine-the-winner-of-a-bowling-game"
+    },
+    {
+        "leetcode-id": 2661,
+        "title": "First Completely Painted Row or Column",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat both contain all the integers in the range [1, m * n].\nGo through each index i in arr starting from index 0 and paint the cell in mat containing the integer arr[i].\nReturn the smallest index i at which either a row or a column will be completely painted in mat.",
+        "examples": [
+            "Example 1:\nInput: arr = [1,3,4,2], mat = [[1,4],[2,3]]\nOutput: 2\nExplanation: The moves are shown in order, and both the first row and second column of the matrix become fully painted at arr[2].",
+            "Example 2:\nInput: arr = [2,8,7,4,1,3,5,6,9], mat = [[3,2,5],[1,4,6],[8,7,9]]\nOutput: 3\nExplanation: The second column becomes fully painted at arr[3]."
+        ],
+        "constraints": "Constraints:\n\nm == mat.length\nn = mat[i].length\narr.length == m * n\n1 <= m, n <= 10^5\n1 <= m * n <= 10^5\n1 <= arr[i], mat[r][c] <= m * n\nAll the integers of arr are unique.\nAll the integers of mat are unique.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Matrix"
+        ],
+        "title-slug": "first-completely-painted-row-or-column"
+    },
+    {
+        "leetcode-id": 2662,
+        "title": "Minimum Cost of a Path With Special Roads",
+        "difficulty": 2,
+        "description": "You are given an array start where start = [startX, startY] represents your initial position (startX, startY) in a 2D space. You are also given the array target where target = [targetX, targetY] represents your target position (targetX, targetY).\nThe cost of going from a position (x1, y1) to any other position in the space (x2, y2) is |x2 - x1| + |y2 - y1|.\nThere are also some special roads. You are given a 2D array specialRoads where specialRoads[i] = [x1i, y1i, x2i, y2i, costi] indicates that the i^th special road can take you from (x1i, y1i) to (x2i, y2i) with a cost equal to costi. You can use each special road any number of times.\nReturn the minimum cost required to go from (startX, startY) to (targetX, targetY).",
+        "examples": [
+            "Example 1:\nInput: start = [1,1], target = [4,5], specialRoads = [[1,2,3,3,2],[3,4,4,5,1]]\nOutput: 5\nExplanation: The optimal path from (1,1) to (4,5) is the following:\n- (1,1) -> (1,2). This move has a cost of |1 - 1| + |2 - 1| = 1.\n- (1,2) -> (3,3). This move uses the first special edge, the cost is 2.\n- (3,3) -> (3,4). This move has a cost of |3 - 3| + |4 - 3| = 1.\n- (3,4) -> (4,5). This move uses the second special edge, the cost is 1.\nSo the total cost is 1 + 2 + 1 + 1 = 5.\nIt can be shown that we cannot achieve a smaller total cost than 5.",
+            "Example 2:\nInput: start = [3,2], target = [5,7], specialRoads = [[3,2,3,4,4],[3,3,5,5,5],[3,4,5,6,6]]\nOutput: 7\nExplanation: It is optimal to not use any special edges and go directly from the starting to the ending position with a cost |5 - 3| + |7 - 2| = 7."
+        ],
+        "constraints": "Constraints:\n\nstart.length == target.length == 2\n1 <= startX <= targetX <= 10^5\n1 <= startY <= targetY <= 10^5\n1 <= specialRoads.length <= 200\nspecialRoads[i].length == 5\nstartX <= x1i, x2i <= targetX\nstartY <= y1i, y2i <= targetY\n1 <= costi <= 10^5",
+        "tags": [
+            "Array",
+            "Graph",
+            "Heap (Priority Queue)",
+            "Shortest Path"
+        ],
+        "title-slug": "minimum-cost-of-a-path-with-special-roads"
+    },
+    {
+        "leetcode-id": 2663,
+        "title": "Lexicographically Smallest Beautiful String",
+        "difficulty": 3,
+        "description": "A string is beautiful if:\n\nIt consists of the first k letters of the English lowercase alphabet.\nIt does not contain any substring of length 2 or more which is a palindrome.\n\nYou are given a beautiful string s of length n and a positive integer k.\nReturn the lexicographically smallest string of length n, which is larger than s and is beautiful. If there is no such string, return an empty string.\nA string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b.\n\nFor example, \"abcd\" is lexicographically larger than \"abcc\" because the first position they differ is at the fourth character, and d is greater than c.",
+        "examples": [
+            "Example 1:\nInput: s = \"abcz\", k = 26\nOutput: \"abda\"\nExplanation: The string \"abda\" is beautiful and lexicographically larger than the string \"abcz\".\nIt can be proven that there is no string that is lexicographically larger than the string \"abcz\", beautiful, and lexicographically smaller than the string \"abda\".",
+            "Example 2:\nInput: s = \"dc\", k = 4\nOutput: \"\"\nExplanation: It can be proven that there is no string that is lexicographically larger than the string \"dc\" and is beautiful."
+        ],
+        "constraints": "Constraints:\n\n1 <= n == s.length <= 10^5\n4 <= k <= 26\ns is a beautiful string.",
+        "tags": [
+            "String",
+            "Greedy"
+        ],
+        "title-slug": "lexicographically-smallest-beautiful-string"
+    },
+    {
+        "leetcode-id": 2670,
+        "title": "Find the Distinct Difference Array",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed array nums of length n.\nThe distinct difference array of nums is an array diff of length n such that diff[i] is equal to the number of distinct elements in the suffix nums[i + 1, ..., n - 1] subtracted from the number of distinct elements in the prefix nums[0, ..., i].\nReturn the distinct difference array of nums.\nNote that nums[i, ..., j] denotes the subarray of nums starting at index i and ending at index j inclusive. Particularly, if i > j then nums[i, ..., j] denotes an empty subarray.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,3,4,5]\nOutput: [-3,-1,1,3,5]\nExplanation: For index i = 0, there is 1 element in the prefix and 4 distinct elements in the suffix. Thus, diff[0] = 1 - 4 = -3.\nFor index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1.\nFor index i = 2, there are 3 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 3 - 2 = 1.\nFor index i = 3, there are 4 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 4 - 1 = 3.\nFor index i = 4, there are 5 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 5 - 0 = 5.",
+            "Example 2:\nInput: nums = [3,2,3,4,2]\nOutput: [-2,-1,0,2,3]\nExplanation: For index i = 0, there is 1 element in the prefix and 3 distinct elements in the suffix. Thus, diff[0] = 1 - 3 = -2.\nFor index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1.\nFor index i = 2, there are 2 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 2 - 2 = 0.\nFor index i = 3, there are 3 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 3 - 1 = 2.\nFor index i = 4, there are 3 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 3 - 0 = 3."
+        ],
+        "constraints": "Constraints:\n\n1 <= n == nums.length\u00a0<= 50\n1 <= nums[i] <= 50",
+        "tags": [
+            "Array",
+            "Hash Table"
+        ],
+        "title-slug": "find-the-distinct-difference-array"
+    },
+    {
+        "leetcode-id": 2671,
+        "title": "Frequency Tracker",
+        "difficulty": 2,
+        "description": "Design a data structure that keeps track of the values in it and answers some queries regarding their frequencies.\nImplement the FrequencyTracker class.\n\nFrequencyTracker(): Initializes the FrequencyTracker object with an empty array initially.\nvoid add(int number): Adds number to the data structure.\nvoid deleteOne(int number): Deletes one occurrence of number from the data structure. The data structure may not contain number, and in this case nothing is deleted.\nbool hasFrequency(int frequency): Returns true if there is a number in the data structure that occurs frequency number of times, otherwise, it returns false.",
+        "examples": [
+            "Example 1:\nInput\n[\"FrequencyTracker\", \"add\", \"add\", \"hasFrequency\"]\n[[], [3], [3], [2]]\nOutput\n[null, null, null, true]\n\nExplanation\nFrequencyTracker frequencyTracker = new FrequencyTracker();\nfrequencyTracker.add(3); // The data structure now contains [3]\nfrequencyTracker.add(3); // The data structure now contains [3, 3]\nfrequencyTracker.hasFrequency(2); // Returns true, because 3 occurs twice",
+            "Example 2:\nInput\n[\"FrequencyTracker\", \"add\", \"deleteOne\", \"hasFrequency\"]\n[[], [1], [1], [1]]\nOutput\n[null, null, null, false]\n\nExplanation\nFrequencyTracker frequencyTracker = new FrequencyTracker();\nfrequencyTracker.add(1); // The data structure now contains [1]\nfrequencyTracker.deleteOne(1); // The data structure becomes empty []\nfrequencyTracker.hasFrequency(1); // Returns false, because the data structure is empty",
+            "Example 3:\nInput\n[\"FrequencyTracker\", \"hasFrequency\", \"add\", \"hasFrequency\"]\n[[], [2], [3], [1]]\nOutput\n[null, false, null, true]\n\nExplanation\nFrequencyTracker frequencyTracker = new FrequencyTracker();\nfrequencyTracker.hasFrequency(2); // Returns false, because the data structure is empty\nfrequencyTracker.add(3); // The data structure now contains [3]\nfrequencyTracker.hasFrequency(1); // Returns true, because 3 occurs once"
+        ],
+        "constraints": "Constraints:\n\n1 <= number <= 10^5\n1 <= frequency <= 10^5\nAt most, 2 *\u00a010^5\u00a0calls will be made to add, deleteOne, and hasFrequency\u00a0in total.",
+        "tags": [
+            "Hash Table",
+            "Design"
+        ],
+        "title-slug": "frequency-tracker"
+    },
+    {
+        "leetcode-id": 2672,
+        "title": "Number of Adjacent Elements With the Same Color",
+        "difficulty": 2,
+        "description": "There is a 0-indexed array nums of length n. Initially, all elements are uncolored (has a value of 0).\nYou are given a 2D integer array queries where queries[i] = [indexi, colori].\nFor each query, you color the index indexi with the color colori in the array nums.\nReturn an array answer of the same length as queries where answer[i] is the number of adjacent elements with the same color after the i^th query.\nMore formally, answer[i] is the number of indices j, such that 0 <= j < n - 1 and nums[j] == nums[j + 1] and nums[j] != 0 after the i^th query.",
+        "examples": [
+            "Example 1:\nInput: n = 4, queries = [[0,2],[1,2],[3,1],[1,1],[2,1]]\nOutput: [0,1,1,0,2]\nExplanation: Initially array nums = [0,0,0,0], where 0 denotes uncolored elements of the array.\n- After the 1^st query nums = [2,0,0,0]. The count of adjacent elements with the same color is 0.\n- After the 2^nd query nums = [2,2,0,0]. The count of adjacent elements with the same color is 1.\n- After the 3^rd\u00a0query nums = [2,2,0,1]. The count of adjacent elements with the same color is 1.\n- After the 4^th\u00a0query nums = [2,1,0,1]. The count of adjacent elements with the same color is 0.\n- After the 5^th\u00a0query nums = [2,1,1,1]. The count of adjacent elements with the same color is 2.",
+            "Example 2:\nInput: n = 1, queries = [[0,100000]]\nOutput: [0]\nExplanation: Initially array nums = [0], where 0 denotes uncolored elements of the array.\n- After the 1^st query nums = [100000]. The count of adjacent elements with the same color is 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^5\n1 <= queries.length <= 10^5\nqueries[i].length\u00a0== 2\n0 <= indexi\u00a0<= n - 1\n1 <=\u00a0 colori\u00a0<= 10^5",
+        "tags": [
+            "Array"
+        ],
+        "title-slug": "number-of-adjacent-elements-with-the-same-color"
+    },
+    {
+        "leetcode-id": 2673,
+        "title": "Make Costs of Paths Equal in a Binary Tree",
+        "difficulty": 2,
+        "description": "You are given an integer n representing the number of nodes in a perfect binary tree consisting of nodes numbered from 1 to n. The root of the tree is node 1 and each node i in the tree has two children where the left child is the node 2 * i and the right child is 2 * i + 1.\nEach node in the tree also has a cost represented by a given 0-indexed integer array cost of size n where cost[i] is the cost of node i + 1. You are allowed to increment the cost of any node by 1 any number of times.\nReturn the minimum number of increments you need to make the cost of paths from the root to each leaf node equal.\nNote:\n\nA perfect binary tree is a tree where each node, except the leaf nodes, has exactly 2 children.\nThe cost of a path is the sum of costs of nodes in the path.",
+        "examples": [
+            "Example 1:\nInput: n = 7, cost = [1,5,2,2,3,3,1]\nOutput: 6\nExplanation: We can do the following increments:\n- Increase the cost of node 4 one time.\n- Increase the cost of node 3 three times.\n- Increase the cost of node 7 two times.\nEach path from the root to a leaf will have a total cost of 9.\nThe total increments we did is 1 + 3 + 2 = 6.\nIt can be shown that this is the minimum answer we can achieve.",
+            "Example 2:\nInput: n = 3, cost = [5,3,3]\nOutput: 0\nExplanation: The two paths already have equal total costs, so no increments are needed."
+        ],
+        "constraints": "Constraints:\n\n3 <= n <= 10^5\nn + 1 is a power of 2\ncost.length == n\n1 <= cost[i] <= 10^4",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Greedy",
+            "Tree",
+            "Binary Tree"
+        ],
+        "title-slug": "make-costs-of-paths-equal-in-a-binary-tree"
+    },
+    {
+        "leetcode-id": 2678,
+        "title": "Number of Senior Citizens",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15. The system is such that:\n\nThe first ten characters consist of the phone number of passengers.\nThe next character denotes the gender of the person.\nThe following two characters are used to indicate the age of the person.\nThe last two characters determine the seat allotted to that person.\n\nReturn the number of passengers who are strictly more than 60 years old.",
+        "examples": [
+            "Example 1:\nInput: details = [\"7868190130M7522\",\"5303914400F9211\",\"9273338290F4010\"]\nOutput: 2\nExplanation: The passengers at indices 0, 1, and 2 have ages 75, 92, and 40. Thus, there are 2 people who are over 60 years old.",
+            "Example 2:\nInput: details = [\"1313579440F2036\",\"2921522980M5644\"]\nOutput: 0\nExplanation: None of the passengers are older than 60."
+        ],
+        "constraints": "Constraints:\n\n1 <= details.length <= 100\ndetails[i].length == 15\ndetails[i] consists of digits from '0' to '9'.\ndetails[i][10] is either 'M' or 'F' or 'O'.\nThe phone numbers and seat numbers of the passengers are distinct.",
+        "tags": [
+            "Array",
+            "String"
+        ],
+        "title-slug": "number-of-senior-citizens"
+    },
+    {
+        "leetcode-id": 2679,
+        "title": "Sum in a Matrix",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed 2D integer array nums. Initially, your score is 0. Perform the following operations until the matrix becomes empty:\n\nFrom each row in the matrix, select the largest number and remove it. In the case of a tie, it does not matter which number is chosen.\nIdentify the highest number amongst all those removed in step 1. Add that number to your score.\n\nReturn the final score.",
+        "examples": [
+            "Example 1:\nInput: nums = [[7,2,1],[6,4,2],[6,5,3],[3,2,1]]\nOutput: 15\nExplanation: In the first operation, we remove 7, 6, 6, and 3. We then add 7 to our score. Next, we remove 2, 4, 5, and 2. We add 5 to our score. Lastly, we remove 1, 2, 3, and 1. We add 3 to our score. Thus, our final score is 7 + 5 + 3 = 15.",
+            "Example 2:\nInput: nums = [[1]]\nOutput: 1\nExplanation: We remove 1 and add it to the answer. We return 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 300\n1 <= nums[i].length <= 500\n0 <= nums[i][j] <= 10^3",
+        "tags": [
+            "Array",
+            "Sorting",
+            "Heap (Priority Queue)",
+            "Matrix",
+            "Simulation"
+        ],
+        "title-slug": "sum-in-a-matrix"
+    },
+    {
+        "leetcode-id": 2680,
+        "title": "Maximum OR",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2.\nReturn the maximum possible value of nums[0] | nums[1] | ... | nums[n - 1] that can be obtained after applying the operation on nums at most k times.\nNote that a | b denotes the bitwise or between two integers a and b.",
+        "examples": [
+            "Example 1:\nInput: nums = [12,9], k = 1\nOutput: 30\nExplanation: If we apply the operation to index 1, our new array nums will be equal to [12,18]. Thus, we return the bitwise or of 12 and 18, which is 30.",
+            "Example 2:\nInput: nums = [8,1,2], k = 2\nOutput: 35\nExplanation: If we apply the operation twice on index 0, we yield a new array of [32,1,2]. Thus, we return 32|1|2 = 35."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\n1 <= k <= 15",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Bit Manipulation",
+            "Prefix Sum"
+        ],
+        "title-slug": "maximum-or"
+    },
+    {
+        "leetcode-id": 2681,
+        "title": "Power of Heroes",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed integer array nums representing the strength of some heroes. The power of a group of heroes is defined as follows:\n\nLet i0, i1, ... ,ik be the indices of the heroes in a group. Then, the power of this group is max(nums[i0], nums[i1], ... ,nums[ik])^2 * min(nums[i0], nums[i1], ... ,nums[ik]).\n\nReturn the sum of the power of all non-empty groups of heroes possible. Since the sum could be very large, return it modulo 10^9 + 7.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,1,4]\nOutput: 141\nExplanation: \n1^st\u00a0group: [2] has power = 2^2\u00a0* 2 = 8.\n2^nd\u00a0group: [1] has power = 1^2 * 1 = 1. \n3^rd\u00a0group: [4] has power = 4^2 * 4 = 64. \n4^th\u00a0group: [2,1] has power = 2^2 * 1 = 4. \n5^th\u00a0group: [2,4] has power = 4^2 * 2 = 32. \n6^th\u00a0group: [1,4] has power = 4^2 * 1 = 16. \n\u200b\u200b\u200b\u200b\u200b\u200b\u200b7^th\u00a0group: [2,1,4] has power = 4^2\u200b\u200b\u200b\u200b\u200b\u200b\u200b * 1 = 16. \nThe sum of powers of all groups is 8 + 1 + 64 + 4 + 32 + 16 + 16 = 141.",
+            "Example 2:\nInput: nums = [1,1,1]\nOutput: 7\nExplanation: A total of 7 groups are possible, and the power of each group will be 1. Therefore, the sum of the powers of all groups is 7."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Math",
+            "Sorting",
+            "Prefix Sum"
+        ],
+        "title-slug": "power-of-heroes"
+    },
+    {
+        "leetcode-id": 2682,
+        "title": "Find the Losers of the Circular Game",
+        "difficulty": 1,
+        "description": "There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the i^th friend brings you to the (i+1)^th friend for 1 <= i < n, and moving clockwise from the n^th friend brings you to the 1^st friend.\nThe rules of the game are as follows:\n1^st friend receives the ball.\n\nAfter that, 1^st friend passes it to the friend who is k steps away from them in the clockwise direction.\nAfter that, the friend who receives the ball should pass it to the friend who is 2 * k steps away from them in the clockwise direction.\nAfter that, the friend who receives the ball should pass it to the friend who is 3 * k steps away from them in the clockwise direction, and so on and so forth.\n\nIn other words, on the i^th turn, the friend holding the ball should pass it to the friend who is i * k steps away from them in the clockwise direction.\nThe game is finished when some friend receives the ball for the second time.\nThe losers of the game are friends who did not receive the ball in the entire game.\nGiven the number of friends, n, and an integer k, return the array answer, which contains the losers of the game in the ascending order.",
+        "examples": [
+            "Example 1:\nInput: n = 5, k = 2\nOutput: [4,5]\nExplanation: The game goes as follows:\n1) Start at 1^st\u00a0friend and pass the ball to the friend who is 2 steps away from them - 3^rd\u00a0friend.\n2) 3^rd\u00a0friend passes the ball to the friend who is 4 steps away from them - 2^nd\u00a0friend.\n3) 2^nd\u00a0friend passes the ball to the friend who is 6 steps away from them  - 3^rd\u00a0friend.\n4) The game ends as 3^rd\u00a0friend receives the ball for the second time.",
+            "Example 2:\nInput: n = 4, k = 4\nOutput: [2,3,4]\nExplanation: The game goes as follows:\n1) Start at the 1^st\u00a0friend and pass the ball to the friend who is 4 steps away from them - 1^st\u00a0friend.\n2) The game ends as 1^st\u00a0friend receives the ball for the second time."
+        ],
+        "constraints": "Constraints:\n\n1 <= k <= n <= 50",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Simulation"
+        ],
+        "title-slug": "find-the-losers-of-the-circular-game"
+    },
+    {
+        "leetcode-id": 2683,
+        "title": "Neighboring Bitwise XOR",
+        "difficulty": 2,
+        "description": "A 0-indexed array derived with length n is derived by computing the bitwise XOR\u00a0(\u2295) of adjacent values in a binary array original of length n.\nSpecifically, for each index i in the range [0, n - 1]:\n\nIf i = n - 1, then derived[i] = original[i] \u2295 original[0].\nOtherwise, derived[i] = original[i] \u2295 original[i + 1].\n\nGiven an array derived, your task is to determine whether there exists a valid binary array original that could have formed derived.\nReturn true if such an array exists or false otherwise.\n\nA binary array is an array containing only 0's and 1's",
+        "examples": [
+            "Example 1:\nInput: derived = [1,1,0]\nOutput: true\nExplanation: A valid original array that gives derived is [0,1,0].\nderived[0] = original[0] \u2295 original[1] = 0 \u2295 1 = 1 \nderived[1] = original[1] \u2295 original[2] = 1 \u2295 0 = 1\nderived[2] = original[2] \u2295 original[0] = 0 \u2295 0 = 0",
+            "Example 2:\nInput: derived = [1,1]\nOutput: true\nExplanation: A valid original array that gives derived is [0,1].\nderived[0] = original[0] \u2295 original[1] = 1\nderived[1] = original[1] \u2295 original[0] = 1",
+            "Example 3:\nInput: derived = [1,0]\nOutput: false\nExplanation: There is no valid original array that gives derived."
+        ],
+        "constraints": "Constraints:\n\nn == derived.length\n1 <= n\u00a0<= 10^5\nThe values in derived\u00a0are either 0's or 1's",
+        "tags": [
+            "Array",
+            "Bit Manipulation"
+        ],
+        "title-slug": "neighboring-bitwise-xor"
+    },
+    {
+        "leetcode-id": 2684,
+        "title": "Maximum Number of Moves in a Grid",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed m x n matrix grid consisting of positive integers.\nYou can start at any cell in the first column of the matrix, and traverse the grid in the following way:\n\nFrom a cell (row, col), you can move to any of the cells: (row - 1, col + 1), (row, col + 1) and (row + 1, col + 1) such that the value of the cell you move to, should be strictly bigger than the value of the current cell.\n\nReturn the maximum number of moves that you can perform.",
+        "examples": [
+            "Example 1:\nInput: grid = [[2,4,3,5],[5,4,9,3],[3,4,2,11],[10,9,13,15]]\nOutput: 3\nExplanation: We can start at the cell (0, 0) and make the following moves:\n- (0, 0) -> (0, 1).\n- (0, 1) -> (1, 2).\n- (1, 2) -> (2, 3).\nIt can be shown that it is the maximum number of moves that can be made.",
+            "Example 2:\nInput: grid = [[3,2,4],[2,1,9],[1,1,7]]\nOutput: 0\nExplanation: Starting from any cell in the first column we cannot perform any moves."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n2 <= m, n <= 1000\n4 <= m * n <= 10^5\n1 <= grid[i][j] <= 10^6",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Matrix"
+        ],
+        "title-slug": "maximum-number-of-moves-in-a-grid"
+    },
+    {
+        "leetcode-id": 2685,
+        "title": "Count the Number of Complete Components",
+        "difficulty": 2,
+        "description": "You are given an integer n. There is an undirected graph with n vertices, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting vertices ai and bi.\nReturn the number of complete connected components of the graph.\nA connected component is a subgraph of a graph in which there exists a path between any two vertices, and no vertex of the subgraph shares an edge with a vertex outside of the subgraph.\nA connected component is said to be complete if there exists an edge between every pair of its vertices.",
+        "examples": [
+            "Example 1:\nInput: n = 6, edges = [[0,1],[0,2],[1,2],[3,4]]\nOutput: 3\nExplanation: From the picture above, one can see that all of the components of this graph are complete.",
+            "Example 2:\nInput: n = 6, edges = [[0,1],[0,2],[1,2],[3,4],[3,5]]\nOutput: 1\nExplanation: The component containing vertices 0, 1, and 2 is complete since there is an edge between every pair of two vertices. On the other hand, the component containing vertices 3, 4, and 5 is not complete since there is no edge between vertices 4 and 5. Thus, the number of complete components in this graph is 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 50\n0 <= edges.length <= n * (n - 1) / 2\nedges[i].length == 2\n0 <= ai, bi <= n - 1\nai != bi\nThere are no repeated edges.",
+        "tags": [
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Graph"
+        ],
+        "title-slug": "count-the-number-of-complete-components"
+    },
+    {
+        "leetcode-id": 2696,
+        "title": "Minimum String Length After Removing Substrings",
+        "difficulty": 1,
+        "description": "You are given a string s consisting only of uppercase English letters.\nYou can apply some operations to this string where, in one operation, you can remove any occurrence of one of the substrings \"AB\" or \"CD\" from s.\nReturn the minimum possible length of the resulting string that you can obtain.\nNote that the string concatenates after removing the substring and could produce new \"AB\" or \"CD\" substrings.",
+        "examples": [
+            "Example 1:\nInput: s = \"ABFCACDB\"\nOutput: 2\nExplanation: We can do the following operations:\n- Remove the substring \"ABFCACDB\", so s = \"FCACDB\".\n- Remove the substring \"FCACDB\", so s = \"FCAB\".\n- Remove the substring \"FCAB\", so s = \"FC\".\nSo the resulting length of the string is 2.\nIt can be shown that it is the minimum length that we can obtain.",
+            "Example 2:\nInput: s = \"ACBBD\"\nOutput: 5\nExplanation: We cannot do any operations on the string so the length remains the same."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 100\ns\u00a0consists only of uppercase English letters.",
+        "tags": [
+            "String",
+            "Stack",
+            "Simulation"
+        ],
+        "title-slug": "minimum-string-length-after-removing-substrings"
+    },
+    {
+        "leetcode-id": 2697,
+        "title": "Lexicographically Smallest Palindrome",
+        "difficulty": 1,
+        "description": "You are given a string s consisting of lowercase English letters, and you are allowed to perform operations on it. In one operation, you can replace a character in s with another lowercase English letter.\nYour task is to make s a palindrome with the minimum number of operations possible. If there are multiple palindromes that can be made using the minimum number of operations, make the lexicographically smallest one.\nA string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.\nReturn the resulting palindrome string.",
+        "examples": [
+            "Example 1:\nInput: s = \"egcfe\"\nOutput: \"efcfe\"\nExplanation: The minimum number of operations to make \"egcfe\" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is \"efcfe\", by changing 'g'.",
+            "Example 2:\nInput: s = \"abcd\"\nOutput: \"abba\"\nExplanation: The minimum number of operations to make \"abcd\" a palindrome is 2, and the lexicographically smallest palindrome string we can get by modifying two characters is \"abba\".",
+            "Example 3:\nInput: s = \"seven\"\nOutput: \"neven\"\nExplanation: The minimum number of operations to make \"seven\" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is \"neven\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 1000\ns\u00a0consists of only lowercase English letters.",
+        "tags": [
+            "Two Pointers",
+            "String"
+        ],
+        "title-slug": "lexicographically-smallest-palindrome"
+    },
+    {
+        "leetcode-id": 2698,
+        "title": "Find the Punishment Number of an Integer",
+        "difficulty": 2,
+        "description": "Given a positive integer n, return the punishment number of n.\nThe punishment number of n is defined as the sum of the squares of all integers i such that:\n\n1 <= i <= n\nThe decimal representation of i * i can be partitioned into contiguous substrings such that the sum of the integer values of these substrings equals i.",
+        "examples": [
+            "Example 1:\nInput: n = 10\nOutput: 182\nExplanation: There are exactly 3 integers i that satisfy the conditions in the statement:\n- 1 since 1 * 1 = 1\n- 9 since 9 * 9 = 81 and 81 can be partitioned into 8 + 1.\n- 10 since 10 * 10 = 100 and 100 can be partitioned into 10 + 0.\nHence, the punishment number of 10 is 1 + 81 + 100 = 182",
+            "Example 2:\nInput: n = 37\nOutput: 1478\nExplanation: There are exactly 4 integers i that satisfy the conditions in the statement:\n- 1 since 1 * 1 = 1. \n- 9 since 9 * 9 = 81 and 81 can be partitioned into 8 + 1. \n- 10 since 10 * 10 = 100 and 100 can be partitioned into 10 + 0. \n- 36 since 36 * 36 = 1296 and 1296 can be partitioned into 1 + 29 + 6.\nHence, the punishment number of 37 is 1 + 81 + 100 + 1296 = 1478"
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 1000",
+        "tags": [
+            "Math",
+            "Backtracking"
+        ],
+        "title-slug": "find-the-punishment-number-of-an-integer"
+    },
+    {
+        "leetcode-id": 2699,
+        "title": "Modify Graph Edge Weights",
+        "difficulty": 3,
+        "description": "You are given an undirected weighted connected graph containing n nodes labeled from 0 to n - 1, and an integer array edges where edges[i] = [ai, bi, wi] indicates that there is an edge between nodes ai and bi with weight wi.\nSome edges have a weight of -1 (wi = -1), while others have a positive weight (wi > 0).\nYour task is to modify all edges with a weight of -1 by assigning them positive integer values in the range [1, 2 * 10^9] so that the shortest distance between the nodes source and destination becomes equal to an integer target. If there are multiple modifications that make the shortest distance between source and destination equal to target, any of them will be considered correct.\nReturn an array containing all edges (even unmodified ones) in any order if it is possible to make the shortest distance from source to destination equal to target, or an empty array if it's impossible.\nNote: You are not allowed to modify the weights of edges with initial positive weights.",
+        "examples": [
+            "Example 1:\nInput: n = 5, edges = [[4,1,-1],[2,0,-1],[0,3,-1],[4,3,-1]], source = 0, destination = 1, target = 5\nOutput: [[4,1,1],[2,0,1],[0,3,3],[4,3,1]]\nExplanation: The graph above shows a possible modification to the edges, making the distance from 0 to 1 equal to 5.",
+            "Example 2:\nInput: n = 3, edges = [[0,1,-1],[0,2,5]], source = 0, destination = 2, target = 6\nOutput: []\nExplanation: The graph above contains the initial edges. It is not possible to make the distance from 0 to 2 equal to 6 by modifying the edge with weight -1. So, an empty array is returned.",
+            "Example 3:\nInput: n = 4, edges = [[1,0,4],[1,2,3],[2,3,5],[0,3,-1]], source = 0, destination = 2, target = 6\nOutput: [[1,0,4],[1,2,3],[2,3,5],[0,3,1]]\nExplanation: The graph above shows a modified graph having the shortest distance from 0 to 2 as 6."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 100\n1 <= edges.length <= n * (n - 1) / 2\nedges[i].length == 3\n0 <= ai, bi\u00a0<\u00a0n\nwi\u00a0= -1\u00a0or 1 <= wi\u00a0<= 10^7\nai\u00a0!=\u00a0bi\n0 <= source, destination < n\nsource != destination\n1 <= target <= 10^9\nThe graph is connected, and there are no self-loops or repeated edges",
+        "tags": [
+            "Graph",
+            "Heap (Priority Queue)",
+            "Shortest Path"
+        ],
+        "title-slug": "modify-graph-edge-weights"
+    },
+    {
+        "leetcode-id": 2706,
+        "title": "Buy Two Chocolates",
+        "difficulty": 1,
+        "description": "You are given an integer array prices representing the prices of various chocolates in a store. You are also given a single integer money, which represents your initial amount of money.\nYou must buy exactly two chocolates in such a way that you still have some non-negative leftover money. You would like to minimize the sum of the prices of the two chocolates you buy.\nReturn the amount of money you will have leftover after buying the two chocolates. If there is no way for you to buy two chocolates without ending up in debt, return money. Note that the leftover must be non-negative.",
+        "examples": [
+            "Example 1:\nInput: prices = [1,2,2], money = 3\nOutput: 0\nExplanation: Purchase the chocolates priced at 1 and 2 units respectively. You will have 3 - 3 = 0 units of money afterwards. Thus, we return 0.",
+            "Example 2:\nInput: prices = [3,2,3], money = 3\nOutput: 3\nExplanation: You cannot buy 2 chocolates without going in debt, so we return 3."
+        ],
+        "constraints": "Constraints:\n\n2 <= prices.length <= 50\n1 <= prices[i] <= 100\n1 <= money <= 100",
+        "tags": [
+            "Array",
+            "Sorting"
+        ],
+        "title-slug": "buy-two-chocolates"
+    },
+    {
+        "leetcode-id": 2707,
+        "title": "Extra Characters in a String",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary. There may be some extra characters in s which are not present in any of the substrings.\nReturn the minimum number of extra characters left over if you break up s optimally.",
+        "examples": [
+            "Example 1:\nInput: s = \"leetscode\", dictionary = [\"leet\",\"code\",\"leetcode\"]\nOutput: 1\nExplanation: We can break s in two substrings: \"leet\" from index 0 to 3 and \"code\" from index 5 to 8. There is only 1 unused character (at index 4), so we return 1.",
+            "Example 2:\nInput: s = \"sayhelloworld\", dictionary = [\"hello\",\"world\"]\nOutput: 3\nExplanation: We can break s in two substrings: \"hello\" from index 3 to 7 and \"world\" from index 8 to 12. The characters at indices 0, 1, 2 are not used in any substring and thus are considered as extra characters. Hence, we return 3."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 50\n1 <= dictionary.length <= 50\n1 <= dictionary[i].length <= 50\ndictionary[i]\u00a0and s consists of only lowercase English letters\ndictionary contains distinct words",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Dynamic Programming",
+            "Trie"
+        ],
+        "title-slug": "extra-characters-in-a-string"
+    },
+    {
+        "leetcode-id": 2708,
+        "title": "Maximum Strength of a Group",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums representing the score of students in an exam. The teacher would like to form one non-empty group of students with maximal strength, where the strength of a group of students of indices i0, i1, i2, ... , ik is defined as nums[i0] * nums[i1] * nums[i2] * ... * nums[ik\u200b].\nReturn the maximum strength of a group the teacher can create.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,-1,-5,2,5,-9]\nOutput: 1350\nExplanation: One way to form a group of maximal strength is to group the students at indices [0,2,3,4,5]. Their strength is 3 * (-5) * 2 * 5 * (-9) = 1350, which we can show is optimal.",
+            "Example 2:\nInput: nums = [-4,-5,-4]\nOutput: 20\nExplanation: Group the students at indices [0, 1] . Then, we\u2019ll have a resulting strength of 20. We cannot achieve greater strength."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 13\n-9 <= nums[i] <= 9",
+        "tags": [
+            "Array",
+            "Backtracking",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "maximum-strength-of-a-group"
+    },
+    {
+        "leetcode-id": 2709,
+        "title": "Greatest Common Divisor Traversal",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed integer array nums, and you are allowed to traverse between its indices. You can traverse between index i and index j, i != j, if and only if gcd(nums[i], nums[j]) > 1, where gcd is the greatest common divisor.\nYour task is to determine if for every pair of indices i and j in nums, where i < j, there exists a sequence of traversals that can take us from i to j.\nReturn true if it is possible to traverse between all such pairs of indices, or false otherwise.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,3,6]\nOutput: true\nExplanation: In this example, there are 3 possible pairs of indices: (0, 1), (0, 2), and (1, 2).\nTo go from index 0 to index 1, we can use the sequence of traversals 0 -> 2 -> 1, where we move from index 0 to index 2 because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1, and then move from index 2 to index 1 because gcd(nums[2], nums[1]) = gcd(6, 3) = 3 > 1.\nTo go from index 0 to index 2, we can just go directly because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1. Likewise, to go from index 1 to index 2, we can just go directly because gcd(nums[1], nums[2]) = gcd(3, 6) = 3 > 1.",
+            "Example 2:\nInput: nums = [3,9,5]\nOutput: false\nExplanation: No sequence of traversals can take us from index 0 to index 2 in this example. So, we return false.",
+            "Example 3:\nInput: nums = [4,3,12,8]\nOutput: true\nExplanation: There are 6 possible pairs of indices to traverse between: (0, 1), (0, 2), (0, 3), (1, 2), (1, 3), and (2, 3). A valid sequence of traversals exists for each pair, so we return true."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^5",
+        "tags": [
+            "Array",
+            "Math",
+            "Union Find",
+            "Number Theory"
+        ],
+        "title-slug": "greatest-common-divisor-traversal"
+    },
+    {
+        "leetcode-id": 2710,
+        "title": "Remove Trailing Zeros From a String",
+        "difficulty": 1,
+        "description": "Given a positive integer num represented as a string, return the integer num without trailing zeros as a string.",
+        "examples": [
+            "Example 1:\nInput: num = \"51230100\"\nOutput: \"512301\"\nExplanation: Integer \"51230100\" has 2 trailing zeros, we remove them and return integer \"512301\".",
+            "Example 2:\nInput: num = \"123\"\nOutput: \"123\"\nExplanation: Integer \"123\" has no trailing zeros, we return integer \"123\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= num.length <= 1000\nnum consists\u00a0of only digits.\nnum doesn't\u00a0have any leading zeros.",
+        "tags": [
+            "String"
+        ],
+        "title-slug": "remove-trailing-zeros-from-a-string"
+    },
+    {
+        "leetcode-id": 2711,
+        "title": "Difference of Number of Distinct Values on Diagonals",
+        "difficulty": 2,
+        "description": "Given a 0-indexed 2D grid of size m x n, you should find the matrix answer of size m x n.\nThe value of each cell (r, c) of the matrix answer is calculated in the following way:\n\nLet topLeft[r][c] be the number of distinct values in the top-left diagonal of the cell (r, c) in the matrix grid.\nLet bottomRight[r][c] be the number of distinct values in the bottom-right diagonal of the cell (r, c) in the matrix grid.\n\nThen answer[r][c] = |topLeft[r][c] - bottomRight[r][c]|.\nReturn the matrix answer.\nA matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix's end.\nA cell (r1, c1) belongs to the top-left diagonal of the cell (r, c), if both belong to the same diagonal and r1 < r. Similarly is defined bottom-right diagonal.",
+        "examples": [
+            "Example 1:\nInput: grid = [[1,2,3],[3,1,5],[3,2,1]]\nOutput: [[1,1,0],[1,0,1],[0,1,1]]\nExplanation: The 1^st diagram denotes the initial grid.\u00a0\nThe 2^nd diagram denotes a grid for cell (0,0), where blue-colored cells are cells on its bottom-right diagonal.\nThe 3^rd diagram denotes a grid for cell (1,2), where red-colored cells are cells on its top-left diagonal.\nThe 4^th diagram denotes a grid for cell (1,1), where blue-colored cells are cells on its bottom-right diagonal and red-colored cells are cells on its top-left diagonal.\n- The cell (0,0) contains [1,1] on its bottom-right diagonal and [] on its top-left diagonal. The answer is |1 - 0| = 1.\n- The cell (1,2) contains [] on its bottom-right diagonal and [2] on its top-left diagonal. The answer is |0 - 1| = 1.\n- The cell (1,1) contains [1] on its bottom-right diagonal and [1] on its top-left diagonal. The answer is |1 - 1| = 0.\nThe answers of other cells are similarly calculated.",
+            "Example 2:\nInput: grid = [[1]]\nOutput: [[0]]\nExplanation: - The cell (0,0) contains [] on its bottom-right diagonal and [] on its top-left diagonal. The answer is |0 - 0| = 0."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m, n, grid[i][j] <= 50",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Matrix"
+        ],
+        "title-slug": "difference-of-number-of-distinct-values-on-diagonals"
+    },
+    {
+        "leetcode-id": 2712,
+        "title": "Minimum Cost to Make All Characters Equal",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed binary string s of length n on which you can apply two types of operations:\n\nChoose an index i and invert all characters from\u00a0index 0 to index i\u00a0(both inclusive), with a cost of i + 1\nChoose an index i and invert all characters\u00a0from\u00a0index i to index n - 1\u00a0(both inclusive), with a cost of n - i\n\nReturn the minimum cost to make all characters of the string equal.\nInvert a character means\u00a0if its value is '0' it becomes '1' and vice-versa.",
+        "examples": [
+            "Example 1:\nInput: s = \"0011\"\nOutput: 2\nExplanation: Apply the second operation with i = 2 to obtain s = \"0000\" for a cost of 2. It can be shown that 2 is the minimum cost to make all characters equal.",
+            "Example 2:\nInput: s = \"010101\"\nOutput: 9\nExplanation: Apply the first operation with i = 2 to obtain s = \"101101\" for a cost of 3.\nApply the first operation with i = 1 to obtain s = \"011101\" for a cost of 2. \nApply the first operation with i = 0 to obtain s = \"111101\" for a cost of 1. \nApply the second operation with i = 4 to obtain s = \"111110\" for a cost of 2.\nApply the second operation with i = 5 to obtain s = \"111111\" for a cost of 1. \nThe total cost to make all characters equal is 9. It can be shown that 9 is the minimum cost to make all characters equal."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length == n <= 10^5\ns[i] is either '0' or '1'",
+        "tags": [
+            "String",
+            "Dynamic Programming",
+            "Greedy"
+        ],
+        "title-slug": "minimum-cost-to-make-all-characters-equal"
+    },
+    {
+        "leetcode-id": 2713,
+        "title": "Maximum Strictly Increasing Cells in a Matrix",
+        "difficulty": 3,
+        "description": "Given a 1-indexed\u00a0m x n integer matrix mat, you can select any cell in the matrix as your starting cell.\nFrom the starting cell, you can move to any other cell in the same row or column, but only if the value of the destination cell is strictly greater than the value of the current cell. You can repeat this process as many times as possible, moving from cell to cell until you can no longer make any moves.\nYour task is to find the maximum number of cells that you can visit in the matrix by starting from some cell.\nReturn an integer denoting the maximum number of cells that can be visited.",
+        "examples": [
+            "Example 1:\nInput: mat = [[3,1],[3,4]]\nOutput: 2\nExplanation: The image shows how we can visit 2 cells starting from row 1, column 2. It can be shown that we cannot visit more than 2 cells no matter where we start from, so the answer is 2.",
+            "Example 2:\nInput: mat = [[1,1],[1,1]]\nOutput: 1\nExplanation: Since the cells must be strictly increasing, we can only visit one cell in this example.",
+            "Example 3:\nInput: mat = [[3,1,6],[-9,5,7]]\nOutput: 4\nExplanation: The image above shows how we can visit 4 cells starting from row 2, column 1. It can be shown that we cannot visit more than 4 cells no matter where we start from, so the answer is 4."
+        ],
+        "constraints": "Constraints:\n\nm == mat.length\u00a0\nn == mat[i].length\u00a0\n1 <= m, n <= 10^5\n1 <= m * n <= 10^5\n-10^5\u00a0<= mat[i][j] <= 10^5",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Dynamic Programming",
+            "Memoization",
+            "Sorting",
+            "Matrix"
+        ],
+        "title-slug": "maximum-strictly-increasing-cells-in-a-matrix"
+    },
+    {
+        "leetcode-id": 2716,
+        "title": "Minimize String Length",
+        "difficulty": 1,
+        "description": "Given a 0-indexed string s, repeatedly perform the following operation any number of times:\n\nChoose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the left of i (if any) and the closest occurrence of c to the right of i (if any).\n\nYour task is to minimize the length of s by performing the above operation any number of times.\nReturn an integer denoting the length of the minimized string.",
+        "examples": [
+            "Example 1:\nInput: s = \"aaabc\"\nOutput: 3\nExplanation: In this example, s is \"aaabc\". We can start by selecting the character 'a' at index 1. We then remove the closest 'a' to the left of index 1, which is at index 0, and the closest 'a' to the right of index 1, which is at index 2. After this operation, the string becomes \"abc\". Any further operation we perform on the string will leave it unchanged. Therefore, the length of the minimized string is 3.",
+            "Example 2:\nInput: s = \"cbbd\"\nOutput: 3\nExplanation: For this we can start with character 'b' at index 1. There is no occurrence of 'b' to the left of index 1, but there is one to the right at index 2, so we delete the 'b' at index 2. The string becomes \"cbd\" and further operations will leave it unchanged. Hence, the minimized length is 3.",
+            "Example 3:\nInput: s = \"dddaaa\"\nOutput: 2\nExplanation: For this, we can start with the character 'd' at index 1. The closest occurrence of a 'd' to its left is at index 0, and the closest occurrence of a 'd' to its right is at index 2. We delete both index 0 and 2, so the string becomes \"daaa\". In the new string, we can select the character 'a' at index 2. The closest occurrence of an 'a' to its left is at index 1, and the closest occurrence of an 'a' to its right is at index 3. We delete both of them, and the string becomes \"da\". We cannot minimize this further, so the minimized length is 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 100\ns contains only lowercase English letters",
+        "tags": [
+            "Hash Table",
+            "String"
+        ],
+        "title-slug": "minimize-string-length"
+    },
+    {
+        "leetcode-id": 2717,
+        "title": "Semi-Ordered Permutation",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed permutation of n integers nums.\nA permutation is called semi-ordered if the first number equals 1 and the last number equals n. You can perform the below operation as many times as you want until you make nums a semi-ordered permutation:\n\nPick two adjacent elements in nums, then swap them.\n\nReturn the minimum number of operations to make nums a semi-ordered permutation.\nA permutation is a sequence of integers from 1 to n of length n containing each number exactly once.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,1,4,3]\nOutput: 2\nExplanation: We can make the permutation semi-ordered using these sequence of operations: \n1 - swap i = 0 and j = 1. The permutation becomes [1,2,4,3].\n2 - swap i = 2 and j = 3. The permutation becomes [1,2,3,4].\nIt can be proved that there is no sequence of less than two operations that make nums a semi-ordered permutation.",
+            "Example 2:\nInput: nums = [2,4,1,3]\nOutput: 3\nExplanation: We can make the permutation semi-ordered using these sequence of operations:\n1 - swap i = 1 and j = 2. The permutation becomes [2,1,4,3].\n2 - swap i = 0 and j = 1. The permutation becomes [1,2,4,3].\n3 - swap i = 2 and j = 3. The permutation becomes [1,2,3,4].\nIt can be proved that there is no sequence of less than three operations that make nums a semi-ordered permutation.",
+            "Example 3:\nInput: nums = [1,3,4,2,5]\nOutput: 0\nExplanation: The permutation is already a semi-ordered permutation."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length == n <= 50\n1 <= nums[i]\u00a0<= 50\nnums is a permutation.",
+        "tags": [
+            "Array",
+            "Simulation"
+        ],
+        "title-slug": "semi-ordered-permutation"
+    },
+    {
+        "leetcode-id": 2718,
+        "title": "Sum of Matrix After Queries",
+        "difficulty": 2,
+        "description": "You are given an integer n and a 0-indexed\u00a02D array queries where queries[i] = [typei, indexi, vali].\nInitially, there is a 0-indexed n x n matrix filled with 0's. For each query, you must apply one of the following changes:\n\nif typei == 0, set the values in the row with indexi to vali, overwriting any previous values.\nif typei == 1, set the values in the column with indexi to vali, overwriting any previous values.\n\nReturn the sum of integers in the matrix after all queries are applied.",
+        "examples": [
+            "Example 1:\nInput: n = 3, queries = [[0,0,1],[1,2,2],[0,2,3],[1,0,4]]\nOutput: 23\nExplanation: The image above describes the matrix after each query. The sum of the matrix after all queries are applied is 23.",
+            "Example 2:\nInput: n = 3, queries = [[0,0,4],[0,1,2],[1,0,1],[0,2,3],[1,2,1]]\nOutput: 17\nExplanation: The image above describes the matrix after each query. The sum of the matrix after all queries are applied is 17."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^4\n1 <= queries.length <= 5 * 10^4\nqueries[i].length == 3\n0 <= typei <= 1\n0 <= indexi\u00a0< n\n0 <= vali <= 10^5",
+        "tags": [
+            "Array",
+            "Hash Table"
+        ],
+        "title-slug": "sum-of-matrix-after-queries"
+    },
+    {
+        "leetcode-id": 2719,
+        "title": "Count of Integers",
+        "difficulty": 3,
+        "description": "You are given two numeric strings num1 and num2 and two integers max_sum and min_sum. We denote an integer x to be good if:\n\nnum1 <= x <= num2\nmin_sum <= digit_sum(x) <= max_sum.\n\nReturn the number of good integers. Since the answer may be large, return it modulo 10^9 + 7.\nNote that digit_sum(x) denotes the sum of the digits of x.",
+        "examples": [
+            "Example 1:\nInput: num1 = \"1\", num2 = \"12\", min_sum = 1, max_sum = 8\nOutput: 11\nExplanation: There are 11 integers whose sum of digits lies between 1 and 8 are 1,2,3,4,5,6,7,8,10,11, and 12. Thus, we return 11.",
+            "Example 2:\nInput: num1 = \"1\", num2 = \"5\", min_sum = 1, max_sum = 5\nOutput: 5\nExplanation: The 5 integers whose sum of digits lies between 1 and 5 are 1,2,3,4, and 5. Thus, we return 5."
+        ],
+        "constraints": "Constraints:\n\n1 <= num1 <= num2 <= 10^22\n1 <= min_sum <= max_sum <= 400",
+        "tags": [
+            "Math",
+            "String",
+            "Dynamic Programming"
+        ],
+        "title-slug": "count-of-integers"
+    },
+    {
+        "leetcode-id": 2729,
+        "title": "Check if The Number is Fascinating",
+        "difficulty": 1,
+        "description": "You are given an integer n that consists of exactly 3 digits.\nWe call the number n fascinating if, after the following modification, the resulting number contains all the digits from 1 to 9 exactly once and does not contain any 0's:\n\nConcatenate n with the numbers 2 * n and 3 * n.\n\nReturn true if n is fascinating, or false otherwise.\nConcatenating two numbers means joining them together. For example, the concatenation of 121 and 371 is 121371.",
+        "examples": [
+            "Example 1:\nInput: n = 192\nOutput: true\nExplanation: We concatenate the numbers n = 192 and 2 * n = 384 and 3 * n = 576. The resulting number is 192384576. This number contains all the digits from 1 to 9 exactly once.",
+            "Example 2:\nInput: n = 100\nOutput: false\nExplanation: We concatenate the numbers n = 100 and 2 * n = 200 and 3 * n = 300. The resulting number is 100200300. This number does not satisfy any of the conditions."
+        ],
+        "constraints": "Constraints:\n\n100 <= n <= 999",
+        "tags": [
+            "Hash Table",
+            "Math"
+        ],
+        "title-slug": "check-if-the-number-is-fascinating"
+    },
+    {
+        "leetcode-id": 2730,
+        "title": "Find the Longest Semi-Repetitive Substring",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed string s that consists of digits from 0 to 9.\nA string t is called a semi-repetitive if there is at most one consecutive pair of the same digits inside t. For example, 0010, 002020, 0123, 2002, and 54944 are semi-repetitive while\u00a000101022, and 1101234883 are not.\nReturn the length of the longest semi-repetitive substring inside s.\nA substring is a contiguous non-empty sequence of characters within a string.",
+        "examples": [
+            "Example 1:\nInput: s = \"52233\"\nOutput: 4\nExplanation: The longest semi-repetitive substring is \"5223\", which starts at i = 0 and ends at j = 3.",
+            "Example 2:\nInput: s = \"5494\"\nOutput: 4\nExplanation: s is a semi-reptitive string, so the answer is 4.",
+            "Example 3:\nInput: s = \"1111111\"\nOutput: 2\nExplanation: The longest semi-repetitive substring is \"11\", which starts at i = 0 and ends at j = 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 50\n'0' <= s[i] <= '9'",
+        "tags": [
+            "String",
+            "Sliding Window"
+        ],
+        "title-slug": "find-the-longest-semi-repetitive-substring"
+    },
+    {
+        "leetcode-id": 2731,
+        "title": "Movement of Robots",
+        "difficulty": 2,
+        "description": "Some robots are standing on an infinite number line with their initial coordinates given by a 0-indexed integer array nums and will start moving once given the command to move. The robots will move a unit distance each second.\nYou are given a string s denoting the direction in which robots will move on command. 'L' means the robot will move towards the left side or negative side of the number line, whereas 'R' means the robot will move towards the right side or positive side of the number line.\nIf two robots collide, they will start moving in opposite directions.\nReturn the sum of distances between all the\u00a0pairs of robots d seconds after\u00a0the command. Since the sum can be very large, return it modulo 10^9 + 7.\nNote: \n\nFor two robots at the index i and j, pair (i,j) and pair (j,i) are considered the same pair.\nWhen robots collide, they instantly change their directions without wasting any time.\nCollision happens\u00a0when two robots share the same place in a\u00a0moment.\n\t\nFor example, if a robot is positioned in 0 going to the right and another is positioned in 2 going to the left, the next second they'll be both in 1 and they will change direction and the next second the first one will be in 0, heading left, and another will be in 2, heading right.\nFor example,\u00a0if a robot is positioned in 0 going to the right and another is positioned in 1\u00a0going to the left, the next second the first one will be in 0, heading left, and another will be in 1, heading right.",
+        "examples": [
+            "Example 1:\nInput: nums = [-2,0,2], s = \"RLL\", d = 3\nOutput: 8\nExplanation: \nAfter 1 second, the positions are [-1,-1,1]. Now, the robot at index 0 will move left, and the robot at index 1 will move right.\nAfter 2 seconds, the positions are [-2,0,0]. Now, the robot at index 1 will move left, and the robot at index 2 will move right.\nAfter 3 seconds, the positions are [-3,-1,1].\nThe distance between the robot at index 0 and 1 is abs(-3 - (-1)) = 2.\nThe distance between the robot at index 0 and 2 is abs(-3 - 1) = 4.\nThe distance between the robot at index 1 and 2 is abs(-1 - 1) = 2.\nThe sum of the pairs of all distances = 2 + 4 + 2 = 8.",
+            "Example 2:\nInput: nums = [1,0], s = \"RL\", d = 2\nOutput: 5\nExplanation: \nAfter 1 second, the positions are [2,-1].\nAfter 2 seconds, the positions are [3,-2].\nThe distance between the two robots is abs(-2 - 3) = 5."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 10^5\n-2 * 10^9\u00a0<= nums[i] <= 2 * 10^9\n0 <= d <= 10^9\nnums.length == s.length\u00a0\ns consists of 'L' and 'R' only\nnums[i]\u00a0will be unique.",
+        "tags": [
+            "Array",
+            "Brainteaser",
+            "Sorting",
+            "Prefix Sum"
+        ],
+        "title-slug": "movement-of-robots"
+    },
+    {
+        "leetcode-id": 2732,
+        "title": "Find a Good Subset of the Matrix",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed m x n binary matrix grid.\nLet us call a non-empty subset of rows good if the sum of each column of the subset is at most half of the length of the subset.\nMore formally, if the length of the chosen subset of rows is k, then the sum of each column should be at most floor(k / 2).\nReturn an integer array that contains row indices of a good subset sorted in ascending order.\nIf there are multiple good subsets, you can return any of them. If there are no good subsets, return an empty array.\nA subset of rows of the matrix grid is any matrix that can be obtained by deleting some (possibly none or all) rows from grid.",
+        "examples": [
+            "Example 1:\nInput: grid = [[0,1,1,0],[0,0,0,1],[1,1,1,1]]\nOutput: [0,1]\nExplanation: We can choose the 0^th and 1^st rows to create a good subset of rows.\nThe length of the chosen subset is 2.\n- The sum of the 0^th\u00a0column is 0 + 0 = 0, which is at most half of the length of the subset.\n- The sum of the 1^st\u00a0column is 1 + 0 = 1, which is at most half of the length of the subset.\n- The sum of the 2^nd\u00a0column is 1 + 0 = 1, which is at most half of the length of the subset.\n- The sum of the 3^rd\u00a0column is 0 + 1 = 1, which is at most half of the length of the subset.",
+            "Example 2:\nInput: grid = [[0]]\nOutput: [0]\nExplanation: We can choose the 0^th row to create a good subset of rows.\nThe length of the chosen subset is 1.\n- The sum of the 0^th\u00a0column is 0, which is at most half of the length of the subset.",
+            "Example 3:\nInput: grid = [[1,1,1],[1,1,1]]\nOutput: []\nExplanation: It is impossible to choose any subset of rows to create a good subset."
+        ],
+        "constraints": "Constraints:\n\nm == grid.length\nn == grid[i].length\n1 <= m <= 10^4\n1 <= n <= 5\ngrid[i][j] is either 0 or 1.",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Bit Manipulation",
+            "Matrix"
+        ],
+        "title-slug": "find-a-good-subset-of-the-matrix"
+    },
+    {
+        "leetcode-id": 2733,
+        "title": "Neither Minimum nor Maximum",
+        "difficulty": 1,
+        "description": "Given an integer array nums containing distinct positive integers, find and return any number from the array that is neither the minimum nor the maximum value in the array, or -1 if there is no such number.\nReturn the selected integer.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,2,1,4]\nOutput: 2\nExplanation: In this example, the minimum value is 1 and the maximum value is 4. Therefore, either 2 or 3 can be valid answers.",
+            "Example 2:\nInput: nums = [1,2]\nOutput: -1\nExplanation: Since there is no number in nums that is neither the maximum nor the minimum, we cannot select a number that satisfies the given condition. Therefore, there is no answer.",
+            "Example 3:\nInput: nums = [2,1,3]\nOutput: 2\nExplanation: Since 2 is neither the maximum nor the minimum value in nums, it is the only valid answer."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100\nAll values in nums are distinct",
+        "tags": [
+            "Array",
+            "Sorting"
+        ],
+        "title-slug": "neither-minimum-nor-maximum"
+    },
+    {
+        "leetcode-id": 2734,
+        "title": "Lexicographically Smallest String After Substring Operation",
+        "difficulty": 2,
+        "description": "You are given a string s consisting of only lowercase English letters. In one operation, you can do the following:\n\nSelect any non-empty substring of s, possibly the entire string, then replace each one of its characters with the previous character of the English alphabet. For example, 'b' is converted to 'a', and 'a' is converted to 'z'.\n\nReturn the lexicographically smallest string you can obtain after performing the above operation exactly once.\nA substring is a contiguous sequence of characters in a string.\nA string x is lexicographically smaller than a string y of the same length if x[i] comes before y[i] in alphabetic order for the first position i such that x[i] != y[i].",
+        "examples": [
+            "Example 1:\nInput: s = \"cbabc\"\nOutput: \"baabc\"\nExplanation: We apply the operation on the substring starting at index 0, and ending at index 1 inclusive. \nIt can be proven that the resulting string is the lexicographically smallest.",
+            "Example 2:\nInput: s = \"acbbc\"\nOutput: \"abaab\"\nExplanation: We apply the operation on the substring starting at index 1, and ending at index 4 inclusive. \nIt can be proven that the resulting string is the lexicographically smallest.",
+            "Example 3:\nInput: s = \"leetcode\"\nOutput: \"kddsbncd\"\nExplanation: We apply the operation on the entire string. \nIt can be proven that the resulting string is the lexicographically smallest."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 3 * 10^5\ns consists of lowercase English letters",
+        "tags": [
+            "String",
+            "Greedy"
+        ],
+        "title-slug": "lexicographically-smallest-string-after-substring-operation"
+    },
+    {
+        "leetcode-id": 2735,
+        "title": "Collecting Chocolates",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums of size n representing the cost of collecting different chocolates. The cost of collecting the chocolate at the index i\u00a0is nums[i]. Each chocolate is of a different type, and initially, the chocolate at the index\u00a0i\u00a0is of i^th type.\nIn one operation, you can do the following with an incurred cost of x:\n\nSimultaneously change the chocolate of i^th type to ((i + 1) mod n)^th type for all chocolates.\n\nReturn the minimum cost to collect chocolates of all types, given that you can perform as many operations as you would like.",
+        "examples": [
+            "Example 1:\nInput: nums = [20,1,15], x = 5\nOutput: 13\nExplanation: Initially, the chocolate types are [0,1,2]. We will buy the 1^st\u00a0type of chocolate at a cost of 1.\nNow, we will perform the operation at a cost of 5, and the types of chocolates will become [1,2,0]. We will buy the 2^nd^ type of chocolate at a cost of 1.\nNow, we will again perform the operation at a cost of 5, and the chocolate types will become [2,0,1]. We will buy the 0^th type of chocolate at a cost of 1. \nThus, the total cost will become (1 + 5 + 1 + 5 + 1) = 13. We can prove that this is optimal.",
+            "Example 2:\nInput: nums = [1,2,3], x = 4\nOutput: 6\nExplanation: We will collect all three types of chocolates at their own price without performing any operations. Therefore, the total cost is 1 + 2 + 3 = 6."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 10^9\n1 <= x <= 10^9",
+        "tags": [
+            "Array",
+            "Enumeration"
+        ],
+        "title-slug": "collecting-chocolates"
+    },
+    {
+        "leetcode-id": 2736,
+        "title": "Maximum Sum Queries",
+        "difficulty": 3,
+        "description": "You are given two 0-indexed integer arrays nums1 and nums2, each of length n, and a 1-indexed 2D array queries where queries[i] = [xi, yi].\nFor the i^th query, find the maximum value of nums1[j] + nums2[j] among all indices j (0 <= j < n), where nums1[j] >= xi and nums2[j] >= yi, or -1 if there is no j satisfying the constraints.\nReturn an array answer where answer[i] is the answer to the i^th query.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [4,3,1,2], nums2 = [2,4,9,5], queries = [[4,1],[1,3],[2,5]]\nOutput: [6,10,7]\nExplanation: \nFor the 1st query xi = 4\u00a0and\u00a0yi = 1, we can select index\u00a0j = 0\u00a0since\u00a0nums1[j] >= 4\u00a0and\u00a0nums2[j] >= 1. The sum\u00a0nums1[j] + nums2[j]\u00a0is 6, and we can show that 6 is the maximum we can obtain.\n\nFor the 2nd query xi = 1\u00a0and\u00a0yi = 3, we can select index\u00a0j = 2\u00a0since\u00a0nums1[j] >= 1\u00a0and\u00a0nums2[j] >= 3. The sum\u00a0nums1[j] + nums2[j]\u00a0is 10, and we can show that 10 is the maximum we can obtain. \n\nFor the 3rd query xi = 2\u00a0and\u00a0yi = 5, we can select index\u00a0j = 3\u00a0since\u00a0nums1[j] >= 2\u00a0and\u00a0nums2[j] >= 5. The sum\u00a0nums1[j] + nums2[j]\u00a0is 7, and we can show that 7 is the maximum we can obtain.\n\nTherefore, we return\u00a0[6,10,7].",
+            "Example 2:\nInput: nums1 = [3,2,5], nums2 = [2,3,4], queries = [[4,4],[3,2],[1,1]]\nOutput: [9,9,9]\nExplanation: For this example, we can use index\u00a0j = 2\u00a0for all the queries since it satisfies the constraints for each query.",
+            "Example 3:\nInput: nums1 = [2,1], nums2 = [2,3], queries = [[3,3]]\nOutput: [-1]\nExplanation: There is one query in this example with xi = 3 and yi = 3. For every index, j, either nums1[j] < xi or nums2[j] < yi. Hence, there is no solution."
+        ],
+        "constraints": "Constraints:\n\nnums1.length == nums2.length\u00a0\nn ==\u00a0nums1.length\u00a0\n1 <= n <= 10^5\n1 <= nums1[i], nums2[i] <= 10^9\u00a0\n1 <= queries.length <= 10^5\nqueries[i].length ==\u00a02\nxi\u00a0== queries[i][1]\nyi == queries[i][2]\n1 <= xi, yi <= 10^9",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Stack",
+            "Binary Indexed Tree",
+            "Segment Tree",
+            "Sorting",
+            "Monotonic Stack"
+        ],
+        "title-slug": "maximum-sum-queries"
+    },
+    {
+        "leetcode-id": 2739,
+        "title": "Total Distance Traveled",
+        "difficulty": 1,
+        "description": "A truck has two fuel tanks. You are given two integers, mainTank representing the fuel present in the main tank in liters and additionalTank representing the fuel present in the additional tank in liters.\nThe truck has a mileage of 10 km per liter. Whenever 5 liters of fuel get\u00a0used up in the main tank,\u00a0if the additional tank has at least 1 liters of fuel, 1 liters of fuel will be transferred from the additional tank to the main tank.\nReturn the maximum distance which can be traveled.\nNote: Injection from the additional tank is not continuous. It happens suddenly and immediately for every 5 liters consumed.",
+        "examples": [
+            "Example 1:\nInput: mainTank = 5, additionalTank = 10\nOutput: 60\nExplanation: \nAfter spending 5 litre of fuel, fuel remaining is (5 - 5 + 1) = 1 litre and distance traveled is 50km.\nAfter spending another 1 litre of fuel, no fuel gets injected in the main tank and the main tank becomes empty.\nTotal distance traveled is 60km.",
+            "Example 2:\nInput: mainTank = 1, additionalTank = 2\nOutput: 10\nExplanation: \nAfter spending 1 litre of fuel, the main tank becomes empty.\nTotal distance traveled is 10km."
+        ],
+        "constraints": "Constraints:\n\n1 <= mainTank, additionalTank <= 100",
+        "tags": [
+            "Math",
+            "Simulation"
+        ],
+        "title-slug": "total-distance-traveled"
+    },
+    {
+        "leetcode-id": 2740,
+        "title": "Find the Value of the Partition",
+        "difficulty": 2,
+        "description": "You are given a positive integer array nums.\nPartition nums into two arrays,\u00a0nums1 and nums2, such that:\n\nEach element of the array nums belongs to either the array nums1 or the array nums2.\nBoth arrays are non-empty.\nThe value of the partition is minimized.\n\nThe value of the partition is |max(nums1) - min(nums2)|.\nHere, max(nums1) denotes the maximum element of the array nums1, and min(nums2) denotes the minimum element of the array nums2.\nReturn the integer denoting the value of such partition.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,2,4]\nOutput: 1\nExplanation: We can partition the array nums into nums1 = [1,2] and nums2 = [3,4].\n- The maximum element of the array nums1 is equal to 2.\n- The minimum element of the array nums2 is equal to 3.\nThe value of the partition is |2 - 3| = 1. \nIt can be proven that 1 is the minimum value out of all partitions.",
+            "Example 2:\nInput: nums = [100,1,10]\nOutput: 9\nExplanation: We can partition the array nums into nums1 = [10] and nums2 = [100,1].\n- The maximum element of the array nums1 is equal to 10.\n- The minimum element of the array nums2 is equal to 1.\nThe value of the partition is |10 - 1| = 9.\nIt can be proven that 9 is the minimum value out of all partitions."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Sorting"
+        ],
+        "title-slug": "find-the-value-of-the-partition"
+    },
+    {
+        "leetcode-id": 2741,
+        "title": "Special Permutations",
+        "difficulty": 2,
+        "description": "You are given a\u00a00-indexed\u00a0integer array\u00a0nums\u00a0containing\u00a0n\u00a0distinct positive integers. A permutation of\u00a0nums\u00a0is called special if:\n\nFor all indexes\u00a00 <= i < n - 1, either\u00a0nums[i] % nums[i+1] == 0\u00a0or\u00a0nums[i+1] % nums[i] == 0.\n\nReturn\u00a0the total number of special permutations.\u00a0As the answer could be large, return it\u00a0modulo\u00a010^9\u00a0+ 7.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,3,6]\nOutput: 2\nExplanation: [3,6,2] and [2,6,3] are the two special permutations of nums.",
+            "Example 2:\nInput: nums = [1,4,3]\nOutput: 2\nExplanation: [3,1,4] and [4,1,3] are the two special permutations of nums."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 14\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Bit Manipulation",
+            "Bitmask"
+        ],
+        "title-slug": "special-permutations"
+    },
+    {
+        "leetcode-id": 2742,
+        "title": "Painting the Walls",
+        "difficulty": 3,
+        "description": "You are given two 0-indexed integer arrays,\u00a0cost and time, of size n representing the costs and the time taken to paint n different walls respectively. There are two painters available:\n\nA\u00a0paid painter\u00a0that paints the i^th wall in time[i] units of time and takes cost[i] units of money.\nA\u00a0free painter that paints\u00a0any wall in 1 unit of time at a cost of 0. But the\u00a0free painter can only be used if the paid painter is already occupied.\n\nReturn the minimum amount of money required to paint the n\u00a0walls.",
+        "examples": [
+            "Example 1:\nInput: cost = [1,2,3,2], time = [1,2,3,2]\nOutput: 3\nExplanation: The walls at index 0 and 1 will be painted by the paid painter, and it will take 3 units of time; meanwhile, the free painter will paint the walls at index 2 and 3, free of cost in 2 units of time. Thus, the total cost is 1 + 2 = 3.",
+            "Example 2:\nInput: cost = [2,3,4,2], time = [1,1,1,1]\nOutput: 4\nExplanation: The walls at index 0 and 3 will be painted by the paid painter, and it will take 2 units of time; meanwhile, the free painter will paint the walls at index 1 and 2, free of cost in 2 units of time. Thus, the total cost is 2 + 2 = 4."
+        ],
+        "constraints": "Constraints:\n\n1 <= cost.length <= 500\ncost.length == time.length\n1 <= cost[i] <= 10^6\n1 <= time[i] <= 500",
+        "tags": [
+            "Array",
+            "Dynamic Programming"
+        ],
+        "title-slug": "painting-the-walls"
+    },
+    {
+        "leetcode-id": 2744,
+        "title": "Find Maximum Number of String Pairs",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed array words consisting of distinct strings.\nThe string words[i] can be paired with the string words[j] if:\n\nThe string words[i] is equal to the reversed string of words[j].\n0 <= i < j < words.length.\n\nReturn the maximum number of pairs that can be formed from the array words.\nNote that\u00a0each string can belong in\u00a0at most one pair.",
+        "examples": [
+            "Example 1:\nInput: words = [\"cd\",\"ac\",\"dc\",\"ca\",\"zz\"]\nOutput: 2\nExplanation: In this example, we can form 2 pair of strings in the following way:\n- We pair the 0^th string with the 2^nd string, as the reversed string of word[0] is \"dc\" and is equal to words[2].\n- We pair the 1^st string with the 3^rd string, as the reversed string of word[1] is \"ca\" and is equal to words[3].\nIt can be proven that 2 is the maximum number of pairs that can be formed.",
+            "Example 2:\nInput: words = [\"ab\",\"ba\",\"cc\"]\nOutput: 1\nExplanation: In this example, we can form 1 pair of strings in the following way:\n- We pair the 0^th string with the 1^st string, as the reversed string of words[1] is \"ab\" and is equal to words[0].\nIt can be proven that 1 is the maximum number of pairs that can be formed.",
+            "Example 3:\nInput: words = [\"aa\",\"ab\"]\nOutput: 0\nExplanation: In this example, we are unable to form any pair of strings."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 50\nwords[i].length == 2\nwords\u00a0consists of distinct strings.\nwords[i]\u00a0contains only lowercase English letters.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Simulation"
+        ],
+        "title-slug": "find-maximum-number-of-string-pairs"
+    },
+    {
+        "leetcode-id": 2745,
+        "title": "Construct the Longest New String",
+        "difficulty": 2,
+        "description": "You are given three integers x, y, and z.\nYou have x strings equal to \"AA\", y strings equal to \"BB\", and z strings equal to \"AB\". You want to choose some (possibly all or none) of these strings and concactenate them in some order to form a new string. This new string must not contain \"AAA\" or \"BBB\" as a substring.\nReturn the maximum possible length of the new string.\nA substring is a contiguous non-empty sequence of characters within a string.",
+        "examples": [
+            "Example 1:\nInput: x = 2, y = 5, z = 1\nOutput: 12\nExplanation: We can concactenate the strings \"BB\", \"AA\", \"BB\", \"AA\", \"BB\", and \"AB\" in that order. Then, our new string is \"BBAABBAABBAB\". \nThat string has length 12, and we can show that it is impossible to construct a string of longer length.",
+            "Example 2:\nInput: x = 3, y = 2, z = 2\nOutput: 14\nExplanation: We can concactenate the strings \"AB\", \"AB\", \"AA\", \"BB\", \"AA\", \"BB\", and \"AA\" in that order. Then, our new string is \"ABABAABBAABBAA\". \nThat string has length 14, and we can show that it is impossible to construct a string of longer length."
+        ],
+        "constraints": "Constraints:\n\n1 <= x, y, z <= 50",
+        "tags": [
+            "Math",
+            "Greedy",
+            "Brainteaser"
+        ],
+        "title-slug": "construct-the-longest-new-string"
+    },
+    {
+        "leetcode-id": 2746,
+        "title": "Decremental String Concatenation",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array words containing n strings.\nLet's define a join operation join(x, y) between two strings x and y as concatenating them into xy. However, if the last character of x is equal to the first character of y, one of them is deleted.\nFor example join(\"ab\", \"ba\") = \"aba\" and join(\"ab\", \"cde\") = \"abcde\".\nYou are to perform n - 1 join operations. Let str0 = words[0]. Starting from i = 1 up to i = n - 1, for the i^th operation, you can do one of the following:\n\nMake stri = join(stri - 1, words[i])\nMake stri = join(words[i], stri - 1)\n\nYour task is to minimize the length of strn - 1.\nReturn an integer denoting the minimum possible length of strn - 1.",
+        "examples": [
+            "Example 1:\nInput: words = [\"aa\",\"ab\",\"bc\"]\nOutput: 4\nExplanation: In this example, we can perform join operations in the following order to minimize the length of str2: \nstr0 = \"aa\"\nstr1 = join(str0, \"ab\") = \"aab\"\nstr2 = join(str1, \"bc\") = \"aabc\" \nIt can be shown that the minimum possible length of str2 is 4.",
+            "Example 2:\nInput: words = [\"ab\",\"b\"]\nOutput: 2\nExplanation: In this example, str0 = \"ab\", there are two ways to get str1: \njoin(str0, \"b\") = \"ab\" or join(\"b\", str0) = \"bab\". \nThe first string, \"ab\", has the minimum length. Hence, the answer is 2.",
+            "Example 3:\nInput: words = [\"aaa\",\"c\",\"aba\"]\nOutput: 6\nExplanation: In this example, we can perform join operations in the following order to minimize the length of str2: \nstr0 = \"aaa\"\nstr1 = join(str0, \"c\") = \"aaac\"\nstr2 = join(\"aba\", str1) = \"abaaac\"\nIt can be shown that the minimum possible length of str2 is 6."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 1000\n1 <= words[i].length <= 50\nEach character in words[i] is an English lowercase letter",
+        "tags": [
+            "Array",
+            "String",
+            "Dynamic Programming"
+        ],
+        "title-slug": "decremental-string-concatenation"
+    },
+    {
+        "leetcode-id": 2747,
+        "title": "Count Zero Request Servers",
+        "difficulty": 2,
+        "description": "You are given an integer n denoting the total number of servers and a 2D 0-indexed integer array logs, where logs[i] = [server_id, time] denotes that the server with id server_id received a request at time time.\nYou are also given an integer x and a 0-indexed integer array queries.\nReturn a 0-indexed integer array arr of length queries.length where arr[i] represents the number of servers that did not receive any requests during the time interval [queries[i] - x, queries[i]].\nNote that the time intervals are inclusive.",
+        "examples": [
+            "Example 1:\nInput: n = 3, logs = [[1,3],[2,6],[1,5]], x = 5, queries = [10,11]\nOutput: [1,2]\nExplanation: \nFor queries[0]: The servers with ids 1 and 2 get requests in the duration of [5, 10]. Hence, only server 3 gets zero requests.\nFor queries[1]: Only the server with id 2 gets a request in duration of [6,11]. Hence, the servers with ids 1 and 3 are the only servers that do not receive any requests during that time period.",
+            "Example 2:\nInput: n = 3, logs = [[2,4],[2,1],[1,2],[3,1]], x = 2, queries = [3,4]\nOutput: [0,1]\nExplanation: \nFor queries[0]: All servers get at least one request in the duration of [1, 3].\nFor queries[1]: Only server with id 3 gets no request in the duration [2,4]."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^5\n1 <= logs.length <= 10^5\n1 <= queries.length <= 10^5\nlogs[i].length == 2\n1 <= logs[i][0] <= n\n1 <= logs[i][1] <= 10^6\n1 <= x <= 10^5\nx <\u00a0queries[i]\u00a0<= 10^6",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sliding Window",
+            "Sorting"
+        ],
+        "title-slug": "count-zero-request-servers"
+    },
+    {
+        "leetcode-id": 2748,
+        "title": "Number of Beautiful Pairs",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums. A pair of indices i, j where 0 <=\u00a0i < j < nums.length is called beautiful if the first digit of nums[i] and the last digit of nums[j] are coprime.\nReturn the total number of beautiful pairs in nums.\nTwo integers x and y are coprime if there is no integer greater than 1 that divides both of them. In other words, x and y are coprime if gcd(x, y) == 1, where gcd(x, y) is the greatest common divisor of x and y.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,5,1,4]\nOutput: 5\nExplanation: There are 5 beautiful pairs in nums:\nWhen i = 0 and j = 1: the first digit of nums[0] is 2, and the last digit of nums[1] is 5. We can confirm that 2 and 5 are coprime, since gcd(2,5) == 1.\nWhen i = 0 and j = 2: the first digit of nums[0] is 2, and the last digit of nums[2] is 1. Indeed, gcd(2,1) == 1.\nWhen i = 1 and j = 2: the first digit of nums[1] is 5, and the last digit of nums[2] is 1. Indeed, gcd(5,1) == 1.\nWhen i = 1 and j = 3: the first digit of nums[1] is 5, and the last digit of nums[3] is 4. Indeed, gcd(5,4) == 1.\nWhen i = 2 and j = 3: the first digit of nums[2] is 1, and the last digit of nums[3] is 4. Indeed, gcd(1,4) == 1.\nThus, we return 5.",
+            "Example 2:\nInput: nums = [11,21,12]\nOutput: 2\nExplanation: There are 2 beautiful pairs:\nWhen i = 0 and j = 1: the first digit of nums[0] is 1, and the last digit of nums[1] is 1. Indeed, gcd(1,1) == 1.\nWhen i = 0 and j = 2: the first digit of nums[0] is 1, and the last digit of nums[2] is 2. Indeed, gcd(1,2) == 1.\nThus, we return 2."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 100\n1 <= nums[i] <= 9999\nnums[i] % 10 != 0",
+        "tags": [
+            "Array",
+            "Math",
+            "Number Theory"
+        ],
+        "title-slug": "number-of-beautiful-pairs"
+    },
+    {
+        "leetcode-id": 2749,
+        "title": "Minimum Operations to Make the Integer Zero",
+        "difficulty": 2,
+        "description": "You are given two integers num1 and num2.\nIn one operation, you can choose integer i in the range [0, 60] and subtract 2^i + num2 from num1.\nReturn the integer denoting the minimum number of operations needed to make num1 equal to 0.\nIf it is impossible to make num1 equal to 0, return -1.",
+        "examples": [
+            "Example 1:\nInput: num1 = 3, num2 = -2\nOutput: 3\nExplanation: We can make 3 equal to 0 with the following operations:\n- We choose i = 2 and substract 2^2 + (-2) from 3, 3 - (4 + (-2)) = 1.\n- We choose i = 2 and substract 2^2\u00a0+ (-2) from 1, 1 - (4 + (-2)) = -1.\n- We choose i = 0 and substract 2^0\u00a0+ (-2) from -1, (-1) - (1 + (-2)) = 0.\nIt can be proven, that 3 is the minimum number of operations that we need to perform.",
+            "Example 2:\nInput: num1 = 5, num2 = 7\nOutput: -1\nExplanation: It can be proven, that it is impossible to make 5 equal to 0 with the given operation."
+        ],
+        "constraints": "Constraints:\n\n1 <= num1 <= 10^9\n-10^9\u00a0<= num2 <= 10^9",
+        "tags": [
+            "Bit Manipulation",
+            "Brainteaser"
+        ],
+        "title-slug": "minimum-operations-to-make-the-integer-zero"
+    },
+    {
+        "leetcode-id": 2750,
+        "title": "Ways to Split Array Into Good Subarrays",
+        "difficulty": 2,
+        "description": "You are given a binary array nums.\nA subarray of an array is good if it contains exactly one element with the value 1.\nReturn an integer denoting the number of ways to split the array nums into good subarrays. As the number may be too large, return it modulo 10^9 + 7.\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [0,1,0,0,1]\nOutput: 3\nExplanation: There are 3 ways to split nums into good subarrays:\n- [0,1] [0,0,1]\n- [0,1,0] [0,1]\n- [0,1,0,0] [1]",
+            "Example 2:\nInput: nums = [0,1,0]\nOutput: 1\nExplanation: There is 1 way to split nums into good subarrays:\n- [0,1,0]"
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] <= 1",
+        "tags": [
+            "Array",
+            "Math",
+            "Dynamic Programming"
+        ],
+        "title-slug": "ways-to-split-array-into-good-subarrays"
+    },
+    {
+        "leetcode-id": 2751,
+        "title": "Robot Collisions",
+        "difficulty": 3,
+        "description": "There are n 1-indexed robots, each having a position on a line, health, and movement direction.\nYou are given 0-indexed integer arrays positions, healths, and a string directions (directions[i] is either 'L' for left or 'R' for right). All integers in positions are unique.\nAll robots start moving on the line simultaneously at the same speed in their given directions. If two robots ever share the same position while moving, they will collide.\nIf two robots collide, the robot with lower health is removed from the line, and the health of the other robot decreases by one. The surviving robot continues in the same direction it was going. If both robots have the same health, they are both removed from the line.\nYour task is to determine the health of the robots that survive the collisions, in the same order that the robots were given, i.e. final heath of robot 1 (if survived), final health of robot 2 (if survived), and so on. If there are no survivors, return an empty array.\nReturn an array containing the health of the remaining robots (in the order they were given in the input), after no further collisions can occur.\nNote: The positions may be unsorted.",
+        "examples": [
+            "Example 1:\nInput: positions = [5,4,3,2,1], healths = [2,17,9,15,10], directions = \"RRRRR\"\nOutput: [2,17,9,15,10]\nExplanation: No collision occurs in this example, since all robots are moving in the same direction. So, the health of the robots in order from the first robot is returned, [2, 17, 9, 15, 10].",
+            "Example 2:\nInput: positions = [3,5,2,6], healths = [10,10,15,12], directions = \"RLRL\"\nOutput: [14]\nExplanation: There are 2 collisions in this example. Firstly, robot 1 and robot 2 will collide, and since both have the same health, they will be removed from the line. Next, robot 3 and robot 4 will collide and since robot 4's health is smaller, it gets removed, and robot 3's health becomes 15 - 1 = 14. Only robot 3 remains, so we return [14].",
+            "Example 3:\nInput: positions = [1,2,5,6], healths = [10,10,11,11], directions = \"RLRL\"\nOutput: []\nExplanation: Robot 1 and robot 2 will collide and since both have the same health, they are both removed. Robot 3 and 4 will collide and since both have the same health, they are both removed. So, we return an empty array, []."
+        ],
+        "constraints": "Constraints:\n\n1 <= positions.length == healths.length == directions.length == n <= 10^5\n1 <= positions[i], healths[i] <= 10^9\ndirections[i] == 'L' or directions[i] == 'R'\nAll values in positions are distinct",
+        "tags": [
+            "Array",
+            "Stack",
+            "Sorting",
+            "Simulation"
+        ],
+        "title-slug": "robot-collisions"
+    },
+    {
+        "leetcode-id": 2760,
+        "title": "Longest Even Odd Subarray With Threshold",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums and an integer threshold.\nFind the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following conditions:\n\nnums[l] % 2 == 0\nFor all indices i in the range [l, r - 1], nums[i] % 2 != nums[i + 1] % 2\nFor all indices i in the range [l, r], nums[i] <= threshold\n\nReturn an integer denoting the length of the longest such subarray.\nNote: A subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,2,5,4], threshold = 5\nOutput: 3\nExplanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 3 => [2,5,4]. This subarray satisfies the conditions.\nHence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.",
+            "Example 2:\nInput: nums = [1,2], threshold = 2\nOutput: 1\nExplanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 1 => [2]. \nIt satisfies all the conditions and we can show that 1 is the maximum possible achievable length.",
+            "Example 3:\nInput: nums = [2,3,4,5], threshold = 4\nOutput: 3\nExplanation: In this example, we can select the subarray that starts at l = 0 and ends at r = 2 => [2,3,4]. \nIt satisfies all the conditions.\nHence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 100 \n1 <= nums[i] <= 100 \n1 <= threshold <= 100",
+        "tags": [
+            "Array",
+            "Sliding Window"
+        ],
+        "title-slug": "longest-even-odd-subarray-with-threshold"
+    },
+    {
+        "leetcode-id": 2761,
+        "title": "Prime Pairs With Target Sum",
+        "difficulty": 2,
+        "description": "You are given an integer n. We say that two integers x and y form a prime number pair if:\n\n1 <= x <= y <= n\nx + y == n\nx and y are prime numbers\n\nReturn the 2D sorted list of prime number pairs [xi, yi]. The list should be sorted in increasing order of xi. If there are no prime number pairs at all, return an empty array.\nNote: A prime number is a natural number greater than 1 with only two factors, itself and 1.",
+        "examples": [
+            "Example 1:\nInput: n = 10\nOutput: [[3,7],[5,5]]\nExplanation: In this example, there are two prime pairs that satisfy the criteria. \nThese pairs are [3,7] and [5,5], and we return them in the sorted order as described in the problem statement.",
+            "Example 2:\nInput: n = 2\nOutput: []\nExplanation: We can show that there is no prime number pair that gives a sum of 2, so we return an empty array."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^6",
+        "tags": [
+            "Array",
+            "Math",
+            "Enumeration",
+            "Number Theory"
+        ],
+        "title-slug": "prime-pairs-with-target-sum"
+    },
+    {
+        "leetcode-id": 2762,
+        "title": "Continuous Subarrays",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums. A subarray of nums is called continuous if:\n\nLet i, i + 1, ..., j be the indices in the subarray. Then, for each pair of indices i <= i1, i2 <= j, 0 <= |nums[i1] - nums[i2]| <= 2.\n\nReturn the total number of continuous subarrays.\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [5,4,2,4]\nOutput: 8\nExplanation: \nContinuous subarray of size 1: [5], [4], [2], [4].\nContinuous subarray of size 2: [5,4], [4,2], [2,4].\nContinuous subarray of size 3: [4,2,4].\nThereare no subarrys of size 4.\nTotal continuous subarrays = 4 + 3 + 1 = 8.\nIt can be shown that there are no more continuous subarrays.",
+            "Example 2:\nInput: nums = [1,2,3]\nOutput: 6\nExplanation: \nContinuous subarray of size 1: [1], [2], [3].\nContinuous subarray of size 2: [1,2], [2,3].\nContinuous subarray of size 3: [1,2,3].\nTotal continuous subarrays = 3 + 2 + 1 = 6."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Queue",
+            "Sliding Window",
+            "Heap (Priority Queue)",
+            "Ordered Set",
+            "Monotonic Queue"
+        ],
+        "title-slug": "continuous-subarrays"
+    },
+    {
+        "leetcode-id": 2763,
+        "title": "Sum of Imbalance Numbers of All Subarrays",
+        "difficulty": 3,
+        "description": "The imbalance number of a 0-indexed integer array arr of length n is defined as the number of indices in sarr = sorted(arr) such that:\n\n0 <= i < n - 1, and\nsarr[i+1] - sarr[i] > 1\n\nHere, sorted(arr) is the function that returns the sorted version of arr.\nGiven a 0-indexed integer array nums, return the sum of imbalance numbers of all its subarrays.\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,3,1,4]\nOutput: 3\nExplanation: There are 3 subarrays with non-zero imbalance numbers:\n- Subarray [3, 1] with an imbalance number of 1.\n- Subarray [3, 1, 4] with an imbalance number of 1.\n- Subarray [1, 4] with an imbalance number of 1.\nThe imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 3.",
+            "Example 2:\nInput: nums = [1,3,3,3,5]\nOutput: 8\nExplanation: There are 7 subarrays with non-zero imbalance numbers:\n- Subarray [1, 3] with an imbalance number of 1.\n- Subarray [1, 3, 3] with an imbalance number of 1.\n- Subarray [1, 3, 3, 3] with an imbalance number of 1.\n- Subarray [1, 3, 3, 3, 5] with an imbalance number of 2. \n- Subarray [3, 3, 3, 5] with an imbalance number of 1. \n- Subarray [3, 3, 5] with an imbalance number of 1.\n- Subarray [3, 5] with an imbalance number of 1.\nThe imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 8."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= nums.length",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Ordered Set"
+        ],
+        "title-slug": "sum-of-imbalance-numbers-of-all-subarrays"
+    },
+    {
+        "leetcode-id": 2765,
+        "title": "Longest Alternating Subarray",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums. A subarray s of length m is called alternating if:\n\nm is greater than 1.\ns1 = s0 + 1.\nThe 0-indexed subarray s looks like [s0, s1, s0, s1,...,s(m-1) % 2]. In other words, s1 - s0 = 1, s2 - s1 = -1, s3 - s2 = 1, s4 - s3 = -1, and so on up to s[m - 1] - s[m - 2] = (-1)^m.\n\nReturn the maximum length of all alternating subarrays present in nums or -1 if no such subarray exists.\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,3,4,3,4]\nOutput: 4\nExplanation: The alternating subarrays are [3,4], [3,4,3], and [3,4,3,4]. The longest of these is [3,4,3,4], which is of length 4.",
+            "Example 2:\nInput: nums = [4,5,6]\nOutput: 2\nExplanation: [4,5] and [5,6] are the only two alternating subarrays. They are both of length 2."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 100\n1 <= nums[i] <= 10^4",
+        "tags": [
+            "Array",
+            "Enumeration"
+        ],
+        "title-slug": "longest-alternating-subarray"
+    },
+    {
+        "leetcode-id": 2766,
+        "title": "Relocate Marbles",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums representing the initial positions of some marbles. You are also given two 0-indexed integer arrays moveFrom and moveTo of equal length.\nThroughout moveFrom.length steps, you will change the positions of the marbles. On the i^th step, you will move all marbles at position moveFrom[i] to position moveTo[i].\nAfter completing all the steps, return the sorted list of occupied positions.\nNotes:\n\nWe call a position occupied if there is at least one marble in that position.\nThere may be multiple marbles in a single position.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5]\nOutput: [5,6,8,9]\nExplanation: Initially, the marbles are at positions 1,6,7,8.\nAt the i = 0th step, we move the marbles at position 1 to position 2. Then, positions 2,6,7,8 are occupied.\nAt the i = 1st step, we move the marbles at position 7 to position 9. Then, positions 2,6,8,9 are occupied.\nAt the i = 2nd step, we move the marbles at position 2 to position 5. Then, positions 5,6,8,9 are occupied.\nAt the end, the final positions containing at least one marbles are [5,6,8,9].",
+            "Example 2:\nInput: nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2]\nOutput: [2]\nExplanation: Initially, the marbles are at positions [1,1,3,3].\nAt the i = 0th step, we move all the marbles at position 1 to position 2. Then, the marbles are at positions [2,2,3,3].\nAt the i = 1st step, we move all the marbles at position 3 to position 2. Then, the marbles are at positions [2,2,2,2].\nSince 2 is the only occupied position, we return [2]."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= moveFrom.length <= 10^5\nmoveFrom.length == moveTo.length\n1 <= nums[i], moveFrom[i], moveTo[i] <= 10^9\nThe test cases are generated such that there is at least a marble in\u00a0moveFrom[i]\u00a0at the moment we want to apply\u00a0the i^th\u00a0move.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sorting",
+            "Simulation"
+        ],
+        "title-slug": "relocate-marbles"
+    },
+    {
+        "leetcode-id": 2767,
+        "title": "Partition String Into Minimum Beautiful Substrings",
+        "difficulty": 2,
+        "description": "Given a binary string s, partition the string into one or more substrings such that each substring is beautiful.\nA string is beautiful if:\n\nIt doesn't contain leading zeros.\nIt's the binary representation of a number that is a power of 5.\n\nReturn the minimum number of substrings in such partition. If it is impossible to partition the string s into beautiful substrings,\u00a0return -1.\nA substring is a contiguous sequence of characters in a string.",
+        "examples": [
+            "Example 1:\nInput: s = \"1011\"\nOutput: 2\nExplanation: We can paritition the given string into [\"101\", \"1\"].\n- The string \"101\" does not contain leading zeros and is the binary representation of integer 5^1 = 5.\n- The string \"1\" does not contain leading zeros and is the binary representation of integer 5^0 = 1.\nIt can be shown that 2 is the minimum number of beautiful substrings that s can be partitioned into.",
+            "Example 2:\nInput: s = \"111\"\nOutput: 3\nExplanation: We can paritition the given string into [\"1\", \"1\", \"1\"].\n- The string \"1\" does not contain leading zeros and is the binary representation of integer 5^0 = 1.\nIt can be shown that 3 is the minimum number of beautiful substrings that s can be partitioned into.",
+            "Example 3:\nInput: s = \"0\"\nOutput: -1\nExplanation: We can not partition the given string into beautiful substrings."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 15\ns[i] is either '0' or '1'.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Dynamic Programming",
+            "Backtracking"
+        ],
+        "title-slug": "partition-string-into-minimum-beautiful-substrings"
+    },
+    {
+        "leetcode-id": 2768,
+        "title": "Number of Black Blocks",
+        "difficulty": 2,
+        "description": "You are given two integers m and n representing the dimensions of a\u00a00-indexed\u00a0m x n grid.\nYou are also given a 0-indexed 2D integer matrix coordinates, where coordinates[i] = [x, y] indicates that the cell with coordinates [x, y] is colored black. All cells in the grid that do not appear in coordinates are white.\nA block is defined as a 2 x 2 submatrix of the grid. More formally, a block with cell [x, y] as its top-left corner where 0 <= x < m - 1 and 0 <= y < n - 1 contains the coordinates [x, y], [x + 1, y], [x, y + 1], and [x + 1, y + 1].\nReturn a 0-indexed integer array arr of size 5 such that arr[i] is the number of blocks that contains exactly i black cells.",
+        "examples": [
+            "Example 1:\nInput: m = 3, n = 3, coordinates = [[0,0]]\nOutput: [3,1,0,0,0]\nExplanation: The grid looks like this:\n\nThere is only 1 block with one black cell, and it is the block starting with cell [0,0].\nThe other 3 blocks start with cells [0,1], [1,0] and [1,1]. They all have zero black cells. \nThus, we return [3,1,0,0,0].",
+            "Example 2:\nInput: m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]\nOutput: [0,2,2,0,0]\nExplanation: The grid looks like this:\n\nThere are 2 blocks with two black cells (the ones starting with cell coordinates [0,0] and [0,1]).\nThe other 2 blocks have starting cell coordinates of [1,0] and [1,1]. They both have 1 black cell.\nTherefore, we return [0,2,2,0,0]."
+        ],
+        "constraints": "Constraints:\n\n2 <= m <= 10^5\n2 <= n <= 10^5\n0 <= coordinates.length <= 10^4\ncoordinates[i].length == 2\n0 <= coordinates[i][0] < m\n0 <= coordinates[i][1] < n\nIt is guaranteed that coordinates contains pairwise distinct coordinates.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Enumeration"
+        ],
+        "title-slug": "number-of-black-blocks"
+    },
+    {
+        "leetcode-id": 2769,
+        "title": "Find the Maximum Achievable Number",
+        "difficulty": 1,
+        "description": "You are given two integers, num and t.\nAn integer x is called achievable if it can become equal to num after applying the following operation no more than t times:\n\nIncrease or decrease x by 1, and simultaneously increase or decrease num by 1.\n\nReturn the maximum possible achievable number. It can be proven that there exists at least one achievable number.",
+        "examples": [
+            "Example 1:\nInput: num = 4, t = 1\nOutput: 6\nExplanation: The maximum achievable number is x = 6; it can become equal to num after performing this operation:\n1- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5. \nIt can be proven that there is no achievable number larger than 6.",
+            "Example 2:\nInput: num = 3, t = 2\nOutput: 7\nExplanation: The maximum achievable number is x = 7; after performing these operations, x will equal num: \n1- Decrease x by 1, and increase num by 1. Now, x = 6 and num = 4.\n2- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.\nIt can be proven that there is no achievable number larger than 7."
+        ],
+        "constraints": "Constraints:\n\n1 <= num, t\u00a0<= 50",
+        "tags": [
+            "Math"
+        ],
+        "title-slug": "find-the-maximum-achievable-number"
+    },
+    {
+        "leetcode-id": 2770,
+        "title": "Maximum Number of Jumps to Reach the Last Index",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array nums of n integers and an integer target.\nYou are initially positioned at index 0. In one step, you can jump from index i to any index j such that:\n\n0 <= i < j < n\n-target <= nums[j] - nums[i] <= target\n\nReturn the maximum number of jumps you can make to reach index n - 1.\nIf there is no way to reach index n - 1, return -1.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,6,4,1,2], target = 2\nOutput: 3\nExplanation: To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:\n- Jump from index 0 to index 1. \n- Jump from index 1 to index 3.\n- Jump from index 3 to index 5.\nIt can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 3 jumps. Hence, the answer is 3.",
+            "Example 2:\nInput: nums = [1,3,6,4,1,2], target = 3\nOutput: 5\nExplanation: To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:\n- Jump from index 0 to index 1.\n- Jump from index 1 to index 2.\n- Jump from index 2 to index 3.\n- Jump from index 3 to index 4.\n- Jump from index 4 to index 5.\nIt can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 5 jumps. Hence, the answer is 5.",
+            "Example 3:\nInput: nums = [1,3,6,4,1,2], target = 0\nOutput: -1\nExplanation: It can be proven that there is no jumping sequence that goes from 0 to n - 1. Hence, the answer is -1."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length == n <= 1000\n-10^9\u00a0<= nums[i]\u00a0<= 10^9\n0 <= target <= 2 * 10^9",
+        "tags": [
+            "Array",
+            "Dynamic Programming"
+        ],
+        "title-slug": "maximum-number-of-jumps-to-reach-the-last-index"
+    },
+    {
+        "leetcode-id": 2771,
+        "title": "Longest Non-decreasing Subarray From Two Arrays",
+        "difficulty": 2,
+        "description": "You are given two 0-indexed integer arrays nums1 and nums2 of length n.\nLet's define another 0-indexed integer array, nums3, of length n. For each index i in the range [0, n - 1], you can assign either nums1[i] or nums2[i] to nums3[i].\nYour task is to maximize the length of the longest non-decreasing subarray in nums3 by choosing its values optimally.\nReturn an integer representing the length of the longest non-decreasing subarray in nums3.\nNote: A subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [2,3,1], nums2 = [1,2,1]\nOutput: 2\nExplanation: One way to construct nums3 is: \nnums3 = [nums1[0], nums2[1], nums2[2]] => [2,2,1]. \nThe subarray starting from index 0 and ending at index 1, [2,2], forms a non-decreasing subarray of length 2. \nWe can show that 2 is the maximum achievable length.",
+            "Example 2:\nInput: nums1 = [1,3,2,1], nums2 = [2,2,3,4]\nOutput: 4\nExplanation: One way to construct nums3 is: \nnums3 = [nums1[0], nums2[1], nums2[2], nums2[3]] => [1,2,3,4]. \nThe entire array forms a non-decreasing subarray of length 4, making it the maximum achievable length.",
+            "Example 3:\nInput: nums1 = [1,1], nums2 = [2,2]\nOutput: 2\nExplanation: One way to construct nums3 is: \nnums3 = [nums1[0], nums1[1]] => [1,1]. \nThe entire array forms a non-decreasing subarray of length 2, making it the maximum achievable length."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums1.length == nums2.length == n <= 10^5\n1 <= nums1[i], nums2[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Dynamic Programming"
+        ],
+        "title-slug": "longest-non-decreasing-subarray-from-two-arrays"
+    },
+    {
+        "leetcode-id": 2772,
+        "title": "Apply Operations to Make All Array Elements Equal to Zero",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums and a positive integer k.\nYou can apply the following operation on the array any number of times:\n\nChoose any subarray of size k from the array and decrease all its elements by 1.\n\nReturn true if you can make all the array elements equal to 0, or false otherwise.\nA subarray is a contiguous non-empty part of an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,2,3,1,1,0], k = 3\nOutput: true\nExplanation: We can do the following operations:\n- Choose the subarray [2,2,3]. The resulting array will be nums = [1,1,2,1,1,0].\n- Choose the subarray [2,1,1]. The resulting array will be nums = [1,1,1,0,0,0].\n- Choose the subarray [1,1,1]. The resulting array will be nums = [0,0,0,0,0,0].",
+            "Example 2:\nInput: nums = [1,3,1,1], k = 2\nOutput: false\nExplanation: It is not possible to make all the array elements equal to 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= k <= nums.length <= 10^5\n0 <= nums[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Prefix Sum"
+        ],
+        "title-slug": "apply-operations-to-make-all-array-elements-equal-to-zero"
+    },
+    {
+        "leetcode-id": 2778,
+        "title": "Sum of Squares of Special Elements ",
+        "difficulty": 1,
+        "description": "You are given a 1-indexed integer array nums of length n.\nAn element nums[i] of nums is called special if i divides n, i.e. n % i == 0.\nReturn the sum of the squares of all special elements of nums.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,3,4]\nOutput: 21\nExplanation: There are exactly 3 special elements in nums: nums[1] since 1 divides 4, nums[2] since 2 divides 4, and nums[4] since 4 divides 4. \nHence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21.",
+            "Example 2:\nInput: nums = [2,7,1,19,18,3]\nOutput: 63\nExplanation: There are exactly 4 special elements in nums: nums[1] since 1 divides 6, nums[2] since 2 divides 6, nums[3] since 3 divides 6, and nums[6] since 6 divides 6. \nHence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length == n <= 50\n1 <= nums[i] <= 50",
+        "tags": [
+            "Array",
+            "Simulation"
+        ],
+        "title-slug": "sum-of-squares-of-special-elements"
+    },
+    {
+        "leetcode-id": 2779,
+        "title": "Maximum Beauty of an Array After Applying Operation",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array nums and a non-negative integer k.\nIn one operation, you can do the following:\n\nChoose an index i that hasn't been chosen before from the range [0, nums.length - 1].\nReplace nums[i] with any integer from the range [nums[i] - k, nums[i] + k].\n\nThe beauty of the array is the length of the longest subsequence consisting of equal elements.\nReturn the maximum possible beauty of the array nums after applying the operation any number of times.\nNote that you can apply the operation to each index only once.\nA\u00a0subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the order of the remaining elements.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,6,1,2], k = 2\nOutput: 3\nExplanation: In this example, we apply the following operations:\n- Choose index 1, replace it with 4 (from range [4,8]), nums = [4,4,1,2].\n- Choose index 3, replace it with 4 (from range [0,4]), nums = [4,4,1,4].\nAfter the applied operations, the beauty of the array nums is 3 (subsequence consisting of indices 0, 1, and 3).\nIt can be proven that 3 is the maximum possible length we can achieve.",
+            "Example 2:\nInput: nums = [1,1,1,1], k = 10\nOutput: 4\nExplanation: In this example we don't have to apply any operations.\nThe beauty of the array nums is 4 (whole array)."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i], k <= 10^5",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Sliding Window",
+            "Sorting"
+        ],
+        "title-slug": "maximum-beauty-of-an-array-after-applying-operation"
+    },
+    {
+        "leetcode-id": 2780,
+        "title": "Minimum Index of a Valid Split",
+        "difficulty": 2,
+        "description": "An element x of an integer array arr of length m is dominant if freq(x) * 2 > m, where freq(x) is the number of occurrences of x in arr. Note that this definition implies that arr can have at most one dominant element.\nYou are given a 0-indexed integer array nums of length n with one dominant element.\nYou can split nums at an index i into two arrays nums[0, ..., i] and nums[i + 1, ..., n - 1], but the split is only valid if:\n\n0 <= i < n - 1\nnums[0, ..., i], and nums[i + 1, ..., n - 1] have the same dominant element.\n\nHere, nums[i, ..., j] denotes the subarray of nums starting at index i and ending at index j, both ends being inclusive. Particularly, if j < i then nums[i, ..., j] denotes an empty subarray.\nReturn the minimum index of a valid split. If no valid split exists, return -1.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,2,2]\nOutput: 2\nExplanation: We can split the array at index 2 to obtain arrays [1,2,2] and [2]. \nIn array [1,2,2], element 2 is dominant since it occurs twice in the array and 2 * 2 > 3. \nIn array [2], element 2 is dominant since it occurs once in the array and 1 * 2 > 1.\nBoth [1,2,2] and [2] have the same dominant element as nums, so this is a valid split. \nIt can be shown that index 2 is the minimum index of a valid split.",
+            "Example 2:\nInput: nums = [2,1,3,1,1,1,7,1,2,1]\nOutput: 4\nExplanation: We can split the array at index 4 to obtain arrays [2,1,3,1,1] and [1,7,1,2,1].\nIn array [2,1,3,1,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.\nIn array [1,7,1,2,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.\nBoth [2,1,3,1,1] and [1,7,1,2,1] have the same dominant element as nums, so this is a valid split.\nIt can be shown that index 4 is the minimum index of a valid split.",
+            "Example 3:\nInput: nums = [3,3,3,3,7,2,2]\nOutput: -1\nExplanation: It can be shown that there is no valid split."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\nnums has exactly one dominant element.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sorting"
+        ],
+        "title-slug": "minimum-index-of-a-valid-split"
+    },
+    {
+        "leetcode-id": 2781,
+        "title": "Length of the Longest Valid Substring",
+        "difficulty": 3,
+        "description": "You are given a string word and an array of strings forbidden.\nA string is called valid if none of its substrings are present in forbidden.\nReturn the length of the longest valid substring of the string word.\nA substring is a contiguous sequence of characters in a string, possibly empty.",
+        "examples": [
+            "Example 1:\nInput: word = \"cbaaaabc\", forbidden = [\"aaa\",\"cb\"]\nOutput: 4\nExplanation: There are 11 valid substrings in word: \"c\", \"b\", \"a\", \"ba\", \"aa\", \"bc\", \"baa\", \"aab\", \"ab\", \"abc\" and \"aabc\". The length of the longest valid substring is 4. \nIt can be shown that all other substrings contain either \"aaa\" or \"cb\" as a substring.",
+            "Example 2:\nInput: word = \"leetcode\", forbidden = [\"de\",\"le\",\"e\"]\nOutput: 4\nExplanation: There are 11 valid substrings in word: \"l\", \"t\", \"c\", \"o\", \"d\", \"tc\", \"co\", \"od\", \"tco\", \"cod\", and \"tcod\". The length of the longest valid substring is 4.\nIt can be shown that all other substrings contain either \"de\", \"le\", or \"e\" as a substring."
+        ],
+        "constraints": "Constraints:\n\n1 <= word.length <= 10^5\nword consists only of lowercase English letters.\n1 <= forbidden.length <= 10^5\n1 <= forbidden[i].length <= 10\nforbidden[i] consists only of lowercase English letters.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "String",
+            "Sliding Window"
+        ],
+        "title-slug": "length-of-the-longest-valid-substring"
+    },
+    {
+        "leetcode-id": 2784,
+        "title": "Check if Array is Good",
+        "difficulty": 1,
+        "description": "You are given an integer array nums. We consider an array good if it is a permutation of an array base[n].\nbase[n] = [1, 2, ..., n - 1, n, n] (in other words, it is an array of length n + 1 which contains 1 to n - 1 exactly once, plus two occurrences of n). For example, base[1] = [1, 1] and base[3] = [1, 2, 3, 3].\nReturn true if the given array is good, otherwise return false.\nNote: A permutation of integers represents an arrangement of these numbers.",
+        "examples": [
+            "Example 1:\nInput: nums = [2, 1, 3]\nOutput: false\nExplanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false.",
+            "Example 2:\nInput: nums = [1, 3, 3, 2]\nOutput: true\nExplanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true.",
+            "Example 3:\nInput: nums = [1, 1]\nOutput: true\nExplanation: Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true.",
+            "Example 4:\nInput: nums = [3, 4, 4, 1, 2, 1]\nOutput: false\nExplanation: Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= num[i] <= 200",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sorting"
+        ],
+        "title-slug": "check-if-array-is-good"
+    },
+    {
+        "leetcode-id": 2785,
+        "title": "Sort Vowels in a String",
+        "difficulty": 2,
+        "description": "Given a 0-indexed string s, permute s to get a new string t such that:\n\nAll consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such that s[i] is a consonant, then t[i] = s[i].\nThe vowels must be sorted in the nondecreasing order of their ASCII values. More formally, for pairs of indices i, j with 0 <= i < j < s.length such that s[i] and s[j] are vowels, then t[i] must not have a higher ASCII value than t[j].\n\nReturn the resulting string.\nThe vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in lowercase or uppercase. Consonants comprise all letters that are not vowels.",
+        "examples": [
+            "Example 1:\nInput: s = \"lEetcOde\"\nOutput: \"lEOtcede\"\nExplanation: 'E', 'O', and 'e' are the vowels in s; 'l', 't', 'c', and 'd' are all consonants. The vowels are sorted according to their ASCII values, and the consonants remain in the same places.",
+            "Example 2:\nInput: s = \"lYmpH\"\nOutput: \"lYmpH\"\nExplanation: There are no vowels in s (all characters in s are consonants), so we return \"lYmpH\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 10^5\ns consists only of letters of the\u00a0English alphabet\u00a0in uppercase and lowercase.",
+        "tags": [
+            "String",
+            "Sorting"
+        ],
+        "title-slug": "sort-vowels-in-a-string"
+    },
+    {
+        "leetcode-id": 2786,
+        "title": "Visit Array Positions to Maximize Score",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums and a positive integer x.\nYou are initially at position 0 in the array and you can visit other positions according to the following rules:\n\nIf you are currently in position i, then you can move to any position j such that i < j.\nFor each position i that you visit, you get a score of nums[i].\nIf you move from a position i to a position j and the parities of nums[i] and nums[j] differ, then you lose a score of x.\n\nReturn the maximum total score you can get.\nNote that initially you have nums[0] points.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,3,6,1,9,2], x = 5\nOutput: 13\nExplanation: We can visit the following positions in the array: 0 -> 2 -> 3 -> 4.\nThe corresponding values are 2, 6, 1 and 9. Since the integers 6 and 1 have different parities, the move 2 -> 3 will make you lose a score of x = 5.\nThe total score will be: 2 + 6 + 1 + 9 - 5 = 13.",
+            "Example 2:\nInput: nums = [2,4,6,8], x = 3\nOutput: 20\nExplanation: All the integers in the array have the same parities, so we can visit all of them without losing any score.\nThe total score is: 2 + 4 + 6 + 8 = 20."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 10^5\n1 <= nums[i], x <= 10^6",
+        "tags": [
+            "Array",
+            "Dynamic Programming"
+        ],
+        "title-slug": "visit-array-positions-to-maximize-score"
+    },
+    {
+        "leetcode-id": 2787,
+        "title": "Ways to Express an Integer as Sum of Powers",
+        "difficulty": 2,
+        "description": "Given two positive integers n and x.\nReturn the number of ways n can be expressed as the sum of the x^th power of unique positive integers, in other words, the number of sets of unique integers [n1, n2, ..., nk] where n = n1^x + n2^x + ... + nk^x.\nSince the result can be very large, return it modulo 10^9 + 7.\nFor example, if n = 160 and x = 3, one way to express n is n = 2^3 + 3^3 + 5^3.",
+        "examples": [
+            "Example 1:\nInput: n = 10, x = 2\nOutput: 1\nExplanation: We can express n as the following: n = 3^2 + 1^2 = 10.\nIt can be shown that it is the only way to express 10 as the sum of the 2^nd power of unique integers.",
+            "Example 2:\nInput: n = 4, x = 1\nOutput: 2\nExplanation: We can express n in the following ways:\n- n = 4^1 = 4.\n- n = 3^1 + 1^1 = 4."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 300\n1 <= x <= 5",
+        "tags": [
+            "Dynamic Programming"
+        ],
+        "title-slug": "ways-to-express-an-integer-as-sum-of-powers"
+    },
+    {
+        "leetcode-id": 2788,
+        "title": "Split Strings by Separator",
+        "difficulty": 1,
+        "description": "Given an array of strings words and a character separator, split each string in words by separator.\nReturn an array of strings containing the new strings formed after the splits, excluding empty strings.\nNotes\n\nseparator is used to determine where the split should occur, but it is not included as part of the resulting strings.\nA split may result in more than two strings.\nThe resulting strings must maintain the same order as they were initially given.",
+        "examples": [
+            "Example 1:\nInput: words = [\"one.two.three\",\"four.five\",\"six\"], separator = \".\"\nOutput: [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"]\nExplanation: In this example we split as follows:\n\n\"one.two.three\" splits into \"one\", \"two\", \"three\"\n\"four.five\" splits into \"four\", \"five\"\n\"six\" splits into \"six\" \n\nHence, the resulting array is [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"].",
+            "Example 2:\nInput: words = [\"$easy$\",\"$problem$\"], separator = \"$\"\nOutput: [\"easy\",\"problem\"]\nExplanation: In this example we split as follows: \n\n\"$easy$\" splits into \"easy\" (excluding empty strings)\n\"$problem$\" splits into \"problem\" (excluding empty strings)\n\nHence, the resulting array is [\"easy\",\"problem\"].",
+            "Example 3:\nInput: words = [\"|||\"], separator = \"|\"\nOutput: []\nExplanation: In this example the resulting split of \"|||\" will contain only empty strings, so we return an empty array []."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 100\n1 <= words[i].length <= 20\ncharacters in words[i] are either lowercase English letters or characters from the string \".,|$#@\" (excluding the quotes)\nseparator is a character from the string \".,|$#@\" (excluding the quotes)",
+        "tags": [
+            "Array",
+            "String"
+        ],
+        "title-slug": "split-strings-by-separator"
+    },
+    {
+        "leetcode-id": 2789,
+        "title": "Largest Element in an Array after Merge Operations",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array nums consisting of positive integers.\nYou can do the following operation on the array any number of times:\n\nChoose an integer i such that 0 <= i < nums.length - 1 and nums[i] <= nums[i + 1]. Replace the element nums[i + 1] with nums[i] + nums[i + 1] and delete the element nums[i] from the array.\n\nReturn the value of the largest element that you can possibly obtain in the final array.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,3,7,9,3]\nOutput: 21\nExplanation: We can apply the following operations on the array:\n- Choose i = 0. The resulting array will be nums = [5,7,9,3].\n- Choose i = 1. The resulting array will be nums = [5,16,3].\n- Choose i = 0. The resulting array will be nums = [21,3].\nThe largest element in the final array is 21. It can be shown that we cannot obtain a larger element.",
+            "Example 2:\nInput: nums = [5,3,3]\nOutput: 11\nExplanation: We can do the following operations on the array:\n- Choose i = 1. The resulting array will be nums = [5,6].\n- Choose i = 0. The resulting array will be nums = [11].\nThere is only one element in the final array, which is 11."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^6",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Prefix Sum"
+        ],
+        "title-slug": "largest-element-in-an-array-after-merge-operations"
+    },
+    {
+        "leetcode-id": 2790,
+        "title": "Maximum Number of Groups With Increasing Length",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed array usageLimits of length n.\nYour task is to create groups using numbers from 0 to n - 1, ensuring that each number, i, is used no more than usageLimits[i] times in total across all groups. You must also satisfy the following conditions:\n\nEach group must consist of distinct numbers, meaning that no duplicate numbers are allowed within a single group.\nEach group (except the first one) must have a length strictly greater than the previous group.\n\nReturn an integer denoting the maximum number of groups you can create while satisfying these conditions.",
+        "examples": [
+            "Example 1:\nInput: usageLimits = [1,2,5]\nOutput: 3\nExplanation: In this example, we can use 0 at most once, 1 at most twice, and 2 at most five times.\nOne way of creating the maximum number of groups while satisfying the conditions is: \nGroup 1 contains the number [2].\nGroup 2 contains the numbers [1,2].\nGroup 3 contains the numbers [0,1,2]. \nIt can be shown that the maximum number of groups is 3. \nSo, the output is 3.",
+            "Example 2:\nInput: usageLimits = [2,1,2]\nOutput: 2\nExplanation: In this example, we can use 0 at most twice, 1 at most once, and 2 at most twice.\nOne way of creating the maximum number of groups while satisfying the conditions is:\nGroup 1 contains the number [0].\nGroup 2 contains the numbers [1,2].\nIt can be shown that the maximum number of groups is 2.\nSo, the output is 2.",
+            "Example 3:\nInput: usageLimits = [1,1]\nOutput: 1\nExplanation: In this example, we can use both 0 and 1 at most once.\nOne way of creating the maximum number of groups while satisfying the conditions is:\nGroup 1 contains the number [0].\nIt can be shown that the maximum number of groups is 1.\nSo, the output is 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= usageLimits.length <= 10^5\n1 <= usageLimits[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Math",
+            "Binary Search",
+            "Greedy",
+            "Sorting"
+        ],
+        "title-slug": "maximum-number-of-groups-with-increasing-length"
+    },
+    {
+        "leetcode-id": 2791,
+        "title": "Count Paths That Can Form a Palindrome in a Tree",
+        "difficulty": 3,
+        "description": "You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.\nYou are also given a string s of length n, where s[i] is the character assigned to the edge between i and parent[i]. s[0] can be ignored.\nReturn the number of pairs of nodes (u, v) such that u < v and the characters assigned to edges on the path from u to v can be rearranged to form a palindrome.\nA string is a palindrome when it reads the same backwards as forwards.",
+        "examples": [
+            "Example 1:\nInput: parent = [-1,0,0,1,1,2], s = \"acaabc\"\nOutput: 8\nExplanation: The valid pairs are:\n- All the pairs (0,1), (0,2), (1,3), (1,4) and (2,5) result in one character which is always a palindrome.\n- The pair (2,3) result in the string \"aca\" which is a palindrome.\n- The pair (1,5) result in the string \"cac\" which is a palindrome.\n- The pair (3,5) result in the string \"acac\" which can be rearranged into the palindrome \"acca\".",
+            "Example 2:\nInput: parent = [-1,0,0,0,0], s = \"aaaaa\"\nOutput: 10\nExplanation: Any pair of nodes (u,v) where u < v is valid."
+        ],
+        "constraints": "Constraints:\n\nn == parent.length == s.length\n1 <= n <= 10^5\n0 <= parent[i] <= n - 1 for all i >= 1\nparent[0] == -1\nparent represents a valid tree.\ns consists of only lowercase English letters.",
+        "tags": [
+            "Dynamic Programming",
+            "Bit Manipulation",
+            "Tree",
+            "Depth-First Search",
+            "Bitmask"
+        ],
+        "title-slug": "count-paths-that-can-form-a-palindrome-in-a-tree"
+    },
+    {
+        "leetcode-id": 2798,
+        "title": "Number of Employees Who Met the Target",
+        "difficulty": 1,
+        "description": "There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company.\nThe company requires each employee to work for at least target hours.\nYou are given a 0-indexed array of non-negative integers hours of length n and a non-negative integer target.\nReturn the integer denoting the number of employees who worked at least target hours.",
+        "examples": [
+            "Example 1:\nInput: hours = [0,1,2,3,4], target = 2\nOutput: 3\nExplanation: The company wants each employee to work for at least 2 hours.\n- Employee 0 worked for 0 hours and didn't meet the target.\n- Employee 1 worked for 1 hours and didn't meet the target.\n- Employee 2 worked for 2 hours and met the target.\n- Employee 3 worked for 3 hours and met the target.\n- Employee 4 worked for 4 hours and met the target.\nThere are 3 employees who met the target.",
+            "Example 2:\nInput: hours = [5,1,4,2,2], target = 6\nOutput: 0\nExplanation: The company wants each employee to work for at least 6 hours.\nThere are 0 employees who met the target."
+        ],
+        "constraints": "Constraints:\n\n1 <= n == hours.length <= 50\n0 <=\u00a0hours[i], target <= 10^5",
+        "tags": [
+            "Array",
+            "Enumeration"
+        ],
+        "title-slug": "number-of-employees-who-met-the-target"
+    },
+    {
+        "leetcode-id": 2799,
+        "title": "Count Complete Subarrays in an Array",
+        "difficulty": 2,
+        "description": "You are given an array nums consisting of positive integers.\nWe call a subarray of an array complete if the following condition is satisfied:\n\nThe number of distinct elements in the subarray is equal to the number of distinct elements in the whole array.\n\nReturn the number of complete subarrays.\nA subarray is a contiguous non-empty part of an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,1,2,2]\nOutput: 4\nExplanation: The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].",
+            "Example 2:\nInput: nums = [5,5,5,5]\nOutput: 10\nExplanation: The array consists only of the integer 5, so any subarray is complete. The number of subarrays that we can choose is 10."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 2000",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sliding Window"
+        ],
+        "title-slug": "count-complete-subarrays-in-an-array"
+    },
+    {
+        "leetcode-id": 2800,
+        "title": "Shortest String That Contains Three Strings",
+        "difficulty": 2,
+        "description": "Given three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings.\nIf there are multiple such strings, return the lexicographically smallest one.\nReturn a string denoting the answer to the problem.\nNotes\n\nA string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.\nA substring is a contiguous sequence of characters within a string.",
+        "examples": [
+            "Example 1:\nInput: a = \"abc\", b = \"bca\", c = \"aaa\"\nOutput: \"aaabca\"\nExplanation:  We show that \"aaabca\" contains all the given strings: a = ans[2...4], b = ans[3..5], c = ans[0..2]. It can be shown that the length of the resulting string would be at least 6 and \"aaabca\" is the lexicographically smallest one.",
+            "Example 2:\nInput: a = \"ab\", b = \"ba\", c = \"aba\"\nOutput: \"aba\"\nExplanation: We show that the string \"aba\" contains all the given strings: a = ans[0..1], b = ans[1..2], c = ans[0..2]. Since the length of c is 3, the length of the resulting string would be at least 3. It can be shown that \"aba\" is the lexicographically smallest one."
+        ],
+        "constraints": "Constraints:\n\n1 <= a.length, b.length, c.length <= 100\na, b, c consist only of lowercase English letters.",
+        "tags": [
+            "String",
+            "Greedy",
+            "Enumeration"
+        ],
+        "title-slug": "shortest-string-that-contains-three-strings"
+    },
+    {
+        "leetcode-id": 2801,
+        "title": "Count Stepping Numbers in Range",
+        "difficulty": 3,
+        "description": "Given two positive integers low and high represented as strings, find the count of stepping numbers in the inclusive range [low, high].\nA stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly 1.\nReturn an integer denoting the count of stepping numbers in the inclusive range [low, high]. \nSince the answer may be very large, return it modulo 10^9 + 7.\nNote: A stepping number should not have a leading zero.",
+        "examples": [
+            "Example 1:\nInput: low = \"1\", high = \"11\"\nOutput: 10\nExplanation: The stepping numbers in the range [1,11] are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10. There are a total of 10 stepping numbers in the range. Hence, the output is 10.",
+            "Example 2:\nInput: low = \"90\", high = \"101\"\nOutput: 2\nExplanation: The stepping numbers in the range [90,101] are 98 and 101. There are a total of 2 stepping numbers in the range. Hence, the output is 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= int(low) <= int(high) < 10^100\n1 <= low.length, high.length <= 100\nlow and high consist of only digits.\nlow and high don't have any leading zeros.",
+        "tags": [
+            "String",
+            "Dynamic Programming"
+        ],
+        "title-slug": "count-stepping-numbers-in-range"
+    },
+    {
+        "leetcode-id": 2806,
+        "title": "Account Balance After Rounded Purchase",
+        "difficulty": 1,
+        "description": "Initially, you have a bank account balance of 100 dollars.\nYou are given an integer purchaseAmount representing the amount you will spend on a purchase in dollars.\nAt the store where you will make the purchase, the purchase amount is rounded to the nearest multiple of 10. In other words, you pay a non-negative amount, roundedAmount, such that roundedAmount is a multiple of 10 and abs(roundedAmount - purchaseAmount) is minimized.\nIf there is more than one nearest multiple of 10, the largest multiple is chosen.\nReturn an integer denoting your account balance after making a purchase worth purchaseAmount dollars from the store.\nNote: 0 is considered to be a multiple of 10 in this problem.",
+        "examples": [
+            "Example 1:\nInput: purchaseAmount = 9\nOutput: 90\nExplanation: In this example, the nearest multiple of 10 to 9 is 10. Hence, your account balance becomes 100 - 10 = 90.",
+            "Example 2:\nInput: purchaseAmount = 15\nOutput: 80\nExplanation: In this example, there are two nearest multiples of 10 to 15: 10 and 20. So, the larger multiple, 20, is chosen.\nHence, your account balance becomes 100 - 20 = 80."
+        ],
+        "constraints": "Constraints:\n\n0 <= purchaseAmount <= 100",
+        "tags": [
+            "Math"
+        ],
+        "title-slug": "account-balance-after-rounded-purchase"
+    },
+    {
+        "leetcode-id": 2807,
+        "title": "Insert Greatest Common Divisors in Linked List",
+        "difficulty": 2,
+        "description": "Given the head of a linked list head, in which each node contains an integer value.\nBetween every pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor of them.\nReturn the linked list after insertion.\nThe greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.",
+        "examples": [
+            "Example 1:\nInput: head = [18,6,10,3]\nOutput: [18,6,6,2,10,1,3]\nExplanation: The 1^st diagram denotes the initial linked list and the 2^nd diagram denotes the linked list after inserting the new nodes (nodes in blue are the inserted nodes).\n- We insert the greatest common divisor of 18 and 6 = 6 between the 1^st and the 2^nd nodes.\n- We insert the greatest common divisor of 6 and 10 = 2 between the 2^nd and the 3^rd nodes.\n- We insert the greatest common divisor of 10 and 3 = 1 between the 3^rd and the 4^th nodes.\nThere are no more adjacent nodes, so we return the linked list.",
+            "Example 2:\nInput: head = [7]\nOutput: [7]\nExplanation: The 1^st diagram denotes the initial linked list and the 2^nd diagram denotes the linked list after inserting the new nodes.\nThere are no pairs of adjacent nodes, so we return the initial linked list."
+        ],
+        "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [1, 5000].\n1 <= Node.val <= 1000",
+        "tags": [
+            "Array",
+            "Linked List",
+            "Math"
+        ],
+        "title-slug": "insert-greatest-common-divisors-in-linked-list"
+    },
+    {
+        "leetcode-id": 2808,
+        "title": "Minimum Seconds to Equalize a Circular Array",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array nums containing n integers.\nAt each second, you perform the following operation on the array:\n\nFor every index i in the range [0, n - 1], replace nums[i] with either nums[i], nums[(i - 1 + n) % n], or nums[(i + 1) % n].\n\nNote that all the elements get replaced simultaneously.\nReturn the minimum number of seconds needed to make all elements in the array nums equal.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,1,2]\nOutput: 1\nExplanation: We can equalize the array in 1 second in the following way:\n- At 1^st second, replace values at each index with [nums[3],nums[1],nums[3],nums[3]]. After replacement, nums = [2,2,2,2].\nIt can be proven that 1 second is the minimum amount of seconds needed for equalizing the array.",
+            "Example 2:\nInput: nums = [2,1,3,3,2]\nOutput: 2\nExplanation: We can equalize the array in 2 seconds in the following way:\n- At 1^st second, replace values at each index with [nums[0],nums[2],nums[2],nums[2],nums[3]]. After replacement, nums = [2,3,3,3,3].\n- At 2^nd second, replace values at each index with [nums[1],nums[1],nums[2],nums[3],nums[4]]. After replacement, nums = [3,3,3,3,3].\nIt can be proven that 2 seconds is the minimum amount of seconds needed for equalizing the array.",
+            "Example 3:\nInput: nums = [5,5,5,5]\nOutput: 0\nExplanation: We don't need to perform any operations as all elements in the initial array are the same."
+        ],
+        "constraints": "Constraints:\n\n1 <= n == nums.length <= 10^5\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Greedy"
+        ],
+        "title-slug": "minimum-seconds-to-equalize-a-circular-array"
+    },
+    {
+        "leetcode-id": 2809,
+        "title": "Minimum Time to Make Array Sum At Most x",
+        "difficulty": 3,
+        "description": "You are given two 0-indexed integer arrays nums1 and nums2 of equal length. Every second, for all indices 0 <= i < nums1.length, value of nums1[i] is incremented by nums2[i]. After this is done, you can do the following operation:\n\nChoose an index 0 <= i < nums1.length and make nums1[i] = 0.\n\nYou are also given an integer x.\nReturn the minimum time in which you can make the sum of all elements of nums1 to be less than or equal to x, or -1 if this is not possible.",
+        "examples": [
+            "Example 1:\nInput: nums1 = [1,2,3], nums2 = [1,2,3], x = 4\nOutput: 3\nExplanation: \nFor the 1st second, we apply the operation on i = 0. Therefore nums1 = [0,2+2,3+3] = [0,4,6]. \nFor the 2nd second, we apply the operation on i = 1. Therefore nums1 = [0+1,0,6+3] = [1,0,9]. \nFor the 3rd second, we apply the operation on i = 2. Therefore nums1 = [1+1,0+2,0] = [2,2,0]. \nNow sum of nums1 = 4. It can be shown that these operations are optimal, so we return 3.",
+            "Example 2:\nInput: nums1 = [1,2,3], nums2 = [3,3,3], x = 4\nOutput: -1\nExplanation: It can be shown that the sum of nums1 will always be greater than x, no matter which operations are performed."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums1.length <= 10^3\n1 <= nums1[i] <= 10^3\n0 <= nums2[i] <= 10^3\nnums1.length == nums2.length\n0 <= x <= 10^6",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Sorting"
+        ],
+        "title-slug": "minimum-time-to-make-array-sum-at-most-x"
+    },
+    {
+        "leetcode-id": 2810,
+        "title": "Faulty Keyboard",
+        "difficulty": 1,
+        "description": "Your laptop keyboard is faulty, and whenever you type a character 'i' on it, it reverses the string that you have written. Typing other characters works as expected.\nYou are given a 0-indexed string s, and you type each character of s using your faulty keyboard.\nReturn the final string that will be present on your laptop screen.",
+        "examples": [
+            "Example 1:\nInput: s = \"string\"\nOutput: \"rtsng\"\nExplanation: \nAfter typing first character, the text on the screen is \"s\".\nAfter the second character, the text is \"st\". \nAfter the third character, the text is \"str\".\nSince the fourth character is an 'i', the text gets reversed and becomes \"rts\".\nAfter the fifth character, the text is \"rtsn\". \nAfter the sixth character, the text is \"rtsng\". \nTherefore, we return \"rtsng\".",
+            "Example 2:\nInput: s = \"poiinter\"\nOutput: \"ponter\"\nExplanation: \nAfter the first character, the text on the screen is \"p\".\nAfter the second character, the text is \"po\". \nSince the third character you type is an 'i', the text gets reversed and becomes \"op\". \nSince the fourth character you type is an 'i', the text gets reversed and becomes \"po\".\nAfter the fifth character, the text is \"pon\".\nAfter the sixth character, the text is \"pont\". \nAfter the seventh character, the text is \"ponte\". \nAfter the eighth character, the text is \"ponter\". \nTherefore, we return \"ponter\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 100\ns consists of lowercase English letters.\ns[0] != 'i'",
+        "tags": [
+            "String",
+            "Simulation"
+        ],
+        "title-slug": "faulty-keyboard"
+    },
+    {
+        "leetcode-id": 2811,
+        "title": "Check if it is Possible to Split Array",
+        "difficulty": 2,
+        "description": "You are given an array nums of length n and an integer m. You need to determine if it is possible to split the array into n non-empty arrays by performing a series of steps.\nIn each step, you can select an existing array (which may be the result of previous steps) with a length of at least two and split it into two subarrays, if, for each resulting subarray, at least one of the following holds:\n\nThe length of the subarray is one, or\nThe sum of elements of the subarray is greater than or equal to m.\n\nReturn true if you can split the given array into n arrays, otherwise return false.\nNote: A subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [2, 2, 1], m = 4\nOutput: true\nExplanation: We can split the array into [2, 2] and [1] in the first step. Then, in the second step, we can split [2, 2] into [2] and [2]. As a result, the answer is true.",
+            "Example 2:\nInput: nums = [2, 1, 3], m = 5 \nOutput: false\nExplanation: We can try splitting the array in two different ways: the first way is to have [2, 1] and [3], and the second way is to have [2] and [1, 3]. However, both of these ways are not valid. So, the answer is false.",
+            "Example 3:\nInput: nums = [2, 3, 3, 2, 3], m = 6\nOutput: true\nExplanation: We can split the array into [2, 3, 3, 2] and [3] in the first step. Then, in the second step, we can split [2, 3, 3, 2] into [2, 3, 3] and [2]. Then, in the third step, we can split [2, 3, 3] into [2] and [3, 3]. And in the last step we can split [3, 3] into [3] and [3]. As a result, the answer is true."
+        ],
+        "constraints": "Constraints:\n\n1 <= n == nums.length <= 100\n1 <= nums[i] <= 100\n1 <= m <= 200",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Greedy"
+        ],
+        "title-slug": "check-if-it-is-possible-to-split-array"
+    },
+    {
+        "leetcode-id": 2812,
+        "title": "Find the Safest Path in a Grid",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents:\n\nA cell containing a thief if grid[r][c] = 1\nAn empty cell if grid[r][c] = 0\n\nYou are initially positioned at cell (0, 0). In one move, you can move to any adjacent cell in the grid, including cells containing thieves.\nThe safeness factor of a path on the grid is defined as the minimum manhattan distance from any cell in the path to any thief in the grid.\nReturn the maximum safeness factor of all paths leading to cell (n - 1, n - 1).\nAn adjacent cell of cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) and (r - 1, c) if it exists.\nThe Manhattan distance between two cells (a, b) and (x, y) is equal to |a - x| + |b - y|, where |val| denotes the absolute value of val.",
+        "examples": [
+            "Example 1:\nInput: grid = [[1,0,0],[0,0,0],[0,0,1]]\nOutput: 0\nExplanation: All paths from (0, 0) to (n - 1, n - 1) go through the thieves in cells (0, 0) and (n - 1, n - 1).",
+            "Example 2:\nInput: grid = [[0,0,1],[0,0,0],[0,0,0]]\nOutput: 2\nExplanation: The path depicted in the picture above has a safeness factor of 2 since:\n- The closest cell of the path to the thief at cell (0, 2) is cell (0, 0). The distance between them is | 0 - 0 | + | 0 - 2 | = 2.\nIt can be shown that there are no other paths with a higher safeness factor.",
+            "Example 3:\nInput: grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]\nOutput: 2\nExplanation: The path depicted in the picture above has a safeness factor of 2 since:\n- The closest cell of the path to the thief at cell (0, 3) is cell (1, 2). The distance between them is | 0 - 1 | + | 3 - 2 | = 2.\n- The closest cell of the path to the thief at cell (3, 0) is cell (3, 2). The distance between them is | 3 - 3 | + | 0 - 2 | = 2.\nIt can be shown that there are no other paths with a higher safeness factor."
+        ],
+        "constraints": "Constraints:\n\n1 <= grid.length == n <= 400\ngrid[i].length == n\ngrid[i][j] is either 0 or 1.\nThere is at least one thief in the grid.",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Breadth-First Search",
+            "Union Find",
+            "Matrix"
+        ],
+        "title-slug": "find-the-safest-path-in-a-grid"
+    },
+    {
+        "leetcode-id": 2813,
+        "title": "Maximum Elegance of a K-Length Subsequence",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed 2D integer array items of length n and an integer k.\nitems[i] = [profiti, categoryi], where profiti and categoryi denote the profit and category of the i^th item respectively.\nLet's define the elegance of a subsequence of items as total_profit + distinct_categories^2, where total_profit is the sum of all profits in the subsequence, and distinct_categories is the number of distinct categories from all the categories in the selected subsequence.\nYour task is to find the maximum elegance from all subsequences of size k in items.\nReturn an integer denoting the maximum elegance of a subsequence of items with size exactly k.\nNote: A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order.",
+        "examples": [
+            "Example 1:\nInput: items = [[3,2],[5,1],[10,1]], k = 2\nOutput: 17\nExplanation: In this example, we have to select a subsequence of size 2.\nWe can select items[0] = [3,2] and items[2] = [10,1].\nThe total profit in this subsequence is 3 + 10 = 13, and the subsequence contains 2 distinct categories [2,1].\nHence, the elegance is 13 + 2^2 = 17, and we can show that it is the maximum achievable elegance.",
+            "Example 2:\nInput: items = [[3,1],[3,1],[2,2],[5,3]], k = 3\nOutput: 19\nExplanation: In this example, we have to select a subsequence of size 3. \nWe can select items[0] = [3,1], items[2] = [2,2], and items[3] = [5,3]. \nThe total profit in this subsequence is 3 + 2 + 5 = 10, and the subsequence contains 3 distinct categories [1,2,3]. \nHence, the elegance is 10 + 3^2 = 19, and we can show that it is the maximum achievable elegance.",
+            "Example 3:\nInput: items = [[1,1],[2,1],[3,1]], k = 3\nOutput: 7\nExplanation: In this example, we have to select a subsequence of size 3. \nWe should select all the items. \nThe total profit will be 1 + 2 + 3 = 6, and the subsequence contains 1 distinct category [1]. \nHence, the maximum elegance is 6 + 1^2 = 7."
+        ],
+        "constraints": "Constraints:\n\n1 <= items.length == n <= 10^5\nitems[i].length == 2\nitems[i][0] == profiti\nitems[i][1] == categoryi\n1 <= profiti <= 10^9\n1 <= categoryi <= n \n1 <= k <= n",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Greedy",
+            "Sorting",
+            "Heap (Priority Queue)"
+        ],
+        "title-slug": "maximum-elegance-of-a-k-length-subsequence"
+    },
+    {
+        "leetcode-id": 2815,
+        "title": "Max Pair Sum in an Array",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums. You have to find the maximum sum of a pair of numbers from nums such that the maximum digit in both numbers are equal.\nReturn the maximum sum or -1 if no such pair exists.",
+        "examples": [
+            "Example 1:\nInput: nums = [51,71,17,24,42]\nOutput: 88\nExplanation: \nFor i = 1 and j = 2, nums[i] and nums[j] have equal maximum digits with a pair sum of 71 + 17 = 88. \nFor i = 3 and j = 4, nums[i] and nums[j] have equal maximum digits with a pair sum of 24 + 42 = 66.\nIt can be shown that there are no other pairs with equal maximum digits, so the answer is 88.",
+            "Example 2:\nInput: nums = [1,2,3,4]\nOutput: -1\nExplanation: No pair exists in nums with equal maximum digits."
+        ],
+        "constraints": "Constraints:\n\n2 <= nums.length <= 100\n1 <= nums[i] <= 10^4",
+        "tags": [
+            "Array",
+            "Hash Table"
+        ],
+        "title-slug": "max-pair-sum-in-an-array"
+    },
+    {
+        "leetcode-id": 2816,
+        "title": "Double a Number Represented as a Linked List",
+        "difficulty": 2,
+        "description": "You are given the head of a non-empty linked list representing a non-negative integer without leading zeroes.\nReturn the head of the linked list after doubling it.",
+        "examples": [
+            "Example 1:\nInput: head = [1,8,9]\nOutput: [3,7,8]\nExplanation: The figure above corresponds to the given linked list which represents the number 189. Hence, the returned linked list represents the number 189 * 2 = 378.",
+            "Example 2:\nInput: head = [9,9,9]\nOutput: [1,9,9,8]\nExplanation: The figure above corresponds to the given linked list which represents the number 999. Hence, the returned linked list reprersents the number 999 * 2 = 1998."
+        ],
+        "constraints": "Constraints:\n\nThe number of nodes in the list is in the range [1, 10^4]\n0 <= Node.val <= 9\nThe input is generated such that the list represents a number that does not have leading zeros, except the number 0 itself.",
+        "tags": [
+            "Linked List",
+            "Math",
+            "Stack"
+        ],
+        "title-slug": "double-a-number-represented-as-a-linked-list"
+    },
+    {
+        "leetcode-id": 2817,
+        "title": "Minimum Absolute Difference Between Elements With Constraint",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums and an integer x.\nFind the minimum absolute difference between two elements in the array that are at least x indices apart.\nIn other words, find two indices i and j such that abs(i - j) >= x and abs(nums[i] - nums[j]) is minimized.\nReturn an integer denoting the minimum absolute difference between two elements that are at least x indices apart.",
+        "examples": [
+            "Example 1:\nInput: nums = [4,3,2,4], x = 2\nOutput: 0\nExplanation: We can select nums[0] = 4 and nums[3] = 4. \nThey are at least 2 indices apart, and their absolute difference is the minimum, 0. \nIt can be shown that 0 is the optimal answer.",
+            "Example 2:\nInput: nums = [5,3,2,10,15], x = 1\nOutput: 1\nExplanation: We can select nums[1] = 3 and nums[2] = 2.\nThey are at least 1 index apart, and their absolute difference is the minimum, 1.\nIt can be shown that 1 is the optimal answer.",
+            "Example 3:\nInput: nums = [1,2,3,4], x = 3\nOutput: 3\nExplanation: We can select nums[0] = 1 and nums[3] = 4.\nThey are at least 3 indices apart, and their absolute difference is the minimum, 3.\nIt can be shown that 3 is the optimal answer."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\n0 <= x < nums.length",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Ordered Set"
+        ],
+        "title-slug": "minimum-absolute-difference-between-elements-with-constraint"
+    },
+    {
+        "leetcode-id": 2818,
+        "title": "Apply Operations to Maximize Score",
+        "difficulty": 3,
+        "description": "You are given an array nums of n positive integers and an integer k.\nInitially, you start with a score of 1. You have to maximize your score by applying the following operation at most k times:\n\nChoose any non-empty subarray nums[l, ..., r] that you haven't chosen previously.\nChoose an element x of nums[l, ..., r] with the highest prime score. If multiple such elements exist, choose the one with the smallest index.\nMultiply your score by x.\n\nHere, nums[l, ..., r] denotes the subarray of nums starting at index l and ending at the index r, both ends being inclusive.\nThe prime score of an integer x is equal to the number of distinct prime factors of x. For example, the prime score of 300 is 3 since 300 = 2 * 2 * 3 * 5 * 5.\nReturn the maximum possible score after applying at most k operations.\nSince the answer may be large, return it modulo 10^9 + 7.",
+        "examples": [
+            "Example 1:\nInput: nums = [8,3,9,3,8], k = 2\nOutput: 81\nExplanation: To get a score of 81, we can apply the following operations:\n- Choose subarray nums[2, ..., 2]. nums[2] is the only element in this subarray. Hence, we multiply the score by nums[2]. The score becomes 1 * 9 = 9.\n- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 1, but nums[2] has the smaller index. Hence, we multiply the score by nums[2]. The score becomes 9 * 9 = 81.\nIt can be proven that 81 is the highest score one can obtain.",
+            "Example 2:\nInput: nums = [19,12,14,6,10,18], k = 3\nOutput: 4788\nExplanation: To get a score of 4788, we can apply the following operations: \n- Choose subarray nums[0, ..., 0]. nums[0] is the only element in this subarray. Hence, we multiply the score by nums[0]. The score becomes 1 * 19 = 19.\n- Choose subarray nums[5, ..., 5]. nums[5] is the only element in this subarray. Hence, we multiply the score by nums[5]. The score becomes 19 * 18 = 342.\n- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 2, but nums[2] has the smaller index. Hence, we multipy the score by nums[2]. The score becomes 342 * 14 = 4788.\nIt can be proven that 4788 is the highest score one can obtain."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length == n <= 10^5\n1 <= nums[i] <= 10^5\n1 <= k <= min(n * (n + 1) / 2, 10^9)",
+        "tags": [
+            "Array",
+            "Math",
+            "Stack",
+            "Greedy",
+            "Monotonic Stack",
+            "Number Theory"
+        ],
+        "title-slug": "apply-operations-to-maximize-score"
+    },
+    {
+        "leetcode-id": 2824,
+        "title": "Count Pairs Whose Sum is Less than Target",
+        "difficulty": 1,
+        "description": "Given a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] < target.",
+        "examples": [
+            "Example 1:\nInput: nums = [-1,1,2,3,1], target = 2\nOutput: 3\nExplanation: There are 3 pairs of indices that satisfy the conditions in the statement:\n- (0, 1) since 0 < 1 and nums[0] + nums[1] = 0 < target\n- (0, 2) since 0 < 2 and nums[0] + nums[2] = 1 < target \n- (0, 4) since 0 < 4 and nums[0] + nums[4] = 0 < target\nNote that (0, 3) is not counted since nums[0] + nums[3] is not strictly less than the target.",
+            "Example 2:\nInput: nums = [-6,2,5,-2,-7,-1,3], target = -2\nOutput: 10\nExplanation: There are 10 pairs of indices that satisfy the conditions in the statement:\n- (0, 1) since 0 < 1 and nums[0] + nums[1] = -4 < target\n- (0, 3) since 0 < 3 and nums[0] + nums[3] = -8 < target\n- (0, 4) since 0 < 4 and nums[0] + nums[4] = -13 < target\n- (0, 5) since 0 < 5 and nums[0] + nums[5] = -7 < target\n- (0, 6) since 0 < 6 and nums[0] + nums[6] = -3 < target\n- (1, 4) since 1 < 4 and nums[1] + nums[4] = -5 < target\n- (3, 4) since 3 < 4 and nums[3] + nums[4] = -9 < target\n- (3, 5) since 3 < 5 and nums[3] + nums[5] = -3 < target\n- (4, 5) since 4 < 5 and nums[4] + nums[5] = -8 < target\n- (4, 6) since 4 < 6 and nums[4] + nums[6] = -4 < target"
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length == n <= 50\n-50 <= nums[i], target <= 50",
+        "tags": [
+            "Array",
+            "Two Pointers",
+            "Sorting"
+        ],
+        "title-slug": "count-pairs-whose-sum-is-less-than-target"
+    },
+    {
+        "leetcode-id": 2825,
+        "title": "Make String a Subsequence Using Cyclic Increments",
+        "difficulty": 2,
+        "description": "You are given two 0-indexed strings str1 and str2.\nIn an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', and so on, and 'z' becomes 'a'.\nReturn true if it is possible to make str2 a subsequence of str1 by performing the operation at most once, and false otherwise.\nNote: A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.",
+        "examples": [
+            "Example 1:\nInput: str1 = \"abc\", str2 = \"ad\"\nOutput: true\nExplanation: Select index 2 in str1.\nIncrement str1[2] to become 'd'. \nHence, str1 becomes \"abd\" and str2 is now a subsequence. Therefore, true is returned.",
+            "Example 2:\nInput: str1 = \"zc\", str2 = \"ad\"\nOutput: true\nExplanation: Select indices 0 and 1 in str1. \nIncrement str1[0] to become 'a'. \nIncrement str1[1] to become 'd'. \nHence, str1 becomes \"ad\" and str2 is now a subsequence. Therefore, true is returned.",
+            "Example 3:\nInput: str1 = \"ab\", str2 = \"d\"\nOutput: false\nExplanation: In this example, it can be shown that it is impossible to make str2 a subsequence of str1 using the operation at most once. \nTherefore, false is returned."
+        ],
+        "constraints": "Constraints:\n\n1 <= str1.length <= 10^5\n1 <= str2.length <= 10^5\nstr1 and str2 consist of only lowercase English letters.",
+        "tags": [
+            "Two Pointers",
+            "String"
+        ],
+        "title-slug": "make-string-a-subsequence-using-cyclic-increments"
+    },
+    {
+        "leetcode-id": 2826,
+        "title": "Sorting Three Groups",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums of length n.\n\nThe numbers from 0 to n - 1 are divided into three groups numbered from 1 to 3, where number i belongs to group nums[i]. Notice that some groups may be empty.\n\nYou are allowed to perform this operation any number of times:\n\nPick number x and change its group. More formally, change nums[x] to any number from 1 to 3.\n\nA new array res is constructed using the following procedure:\n\nSort the numbers in each group independently.\nAppend the elements of groups 1, 2, and 3 to res in this order.\n\nArray nums is called a beautiful array if the constructed array res is sorted in non-decreasing order.\nReturn the minimum number of operations to make nums a beautiful array.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,1,3,2,1]\nOutput: 3\nExplanation: It's optimal to perform three operations:\n1. change nums[0] to 1.\n2. change nums[2] to 1.\n3. change nums[3] to 1.\nAfter performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3,4] and group 2 and group 3 become empty. Hence, res is equal to [0,1,2,3,4] which is sorted in non-decreasing order.\nIt can be proven that there is no valid sequence of less than three operations.",
+            "Example 2:\nInput: nums = [1,3,2,1,3,3]\nOutput: 2\nExplanation: It's optimal to perform two operations:\n1. change nums[1] to 1.\n2. change nums[2] to 1.\nAfter performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3], group 2 becomes empty, and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order.\nIt can be proven that there is no valid sequence of less than two operations.",
+            "Example 3:\nInput: nums = [2,2,2,2,3,3]\nOutput: 0\nExplanation: It's optimal to not perform operations.\nAfter sorting the numbers in each group, group 1 becomes empty, group 2 becomes equal to [0,1,2,3] and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 3",
+        "tags": [
+            "Array",
+            "Dynamic Programming"
+        ],
+        "title-slug": "sorting-three-groups"
+    },
+    {
+        "leetcode-id": 2827,
+        "title": "Number of Beautiful Integers in the Range",
+        "difficulty": 3,
+        "description": "You are given positive integers low, high, and k.\nA number is beautiful if it meets both of the following conditions:\n\nThe count of even digits in the number is equal to the count of odd digits.\nThe number is divisible by k.\n\nReturn the number of beautiful integers in the range [low, high].",
+        "examples": [
+            "Example 1:\nInput: low = 10, high = 20, k = 3\nOutput: 2\nExplanation: There are 2 beautiful integers in the given range: [12,18]. \n- 12 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.\n- 18 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.\nAdditionally we can see that:\n- 16 is not beautiful because it is not divisible by k = 3.\n- 15 is not beautiful because it does not contain equal counts even and odd digits.\nIt can be shown that there are only 2 beautiful integers in the given range.",
+            "Example 2:\nInput: low = 1, high = 10, k = 1\nOutput: 1\nExplanation: There is 1 beautiful integer in the given range: [10].\n- 10 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 1.\nIt can be shown that there is only 1 beautiful integer in the given range.",
+            "Example 3:\nInput: low = 5, high = 5, k = 2\nOutput: 0\nExplanation: There are 0 beautiful integers in the given range.\n- 5 is not beautiful because it is not divisible by k = 2 and it does not contain equal even and odd digits."
+        ],
+        "constraints": "Constraints:\n\n0 < low <= high <= 10^9\n0 < k <= 20",
+        "tags": [
+            "Math",
+            "Dynamic Programming"
+        ],
+        "title-slug": "number-of-beautiful-integers-in-the-range"
+    },
+    {
+        "leetcode-id": 2828,
+        "title": "Check if a String Is an Acronym of Words",
+        "difficulty": 1,
+        "description": "Given an array of strings words and a string s, determine if s is an acronym of words.\nThe string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in order. For example, \"ab\" can be formed from [\"apple\", \"banana\"], but it can't be formed from [\"bear\", \"aardvark\"].\nReturn true if s is an acronym of words, and false otherwise.",
+        "examples": [
+            "Example 1:\nInput: words = [\"alice\",\"bob\",\"charlie\"], s = \"abc\"\nOutput: true\nExplanation: The first character in the words \"alice\", \"bob\", and \"charlie\" are 'a', 'b', and 'c', respectively. Hence, s = \"abc\" is the acronym.",
+            "Example 2:\nInput: words = [\"an\",\"apple\"], s = \"a\"\nOutput: false\nExplanation: The first character in the words \"an\" and \"apple\" are 'a' and 'a', respectively. \nThe acronym formed by concatenating these characters is \"aa\". \nHence, s = \"a\" is not the acronym.",
+            "Example 3:\nInput: words = [\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"], s = \"ngguoy\"\nOutput: true\nExplanation: By concatenating the first character of the words in the array, we get the string \"ngguoy\". \nHence, s = \"ngguoy\" is the acronym."
+        ],
+        "constraints": "Constraints:\n\n1 <= words.length <= 100\n1 <= words[i].length <= 10\n1 <= s.length <= 100\nwords[i] and s consist of lowercase English letters.",
+        "tags": [
+            "Array",
+            "String"
+        ],
+        "title-slug": "check-if-a-string-is-an-acronym-of-words"
+    },
+    {
+        "leetcode-id": 2829,
+        "title": "Determine the Minimum Sum of a k-avoiding Array",
+        "difficulty": 2,
+        "description": "You are given two integers,\u00a0n and k.\nAn array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k.\nReturn the minimum possible sum of a k-avoiding array of length n.",
+        "examples": [
+            "Example 1:\nInput: n = 5, k = 4\nOutput: 18\nExplanation: Consider the k-avoiding array [1,2,4,5,6], which has a sum of 18.\nIt can be proven that there is no k-avoiding array with a sum less than 18.",
+            "Example 2:\nInput: n = 2, k = 6\nOutput: 3\nExplanation: We can construct the array [1,2], which has a sum of 3.\nIt can be proven that there is no k-avoiding array with a sum less than 3."
+        ],
+        "constraints": "Constraints:\n\n1 <= n, k <= 50",
+        "tags": [
+            "Math",
+            "Greedy"
+        ],
+        "title-slug": "determine-the-minimum-sum-of-a-k-avoiding-array"
+    },
+    {
+        "leetcode-id": 2830,
+        "title": "Maximize the Profit as the Salesman",
+        "difficulty": 2,
+        "description": "You are given an integer n representing the number of houses on a number line, numbered from 0 to n - 1.\nAdditionally, you are given a 2D integer array offers where offers[i] = [starti, endi, goldi], indicating that i^th buyer wants to buy all the houses from starti to endi for goldi amount of gold.\nAs a salesman, your goal is to maximize your earnings by strategically selecting and selling houses to buyers.\nReturn the maximum amount of gold you can earn.\nNote that different buyers can't buy the same house, and some houses may remain unsold.",
+        "examples": [
+            "Example 1:\nInput: n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]\nOutput: 3\nExplanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.\nWe sell houses in the range [0,0] to 1^st buyer for 1 gold and houses in the range [1,3] to 3^rd buyer for 2 golds.\nIt can be proven that 3 is the maximum amount of gold we can achieve.",
+            "Example 2:\nInput: n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]\nOutput: 10\nExplanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.\nWe sell houses in the range [0,2] to 2^nd buyer for 10 golds.\nIt can be proven that 10 is the maximum amount of gold we can achieve."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^5\n1 <= offers.length <= 10^5\noffers[i].length == 3\n0 <= starti <= endi <= n - 1\n1 <= goldi <= 10^3",
+        "tags": [
+            "Array",
+            "Binary Search",
+            "Dynamic Programming",
+            "Sorting"
+        ],
+        "title-slug": "maximize-the-profit-as-the-salesman"
+    },
+    {
+        "leetcode-id": 2831,
+        "title": "Find the Longest Equal Subarray",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums and an integer k.\nA subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray.\nReturn the length of the longest possible equal subarray after deleting at most k elements from nums.\nA subarray is a contiguous, possibly empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,2,3,1,3], k = 3\nOutput: 3\nExplanation: It's optimal to delete the elements at index 2 and index 4.\nAfter deleting them, nums becomes equal to [1, 3, 3, 3].\nThe longest equal subarray starts at i = 1 and ends at j = 3 with length equal to 3.\nIt can be proven that no longer equal subarrays can be created.",
+            "Example 2:\nInput: nums = [1,1,2,2,1,1], k = 2\nOutput: 4\nExplanation: It's optimal to delete the elements at index 2 and index 3.\nAfter deleting them, nums becomes equal to [1, 1, 1, 1].\nThe array itself is an equal subarray, so the answer is 4.\nIt can be proven that no longer equal subarrays can be created."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= nums.length\n0 <= k <= nums.length",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Binary Search",
+            "Sliding Window"
+        ],
+        "title-slug": "find-the-longest-equal-subarray"
+    },
+    {
+        "leetcode-id": 2833,
+        "title": "Furthest Point From Origin",
+        "difficulty": 1,
+        "description": "You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0.\nIn the i^th move, you can choose one of the following directions:\n\nmove to the left if moves[i] = 'L' or moves[i] = '_'\nmove to the right if moves[i] = 'R' or moves[i] = '_'\n\nReturn the distance from the origin of the furthest point you can get to after n moves.",
+        "examples": [
+            "Example 1:\nInput: moves = \"L_RL__R\"\nOutput: 3\nExplanation: The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves \"LLRLLLR\".",
+            "Example 2:\nInput: moves = \"_R__LL_\"\nOutput: 5\nExplanation: The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves \"LRLLLLL\".",
+            "Example 3:\nInput: moves = \"_______\"\nOutput: 7\nExplanation: The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves \"RRRRRRR\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= moves.length == n <= 50\nmoves consists only of characters 'L', 'R' and '_'.",
+        "tags": [
+            "Array",
+            "Counting"
+        ],
+        "title-slug": "furthest-point-from-origin"
+    },
+    {
+        "leetcode-id": 2834,
+        "title": "Find the Minimum Possible Sum of a Beautiful Array",
+        "difficulty": 2,
+        "description": "You are given positive integers n and target.\nAn array nums is beautiful if it meets the following conditions:\n\nnums.length == n.\nnums consists of pairwise distinct positive integers.\nThere doesn't exist two distinct indices, i and j, in the range [0, n - 1], such that nums[i] + nums[j] == target.\n\nReturn the minimum possible sum that a beautiful array could have modulo 10^9 + 7.",
+        "examples": [
+            "Example 1:\nInput: n = 2, target = 3\nOutput: 4\nExplanation: We can see that nums = [1,3] is beautiful.\n- The array nums has length n = 2.\n- The array nums consists of pairwise distinct positive integers.\n- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.\nIt can be proven that 4 is the minimum possible sum that a beautiful array could have.",
+            "Example 2:\nInput: n = 3, target = 3\nOutput: 8\nExplanation: We can see that nums = [1,3,4] is beautiful.\n- The array nums has length n = 3.\n- The array nums consists of pairwise distinct positive integers.\n- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.\nIt can be proven that 8 is the minimum possible sum that a beautiful array could have.",
+            "Example 3:\nInput: n = 1, target = 1\nOutput: 1\nExplanation: We can see, that nums = [1] is beautiful."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^9\n1 <= target <= 10^9",
+        "tags": [
+            "Math",
+            "Greedy"
+        ],
+        "title-slug": "find-the-minimum-possible-sum-of-a-beautiful-array"
+    },
+    {
+        "leetcode-id": 2835,
+        "title": "Minimum Operations to Form Subsequence With Target Sum",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed array nums consisting of non-negative powers of 2, and an integer target.\nIn one operation, you must apply the following changes to the array:\n\nChoose any element of the array nums[i] such that nums[i] > 1.\nRemove nums[i] from the array.\nAdd two occurrences of nums[i] / 2 to the end of nums.\n\nReturn the minimum number of operations you need to perform so that nums contains a subsequence whose elements sum to target. If it is impossible to obtain such a subsequence, return -1.\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,2,8], target = 7\nOutput: 1\nExplanation: In the first operation, we choose element nums[2]. The array becomes equal to nums = [1,2,4,4].\nAt this stage, nums contains the subsequence [1,2,4] which sums up to 7.\nIt can be shown that there is no shorter sequence of operations that results in a subsequnce that sums up to 7.",
+            "Example 2:\nInput: nums = [1,32,1,2], target = 12\nOutput: 2\nExplanation: In the first operation, we choose element nums[1]. The array becomes equal to nums = [1,1,2,16,16].\nIn the second operation, we choose element nums[3]. The array becomes equal to nums = [1,1,2,16,8,8]\nAt this stage, nums contains the subsequence [1,1,2,8] which sums up to 12.\nIt can be shown that there is no shorter sequence of operations that results in a subsequence that sums up to 12.",
+            "Example 3:\nInput: nums = [1,32,1], target = 35\nOutput: -1\nExplanation: It can be shown that no sequence of operations results in a subsequence that sums up to 35."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 2^30\nnums consists only of non-negative powers of two.\n1 <= target < 2^31",
+        "tags": [
+            "Array",
+            "Greedy",
+            "Bit Manipulation"
+        ],
+        "title-slug": "minimum-operations-to-form-subsequence-with-target-sum"
+    },
+    {
+        "leetcode-id": 2836,
+        "title": "Maximize Value of Function in a Ball Passing Game",
+        "difficulty": 3,
+        "description": "You are given a 0-indexed integer array receiver of length n and an integer k.\nThere are n players having a unique id in the range [0, n - 1] who will play a ball passing game, and receiver[i] is the id of the player who receives passes from the player with id i. Players can pass to themselves, i.e. receiver[i] may be equal to i.\nYou must choose one of the n players as the starting player for the game, and the ball will be passed exactly k times starting from the chosen player.\nFor a chosen starting player having id x, we define a function f(x) that denotes the sum of x and the ids of all players who receive the ball during the k passes, including repetitions. In other words, f(x) = x + receiver[x] + receiver[receiver[x]] + ... + receiver^(k)[x].\nYour task is to choose a starting player having id x that maximizes the value of f(x).\nReturn an integer denoting the maximum value of the function.\nNote: receiver may contain duplicates.",
+        "examples": [
+            "Example 1:\nPass Number\nSender ID\nReceiver ID\nx + Receiver IDs\n\n\n\u00a0\n\u00a0\n\u00a0\n2\n\n\n1\n2\n1\n3\n\n\n2\n1\n0\n3\n\n\n3\n0\n2\n5\n\n\n4\n2\n1\n6\n\n\n\n\nInput: receiver = [2,0,1], k = 4\nOutput: 6\nExplanation: The table above shows a simulation of the game starting with the player having id x = 2. \nFrom the table, f(2) is equal to 6. \nIt can be shown that 6 is the maximum achievable value of the function. \nHence, the output is 6.",
+            "Example 2:\nPass Number\nSender ID\nReceiver ID\nx + Receiver IDs\n\n\n\u00a0\n\u00a0\n\u00a0\n4\n\n\n1\n4\n3\n7\n\n\n2\n3\n2\n9\n\n\n3\n2\n1\n10\n\n\n\n\nInput: receiver = [1,1,1,2,3], k = 3\nOutput: 10\nExplanation: The table above shows a simulation of the game starting with the player having id x = 4. \nFrom the table, f(4) is equal to 10. \nIt can be shown that 10 is the maximum achievable value of the function. \nHence, the output is 10."
+        ],
+        "constraints": "Constraints:\n\n1 <= receiver.length == n <= 10^5\n0 <= receiver[i] <= n - 1\n1 <= k <= 10^10",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Bit Manipulation"
+        ],
+        "title-slug": "maximize-value-of-function-in-a-ball-passing-game"
+    },
+    {
+        "leetcode-id": 2839,
+        "title": "Check if Strings Can be Made Equal With Operations I",
+        "difficulty": 1,
+        "description": "You are given two strings s1 and s2, both of length 4, consisting of lowercase English letters.\nYou can apply the following operation on any of the two strings any number of times:\n\nChoose any two indices i and j such that j - i = 2, then swap the two characters at those indices in the string.\n\nReturn true if you can make the strings s1 and s2 equal, and false otherwise.",
+        "examples": [
+            "Example 1:\nInput: s1 = \"abcd\", s2 = \"cdab\"\nOutput: true\nExplanation: We can do the following operations on s1:\n- Choose the indices i = 0, j = 2. The resulting string is s1 = \"cbad\".\n- Choose the indices i = 1, j = 3. The resulting string is s1 = \"cdab\" = s2.",
+            "Example 2:\nInput: s1 = \"abcd\", s2 = \"dacb\"\nOutput: false\nExplanation: It is not possible to make the two strings equal."
+        ],
+        "constraints": "Constraints:\n\ns1.length == s2.length == 4\ns1 and s2 consist only of lowercase English letters.",
+        "tags": [
+            "String"
+        ],
+        "title-slug": "check-if-strings-can-be-made-equal-with-operations-i"
+    },
+    {
+        "leetcode-id": 2840,
+        "title": "Check if Strings Can be Made Equal With Operations II",
+        "difficulty": 2,
+        "description": "You are given two strings s1 and s2, both of length n, consisting of lowercase English letters.\nYou can apply the following operation on any of the two strings any number of times:\n\nChoose any two indices i and j such that i < j and the difference j - i is even, then swap the two characters at those indices in the string.\n\nReturn true if you can make the strings s1 and s2 equal, and\u00a0false otherwise.",
+        "examples": [
+            "Example 1:\nInput: s1 = \"abcdba\", s2 = \"cabdab\"\nOutput: true\nExplanation: We can apply the following operations on s1:\n- Choose the indices i = 0, j = 2. The resulting string is s1 = \"cbadba\".\n- Choose the indices i = 2, j = 4. The resulting string is s1 = \"cbbdaa\".\n- Choose the indices i = 1, j = 5. The resulting string is s1 = \"cabdab\" = s2.",
+            "Example 2:\nInput: s1 = \"abe\", s2 = \"bea\"\nOutput: false\nExplanation: It is not possible to make the two strings equal."
+        ],
+        "constraints": "Constraints:\n\nn == s1.length == s2.length\n1 <= n <= 10^5\ns1 and s2 consist only of lowercase English letters.",
+        "tags": [
+            "Hash Table",
+            "String",
+            "Sorting"
+        ],
+        "title-slug": "check-if-strings-can-be-made-equal-with-operations-ii"
+    },
+    {
+        "leetcode-id": 2841,
+        "title": "Maximum Sum of Almost Unique Subarray",
+        "difficulty": 2,
+        "description": "You are given an integer array nums and two positive integers m and k.\nReturn the maximum sum out of all almost unique subarrays of length k of nums. If no such subarray exists, return 0.\nA subarray of nums is almost unique if it contains at least m distinct elements.\nA subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [2,6,7,3,1,7], m = 3, k = 4\nOutput: 18\nExplanation: There are 3 almost unique subarrays of size k = 4. These subarrays are [2, 6, 7, 3], [6, 7, 3, 1], and [7, 3, 1, 7]. Among these subarrays, the one with the maximum sum is [2, 6, 7, 3] which has a sum of 18.",
+            "Example 2:\nInput: nums = [5,9,9,2,4,5,4], m = 1, k = 3\nOutput: 23\nExplanation: There are 5 almost unique subarrays of size k. These subarrays are [5, 9, 9], [9, 9, 2], [9, 2, 4], [2, 4, 5], and [4, 5, 4]. Among these subarrays, the one with the maximum sum is [5, 9, 9] which has a sum of 23.",
+            "Example 3:\nInput: nums = [1,2,1,2,1,2,1], m = 3, k = 3\nOutput: 0\nExplanation: There are no subarrays of size k = 3 that contain at least m = 3 distinct elements in the given array [1,2,1,2,1,2,1]. Therefore, no almost unique subarrays exist, and the maximum sum is 0."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 2 * 10^4\n1 <= m <= k <= nums.length\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Sliding Window"
+        ],
+        "title-slug": "maximum-sum-of-almost-unique-subarray"
+    },
+    {
+        "leetcode-id": 2842,
+        "title": "Count K-Subsequences of a String With Maximum Beauty",
+        "difficulty": 3,
+        "description": "You are given a string s and an integer k.\nA k-subsequence is a subsequence of s, having length k, and all its characters are unique, i.e., every character occurs once.\nLet f(c) denote the number of times the character c occurs in s.\nThe beauty of a k-subsequence is the sum of f(c) for every character c in the k-subsequence.\nFor example, consider s = \"abbbdd\" and k = 2:\n\nf('a') = 1, f('b') = 3, f('d') = 2\nSome k-subsequences of s are:\n\t\n\"abbbdd\" -> \"ab\" having a beauty of f('a') + f('b') = 4\n\"abbbdd\" -> \"ad\" having a beauty of f('a') + f('d') = 3\n\"abbbdd\" -> \"bd\" having a beauty of f('b') + f('d') = 5\n\n\n\nReturn an integer denoting the number of k-subsequences whose beauty is the maximum among all k-subsequences. Since the answer may be too large, return it modulo 10^9 + 7.\nA subsequence of a string is a new string formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.\nNotes\n\nf(c) is the number of times a character c occurs in s, not a k-subsequence.\nTwo k-subsequences are considered different if one is formed by an index that is not present in the other. So, two k-subsequences may form the same string.",
+        "examples": [
+            "Example 1:\nInput: s = \"bcca\", k = 2\nOutput: 4\nExplanation: From s we have f('a') = 1, f('b') = 1, and f('c') = 2.\nThe k-subsequences of s are: \nbcca having a beauty of f('b') + f('c') = 3 \nbcca having a beauty of f('b') + f('c') = 3 \nbcca having a beauty of f('b') + f('a') = 2 \nbcca having a beauty of f('c') + f('a') = 3\nbcca having a beauty of f('c') + f('a') = 3 \nThere are 4 k-subsequences that have the maximum beauty, 3. \nHence, the answer is 4.",
+            "Example 2:\nInput: s = \"abbcd\", k = 4\nOutput: 2\nExplanation: From s we have f('a') = 1, f('b') = 2, f('c') = 1, and f('d') = 1. \nThe k-subsequences of s are: \nabbcd having a beauty of f('a') + f('b') + f('c') + f('d') = 5\nabbcd having a beauty of f('a') + f('b') + f('c') + f('d') = 5 \nThere are 2 k-subsequences that have the maximum beauty, 5. \nHence, the answer is 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 2 * 10^5\n1 <= k <= s.length\ns consists only of lowercase English letters.",
+        "tags": [
+            "Hash Table",
+            "Math",
+            "String",
+            "Greedy",
+            "Combinatorics"
+        ],
+        "title-slug": "count-k-subsequences-of-a-string-with-maximum-beauty"
+    },
+    {
+        "leetcode-id": 2843,
+        "title": "  Count Symmetric Integers",
+        "difficulty": 1,
+        "description": "You are given two positive integers low and high.\nAn integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the sum of the last n digits of x. Numbers with an odd number of digits are never symmetric.\nReturn the number of symmetric integers in the range [low, high].",
+        "examples": [
+            "Example 1:\nInput: low = 1, high = 100\nOutput: 9\nExplanation: There are 9 symmetric integers between 1 and 100: 11, 22, 33, 44, 55, 66, 77, 88, and 99.",
+            "Example 2:\nInput: low = 1200, high = 1230\nOutput: 4\nExplanation: There are 4 symmetric integers between 1200 and 1230: 1203, 1212, 1221, and 1230."
+        ],
+        "constraints": "Constraints:\n\n1 <= low <= high <= 10^4",
+        "tags": [
+            "Math",
+            "Enumeration"
+        ],
+        "title-slug": "count-symmetric-integers"
+    },
+    {
+        "leetcode-id": 2844,
+        "title": "Minimum Operations to Make a Special Number",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed string num representing a non-negative integer.\nIn one operation, you can pick any digit of num and delete it. Note that if you delete all the digits of num, num becomes 0.\nReturn the minimum number of operations required to make num special.\nAn integer x is considered special if it is divisible by 25.",
+        "examples": [
+            "Example 1:\nInput: num = \"2245047\"\nOutput: 2\nExplanation: Delete digits num[5] and num[6]. The resulting number is \"22450\" which is special since it is divisible by 25.\nIt can be shown that 2 is the minimum number of operations required to get a special number.",
+            "Example 2:\nInput: num = \"2908305\"\nOutput: 3\nExplanation: Delete digits num[3], num[4], and num[6]. The resulting number is \"2900\" which is special since it is divisible by 25.\nIt can be shown that 3 is the minimum number of operations required to get a special number.",
+            "Example 3:\nInput: num = \"10\"\nOutput: 1\nExplanation: Delete digit num[0]. The resulting number is \"0\" which is special since it is divisible by 25.\nIt can be shown that 1 is the minimum number of operations required to get a special number."
+        ],
+        "constraints": "Constraints:\n\n1 <= num.length <= 100\nnum only consists of digits '0' through '9'.\nnum does not contain any leading zeros.",
+        "tags": [
+            "Math",
+            "String",
+            "Greedy",
+            "Enumeration"
+        ],
+        "title-slug": "minimum-operations-to-make-a-special-number"
+    },
+    {
+        "leetcode-id": 2845,
+        "title": "Count of Interesting Subarrays",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums, an integer modulo, and an integer k.\nYour task is to find the count of subarrays that are interesting.\nA subarray nums[l..r] is interesting if the following condition holds:\n\nLet cnt be the number of indices i in the range [l, r] such that nums[i] % modulo == k. Then, cnt % modulo == k.\n\nReturn an integer denoting the count of interesting subarrays. \nNote: A subarray is a contiguous non-empty sequence of elements within an array.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,2,4], modulo = 2, k = 1\nOutput: 3\nExplanation: In this example the interesting subarrays are: \nThe subarray nums[0..0] which is [3]. \n- There is only one index, i = 0, in the range [0, 0] that satisfies nums[i] % modulo == k. \n- Hence, cnt = 1 and cnt % modulo == k.  \nThe subarray nums[0..1] which is [3,2].\n- There is only one index, i = 0, in the range [0, 1] that satisfies nums[i] % modulo == k.  \n- Hence, cnt = 1 and cnt % modulo == k.\nThe subarray nums[0..2] which is [3,2,4]. \n- There is only one index, i = 0, in the range [0, 2] that satisfies nums[i] % modulo == k. \n- Hence, cnt = 1 and cnt % modulo == k. \nIt can be shown that there are no other interesting subarrays. So, the answer is 3.",
+            "Example 2:\nInput: nums = [3,1,9,6], modulo = 3, k = 0\nOutput: 2\nExplanation: In this example the interesting subarrays are: \nThe subarray nums[0..3] which is [3,1,9,6]. \n- There are three indices, i = 0, 2, 3, in the range [0, 3] that satisfy nums[i] % modulo == k. \n- Hence, cnt = 3 and cnt % modulo == k. \nThe subarray nums[1..1] which is [1]. \n- There is no index, i, in the range [1, 1] that satisfies nums[i] % modulo == k. \n- Hence, cnt = 0 and cnt % modulo == k. \nIt can be shown that there are no other interesting subarrays. So, the answer is 2."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5 \n1 <= nums[i] <= 10^9\n1 <= modulo <= 10^9\n0 <= k < modulo",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Prefix Sum"
+        ],
+        "title-slug": "count-of-interesting-subarrays"
+    },
+    {
+        "leetcode-id": 2846,
+        "title": "Minimum Edge Weight Equilibrium Queries in a Tree",
+        "difficulty": 3,
+        "description": "There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ui, vi, wi] indicates that there is an edge between nodes ui and vi with weight wi in the tree.\nYou are also given a 2D integer array queries of length m, where queries[i] = [ai, bi]. For each query, find the minimum number of operations required to make the weight of every edge on the path from ai to bi equal. In one operation, you can choose any edge of the tree and change its weight to any value.\nNote that:\n\nQueries are independent of each other, meaning that the tree returns to its initial state on each new query.\nThe path from ai to bi is a sequence of distinct nodes starting with node ai and ending with node bi such that every two adjacent nodes in the sequence share an edge in the tree.\n\nReturn an array answer of length m where answer[i] is the answer to the i^th query.",
+        "examples": [
+            "Example 1:\nInput: n = 7, edges = [[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]], queries = [[0,3],[3,6],[2,6],[0,6]]\nOutput: [0,0,1,3]\nExplanation: In the first query, all the edges in the path from 0 to 3 have a weight of 1. Hence, the answer is 0.\nIn the second query, all the edges in the path from 3 to 6 have a weight of 2. Hence, the answer is 0.\nIn the third query, we change the weight of edge [2,3] to 2. After this operation, all the edges in the path from 2 to 6 have a weight of 2. Hence, the answer is 1.\nIn the fourth query, we change the weights of edges [0,1], [1,2] and [2,3] to 2. After these operations, all the edges in the path from 0 to 6 have a weight of 2. Hence, the answer is 3.\nFor each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from ai to bi.",
+            "Example 2:\nInput: n = 8, edges = [[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]], queries = [[4,6],[0,4],[6,5],[7,4]]\nOutput: [1,2,2,3]\nExplanation: In the first query, we change the weight of edge [1,3] to 6. After this operation, all the edges in the path from 4 to 6 have a weight of 6. Hence, the answer is 1.\nIn the second query, we change the weight of edges [0,3] and [3,1] to 6. After these operations, all the edges in the path from 0 to 4 have a weight of 6. Hence, the answer is 2.\nIn the third query, we change the weight of edges [1,3] and [5,2] to 6. After these operations, all the edges in the path from 6 to 5 have a weight of 6. Hence, the answer is 2.\nIn the fourth query, we change the weights of edges [0,7], [0,3] and [1,3] to 6. After these operations, all the edges in the path from 7 to 4 have a weight of 6. Hence, the answer is 3.\nFor each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from ai to bi."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^4\nedges.length == n - 1\nedges[i].length == 3\n0 <= ui, vi < n\n1 <= wi <= 26\nThe input is generated such that edges represents a valid tree.\n1 <= queries.length == m <= 2 * 10^4\nqueries[i].length == 2\n0 <= ai, bi < n",
+        "tags": [
+            "Array",
+            "Tree",
+            "Graph",
+            "Strongly Connected Component"
+        ],
+        "title-slug": "minimum-edge-weight-equilibrium-queries-in-a-tree"
+    },
+    {
+        "leetcode-id": 2848,
+        "title": "Points That Intersect With Cars",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [starti, endi] where starti is the starting point of the i^th car and endi is the ending point of the i^th car.\nReturn the number of integer points on the line that are covered with any part of a car.",
+        "examples": [
+            "Example 1:\nInput: nums = [[3,6],[1,5],[4,7]]\nOutput: 7\nExplanation: All the points from 1 to 7 intersect at least one car, therefore the answer would be 7.",
+            "Example 2:\nInput: nums = [[1,3],[5,8]]\nOutput: 7\nExplanation: Points intersecting at least one car are 1, 2, 3, 5, 6, 7, 8. There are a total of 7 points, therefore the answer would be 7."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 100\nnums[i].length == 2\n1 <= starti\u00a0<= endi\u00a0<= 100",
+        "tags": [
+            "Hash Table",
+            "Math",
+            "Prefix Sum"
+        ],
+        "title-slug": "points-that-intersect-with-cars"
+    },
+    {
+        "leetcode-id": 2849,
+        "title": "Determine if a Cell Is Reachable at a Given Time",
+        "difficulty": 2,
+        "description": "You are given four integers sx, sy, fx, fy, and a non-negative integer t.\nIn an infinite 2D grid, you start at the cell (sx, sy). Each second, you must move to any of its adjacent cells.\nReturn true if you can reach cell (fx, fy) after exactly t seconds, or false otherwise.\nA cell's adjacent cells are the 8 cells around it that share at least one corner with it. You can visit the same cell several times.",
+        "examples": [
+            "Example 1:\nInput: sx = 2, sy = 4, fx = 7, fy = 7, t = 6\nOutput: true\nExplanation: Starting at cell (2, 4), we can reach cell (7, 7) in exactly 6 seconds by going through the cells depicted in the picture above.",
+            "Example 2:\nInput: sx = 3, sy = 1, fx = 7, fy = 3, t = 3\nOutput: false\nExplanation: Starting at cell (3, 1), it takes at least 4 seconds to reach cell (7, 3) by going through the cells depicted in the picture above. Hence, we cannot reach cell (7, 3) at the third second."
+        ],
+        "constraints": "Constraints:\n\n1 <= sx, sy, fx, fy <= 10^9\n0 <= t <= 10^9",
+        "tags": [
+            "Math"
+        ],
+        "title-slug": "determine-if-a-cell-is-reachable-at-a-given-time"
+    },
+    {
+        "leetcode-id": 2850,
+        "title": "Minimum Moves to Spread Stones Over Grid",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed 2D integer matrix grid of size 3 * 3, representing the number of stones in each cell. The grid contains exactly 9 stones, and there can be multiple stones in a single cell.\nIn one move, you can move a single stone from its current cell to any other cell if the two cells share a side.\nReturn the minimum number of moves required to place one stone in each cell.",
+        "examples": [
+            "Example 1:\nInput: grid = [[1,1,0],[1,1,1],[1,2,1]]\nOutput: 3\nExplanation: One possible sequence of moves to place one stone in each cell is: \n1- Move one stone from cell (2,1) to cell (2,2).\n2- Move one stone from cell (2,2) to cell (1,2).\n3- Move one stone from cell (1,2) to cell (0,2).\nIn total, it takes 3 moves to place one stone in each cell of the grid.\nIt can be shown that 3 is the minimum number of moves required to place one stone in each cell.",
+            "Example 2:\nInput: grid = [[1,3,0],[1,0,0],[1,0,3]]\nOutput: 4\nExplanation: One possible sequence of moves to place one stone in each cell is:\n1- Move one stone from cell (0,1) to cell (0,2).\n2- Move one stone from cell (0,1) to cell (1,1).\n3- Move one stone from cell (2,2) to cell (1,2).\n4- Move one stone from cell (2,2) to cell (2,1).\nIn total, it takes 4 moves to place one stone in each cell of the grid.\nIt can be shown that 4 is the minimum number of moves required to place one stone in each cell."
+        ],
+        "constraints": "Constraints:\n\ngrid.length == grid[i].length == 3\n0 <= grid[i][j] <= 9\nSum of grid is equal to 9.",
+        "tags": [
+            "Array",
+            "Dynamic Programming",
+            "Breadth-First Search",
+            "Matrix"
+        ],
+        "title-slug": "minimum-moves-to-spread-stones-over-grid"
+    },
+    {
+        "leetcode-id": 2851,
+        "title": "String Transformation",
+        "difficulty": 3,
+        "description": "You are given two strings s and t of equal length n. You can perform the following operation on the string s:\n\nRemove a suffix of s of length l where 0 < l < n and append it at the start of s.\n\tFor example, let s = 'abcd' then in one operation you can remove the suffix 'cd' and append it in front of s making s = 'cdab'.\n\nYou are also given an integer k. Return the number of ways in which s can be transformed into t in exactly k operations.\nSince the answer can be large, return it modulo 10^9 + 7.",
+        "examples": [
+            "Example 1:\nInput: s = \"abcd\", t = \"cdab\", k = 2\nOutput: 2\nExplanation: \nFirst way:\nIn first operation, choose suffix from index = 3, so resulting s = \"dabc\".\nIn second operation, choose suffix from index = 3, so resulting s = \"cdab\".\n\nSecond way:\nIn first operation, choose suffix from index = 1, so resulting s = \"bcda\".\nIn second operation, choose suffix from index = 1, so resulting s = \"cdab\".",
+            "Example 2:\nInput: s = \"ababab\", t = \"ababab\", k = 1\nOutput: 2\nExplanation: \nFirst way:\nChoose suffix from index = 2, so resulting s = \"ababab\".\n\nSecond way:\nChoose suffix from index = 4, so resulting s = \"ababab\"."
+        ],
+        "constraints": "Constraints:\n\n2 <= s.length <= 5 * 10^5\n1 <= k <= 10^15\ns.length == t.length\ns and t consist of only lowercase English alphabets.",
+        "tags": [
+            "Math",
+            "String",
+            "Dynamic Programming",
+            "String Matching"
+        ],
+        "title-slug": "string-transformation"
+    },
+    {
+        "leetcode-id": 2855,
+        "title": "Minimum Right Shifts to Sort the Array",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed array nums of length n containing distinct positive integers. Return the minimum number of right shifts required to sort nums and -1 if this is not possible.\nA right shift is defined as shifting the element at index i to index (i + 1) % n, for all indices.",
+        "examples": [
+            "Example 1:\nInput: nums = [3,4,5,1,2]\nOutput: 2\nExplanation: \nAfter the first right shift, nums = [2,3,4,5,1].\nAfter the second right shift, nums = [1,2,3,4,5].\nNow nums is sorted; therefore the answer is 2.",
+            "Example 2:\nInput: nums = [1,3,5]\nOutput: 0\nExplanation: nums is already sorted therefore, the answer is 0.",
+            "Example 3:\nInput: nums = [2,1,4]\nOutput: -1\nExplanation: It's impossible to sort the array using right shifts."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100\nnums contains distinct integers.",
+        "tags": [
+            "Array"
+        ],
+        "title-slug": "minimum-right-shifts-to-sort-the-array"
+    },
+    {
+        "leetcode-id": 2856,
+        "title": "Minimum Array Length After Pair Removals",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed sorted array of integers nums.\nYou can perform the following operation any number of times:\n\nChoose two indices, i and j, where i < j, such that nums[i] < nums[j].\nThen, remove the elements at indices i and j from nums. The remaining elements retain their original order, and the array is re-indexed.\n\nReturn an integer that denotes the minimum length of nums after performing the operation any number of times (including zero).\nNote that nums is sorted in non-decreasing order.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,3,4,9]\nOutput: 0\nExplanation: Initially, nums = [1, 3, 4, 9].\nIn the first operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 1 < 3.\nRemove indices 0 and 1, and nums becomes [4, 9].\nFor the next operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 4 < 9.\nRemove indices 0 and 1, and nums becomes an empty array [].\nHence, the minimum length achievable is 0.",
+            "Example 2:\nInput: nums = [2,3,6,9]\nOutput: 0\nExplanation: Initially, nums = [2, 3, 6, 9]. \nIn the first operation, we can choose index 0 and 2 because nums[0] < nums[2] <=> 2 < 6. \nRemove indices 0 and 2, and nums becomes [3, 9]. \nFor the next operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 3 < 9. \nRemove indices 0 and 1, and nums becomes an empty array []. \nHence, the minimum length achievable is 0.",
+            "Example 3:\nInput: nums = [1,1,2]\nOutput: 1\nExplanation: Initially, nums = [1, 1, 2].\nIn an operation, we can choose index 0 and 2 because nums[0] < nums[2] <=> 1 < 2. \nRemove indices 0 and 2, and nums becomes [1]. \nIt is no longer possible to perform an operation on the array. \nHence, the minimum achievable length is 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n1 <= nums[i] <= 10^9\nnums is sorted in non-decreasing order.",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Two Pointers",
+            "Binary Search",
+            "Greedy",
+            "Counting"
+        ],
+        "title-slug": "minimum-array-length-after-pair-removals"
+    },
+    {
+        "leetcode-id": 2857,
+        "title": "Count Pairs of Points With Distance k",
+        "difficulty": 2,
+        "description": "You are given a 2D integer array coordinates and an integer k, where coordinates[i] = [xi, yi] are the coordinates of the i^th point in a 2D plane.\nWe define the distance between two points (x1, y1) and (x2, y2) as (x1 XOR x2) + (y1 XOR y2) where XOR is the bitwise XOR operation.\nReturn the number of pairs (i, j) such that i < j and the distance between points i and j is equal to k.",
+        "examples": [
+            "Example 1:\nInput: coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5\nOutput: 2\nExplanation: We can choose the following pairs:\n- (0,1): Because we have (1 XOR 4) + (2 XOR 2) = 5.\n- (2,3): Because we have (1 XOR 5) + (3 XOR 2) = 5.",
+            "Example 2:\nInput: coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0\nOutput: 10\nExplanation: Any two chosen pairs will have a distance of 0. There are 10 ways to choose two pairs."
+        ],
+        "constraints": "Constraints:\n\n2 <= coordinates.length <= 50000\n0 <= xi, yi <= 10^6\n0 <= k <= 100",
+        "tags": [
+            "Array",
+            "Hash Table",
+            "Bit Manipulation"
+        ],
+        "title-slug": "count-pairs-of-points-with-distance-k"
+    },
+    {
+        "leetcode-id": 2858,
+        "title": "Minimum Edge Reversals So Every Node Is Reachable",
+        "difficulty": 3,
+        "description": "There is a simple directed graph with n nodes labeled from 0 to n - 1. The graph would form a tree if its edges were bi-directional.\nYou are given an integer n and a 2D integer array edges, where edges[i] = [ui, vi] represents a directed edge going from node ui to node vi.\nAn edge reversal changes the direction of an edge, i.e., a directed edge going from node ui to node vi becomes a directed edge going from node vi to node ui.\nFor every node i in the range [0, n - 1], your task is to independently calculate the minimum number of edge reversals required so it is possible to reach any other node starting from node i through a sequence of directed edges.\nReturn an integer array answer, where answer[i] is the  minimum number of edge reversals required so it is possible to reach any other node starting from node i through a sequence of directed edges.",
+        "examples": [
+            "Example 1:\nInput: n = 4, edges = [[2,0],[2,1],[1,3]]\nOutput: [1,1,0,2]\nExplanation: The image above shows the graph formed by the edges.\nFor node 0: after reversing the edge [2,0], it is possible to reach any other node starting from node 0.\nSo, answer[0] = 1.\nFor node 1: after reversing the edge [2,1], it is possible to reach any other node starting from node 1.\nSo, answer[1] = 1.\nFor node 2: it is already possible to reach any other node starting from node 2.\nSo, answer[2] = 0.\nFor node 3: after reversing the edges [1,3] and [2,1], it is possible to reach any other node starting from node 3.\nSo, answer[3] = 2.",
+            "Example 2:\nInput: n = 3, edges = [[1,2],[2,0]]\nOutput: [2,0,1]\nExplanation: The image above shows the graph formed by the edges.\nFor node 0: after reversing the edges [2,0] and [1,2], it is possible to reach any other node starting from node 0.\nSo, answer[0] = 2.\nFor node 1: it is already possible to reach any other node starting from node 1.\nSo, answer[1] = 0.\nFor node 2: after reversing the edge [1, 2], it is possible to reach any other node starting from node 2.\nSo, answer[2] = 1."
+        ],
+        "constraints": "Constraints:\n\n2 <= n <= 10^5\nedges.length == n - 1\nedges[i].length == 2\n0 <= ui == edges[i][0] < n\n0 <= vi == edges[i][1] < n\nui != vi\nThe input is generated such\u00a0that if the edges were bi-directional, the graph would be a tree.",
+        "tags": [
+            "Dynamic Programming",
+            "Depth-First Search",
+            "Breadth-First Search",
+            "Graph"
+        ],
+        "title-slug": "minimum-edge-reversals-so-every-node-is-reachable"
+    },
+    {
+        "leetcode-id": 2859,
+        "title": "Sum of Values at Indices With K Set Bits",
+        "difficulty": 1,
+        "description": "You are given a 0-indexed integer array nums and an integer k.\nReturn an integer that denotes the sum of elements in nums whose corresponding indices have exactly k set bits in their binary representation.\nThe set bits in an integer are the 1's present when it is written in binary.\n\nFor example, the binary representation of 21 is 10101, which has 3 set bits.",
+        "examples": [
+            "Example 1:\nInput: nums = [5,10,1,5,2], k = 1\nOutput: 13\nExplanation: The binary representation of the indices are: \n0 = 0002\n1 = 0012\n2 = 0102\n3 = 0112\n4 = 1002 \nIndices 1, 2, and 4 have k = 1 set bits in their binary representation.\nHence, the answer is nums[1] + nums[2] + nums[4] = 13.",
+            "Example 2:\nInput: nums = [4,3,2,1], k = 2\nOutput: 1\nExplanation: The binary representation of the indices are:\n0 = 002\n1 = 012\n2 = 102\n3 = 112\nOnly index 3 has k = 2 set bits in its binary representation.\nHence, the answer is nums[3] = 1."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 1000\n1 <= nums[i] <= 10^5\n0 <= k <= 10",
+        "tags": [
+            "Array",
+            "Bit Manipulation"
+        ],
+        "title-slug": "sum-of-values-at-indices-with-k-set-bits"
+    },
+    {
+        "leetcode-id": 2860,
+        "title": "Happy Students",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed integer array nums of length n where n is the total number of students in the class. The class teacher tries to select a group of students so that all the students remain happy.\nThe i^th student will become happy if one of these two conditions is met:\n\nThe student is selected and the total number of selected students is strictly greater than nums[i].\nThe student is not selected and the total number of selected students is strictly less than nums[i].\n\nReturn the number of ways to select a group of students so that everyone remains happy.",
+        "examples": [
+            "Example 1:\nInput: nums = [1,1]\nOutput: 2\nExplanation: \nThe two possible ways are:\nThe class teacher selects no student.\nThe class teacher selects both students to form the group. \nIf the class teacher selects just one student to form a group then the both students will not be happy. Therefore, there are only two possible ways.",
+            "Example 2:\nInput: nums = [6,0,3,3,6,7,2,7]\nOutput: 3\nExplanation: \nThe three possible ways are:\nThe class teacher selects the student with index = 1 to form the group.\nThe class teacher selects the students with index = 1, 2, 3, 6 to form the group.\nThe class teacher selects all the students to form the group."
+        ],
+        "constraints": "Constraints:\n\n1 <= nums.length <= 10^5\n0 <= nums[i] < nums.length",
+        "tags": [
+            "Array",
+            "Sorting",
+            "Enumeration"
+        ],
+        "title-slug": "happy-students"
+    },
+    {
+        "leetcode-id": 2861,
+        "title": "Maximum Number of Alloys",
+        "difficulty": 2,
+        "description": "You are the owner of a company that creates alloys using various types of metals. There are n different types of metals available, and you have access to k machines that can be used to create alloys. Each machine requires a specific amount of each metal type to create an alloy.\nFor the i^th machine to create an alloy, it needs composition[i][j] units of metal of type j. Initially, you have stock[i] units of metal type i, and purchasing one unit of metal type i costs cost[i] coins.\nGiven integers n, k, budget, a 1-indexed 2D array composition, and 1-indexed arrays stock and cost, your goal is to maximize the number of alloys the company can create while staying within the budget of budget coins.\nAll alloys must be created with the same machine.\nReturn the maximum number of alloys that the company can create.",
+        "examples": [
+            "Example 1:\nInput: n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,0], cost = [1,2,3]\nOutput: 2\nExplanation: It is optimal to use the 1^st machine to create alloys.\nTo create 2 alloys we need to buy the:\n- 2 units of metal of the 1^st type.\n- 2 units of metal of the 2^nd type.\n- 2 units of metal of the 3^rd type.\nIn total, we need 2 * 1 + 2 * 2 + 2 * 3 = 12 coins, which is smaller than or equal to budget = 15.\nNotice that we have 0 units of metal of each type and we have to buy all the required units of metal.\nIt can be proven that we can create at most 2 alloys.",
+            "Example 2:\nInput: n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,100], cost = [1,2,3]\nOutput: 5\nExplanation: It is optimal to use the 2^nd machine to create alloys.\nTo create 5 alloys we need to buy:\n- 5 units of metal of the 1^st type.\n- 5 units of metal of the 2^nd type.\n- 0 units of metal of the 3^rd type.\nIn total, we need 5 * 1 + 5 * 2 + 0 * 3 = 15 coins, which is smaller than or equal to budget = 15.\nIt can be proven that we can create at most 5 alloys.",
+            "Example 3:\nInput: n = 2, k = 3, budget = 10, composition = [[2,1],[1,2],[1,1]], stock = [1,1], cost = [5,5]\nOutput: 2\nExplanation: It is optimal to use the 3^rd machine to create alloys.\nTo create 2 alloys we need to buy the:\n- 1 unit of metal of the 1^st type.\n- 1 unit of metal of the 2^nd type.\nIn total, we need 1 * 5 + 1 * 5 = 10 coins, which is smaller than or equal to budget = 10.\nIt can be proven that we can create at most 2 alloys."
+        ],
+        "constraints": "Constraints:\n\n1 <= n, k <= 100\n0 <= budget <= 10^8\ncomposition.length == k\ncomposition[i].length == n\n1 <= composition[i][j] <= 100\nstock.length == cost.length == n\n0 <= stock[i] <= 10^8\n1 <= cost[i] <= 100",
+        "tags": [
+            "Array",
+            "Binary Search"
+        ],
+        "title-slug": "maximum-number-of-alloys"
+    },
+    {
+        "leetcode-id": 2862,
+        "title": "Maximum Element-Sum of a Complete Subset of Indices",
+        "difficulty": 3,
+        "description": "You are given a 1-indexed array nums of n integers.\nA set of numbers is complete if the product of every pair of its elements is a perfect square.\nFor a subset of the indices set {1, 2, ..., n} represented as {i1, i2, ..., ik}, we define its element-sum as: nums[i1] + nums[i2] + ... + nums[ik].\nReturn the maximum element-sum of a complete subset of the indices set {1, 2, ..., n}.\nA perfect square is a number that can be expressed as the product of an integer by itself.",
+        "examples": [
+            "Example 1:\nInput: nums = [8,7,3,5,7,2,4,9]\nOutput: 16\nExplanation: Apart from the subsets consisting of a single index, there are two other complete subsets of indices: {1,4} and {2,8}.\nThe sum of the elements corresponding to indices 1 and 4 is equal to nums[1] + nums[4] = 8 + 5 = 13.\nThe sum of the elements corresponding to indices 2 and 8 is equal to nums[2] + nums[8] = 7 + 9 = 16.\nHence, the maximum element-sum of a complete subset of indices is 16.",
+            "Example 2:\nInput: nums = [5,10,3,10,1,13,7,9,4]\nOutput: 19\nExplanation: Apart from the subsets consisting of a single index, there are four other complete subsets of indices: {1,4}, {1,9}, {2,8}, {4,9}, and {1,4,9}.\nThe sum of the elements corresponding to indices 1 and 4 is equal to nums[1] + nums[4] = 5 + 10 = 15.\nThe sum of the elements corresponding to indices 1 and 9 is equal to nums[1] + nums[9] = 5 + 4 = 9.\nThe sum of the elements corresponding to indices 2 and 8 is equal to nums[2] + nums[8] = 10 + 9 = 19.\nThe sum of the elements corresponding to indices 4 and 9 is equal to nums[4] + nums[9] = 10 + 4 = 14.\nThe sum of the elements corresponding to indices 1, 4, and 9 is equal to nums[1] + nums[4] + nums[9] = 5 + 10 + 4 = 19.\nHence, the maximum element-sum of a complete subset of indices is 19."
+        ],
+        "constraints": "Constraints:\n\n1 <= n == nums.length <= 10^4\n1 <= nums[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Math",
+            "Number Theory"
+        ],
+        "title-slug": "maximum-element-sum-of-a-complete-subset-of-indices"
+    },
+    {
+        "leetcode-id": 2864,
+        "title": "Maximum Odd Binary Number",
+        "difficulty": 1,
+        "description": "You are given a binary string s that contains at least one '1'.\nYou have to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number that can be created from this combination.\nReturn a string representing the maximum odd binary number that can be created from the given combination.\nNote that the resulting string can have leading zeros.",
+        "examples": [
+            "Example 1:\nInput: s = \"010\"\nOutput: \"001\"\nExplanation: Because there is just one '1', it must be in the last position. So the answer is \"001\".",
+            "Example 2:\nInput: s = \"0101\"\nOutput: \"1001\"\nExplanation: One of the '1's must be in the last position. The maximum number that can be made with the remaining digits is \"100\". So the answer is \"1001\"."
+        ],
+        "constraints": "Constraints:\n\n1 <= s.length <= 100\ns consists only of '0' and '1'.\ns contains at least one '1'.",
+        "tags": [
+            "Math",
+            "String",
+            "Greedy"
+        ],
+        "title-slug": "maximum-odd-binary-number"
+    },
+    {
+        "leetcode-id": 2865,
+        "title": "Beautiful Towers I",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array maxHeights of n integers.\nYou are tasked with building n towers in the coordinate line. The i^th tower is built at coordinate i and has a height of heights[i].\nA configuration of towers is beautiful if the following conditions hold:\n\n1 <= heights[i] <= maxHeights[i]\nheights is a mountain array.\n\nArray heights is a mountain if there exists an index i such that:\n\nFor all 0 < j <= i, heights[j - 1] <= heights[j]\nFor all i <= k < n - 1, heights[k + 1] <= heights[k]\n\nReturn the maximum possible sum of heights of a beautiful configuration of towers.",
+        "examples": [
+            "Example 1:\nInput: maxHeights = [5,3,4,1,1]\nOutput: 13\nExplanation: One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]  \n- heights is a mountain of peak i = 0.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.",
+            "Example 2:\nInput: maxHeights = [6,5,3,9,2,7]\nOutput: 22\nExplanation: One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 3.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.",
+            "Example 3:\nInput: maxHeights = [3,2,5,5,2,3]\nOutput: 18\nExplanation: One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 2. \nNote that, for this configuration, i = 3 can also be considered a peak.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 18."
+        ],
+        "constraints": "Constraints:\n\n1 <= n == maxHeights <= 10^3\n1 <= maxHeights[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Stack",
+            "Monotonic Stack"
+        ],
+        "title-slug": "beautiful-towers-i"
+    },
+    {
+        "leetcode-id": 2866,
+        "title": "Beautiful Towers II",
+        "difficulty": 2,
+        "description": "You are given a 0-indexed array maxHeights of n integers.\nYou are tasked with building n towers in the coordinate line. The i^th tower is built at coordinate i and has a height of heights[i].\nA configuration of towers is beautiful if the following conditions hold:\n\n1 <= heights[i] <= maxHeights[i]\nheights is a mountain array.\n\nArray heights is a mountain if there exists an index i such that:\n\nFor all 0 < j <= i, heights[j - 1] <= heights[j]\nFor all i <= k < n - 1, heights[k + 1] <= heights[k]\n\nReturn the maximum possible sum of heights of a beautiful configuration of towers.",
+        "examples": [
+            "Example 1:\nInput: maxHeights = [5,3,4,1,1]\nOutput: 13\nExplanation: One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]  \n- heights is a mountain of peak i = 0.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.",
+            "Example 2:\nInput: maxHeights = [6,5,3,9,2,7]\nOutput: 22\nExplanation: One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 3.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.",
+            "Example 3:\nInput: maxHeights = [3,2,5,5,2,3]\nOutput: 18\nExplanation: One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 2. \nNote that, for this configuration, i = 3 can also be considered a peak.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 18."
+        ],
+        "constraints": "Constraints:\n\n1 <= n == maxHeights\u00a0<= 10^5\n1 <= maxHeights[i] <= 10^9",
+        "tags": [
+            "Array",
+            "Stack",
+            "Monotonic Stack"
+        ],
+        "title-slug": "beautiful-towers-ii"
+    },
+    {
+        "leetcode-id": 2867,
+        "title": "Count Valid Paths in a Tree",
+        "difficulty": 3,
+        "description": "There is an undirected tree with n nodes labeled from 1 to n. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree.\nReturn the number of valid paths in the tree.\nA path (a, b) is valid if there exists exactly one prime number among the node labels in the path from a to b.\nNote that:\n\nThe path (a, b) is a sequence of distinct nodes starting with node a and ending with node b such that every two adjacent nodes in the sequence share an edge in the tree.\nPath (a, b) and path (b, a) are considered the same and counted only once.",
+        "examples": [
+            "Example 1:\nInput: n = 5, edges = [[1,2],[1,3],[2,4],[2,5]]\nOutput: 4\nExplanation: The pairs with exactly one prime number on the path between them are: \n- (1, 2) since the path from 1 to 2 contains prime number 2. \n- (1, 3) since the path from 1 to 3 contains prime number 3.\n- (1, 4) since the path from 1 to 4 contains prime number 2.\n- (2, 4) since the path from 2 to 4 contains prime number 2.\nIt can be shown that there are only 4 valid paths.",
+            "Example 2:\nInput: n = 6, edges = [[1,2],[1,3],[2,4],[3,5],[3,6]]\nOutput: 6\nExplanation: The pairs with exactly one prime number on the path between them are: \n- (1, 2) since the path from 1 to 2 contains prime number 2.\n- (1, 3) since the path from 1 to 3 contains prime number 3.\n- (1, 4) since the path from 1 to 4 contains prime number 2.\n- (1, 6) since the path from 1 to 6 contains prime number 3.\n- (2, 4) since the path from 2 to 4 contains prime number 2.\n- (3, 6) since the path from 3 to 6 contains prime number 3.\nIt can be shown that there are only 6 valid paths."
+        ],
+        "constraints": "Constraints:\n\n1 <= n <= 10^5\nedges.length == n - 1\nedges[i].length == 2\n1 <= ui, vi <= n\nThe input is generated such that edges represent a valid tree.",
+        "tags": [
+            "Math",
+            "Dynamic Programming",
+            "Tree",
+            "Depth-First Search",
+            "Number Theory"
+        ],
+        "title-slug": "count-valid-paths-in-a-tree"
+    }
+]
\ No newline at end of file