Category: Java programming question
-
LeetCode Problem 593 Valid Square
1. Problem Summary You are given four points in a 2D plane.Each point is represented by a pair of integers: Your task is to determine whether these four points form a square, regardless of their ordering. To be considered a valid square: Example interpretation:If the points are: These form a perfect square → return true.…
-
LeetCode Problem 832 Flipping an Image
1. Problem Summary You are given a binary matrix image where each entry is either: Your task is to transform the matrix by performing two operations on each row: Finally, return the resulting matrix. Example interpretation:If a row is: After flipping: After inverting: 2. Key Insights Flip and invert can be combined in one pass…
-
LeetCode Problem 563 Binary Tree Tilt
1. Problem Summary You are given the root of a binary tree.Your task is to compute the total tilt of the tree, where: Important details: Example interpretation:If a node has left subtree sum = 10 and right subtree sum = 4, its tilt is: 2. Key Insights Subtree sums must be computed for every node…
-
Find the Smallest Divisor Given a Threshold
1. Problem Summary You are given: Your task is to find the smallest positive integer divisor such that: Important characteristics: Example interpretation:If nums = [1,2,5,9] and threshold = 6, the smallest divisor that keeps the ceiling-sum ≤ 6 is 5. 2. Key Insights Ceiling division is required Formula: Relationship between divisor and sum Meaning: Monotonic…
-
Minimum Cost to Move Chips to the Same Position
1. Problem Summary You are given an array position where each element represents the position of a chip on a number line. You must move all chips to the same position, where movement cost rules are: Your task is to compute the minimum total cost required to gather all chips at a single position. Example…
-
LeetCode Problem 310 Minimum Height Trees
1. Problem Summary You are given an undirected graph representing a tree with: Your task is to return all node labels that can serve as roots of Minimum Height Trees (MHTs). Important characteristics: Example interpretation:For input: The tree rooted at node 1 has minimum height, so output is: 2. Key Insights A Minimum Height Tree…
-
LeetCode Problem 1446 Consecutive Characters
1. Problem Summary You are given a string s consisting only of lowercase English letters.Your task is to determine the length of the longest substring made up of the same repeated character. In other words, you must find the maximum count of consecutive repeating characters appearing contiguously in the string. Example interpretation:For input: The longest…
-
LeetCode Problem 147 Insertion Sort List
1. Problem Summary You are given the head of a singly linked list.Your task is to sort the linked list in ascending order using the logic of insertion sort, and return the new head. Important characteristics: Example interpretation:For input: Sorted output: 2. Key Insights Why standard insertion sort fits linked lists Insertion sort inserts elements…
-
Convert Binary Number in a Linked List to Integer
1. Problem Summary You are given the head of a singly linked list, where each node contains a value of either: These node values represent a binary number, where: Your task is to: Example interpretation:If the linked list is: This represents binary 101, which equals decimal 5. 2. Key Insights Linked list ordering matches binary…
-
Number of Longest Increasing Subsequence
1. Problem Summary You are given an integer array nums.Your task is to determine: Important clarifications: Example: 2. Key Insights LIS length alone is not enough This problem extends the classic LIS by also counting how many achieve that length. We track two values per index For each index i: Transition logic For every earlier…
