Leetcode 0019. Remove Nth Node From End of List

Posted on Mon 02 December 2024 in Leetcode • Tagged with linked-list, two-pointers, trailing-pointer

Question Link : https://leetcode.com/problems/remove-nth-node-from-end-of-list/

Difficulty: Medium

Premium: False

Question

Given the head of a linked list, remove the nth node from the end of the list and return its head.   Example 1:

Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5]

Example …


Continue reading

Leetcode 0026. Remove Duplicates from Sorted Array

Posted on Fri 01 November 2024 in Leetcode • Tagged with array-shift, two-pointers

Question Link : https://leetcode.com/problems/remove-duplicates-from-sorted-array/

Difficulty: Easy

Premium: False

Question

Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique …


Continue reading

Leetcode 0027. Remove Element

Posted on Fri 01 November 2024 in Leetcode • Tagged with two-pointers

Question Link : https://leetcode.com/problems/remove-element/

Difficulty: Easy

Premium: False

Question

Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to …


Continue reading

Leetcode 0881. Boats to Save People

Posted on Sun 02 April 2023 in Leetcode • Tagged with two-pointers, greedy

Question Link : https://leetcode.com/problems/boats-to-save-people/

Difficulty: Medium

Premium: False

Question

You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two …


Continue reading

Leetcode 0011. Container With Most Water

Posted on Mon 27 March 2023 in Leetcode • Tagged with two-pointers

Question Link : https://leetcode.com/problems/container-with-most-water/

Difficulty: Medium

Premium: False

Question

You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with …


Continue reading

Leetcode 0328. Odd Even Linked List

Posted on Mon 05 December 2022 in Leetcode • Tagged with two-pointers

Question Link : https://leetcode.com/problems/odd-even-linked-list/

Difficulty: Medium

Premium: False

Question

Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list. The first node is considered odd, and the second node …


Continue reading

Leetcode 2460. Apply Operations to an Array

Posted on Tue 08 November 2022 in Leetcode • Tagged with two-pointers

Question Link : https://leetcode.com/problems/apply-operations-to-an-array/

Difficulty: Easy

Question

You are given a 0-indexed array nums of size n consisting of non-negative integers. You need to apply n - 1 operations to this array where, in the ith operation (0-indexed), you will apply the following on the ith element of …


Continue reading

Leetcode 2441. Largest Positive Integer That Exists With Its Negative

Posted on Sat 05 November 2022 in Leetcode • Tagged with two-pointers

Question Link : https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/

Difficulty: Easy

Question

Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array. Return the positive integer k. If there is no such integer, return -1.   Example 1 …


Continue reading

Leetcode 0283. Move Zeroes

Posted on Thu 03 November 2022 in Leetcode • Tagged with array-shift, two-pointers

Question Link : https://leetcode.com/problems/move-zeroes/

Difficulty: Easy

Question

Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this in-place without making a copy of the array.   Example 1: Input: nums …


Continue reading

Leetcode 0345. Reverse Vowels of a String

Posted on Thu 03 November 2022 in Leetcode • Tagged with two-pointers, string

Question Link : https://leetcode.com/problems/reverse-vowels-of-a-string/

Difficulty: Easy

Question

Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once.   Example 1: Input …


Continue reading