Coding Patterns

Sort Colors

Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order…

Reverse String

Given a character array s, reverse the order of its elements in-place.

Move Zeroes

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Modify the array in-place with…

Remove Element

Given an array nums and a value val, remove all instances of that value in-place and return the new length of the array. Do not allocate extra space for another…

Remove Duplicates from Sorted Array

Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length. Do not allocate extra space for another array. Modify…

Valid Palindrome?

Given a string s, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. A palindrome is a word, phrase, number, or other sequences of characters that…

Two Sum II – Input Array is Sorted

Given an array numbers that is sorted in non-decreasing order and a target target, find two numbers in the array such that they add up to the target. You may…

3 Sum Problem

Given an array nums of n integers, find all unique triplets in the array that sum up to zero. Each triplet must be in non-descending order (i.e., the elements of…

Container With Most Water

Given an array height of non-negative integers representing the heights of lines on a 2D plane, where the width of each line is 1, find two lines which, together with…

Peak Index in a Mountain Array

Given an array of integers arr that represents a mountain, you need to find the peak index. A peak index is an index such that arr arr.…