LC 74 Flashcards

1
Q

Two Sums
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].

A

use hashmap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Longest Substring Without Repeating Characters
Input: s = “abcabcbb”
Output: 3
Explanation: The answer is “abc”, with the length of 3.

A

???

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Longest Palindromic Substring
Input: s = “babad”
Output: “bab”
Explanation: “aba” is also a valid answer.

A

???

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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.

A

find max area by multiplying

min height between arr[x] or arr[y] * (y-x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

3Sums

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Remove Nth Node From End of List
Input: head = [1,2,3,4,5], n = 2
Output: [1,2,3,5]

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Valid Parentheses

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Merge Two Sorted Lists
Input: list1 = [1,2,4], list2 = [1,3,4]
Output: [1,1,2,3,4,4]
ListNode

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Search in Rotated Sorted Array

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Rotate Image

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Group Anagrams

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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.

A

find max
keep calculating temp max
max is max, tempmax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Spiral Matrix

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Jump Game

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Merge Intervals

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
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
A
17
Q

Insert Interval

A
18
Q

Unique Paths

A
19
Q
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
A
20
Q

Set Matrix Zeroes

A
21
Q

Minimum Window Substring

A
22
Q

Word Search

A
23
Q

Decode Ways

A
24
Q

Validate Binary Search Tree

A
25
Q

Same Tree

A