Category: Java programming question
-
LeetCode Problem 441: Arranging Coins
1. Problem Statement You have n coins, and you want to arrange them in the shape of a staircase.Each row k in the staircase contains exactly k coins. Return the number of complete rows that can be formed. Example 1:Input: n = 5Output: 2Explanation: Example 2:Input: n = 8Output: 3Explanation: 2. Key Insight The total…
-
LeetCode Problem 414: Third Maximum Number
Problem Statement Given an integer array nums, return the third distinct maximum number in the array.If the third maximum does not exist, return the maximum number. Example 1 Input: Output: Explanation:The third distinct maximum number is 1 (since the numbers in descending order are 3, 2, 1). Example 2 Input: Output: Explanation:There are only two…
-
LeetCode Problem 212: Word Search II
Problem Statement You are given an m x n board of characters and a list of strings called words.Return all the words that can be formed by tracing adjacent letters on the board. Each letter cell may be used only once per word, and words must be formed from horizontally or vertically adjacent cells. Example…
-
LeetCode Problem 62: Unique Paths
Problem Statement A robot is located at the top-left corner of an m x n grid (marked as (0,0)). The robot can only move either down or right at any point in time.The robot is trying to reach the bottom-right corner of the grid (marked as (m-1, n-1)). Return the number of possible unique paths…
-
LeetCode Problem 332: Reconstruct Itinerary
Problem Statement You are given a list of airline tickets represented by pairs of departure and arrival airports [from, to].Reconstruct the itinerary in order.All tickets belong to a man who departs from “JFK”. Thus, the itinerary must begin with “JFK”. If there are multiple valid itineraries, return the one with the smallest lexical order when…
-
LeetCode Problem 279 – Perfect Squares
Problem Statement Given an integer n, return the least number of perfect square numbers that sum to n. A perfect square is an integer that can be expressed as x² where x is an integer.For example, 1, 4, 9, 16, 25, 36, … are perfect squares. You must find the minimum number of such numbers…
-
LeetCode Problem 129 – Sum Root to Leaf Numbers
Problem Description You are given the root of a binary tree containing digits from 0 to 9.Each root-to-leaf path in the tree represents a number formed by concatenating the digits along that path. Return the total sum of all root-to-leaf numbers. A leaf is a node with no children. Example 1: Example 2: Constraints: Intuition…
-
LeetCode Problem 287 – Find the Duplicate Number
Problem Description You are given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.There is only one repeated number in nums, return this duplicate number. You must solve the problem without modifying the array and using only constant extra space. Example: Constraints: Intuition Since…
-
LeetCode Problem 96: Unique Binary Search Trees
Problem Overview You are given an integer n, representing the number of nodes labeled from 1 to n.Your task is to determine how many structurally unique Binary Search Trees (BSTs) can be constructed using all the numbers from 1 to n. In a Binary Search Tree: Example 1: Explanation:There are five structurally unique BSTs that…
-
LeetCode Problem 91: Decode Ways
Problem Overview You are given a string s containing only digits (0–9). The goal is to determine how many possible ways there are to decode the string into letters, where: Each number from 1 to 26 corresponds to an uppercase English letter. You need to find how many different ways the string can be decoded…
