Category: Java programming question
-
LeetCode Problem 557: Reverse Words in a String III
Problem Overview You are given a string s that contains words separated by single spaces. Your task is to reverse the characters of each word, while keeping the order of the words and the spaces exactly the same. In simple terms, you need to reverse each word individually, but not the order of the words.…
-
LeetCode Problem 541: Reverse String II
Problem Overview You are given a string s and an integer k.Your task is to reverse the first k characters for every 2k characters in the string. In other words: Example 1: Example 2: Intuition / Approach We can solve this problem efficiently by iterating through the string in chunks of 2k characters.For every chunk:…
-
LeetCode Problem 344: Reverse String
Problem Overview The problem asks you to reverse the given array of characters in-place. This means you cannot use extra memory for another array; instead, you must modify the input array directly. Formally:Given a character array s, reverse the order of the characters in it so that the first element becomes the last, and the…
-
Problem 1029: Two City Scheduling
Problem Overview A company is planning to interview 2n people. You must send exactly n people to city A and the remaining n people to city B. The cost of sending each person to either city A or city B is given as a 2D array costs, where: Your task is to minimize the total…
-
Problem 237: Delete Node in a Linked List
Problem Overview You are given a node in a singly linked list, and your task is to delete this node.You are not given access to the head of the linked list — only the node that needs to be deleted. It is guaranteed that the node to be deleted is not the last node in…
-
Problem 226: Invert Binary Tree
Problem Overview You are given the root of a binary tree. The task is to invert the binary tree and return its root. Inverting a binary tree means swapping the left and right child of every node in the tree. Example 1 Explanation:Every left child is swapped with its corresponding right child recursively throughout the…
-
Problem 72: Edit Distance
Problem Overview You are given two strings, word1 and word2. You need to determine the minimum number of operations required to convert word1 into word2. The allowed operations are: You must find the fewest possible sequence of these operations to make the two strings identical. Example 1 Example 2 Intuition / Approach This problem is…
-
LeetCode Problem 1460: Make Two Arrays Equal by Reversing Subarrays
Problem Overview You are given two integer arrays target and arr of the same length n. In one operation, you can choose any subarray of arr and reverse it.You can perform this operation any number of times. Return true if you can make arr equal to target, otherwise return false. Example 1:Input:target = [1,2,3,4], arr…
-
LeetCode Problem 973: K Closest Points to Origin
Problem Overview You are given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, and an integer k. Your task is to return the k points closest to the origin (0, 0). The distance between any point (x, y) and the origin (0, 0) is calculated as: However,…
-
LeetCode Problem 207: Course Schedule
Problem Overview You are given an integer numCourses representing the total number of courses labeled from 0 to numCourses – 1. You are also given an array prerequisites, where each element prerequisites[i] = [a, b] indicates that you must take course b before course a. Return true if it is possible to finish all courses,…
