Category: Java programming question
-
LeetCode 409 — Longest Palindrome
Given a string containing uppercase and lowercase characters, you must determine the length of the longest palindrome that can be formed using the characters in the string. Examples: Problem Understanding A palindrome reads the same forward and backward. To build the longest possible palindrome: So the key question becomes: How many characters can we pair,…
-
LeetCode 1286 — Iterator for Combination
This problem asks you to design a data structure that generates combinations of characters from a given string, in lexicographical order, one at a time, through two methods: You must implement: Example: Problem Understanding Given: You must: Important notes: Logic Explained in Simple English To solve this problem cleanly, think about it like this: Why…
-
LeetCode 119 — Pascal’s Triangle II
This problem asks you to return a specific row of Pascal’s Triangle, indexed starting from 0. Examples: Problem Understanding Pascal’s Triangle is built with these rules: Example rows: But in this problem, you must return only the requested row, not the entire triangle. Logic Explained in Simple English There are two main ways to build…
-
LeetCode 274 — H-Index
You are given an array where each element represents the number of citations a researcher has received for each of their papers. The goal is to compute the H-Index. The H-Index is defined as: A researcher has an H-index of h if h of their papers have at least h citations each, and the remaining…
-
LeetCode 171 — Excel Sheet Column Number
This problem is the reverse of LeetCode 168.Instead of converting a number to a column title, here you are given a column title (like used in Excel) and must convert it into the corresponding integer. Examples: Problem Understanding Excel column titles behave like a base-26 number system, but instead of digits 0–25, letters represent values…
-
LeetCode 994 — Rotting Oranges
You are given a grid where each cell represents: Every minute, any fresh orange that is adjacent (up, down, left, right) to a rotten orange also becomes rotten. Your task: Return the minimum number of minutes required for all oranges to become rotten.If it is impossible, return -1. Example: Problem Understanding and Key Observations Important…
-
LeetCode 437 — Path Sum III
This problem asks you to count how many paths in a binary tree have a sum equal to a given target value. The path: Example: The three valid paths are: Problem Requirements and Observations Important characteristics: Constraints: Logic Explained in Simple English There are two common ways to solve this: Approach A: Simple Recursive Counting…
-
LeetCode 987 — Vertical Order Traversal of a Binary Tree
Vertical Order Traversal means we must print nodes column by column, from leftmost vertical line to rightmost. But unlike the simpler vertical order problem, this one has strict ordering rules. Given a binary tree, return the vertical traversal such that: Example: How Coordinates Work We treat the tree as a grid: Example coordinate mapping: Now…
-
LeetCode 442 — Find All Duplicates in an Array
You are given an array of integers where: Your task:Return all elements that appear exactly twice in the array, without using extra space proportional to n. Example: Problem Requirements and Constraints This means: Logic Explained The key insight: Since all numbers are between 1 and n, each number corresponds to a valid index in the…
-
LeetCode 211 — Design Add and Search Words Data Structure
Build a data structure that can store words and search them, but with a twist: the search function must support the dot character . which can match any single letter. Example: Problem Requirements You must implement a class with two methods: addWord(word) Stores a word in the data structure. search(pattern) Returns true if: Constraints to…
