Learnitweb

Category: Java programming question

  • LeetCode 974: Subarrays Divisible by K

    1. Introduction This problem asks you to count how many contiguous subarrays in an integer array have a sum divisible by a given integer K. The subarray must be continuous, and the sum must satisfy the condition: (sum % K == 0) Example inputs and outputs: Input: nums = [4,5,0,-2,-3,1], K = 5Output: 7 The…

  • LeetCode 342: Power of Four

    1. Introduction LeetCode Problem 342 asks you to determine whether a given integer is a power of four. A number qualifies if it can be expressed as 4ⁿ for some non-negative integer n. Examples of valid results include 1, 4, 16, 64, 256, and so on. The task is to return true if the number…

  • Problem 168: Excel Sheet Column Title

    You are given a positive integer columnNumber, and you must return its corresponding Excel column title. Excel columns work like this: 1 → A2 → B3 → C…26 → Z27 → AA28 → AB…52 → AZ53 → BA… This is essentially a base-26 conversion, but with a twist:There is no zero, and Excel uses 1–26…

  • Problem 125: Valid Palindrome

    You are given a string s.Your task is to determine whether it is a valid palindrome after: Ignoring all non-alphanumeric charactersConverting all letters to lowercase A palindrome reads the same forwards and backwards. Understanding the Problem We only care about: A–Z, a–z0–9 All other characters (spaces, commas, punctuation, etc.) must be skipped. Examples: Input: “A…

  • Problem 705: Design HashSet

    You must design your own HashSet data structure from scratch.It should support the following operations efficiently: add(key)remove(key)contains(key) You are NOT allowed to use built-in HashSet libraries. The input range of keys is typically from 0 to 1,000,000. Understanding the Problem HashSet stores unique integers with fast O(1) operations. You need to implement: void add(int key)void…

  • Problem 520: Detect Capital

    You are given a word, and you must determine whether the usage of capital letters is correct based on the following rules: A word is correctly capitalized if: Any word that violates these three patterns is incorrect. Your task is to return true if the capitalization is valid, false otherwise. Understanding the Problem Examples: Input:…

  • Problem 70: Climbing Stairs

    You are climbing a staircase with n steps.Each time you can take either 1 step or 2 steps.Your task is to return how many distinct ways you can reach the top. Understanding the Problem If n = 1Ways = 1(Only one move of 1 step) If n = 2Ways = 2(1+1)(2) If n = 3Ways…

  • Problem 140: Word Break II

    You are given a string s and a list of words wordDict.You must return all possible sentences where s can be segmented such that each segment is a word in the dictionary. Unlike Word Break I (Problem 139), where you return true/false, here you must return all valid combinations. Understanding the Problem Example: s =…

  • Problem 309: Best Time to Buy and Sell Stock with Cooldown

    You are given an array prices where prices[i] is the stock price on day i.You may complete as many transactions as you want, but after selling, you must wait one cooldown day before buying again. Your task:Return the maximum profit possible. Understanding the Problem You can: Buy one shareSell one shareNot hold multiple sharesCooldown: after…

  • Problem 621: Task Scheduler

    You are given: An array of CPU tasks, each represented by an uppercase letterA non-negative cooling interval n The CPU can execute one task per unit time, but the same task must have at least n units of cooling time before it can run again. Your goal:Return the minimum number of time intervals needed to…