Learnitweb

Category: Java programming question

  • Longest Consecutive Sequence

    1. Problem Summary You are given an unsorted integer array nums. Your task is to find the length of the longest consecutive sequence, where: Example: 2. Key Insights Insight 1: Sorting works, but too slow Sorting takes: But we need an O(N) solution. Insight 2: HashSet enables O(1) lookups If values are stored in a…

  • Max Area of Island

    1. Problem Summary You are given a 2D grid consisting of: An island is defined as a group of connected 1s where connectivity is: Your task is to compute: If there is no land at all, return: Example: 2. Key Insights Insight 1: This is a connected-component counting problem Each island is a connected region…

  • Maximum Product of Word Lengths

    1. Problem Summary You are given an array of strings words. Your task is to find the maximum value of: where: Example: Valid pair: Lengths: Output: 2. Key Insights Insight 1: Checking shared letters directly is too slow Naive comparison of characters between every pair is: Where L = max word length. Insight 2: Letters…

  • Partitioning Into Minimum Number of Deci-Binary Numbers

    1. Problem Summary You are given a string n representing a positive decimal integer.Your task is to determine the minimum number of positive deci-binary numbers whose sum equals n. A deci-binary number is defined as: Goal: Example: 2. Key Insights Insight 1: Digits add independently by position Since deci-binary numbers only contain 0 or 1…

  • Binary Tree Level Order Traversal

    1. Problem Summary You are given the root of a binary tree.Your task is to return the level order traversal, meaning: Example interpretation: Given tree: Output: 2. Key Insights Level order traversal is essentially a breadth-first traversal We must explore the tree breadth-first rather than depth-first. A queue naturally processes nodes level by level As…

  • LeetCode Problem 665 Non-decreasing Array

    1. Problem Summary You are given an integer array nums. Your task is to determine whether the array can become non-decreasing by modifying at most one element. A non-decreasing array satisfies: Constraints and rules: Example: Example: 2. Key Insights Insight 1: Violations tell the story A violation occurs when: If we encounter more than one…

  • Non-decreasing Array

    1. Problem Summary You are given an integer array nums, and your task is to determine whether it is possible to make the array non-decreasing by modifying at most one element. A non-decreasing array satisfies: Rules: Example interpretation:Input: Modify 4 → 2 to get [2,2,3] → return true. Input: Needs at least two modifications →…

  • Running Sum of 1D Array

    1. Problem Summary You are given an integer array nums. Your task is to compute and return a new array result where: This is known as the running sum or prefix sum of the array. Example interpretation:If: Then: 2. Key Insights Running sum accumulates progressively Each position builds on previous sum rather than recomputing from…

  • Palindrome Linked List

    1. Problem Summary You are given the head of a singly linked list.Your task is to determine whether the linked list represents a palindrome, meaning: Important details: Example interpretation:Input: Output: Another example: Output: 2. Key Insights Linked lists do not allow reverse indexing Unlike arrays, we cannot compare front and back via indices efficiently. Optimal…

  • LeetCode Problem 706 Design HashMap

    1. Problem Summary You are asked to implement a basic HashMap data structure from scratch without using: Your custom HashMap must support three operations: Behavior requirements: Constraints: 2. Key Insights Direct array is too large Even though key range is bounded (up to 1,000,000), storing a direct array that large is space-inefficient. Hashing required for…