Open in app

Sign In

Write

Sign In

Eddie Dong
Eddie Dong

1 Follower

Home

About

Aug 18, 2021

LC986

Problem: Given two sorted lists of intervals, List A and List B, the intervals in each list are not overlapped or disjoint. Find the overlapping intervals between A and B Intuition: When we see two sorted arrays/Lists, naturally we can think of anther problem that we know how to solve — merge two sorted arrays. Thus, we can use two pointers to do this problem. We now how to move the pointers according to the ending time of each interval. If A[i].end < B[j].end, we move i because B[j] may have additional time period to overlap with different interval from A. Secondly, we can easily get the overlapping interval by:

Two Pointers

1 min read

LC986
LC986
Two Pointers

1 min read


Aug 18, 2021

LC767

Problem: Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.Return any possible rearrangement of s or return "" if not possible. Intuition: Use least frequent characters to fill the gap between most frequent characters. Discussion: The most frequent characters in the…

Heap

1 min read

LC767
LC767
Heap

1 min read


Jul 18, 2021

LC 1041

Problem: Instruction for a robot movement L : turn left, R: turn right, G: go straight for 1 step Given sequence of instruction will be repeated indefinitely. Goal: given a sequence of instructions, check if robot forming a cycle. Intuition: if after one scan of execution, the robot faces different direction than starting direction(north), then won’t form a cycle. or if the starting position and the ending position is the same, it forms a cycle

Simulation

1 min read

LC 1041
LC 1041
Simulation

1 min read


Jul 17, 2021

LC 560

Goal: Find the numbers of subarrays that sum up to k. Array is an int array and has duplicates and negative numbers. Intuition: when negative numbers are allowed, then we cannot use the sliding window method because we can’t decide the right boundary of the window. Thus, we need a way to guarantee the windows can be closed. So prefix sum is good approach since prefix[i] — prefix[j] == k is a fix window.

Prefix Sum

1 min read

LC 560
LC 560
Prefix Sum

1 min read


Jan 18, 2021

LC 974

Goal: Given an array of integers, count number of subarrays that have sums that are divisible by K, where 2 ≤ K ≤ 10000. The subarray size should be at least 1. Intuition: The naive way is to try all the subarrays in nested loops. That will take O(n³). That is…

Prefix Sum

1 min read

LC 974
LC 974
Prefix Sum

1 min read


Jan 14, 2021

LC 31

Goal: Given an array of non-negative integers, find the lexicographically next permutation. If no such permutation, return the ascending order permutation. Intuition: 1. Notice that non-increasing sequence does not have next greater permutation, and non-decreasing sequence is the smallest permutation. 2. …

Mono Sequence

1 min read

LC 31
LC 31
Mono Sequence

1 min read


Jan 14, 2021

LC 84

Goal: Given an array of non-negative integers which represent histograms with width of 1 and height of the integer value. Find the largest area of any consecutive histograms can form. Intuition: Max area must use one of the histogram as the height, thus we can calculate areas formed with every histogram…

Mono Stack

2 min read

LC 84
LC 84
Mono Stack

2 min read


Jan 13, 2021

LC 239

Goal: Given an integer array and window side of K, find the max values for every window in the array. Return the max values array. Intuition: For window of size k ending with [i], the max of this window must ≥ [i] and must be within the window borders. …

Double Ended Queue

2 min read

LC 239
LC 239
Double Ended Queue

2 min read


Jan 13, 2021

LC 862

Goal: find the size of shortest subarray in given array that sum up to at least K, where negative integer is allowed. Reasoning for techniques used: 1. Prefix sum: Because negative number is allowed. This causes a problem that you don’t know when to stop expanding or shrinking the window. It’s…

Mono Sequence

1 min read

LC 862
LC 862
Mono Sequence

1 min read


Jan 12, 2021

LC 76

Goal: Find the minimum length substring in s that will cover all the characters in t. Represent three states of the problem: zero: just meet the needs positive: needs negative: extra or not needed Algorithm: 1. Use an array/list of size 128 to represent all types of characters and initialize the…

Sliding Window

2 min read

LC 76
LC 76
Sliding Window

2 min read

Eddie Dong

Eddie Dong

1 Follower

Study notes.

Following
  • csgator

    csgator

  • Sukhjinder Arora

    Sukhjinder Arora

  • freeCodeCamp

    freeCodeCamp

See all (12)

Help

Status

Writers

Blog

Careers

Privacy

Terms

About

Text to speech