Posts with tag 'two pointers'

Remove Duplicate Numbers

less than 1 minute read

Given a list of integers nums, remove numbers that appear multiple times in the list, while maintaining order of the appearance in the original list.

Profitable Job Matching

1 minute read

You are given lists of integers people, jobs, profits. Each person i in people have people[i] amount of strength, and performing job j requires jobs[j] amoun...

Sum of Three Numbers Less than Target

1 minute read

Given a list of integers nums and an integer target, return the number of triples i < j < k that exist such that nums[i] + nums[j] + nums[k] < target.

Longest Sublist of 1s After K Sets

less than 1 minute read

You are given a list of integers nums containing 1s and 0s and an integer k. Given that you can set at most k 0s to 1s, return the length of the longest subl...

Minimum Window Substring

less than 1 minute read

Given two lowercase alphabet strings a and b, return the length of a minimum substring in a that contains all the characters of b.

Sort by Permutation

less than 1 minute read

Given a list of strings lst and a list of integers p, reorder lst so that every lst[i] gets placed to p[i].

Linked List Partitioning

less than 1 minute read

You are given a singly linked list node and an integer k. Order the linked list so that all nodes whose values are less than k come first, all nodes whose va...

Sum of Four Numbers

1 minute read

Given a list of integers nums and an integer k, return whether there are four distinct elements in the list that add up to k.

Maximum Unique Sublist Sum

less than 1 minute read

You are given a list of non-negative integers nums. Return the maximum sum of a sublist in nums containing only unique values.

Sum Pairs to Target

1 minute read

You are given a list of integers nums and an integer target. In one operation we can remove any two numbers in nums if the pair sums to target. Return the ma...

Longest 1s After One Flip

less than 1 minute read

You are given a string s containing 1s and 0s. Given that you can flip at most one "0", return the length of the longest contiguous substring of 1s.

K Distinct Window

less than 1 minute read

Given a list of integers nums and an integer k, return a list of count of distinct numbers in each window of size k.

Partition String

less than 1 minute read

Given a lowercase alphabet string s, partition s into as many pieces as possible such that each letter appears in at most one piece and return the sizes of t...

Kth Last Node of a Linked List

less than 1 minute read

Given a singly linked list node, return the value of the kth last node (0-indexed). k is guaranteed not to be larger than the size of the linked list.

Sum of Two Numbers with Sorted List

1 minute read

Given a list of integers nums sorted in ascending order and an integer k, return whether any two elements from the list add up to k. You may not use the same...

Sum of Two Numbers Less Than Target

less than 1 minute read

Given a list of integers nums and an integer target, return the sum of the largest pair of numbers in nums whose sum is less than target. You can assume that...

Sum of Three Numbers

less than 1 minute read

Given a list of integers nums and an integer k, determine if there are three distinct elements in the list that add up to k.

Stuck Keyboard

1 minute read

You are given two strings typed and target. You want to write target, but the keyboard is stuck so some characters may be written 1 or more times. Return whe...

Square of a List

less than 1 minute read

Given a list of integers sorted in ascending order nums, square the elements and give the output in sorted order.

Sentence Reversal

less than 1 minute read

Given a list of strings sentence where each sentence[i] is a string with single character, reverse the order of the words in the sentence.

Rotate Linked List by K

less than 1 minute read

Given a linked list node and a non-negative integer k, rotate the list to the right by k places.

Rain Catcher

1 minute read

You are given a list of non-negative integers nums where each element represents the height of a hill. Suppose it will rain and all the spaces between two si...

Quadratic Application

1 minute read

You are given a list of integers nums sorted in ascending order, and integers a, b, and c. Apply the following function for each number x in nums: \(ax^2 + b...

Palindrome Linked List

less than 1 minute read

Given a singly linked list node whose values are integers, determine whether the linked list forms a palindrome.

Merging Two Sorted Lists

less than 1 minute read

Given two lists of integers a and b sorted in ascending order, merge them into one large sorted list.

List Partitioning

less than 1 minute read

Given a list of strings strs, containing the strings "red", "green" and "blue", partition the list so that the red come before green, which come before blue.

Interval Overlaps

less than 1 minute read

You are given a list of closed intervals l0 and another list of intervals l1. Individually, each list is non-overlapping and are sorted in ascending order.

In-Place Move Zeros to End of List

less than 1 minute read

Given a list of integers nums, put all the zeros to the back of the list by modifying the list in-place. The relative ordering of other elements should stay ...

Equalize List Sums with Minimal Updates

1 minute read

You are given two lists of integers a and b where every element in both lists is between 1 to 6. Consider an operation where you pick a number in either a or...

Detect the Only Duplicate in a List

less than 1 minute read

You are given a list nums of length n + 1 picked from the range 1, 2, ..., n. By the pigeonhole principle, there must be a duplicate. Find and return it. The...

Check Palindrome

less than 1 minute read

Given a string s, return whether it is a palindrome.

Back to top ↑