Marcy Blog

Failed to be a geek

Problem: Number of Boomerangs

Question Given n points in the plane that are all pairwise distinct, a “boomerang” is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the or...

Problem: Maximum Size Subarray Sum Equals k

Question Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn’t one, return 0 instead. Note: The sum of the entire nums array is guaranteed...

Problem: Contiguous Array

Question Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. Example 1: Input: [0,1] Output: 2 Explanation: [0, 1] is the longest contiguous subar...

Problem: First Unique Character in a String

Question Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Not...

Problem: Insert Delete GetRandom O(1)

Question Design a data structure that supports all following operations in average O(1) time. insert(val): Inserts an item val to the set if not already present. remove(val): Removes an item...

Problem: Insert Delete GetRandom O(1)

Question Design a data structure that supports all following operations in average O(1) time. Note: Duplicate elements are allowed. insert(val): Inserts an item val to the collection. remove...

Problem: Valid Anagram

Question Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. Note: You m...

Problem: Sort Characters By Frequency

Question Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: "tree" Output: "eert" Explanation: 'e' appears twice while 'r' and 't' both appear ...

Problem: Single Number

Question Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without...

Problem: Longest Substring Without Repeating Characters

Question Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer...