LC 74 Flashcards
Two Sums
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
use hashmap
Longest Substring Without Repeating Characters
Input: s = “abcabcbb”
Output: 3
Explanation: The answer is “abc”, with the length of 3.
???
Longest Palindromic Substring
Input: s = “babad”
Output: “bab”
Explanation: “aba” is also a valid answer.
???
Container With Most Water
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
find max area by multiplying
min height between arr[x] or arr[y] * (y-x)
3Sums
sort the array use 2sums and add logic 2sums + arr[x] > 0 reduce end 2sums + arr[x] < 0 increment start else you found 3 elements adds to 0
Remove Nth Node From End of List
Input: head = [1,2,3,4,5], n = 2
Output: [1,2,3,5]
use temp node to point to head and keep traversing
while this keep counter
counter reaches the n the node
set the temp.next to next of next
Valid Parentheses
Merge Two Sorted Lists
Input: list1 = [1,2,4], list2 = [1,3,4]
Output: [1,1,2,3,4,4]
ListNode
Search in Rotated Sorted Array
Rotate Image
Group Anagrams
Maximum Subarray
Input: nums = [-2,1,-3,4,-1,2,1,-5,4]
Output: 6
Explanation: [4,-1,2,1] has the largest sum = 6.
find max
keep calculating temp max
max is max, tempmax
Spiral Matrix
Jump Game
Merge Intervals
Merge k Sorted Lists Input: lists = [[1,4,5],[1,3,4],[2,6]] Output: [1,1,2,3,4,4,5,6] Explanation: The linked-lists are: [ 1->4->5, 1->3->4, 2->6 ] merging them into one sorted list: 1->1->2->3->4->4->5->6
Insert Interval
Unique Paths
Climbing Stairs Input: n = 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps
Set Matrix Zeroes
Minimum Window Substring
Word Search
Decode Ways
Validate Binary Search Tree
Same Tree