This shows you the differences between two versions of the page.
pa:laboratoare:laborator-00 [2025/02/24 23:00] darius.neatu [Exercitii] |
pa:laboratoare:laborator-00 [2025/03/06 22:57] (current) darius.neatu [Exercitii] |
||
---|---|---|---|
Line 119: | Line 119: | ||
2. Pentru fiecare din elementele următoarele, dacă acesta este mai mare decât minimul din heap, se șterge minimul și se adaugă elementul curent. Mereu în heap avem k elemente la final de pas în această etapă. | 2. Pentru fiecare din elementele următoarele, dacă acesta este mai mare decât minimul din heap, se șterge minimul și se adaugă elementul curent. Mereu în heap avem k elemente la final de pas în această etapă. | ||
- | 3. Răspunsul este minimul din heap la finalul parcurgerii. Complexitate este de $ O(n log k) $. | + | 3. Răspunsul este minimul din heap la finalul parcurgerii. |
+ | |||
+ | Complexitate este de $ O(n log k) $, care este mai bună. Implementați și testați pe Leetcode! | ||
</spoiler> | </spoiler> | ||
- | * **Task02**: Rezolvați problema [[https://leetcode.com/problems/sliding-window-maximum/| Sliding Window Maximum]]. | + | <spoiler Soluția 3> |
+ | Hint: Soluția 2 nu este optimă! Se poate și $O(n)$, dar considerăm că este înafara scopului laboratorului 0. | ||
+ | </spoiler> | ||
- | * **Task03**: Rezolvați problema [[https://leetcode.com/problems/longest-substring-without-repeating-characters| Longest Substring without repeating characters]]. | + | * **Task02**: Discutați problema [[https://leetcode.com/problems/sliding-window-maximum/| Sliding Window Maximum]] și problema [[https://leetcode.com/problems/longest-substring-without-repeating-characters| Longest Substring without repeating characters]]. Implementați și testați cel puțin o problemă. |
- | * **Task04**: Rezolvați problema [[https://leetcode.com/problems/min-stack/description/| Min Stack]]. | + | * **Task03**: Rezolvați problema [[https://leetcode.com/problems/min-stack/description/| Min Stack]]. |