Application of Residue Theorem to evaluate real integrations.pptx
Leetcode Problem Solution
1. Week 5
• Cheapest Flights within k stops
• Merge K sorted Lists
• Race Car
2. Cheapest Flights within k stops
• There are n cities connected by m flights. Each
flight starts from city u and arrives at v with a
price w.
• Now given all the cities and flights, together
with starting city src and the destination dst,
your task is to find the cheapest price
from src to dst with up to k stops. If there is no
such route, output -1.
3. Example:
The cheapest price from city 0 to city 2 with at most 1 stop costs 200, as
marked red in the picture.
8. // Adjacency Matrix
// Calling DFS through solve function
// Graph Generation
// Visited Array
// Keep track of the minimum cost
// Cost Matrix
9.
10. Merge K sorted Lists
• You are given an array of k linked-lists lists,
each linked-list is sorted in ascending order.
• Merge all the linked-lists into one sorted
linked-list and return it.
29. Race Car
• Your car starts at position 0 and speed +1 on an infinite number
line. (Your car can go into negative positions.)
• Your car drives automatically according to a sequence of
instructions A (accelerate) and R (reverse).
• When you get an instruction "A", your car does the
following: position += speed, speed *= 2.
• When you get an instruction "R", your car does the following: if
your speed is positive then speed = -1 , otherwise speed = 1. (Your
position stays the same.)
• For example, after commands "AAR", your car goes to positions 0-
>1->3->3, and your speed goes to 1->2->4->-1.
• Now for some target position, say the length of the shortest
sequence of instructions to get there.