Examness

Advanced Python

১২টি অনুশীলন · শেখানোর ক্রমে

  1. 1Fibonacci without the exponential blowupWrite `fib(n)` returning the nth Fibonacci number, with `fib(0) = 0` and `fib(1) = 1`.memoisationrecursioncomplexity12m
  2. 2Longest common subsequenceWrite `lcs_length(a, b)` returning the length of the longest subsequence common to both strings.2D dynamic programmingtablessubsequences20m
  3. 3Shortest path by breadth-first searchWrite `shortest_path(graph, start, goal)` returning the fewest hops between two nodes, or `-1` when no route exists.BFSqueuesvisited setsgraphs18m
  4. 4Order tasks by dependencyWrite `task_order(tasks)` where `tasks` maps each task to the list of tasks it depends on.topological sortin-degreecycle detection20m
  5. 5Merge overlapping intervalsWrite `merge_intervals(intervals)` collapsing every overlap into a single span.sortingsweepedge cases15m
  6. 6Two numbers that add to a targetWrite `two_sum(numbers, target)` returning the indices of the two values that add to `target`, as a tuple, smallest index first.hash mapsone passO(n) vs O(n^2)12m
  7. 7Least-recently-used cacheWrite an `LRUCache(capacity)` class with `get(key)` and `put(key, value)`.OrderedDictevictioncapacity22m
  8. 8A timer you can use with `with`Write a `Timer` class usable as a context manager.context managers__enter____exit__15m
  9. 9An object you can loop overWrite a `Countdown(start)` class that can be used in a `for` loop, yielding `start` down to 1.__iter____next__StopIteration15m
  10. 10QuicksortWrite `quicksort(numbers)` returning a new sorted list.divide and conquerpartitioningrecursion15m
  11. 11Publish and subscribeWrite an `EventEmitter` class with `on(event, handler)`, `off(event, handler)` and `emit(event, *args)`.callbacksdict of listsobserver pattern18m
  12. 12Sliding-window rate limiterWrite a `RateLimiter(max_calls, window)` class with one method, `allow(now)`.sliding windowdequetime-based state20m