Skip to main content
763, Partition Labels

I Problem

You are given a string s. We want to partition the string into as many parts as possible so that each letter appears in at most one part.

Note that the partition is done so that after concatenating all the parts in order, the resultant string should be s.


MikeAbout 1 mingreedymediumgreedytwo pointershash tablestring
455, Assign Cookies

I Problem

Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie.

Each child i has a greed factor g[i], which is the minimum size of a cookie that the child will be content with; and each cookie j has a size s[j]. If s[j] >= g[i], we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.


MikeAbout 2 mingreedyeasygreedyarraytwo pointerssorting
28, Find the Index of the First Occurrence in a String

I Problem

Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

Example 1
Input: haystack = "sadbutsad", needle = "sad"
Output: 0
Explanation: "sad" occurs at index 0 and 6. The first occurrence is at index 0, so we return 0.


MikeAbout 2 minstringeasystringstring matchingtwo pointers
151, Reverse words in a String

I Problem

Given an input string s, reverse the order of the words.

A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space.

Return a string of the words in reverse order concatenated by a single space.


MikeAbout 3 minstringmediumstringtwo pointers
541, Reverse String II

I Problem

Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string.

  • If there are fewer than k characters left, reverse all of them.
  • If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and leave the other as original.

MikeLess than 1 minutestringeasystringtwo pointers
344, Reverse String

I Problem

Write a function that reverses a string. The input string is given as an array of characters s.

You must do this by modifying the input array in-place with O(1) extra memory.


MikeLess than 1 minutestringeasystringtwo pointers
18, Four Sum

I Problem

Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:

  • 0 <= a, b, c, d < n
  • a, b, c, and d are distinct.
  • nums[a] + nums[b] + nums[c] + nums[d] == target

MikeAbout 3 minhashtablemediumarraytwo pointerssorting
16, Three Sum Closest

I Problem

Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target.

Return the sum of the three integers.

You may assume that each input would have exactly one solution.


MikeAbout 2 minhashtablemediumarraytwo pointerssorting
15, Three Sum

I Problem

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Notice that the solution set must not contain duplicate triplets.


MikeAbout 2 minhashtablemediumarraytwo pointerssorting
202, Happy Number

I Problem

Write an algorithm to determine if a number n is happy.

A happy number is a number defined by the following process:

  • Starting with any positive integer, replace the number by the sum of the squares of its digits.
  • Repeat the process until the number equals 1(where it will stay), or it loops endlessly in a cycle which does not include 1.
  • Those numbers for which this process ends in 1 are happy.

MikeAbout 1 minhashtableeasyhash tablemathtwo pointers
2
3