Programowanie konkurencyjneŁatwe

Najdłuższy podciąg bitoniczny

Szczegółowy przewodnik i implementacja Python dla problemu „Najdłuższego podciągu bitonicznego”.

Oświadczenie o problemie

Łatwe

Napisz funkcję lbs(arr), która zwraca długość najdłuższego podciągu bitonicznego w tablicy arr. Podciąg jest bitoniczny, jeśli najpierw rośnie, a następnie maleje, lub ściśle rośnie, lub ściśle maleje.

Ograniczenia
  • 1 <= len(arr) <= 1000
  • -10^4 <= arr[i] <= 10^4

Przykłady

Example 1
Input
lbs([1, 11, 2, 10, 4, 5, 2, 1])
Output
6
Explanation

The longest bitonic subsequence is [1, 2, 10, 5, 2, 1] or [1, 2, 4, 5, 2, 1] with length 6.

Example 2
Input
lbs([12, 11, 40, 5, 3, 1])
Output
5
Explanation

The longest bitonic subsequence is [12, 11, 5, 3, 1] or [11, 40, 5, 3, 1] with length 5.

Need a Hint?
Rozważ użycie struktur danych specyficznych dla programowania dynamicznego, takich jak zestawy lub sterty.
Edge Cases to Watch
  • Puste struktury wejściowe
  • Wejścia jednoelementowe
  • Duże granice liczbowe

Gotowy do rozwiązania?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Otwórz w Edytorze
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Polecane zasoby Pythona

Poszerzaj swoją wiedzę dzięki powiązanym interaktywnym samouczkom, ściągawkom i porównaniom kodów.