Category: Java programming question
-
LeetCode Problem 338: Counting Bits
Problem Overview You are given a non-negative integer n. For every number i in the range [0, n], you need to calculate how many 1s are present in the binary representation of i.Return the result as an integer array ans of length n + 1, where ans[i] represents the number of 1s in the binary…
-
LeetCode Problem 886: Possible Bipartition
1. Problem Description You are given an integer n, representing the number of people labeled from 1 to n.You are also given an array dislikes, where dislikes[i] = [a, b] means that person a and person b dislike each other. Your task is to determine whether it is possible to divide all people into two…
-
LeetCode Problem 1035: Uncrossed Lines
1. Problem Description You are given two integer arrays nums1 and nums2.We draw a line connecting nums1[i] and nums2[j] if and only if nums1[i] == nums2[j], and no two lines cross each other. Your task is to return the maximum number of connecting lines that can be drawn between these arrays such that no two…
-
LeetCode Problem 1456: Maximum Number of Vowels in a Substring of Given Length
1. Problem Overview This problem tests your understanding of string manipulation and the sliding window technique. The goal is to find the maximum number of vowels that appear in any substring of length k within a given string s. Problem Statement (LeetCode 1456) Given a string s and an integer k, return the maximum number…
-
LeetCode Problem 46: Permutations
1. Problem Overview The “Permutations” problem is a backtracking problem where we are asked to generate all possible arrangements (permutations) of a given array of distinct integers. Problem Statement (LeetCode 46) Given an array nums of distinct integers, return all the possible permutations.You may return the answer in any order. Example 1: Example 2: Example…
-
LeetCode Problem 986: Interval List Intersections
1. Problem Overview This problem deals with two lists of intervals. Each list contains non-overlapping intervals, and the intervals in each list are sorted in ascending order by their start time. The task is to find all intersections between the two lists of intervals — that is, all intervals that overlap between the two lists.…
-
LeetCode Problem 451: Sort Characters By Frequency
1. Problem Overview The “Sort Characters By Frequency” problem asks us to rearrange characters in a given string such that characters appear in descending order of their frequency (the number of times they occur). If two characters have the same frequency, their order relative to each other does not matter. Problem Statement (LeetCode 451) Given…
-
LeetCode 451: Sort Characters By Frequency
Problem Statement Given a string s, sort it in decreasing order based on the frequency of characters and return the resulting string. Example 1:Input: “tree”Output: “eert” or “eetr”Explanation: ‘e’ appears twice, ‘r’ and ‘t’ appear once each. Example 2:Input: “cccaaa”Output: “cccaaa” or “aaaccc”Explanation: ‘c’ and ‘a’ both appear three times. Order among same frequency characters…
-
LeetCode 1277: Count Square Submatrices with All Ones
Problem Statement Given a m x n binary matrix mat (containing only 0s and 1s), return the total number of square submatrices that have all ones. Example 1:Input: Output: 15Explanation: Example 2:Input: Output: 7 Constraints: Approach in Plain English Key idea: DP stores size of largest square ending at each cell, which implicitly counts smaller…
-
LeetCode 230: Kth Smallest Element in a BST
Problem Statement Given the root of a binary search tree (BST) and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree. Example 1:Input: root = [3,1,4,null,2], k = 1Output: 1 Example 2:Input: root = [5,3,6,2,4,null,null,1], k = 3Output: 3 Constraints: Approach in Plain English Key…
