javamyblog
javamyblog
Untitled
149 posts
Don't wanna be here? Send us removal request.
javamyblog · 1 year ago
Text
120. Triangle Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row. Example 1: Input: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]Output: 11Explanation: The triangle looks like: 2 3 4 6 5 74 1 8…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Simplifying Unix-style File Paths in Java
71. Simplify Path Given an absolute path for a Unix-style file system, which begins with a slash '/', transform this path into its simplified canonical path. In Unix-style file system context, a single period '.' signifies the current directory, a double period ".." denotes moving up one directory level, and multiple slashes such as "//" are interpreted as a single slash. In this problem, treat…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Evaluating Reverse Polish Notation
150. Evaluate Reverse Polish Notation You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation. Evaluate the expression. Return an integer that represents the value of the expression. Note that: The valid operators are '+', '-', '*', and '/'. Each operand may be an integer or another expression. The division between two integers always…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Finding the Smallest String Starting from a Leaf in a Binary Tree
988. Smallest String Starting From Leaf You are given the root of a binary tree where each node has a value in the range [0, 25] representing the letters 'a' to 'z'. Return the lexicographically smallest string that starts at a leaf of this tree and ends at the root. As a reminder, any shorter prefix of a string is lexicographically smaller. For example, "ab" is lexicographically smaller than…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Finding Paths with a Given Sum in a Binary Tree
113. Path Sum II Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum. Each path should be returned as a list of the node values, not node references. A root-to-leaf path is a path starting from the root and ending at any leaf node. A leaf is a node with no children. Example 1: Input: root =…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Finding the Minimum Falling Path Sum
931. Minimum Falling Path Sum Given an n x n array of integers matrix, return the minimum sum of any falling path through matrix. A falling path starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position (row, col) will be (row + 1, col - 1), (row + 1, col), or (row + 1, col +…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Finding the Maximum Area of an Island in Java
695. Max Area of Island You are given an m x n binary matrix grid. An island is a group of 1‘s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. The area of an island is the number of cells with a value 1 in the island. Return the maximum area of an island in grid. If there is no island, return 0. Example…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Generating Parentheses Combinations in Java
22. Generate Parentheses Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1: Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"] Example 2: Input: n = 1 Output: ["()"] Constraints: 1 <= n <= 8 In this blog post, we’ll explore a Java solution to generate all combinations of well-formed parentheses given a number…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Min Cost Climbing Stairs
746. Min Cost Climbing Stairs You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps. You can either start from the step with index 0, or the step with index 1. Return the minimum cost to reach the top of the floor. Example 1: Input: cost = [10,15,20] Output: 15 Explanation: You will start at index…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Optimizing String Compression
443. String Compression Given an array of characters chars, compress it using the following algorithm: Begin with an empty string s. For each group of consecutive repeating characters in chars: If the group’s length is 1, append the character to s. Otherwise, append the character followed by the group’s length. The compressed string s should not be returned separately, but instead, be stored…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Maximizing Equal Substrings Within a Cost Constraint
1208. Get Equal Substrings Within Budget You are given two strings s and t of the same length and an integer maxCost. You want to change s to t. Changing the ith character of s to ith character of t costs |s[i] - t[i]| (i.e., the absolute difference between the ASCII values of the characters). Return the maximum length of a substring of s that can be changed to be the same as the corresponding…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Understanding the Special Array Algorithm in Java
1608. Special Array With X Elements Greater Than or Equal X You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x. Notice that x does not have to be an element in nums. Return x if the array is special, otherwise, return -1. It can be proven that if nums is…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
WordBreak
140. Word Break II Given a string s and a dictionary of strings wordDict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in any order. Note that the same word in the dictionary may be reused multiple times in the segmentation. Example 1: Input: s = "catsanddog", wordDict = ["cat","cats","and","sand","dog"] Output: ["cats…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Exploring the "Rotting Oranges" Problem
994. Rotting Oranges You are given an m x n grid where each cell can have one of three values: 0 representing an empty cell, 1 representing a fresh orange, or 2 representing a rotten orange. Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten. Return the minimum number of minutes that must elapse until no cell has a fresh orange. If this is…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Exploring the "Beautiful Subsets" Problem
2597. The Number of Beautiful Subsets You are given an array nums of positive integers and a positive integer k. A subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k. Return the number of non-empty beautiful subsets of the array nums. A subset of nums is an array that can be obtained by deleting some (possibly none) elements from nums. Two…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Exploring the Dice Roll Sum Problem
1155. Number of Dice Rolls With Target Sum You have n dice, and each dice has k faces numbered from 1 to k. Given three integers n, k, and target, return the number of possible ways (out of the kn total ways) to roll the dice, so the sum of the face-up numbers equals target. Since the answer may be too large, return it modulo 109 + 7. Example 1: Input: n = 1, k = 6, target = 3 Output:…
Tumblr media
View On WordPress
0 notes
javamyblog · 1 year ago
Text
Exploring Palindromic Partitions
131. Palindrome Partitioning Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Example 1: Input: s = "aab" Output: [["a","a","b"],["aa","b"]] Example 2: Input: s = "a" Output: [["a"]] Constraints: 1 <= s.length <= 16 s contains only lowercase English letters. Hello, coding enthusiasts! Today, we’re…
Tumblr media
View On WordPress
0 notes