Fading Coder

One Final Commit for the Last Sprint

Three Problems from LeetCode Weekly Contest 405

Problem 1: Encrypted String This is a straightforward simulation: for each index i in the original string, the encrypted character is taken from index (i + k) % n. Below is an implementation using a character array for clarity. class Solution { public String getEncryptedString(String s, int k) { int...

Efficient Solutions for Common Array Manipulation Problems

Merging Two Sorted Arrays Approach: Use two pointers starting from the end of both arrays and fill the result array from the end to avoid overwriting. Implementation: class ArrayMerger { public void combineSortedArrays(int[] primary, int size1, int[] secondary, int size2) { int position = primary.le...

Hash Table and Two-Pointer Techniques for K-Sum Problems

4Sum II: Pair Summation with Hash Maps Given four integer arrays of equal length, determine the number of tuple combinations (i, j, k, l) where the sum of corresponding elements equals zero. Unlike single-array k-sum problems requiring deduplication, this scenario involves four independent collectio...

Adding Two Numbers Represented by Linked Lists

Problem Description Given two non-empty linked lists representing non-negative integres in reverse digit order, combine the numbers and return the result as a linked list. Basic Iterative Approach class Solution { public ListNode addTwoNumbers(ListNode first, ListNode second) { ListNode dummyHead =...

Common Linked List Problems and Solutions

Copy List with Random Pointer This problem is a classic deep copy scenario, similar to graph cloning (e.g., LeetCode 133). Approach: Traverse the list once to copy the next pointers. During this traversal, store the mapping between original nodes and their copies in a hash map. Traverse the list a s...

Solving the Two Sum Problem in Java

Given an array of integers nums and an integer target, return the indices of two numbers that add up to the target value. Example: Input: nums = [3, 4, 2], target = 6 Output: [1, 2] Explanation: nums[1] + nums[2] equals 6 Approaches Brute Force Method: Iterate through each element and check every ot...

Implementing Core Linked List Operations: Removal, Design, and Reversal in Python

Working with singly linked lists requires a firm grasp of pointer manipulation and edge-case handling. The following sections break down three classic problems: removing nodes by value, building a custom linked list with index-based operations, and reversing a list in-place. Eliminating Nodes with a...

LeetCode-Java: 271. Contains Duplicate

Problem Description Given an integer array nums, return true if any value appears at least twice in the array, and return false if all elements are distinct. Example 1: Input: nums = [1,2,3,1] Output: true Example 2: Input: nums = [1,2,3,4] Output: false Example 3: Input: nums = [1,1,1,3,3,4,3,2,4,2...

Solving Three LeetCode Problems: Minimum Time Visiting Points, Search Suggestions, and Tic-Tac-Toe Winner

Minimum Time to Visit All Points Given integer coordinates points[i] = [xi, yi] for n points on a plane, calculate the minimum time in seconds to visit all points in the order given. Movement rules: Each second, move one unit horizontally, vertically, or diagonally (one unit in both directions). Exa...

Determining Palindrome Numbers Without Extra Space in Python

Understanding the Problem The objective is to verify if a given integer is a palindrome. A palindrome reads the same backward as forward. For integers, this means that if we reverse the sequence of digits, the value remains identical. The problem imposes a strict constraint: the solution must not us...